diff options
Diffstat (limited to 'condense/CondenseVisitor.java')
-rw-r--r-- | condense/CondenseVisitor.java | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/condense/CondenseVisitor.java b/condense/CondenseVisitor.java index a5d742c..a35699f 100644 --- a/condense/CondenseVisitor.java +++ b/condense/CondenseVisitor.java @@ -17,6 +17,13 @@ public class CondenseVisitor extends VInstr.Visitor<RuntimeException>{ this.vaporm = vaporm; this.mips = new ArrayList<String>(); + // preamble + this.mips.add(0, ".data"); + this.addMIPS(".text"); + this.addMIPS("jal Main"); + this.addMIPS("li $v0 10"); + this.addMIPS("syscall"); + for (int i = 0; i < vp.functions.length; ++i) { this.curr = new StackHelper(vp.functions[i].stack); this.addMIPS(vp.functions[i].ident+":"); @@ -47,6 +54,30 @@ public class CondenseVisitor extends VInstr.Visitor<RuntimeException>{ this.curr.getFrameSize())); this.addMIPS(" jr $ra"); } + + this.addMIPS("_print:"); + this.addMIPS(" li $v0 1 # syscall: print integer"); + this.addMIPS(" syscall"); + this.addMIPS(" la $a0 _newline"); + this.addMIPS(" li $v0 4 # syscall: print string"); + this.addMIPS(" syscall"); + this.addMIPS(" jr $ra"); + + this.addMIPS("_error:"); + this.addMIPS(" li $v0 4 # syscall: print string"); + this.addMIPS(" syscall"); + this.addMIPS(" li $v0 10 # syscall: exit"); + this.addMIPS(" syscall"); + + this.addMIPS("_heapAlloc:"); + this.addMIPS(" li $v0 9 # syscall: sbrk"); + this.addMIPS(" syscall"); + this.addMIPS(" jr $ra"); + + this.addMIPS(".data"); + this.addMIPS(".align 0"); + this.addMIPS("_newline: .asciiz \"\\n\""); + this.addMIPS("_str0: .asciiz \"null pointer\\n\""); } public ArrayList<String> getMIPS() { |