Homework 4
This commit is contained in:
parent
0afc86ceeb
commit
72cc3206c4
125 changed files with 4200 additions and 1636 deletions
|
@ -1,19 +1,6 @@
|
|||
package cd;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.Reader;
|
||||
import java.io.Writer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.antlr.v4.runtime.ANTLRInputStream;
|
||||
import org.antlr.v4.runtime.BailErrorStrategy;
|
||||
import org.antlr.v4.runtime.CommonTokenStream;
|
||||
import org.antlr.v4.runtime.misc.ParseCancellationException;
|
||||
|
||||
import cd.backend.codegen.AstCodeGenerator;
|
||||
import cd.frontend.parser.JavaliAstVisitor;
|
||||
import cd.frontend.parser.JavaliLexer;
|
||||
import cd.frontend.parser.JavaliParser;
|
||||
|
@ -24,6 +11,14 @@ import cd.ir.Ast.ClassDecl;
|
|||
import cd.ir.Symbol;
|
||||
import cd.ir.Symbol.TypeSymbol;
|
||||
import cd.util.debug.AstDump;
|
||||
import org.antlr.v4.runtime.ANTLRInputStream;
|
||||
import org.antlr.v4.runtime.BailErrorStrategy;
|
||||
import org.antlr.v4.runtime.CommonTokenStream;
|
||||
import org.antlr.v4.runtime.misc.ParseCancellationException;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The main entrypoint for the compiler. Consists of a series
|
||||
|
@ -37,7 +32,7 @@ public class Main {
|
|||
// Set to non-null to write debug info out
|
||||
public Writer debug = null;
|
||||
|
||||
// Set to non-null to write dump of control flow graph (Advanced Compiler Design)
|
||||
// Set to non-null to write dump of control flow graph
|
||||
public File cfgdumpbase;
|
||||
|
||||
/** Symbol for the Main type */
|
||||
|
@ -74,6 +69,12 @@ public class Main {
|
|||
|
||||
// Run the semantic check:
|
||||
m.semanticCheck(astRoots);
|
||||
|
||||
// Generate code:
|
||||
String sFile = arg + Config.ASMEXT;
|
||||
try (FileWriter fout = new FileWriter(sFile)) {
|
||||
m.generateCode(astRoots, fout);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -111,6 +112,13 @@ public class Main {
|
|||
new SemanticAnalyzer(this).check(astRoots);
|
||||
}
|
||||
}
|
||||
|
||||
public void generateCode(List<ClassDecl> astRoots, Writer out) {
|
||||
{
|
||||
AstCodeGenerator cg = AstCodeGenerator.createCodeGenerator(this, out);
|
||||
cg.go(astRoots);
|
||||
}
|
||||
}
|
||||
|
||||
/** Dumps the AST to the debug stream */
|
||||
private void dumpAst(List<ClassDecl> astRoots) throws IOException {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue