refactor: Use strategy for CodeGenerator backend
This makes it easier to switch between the code generator backends which may help debugging.
This commit is contained in:
parent
70528858cc
commit
56536cc64b
3 changed files with 17 additions and 3 deletions
|
|
@ -1,6 +1,7 @@
|
|||
package edu.kit.kastel.vads.compiler;
|
||||
|
||||
import edu.kit.kastel.vads.compiler.backend.aasm.CodeGenerator;
|
||||
import edu.kit.kastel.vads.compiler.backend.CodeGenerator;
|
||||
import edu.kit.kastel.vads.compiler.backend.aasm.AasmCodeGenerator;
|
||||
import edu.kit.kastel.vads.compiler.ir.IrGraph;
|
||||
import edu.kit.kastel.vads.compiler.ir.SsaTranslation;
|
||||
import edu.kit.kastel.vads.compiler.ir.optimize.LocalValueNumbering;
|
||||
|
|
@ -50,7 +51,8 @@ public class Main {
|
|||
}
|
||||
|
||||
// TODO: generate assembly and invoke gcc instead of generating abstract assembly
|
||||
String s = new CodeGenerator().generateCode(graphs);
|
||||
CodeGenerator generator = new AasmCodeGenerator();
|
||||
String s = generator.generateCode(graphs);
|
||||
Files.writeString(output, s);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,11 @@
|
|||
package edu.kit.kastel.vads.compiler.backend;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import edu.kit.kastel.vads.compiler.ir.IrGraph;
|
||||
|
||||
public interface CodeGenerator {
|
||||
|
||||
public String generateCode(List<IrGraph> program);
|
||||
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
package edu.kit.kastel.vads.compiler.backend.aasm;
|
||||
|
||||
import edu.kit.kastel.vads.compiler.backend.CodeGenerator;
|
||||
import edu.kit.kastel.vads.compiler.backend.regalloc.Register;
|
||||
import edu.kit.kastel.vads.compiler.ir.IrGraph;
|
||||
import edu.kit.kastel.vads.compiler.ir.node.AddNode;
|
||||
|
|
@ -23,7 +24,7 @@ import java.util.Set;
|
|||
|
||||
import static edu.kit.kastel.vads.compiler.ir.util.NodeSupport.predecessorSkipProj;
|
||||
|
||||
public class CodeGenerator {
|
||||
public class AasmCodeGenerator implements CodeGenerator {
|
||||
|
||||
public String generateCode(List<IrGraph> program) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
Loading…
Add table
Add a link
Reference in a new issue