summaryrefslogtreecommitdiff
path: root/submit/MIPSResult.java
diff options
context:
space:
mode:
Diffstat (limited to 'submit/MIPSResult.java')
-rw-r--r--submit/MIPSResult.java61
1 files changed, 61 insertions, 0 deletions
diff --git a/submit/MIPSResult.java b/submit/MIPSResult.java
new file mode 100644
index 0000000..212719e
--- /dev/null
+++ b/submit/MIPSResult.java
@@ -0,0 +1,61 @@
+/*
+ */
+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;
+ }
+
+}