1 {-# LANGUAGE OverloadedStrings #-}
2 module BasicBlocks where
5 import System.Environment
6 import qualified Data.Map as M
7 import qualified Data.ByteString.Lazy as B
20 [clspath] -> parseFile clspath
21 _ -> error "Synopsis: dump-class File.class"
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
30 let mainmethod = lookupMethod "fib" cls -- "main|([Ljava/lang/String;)V" cf
31 putStrLn $ show $ testCFG mainmethod
33 test = parseFile "./tests/Fib.class"
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"
45 buildCFG :: [Instruction] -> String
46 buildCFG xs = concatMap show xs