diff options
| author | aarne <aarne@cs.chalmers.se> | 2008-06-25 16:54:35 +0000 |
|---|---|---|
| committer | aarne <aarne@cs.chalmers.se> | 2008-06-25 16:54:35 +0000 |
| commit | e9e80fc389365e24d4300d7d5390c7d833a96c50 (patch) | |
| tree | f0b58473adaa670bd8fc52ada419d8cad470ee03 /examples/gfcc/compiler/CleanJVM.hs | |
| parent | b96b36f43de3e2f8b58d5f539daa6f6d47f25870 (diff) | |
changed names of resource-1.3; added a note on homepage on release
Diffstat (limited to 'examples/gfcc/compiler/CleanJVM.hs')
| -rw-r--r-- | examples/gfcc/compiler/CleanJVM.hs | 57 |
1 files changed, 0 insertions, 57 deletions
diff --git a/examples/gfcc/compiler/CleanJVM.hs b/examples/gfcc/compiler/CleanJVM.hs deleted file mode 100644 index ab879ff0e..000000000 --- a/examples/gfcc/compiler/CleanJVM.hs +++ /dev/null @@ -1,57 +0,0 @@ -module Main where - -import Char -import System - ---- translation from Symbolic JVM to real Jasmin code - -main :: IO () -main = do - jvm:src:_ <- getArgs - s <- readFile jvm - let cls = takeWhile (/='.') src - let obj = cls ++ ".j" - writeFile obj $ boilerplate cls - appendFile obj $ mkJVM cls s - putStrLn $ "wrote file " ++ obj - system $ "jasmin " ++ obj - return () - -mkJVM :: String -> String -> String -mkJVM cls = unlines . reverse . fst . foldl trans ([],([],0)) . lines where - trans (code,(env,v)) s = case words s of - ".method":p:s:f:ns - | f == "main" -> - (".method public static main([Ljava/lang/String;)V":code,([],1)) - | otherwise -> - (unwords [".method",p,s, f ++ glue ns] : code,([],0)) - "alloc":t:x:_ -> (("; " ++ s):code, ((x,v):env, v + size t)) - ".limit":"locals":ns -> chCode (".limit locals " ++ show (length ns)) - "runtime":f:ns -> chCode $ "invokestatic " ++ "runtime/" ++ f ++ glue ns - "static":f:ns -> chCode $ "invokestatic " ++ cls ++ "/" ++ f ++ glue ns - "alloc":ns -> chCode $ "; " ++ s - ins:x:_ | symb ins -> chCode $ ins ++ " " ++ look x - "goto":ns -> chCode $ "goto " ++ glue ns - "ifeq":ns -> chCode $ "ifeq " ++ glue ns - "label":ns -> chCode $ glue ns ++ ":" - ";":[] -> chCode "" - _ -> chCode s - where - chCode c = (c:code,(env,v)) - look x = maybe (error $ x ++ show env) show $ lookup x env - glue = init . concat - symb = flip elem ["load","store"] . tail - size t = case t of - "d" -> 2 - _ -> 1 - -boilerplate :: String -> String -boilerplate cls = unlines [ - ".class public " ++ cls, - ".super java/lang/Object", - ".method public <init>()V", - "aload_0", - "invokenonvirtual java/lang/Object/<init>()V", - "return", - ".end method" - ] |
