Skip to content

Commit

Permalink
Added procEntryExit 1, 2, and 3 into compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
jake-derry committed Apr 13, 2020
1 parent 096ba48 commit 69affcb
Show file tree
Hide file tree
Showing 15 changed files with 153 additions and 6 deletions.
Binary file modified .cm/amd64-unix/main.sml
Binary file not shown.
Binary file modified IR/.cm/amd64-unix/translate.sml
Binary file not shown.
3 changes: 2 additions & 1 deletion IR/translate.sml
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,9 @@ struct
F.nextFrame ({name = label, formals = []}))
| NONTOP ({unique = _, parent = _, frame = frame'}) => frame'
val trBody = unNx body'
val trBody' = F.procEntryExit1(levelFrame, trBody)
in (* Append to frag list *)
fragList := F.PROC ({body = trBody, frame = levelFrame}) :: (!fragList)
fragList := F.PROC ({body = trBody', frame = levelFrame}) :: (!fragList)
end

fun result () = !fragList
Expand Down
2 changes: 1 addition & 1 deletion assem/.cm/SKEL/frame.sig
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Skeleton 5
d2f2d"Temp"d"Tree"ac"FRAME"h0
d2f3d"Temp"d"Tree"d"Assem"ac"FRAME"h0
Binary file modified assem/.cm/amd64-unix/codegen.sig
Binary file not shown.
Binary file modified assem/.cm/amd64-unix/frame.sig
Binary file not shown.
8 changes: 7 additions & 1 deletion assem/frame.sig
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,11 @@ sig

val printFrame : frame -> unit

val externalCall : string * Tree.exp list -> Tree.exp
val externalCall : string * Tree.exp list -> Tree.exp

val procEntryExit1: frame * Tree.stm -> Tree.stm
val procEntryExit2: frame * Assem.instr list -> Assem.instr list
val procEntryExit3 : frame * Assem.instr list -> {prolog: string,
body: Assem.instr list,
epilog: string}
end
5 changes: 3 additions & 2 deletions main.sml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ struct
val stms = Canon.linearize body
(* val _ = app (fn s => Printtree.printtree(out,s)) stms; *)
val stms' = Canon.traceSchedule(Canon.basicBlocks stms)
val instrs = List.concat(map (MIPSGen.codeGen frame) stms')
val instrs = F.procEntryExit2 (frame, List.concat (map (MIPSGen.codeGen frame) stms'))
val {prolog, body, epilog} = F.procEntryExit3 (frame, instrs)
val format0 = Assem.format(Temp.makestring)
in app (fn i => TextIO.output(out, (format0 i) ^ "\n")) instrs
in (TextIO.output (out, prolog); (app (fn i => TextIO.output(out, (format0 i) ^ "\n")) instrs); TextIO.output (out, epilog))
end
| emitproc out (F.STRING(lab,s)) = TextIO.output(out, (F.string (lab,s)) ^ "\n")

Expand Down
Binary file modified mips/.cm/amd64-unix/mipsframe.sml
Binary file not shown.
Binary file modified mips/.cm/amd64-unix/mipsgen.sml
Binary file not shown.
11 changes: 11 additions & 0 deletions mips/mipsframe.sml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,17 @@ struct

fun procEntryExit1(frame', stm') = stm'

fun procEntryExit2(frame, body) =
body @
[A.OPER{assem="",
src =[ZERO,RA,SP]@calleesaves,
dst=[], jump=SOME[]}]

fun procEntryExit3({name, formals, numLocals, curOffset}, body) =
{prolog = "PROCEDURE " ^ Symbol.name name ^ "\n",
body = body,
epilog = "END " ^ Symbol.name name ^ "\n"}

fun exp (fraccess, frameaddr) =
case fraccess of
InFrame offset => Tree.MEM(Tree.BINOP(Tree.PLUS, frameaddr, Tree.CONST offset))
Expand Down
32 changes: 32 additions & 0 deletions testcases/test1.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
PROCEDURE L0
L4:
addi t146, t124, ~4
move t145, t146
move t147, t106
move t148, t107
move t149, t108
move t150, t109
move t151, t110
move t152, t111
move t153, t112
move t154, t113
addi t155, r0, 10
move t102, t155
addi t156, r0, 0
move t103, t156
jal initArray
move t113, t154
move t112, t153
move t111, t152
move t110, t151
move t109, t150
move t108, t149
move t107, t148
move t106, t147
move t144, t125
sw t145, 0(t144)
lw t157, ~4(t124)
jr L3
L3:

END L0
77 changes: 77 additions & 0 deletions testcases/test19.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
L13:
move t165, t106
move t166, t107
move t167, t108
move t168, t109
move t169, t110
move t170, t111
move t171, t112
move t172, t113
move t102, t124
addi t173, r0, 0
move t103, t173
la t174, L5
move t104, t174
jal L2
move t113, t172
move t112, t171
move t111, t170
move t110, t169
move t109, t168
move t108, t167
move t107, t166
move t106, t165
jr L12
L12:
str2
L15:
move t175, t106
move t176, t107
move t177, t108
move t178, t109
move t179, t110
move t180, t111
move t181, t112
move t182, t113
move t102, t124
addi t183, t133, 1
move t103, t183
jal L1
move t113, t182
move t112, t181
move t111, t180
move t110, t179
move t109, t178
move t108, t177
move t107, t176
move t106, t175
jr L14
L14:
L17:
move t184, t106
move t185, t107
move t186, t108
move t187, t109
move t188, t110
move t189, t111
move t190, t112
move t191, t113
move t102, t124
addi t192, r0, 0
move t103, t192
la t193, L3
move t104, t193
jal L2
move t113, t191
move t112, t190
move t111, t189
move t110, t188
move t109, t187
move t108, t186
move t107, t185
move t106, t184
la t194, L4
jr L16
L16:

str
19 changes: 19 additions & 0 deletions testcases/test37.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
L11:
addi t147, r0, 0
sw t124, ~4(t147)
addi t148, r0, 1
sw t124, ~8(t148)
lw t150, ~4(t124)
lw t151, ~8(t124)
add t149, t150, t151
jr L10
L10:
L13:
addi t152, r0, 0
sw t124, ~4(t152)
addi t153, r0, 1
sw t124, ~8(t153)
lw t155, ~8(t124)
addi t154, t155, 0
jr L12
L12:
2 changes: 1 addition & 1 deletion testcases/test37.tig
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
variables with the same name. The second one hides the first. */
let
var a := 0
var a := 1
var b := 1
in
a + b
end

0 comments on commit 69affcb

Please sign in to comment.