[hackers] [scc] [cc2-qbe] Don't use b or h in function related things || Roberto E. Vargas Caballero
commit c5387758adeb9d061534f9e361b283083148637d
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Sat Jan 21 10:51:56 2017 +0100
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Sat Jan 21 10:51:56 2017 +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.
diff --git a/cc2/arch/qbe/arch.h b/cc2/arch/qbe/arch.h
index 7c86252..e2b01ce 100644
--- a/cc2/arch/qbe/arch.h
+++ b/cc2/arch/qbe/arch.h
_AT_@ -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
index 8900c6b..50a7b3f 100644
--- a/cc2/arch/qbe/cgen.c
+++ b/cc2/arch/qbe/cgen.c
_AT_@ -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
index 570a7b2..55b8a06 100644
--- a/cc2/arch/qbe/code.c
+++ b/cc2/arch/qbe/code.c
_AT_@ -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},
_AT_@ -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)
{
_AT_@ -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{");
_AT_@ -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
_AT_@ -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
Received on Sat Jan 21 2017 - 10:54:43 CET
This archive was generated by hypermail 2.3.0
: Sat Jan 21 2017 - 11:00:18 CET