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
|
import java.io.*;
import cs132.util.ProblemException;
import cs132.vapor.parser.VaporParser;
import cs132.vapor.ast.VaporProgram;
import cs132.vapor.ast.VBuiltIn.Op;
import cs132.vapor.ast.VFunction;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.PrintStream;
import st.*;
import misc.*;
import vaporize.library.*;
public class V2VM {
public static void main(String[] args) {
try {
VFunction[] funts = parseVapor(System.in, System.out).functions;
ControlFlowGraph cfg = new ControlFlowGraph<Void, Void>();
TotalSpill<String, Void> ts = new TotalSpill<String, Void>();
for (VFunction f : funts) {
f.body[0].accept("", ts);
}
} catch (IOException e) {
System.out.println(e.toString());
System.exit(1);
}
}
public static VaporProgram parseVapor(InputStream in, PrintStream err) throws IOException {
Op[] ops = {
Op.Add, Op.Sub, Op.MulS, Op.Eq, Op.Lt, Op.LtS,
Op.PrintIntS, Op.HeapAllocZ, Op.Error,
};
boolean allowLocals = true;
String[] registers = null;
boolean allowStack = false;
VaporProgram program;
try {
program = VaporParser.run(new InputStreamReader(in), 1, 1,
java.util.Arrays.asList(ops),
allowLocals, registers, allowStack);
} catch (ProblemException ex) {
err.println(ex.getMessage());
return null;
}
return program;
}
}
|