MapBB,
printMapBB,
parseMethod,
- test_main
+ test_main,
+ testCFG -- added by hs to perform benches from outside
)where
import Data.Binary
--- /dev/null
+{-# LANGUAGE OverloadedStrings #-}
+module Main where
+
+import Frontend
+import Graph
+import Data.Maybe
+import Control.Monad.State
+import Data.Set as S
+import Control.Monad
+
+import Mate.BasicBlocks
+
+import JVM.ClassFile
+import JVM.Converter
+import JVM.Assembler
+
+import Mate.Utilities
+import qualified Data.ByteString.Lazy as B
+
+printG' :: Ord k => G k -> [k]
+printG' g = evalState (foldGM ((: []), (++)) (\node -> let (Just v) = value node in v) [] g) S.empty
+
+value (Node val _ _) = Just val
+value (Leaf val ) = Just val
+value Nil = Nothing
+
+
+main = do con@(Just (ins,cls)) <- getMethodIO "../tests/AbsurdlyHuge.class" "absurdlyHuge"
+ let perform' = do
+ let method = "absurdlyHuge"
+ let msig = methodSignature $ (classMethods cls) !! 1
+ --B.putStrLn (method `B.append` ": " `B.append` (encode msig))
+ let result = testCFG $ lookupMethod method cls
+ printMapBB result
+ let perform = do
+ 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
+ forM_ [0..100] (\x -> do perform)
+
+
getBranch :: NInst -> [Int]
getBranch (Source s, size, IF_ICMP _ t) = [addW16Signed s t, s+size]
getBranch (Source s, size, GOTO t) = [addW16Signed s t]
+getBranch (Source s, size, IRETURN ) = [0] --actually wrong
getBranch _ = []
-- a version of Prelude.span whereby the first element
-- Generates a cyclic datastructure given edges and nodes
-- TODO: remove lists with maps in inputs
-toG :: (Ord k) => ([r] -> a -> r) -> [(k,[k])] -> k -> [(k, a)] -> Maybe r
+toG :: (Ord k,Show k) => ([r] -> a -> r) -> [(k,[k])] -> k -> [(k, a)] -> Maybe r
toG g xs start pls = let nodeTable = M.fromList pls
payload s = case M.lookup s nodeTable of
Just x -> x
node f p t = case M.lookup t conn of
(Just x) -> x
- Nothing -> error "illformed edge/node list in toG"
+ Nothing
+ -> error $ "illformed edge/node list in toG" ++ (show t)
in M.lookup start conn
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
--- /dev/null
+public class AbsurdlyHuge
+{
+public static int absurdlyHuge(int x)
+{
+for(int i=0;i<x;i++)
+{
+for(int u=0;u<x;u++)
+{
+for(int k=0;k<x;k++)
+{
+for(int v=0;v<x;v++)
+{
+for(int w=0;w<x;w++)
+{
+for(int z=0;z<x;z++)
+{
+for(int g=0;w<x;w++)
+{
+if(i+u+k+v+w+z<x)
+{
+return absurdlyHuge(k+v);
+}
+else
+{
+return absurdlyHuge(w+z);
+}
+}
+}
+}
+}
+}
+}
+}
+return 0;
+}
+
+ public static void main(String[] args)
+ {
+ absurdlyHuge(1);
+ }
+}