[LLVMdev] Tool for run-time code generation?
resistor at mac.com
Fri Jul 16 13:26:49 PDT 2010
On Jul 16, 2010, at 12:48 PM, David Piepgrass wrote:
> If you mean that dynamically generated code cannot call malloc (why not? Couldn't I provide a table that tells LLVM the address of malloc and any other methods I want to call?), even then it is not a problem, since the code I want to generate will simply access records and do some arithmetic.
He does mean exactly that. Being able to call a function means that you need to know how the system's calling convention works (what parameters go in register/on the stack, where return values go, etc.). Not just that: accessing a record requires you to know how the record is laid out in memory, which is also governed by platform-specific rules in the translation from C structs to actual memory layouts (complete with padding, etc).
That said, if you're very, very careful to control layouts by hand and only to call functions whose calling convention you can model (maybe write your own prologue in ASM?), you could probably coerce it into working.
More information about the llvm-dev