-initMethodPool :: IO ()
-initMethodPool = do
- mmap2ptr M.empty >>= set_mmap
- cmap2ptr M.empty >>= set_cmap
-
-compileBB :: MapBB -> MethodInfo -> IO (Ptr Word8)
-compileBB hmap methodinfo = do
- mmap <- get_mmap >>= ptr2mmap
- cmap <- get_cmap >>= ptr2cmap
-
- -- TODO(bernhard): replace parsing with some kind of classpool
- cls <- parseClassFile $ toString $ (cName methodinfo) `B.append` ".class"
- let ebb = emitFromBB cls hmap
- (_, Right ((entry, _, _, new_cmap), disasm)) <- runCodeGen ebb () ()
- let w32_entry = ((fromIntegral $ ptrToIntPtr entry) :: Word32)
-
- let mmap' = M.insert methodinfo w32_entry mmap
- let cmap' = M.union cmap new_cmap -- prefers elements in cmap
- mmap2ptr mmap' >>= set_mmap
- cmap2ptr cmap' >>= set_cmap
-
- printf "disasm:\n"
- mapM_ (putStrLn . showAtt) disasm
- -- UNCOMMENT NEXT LINE FOR GDB FUN
- -- _ <- getLine
- -- (1) start it with `gdb ./mate' and then `run <classfile>'
- -- (2) on getLine, press ctrl+c
+addMethodRef :: NativeWord -> MethodInfo -> [B.ByteString] -> IO ()
+addMethodRef entry (MethodInfo mmname _ msig) clsnames = do
+ mmap <- getMethodMap
+ let newmap = foldr (\i -> M.insert (MethodInfo mmname i msig) entry) M.empty clsnames
+ setMethodMap $ mmap `M.union` newmap
+
+
+compileBB :: RawMethod -> MethodInfo -> IO NativeWord
+compileBB rawmethod methodinfo = do
+ tmap <- getTrapMap
+
+ cls <- getClassFile (methClassName methodinfo)
+ let ebb = emitFromBB cls rawmethod
+ (_, Right right) <- runCodeGen ebb () ()
+
+ let ((entry, _, _, new_tmap), _) = right
+ setTrapMap $ tmap `M.union` new_tmap -- prefers elements in tmap
+
+ printfJit "generated code of \"%s\" from \"%s\":\n" (toString $ methName methodinfo) (toString $ methClassName methodinfo)
+ printfJit "\tstacksize: 0x%04x, locals: 0x%04x\n" (rawStackSize rawmethod) (rawLocals rawmethod)
+#ifdef DBG_JIT
+ mapM_ (printfJit "%s\n" . showAtt) (snd right)
+#endif
+ printfJit "\n\n"
+ -- UNCOMMENT NEXT LINES FOR GDB FUN
+ -- if (toString $ methName methodinfo) == "thejavamethodIwant2debug"
+ -- then putStrLn "press CTRL+C now for setting a breakpoint. then `c' and ENTER for continue" >> getLine
+ -- else return "foo"
+ -- (1) build a debug build (see HACKING) and execute `make tests/Fib.gdb'
+ -- for example, where the suffix is important
+ -- (2) on getLine, press CTRL+C