commit f67d0534ce16ec2ac8a50c21e5f2e87915756dfe
parent de755db38679f8349e10fda5d6150ad10e1aaac5
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Fri, 16 Sep 2016 14:53:08 +0200
[cc2-qbe] Add basic support for struct assignment
At this moment there is no implementatin of struct assignment in
qbe, so this is only a skeleton to be filled later.
Diffstat:
5 files changed, 22 insertions(+), 5 deletions(-)
diff --git a/cc2/arch/qbe/arch.h b/cc2/arch/qbe/arch.h
@@ -9,6 +9,7 @@ enum asmop {
ASSTH,
ASSTW,
ASSTL,
+ ASSTM,
ASSTS,
ASSTD,
diff --git a/cc2/arch/qbe/cgen.c b/cc2/arch/qbe/cgen.c
@@ -113,6 +113,10 @@ load(Type *tp, Node *np, Node *new)
{
int op;
+ if (tp->flags & AGGRF) {
+ *new = *np;
+ return new;
+ }
switch (tp->size) {
case 1:
op = ASLDB;
@@ -127,8 +131,7 @@ load(Type *tp, Node *np, Node *new)
op = (tp->flags & FLOATF) ? ASLDD : ASLDL;
break;
default:
- *new = *np;
- return new;
+ abort();
}
code(op, tmpnode(new, tp), np, NULL);
@@ -273,7 +276,8 @@ assign(Type *tp, Node *to, Node *from)
op = (tp->flags & FLOATF) ? ASSTD : ASSTL;
break;
default:
- abort();
+ op = ASSTM;
+ break;
}
code(op, to, from, NULL);
return from;
diff --git a/cc2/arch/qbe/code.c b/cc2/arch/qbe/code.c
@@ -11,7 +11,7 @@
static void binary(void), unary(void), store(void), jmp(void), ret(void),
branch(void), call(void), ecall(void), param(void),
- alloc(void), form2local(void);
+ alloc(void), form2local(void), ldir(void);
static struct opdata {
void (*fun)(void);
@@ -29,6 +29,7 @@ static struct opdata {
[ASSTH] = {.fun = store, .txt = "store", .letter = 'h'},
[ASSTW] = {.fun = store, .txt = "store", .letter = 'w'},
[ASSTL] = {.fun = store, .txt = "store", .letter = 'l'},
+ [ASSTM] = {.fun = ldir},
[ASSTS] = {.fun = store, .txt = "store", .letter = 's'},
[ASSTD] = {.fun = store, .txt = "store", .letter = 'd'},
@@ -369,6 +370,16 @@ binary(void)
}
static void
+ldir(void)
+{
+ struct opdata *p = &optbl[pc->op];
+ char to[ADDR_LEN], from[ADDR_LEN];
+ /* TODO: what type do we use for the size? */
+
+ /* TODO: it is pending */
+}
+
+static void
store(void)
{
struct opdata *p = &optbl[pc->op];
diff --git a/cc2/cc2.h b/cc2/cc2.h
@@ -9,7 +9,7 @@ enum tflags {
INTF = 2,
FLOATF = 4,
STRF = 8,
- UNIONF = 16,
+ AGGRF = 16,
FUNF = 32,
PARF = 64,
};
diff --git a/cc2/parser.c b/cc2/parser.c
@@ -487,6 +487,7 @@ aggregate(void)
tp->size = size->u.i;
tp->align = align->u.i;
+ tp->flags = AGGRF;
/*
* type is the first field of Symbol so we can obtain the
* address of the symbol from the address of the type.