[LLVMdev] Scheme on LLVM IR
Tim Northover
t.p.northover at gmail.com
Wed Aug 7 02:35:33 PDT 2013
Hi Peter,
> Are there any better ways to solve this? Does any of the existing
> calling conventions support this?
Can't you handle this entirely in the front-end? Just decide by fiat
that all of your scheme functions will take an extra (hidden to the
Scheme users) parameter saying how many args they were given. That's
how C++ deals with the implicit "this" parameter for class methods.
Then you could either use varargs or bitcast your functions to a
reasonable type when used.
> 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).
A similar approach could work there, though targets aren't used to
dealing with lots of return values so you may encounter more problems
(i.e. LLVM bugs).
> 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.
Is that on x86-32 Windows? In almost all other cases varargs are
passed in a manner compatible with non-variadic functions -- there's
just too much bad software out there that relies on this (it was
allowed in the bad old K&R C days) so ABIs are designed with that in
mind.
But you're right about them not usually keeping count.
Cheers.
Tim.
More information about the llvm-dev
mailing list