X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=3a_asm%2FMain.hs;h=2515674cf1444255fe6604d116ff55cc0ea7aa09;hb=6eca79af925f3c735fcab6879d4e52c0bfd06fb0;hp=df442a41d523869416f7db400302bf85c058ee19;hpb=78b5a79f05914f46808af252ba30a6a81ea2c5dd;p=calu.git diff --git a/3a_asm/Main.hs b/3a_asm/Main.hs index df442a4..2515674 100644 --- a/3a_asm/Main.hs +++ b/3a_asm/Main.hs @@ -1,7 +1,6 @@ -- as for deep thoughts ISA ----------------------------------------------------------------------------- -module Main where import DT import DTFormat @@ -31,6 +30,20 @@ main = do 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 @@ -39,22 +52,6 @@ inc :: Counter -> Counter 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)) @@ -145,11 +142,6 @@ parseConst = do 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 "" @@ -196,3 +188,4 @@ lf_stext = do string ".text" parseMySpaces return $ DTF_State InText +