3a_asm: parse even more :>
[calu.git] / 3a_asm / DTFormat.hs
1 module DTFormat where
2
3 import Data.Word
4 import Text.Printf
5
6 data DT_State = NoState | InData | InText deriving (Show,Eq)
7
8 type Address = Word32
9 type Value = Word32
10 type ValueToParse = String
11 type Code = String
12 type Label = String
13 type Comment = String
14
15 data DTF =
16         DTF_Data Address Value Code Label Comment |
17         DTF_Instr Address Value Code Label Comment |
18         DTF_Comment Comment |
19         DTF_Label Label Comment Address |
20         -- types for intern processing
21         DTF_InstrToParse Address ValueToParse Code Label Comment |
22         DTF_SectionToDet Address Value Code Label Comment |
23         DTF_Org Address |
24         DTF_State DT_State
25
26 instance Show (DTF) where
27         showsPrec n = showsDTF
28
29 showsDTF :: DTF -> ShowS
30 showsDTF (DTF_Data a v c l s) = (++) (datins "0" a v c l s)
31 showsDTF (DTF_Instr a v c l s) = (++) (datins "1" a v c l s)
32 showsDTF (DTF_Comment c) = (++) (printf "2;%s\n" c)
33 showsDTF (DTF_Label l c _) = (++) (printf "3;%s;%s\n" l c)
34 showsDTF (DTF_InstrToParse a v c l s) = (++) (printf "itp;%08x;%s;%s;%s;%s\n" a v c l s)
35 showsDTF (DTF_SectionToDet a v c l s) = (++) (datins "std" a v c l s)
36 showsDTF (DTF_Org a) = (++) (printf "org;%08x\n" a)
37 showsDTF (DTF_State s) = (++) (printf "sta;%s\n" (show s))
38
39 datins :: String -> Address -> Value -> Code -> Label -> Comment -> String
40 datins = printf "%s;%08x;%08x;%s;%s;%s\n"
41