1 -- as for deep thoughts ISA
2 -----------------------------------------------------------------------------
9 import Control.Applicative hiding ((<|>),many)
12 import System.Environment
15 import Text.Parsec.String
16 import Text.Parsec.Combinator
17 import qualified Data.Map as M
20 import qualified Data.ByteString.Lazy as BL
21 -- import Data.Binary.Put
26 content <- getContents
27 let src = (filter (((/=) "") . snd) $ (zip [1..] (lines content)))
28 let (dict,formatedsrc) = convertDTF src 0x00 0x00 init_labels
33 case runParser DT.parseInstructions () "stdin" src of
36 sequence_ [printf "0x%08X\n" x | x <- val]
41 inc :: Counter -> Counter
44 setabsolute :: Counter -> Counter
48 type DictLabel = (String -> Word32)
50 init_labels :: DictLabel
51 init_labels _ = 0xffffffff
53 add_label :: DictLabel -> (String,Word32) -> DictLabel
55 | dic s /= 0xffffffff = error ("Label " ++ s ++ " already exists")
63 convertDTF :: [(Int,String)] -> Counter -> Counter -> DictLabel -> (DictLabel, [DTF])
64 convertDTF [] _ _ d = (d,[])
65 convertDTF ((lno,str):xs) datacnt instrcnt dict =
66 (newdict, (DTF_Comment str):next)
68 (newdict,next) = convertDTF xs (inc datacnt) (inc instrcnt) dict
70 testDTF :: String -> IO ()
72 case (parse parseDTFLine "" (input++"\n")) of
73 Left err -> do { putStr "failz"; print err}
74 Right x -> do { print x }
76 parseDTFLine :: Parser DTF
77 parseDTFLine = foldl1 (<|>) (fmap try lineFormats) <* char '\n'
79 lineFormats = [lf_data, lf_comment, lf_label, lf_toparse, lf_org]
81 lf_data = do string "data"; return $ DTF_Comment "lolz0"
86 comment <- many $ noneOf ['\n']
88 return $ DTF_Comment comment
90 lf_label = do string "label"; return $ DTF_Comment "lolz1"
91 lf_toparse = do string "toparse"; return $ DTF_Comment "lolz2"
92 lf_org = do string "org"; return $ DTF_Comment "lolz3"