aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.rst2
-rw-r--r--mips.c16
-rw-r--r--semantics.c1
-rw-r--r--ssa.c26
-rw-r--r--ssa.h1
5 files changed, 31 insertions, 15 deletions
diff --git a/README.rst b/README.rst
index 62df5d9..ad625af 100644
--- a/README.rst
+++ b/README.rst
@@ -1,4 +1,4 @@
-CBIC: C Implemented Bare and Ingenuous Compiler
+CIBIC: C Implemented Bare and Ingenuous Compiler
=================================================
Build Requirements
diff --git a/mips.c b/mips.c
index efb51ba..ab02606 100644
--- a/mips.c
+++ b/mips.c
@@ -492,6 +492,7 @@ void mips_generate(void) {
}
break;
case PUSH:
+ if (!i->sysp)
{
int rs = mips_to_reg(i->src1, reg_v0);
/*
@@ -523,20 +524,19 @@ void mips_generate(void) {
int j;
memset(used_reg, 0, sizeof used_reg);
/* NOTE: bad hack */
- if (i->src1->kind == IMMF)
+ if (i->prev->op == PUSH && i->prev->sysp)
{
char *fname = i->src1->info.str;
int flag = 0;
+ int rs = mips_to_reg(i->prev->src1, 4);
if (!strcmp(fname, "__print_int")) flag = 1;
else if (!strcmp(fname, "__print_char")) flag = 11;
else if (!strcmp(fname, "__print_string")) flag = 4;
- if (flag)
- {
- printf( "\tlw $a0, 0($sp)\n"
- "\tli $2, %d\n"
- "\tsyscall\n", flag);
- break;
- }
+ else assert(0);
+ if (rs != 4) printf("\tmove $4, $%d\n", rs);
+ printf( "\tli $2, %d\n"
+ "\tsyscall\n", flag);
+ break;
}
if (rt->type == CSTRUCT || rt->type == CUNION)
used_reg[30] = 1; /* save $fp */
diff --git a/semantics.c b/semantics.c
index 30088ca..d8fe289 100644
--- a/semantics.c
+++ b/semantics.c
@@ -273,6 +273,7 @@ CVar_t cvar_create(char *name, CType_t type, CNode *ast) {
cv->loc = 0;
cv->weight = 0;
cv->reload = 0;
+ cv->cnt = 0;
return cv;
}
diff --git a/ssa.c b/ssa.c
index f92d4f3..9d318b4 100644
--- a/ssa.c
+++ b/ssa.c
@@ -38,6 +38,7 @@ CInst_t cinst_create(void) {
inst->dest = NULL;
inst->src1 = NULL;
inst->src2 = NULL;
+ inst->sysp = 0;
return inst;
}
@@ -1608,7 +1609,7 @@ void renaming_dfs(CBlock_t blk) {
CVar_t var = dest->info.var;
COList_t n = NEW(COList), n2;
dest->sub = var->cnt++;
- dest->def = ih->next; /* the first inst */
+/* dest->def = ih->next; *//* the first inst */
n->opr = dest;
n->next = var->stack;
var->stack = n;
@@ -1645,7 +1646,7 @@ void renaming_dfs(CBlock_t blk) {
CVar_t var = dest->info.var;
COList_t n = NEW(COList), n2;
dest->sub = var->cnt++;
- dest->def = i;
+ /* dest->def = i; */
n->opr = dest;
n->next = var->stack;
var->stack = n;
@@ -1710,14 +1711,21 @@ void mark_insts(void) {
CBlock_t b = blks[ord[i]];
CInst_t ih = b->insts, ii;
CPhi_t ph = b->phis, pi;
+ for (pi = ph->next; pi != ph; pi = pi->next)
+ {
+ pi->dest->def = ih->next;
+ icnt++;
+ }
if (cblock_isempty(b))
b->first = b->last = icnt++;
else
{
- for (pi = ph->next; pi != ph; pi = pi->next)
- icnt++;
for (ii = ih->next; ii != ih; ii = ii->next)
+ {
+ if (ii->op != WARR && ii->dest)
+ ii->dest->def = ii;
ii->id = icnt++;
+ }
b->first = ih->next->id;
b->last = ih->prev->id;
}
@@ -2287,8 +2295,10 @@ void const_propagation(void) {
{
c = copr_create();
c->kind = IMM;
+ /*
free(i->src1);
free(i->src2);
+ */
i->op = MOVE;
i->src1 = c;
c->info.imm = immd;
@@ -2342,6 +2352,7 @@ void strength_reduction(void) {
cstr->id = cstr->prev->id + 1; \
inst = cinst_create(); \
inst->op = PUSH; \
+ inst->sysp = 1; \
inst->src1 = copr_create(); \
inst->src1->kind = IMMS; \
inst->src1->info.cstr = cstr; \
@@ -2445,8 +2456,6 @@ void strength_reduction(void) {
print->dest->type = i->dest->type;
print->src1 = copr_create();
print->src1->kind = IMMF;
-
-
PRINT_BARE_STRING;
switch (*(++sp))
{
@@ -2455,6 +2464,7 @@ void strength_reduction(void) {
if (push != i)
{
np = push->next;
+ push->sysp = 1;
cblock_append(ibuff, push);
push = np;
}
@@ -2467,6 +2477,7 @@ void strength_reduction(void) {
if (push != i)
{
np = push->next;
+ push->sysp = 1;
cblock_append(ibuff, push);
push = np;
}
@@ -2480,6 +2491,7 @@ void strength_reduction(void) {
if (push != i)
{
np = push->next;
+ push->sysp = 1;
cblock_append(ibuff, push);
push = np;
}
@@ -2496,6 +2508,7 @@ void strength_reduction(void) {
cstr->id = cstr->prev->id + 1;
inst = cinst_create();
inst->op = PUSH;
+ inst->sysp = 1;
inst->src1 = copr_create();
inst->src1->kind = IMMS;
inst->src1->info.cstr = cstr;
@@ -2503,6 +2516,7 @@ void strength_reduction(void) {
for (; push != i; push = np)
{
np = push->next;
+ push->sysp = 1;
cblock_append(ibuff, push);
}
print->src1->info.str = "printf";
diff --git a/ssa.h b/ssa.h
index a85e5c7..e3b04ed 100644
--- a/ssa.h
+++ b/ssa.h
@@ -76,6 +76,7 @@ struct CInst {
CType_t wtype; /* for WARR */
int id;
int is_def;
+ int sysp;
int bret; /* for CALL */
int offset; /* for PUSH */
};