First: you cannot use the tail call if you want to pass varargs:
http://llvm.org/docs/LangRef.html
- An additional tail marker indicates that the called function does not have access to any allocas or varargs in the caller.
Second: what are your conventions?
Third: to handle varargs (for example, in C) you need to use the va_* functions to create a new va_list and copy all the parameters to it:
http://llvm.org/docs/LangRef.html#int-varargs
Last: each function that will be called by this dispatcher must use the va_* functions to get its arguments.
UPDATE:
You need to know which calling convention you will use (which is the default) before talking about the stack as storing function arguments. Then. You cannot access the argument "..." without the va_ * parameters, because this is ONLY access to them in the LLVM assembly.
There is a way to do smth, as in C, here printf will call vfprintf with all arguments "..." and don't know how many arguments will pass
// 3-clause BSD licensed to The Regents of the University of California. int printf(const char *fmt, ...) { int ret; va_list ap; va_start(ap, fmt); ret = vfprintf(stdout, fmt, ap); va_end(ap); return (ret); }
Vfprintf is declared in a special way to get "..." and extract arguments from it:
int vfprintf(FILE *fp, const char *fmt0, __va_list ap) { ... va_arg(ap, type)
source share