- let l = buildMethodID cls cpidx
- calladdr <- getCurrentOffset
- newNamedLabel (show l) >>= defineLabel
- -- causes SIGILL. in the signal handler we patch it to the acutal call.
- -- place a nop at the end, therefore the disasm doesn't screw up
- emit32 (0xffff9090 :: Word32) >> emit8 (0x90 :: Word8)
- -- discard arguments on stack
- let argcnt = ((if hasThis then 1 else 0) + (methodGetArgsCount cls cpidx)) * 4
- when (argcnt > 0) (add esp argcnt)
- -- push result on stack if method has a return value
- when (methodHaveReturnValue cls cpidx) (push eax)
- return $ Just $ (calladdr, MI l)
-
- emit' :: J.Instruction -> CodeGen e s (Maybe (Word32, TrapInfo))
+ let l = buildMethodID cls cpidx
+ calladdr <- getCurrentOffset
+ newNamedLabel (show l) >>= defineLabel
+ -- causes SIGILL. in the signal handler we patch it to the acutal call.
+ -- place a nop at the end, therefore the disasm doesn't screw up
+ emit32 (0xffff9090 :: Word32) >> emit8 (0x90 :: Word8)
+ -- discard arguments on stack
+ let argcnt = ((if hasThis then 1 else 0) + (methodGetArgsCount $ methodNameTypeByIdx cls cpidx)) * 4
+ when (argcnt > 0) (add esp argcnt)
+ -- push result on stack if method has a return value
+ when (methodHaveReturnValue cls cpidx) (push eax)
+ -- +2 is for correcting eip in trap context
+ return $ Just (calladdr + 2, StaticMethod l)
+
+ invokeEpilog :: Word16 -> Word32 -> (Bool -> TrapCause) -> CodeGen e s (Maybe (Word32, TrapCause))
+ invokeEpilog cpidx offset trapcause = do
+ -- make actual (indirect) call
+ calladdr <- getCurrentOffset
+ call (Disp offset, eax)
+ -- discard arguments on stack (+4 for "this")
+ let argcnt = 4 + 4 * (methodGetArgsCount $ methodNameTypeByIdx cls cpidx)
+ when (argcnt > 0) (add esp argcnt)
+ -- push result on stack if method has a return value
+ when (methodHaveReturnValue cls cpidx) (push eax)
+ let imm8 = is8BitOffset offset
+ return $ Just (calladdr + (if imm8 then 3 else 6), trapcause imm8)
+
+ emit'' :: J.Instruction -> CodeGen e s (Maybe (Word32, TrapCause))
+ emit'' insn = newNamedLabel ("jvm_insn: " ++ show insn) >>= defineLabel >> emit' insn
+
+ emit' :: J.Instruction -> CodeGen e s (Maybe (Word32, TrapCause))