\begin{code} module Main where import qualified Brianweb.Java.Structure as S import Brianweb.Java.Class import Brianweb.Control.Monad.Fail import CPUTime import Monad import System main :: IO () main = do args <- getArgs case args of [arg] | take 1 arg /= "!" -> main1 arg _ -> test main1 :: String -> IO () main1 arg = do cf <- time "readClassFile" $ S.readClassFile arg c <- time "buildClass" $ buildClass cf cf' <- time "unbuildClass" $ return (unbuildClass' (S.c_constant_pool cf) c) time "writeClassFile" $ S.writeClassFile cf' (arg++"~") let ds = diffs 10 (show cf) (show cf') mapM_ putStrLn ds unless (null ds) (fail "output different") diffs :: Int -> String -> String -> [String] diffs 0 _ _ = [] diffs n xs ys | null a = [] | otherwise = left : right : uncurry (diffs (n-1)) (unzip (tail a)) where (b,a) = break (uncurry (/=)) (zip xs ys) left = reverse (take 30 (reverse (map fst b))) ++ take 40 (map fst a) right = reverse (take 30 (reverse (map snd b))) ++ take 40 (map snd a) time :: Eq a => String -> IO a -> IO a time d m = do t0 <- getCPUTime x <- m when (x /= x) undefined t1 <- getCPUTime putStrLn $ d ++ ": " ++ show ((t1 - t0 + 500) `div` (10^(9::Int))) ++ "ms" return x \end{code}