-
-
-parseMethod :: Class Resolved -> B.ByteString -> IO (Maybe MapBB)
-parseMethod cls method = do
- putStr "BB: analysing: "
- let msig = methodSignature $ (classMethods cls) !! 1
- B.putStrLn (method `B.append` ": " `B.append` (encode msig))
- return $ testCFG $ lookupMethod method cls
-
-
-testCFG :: Maybe (Method Resolved) -> Maybe MapBB
-testCFG (Just m) = case attrByName m "Code" of
- Nothing -> Nothing
- Just bytecode -> Just $ buildCFG $ codeInstructions $ decodeMethod bytecode
-testCFG _ = Nothing
-
+#endif
+#endif
+
+
+parseMethod :: Class Direct -> B.ByteString -> MethodSignature -> IO RawMethod
+parseMethod cls methodname sig = do
+ let method = case lookupMethodSig methodname sig cls of
+ Just m -> m
+ Nothing -> error $ "method " ++ (show . toString) methodname ++ " not found"
+ let codeseg = case attrByName method "Code" of
+ Just m -> m
+ Nothing -> error $ "codeseg " ++ (show . toString) methodname ++ " not found"
+ let decoded = decodeMethod codeseg
+ let mapbb = testCFG decoded
+ let locals = fromIntegral (codeMaxLocals decoded)
+ let stacks = fromIntegral (codeStackSize decoded)
+ let methoddirect = methodInfoToMethod (MethodInfo methodname "" sig) cls
+ let isStatic = methodIsStatic methoddirect
+ let nametype = methodNameType methoddirect
+ let argscount = methodGetArgsCount nametype + (if isStatic then 0 else 1)
+
+ let msig = methodSignature $ classMethods cls !! 1
+ printfBb "BB: analysing \"%s\"\n" $ toString (methodname `B.append` ": " `B.append` encode msig)
+#ifdef DBG_BB
+ case maybe_bb of
+ Just m -> printMapBB $ rawMapBB m
+ Nothing -> return ()
+#endif
+ -- small example how to get information about
+ -- exceptions of a method
+ -- TODO: remove ;-)
+ let (Just m) = lookupMethodSig methodname sig cls
+ case attrByName m "Code" of
+ Nothing ->
+ printfBb "exception: no handler for this method\n"
+ Just exceptionstream ->
+ printfBb "exception: \"%s\"\n" (show $ codeExceptions $ decodeMethod exceptionstream)
+ return $ RawMethod mapbb locals stacks argscount
+
+
+testCFG :: Code -> MapBB
+testCFG = buildCFG . codeInstructions