scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit dd20c9cb3f57b3af3bc1f6ecc088fdb214fdd4f8
parent 1f8ba936aa0b76b92cde96c1cd7e07bcc1fa2621
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Thu,  2 Jun 2016 14:50:07 +0200

[cc2-qbe] Add type in function parameters

This was the last point missed in function calls, and after this point
we can generate beatiful programs that will do something interesting.

Diffstat:
Mcc2/arch/qbe/cgen.c | 4+++-
Mcc2/arch/qbe/code.c | 9++++++---
2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/cc2/arch/qbe/cgen.c b/cc2/arch/qbe/cgen.c @@ -266,7 +266,9 @@ call(Node *np) for (q = pars; q < &pars[n]; ++q) { op = (q == &pars[n-1]) ? ASPARE : ASPAR; - code(op, NULL, *q, NULL); + p = newnode(OTMP); + p->type = (*q)->type; + code(op, NULL, *q, tmpnode(p)); } code(ASCALL, NULL, NULL, NULL); diff --git a/cc2/arch/qbe/code.c b/cc2/arch/qbe/code.c @@ -133,8 +133,8 @@ static struct opdata { [ASCALLL] = {.fun = call, .letter = 'l'}, [ASCALLD] = {.fun = call, .letter = 'd'}, [ASCALL] = {.fun = ecall}, - [ASPAR] = {.fun = param, .txt = "\t\t%s,\n"}, - [ASPARE] = {.fun = param, .txt = "\t\t%s\n"}, + [ASPAR] = {.fun = param, .txt = "\t\t%s %s,\n"}, + [ASPARE] = {.fun = param, .txt = "\t\t%s %s\n"}, }; static char buff[ADDR_LEN]; @@ -421,7 +421,10 @@ call(void) static void param(void) { - printf(optbl[pc->op].txt, addr2txt(&pc->from1)); + Symbol *sym = pc->from2.u.sym; + + printf(optbl[pc->op].txt, + size2asm(&sym->type), addr2txt(&pc->from1)); } static void