+{-# LANGUAGE ScopedTypeVariables #-}
+{-# LANGUAGE NoMonomorphismRestriction #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
module ScratchHS where
import Data.Maybe
+import Control.Monad.State
-import Harpy
-import Harpy.X86Disassembler
+import Harpy hiding(fst,add)
+import qualified Harpy.X86Disassembler as H
+import qualified Data.ByteString.Lazy as B
+import qualified Data.Set as S
+import qualified Data.Heap as H
import Foreign
-import Control.Monad
+
+import Debug.Trace
+import Data.Int
import JVM.ClassFile
import JVM.Converter
import JVM.Dump
-import qualified JVM.Assembler as JAsm
+import JVM.Assembler
import Mate.Utilities
import Mate.BasicBlocks
+import Frontend
+import Graph
+
$(callDecl "callAsWord32" [t|Word32|])
data SimpleStack = PushLit Int
-run :: [RegIL] -> Ptr Int32 -> IO (MateState, Either ErrMsg [Instruction])
+run :: [RegIL] -> Ptr Int32 -> IO (MateState, Either ErrMsg [H.Instruction])
run program env = let compileAndFeedback = mapM_ compileRegIL program >> disassemble
in runCodeGen compileAndFeedback env (MateState "none")
testEnv p' = do
ptr <- emptyMemory 26
(_, Right code) <- run p' ptr
- return $ map showIntel code
+ return $ map H.showIntel code
simpleTest :: [RegIL]
return (cls, lookupMethod methodName cls)
-getFib = do (cls, Just m) <- loadMethod "ackermann" "../tests/Ackermann.class"
+getFib = do (cls, Just m) <- loadMethod "fac" "../tests/Fac.class"
return (cls, m)
fibBasicBlocks = do (cls,m) <- getFib
- hmap <- parseMethod cls "ackermann"
+ hmap <- parseMethod cls "facFor"
printMapBB hmap
return ()
+
+
+fib = do con@(Just (ins,cls)) <- getMethodIO "../tests/Fac.class" "facFor"
+ let offsets = getInstOffsets ins
+ let taggedInst = zip3 (map Source $ sumSeries'' offsets) offsets ins
+ mapM_ print taggedInst
+ let continuations = execState (findContinuations taggedInst) ([],H.empty)
+ print continuations
+ let cfg = buildCFGContext con
+ print cfg
+ return cfg
+
+fib' = do con@(Just (ins,cls)) <- getMethodIO "../tests/Fac.class" "facFor"
+ let tagged = getInstructions ins
+ print tagged
+ let backRefs = splitBlocksBackRef tagged
+ let splitted = splitBlocks backRefs tagged
+ print splitted
+ let transitions = getTransitions splitted
+ let nodes = getNodes splitted
+ print "nodes:"
+ print nodes
+ print "transitions"
+ print transitions
+ let (Just finalCyclicStructure) = indirectCFGToG splitted
+ print "Final result"
+ print $ printG' finalCyclicStructure
+
+main = do con@(Just (ins,cls)) <- getMethodIO "../tests/AbsurdlyHuge.class" "absurdlyHuge"
+ let tagged = getInstructions ins
+ let backRefs = splitBlocksBackRef tagged
+ let splitted = splitBlocks backRefs tagged
+ let transitions = getTransitions splitted
+ let nodes = getNodes splitted
+ print "nodes:"
+ print nodes
+ print "transitions"
+ print transitions
+ let (Just finalCyclicStructure) = indirectCFGToG splitted
+ print "Final result"
+ print $ printG' finalCyclicStructure
+
+
+
+
+diamant :: G String
+diamant = let start = Node "a" left right
+ left = Node "l" end Nil
+ right = Node "r" end Nil
+ end = Node "g" start Nil
+ in start
+
+dag = Node "a" (Node "b" (Leaf "c") (Leaf "d")) (Node "b" (Leaf "c") (Leaf "d"))
+
+
+value (Node val _ _) = Just val
+value (Leaf val ) = Just val
+value Nil = Nothing
+
+
+printG' :: Ord k => G k -> [k]
+printG' g = evalState (foldGM ((: []), (++)) (\node -> let (Just v) = value node in v) [] g) S.empty