2023-04-10 11:17:11 -04:00
|
|
|
/*
|
|
|
|
* Code formatter project
|
|
|
|
* CS 4481
|
|
|
|
*/
|
|
|
|
package submit.ast;
|
|
|
|
|
2023-04-23 02:24:42 -04:00
|
|
|
import submit.MIPSResult;
|
|
|
|
import submit.RegisterAllocator;
|
|
|
|
import submit.SymbolTable;
|
|
|
|
|
2023-04-10 11:17:11 -04:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @author edwajohn
|
|
|
|
*/
|
|
|
|
public class NumConstant extends AbstractNode implements Expression {
|
|
|
|
|
|
|
|
private final int value;
|
|
|
|
|
2023-04-23 02:24:42 -04:00
|
|
|
public NumConstant(int value) { this.value = value; }
|
2023-04-10 11:17:11 -04:00
|
|
|
|
|
|
|
public void toCminus(StringBuilder builder, final String prefix) {
|
|
|
|
builder.append(Integer.toString(value));
|
|
|
|
}
|
|
|
|
|
2023-04-23 02:24:42 -04:00
|
|
|
@Override
|
|
|
|
public MIPSResult toMIPS(StringBuilder code, StringBuilder data,
|
|
|
|
SymbolTable symbolTable,
|
|
|
|
RegisterAllocator regAllocator) {
|
|
|
|
String register = regAllocator.getAny();
|
|
|
|
code.append(String.format("li %s %d\n", register, value));
|
|
|
|
|
|
|
|
return MIPSResult.createRegisterResult(register, VarType.INT);
|
|
|
|
}
|
2023-04-10 11:17:11 -04:00
|
|
|
}
|