fixed broken Makefile (sry - forgot to check Makefile), added RegisterAllocation...
[mate.git] / src / BasicBlocks.hs
1 {-# LANGUAGE OverloadedStrings #-}
2 module BasicBlocks where
3
4 import Data.Binary
5 import System.Environment
6 import qualified Data.Map as M
7 import qualified Data.ByteString.Lazy as B
8
9 import JVM.Common
10 import JVM.ClassFile
11 import JVM.Converter
12 import JVM.Dump
13 import JVM.Assembler
14
15 import Utilities
16
17 main = do
18   args <- getArgs
19   case args of
20     [clspath] -> parseFile clspath
21     _ -> error "Synopsis: dump-class File.class"
22
23
24 parseFile :: String -> IO ()
25 parseFile clspath = do
26                      --clsFile <- decodeFile clspath
27                      --putStrLn $ showListIx $ M.assocs $ constsPool (clsFile :: Class Pointers)
28                      cls <- parseClassFile clspath
29                      --dumpClass cls    
30                      let mainmethod = lookupMethod "fib" cls -- "main|([Ljava/lang/String;)V" cf
31                      putStrLn $ show $ testCFG mainmethod
32
33 test = parseFile "./tests/Fib.class"
34
35
36 testCFG :: Maybe (Method Resolved) -> String
37 testCFG (Just m) = case attrByName m "Code" of
38                      Nothing       -> error "no code"
39                      Just bytecode -> let code = decodeMethod bytecode
40                                           instructions = codeInstructions code
41                                       in show $ buildCFG instructions
42 testCFG _        = error "no method to build cfg"
43
44
45 buildCFG :: [Instruction] -> String
46 buildCFG xs = concatMap show xs