[hackers] [scc] [cc2-qbe] Add jumps to qbe || Roberto E. Vargas Caballero
commit b90eb5f63f1264a37528244e8c2ce6a77a8da36a
Author: Roberto E. Vargas Caballero <Roberto E. Vargas Caballero>
AuthorDate: Sat Apr 23 17:27:50 2016 +0200
Commit: Roberto E. Vargas Caballero <Roberto E. Vargas Caballero>
CommitDate: Sat Apr 23 17:27:50 2016 +0200
[cc2-qbe] Add jumps to qbe
diff --git a/cc2/arch/qbe/arch.h b/cc2/arch/qbe/arch.h
index e01030d..00a2eec 100644
--- a/cc2/arch/qbe/arch.h
+++ b/cc2/arch/qbe/arch.h
_AT_@ -128,5 +128,7 @@ enum asmop {
ASSLTOS,
ASEXTS,
- ASTRUNCD
+ ASTRUNCD,
+
+ ASJMP
};
diff --git a/cc2/arch/qbe/cgen.c b/cc2/arch/qbe/cgen.c
index 5f2ff87..6d465be 100644
--- a/cc2/arch/qbe/cgen.c
+++ b/cc2/arch/qbe/cgen.c
_AT_@ -225,6 +225,7 @@ cgen(Node *np)
if (!np)
return NULL;
+ setlabel(np->label);
l = cgen(np->left);
r = cgen(np->right);
tp = &np->type;
_AT_@ -327,8 +328,9 @@ cgen(Node *np)
case OOR:
abort();
case OBRANCH:
+ abort();
case OJMP:
- code(op, NULL, l, r);
+ code(ASJMP, np, NULL, NULL);
return NULL;
case ORET:
case OCASE:
diff --git a/cc2/arch/qbe/code.c b/cc2/arch/qbe/code.c
index 41ea806..a5a01e0 100644
--- a/cc2/arch/qbe/code.c
+++ b/cc2/arch/qbe/code.c
_AT_@ -9,7 +9,7 @@
#define ADDR_LEN (IDENTSIZ+64)
-static void binary(void), unary(void), store(void);
+static void binary(void), unary(void), store(void), jmp(void);
static struct opdata {
void (*fun)(void);
_AT_@ -121,6 +121,8 @@ static struct opdata {
[ASEXTS] = {.fun = unary, .txt = "exts", .letter = 'd'},
[ASSLTOS]= {.fun = unary, .txt = "truncd", .letter = 's'},
+
+ [ASJMP] = {.fun = jmp},
};
static char buff[ADDR_LEN];
_AT_@ -334,7 +336,8 @@ writeout(void)
for (pc = prog; pc; pc = pc->next) {
if (pc->label)
printf("%s:\n", symname(pc->label));
- (*optbl[pc->op].fun)();
+ if (pc->op)
+ (*optbl[pc->op].fun)();
}
puts("}");
_AT_@ -390,6 +393,12 @@ unary(void)
printf("\t%s %c=\t%s\t%s\n", to, p->letter, p->txt, from);
}
+static void
+jmp(void)
+{
+ printf("\t\tjmp\t%s\n", addr2txt(&pc->to));
+}
+
void
endinit(void)
{
diff --git a/cc2/cc2.h b/cc2/cc2.h
index 5bd31e4..44ce9b1 100644
--- a/cc2/cc2.h
+++ b/cc2/cc2.h
_AT_@ -200,6 +200,7 @@ extern void data(Node *np);
extern void writeout(void), endinit(void), newfun(void);
extern void code(int op, Node *to, Node *from1, Node *from2);
extern void defvar(Symbol *), defpar(Symbol *), defglobal(Symbol *);
+extern void setlabel(Symbol *sym);
/* node.c */
extern void apply(Node *(*fun)(Node *));
Received on Sun Apr 24 2016 - 17:29:38 CEST
This archive was generated by hypermail 2.3.0
: Sun Apr 24 2016 - 17:36:27 CEST