codegen: patch method calls on-demand via traps
authorBernhard Urban <lewurm@gmail.com>
Sun, 8 Apr 2012 18:21:56 +0000 (20:21 +0200)
committerBernhard Urban <lewurm@gmail.com>
Sun, 8 Apr 2012 18:26:10 +0000 (20:26 +0200)
commit697a28a8f6f2ea536bec08056b668fb0f2e84e3a
treeb6a6b0e8a2772245755636a3639d4da4e9129941
parent7679c53ec01fa705b1a551e88116899c7f71bdc0
codegen: patch method calls on-demand via traps

we can determine the source of an invalid memory access via unix signal
handling. to do so, we write
 > mov (Addr 0) eax    ; 0x8905 0000 0000
which tries to access memory at address 0. upon first execution of this
instruction the signalhandler is called. there, we replace it with
 > nop                 ; 0x90
 > call <target>       ; 0xe8 YYYY YYYY  ; Y = target

at the moment, this just works with Fib.fib() (or other recursive methods)
as the <target> address is more or less hardcoded.

several TODOs:
- determine address of target method in a different way
- after a call, we have to throw away arguments of the call.
  this is hardcoded now.
Mate/X86CodeGen.hs
tests/Fib.java
trap.c