-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lcc: argument references in variadic functions #62
Comments
This seems to work:
|
There may be a secondary issue: the data stack doesn't seem to be fully unwound upon return from a variadic function. Only the formal arguments are popped, by the callee. The responsibility should in this case probably lie with the caller instead. |
Concept that seems to work for the secondary issue.
|
Some thoughts before I forget:
|
- Example.c: demonstrate sprintf and printf for %d, %u, %s and %c - lcc: change argument order to support va_arg() (issue #62) - lcc: caller of variadic function pops the "extra" arguments - lcc: fix bug in swapping comparison operands (issue #63) - stdarg: va_start, va_arg, v_end (and va_sarg, see comments issue #62) - ctype: isdigit - stdio: fprintf, fputc, fputs, printf, putchar, puts, snprint, vfprintf, vprintf, vsnprintf, vsprintf - Makefile: fix mixup between LCC and not native compiler
See the comments in Utils/lcc/src/gt1.md
|
Remaining issue has low priority |
Suggesting to close this issue since glcc does this correctly already. |
Working on printf and implementing stdarg, when I noticed this:
This prints '45' instead of '12'.
The argument order on the stack is backwards in memory, because the data stack grows downwards and the first argument gets pushed first. Arguments are referenced relative to the stack pointer (by
ldloc
/stloc
) and not the frame pointer (as there is no such a thing?).From src/gt1.md:
It's not immediately clear to me how to fix this. We wouldn't want to introduce a frame pointer just for this. Reversing the order of arguments on the stack comes to mind. This requires a bit of surgery, and I believe C allows the implementation to perform backwards evaluation of arguments. I'm happy to take a shot at it. Any thoughts if I might overlook something, @pgavlin?
The text was updated successfully, but these errors were encountered: