- (offins, targets) = runState (calculateInstructionOffset tryBlocks xs) S.empty
- alltargets = S.toList $ S.insert 0 targets
- tryBlocks = map (fromIntegral . eStartPC) excps
- handlerEntries = map (fromIntegral . eHandlerPC) excps
-
-buildCFG' :: [OffIns] -> Int -> State MapBB ()
-buildCFG' insns off = do
- let value = parseBasicBlock off insns
- modify (M.insert off value)
+ buildCFG :: [Instruction] -> [CodeException] -> MapBB
+ buildCFG xs excps = execState (mapM buildCFG' $ alltargets ++ handlerEntries) M.empty
+ where
+ (offins, targets) = runState (calculateInstructionOffset tryBlocks xs) S.empty
+ alltargets = S.toList $ S.insert 0 targets
+ tryBlocks = map (fromIntegral . eStartPC) excps
+ handlerEntries = map (fromIntegral . eHandlerPC) excps
+
+ exceptionMap :: M.Map (Word16, Word16) [(B.ByteString, Word16)]
+ exceptionMap = foldl f M.empty excps
+ where
+ f emap ce =
+ if M.member key emap
+ then M.adjust (value:) key emap
+ else M.insert key [value] emap
+ where
+ key = (&&&) eStartPC eEndPC ce
+ value = (&&&) (buildClassID cls . eCatchType) eHandlerPC ce
+
+ buildCFG' :: Int -> State MapBB ()
+ buildCFG' off = do
+ let value = parseBasicBlock off offins
+ modify (M.insert off value)