mirror of
https://gitlab.com/camelot/kickc.git
synced 2024-12-20 07:30:00 +00:00
Made room for new pass 3 interval analysis
This commit is contained in:
parent
0aa64b3203
commit
69cbee294d
@ -49,8 +49,8 @@ public class Compiler {
|
||||
KickCParser.FileContext file = pass0ParseInput(input, log);
|
||||
Program program = pass1GenerateSSA(file, log);
|
||||
pass2OptimizeSSA(program, log);
|
||||
AsmProgram asmProgram = pass3GenerateAsm(program, log);
|
||||
pass4OptimizeAsm(asmProgram, log);
|
||||
AsmProgram asmProgram = pass4GenerateAsm(program, log);
|
||||
pass5OptimizeAsm(asmProgram, log);
|
||||
|
||||
log.append("FINAL SYMBOL TABLE");
|
||||
log.append(program.getScope().getSymbolTableContents());
|
||||
@ -64,16 +64,16 @@ public class Compiler {
|
||||
}
|
||||
}
|
||||
|
||||
public void pass4OptimizeAsm(AsmProgram asmProgram, CompileLog log) {
|
||||
List<Pass4AsmOptimization> pass4Optimizations = new ArrayList<>();
|
||||
pass4Optimizations.add(new Pass4NextJumpElimination(asmProgram, log));
|
||||
pass4Optimizations.add(new Pass4UnnecesaryLoadElimination(asmProgram, log));
|
||||
public void pass5OptimizeAsm(AsmProgram asmProgram, CompileLog log) {
|
||||
List<Pass5AsmOptimization> pass4Optimizations = new ArrayList<>();
|
||||
pass4Optimizations.add(new Pass5NextJumpElimination(asmProgram, log));
|
||||
pass4Optimizations.add(new Pass5UnnecesaryLoadElimination(asmProgram, log));
|
||||
boolean asmOptimized = true;
|
||||
while (asmOptimized) {
|
||||
asmOptimized = false;
|
||||
for (Pass4AsmOptimization optimization : pass4Optimizations) {
|
||||
boolean stepOtimized = optimization.optimize();
|
||||
if (stepOtimized) {
|
||||
for (Pass5AsmOptimization optimization : pass4Optimizations) {
|
||||
boolean stepOptimized = optimization.optimize();
|
||||
if (stepOptimized) {
|
||||
log.append("Succesful ASM optimization " + optimization.getClass().getSimpleName());
|
||||
asmOptimized = true;
|
||||
log.append("ASSEMBLER");
|
||||
@ -83,13 +83,13 @@ public class Compiler {
|
||||
}
|
||||
}
|
||||
|
||||
public AsmProgram pass3GenerateAsm(Program program, CompileLog log) {
|
||||
Pass3BlockSequencePlanner pass3BlockSequencePlanner = new Pass3BlockSequencePlanner(program);
|
||||
pass3BlockSequencePlanner.plan();
|
||||
Pass3RegisterAllocation pass3RegisterAllocation = new Pass3RegisterAllocation(program);
|
||||
pass3RegisterAllocation.allocate();
|
||||
Pass3CodeGeneration pass3CodeGeneration = new Pass3CodeGeneration(program);
|
||||
AsmProgram asmProgram = pass3CodeGeneration.generate();
|
||||
public AsmProgram pass4GenerateAsm(Program program, CompileLog log) {
|
||||
Pass4BlockSequencePlanner pass4BlockSequencePlanner = new Pass4BlockSequencePlanner(program);
|
||||
pass4BlockSequencePlanner.plan();
|
||||
Pass4RegisterAllocation pass4RegisterAllocation = new Pass4RegisterAllocation(program);
|
||||
pass4RegisterAllocation.allocate();
|
||||
Pass4CodeGeneration pass4CodeGeneration = new Pass4CodeGeneration(program);
|
||||
AsmProgram asmProgram = pass4CodeGeneration.generate();
|
||||
|
||||
log.append("INITIAL ASM");
|
||||
log.append(asmProgram.toString());
|
||||
|
@ -7,12 +7,12 @@ import java.util.List;
|
||||
import java.util.Stack;
|
||||
|
||||
/** Plan the optimal sequence for the blocks of the control flow graph */
|
||||
public class Pass3BlockSequencePlanner {
|
||||
public class Pass4BlockSequencePlanner {
|
||||
|
||||
private ControlFlowGraph graph;
|
||||
private ProgramScope scope;
|
||||
|
||||
public Pass3BlockSequencePlanner(Program program) {
|
||||
public Pass4BlockSequencePlanner(Program program) {
|
||||
this.graph = program.getGraph();
|
||||
this.scope = program.getScope();
|
||||
}
|
@ -8,12 +8,12 @@ import java.util.*;
|
||||
/**
|
||||
* Code Generation of 6502 Assembler from ICL/SSA Control Flow Graph
|
||||
*/
|
||||
public class Pass3CodeGeneration {
|
||||
public class Pass4CodeGeneration {
|
||||
|
||||
private ControlFlowGraph graph;
|
||||
private ProgramScope symbols;
|
||||
|
||||
public Pass3CodeGeneration(Program program) {
|
||||
public Pass4CodeGeneration(Program program) {
|
||||
this.graph = program.getGraph();
|
||||
this.symbols = program.getScope();
|
||||
}
|
@ -5,13 +5,13 @@ import dk.camelot64.kickc.icl.*;
|
||||
/**
|
||||
* Register Allocation for variables
|
||||
*/
|
||||
public class Pass3RegisterAllocation {
|
||||
public class Pass4RegisterAllocation {
|
||||
|
||||
private ControlFlowGraph graph;
|
||||
private ProgramScope symbols;
|
||||
int currentZp = 2;
|
||||
|
||||
public Pass3RegisterAllocation(Program program) {
|
||||
public Pass4RegisterAllocation(Program program) {
|
||||
this.graph = program.getGraph();
|
||||
this.symbols = program.getScope();
|
||||
}
|
@ -10,12 +10,12 @@ import java.util.List;
|
||||
/** Optimization performed on Assembler Code (Asm Code).
|
||||
* Optimizations are performed repeatedly until none of them yield any result
|
||||
**/
|
||||
public abstract class Pass4AsmOptimization {
|
||||
public abstract class Pass5AsmOptimization {
|
||||
|
||||
protected CompileLog log;
|
||||
private AsmProgram program;
|
||||
|
||||
public Pass4AsmOptimization(AsmProgram program, CompileLog log) {
|
||||
public Pass5AsmOptimization(AsmProgram program, CompileLog log) {
|
||||
this.program = program;
|
||||
this.log = log;
|
||||
}
|
@ -10,9 +10,9 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/** Optimize assembler code by removing jumps to labels immediately following the jump */
|
||||
public class Pass4NextJumpElimination extends Pass4AsmOptimization {
|
||||
public class Pass5NextJumpElimination extends Pass5AsmOptimization {
|
||||
|
||||
public Pass4NextJumpElimination(AsmProgram program, CompileLog log) {
|
||||
public Pass5NextJumpElimination(AsmProgram program, CompileLog log) {
|
||||
super(program, log);
|
||||
}
|
||||
|
@ -8,9 +8,9 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/** Maps out register values entering all instructions. Removes unnecessary loads / clears / sets */
|
||||
public class Pass4UnnecesaryLoadElimination extends Pass4AsmOptimization {
|
||||
public class Pass5UnnecesaryLoadElimination extends Pass5AsmOptimization {
|
||||
|
||||
public Pass4UnnecesaryLoadElimination(AsmProgram program, CompileLog log) {
|
||||
public Pass5UnnecesaryLoadElimination(AsmProgram program, CompileLog log) {
|
||||
super(program, log);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user