blob: e32a7d234a50eb0bac361fd0275eca08ae684e2c (
plain) (
blame)
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
|
/*
* Code formatter project
* CS 4481
*/
package submit.ast;
import java.util.ArrayList;
import java.util.List;
import submit.MIPSResult;
import submit.RegisterAllocator;
import submit.SymbolTable;
/**
*
* @author edwajohn
*/
public class Program extends AbstractNode implements Node {
private ArrayList<Declaration> declarations;
public Program(List<Declaration> declarations) {
this.declarations = new ArrayList<>(declarations);
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
toCminus(builder, "");
return builder.toString();
}
@Override
public void toCminus(StringBuilder builder, String prefix) {
for (Declaration declaration : declarations) {
declaration.toCminus(builder, "");
}
}
@Override
public MIPSResult toMIPS(StringBuilder code, StringBuilder data,
SymbolTable symbolTable,
RegisterAllocator registerAllocator) {
// Store newline in .data
data.append("newline: .asciiz \"\\n\"\n");
for (Declaration declaration : declarations)
declaration.toMIPS(code, data, symbolTable, registerAllocator);
return MIPSResult.createVoidResult();
}
}
|