aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile16
-rw-r--r--const.h1
-rw-r--r--semantics.c12
-rw-r--r--semantics.h9
-rw-r--r--ssa.c29
5 files changed, 38 insertions, 29 deletions
diff --git a/Makefile b/Makefile
index 7d10bcb..b5d63a1 100644
--- a/Makefile
+++ b/Makefile
@@ -1,3 +1,9 @@
+ifeq ($(mode), release)
+ CFLAGS = -O2 -Wall
+else
+ CFLAGS = -g -Wall -Wextra -DCIBIC_DEBUG
+endif
+
all: cibic
db:
@@ -12,15 +18,15 @@ lex.yy.o: lex.yy.c cibic.tab.c
cibic.tab.o: cibic.tab.c
gcc -c cibic.tab.c
main.o: main.c
- gcc -c main.c -g -Wall -Wextra
+# gcc -c main.c -g -Wall -Wextra
ast.o: ast.c ast.h
- gcc -c ast.c -g -Wall -Wextra -DCIBIC_DEBUG
+# gcc -c ast.c -g -Wall -Wextra -DCIBIC_DEBUG
semantics.o: semantics.c semantics.h
- gcc -c semantics.c -g -Wall -Wextra -DCIBIC_DEBUG
+# gcc -c semantics.c -g -Wall -Wextra -DCIBIC_DEBUG
ssa.o: ssa.c ssa.h
- gcc -c ssa.c -g -Wall -Wextra -DCIBIC_DEBUG
+# gcc -c ssa.c -g -Wall -Wextra -DCIBIC_DEBUG
mips.o: mips.c mips.h
- gcc -c mips.c -g -Wall -Wextra -DCIBIC_DEBUG
+# gcc -c mips.c -g -Wall -Wextra -DCIBIC_DEBUG
lex.yy.c: cibic.l
flex cibic.l
cibic.tab.c: cibic.y
diff --git a/const.h b/const.h
index 05f12d0..0e307bc 100644
--- a/const.h
+++ b/const.h
@@ -35,4 +35,5 @@ enum {
#define PTR_SIZE 4
#define FLAG_FUNC_CHK (1 << 0)
#define FLAG_FUNC_DEF (1 << 1)
+
#endif
diff --git a/semantics.c b/semantics.c
index f8fffcc..eb584a7 100644
--- a/semantics.c
+++ b/semantics.c
@@ -1256,7 +1256,7 @@ ExpType semantics_exp(CNode *p, CScope_t scope) {
res.type = type;
res.lval = 0;
p->ext.is_const = 1;
- p->ext.const_val = (long)cstr;
+ p->ext.const_val = (uintptr_t)cstr;
}
break;
case EXP:
@@ -1773,12 +1773,12 @@ void ctype_print_(CType_t ct, int lvl, CPSet_t visited) {
fprintf(stderr, "[%s@%lx:{name:%s}",
ct->type == CSTRUCT ? "struct" : "union",
(size_t)ct, ct->name);
- if (cpset_belongs(visited, (long)ct))
+ if (cpset_belongs(visited, (uintptr_t)ct))
{
fprintf(stderr, "]\n");
return;
}
- cpset_insert(visited, (long)ct);
+ cpset_insert(visited, (uintptr_t)ct);
fprintf(stderr, "{size:%d}", ct->size);
fprintf(stderr, "{fields:");
if (f)
@@ -2009,7 +2009,7 @@ void cpset_destroy(CPSet_t cps) {
free(cps);
}
-int cpset_insert(CPSet_t cps, long key) {
+int cpset_insert(CPSet_t cps, uintptr_t key) {
unsigned int hv = key % MAX_TABLE_SIZE;
CPNode *p = cps->head[hv], *np;
for (; p; p = p->next)
@@ -2022,7 +2022,7 @@ int cpset_insert(CPSet_t cps, long key) {
return 1;
}
-void cpset_erase(CPSet_t cps, long key) {
+void cpset_erase(CPSet_t cps, uintptr_t key) {
unsigned int hv = key % MAX_TABLE_SIZE;
int flag = 0;
CPNode *p = cps->head[hv], *pp = NULL;
@@ -2040,7 +2040,7 @@ void cpset_erase(CPSet_t cps, long key) {
free(p);
}
-int cpset_belongs(CPSet_t cps, long key) {
+int cpset_belongs(CPSet_t cps, uintptr_t key) {
unsigned int hv = key % MAX_TABLE_SIZE;
CPNode *p = cps->head[hv];
for (; p; p = p->next)
diff --git a/semantics.h b/semantics.h
index c710304..c6b3ff8 100644
--- a/semantics.h
+++ b/semantics.h
@@ -1,5 +1,6 @@
#ifndef SEMANTICS_H
#define SEMANTICS_H
+#include <stdint.h>
#include "const.h"
typedef struct CNode CNode;
@@ -196,16 +197,16 @@ enum DefState{
typedef struct CPNode CPNode;
typedef struct CPSet {
struct CPNode {
- long key;
+ uintptr_t key;
CPNode *next;
} *head[MAX_TABLE_SIZE];
} CPSet;
typedef CPSet *CPSet_t;
CPSet_t cpset_create(void);
-int cpset_insert(CPSet_t cps, long key);
-int cpset_belongs(CPSet_t cps, long key);
-void cpset_erase(CPSet_t cps, long key);
+int cpset_insert(CPSet_t cps, uintptr_t key);
+int cpset_belongs(CPSet_t cps, uintptr_t key);
+void cpset_erase(CPSet_t cps, uintptr_t key);
void cpset_destroy(CPSet_t cps);
int is_identifier(const char *name);
diff --git a/ssa.c b/ssa.c
index d903bec..ff7c0a7 100644
--- a/ssa.c
+++ b/ssa.c
@@ -1502,7 +1502,7 @@ void insert_phi(CVList_t vars) {
{
CBlock_t y = i->cblk;
CPSet_t phiy = phi[y->id];
- if (!cpset_belongs(phiy, (long)var))
+ if (!cpset_belongs(phiy, (uintptr_t)var))
{
CPhi_t phi = NEW(CPhi);
CBList_t ndef;
@@ -1512,7 +1512,7 @@ void insert_phi(CVList_t vars) {
phi->dest->type = var->type;
phi->oprs = (COpr_t *)malloc(sizeof(COpr_t) * y->pred);
cblock_pappend(y, phi);
- cpset_insert(phiy, (long)var);
+ cpset_insert(phiy, (uintptr_t)var);
ndef = NEW(CBList);
ndef->cblk = y;
ndef->next = def;
@@ -1757,18 +1757,18 @@ void build_intervals(void) {
COpr_t opr = i->oprs[t];
if (opr &&
(opr->kind == VAR ||
- opr->kind == TMP) && !cpset_belongs(curlive, (long)opr))
+ opr->kind == TMP) && !cpset_belongs(curlive, (uintptr_t)opr))
{
COList_t np = NEW(COList);
np->opr = opr;
np->next = live[id];
live[id] = np;
- cpset_insert(curlive, (long)opr);
+ cpset_insert(curlive, (uintptr_t)opr);
}
}
for (; p; p = p->next)
- if (cpset_belongs(liveset[sid], (long)p->opr) &&
- cpset_insert(curlive, (long)p->opr))
+ if (cpset_belongs(liveset[sid], (uintptr_t)p->opr) &&
+ cpset_insert(curlive, (uintptr_t)p->opr))
{
COList_t np = NEW(COList);
np->opr = p->opr;
@@ -1792,7 +1792,7 @@ void build_intervals(void) {
i->dest->kind == TMP) && i->op != WARR) /* def */
{
i->is_def = 1;
- cpset_erase(curlive, (long)i->dest);
+ cpset_erase(curlive, (uintptr_t)i->dest);
}
else
{
@@ -1805,13 +1805,13 @@ void build_intervals(void) {
COpr_t opr = oprs[t];
if (opr &&
(opr->kind == VAR ||
- opr->kind == TMP) && !cpset_belongs(curlive, (long)opr))
+ opr->kind == TMP) && !cpset_belongs(curlive, (uintptr_t)opr))
{
COList_t np = NEW(COList);
np->opr = opr;
np->next = live[id];
live[id] = np;
- cpset_insert(curlive, (long)opr);
+ cpset_insert(curlive, (uintptr_t)opr);
add_range(opr, b, i->id);
}
}
@@ -1820,13 +1820,13 @@ void build_intervals(void) {
{
CPhi_t ph = b->phis, i;
for (i = ph->prev; i != ph; i = i->prev)
- cpset_erase(curlive, (long)i->dest);
+ cpset_erase(curlive, (uintptr_t)i->dest);
}
if (loop_tail[id] != -1)
{
COList_t p;
for (p = live[id]; p; p = p->next)
- if (cpset_belongs(curlive, (long)p->opr))
+ if (cpset_belongs(curlive, (uintptr_t)p->opr))
add_range_(p->opr, b->first, blks[loop_tail[id]]->last + 1);
}
}
@@ -2130,8 +2130,9 @@ void register_alloc(void) {
COpr_t opr = unhandled[i];
CRange_t p;
copr_print(stderr, opr);
+ fprintf(stderr, ":");
for (p = opr->range; p; p = p->next)
- fprintf(stderr, ": [%d, %d)", p->l, p->r);
+ fprintf(stderr, " [%d, %d)", p->l, p->r);
fprintf(stderr, " (begin: %d, end: %d, weight: %d, reg: %d)\n",
opr->begin, opr->end, opr->info.var->weight, opr->reg);
}
@@ -2620,7 +2621,7 @@ void deadcode_elimination() {
void ssa_func(CType_t func) {
#define OPRS_ADD(_opr) \
do { \
- if (cpset_insert(avs, (long)((_opr)->info.var))) \
+ if (cpset_insert(avs, (uintptr_t)((_opr)->info.var))) \
{ \
COList_t n = NEW(COList); \
n->next = oprs; \
@@ -2631,7 +2632,7 @@ void ssa_func(CType_t func) {
#define VS_ADD(_d) \
do { \
- if (cpset_insert(vs, (long)(_d))) \
+ if (cpset_insert(vs, (uintptr_t)(_d))) \
{ \
CVList_t n = NEW(CVList); \
n->next = vars; \