+-----------------------------------------------------------------------------
+
+collectNonProcPointTargets ::
+ UniqSet BlockId -> BlockEnv BrokenBlock
+ -> UniqSet BlockId -> BlockId -> UniqSet BlockId
+collectNonProcPointTargets proc_points blocks current_targets block =
+ if sizeUniqSet current_targets == sizeUniqSet new_targets
+ then current_targets
+ else foldl (collectNonProcPointTargets proc_points blocks) new_targets targets
+ where
+ block' = lookupWithDefaultUFM blocks (panic "TODO") block
+ targets =
+ -- Note the subtlety that since the extra branch after a call
+ -- will always be to a block that is a proc-point,
+ -- this subtraction will always remove that case
+ uniqSetToList $ (mkUniqSet $ brokenBlockTargets block') `minusUniqSet` proc_points
+ -- TODO: remove redundant uniqSetToList
+ new_targets = current_targets `unionUniqSets` (mkUniqSet targets)
+
+procPointToContinuation ::
+ UniqSet BlockId -> BlockEnv BrokenBlock
+ -> BlockId -> Continuation
+procPointToContinuation proc_points blocks start =
+ Continuation is_entry info_table clabel params body
+ where
+ children = (collectNonProcPointTargets proc_points blocks (unitUniqSet start) start) `delOneFromUniqSet` start
+ start_block = lookupWithDefaultUFM blocks (panic "TODO") start
+ children_blocks = map (lookupWithDefaultUFM blocks (panic "TODO")) (uniqSetToList children)
+ body = start_block : children_blocks
+ info_table = [] -- TODO
+ start_block_entry = brokenBlockEntry start_block
+ is_entry = case start_block_entry of
+ FunctionEntry _ _ -> True
+ _ -> False
+ clabel = case start_block_entry of
+ FunctionEntry label _ -> label
+ _ -> mkReturnPtLabel $ getUnique start
+ params = case start_block_entry of
+ FunctionEntry _ args -> args
+ ContinuationEntry args -> args
+ ControlEntry -> [] -- TODO: it's a proc-point, we could pass lives in parameter registers
+