-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.d
More file actions
44 lines (33 loc) · 723 Bytes
/
main.d
File metadata and controls
44 lines (33 loc) · 723 Bytes
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
module optimizer.main;
import optimizer.joptimizer;
import semantic.analyzer;
import parser.j_parser;
import std.stdio;
class Test
{
int x;
}
int main()
{
//Create a new parser
Parser p = new Parser("../code.txt");
//Lex and parse input
p.lex();
p.parse();
//Print AST
writeln("AST:");
p.ast.print();
//Analyze the resulting AST
SemanticAnalyzer a = new SemanticAnalyzer(p.ast);
a.analyzeVariables();
//Load the modified AST into the optimizer
JOptimizer o = new JOptimizer(a.ast, a.env);
//Remove unused variables
o.removeUnusedVariables();
//Remove all nodes that have no effect
o.removeUselessNodes();
//Reprint the modified AST
writeln("\n\nOptimized AST:");
o.ast.print();
return 0;
}