projects
/
calu.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
3a_asm: .define support
[calu.git]
/
3a_asm
/
DTFormat.hs
diff --git
a/3a_asm/DTFormat.hs
b/3a_asm/DTFormat.hs
index 8c3d495655cce50852446804b29f849d00f13285..3e607fdec50803ccd2ad8f7758e044d798ac9af1 100644
(file)
--- a/
3a_asm/DTFormat.hs
+++ b/
3a_asm/DTFormat.hs
@@
-25,6
+25,7
@@
data DTF =
DTF_InstrToParse Address ValueToParse Code Label Comment |
DTF_SectionToDet Address Value Code Label Comment |
DTF_Org Address |
DTF_InstrToParse Address ValueToParse Code Label Comment |
DTF_SectionToDet Address Value Code Label Comment |
DTF_Org Address |
+ DTF_Define Label Value Comment |
DTF_State DT_State
instance Show (DTF) where
DTF_State DT_State
instance Show (DTF) where
@@
-38,24
+39,29
@@
showsDTF (DTF_Label l c _) = (++) (printf "3;%s;%s\n" l c)
showsDTF (DTF_InstrToParse a v c l s) = (++) (printf "itp;%08x;%s;%s;%s;%s\n" a v c l s)
showsDTF (DTF_SectionToDet a v c l s) = (++) (datins "std" a v c l s)
showsDTF (DTF_Org a) = (++) (printf "org;%08x\n" a)
showsDTF (DTF_InstrToParse a v c l s) = (++) (printf "itp;%08x;%s;%s;%s;%s\n" a v c l s)
showsDTF (DTF_SectionToDet a v c l s) = (++) (datins "std" a v c l s)
showsDTF (DTF_Org a) = (++) (printf "org;%08x\n" a)
+showsDTF (DTF_Define l a c) = (++) (printf "def;%s;%08X;%s\n" l a c)
showsDTF (DTF_State s) = (++) (printf "sta;%s\n" (show s))
datins :: String -> Address -> Value -> Code -> Label -> Comment -> String
datins = printf "%s;%08x;%08x;%s;%s;%s\n"
showsDTF (DTF_State s) = (++) (printf "sta;%s\n" (show s))
datins :: String -> Address -> Value -> Code -> Label -> Comment -> String
datins = printf "%s;%08x;%08x;%s;%s;%s\n"
-type DictLabel = (String,Word32)
+-- datastructure for managing labels and defines
+type Dict = (Address,[DictElem])
+type DictElem = (String,Word32)
-get_label :: String -> [DictLabel] -> Maybe Word32
-get_label = lookup
+get_elem :: String -> [DictElem] -> Word32
+get_elem s dict = case (lookup s dict) of
+ Nothing -> error ("unknown label or define: \"" ++ s ++ "\"")
+ Just z -> z
-add_
label :: [DictLabel] -> (String,Word32) -> [DictLabel
]
-add_
label
dic (s,w)
+add_
elem :: [DictElem] -> (String,Word32) -> [DictElem
]
+add_
elem
dic (s,w)
| s == "" = dic -- ignore empty string
| s == "" = dic -- ignore empty string
- | already_in = error ("Label
" ++ s ++
" already exists")
+ | already_in = error ("Label
or define \"" ++ s ++ "\
" already exists")
| otherwise = (s,w):dic
where
| otherwise = (s,w):dic
where
- already_in = case (
get_label
s dic) of
+ already_in = case (
lookup
s dic) of
Just _ -> True
Nothing -> False
Just _ -> True
Nothing -> False