[hackers] [scc] [cc2-qbe] Add basic support for struct assignment || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Fri, 16 Sep 2016 14:57:36 +0200 (CEST)

commit f67d0534ce16ec2ac8a50c21e5f2e87915756dfe
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Fri Sep 16 14:53:08 2016 +0200
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Fri Sep 16 14:53:08 2016 +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.

diff --git a/cc2/arch/qbe/arch.h b/cc2/arch/qbe/arch.h
index 512511e..38eafbb 100644
--- a/cc2/arch/qbe/arch.h
+++ b/cc2/arch/qbe/arch.h
_AT_@ -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
index 4d147e9..7b176df 100644
--- a/cc2/arch/qbe/cgen.c
+++ b/cc2/arch/qbe/cgen.c
_AT_@ -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;
_AT_@ -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);
 
_AT_@ -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
index 1d9164b..7be16c7 100644
--- a/cc2/arch/qbe/code.c
+++ b/cc2/arch/qbe/code.c
_AT_@ -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);
_AT_@ -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'},
 
_AT_@ -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
index 9bc248c..c5256cb 100644
--- a/cc2/cc2.h
+++ b/cc2/cc2.h
_AT_@ -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
index 34da9a9..dfa6f1e 100644
--- a/cc2/parser.c
+++ b/cc2/parser.c
_AT_@ -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.
Received on Fri Sep 16 2016 - 14:57:36 CEST

This archive was generated by hypermail 2.3.0 : Fri Sep 16 2016 - 15:00:29 CEST