-- as for deep thoughts ISA
-----------------------------------------------------------------------------
-import DT
+import DT hiding (not)
import DTFormat
import Expr_eval
content <- getContents
let src = (filter (((/=) "") . snd) $ (zip [1..] (lines content)))
let (dict,formatedsrc) = convertDTF src NoState 0x00 0x00 [("start_",0x00)]
- printf "\nlabels:\n"
- sequence_ [printf "%20s @ 0x%08x\n" l a | (l,a) <- (reverse dict)]
- printf "\nparsed asm:\n"
- sequence_ [printf "%s" (show x) | x <- formatedsrc]
+ if (not $ null args) && ("-d" `elem` args)
+ then do
+ printf "\nlabels:\n"
+ sequence_ [printf "%20s @ 0x%08x\n" l a | (l,a) <- (reverse dict)]
+ printf "\nparsed asm:\n"
+ sequence_ [printf "%s" (show x) | x <- formatedsrc]
+ printf "\nafter parsing the instructions:\n"
+ else do
+ printf ""
+ let base = if "-b" `elem` args then 2 else 16
let parsed = parseInstr dict formatedsrc
- printf "\nafter parsing the instructions:\n"
- sequence_ [printf "%s" (show x) | x <- parsed]
+ sequence_ [printf "%s" (showsDTFBase x base "") | x <- parsed]
parseInstr :: [DictElem] -> [DTF] -> [DTF]
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
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