ram: reducing instr- and dataram
[calu.git] / 3a_asm / DT.hs
index e065c71c16129d5ee2f66d3ed92f023492ce5486..c80186ca399447d171e1eae70e7f17f99427f9ee 100644 (file)
@@ -17,12 +17,12 @@ import Control.Applicative hiding ((<|>))
 
 
 -- parsing --
-instruction :: Dict -> Parser Word32
-instruction dict = foldl1 (<|>) (fmap (\x -> try (x dict)) instructions) <* char '\n'
+instruction :: LineNo -> Dict -> Parser Word32
+instruction lno dict = foldl1 (<|>) (fmap (\x -> try (x dict)) instructions) <* char '\n' <?> (". something at line " ++ show lno ++ " is wrong (ignore line 1 hint above, but pay attention for possible line offset due to #include).")
 
 testins :: String -> IO ()
 testins input =
-       case (parse (instruction dict) "" (input++"\n")) of
+       case (parse (instruction dict) "" (input++"\n")) of
                Left err -> do { putStr "fail :/\n"; print err}
                Right x -> do { printf "0x%08X\n" x }
        where
@@ -38,6 +38,7 @@ iLabel d@(aktadr,_) = do {i <- (iLit d); return $ ((i - aktadr)`div`4) .&. 0xfff
 
 iLit :: Dict -> Parser Word32
 iLit (_,d) = do
+       parseMySpaces
        val <- expr d;
        try (do {
                string "@hi"; parseMySpaces;
@@ -111,6 +112,7 @@ ins m form e  = do {mnem m; form e}
 csv0i_p dict f = f<$>condition<*>branchpred<*>(iLabel dict)
 csv0i_p' f = f<$>condition<*>branchpred
 csv1 f = f<$>condition<%>reg
+csv1' f = f<$>condition
 csv1_p f = f<$>condition<%>reg
 csv2 f = f<$>condition<%>reg<.>reg
 csv2i dict f = f<$>condition<%>reg<.>(iLit16 dict)
@@ -157,7 +159,7 @@ lrs dict = ins "lrs" (csv2i_cd dict) $ shiform 0x0a 1 0
 ars dict = ins "ars" (csv2i_d dict) $ shiform 0x0a 1 1 0
 -- memory
 pop _ = ins "pop" csv1 $ sform 0x0b 0x0
-disc _ = ins "disc" csv1 $ sform 0x0b 0x1
+disc _ = ins "disc" csv1' $ sform' 0x0b 0x1 0
 fetch _ = ins "fetch" csv1 $ sform 0x0b 0x2
 push _ = ins "push" csv1 $ sform 0x0b 0x3
 movpf _ = ins "movpf" csv1 $ sform 0x0c 0x2
@@ -204,6 +206,7 @@ bform opcd typ s cond bp imm = pack [(cond,28),(opcd,23),(imm,7),(free,4),(typ,2
 bform' opcd typ cond bp = bform opcd typ 0 cond bp 0
 
 sform opcd typ cond rd = pack [(cond,28),(opcd,23),(rd,19),(typ,17)]
+sform' opcd typ rd cond = sform opcd typ cond rd
 
 brrform opcd typ cond ra = pack [(cond,28),(opcd,23),(ra,19),(typ,2)]