3a_asm: .define support
authorBernhard Urban <lewurm@gmail.com>
Sun, 31 Oct 2010 23:40:42 +0000 (00:40 +0100)
committerBernhard Urban <lewurm@gmail.com>
Sun, 31 Oct 2010 23:40:42 +0000 (00:40 +0100)
3a_asm/DTFormat.hs
3a_asm/Main.hs

index 139367018da8ce0ca23e5f2f80361bb4310085c6..3e607fdec50803ccd2ad8f7758e044d798ac9af1 100644 (file)
@@ -25,6 +25,7 @@ data DTF =
        DTF_InstrToParse Address ValueToParse Code Label Comment |
        DTF_SectionToDet Address Value Code Label Comment |
        DTF_Org Address |
+       DTF_Define Label Value Comment |
        DTF_State DT_State
 
 instance Show (DTF) where
@@ -38,6 +39,7 @@ showsDTF (DTF_Label l c _) = (++) (printf "3;%s;%s\n" l c)
 showsDTF (DTF_InstrToParse a v c l s) = (++) (printf "itp;%08x;%s;%s;%s;%s\n" a v c l s)
 showsDTF (DTF_SectionToDet a v c l s) = (++) (datins "std" a v c l s)
 showsDTF (DTF_Org a) = (++) (printf "org;%08x\n" a)
+showsDTF (DTF_Define l a c) = (++) (printf "def;%s;%08X;%s\n" l a c)
 showsDTF (DTF_State s) = (++) (printf "sta;%s\n" (show s))
 
 datins :: String -> Address -> Value -> Code -> Label -> Comment -> String
index 2952e8b53925251ba684962ee0b4455ccfcb0ecc..fa5a12c386a5315ddc8d0a6704747fa2aa8d495b 100644 (file)
@@ -58,6 +58,7 @@ convertDTF ((lno,str):xs) state datacnt instrcnt dict = (newdict, (actlist newdt
        where
        actlist (DTF_Org _) = next
        actlist (DTF_State _) = next
+       actlist (DTF_Define _ _ _) = next
        actlist y = y:next
 
        (newdict,next) = convertDTF xs (nstate newdtf) (ndatacnt newdtf) (ninstrcnt newdtf) (ndict newdtf)
@@ -83,6 +84,7 @@ convertDTF ((lno,str):xs) state datacnt instrcnt dict = (newdict, (actlist newdt
        ndict (DTF_InstrToParse a _ _ l _) = dict `add_elem` (l,a)
        ndict (DTF_Data a _ _ l _) = dict `add_elem` (l,a)
        ndict (DTF_Instr a _ _ l _) = dict `add_elem` (l,a)
+       ndict (DTF_Define l v _) = dict `add_elem` (l,v)
        ndict _ = dict
 
        newdtf = case (parse parseDTFLine "" (str++"\n")) of
@@ -103,7 +105,7 @@ convertDTF ((lno,str):xs) state datacnt instrcnt dict = (newdict, (actlist newdt
                                NoState -> error "missing .data or .text"
                                InData -> (DTF_Label l c datacnt)
                                InText -> (DTF_Label l c instrcnt)
-               Right z -> z -- DTF_Comment, DTF_State
+               Right z -> z -- DTF_Comment, DTF_State, DTF_Define
 
 
 
@@ -116,15 +118,20 @@ testDTF input =
 parseDTFLine :: Parser DTF
 parseDTFLine = foldl1 (<|>) (fmap try lineFormats) <* char '\n'
 
-lineFormats = [lf_sdata, lf_stext, lf_org, lf_data, lf_comment, lf_toparse, lf_label]
+lineFormats = [lf_define, lf_sdata, lf_stext, lf_org, lf_data, lf_comment, lf_toparse, lf_label]
 
 -- helper
+parseIdent :: Parser String
+parseIdent = do
+       ident <- letter
+       idents <- many $ (letter <|> digit <|> char '_')
+       return $ (ident:idents)
+
 parseLabel :: Parser String
 parseLabel = do
-       label <- letter 
-       labels <- many $ (letter <|> digit <|> char '_')
+       l <- parseIdent
        char ':'
-       return $ (label:labels)
+       return $ l
 
 parseComment :: Parser String
 parseComment = do
@@ -189,3 +196,12 @@ lf_stext = do
        parseMySpaces
        return $ DTF_State InText
 
+lf_define = do
+       skipMany space
+       string ".define"
+       parseMySpaces
+       id <- parseIdent
+       parseMySpaces; char ','; parseMySpaces
+       ret <- parseConst
+       comment <- try(parseComment) <|> parseMySpaces
+       return $ DTF_Define id ret comment