fixed broken Makefile (sry - forgot to check Makefile), added RegisterAllocation...
[mate.git] / src / BasicBlocks.hs
index 4f8499885ed46b53c0c5977c06bb75c086e9fd55..6bd26e417695043b06a1637e00959c2080530540 100644 (file)
@@ -10,20 +10,37 @@ import JVM.Common
 import JVM.ClassFile
 import JVM.Converter
 import JVM.Dump
+import JVM.Assembler
 
 import Utilities
 
 main = do
   args <- getArgs
   case args of
-    [clspath] -> do
-      clsFile <- decodeFile clspath
-      putStrLn $ showListIx $ M.assocs $ constsPool (clsFile :: Class Pointers)
-      cls <- parseClassFile clspath
-      dumpClass cls    
-      let mainmethod = lookupMethod "main" cls -- "main|([Ljava/lang/String;)V" cf
-      testCFG mainmethod
-      putStrLn "foo"
+    [clspath] -> parseFile clspath
     _ -> error "Synopsis: dump-class File.class"
 
-testCFG _ = undefined
+
+parseFile :: String -> IO ()
+parseFile clspath = do
+                     --clsFile <- decodeFile clspath
+                     --putStrLn $ showListIx $ M.assocs $ constsPool (clsFile :: Class Pointers)
+                     cls <- parseClassFile clspath
+                     --dumpClass cls    
+                     let mainmethod = lookupMethod "fib" cls -- "main|([Ljava/lang/String;)V" cf
+                     putStrLn $ show $ testCFG mainmethod
+
+test = parseFile "./tests/Fib.class"
+
+
+testCFG :: Maybe (Method Resolved) -> String
+testCFG (Just m) = case attrByName m "Code" of
+                     Nothing       -> error "no code"
+                     Just bytecode -> let code = decodeMethod bytecode
+                                          instructions = codeInstructions code
+                                      in show $ buildCFG instructions
+testCFG _        = error "no method to build cfg"
+
+
+buildCFG :: [Instruction] -> String
+buildCFG xs = concatMap show xs