summaryrefslogtreecommitdiff
path: root/Homework/cs5300/compiler/p5-compiler/submit/MIPSResult.java
diff options
context:
space:
mode:
authorElizabeth Alexander Hunt <me@liz.coffee>2026-07-02 11:55:17 -0700
committerElizabeth Alexander Hunt <me@liz.coffee>2026-07-02 11:55:17 -0700
commit6bf4b90c90f15f4ab60833bddf5b5756d1a6b1f6 (patch)
treeed97e39ec77c5231ffd2c394493e68d00ddac5a4 /Homework/cs5300/compiler/p5-compiler/submit/MIPSResult.java
downloadmisc-undergrad-main.tar.gz
misc-undergrad-main.zip
Diffstat (limited to 'Homework/cs5300/compiler/p5-compiler/submit/MIPSResult.java')
-rw-r--r--Homework/cs5300/compiler/p5-compiler/submit/MIPSResult.java60
1 files changed, 60 insertions, 0 deletions
diff --git a/Homework/cs5300/compiler/p5-compiler/submit/MIPSResult.java b/Homework/cs5300/compiler/p5-compiler/submit/MIPSResult.java
new file mode 100644
index 0000000..bccfe76
--- /dev/null
+++ b/Homework/cs5300/compiler/p5-compiler/submit/MIPSResult.java
@@ -0,0 +1,60 @@
+/*
+ */
+package submit;
+
+import submit.ast.VarType;
+
+/**
+ * This class represents the result of generating MIPS code. There are various
+ * forms this result can take: 1) void, for cases where the calling node doesn't
+ * need any information returned, such as a return statement. 2) register, for
+ * cases where the called node needs to inform the calling node what register a
+ * result is placed in, such as BinaryOperator. 3) address, for cases where the
+ * returning result is in memory, such as StringConstant.
+ *
+ * To instantiate a MIPSResult object use the factory methods create...().
+ *
+ */
+public class MIPSResult {
+
+ private final String register;
+ private final String address;
+ private final VarType type;
+
+ public static MIPSResult createVoidResult() {
+ return new MIPSResult(null, null, null);
+ }
+
+ public static MIPSResult createRegisterResult(String register, VarType type) {
+ return new MIPSResult(register, null, type);
+ }
+
+ public static MIPSResult createAddressResult(String address, VarType type) {
+ return new MIPSResult(null, address, type);
+ }
+
+ private MIPSResult(String register, String address, VarType type) {
+ this.register = register;
+ this.address = address;
+ this.type = type;
+ }
+
+ /**
+ * Anytime you get a register from a result you should seriously consider
+ * calling regAllocator.clear(reg) after using the register to minimize
+ * register usage.
+ *
+ * @return
+ */
+ public String getRegister() {
+ return register;
+ }
+
+ public String getAddress() {
+ return address;
+ }
+
+ public VarType getType() {
+ return type;
+ }
+}