Skip to content

Commit

Permalink
change translate.arrayExp still passtest
Browse files Browse the repository at this point in the history
  • Loading branch information
myhgew committed Apr 12, 2014
1 parent b1581e0 commit 87d4b1a
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 27 deletions.
5 changes: 4 additions & 1 deletion codegen.sml
Original file line number Diff line number Diff line change
Expand Up @@ -539,8 +539,11 @@ struct
assem="#load callersave\n",
lab=Temp.newlabel()}
val result = List.concat(map (codegen newFrame) loadCallerInstructionsList)
val comment' = A.LABEL{
assem="#load callersave finish\n",
lab=Temp.newlabel()}
in
comment::result
comment::result@[comment']
end
fun munchJalLabel() = [A.LABEL{
assem="#call function\n",
Expand Down
16 changes: 9 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, L990
L991:
beq $t1, $t0, L329
L330:
lw $t0, -4($fp)
move $s0, $t0
#save arguments to reg
Expand Down Expand Up @@ -57,10 +57,11 @@ lw $t3, 68($sp)
lw $t2, 64($sp)
lw $t1, 60($sp)
lw $t0, 56($sp)
#load callersave finish
move $t0, $v0
mul $t0, $s0, $t0
move $t0, $t0
L992:
L331:
move $v0, $t0
#load calleesaves:
lw $s7, 52($sp)
Expand All @@ -76,10 +77,10 @@ lw $t0, 0($sp)
move $fp, $t0
addi $sp, $sp, 100
jr $ra
L990:
L329:
li $t0, 1
j L992
L994:
j L331
L333:
.text
tig_main:
#save calleesaves:
Expand Down Expand Up @@ -129,6 +130,7 @@ lw $t3, 68($sp)
lw $t2, 64($sp)
lw $t1, 60($sp)
lw $t0, 56($sp)
#load callersave finish
move $v0, $v0
#load calleesaves:
lw $s7, 52($sp)
Expand All @@ -144,7 +146,7 @@ lw $t0, 0($sp)
move $fp, $t0
addi $sp, $sp, 96
jr $ra
L1002:
L342:



Expand Down
5 changes: 3 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
L1032:
L373:
.text
tig_main:
#save calleesaves:
Expand Down Expand Up @@ -103,6 +103,7 @@ lw $t3, 68($sp)
lw $t2, 64($sp)
lw $t1, 60($sp)
lw $t0, 56($sp)
#load callersave finish
move $v0, $v0
#load calleesaves:
lw $s7, 52($sp)
Expand All @@ -118,7 +119,7 @@ lw $t0, 0($sp)
move $fp, $t0
addi $sp, $sp, 108
jr $ra
L1033:
L374:



Expand Down
16 changes: 9 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, L1061
L1062:
beq $t1, $t0, L403
L404:
lw $t0, -4($fp)
move $s0, $t0
#save arguments to reg
Expand Down Expand Up @@ -57,10 +57,11 @@ lw $t3, 68($sp)
lw $t2, 64($sp)
lw $t1, 60($sp)
lw $t0, 56($sp)
#load callersave finish
move $t0, $v0
mul $t0, $s0, $t0
move $t0, $t0
L1063:
L405:
move $v0, $t0
#load calleesaves:
lw $s7, 52($sp)
Expand All @@ -76,13 +77,13 @@ lw $t0, 0($sp)
move $fp, $t0
addi $sp, $sp, 100
jr $ra
L1061:
L403:
lw $t0, -100($fp)
lw $t0, -4($t0)
addi $t0, $t0, 1
move $t0, $t0
j L1063
L1065:
j L405
L407:
.text
tig_main:
#save calleesaves:
Expand Down Expand Up @@ -135,6 +136,7 @@ lw $t3, 68($sp)
lw $t2, 64($sp)
lw $t1, 60($sp)
lw $t0, 56($sp)
#load callersave finish
move $v0, $v0
#load calleesaves:
lw $s7, 52($sp)
Expand All @@ -150,7 +152,7 @@ lw $t0, 0($sp)
move $fp, $t0
addi $sp, $sp, 100
jr $ra
L1073:
L416:



Expand Down
11 changes: 5 additions & 6 deletions test/test1.tig.s
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ sw $a1, -8($fp)
sw $a2, -12($fp)
sw $a3, -16($fp)
#body:
li $s0, 10
#save arguments to reg
addi $t0, $zero, 10
addi $t0, $t0, 1
move $a0, $t0
addi $a0, $s0, 1
#save arguments to reg
li $a1, 2
#save callersave
Expand All @@ -49,9 +48,9 @@ lw $t3, 68($sp)
lw $t2, 64($sp)
lw $t1, 60($sp)
lw $t0, 56($sp)
#load callersave finish
move $t0, $v0
addi $t0, $zero, 10
sw $t0, 0($t0)
sw $s0, 0($t0)
move $t0, $t0
move $v0, $t0
#load calleesaves:
Expand All @@ -68,7 +67,7 @@ lw $t0, 0($sp)
move $fp, $t0
addi $sp, $sp, 100
jr $ra
L963:
L301:



Expand Down
21 changes: 17 additions & 4 deletions translate.sml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ struct
| Inner of {unique:unit ref,parent:level,frame:Frame.frame}
type access = level * Frame.access


(*helper function*)
fun combineStmListToSEQ stmlist : Tree.stm =
case List.length(stmlist) of
0 => List.hd(stmlist)
| 1 => List.hd(stmlist)
| 2 => Tree.SEQ(List.hd(stmlist),List.nth(stmlist,1))
| _ => Tree.SEQ(List.hd(stmlist),combineStmListToSEQ(List.tl(stmlist)))

(*Getter function*)
fun levelUnique level =
case level of
Expand Down Expand Up @@ -446,16 +455,20 @@ struct
fun arrayExp(initExp, sizeExp) =
let
val r = Temp.newtemp()
val sizeTemp = Temp.newtemp() (*assign temp just to store size*)
val size = unEx sizeExp
val init = unEx initExp

in
Ex(
T.ESEQ(
T.SEQ(
T.MOVE(T.TEMP r, Frame.externalCall("initArray", [T.BINOP(T.PLUS, size, T.CONST(1)), init])),
T.MOVE(T.MEM(T.TEMP r), size)
),
combineStmListToSEQ([
T.MOVE(T.TEMP(sizeTemp), size),
T.MOVE(T.TEMP r, Frame.externalCall("initArray", [T.BINOP(T.PLUS, T.TEMP(sizeTemp), T.CONST(1)), init])),
(*save size information at the first position 0($array) = size*)
T.MOVE(T.MEM(T.TEMP r), T.TEMP(sizeTemp))
]),

T.TEMP r
)
)
Expand Down

0 comments on commit 87d4b1a

Please sign in to comment.