moved lookupMethod into separate Utilities file. added BasicBlocks playground
authorHarald Steinlechner <haraldsteinlechner@gmail.com>
Tue, 27 Mar 2012 19:06:56 +0000 (21:06 +0200)
committerHarald Steinlechner <haraldsteinlechner@gmail.com>
Tue, 27 Mar 2012 19:06:56 +0000 (21:06 +0200)
BasicBlocks.hs [new file with mode: 0644]
Utilities.hs [new file with mode: 0644]

diff --git a/BasicBlocks.hs b/BasicBlocks.hs
new file mode 100644 (file)
index 0000000..4f84998
--- /dev/null
@@ -0,0 +1,29 @@
+{-# LANGUAGE OverloadedStrings #-}
+module BasicBlocks where
+
+import Data.Binary
+import System.Environment
+import qualified Data.Map as M
+import qualified Data.ByteString.Lazy as B
+
+import JVM.Common
+import JVM.ClassFile
+import JVM.Converter
+import JVM.Dump
+
+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"
+    _ -> error "Synopsis: dump-class File.class"
+
+testCFG _ = undefined
diff --git a/Utilities.hs b/Utilities.hs
new file mode 100644 (file)
index 0000000..540d054
--- /dev/null
@@ -0,0 +1,18 @@
+module Utilities where
+
+import qualified Data.ByteString.Lazy as B
+
+import qualified JVM.Assembler as J
+import JVM.Assembler hiding (Instruction)
+import JVM.Common
+import JVM.ClassFile
+
+
+-- TODO: actually this function already exists in hs-java-0.3!
+lookupMethod :: B.ByteString -> Class Resolved -> Maybe (Method Resolved)
+lookupMethod name cls = look (classMethods cls)
+  where
+    look [] = Nothing
+    look (f:fs)
+      | methodName f == name = Just f
+      | otherwise  = look fs