aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib.s89
-rw-r--r--mips.c15
-rw-r--r--printf.c3
-rw-r--r--ssa.c12
4 files changed, 73 insertions, 46 deletions
diff --git a/lib.s b/lib.s
index 5ba5563..f97ebc9 100644
--- a/lib.s
+++ b/lib.s
@@ -2,39 +2,41 @@ _func_printf:
addiu $sp, $sp, -64
sw $31, 60($sp) #printf
# load fmt_0
- lw $8, 64($sp) #fmt
# load arg_0
# load ch_0
- lb $9, 12($sp) #ch
+ lb $8, 12($sp) #ch
# load x_0
- lw $10, 4($sp) #x
+ lw $9, 4($sp) #x
# load len_0
- lw $11, 8($sp) #len
+ lw $10, 8($sp) #len
# t0 = addr fmt_0
- addiu $12, $sp, 64
+ addiu $11, $sp, 64
# arg_1 = t0 + 4
- addiu $12, $12, 4
+ addiu $11, $11, 4
# goto __L2
j __L2
__L1:
# t3 = ch_2 == 37
li $3, 37
- seq $13, $9, $3
+ seq $12, $8, $3
# if not (t3) goto __L20
- beqz $13, __L20
+ beqz $12, __L20
# fmt_4 = fmt_1 + 1
- addiu $8, $8, 1
+ lw $2, 64($sp) #fmt
+ addiu $2, $2, 1
+ sw $2, 64($sp) #fmt
# ch_4 = fmt_4[0]
- lb $9, 0($8)
+ lw $2, 64($sp) #fmt
+ lb $8, 0($2)
# t5 = ch_4 == 100
li $3, 100
- seq $13, $9, $3
+ seq $12, $8, $3
# if not (t5) goto __L6
- beqz $13, __L6
+ beqz $12, __L6
# t7 = arg_2[0]
- lw $13, 0($12)
+ lw $12, 0($11)
# push t7
- sw $13, 0($sp) # push
+ sw $12, 0($sp) # push
# t6 = call __print_int
jal _func___print_int
# goto __L19
@@ -42,13 +44,13 @@ __L1:
__L6:
# t8 = ch_4 == 99
li $3, 99
- seq $13, $9, $3
+ seq $12, $8, $3
# if not (t8) goto __L8
- beqz $13, __L8
+ beqz $12, __L8
# t10 = arg_2[0]
- lw $13, 0($12)
+ lw $12, 0($11)
# push t10
- sw $13, 0($sp) # push
+ sw $12, 0($sp) # push
# t9 = call __print_char
jal _func___print_char
# goto __L19
@@ -56,49 +58,49 @@ __L6:
__L8:
# t11 = ch_4 == 115
li $3, 115
- seq $13, $9, $3
+ seq $12, $8, $3
# if not (t11) goto __L10
- beqz $13, __L10
+ beqz $12, __L10
# t13 = arg_2[0]
- lw $13, 0($12)
+ lw $12, 0($11)
# push t13
- sw $13, 0($sp) # push
+ sw $12, 0($sp) # push
# t12 = call __print_string
jal _func___print_string
# goto __L19
j __L19
__L10:
# x_4 = arg_2[0]
- lw $10, 0($12)
+ lw $9, 0($11)
# t15 = x_4 == 0
li $3, 0
- seq $11, $10, $3
+ seq $10, $9, $3
# if not (t15) goto __L12
- beqz $11, __L12
+ beqz $10, __L12
# len_11 = 1
li $2, 1
- move $11 $2
+ move $10 $2
# goto __L15
j __L15
__L12:
# len_8 = 0
li $2, 0
- move $11 $2
+ move $10 $2
# goto __L14
j __L14
__L13:
# x_7 = x_6 / 10
li $3, 10
- divu $10, $10, $3
+ divu $9, $9, $3
# len_10 = len_9 + 1
- addiu $11, $11, 1
+ addiu $10, $10, 1
__L14:
# if (x_6) goto __L13
- bnez $10, __L13
+ bnez $9, __L13
__L15:
# len_5 = 4 - len_4
li $2, 4
- subu $11, $2, $11
+ subu $10, $2, $10
# goto __L17
j __L17
__L16:
@@ -109,36 +111,41 @@ __L16:
jal _func___print_char
# len_7 = len_6 - 1
li $3, 1
- subu $11, $11, $3
+ subu $10, $10, $3
__L17:
# if (len_6) goto __L16
- bnez $11, __L16
+ bnez $10, __L16
# t19 = arg_2[0]
- lw $13, 0($12)
+ lw $12, 0($11)
# push t19
- sw $13, 0($sp) # push
+ sw $12, 0($sp) # push
# t18 = call __print_int
jal _func___print_int
# fmt_6 = fmt_4 + 2
- addiu $8, $8, 2
+ lw $2, 64($sp) #fmt
+ addiu $2, $2, 2
+ sw $2, 64($sp) #fmt
__L19:
# arg_4 = arg_2 + 4
- addiu $12, $12, 4
+ addiu $11, $11, 4
# goto __L21
j __L21
__L20:
# push ch_2
- sw $9, 0($sp) # push
+ sw $8, 0($sp) # push
# t20 = call __print_char
jal _func___print_char
__L21:
# fmt_3 = fmt_2 + 1
- addiu $8, $8, 1
+ lw $2, 64($sp) #fmt
+ addiu $2, $2, 1
+ sw $2, 64($sp) #fmt
__L2:
# ch_2 = fmt_1[0]
- lb $9, 0($8)
+ lw $2, 64($sp) #fmt
+ lb $8, 0($2)
# if (ch_2) goto __L1
- bnez $9, __L1
+ bnez $8, __L1
_ret_printf:
lw $31, 60($sp)
addiu $sp, $sp, 64
diff --git a/mips.c b/mips.c
index 6f85c1b..5fa5831 100644
--- a/mips.c
+++ b/mips.c
@@ -254,6 +254,7 @@ void mips_func_end() {
void mips_generate() {
CBlock_t p;
+ /* int arg_cnt = 0; */
mips_space_alloc();
if (strcmp(func->name, "main"))
printf("_func_%s:\n",func->name);
@@ -275,7 +276,9 @@ void mips_generate() {
switch (i->op)
{
case LOAD:
- if (i->dest->kind == VAR && i->dest->reg > 0)
+ if (i->dest->kind == VAR &&
+ i->dest->reg > 0) /* &&
+ i->dest->info.var->loc >= 0) */
mips_load(i->dest->reg, i->dest);
break;
case MOVE:
@@ -364,8 +367,18 @@ void mips_generate() {
case PUSH:
{
int rs = mips_to_reg(i->src1, reg_v0);
+ /*
+ if (arg_cnt < 4)
+ {
+ printf("\tmove $%d, $%d\n", arg_cnt + 4, rs);
+ }
+ else
+ {
+ */
/* TODO: push struct */
printf("\tsw $%d, %d($sp) # push\n", rs, i->offset);
+ /* }
+ arg_cnt++; */
}
break;
case CALL:
diff --git a/printf.c b/printf.c
index 488c0d5..6d3330b 100644
--- a/printf.c
+++ b/printf.c
@@ -1,5 +1,6 @@
int printf(char *fmt) {
char *arg, ch;
+ int len, x;
arg = (int)&fmt + sizeof(char*);
while ((ch = *fmt))
{
@@ -14,7 +15,7 @@ int printf(char *fmt) {
__print_string(*(char **)arg);
else
{
- int len, x = *(int *)arg;
+ x = *(int *)arg;
if (!x) len = 1;
else
for (len = 0; x; x /= 10, len++);
diff --git a/ssa.c b/ssa.c
index 4b6fe60..6fcc653 100644
--- a/ssa.c
+++ b/ssa.c
@@ -2003,6 +2003,12 @@ void register_alloc() {
for (p = raw_defs; p; p = p->next)
{
COpr_t opr = p->opr;
+ /*
+ if (opr->info.var->loc < 0)
+ {
+ opr->reg = 3 - opr->info.var->loc;
+ continue;
+ } */ /* arguments */
opr->reg = -2;
if (opr->par != opr) continue;
if (cinterv_repr(opr)->range)
@@ -2283,16 +2289,16 @@ void ssa_func(CType_t func) {
CPSet_t vs = cpset_create(), avs = cpset_create();
CVList_t vars = NULL;
COList_t all_oprs = NULL;
- CVar_t pr;
+ /* CVar_t pr; */
int i;
cfg_clear();
dtree_clear();
ssa_comp(func->rec.func.body, entry, NULL);
+ /*
for (i = 0, pr = func->rec.func.params;
i < 4 && pr;
i++, pr = pr->next)
- {
- }
+ pr->loc = -(i + 1); */ /* mark arguments */
for (p = entry; p; p = p->next)
{