summaryrefslogtreecommitdiff
path: root/submit/MIPSResult.java
blob: bccfe76d8755373d7bdea865ff82030b7c2f46c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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;
  }
}