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
--- /dev/null
+import Data.List
+import Data.Maybe
+
+
+type Label a = a
+type IEdge a = (Label a, Label a)
+data IGraph a = IGraph [IEdge a] deriving (Show)
+
+-- TODO: make IEdge eq
+
+--data IArchitecture = Arch { regs :: Integer }
+type IArchitecture = Int --number of regs
+
+
+type Assignment a = (a, Int)
+
+
+edgeEq (from,to) (from',to') = from == from' && to == to'
+
+
+-- TODO: find combinator do match try semantics here
+-- Solution: use list because list is MonadPlus instance
+-- other solution add maybe monadplus implementation
+conflicts (IGraph xs) (label,anotherLabel) = let comparison = edgeEq (label,anotherLabel)
+ comparison' = edgeEq (anotherLabel,label)
+ in isJust (find comparison xs) || isJust (find comparison' xs)
+
+
+isParticipiant label (from,to) = from == label || to == label
+
+count p = length . filter p
+
+degree g@(IGraph xs) label = count (isParticipiant label) xs
+
+
+doChaitin81 :: (Eq a) => IArchitecture -> (IGraph a) -> [Assignment a]
+doChaitin81 numberOfRegisters graph = []
+
+type IState a = ([a],IGraph a)
+
+--chait81Simplification :: (Eq a) => IArchitecture -> SimplState
+--chait81Simplification regs = do (
+
+testGraph = IGraph [("a", "b"), ("a","c"), ("c", "b"), ("b","d"), ("d","c"),("b","e"),("d","e")]
+
+