- replace_eid (G.LGraph eid blocks) = G.LGraph (lookup eid) blocks
- middle = mapExpDeepMiddle exp
- last l = if lpred l then mapExpDeepLast exp (last' l) else l
- last' (LastBranch bid) = LastBranch (lookup bid)
- last' (LastCondBranch p t f) = LastCondBranch p (lookup t) (lookup f)
- last' (LastSwitch e arms) = LastSwitch e (map (liftM lookup) arms)
- last' (LastCall t k a res r) = LastCall t (liftM lookup k) a res r
- exp (CmmLit (CmmBlock bid)) = CmmLit (CmmBlock (lookup bid))
- exp (CmmStackSlot (CallArea (Young id)) i) =
- CmmStackSlot (CallArea (Young (lookup id))) i
- exp e = e
- lookup id = fmap lookup (lookupBlockEnv env id) `orElse` id
-
-replaceLabelsZ :: BlockEnv BlockId -> CmmGraph -> CmmGraph
-replaceLabelsZ = maybeReplaceLabels (const True)
-
--- replaceBranchLabels :: BlockEnv BlockId -> CmmGraph -> CmmGraph
--- replaceBranchLabels env g@(LGraph _ _) = maybeReplaceLabels lpred env g
--- where lpred (LastBranch _) = True
--- lpred _ = False
+ replace_eid g = g {g_entry = lookup (g_entry g)}
+ lookup id = fmap lookup (mapLookup id env) `orElse` id
+
+ middle = mapExpDeep exp
+ last l = if lpred l then mapExpDeep exp (last' l) else l
+ last' :: CmmNode O C -> CmmNode O C
+ last' (CmmBranch bid) = CmmBranch (lookup bid)
+ last' (CmmCondBranch p t f) = CmmCondBranch p (lookup t) (lookup f)
+ last' (CmmSwitch e arms) = CmmSwitch e (map (liftM lookup) arms)
+ last' (CmmCall t k a res r) = CmmCall t (liftM lookup k) a res r
+ last' (CmmForeignCall t r a bid u i) = CmmForeignCall t r a (lookup bid) u i
+
+ exp (CmmLit (CmmBlock bid)) = CmmLit (CmmBlock (lookup bid))
+ exp (CmmStackSlot (CallArea (Young id)) i) = CmmStackSlot (CallArea (Young (lookup id))) i
+ exp e = e
+
+
+replaceLabels :: BlockEnv BlockId -> CmmGraph -> CmmGraph
+replaceLabels = maybeReplaceLabels (const True)