3a_asm: changed data structure again to calculate relative addresses
[calu.git] / 3a_asm / DTFormat.hs
index 8c3d495655cce50852446804b29f849d00f13285..139367018da8ce0ca23e5f2f80361bb4310085c6 100644 (file)
@@ -44,18 +44,22 @@ 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
-       | already_in =  error ("Label " ++ s ++ " already exists")
+       | already_in =  error ("Label or define \"" ++ s ++ "\" already exists")
        | otherwise = (s,w):dic
        where
-       already_in = case (get_label s dic) of
+       already_in = case (lookup s dic) of
                Just _ -> True
                Nothing -> False