3a_asm: first attempt for a proper datastructe for our new dataformat
authorBernhard Urban <lewurm@gmail.com>
Sat, 30 Oct 2010 22:30:07 +0000 (00:30 +0200)
committerBernhard Urban <lewurm@gmail.com>
Sat, 30 Oct 2010 22:30:07 +0000 (00:30 +0200)
3a_asm/DTFormat.hs [new file with mode: 0644]
3a_asm/Main.hs

diff --git a/3a_asm/DTFormat.hs b/3a_asm/DTFormat.hs
new file mode 100644 (file)
index 0000000..819e083
--- /dev/null
@@ -0,0 +1,33 @@
+module DTFormat where
+
+import Data.Word
+import Text.Printf
+
+type Address = Word32
+type Value = Word32
+type ValueToParse = String
+type Code = String
+type Label = String
+type Comment = String
+
+data DTF =
+       DTF_Data Address Value Code Label Comment |
+       DTF_Instr Address Value Code Label Comment |
+       DTF_Comment Comment |
+       DTF_Label Label |
+       DTF_ToParse Address ValueToParse Code Label Comment
+
+instance Show (DTF) where
+       showsPrec n = showsDTF
+
+showsDTF :: DTF -> ShowS
+showsDTF (DTF_Data a v c l s) = (++) (datins "0" a v c l s)
+showsDTF (DTF_Instr a v c l s) = (++) (datins "1" a v c l s)
+showsDTF (DTF_Comment c) = (++) (printf "2;%s\n" c)
+showsDTF (DTF_Label l) = (++) (printf "3;%s\n" l)
+showsDTF (DTF_ToParse a v c l s) = (++) (printf "lulz\n")
+
+
+datins :: String -> Address -> Value -> Code -> Label -> Comment -> String
+datins = printf "%s;%08x;%08x;%s;%s;%s\n"
+
index 25b46bb46e8430ba6c2dd5ae83ebba4fd74dcbb3..d83e022b94bd9c64c20a3cdae7562dace8caa3a6 100644 (file)
@@ -4,6 +4,7 @@
 module Main where
 
 import DT
+import DTFormat
 
 import Control.Applicative hiding ((<|>),many)
 
@@ -12,6 +13,7 @@ import System.Environment
 import Text.Printf
 import Text.Parsec
 import Text.Parsec.String
+import Text.Parsec.Combinator
 import qualified Data.Map as M
 import Data.List
 import qualified Data.ByteString.Lazy as BL
@@ -20,11 +22,21 @@ import qualified Data.ByteString.Lazy as BL
 main :: IO ()
 main = do
        args <- getArgs
-       src <- getContents
+       content <- getContents
+       let src = convertDTF (filter ((/=) "") $ lines content)
        print args
+       print src
+
+{-
        case runParser DT.parseInstructions () "stdin" src of
                Left err -> print err
                Right val -> do
-                       -- TODO: nicht nur das erste element :/
                        sequence_ [printf "0x%08X\n" x | x <- val]
-                       -- mapM (printf "0x%08X\n") val
+-}
+
+--                           data    instr
+-- convertDTF :: [String] -> Dict -> Dict -> ([DTF],Labels)
+
+convertDTF :: [String] -> [DTF]
+convertDTF [] = []
+convertDTF (str:xs) = (DTF_Comment str):(convertDTF xs)