-- as for deep thoughts ISA
-----------------------------------------------------------------------------
-module Main where
import DT
import DTFormat
sequence_ [printf "%10s @ 0x%08x\n" l a | (l,a) <- (reverse dict)]
printf "\nparsed asm:\n"
sequence_ [printf "%s" (show x) | x <- formatedsrc]
+ let parsed = parseInstr dict formatedsrc
+ printf "\nafter parsing the instructions:\n"
+ sequence_ [printf "%s" (show x) | x <- parsed]
+
+
+parseInstr :: [DictLabel] -> [DTF] -> [DTF]
+parseInstr _ [] = []
+parseInstr dict ((DTF_InstrToParse a instr c l s):xs) =
+ (DTF_Instr a bytecode c l s):(parseInstr dict xs)
+ where
+ bytecode = case (parse (instruction dict) "" (instr++"\n")) of
+ Left err -> error ("couldn't parse Instruction: " ++ instr ++ "\n" ++ show err)
+ Right x -> x
+parseInstr dict (x:xs) = x:(parseInstr dict xs)
type Counter = Word32
inc = ((+) 4)
-type DictLabel = (String,Word32)
-
-get_label :: String -> [DictLabel] -> Maybe Word32
-get_label = lookup
-
-add_label :: [DictLabel] -> (String,Word32) -> [DictLabel]
-add_label dic (s,w)
- | s == "" = dic -- ignore empty string
- | already_in = error ("Label " ++ s ++ " already exists")
- | otherwise = (s,w):dic
- where
- already_in = case (get_label s dic) of
- Just _ -> True
- Nothing -> False
-
-
convertDTF :: [(Int,String)] -> DT_State -> Counter -> Counter -> [DictLabel] -> ([DictLabel], [DTF])
convertDTF [] _ _ _ d = (d,[])
convertDTF ((lno,str):xs) state datacnt instrcnt dict = (newdict, (actlist newdtf))
let val = read str
return $ val
-parseMySpaces :: Parser String
-parseMySpaces = do
- ret <- many $ oneOf "\t "
- return $ ret
-
-- teh pars0rs
lf_data = do
l <- try (parseLabel) <|> string ""
string ".text"
parseMySpaces
return $ DTF_State InText
+