basicblock: change order of `TwoTarget'
[mate.git] / Mate / BasicBlocks.hs
index e80d388c05f17e977687d0888b89c22a893c9dc9..25a418e4b64077fb55e19ec03d9ea043c1e7ce21 100644 (file)
@@ -102,7 +102,7 @@ buildCFG xs = buildCFG' H.empty xs' xs'
 
 buildCFG' :: MapBB -> [OffIns] -> [OffIns] -> MapBB
 buildCFG' hmap [] _ = hmap
-buildCFG' hmap (((off, Just entry), _):xs) insns = buildCFG' (insertlist entryi hmap) xs insns
+buildCFG' hmap (((off, entry), _):xs) insns = buildCFG' (insertlist entryi hmap) xs insns
   where
   insertlist :: [BlockID] -> MapBB -> MapBB
   insertlist [] hmap = hmap
@@ -114,11 +114,10 @@ buildCFG' hmap (((off, Just entry), _):xs) insns = buildCFG' (insertlist entryi
   entryi :: [BlockID]
   entryi = (if off == 0 then [0] else []) ++ -- also consider the entrypoint
         case entry of
-        TwoTarget t1 t2 -> [t1, t2]
-        OneTarget t -> [t]
-        Return -> []
-
-buildCFG' hmap (((_, Nothing), _):xs) insns = buildCFG' hmap xs insns
+        Just (TwoTarget t1 t2) -> [t1, t2]
+        Just (OneTarget t) -> [t]
+        Just (Return) -> []
+        Nothing -> []
 
 
 parseBasicBlock :: Int -> [OffIns] -> BasicBlock
@@ -161,5 +160,5 @@ calculateInstructionOffset = cio' (0, Nothing)
     where
     notarget = ((off, Just Return), x):next
     onetarget w16 = ((off, Just $ OneTarget $ (off `addW16Signed` w16)), x):next
-    twotargets w16 = ((off, Just $ TwoTarget (off `addW16Signed` w16) (off + 3)), x):next
+    twotargets w16 = ((off, Just $ TwoTarget (off + 3) (off `addW16Signed` w16)), x):next
     next = cio' (newoffset x off) xs