[LLVMdev] Scheme on LLVM IR
craven at gmx.net
craven at gmx.net
Wed Aug 7 02:15:28 PDT 2013
Hello!
I've been trying to implement a simple compiler from Scheme to LLVM IR,
and have run into the following problem:
In Scheme, any function can be called on any number of arguments, but it
should check at runtime for arity errors.
I haven't been able to find a way in LLVM IR to access the actual number
of parameters a function was called with.
I think the following approach might solve the problem:
- Implement a new calling convention that passes the number of arguments
in a register, and all values in registers / the stack.
- Implement an intrinsic to get the number of arguments in LLVM IR.
- Implement an intrinsic to get at the arguments in LLVM IR.
Are there any better ways to solve this? Does any of the existing
calling conventions support this?
Incidentially, the same handling is necessary for return values (any
function can return any number of values, and the caller must check for
correct return value arity).
Varargs seem a bad match, as everything is passed on the stack, not in
registers, and no count is kept of the actual number of arguments.
Am I correct that in order to implement this, I'd need to add the new
calling convention and intrinsics for each Target separately?
Thanks for any help or suggestions!
Peter
More information about the llvm-dev
mailing list