ref: f8fef90345e4cc025190732f94646facb2456241
parent: 3998b345a115b0d3a59ac550f4416010666eb822
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Sat Jan 21 05:51:56 EST 2017
[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.
--- a/cc2/arch/qbe/arch.h
+++ b/cc2/arch/qbe/arch.h
@@ -133,13 +133,8 @@
ASJMP,
ASBRANCH,
ASRET,
- ASCALLB,
- ASCALLH,
- ASCALLW,
- ASCALLS,
- ASCALLL,
- ASCALLD,
ASCALL,
+ ASCALLE,
ASPAR,
ASPARE,
ASALLOC,
--- a/cc2/arch/qbe/cgen.c
+++ b/cc2/arch/qbe/cgen.c
@@ -242,26 +242,7 @@
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;
@@ -268,7 +249,7 @@
tmpnode(&aux, &(*q)->type);
code(op, NULL, *q, &aux);
}
- code(ASCALL, NULL, NULL, NULL);
+ code(ASCALLE, NULL, NULL, NULL);
return ret;
}
--- a/cc2/arch/qbe/code.c
+++ b/cc2/arch/qbe/code.c
@@ -136,13 +136,8 @@
[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 @@
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 @@
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 @@
{
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 @@
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