File tree Expand file tree Collapse file tree
src/main/kotlin/deep/decaf/tester Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package deep.decaf.tester
2+
3+ import deep.decaf.ir.*
4+ import deep.decaf.low.amd64.*
5+ import deep.decaf.parser.*
6+ import org.antlr.v4.runtime.*
7+ import java.io.*
8+
9+ fun main () {
10+ val folder = File (" /home/deep/work/compiler/low1" )
11+ val files = folder.listFiles()!! .filter { ! it.isDirectory }.sorted()
12+ for (file in files) {
13+ val scanner = DecafLexer (CharStreams .fromFileName(file.absolutePath))
14+ val parser = DecafParser (CommonTokenStream (scanner))
15+ val irTree = parseTreeToIR(parser.program()) as IRProgram
16+ val errors = checkSemantics(irTree)
17+ if (errors.isNotEmpty())
18+ throw RuntimeException (" Invalid program" )
19+ for (method in irTree.methodDeclarations) {
20+ if (method.name == " main" ) {
21+ val blocks = irMethodToLow(method)
22+ println (file.absolutePath)
23+ for (block in blocks) {
24+ print (block)
25+ }
26+ println ()
27+ }
28+ }
29+ }
30+ }
You can’t perform that action at this time.
0 commit comments