Skip to content

Commit

Permalink
bug with recordExp
Browse files Browse the repository at this point in the history
  • Loading branch information
myhgew committed Apr 13, 2014
1 parent d96e979 commit e5a8434
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 37 deletions.
14 changes: 7 additions & 7 deletions passtest/test4.tig.s
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ sw $a3, -16($fp)
#body:
lw $t1, -4($fp)
addi $t0, $zero, 0
beq $t1, $t0, L50
L51:
beq $t1, $t0, L280
L281:
lw $t0, -4($fp)
move $s0, $t0
#save arguments to reg
Expand Down Expand Up @@ -61,7 +61,7 @@ lw $t0, 56($sp)
move $t0, $v0
mul $t0, $s0, $t0
move $t0, $t0
L52:
L282:
move $v0, $t0
#load calleesaves:
lw $s7, 52($sp)
Expand All @@ -77,10 +77,10 @@ lw $t0, 0($sp)
move $fp, $t0
addi $sp, $sp, 100
jr $ra
L50:
L280:
li $t0, 1
j L52
L54:
j L282
L284:
.text
tig_main:
#save calleesaves:
Expand Down Expand Up @@ -146,7 +146,7 @@ lw $t0, 0($sp)
move $fp, $t0
addi $sp, $sp, 96
jr $ra
L63:
L293:



Expand Down
4 changes: 2 additions & 2 deletions passtest/testSL1.tig.s
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ lw $t0, 0($sp)
move $fp, $t0
addi $sp, $sp, 100
jr $ra
L94:
L324:
.text
tig_main:
#save calleesaves:
Expand Down Expand Up @@ -119,7 +119,7 @@ lw $t0, 0($sp)
move $fp, $t0
addi $sp, $sp, 108
jr $ra
L95:
L325:



Expand Down
14 changes: 7 additions & 7 deletions passtest/testSL2.tig.s
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ sw $a3, -16($fp)
#body:
lw $t1, -4($fp)
addi $t0, $zero, 0
beq $t1, $t0, L124
L125:
beq $t1, $t0, L354
L355:
lw $t0, -4($fp)
move $s0, $t0
#save arguments to reg
Expand Down Expand Up @@ -61,7 +61,7 @@ lw $t0, 56($sp)
move $t0, $v0
mul $t0, $s0, $t0
move $t0, $t0
L126:
L356:
move $v0, $t0
#load calleesaves:
lw $s7, 52($sp)
Expand All @@ -77,13 +77,13 @@ lw $t0, 0($sp)
move $fp, $t0
addi $sp, $sp, 100
jr $ra
L124:
L354:
lw $t0, -100($fp)
lw $t0, -4($t0)
addi $t0, $t0, 1
move $t0, $t0
j L126
L128:
j L356
L358:
.text
tig_main:
#save calleesaves:
Expand Down Expand Up @@ -152,7 +152,7 @@ lw $t0, 0($sp)
move $fp, $t0
addi $sp, $sp, 100
jr $ra
L137:
L367:



Expand Down
17 changes: 7 additions & 10 deletions test/test3.tig.s
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
.data
L22: .asciiz "Somebody"
L460: .asciiz "Somebody"
.data
L19: .asciiz "Nobody"
L457: .asciiz "Nobody"
.data
L18: .asciiz "Nobody"
L456: .asciiz "Nobody"
.text
tig_main:
#save calleesaves:
Expand Down Expand Up @@ -53,16 +53,13 @@ lw $t1, 60($sp)
lw $t0, 56($sp)
#load callersave finish
move $t2, $v0
L20:
addi $t1, $zero, 4
addi $t0, $zero, 0
mul $t0, $t1, $t0
sub $t0, $t2, $t0
sw $s0, 0($t0)
addi $t1, $zero, 1
addi $t0, $zero, 2
blt $t1, $t0, L20
L21:
move $t0, $t0
la $t0, L457
sw $t0, 0($t0)
move $t2, $t2
addi $t1, $zero, 0
addi $t0, $zero, 4
Expand All @@ -84,7 +81,7 @@ lw $t0, 0($sp)
move $fp, $t0
addi $sp, $sp, 100
jr $ra
L23:
L461:



Expand Down
46 changes: 35 additions & 11 deletions translate.sml
Original file line number Diff line number Diff line change
Expand Up @@ -479,32 +479,56 @@ struct
(*no need for boundary check*)
fun recordExp(num, valExpList) =
let
(*这个不对 因为这是在SML计算 实际要用一个TEMP index在MIPS里面计算*)
(*或者把所有valExpList的项都输出来*)
val count = ref 0

val alloc = Temp.newlabel()
val done = Temp.newlabel()
val r = Temp.newtemp()

val index = Temp.newtemp()
(*val offset = Temp.newtemp()*)
(*val currTempToSave = Temp.newtemp()*)
val currTempToSave = Temp.newtemp()
val currTemp = Temp.newtemp()

fun initField(resultList, index) =
let
val caculateTempToSave = T.MOVE(T.TEMP currTempToSave, T.BINOP(T.MINUS, T.TEMP r, T.BINOP(T.MUL, T.CONST(wordSize), T.CONST(index))))
val getCurrField = T.MOVE(T.TEMP(currTemp) ,unEx(List.nth(valExpList, index)))
val save = T.MOVE(T.MEM(T.TEMP currTempToSave), T.TEMP currTemp)
val result = [caculateTempToSave,getCurrField,save]
in
if index = num-1
then resultList
else initField(resultList@result,index+1)
end
in
Ex(
T.ESEQ(
combineStmListToSEQ([
T.MOVE(T.TEMP r, Frame.externalCall("allocRecord", [T.CONST(num)])),
(*init all fields until done*)
T.LABEL alloc,

T.MOVE(T.MEM(T.BINOP(T.MINUS, T.TEMP r, T.BINOP(T.MUL, T.CONST(wordSize), T.CONST(!count)))), unEx (List.nth(valExpList, !count))),
combineStmListToSEQ(
[T.MOVE(T.TEMP r, Frame.externalCall("allocRecord", [T.CONST(num)]))]
@
initField([],0)





(*T.LABEL alloc,*)

(*T.MOVE(T.MEM(T.BINOP(T.MINUS, T.TEMP r, T.BINOP(T.MUL, T.CONST(wordSize), T.CONST(!count)))), unEx (List.nth(valExpList, !count))),*)

(*caculate temp to save*)
(*T.MOVE(T.TEMP currTempToSave, T.BINOP(T.MINUS, T.TEMP r, T.BINOP(T.MUL, T.CONST(wordSize), T.CONST(!count)))),*)
(*update the field*)
(*T.MOVE(T.MEM(T.TEMP currTempToSave), unEx(List.nth(valExpList, !count))),*)
(*T.MOVE(T.TEMP(currTemp) ,unEx(List.nth(valExpList, !count))),*)
(*T.MOVE(T.MEM(T.TEMP currTempToSave), T.TEMP currTemp),*)

T.CJUMP(T.LT, T.CONST(count:=(!count)+1; !count), T.CONST(num), alloc, done),
T.LABEL done
(*T.CJUMP(T.LT, T.CONST(count:=(!count)+1; !count), T.CONST(num), alloc, done),*)
(*T.LABEL done*)

]),
),
T.TEMP r
)
)
Expand Down

0 comments on commit e5a8434

Please sign in to comment.