[hackers] [scc] [cc2-qbe] Add different versions of load operations || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Fri, 22 Apr 2016 15:02:00 +0200 (CEST)

commit 97ce08e631def638abe4aa08e45378e71bcdcf5a
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Fri Apr 22 14:59:35 2016 +0200
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Fri Apr 22 14:59:35 2016 +0200

    [cc2-qbe] Add different versions of load operations
    
    Load depend of the type that is going to be loaded from
    memory, so we need a different opcode for the different
    sizes.

diff --git a/cc2/arch/qbe/arch.h b/cc2/arch/qbe/arch.h
index 6984765..feca53a 100644
--- a/cc2/arch/qbe/arch.h
+++ b/cc2/arch/qbe/arch.h
_AT_@ -5,7 +5,6 @@
 #define TSIZE unsigned long
 
 enum asmop {
- ASLOAD,
         ASSTB,
         ASSTH,
         ASSTW,
_AT_@ -13,6 +12,13 @@ enum asmop {
         ASSTS,
         ASSTD,
 
+ ASLDB,
+ ASLDH,
+ ASLDW,
+ ASLDL,
+ ASLDS,
+ ASLDD,
+
         ASADDW,
         ASSUBW,
         ASMULW,
diff --git a/cc2/arch/qbe/cgen.c b/cc2/arch/qbe/cgen.c
index 8a7b5ad..32b28e6 100644
--- a/cc2/arch/qbe/cgen.c
+++ b/cc2/arch/qbe/cgen.c
_AT_@ -107,11 +107,30 @@ static Node *
 load(Node *np)
 {
         Node *new;
+ int op;
+ Type *tp = &np->type;
 
         new = tmpnode(newnode());
         new->left = np;
- new->type = np->type;
- code(ASLOAD, new, np, NULL);
+ new->type = *tp;
+
+ switch (tp->size) {
+ case 1:
+ op = ASLDB;
+ break;
+ case 2:
+ op = ASLDH;
+ break;
+ case 4:
+ op = (tp->flags & INTF) ? ASLDW : ASLDS;
+ break;
+ case 8:
+ op = (tp->flags & INTF) ? ASLDL : ASLDD;
+ break;
+ default:
+ abort();
+ }
+ code(op, new, np, NULL);
 
         return new;
 }
diff --git a/cc2/arch/qbe/code.c b/cc2/arch/qbe/code.c
index 3e3bc91..c0c87e5 100644
--- a/cc2/arch/qbe/code.c
+++ b/cc2/arch/qbe/code.c
_AT_@ -16,7 +16,13 @@ static struct opdata {
         char *txt;
         char letter;
 } optbl [] = {
- [ASLOAD] = {.fun = load, .txt = "load", .letter = 'w'},
+ [ASLDB] = {.fun = load, .txt = "load", .letter = 'b'},
+ [ASLDH] = {.fun = load, .txt = "load", .letter = 'h'},
+ [ASLDW] = {.fun = load, .txt = "load", .letter = 'w'},
+ [ASLDL] = {.fun = load, .txt = "load", .letter = 'l'},
+ [ASLDS] = {.fun = load, .txt = "load", .letter = 's'},
+ [ASLDD] = {.fun = load, .txt = "load", .letter = 'd'},
+
         [ASSTB] = {.fun = store, .txt = "store", .letter = 'b'},
         [ASSTH] = {.fun = store, .txt = "store", .letter = 'h'},
         [ASSTW] = {.fun = store, .txt = "store", .letter = 'w'},
_AT_@ -346,8 +352,12 @@ store(void)
 static void
 load(void)
 {
- printf("\t%s %c=\t", addr2txt(&pc->to), 'w');
- printf("%s\t%s\n", optbl[pc->op].txt, addr2txt(&pc->from1));
+ struct opdata *p = &optbl[pc->op];
+ char to[ADDR_LEN], from[ADDR_LEN];
+
+ strcpy(to, addr2txt(&pc->to));
+ strcpy(from, addr2txt(&pc->from1));
+ printf("\t%s %c=\t%s\t%s\n", to, p->letter, p->txt, from);
 }
 
 void
Received on Fri Apr 22 2016 - 15:02:00 CEST

This archive was generated by hypermail 2.3.0 : Fri Apr 22 2016 - 15:12:18 CEST