X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=rebuild-class.hs;h=4afb954b25cd78dcde77a08daeed2f7c87ec423c;hb=786dff755133ccc2e44445d9c47baa62010e87e4;hp=abe19187fcb99a120f83b44a994bcb3c0502f64e;hpb=8876aca404b4c111461b7582bb772d219babd3aa;p=hs-java.git diff --git a/rebuild-class.hs b/rebuild-class.hs index abe1918..4afb954 100644 --- a/rebuild-class.hs +++ b/rebuild-class.hs @@ -1,42 +1,25 @@ {-# LANGUAGE OverloadedStrings #-} -import Control.Monad -import Data.Array import Data.Binary import System.Environment import qualified Data.ByteString.Lazy as B -import Text.Printf +import qualified Data.Map as M -import JVM.Types +import JVM.Common import JVM.ClassFile import JVM.Converter -import JVM.Assembler +import JVM.Dump main = do args <- getArgs case args of [clspath,outpath] -> do cls <- parseClassFile clspath - clsfile <- decodeFile clspath :: IO ClassFile - 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.putStr (methodName m) - print (methodSignature m) - case attrByName m "Code" of - Nothing -> putStrLn "(no code)\n" - Just bytecode -> let code = decodeMethod bytecode - in forM_ (codeInstructions code) $ \i -> do - putStr " " - print i - putStrLn $ "Source pool:\n" ++ showListIx (constsPool clsfile) - let result = classFile cls - putStrLn $ "Result pool:\n" ++ showListIx (constsPool result) + clsfile <- decodeFile clspath :: IO (Class File) + dumpClass cls + putStrLn $ "Source pool:\n" ++ showListIx (M.elems $ constsPool clsfile) + let result = classDirect2File cls + putStrLn $ "Result pool:\n" ++ showListIx (M.elems $ constsPool result) B.writeFile outpath (encodeClass cls) _ -> error "Synopsis: rebuild-class File.class Output.class"