diff options
author | bd-912 <bdunahu@colostate.edu> | 2024-04-24 21:05:15 -0600 |
---|---|---|
committer | bd-912 <bdunahu@colostate.edu> | 2024-04-24 21:05:15 -0600 |
commit | 62091005231095abbf8e2cebbfce708815cb63f0 (patch) | |
tree | 5186bf7db88b20704a48ab14413349291675ea82 /vaporize/library/VaporizeVisitor.java | |
parent | 0bbc4cb511bd90cebf94ccfcfce5ff8983ebb918 (diff) |
Added VaporizeVisitor, with VAssign, VMemRead, and VMemWrite
Diffstat (limited to 'vaporize/library/VaporizeVisitor.java')
-rw-r--r-- | vaporize/library/VaporizeVisitor.java | 145 |
1 files changed, 145 insertions, 0 deletions
diff --git a/vaporize/library/VaporizeVisitor.java b/vaporize/library/VaporizeVisitor.java new file mode 100644 index 0000000..11f0bc5 --- /dev/null +++ b/vaporize/library/VaporizeVisitor.java @@ -0,0 +1,145 @@ +package vaporize.library; + +import cs132.vapor.ast.*; +import misc.*; + +import java.util.*; + +public class VaporizeVisitor extends VInstr.VisitorP<LIRDict, RuntimeException> { + + private ArrayList<String> vaporm; + + public VaporizeVisitor(VaporProgram vp, ArrayList<String> vaporm, ArrayList<LIRDict> interval_list) { + this.vaporm = vaporm; + + // is it possible for interval_list and the + // function in vp to be out of order? + for (int i = 0; i < vp.functions.length; ++i) { + this.addVaporm(String.format("func %s [in %d, out %d, local %d]", + vp.functions[i].ident, 0, 0, interval_list.get(i).getSpilledNum())); + for (VInstr s : vp.functions[i].body) + s.accept(interval_list.get(i), this); + } + } + + public ArrayList<String> getVaporm() { + return this.vaporm; + } + + public void addVaporm(String str) { + MinimalLogger.info(String.format("Adding string:\n%s", + str)); + this.vaporm.add(str); + } + + public void visit(LIRDict d, VAssign n) throws RuntimeException { + MinimalLogger.info(String.format("->%s (%s)", + n.getClass().getSimpleName(), + n.sourcePos.toString())); + /////////////////////////////////////////////////////////////// + String dest = d.getInterval(((VVarRef.Local) n.dest).ident).getAssignedRegister(); + String source = (n.source instanceof VVarRef.Local) ? + d.getInterval(n.source.toString()).getAssignedRegister() + : n.source.toString(); + this.addVaporm(String.format(" %s = %s", + dest, source)); + /////////////////////////////////////////////////////////////// + MinimalLogger.info(String.format("<-%s (%s)", + n.getClass().getSimpleName(), + n.sourcePos.toString())); + } + + public void visit(LIRDict d, VCall n) throws RuntimeException { + MinimalLogger.info(String.format("->%s (%s)", + n.getClass().getSimpleName(), + n.sourcePos.toString())); + /////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////// + MinimalLogger.info(String.format("<-%s (%s)", + n.getClass().getSimpleName(), + n.sourcePos.toString())); + } + + public void visit(LIRDict d, VBuiltIn n) throws RuntimeException { + MinimalLogger.info(String.format("->%s (%s)", + n.getClass().getSimpleName(), + n.sourcePos.toString())); + /////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////// + MinimalLogger.info(String.format("<-%s (%s)", + n.getClass().getSimpleName(), + n.sourcePos.toString())); + } + + public void visit(LIRDict d, VMemWrite n) throws RuntimeException { + MinimalLogger.info(String.format("->%s (%s)", + n.getClass().getSimpleName(), + n.sourcePos.toString())); + /////////////////////////////////////////////////////////////// + String dest = d.getInterval(((VMemRef.Global) n.dest).base.toString()) + .getAssignedRegister(); + String source = (n.source instanceof VVarRef.Local) ? + d.getInterval(n.source.toString()).getAssignedRegister() : + n.source.toString(); + int byteOffset = ((VMemRef.Global) n.dest).byteOffset; + this.addVaporm(String.format(" [%s+%d] = %s", + dest, byteOffset, source)); + /////////////////////////////////////////////////////////////// + MinimalLogger.info(String.format("<-%s (%s)", + n.getClass().getSimpleName(), + n.sourcePos.toString())); + } + + public void visit(LIRDict d, VMemRead n) throws RuntimeException { + MinimalLogger.info(String.format("->%s (%s)", + n.getClass().getSimpleName(), + n.sourcePos.toString())); + /////////////////////////////////////////////////////////////// + String dest = (n.dest instanceof VVarRef.Local) ? + d.getInterval(n.dest.toString()).getAssignedRegister() : + n.dest.toString(); + String source = d.getInterval(((VMemRef.Global) n.source).base.toString()) + .getAssignedRegister(); + int byteOffset = ((VMemRef.Global) n.source).byteOffset; + this.addVaporm(String.format(" %s = [%s+%d]", + dest, source, byteOffset)); + /////////////////////////////////////////////////////////////// + MinimalLogger.info(String.format("<-%s (%s)", + n.getClass().getSimpleName(), + n.sourcePos.toString())); + } + + public void visit(LIRDict d, VBranch n) throws RuntimeException { + MinimalLogger.info(String.format("->%s (%s)", + n.getClass().getSimpleName(), + n.sourcePos.toString())); + /////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////// + MinimalLogger.info(String.format("<-%s (%s)", + n.getClass().getSimpleName(), + n.sourcePos.toString())); + } + + public void visit(LIRDict d, VGoto n) throws RuntimeException { + MinimalLogger.info(String.format("->%s (%s)", + n.getClass().getSimpleName(), + n.sourcePos.toString())); + /////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////// + MinimalLogger.info(String.format("<-%s (%s)", + n.getClass().getSimpleName(), + n.sourcePos.toString())); + } + + public void visit(LIRDict d, VReturn n) throws RuntimeException { + MinimalLogger.info(String.format("->%s (%s)", + n.getClass().getSimpleName(), + n.sourcePos.toString())); + /////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////// + MinimalLogger.info(String.format("<-%s (%s)", + n.getClass().getSimpleName(), + n.sourcePos.toString())); + } + +} |