gc: delegated mallocs in GarbageAlloc to hs-boehmgc (Mate.GC.Boehm.mallocBytes);
[mate.git] / Mate / BasicBlocks.hs
index d863f55d36e6833d7a42a80ef7caa623acc08e35..955f4f51191d1eae16ebef98636f75d4a4a58a22 100644 (file)
@@ -19,6 +19,7 @@ import Data.Int
 import Data.List
 import qualified Data.Map as M
 import qualified Data.ByteString.Lazy as B
+import Data.Maybe
 
 import JVM.ClassFile
 import JVM.Converter
@@ -89,27 +90,26 @@ test_04 = testInstance "./tests/Fac.class" "fac"
 
 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 method = fromMaybe
+               (error $ "method " ++ (show . toString) methodname ++ " not found")
+               (lookupMethodSig methodname sig cls)
+  let codeseg = fromMaybe
+                (error $ "codeseg " ++ (show . toString) methodname ++ " not found")
+                (attrByName method "Code")
   let decoded = decodeMethod codeseg
   let mapbb = testCFG decoded
   let locals = fromIntegral (codeMaxLocals decoded)
   let stacks = fromIntegral (codeStackSize decoded)
+  let codelen = fromIntegral (codeLength 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
+  let msig = methodSignature method
   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 ()
+  printMapBB mapbb
 #endif
   -- small example how to get information about
   -- exceptions of a method
@@ -120,7 +120,7 @@ parseMethod cls methodname sig = do
       printfBb "exception: no handler for this method\n"
     Just exceptionstream ->
       printfBb "exception: \"%s\"\n" (show $ codeExceptions $ decodeMethod exceptionstream)
-  return $ RawMethod mapbb locals stacks argscount
+  return $ RawMethod mapbb locals stacks argscount codelen
 
 
 testCFG :: Code -> MapBB