1 {-# LANGUAGE OverloadedStrings #-}
2 {-# LANGUAGE TemplateHaskell #-}
4 -- Purpose of this file is just do test some Intermediate representations and stuff ;-)
6 {- Some important material:
8 - Java HotSpotâ„¢ Client Compiler: www.cdl.uni-saarland.de/ssasem/talks/Christian.Wimmer.pdf
9 - http://www.complang.tuwien.ac.at/andi/185A50
11 - [Poletto:1999] http://dl.acm.org/citation.cfm?doid=330249.330250
12 - [Wimmer:2010] http://dl.acm.org/citation.cfm?id=1772954.1772979
17 module ScratchHS where
22 import Harpy.X86Disassembler
31 import qualified JVM.Assembler as JAsm
34 import Mate.BasicBlocks
36 $(callDecl "callAsWord32" [t|Word32|])
38 data SimpleStack = PushLit Int
44 testP = [PushLit 3, PushLit 2, Mul]
47 data ROp = RMul | RAdd
49 data RegIL = RMov Reg Reg
51 | RBin Reg Reg Reg ROp
53 data MateState = MateState String
55 compileRegIL :: RegIL -> CodeGen (Ptr Int32) MateState ()
56 compileRegIL (RMov t s) = do
58 let (mt,ms) = (eax,eax)
62 entryCode :: CodeGen e s ()
63 entryCode = do push ebp
66 exitCode :: CodeGen e s ()
67 exitCode = do mov esp ebp
73 run :: [RegIL] -> Ptr Int32 -> IO (MateState, Either ErrMsg [Instruction])
74 run program env = let compileAndFeedback = mapM_ compileRegIL program >> disassemble
75 in runCodeGen compileAndFeedback env (MateState "none")
78 -- Allocates a buffer with size n. All zero.
79 emptyMemory :: (Storable a, Num a) => Int -> IO (Ptr a)
80 emptyMemory n = mallocArray n
81 >>= (\ptr -> pokeArray ptr (replicate n 0) >> return ptr)
86 (_, Right code) <- run p' ptr
87 return $ map showIntel code
91 simpleTest = [RMov 0 1]
94 -- Just some class file sand
95 loadMethod methodName classFile = do cls <- parseClassFile classFile
97 return (cls, lookupMethod methodName cls)
100 getFib = do (cls, Just m) <- loadMethod "ackermann" "../tests/Ackermann.class"
103 fibBasicBlocks = do (cls,m) <- getFib
104 hmap <- parseMethod cls "ackermann"