sim: labels and comments are now shown
[calu.git] / 3a_asm / Main.hs
index d62fe17360220692b8defa51d7e7495b49dd2a71..08522c658d34fabbc0d97ac1cb7d2744d543418c 100644 (file)
@@ -140,7 +140,7 @@ testDTF input =
 parseDTFLine :: [DictElem] -> Parser DTF
 parseDTFLine dict = foldl1 (<|>) (fmap (\x -> try (x dict)) lineFormats) <* char '\n'
 
-lineFormats = [lf_define, 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_ifill, lf_comment, lf_toparse, lf_label]
 
 -- helper
 parseIdent :: Parser String
@@ -173,12 +173,26 @@ lf_data d = do
        repeat <- try (do {size <- many1 $ noneOf "\n;,"; char ','; return $ size}) <|> return "1"
        -- TODO: atm 32bit imm only
        code <- many1 $ noneOf "\n;"
-       -- TODO: this is quite ugly here :/
-       let (Right val) = parse (parseConst d) "" code
-       let (Right r) = parse (parseConst d) "" repeat
+       let val = case parse (parseConst d) "" code of
+               Right v -> v
+               Left err -> error $ show err
+       let r = case parse (parseConst d) "" repeat of
+               Right v -> v
+               Left err -> error $ show err
        comment <- try(parseComment) <|> parseMySpaces
        return $ DTF_Fill r val (fill ++ (if repeat == "1" then "" else repeat) ++ code) l comment
 
+lf_ifill d = do
+       l <- try (parseLabel) <|> string ""
+       skipMany space
+       fill <- string ".ifill "
+       code <- many1 $ noneOf "\n;"
+       let val = case parse (instruction (0,d)) "" (code++"\n") of
+               Right v -> v
+               Left err -> error $ show err
+       comment <- try(parseComment) <|> parseMySpaces
+       return $ DTF_Fill 1 val (fill ++ code) l comment
+
 lf_comment _ = do
        comment <- parseComment
        return $ DTF_Comment comment