Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.compilerprogramming.ezlang.lexer.Lexer;
import com.compilerprogramming.ezlang.parser.Parser;
import com.compilerprogramming.ezlang.parser.ShortCircuitLowerer;
import com.compilerprogramming.ezlang.semantic.NullableAnalysis;
import com.compilerprogramming.ezlang.semantic.SemaAssignTypes;
import com.compilerprogramming.ezlang.semantic.SemaDefineTypes;
Expand Down Expand Up @@ -31,13 +32,31 @@ public TypeDictionary compileSrc(String src) {
public TypeDictionary compileSrc(String src, EnumSet<Options> options) {
Parser parser = new Parser();
var program = parser.parse(new Lexer(src));
var typeDict = analyze(program);
// Some backend such as the SON do not
// support compiling boolean short-circuit operators
// so we lower them to if blocks. But this is also
// done during tests to prove that the lowering works.
if (options.contains(Options.LOWER_SHORT_CIRCUIT)) {
ShortCircuitLowerer.lower(program);
typeDict = bind(program);
}
compile(typeDict, options);
return typeDict;
}

private TypeDictionary analyze(com.compilerprogramming.ezlang.parser.AST.Program program) {
var typeDict = bind(program);
NullableAnalysis.analyze(typeDict);
return typeDict;
}

private TypeDictionary bind(com.compilerprogramming.ezlang.parser.AST.Program program) {
var typeDict = new TypeDictionary();
var sema = new SemaDefineTypes(typeDict);
sema.analyze(program);
var sema2 = new SemaAssignTypes(typeDict);
sema2.analyze(program);
NullableAnalysis.analyze(typeDict);
compile(typeDict, options);
return typeDict;
}
public static String dumpIR(TypeDictionary typeDictionary) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public enum Options {
SCCP,
CCP, // constant comparison propagation
REGALLOC,
LOWER_SHORT_CIRCUIT, // Lower boolean && || operators to if blocks, used for testing and SON
DUMP_INITIAL_IR,
DUMP_PRE_SSA_DOMTREE,
DUMP_PRE_SSA_DOMFRONTIERS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,19 @@ Value compileAndRun(String src, String mainFunction, EnumSet<Options> optionsIgn

@Parameterized.Parameters
public static Collection<Object[]> data() {
List<EnumSet<Options>> baseOptions = List.of(
Options.NONE,
Options.OPT,
Options.OPT_B,
Options.OPT_ISSA,
Options.OPT_ISSA_B);
List<Object[]> parameters = new ArrayList<>();
parameters.add(new Object[] { Options.NONE });
parameters.add(new Object[] { Options.OPT });
parameters.add(new Object[] { Options.OPT_B });
parameters.add(new Object[] { Options.OPT_ISSA });
parameters.add(new Object[] { Options.OPT_ISSA_B });
for (EnumSet<Options> base : baseOptions) {
parameters.add(new Object[] { EnumSet.copyOf(base) });
EnumSet<Options> lowered = EnumSet.copyOf(base);
lowered.add(Options.LOWER_SHORT_CIRCUIT);
parameters.add(new Object[] { lowered });
}
return parameters;
}

Expand Down
Loading
Loading