Cleanup: remove unused imports.
[hs-java.git] / disassemble.hs
index a11a2ad5ef29046b199856757c9da16993572154..bb6512f6ad3a7a80b214720e9613019d6429a44c 100644 (file)
@@ -1,7 +1,11 @@
 {-# LANGUAGE OverloadedStrings #-}
+module Main where
+
 import Control.Monad
+import Data.Array
 import System.Environment
 import qualified Data.ByteString.Lazy as B
+import Text.Printf
 
 import Data.BinaryState
 import JVM.Types
@@ -15,13 +19,19 @@ main = do
       cls <- decompileFile clspath
       putStr "Class: "
       B.putStrLn (this cls)
+      putStrLn "Constants pool:"
+      forM_ (assocs $ constantPool cls) $ \(i, c) ->
+        putStrLn $ printf "  #%d:\t%s" i (show c)
       putStrLn "Methods:"
       forM_ (methods cls) $ \m -> do
         putStr ">> Method "
-        B.putStrLn (methodName m)
+        B.putStr (methodName m)
+        print (methodSignature m)
         case attrByName m "Code" of
           Nothing -> putStrLn "(no code)\n"
-          Just bytecode -> let (Code code) = decodeS (0 :: Integer) bytecode
-                           in  forM_ code print
+          Just bytecode -> let code = decodeS (0 :: Integer) bytecode
+                           in  forM_ (codeInstructions code) $ \i -> do
+                                 putStr "  "
+                                 print i
 
     _ -> error "Synopsis: disassemble File.class"