scc

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

commit c5387758adeb9d061534f9e361b283083148637d
parent 6d31f2d198f80947e49577f2165c8a4a5ba0c154
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Sat, 21 Jan 2017 10:51:56 +0100

[cc2-qbe] Don't use b or h in function related things

Qbe expects w instead of b or h because X86_64 ABI don't deal
them in a different way to w.

Diffstat:
Mcc2/arch/qbe/arch.h | 7+------
Mcc2/arch/qbe/cgen.c | 23++---------------------
Mcc2/arch/qbe/code.c | 38+++++++++++++++++++++++++++-----------
3 files changed, 30 insertions(+), 38 deletions(-)

diff --git a/cc2/arch/qbe/arch.h b/cc2/arch/qbe/arch.h @@ -133,13 +133,8 @@ enum asmop { ASJMP, ASBRANCH, ASRET, - ASCALLB, - ASCALLH, - ASCALLW, - ASCALLS, - ASCALLL, - ASCALLD, ASCALL, + ASCALLE, ASPAR, ASPARE, ASALLOC, diff --git a/cc2/arch/qbe/cgen.c b/cc2/arch/qbe/cgen.c @@ -242,33 +242,14 @@ call(Node *np, Node *fun, Node *ret) pars[n++] = rhs(p->left, newnode(OTMP)); tp = &np->type; - switch (tp->size) { - case 0: - op = ASCALLW; - break; - case 1: - op = ASCALLB; - break; - case 2: - op = ASCALLH; - break; - case 4: - op = (tp->flags & INTF) ? ASCALLW : ASCALLS; - break; - case 8: - op = (tp->flags & INTF) ? ASCALLL : ASCALLD; - break; - default: - abort(); - } - code(op, tmpnode(ret, tp), fun, NULL); + code(ASCALL, tmpnode(ret, tp), fun, NULL); for (q = pars; q < &pars[n]; ++q) { op = (q == &pars[n-1]) ? ASPARE : ASPAR; tmpnode(&aux, &(*q)->type); code(op, NULL, *q, &aux); } - code(ASCALL, NULL, NULL, NULL); + code(ASCALLE, NULL, NULL, NULL); return ret; } diff --git a/cc2/arch/qbe/code.c b/cc2/arch/qbe/code.c @@ -136,13 +136,8 @@ static struct opdata { [ASBRANCH] = {.fun = branch}, [ASJMP] = {.fun = jmp}, [ASRET] = {.fun = ret}, - [ASCALLB] = {.fun = call, .letter = 'b'}, - [ASCALLH] = {.fun = call, .letter = 'h'}, - [ASCALLW] = {.fun = call, .letter = 'w'}, - [ASCALLS] = {.fun = call, .letter = 's'}, - [ASCALLL] = {.fun = call, .letter = 'l'}, - [ASCALLD] = {.fun = call, .letter = 'd'}, - [ASCALL] = {.fun = ecall}, + [ASCALL] = {.fun = call}, + [ASCALLE] = {.fun = ecall}, [ASPAR] = {.fun = param, .txt = "%s %s, "}, [ASPARE] = {.fun = param, .txt = "%s %s"}, [ASALLOC] = {.fun = alloc}, @@ -308,6 +303,25 @@ data(Node *np) putchar('\n'); } +static char * +size2stack(Type *tp) +{ + switch (tp->size) { + case 0: + return "w"; + case 1: + return "w"; + case 2: + return "w"; + case 4: + return "w"; + case 8: + return "l"; + default: + abort(); + } +} + void writeout(void) { @@ -318,13 +332,13 @@ writeout(void) if (curfun->kind == SGLOB) fputs("export ", stdout); - printf("function %s %s(", size2asm(&curfun->rtype), symname(curfun)); + printf("function %s %s(", size2stack(&curfun->rtype), symname(curfun)); /* declare formal parameters */ for (sep = "", p = locals; p; p = p->next, sep = ",") { if ((p->type.flags & PARF) == 0) break; - printf("%s%s %s.val", sep, size2asm(&p->type), symname(p)); + printf("%s%s %s.val", sep, size2stack(&p->type), symname(p)); } puts(")\n{"); @@ -415,10 +429,12 @@ call(void) { struct opdata *p = &optbl[pc->op]; char to[ADDR_LEN], from[ADDR_LEN]; + Symbol *sym = pc->to.u.sym; strcpy(to, addr2txt(&pc->to)); strcpy(from, addr2txt(&pc->from1)); - printf("\t%s =%c\tcall\t%s(", to, p->letter, from); + printf("\t%s =%s\tcall\t%s(", + to, size2stack(&sym->type), from); } static void @@ -427,7 +443,7 @@ param(void) Symbol *sym = pc->from2.u.sym; printf(optbl[pc->op].txt, - size2asm(&sym->type), addr2txt(&pc->from1)); + size2stack(&sym->type), addr2txt(&pc->from1)); } static void