3a_asm: first attempt for a proper datastructe for our new dataformat
[calu.git] / 3a_asm / DTFormat.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"
+