1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-06-02 00:41:42 +00:00

Parametrizing more ASM

This commit is contained in:
Jesper Gravgaard 2018-11-01 20:44:08 +01:00
parent ca8d817b5d
commit 6973a634ef
4 changed files with 30 additions and 36 deletions

View File

@ -3,21 +3,21 @@ package dk.camelot64.kickc.asm;
/** A label / jump target */
public class AsmLabel implements AsmLine {
private String label;
private AsmParameter label;
private int index;
private boolean dontOptimize;
public AsmLabel(String label) {
public AsmLabel(AsmParameter label) {
this.label = label;
}
public String getLabel() {
public AsmParameter getLabel() {
return label;
}
public void setLabel(String label) {
public void setLabel(AsmParameter label) {
this.label = label;
}

View File

@ -56,7 +56,7 @@ public class AsmProgram {
addLine(new AsmComment(comment));
}
public AsmLabel addLabel(String label) {
public AsmLabel addLabel(AsmParameter label) {
AsmLabel asmLabel = new AsmLabel(label);
addLine(asmLabel);
return asmLabel;

View File

@ -88,7 +88,7 @@ public class Pass4CodeGeneration {
} else {
// Generate label for block inside procedure
asm.startSegment(currentScope, null, blockLabel.getFullName());
asm.addLabel(blockLabel.getLocalName().replace('@', 'b').replace(':', '_'));
asm.addLabel(new AsmParameterLabel(blockLabel));
}
// Generate statements
genStatements(asm, block);
@ -497,7 +497,8 @@ public class Pass4CodeGeneration {
} else if(Procedure.InterruptType.HARDWARE_CLOBBER.equals(interruptType)) {
asm.addInstruction("sta", AsmAddressingMode.ABS, "rega+1", false).setDontOptimize(true);
asm.addInstruction("stx", AsmAddressingMode.ABS, "regx+1", false).setDontOptimize(true);
asm.addInstruction("sty", AsmAddressingMode.ABS, "regy+1", false).setDontOptimize(true); } else {
asm.addInstruction("sty", AsmAddressingMode.ABS, "regy+1", false).setDontOptimize(true);
} else {
throw new RuntimeException("Interrupt Type not supported " + interruptType.name());
}
}
@ -514,24 +515,17 @@ public class Pass4CodeGeneration {
asm.addInstruction("jmp", AsmAddressingMode.ABS, "$ea81", false);
} else if(Procedure.InterruptType.KERNEL_KEYBOARD.equals(interruptType)) {
asm.addInstruction("jmp", AsmAddressingMode.ABS, "$ea31", false);
} else if(Procedure.InterruptType.HARDWARE_ALL.equals(interruptType)) {
asm.addLabel("rega").setDontOptimize(true);
asm.addInstruction("lda", AsmAddressingMode.IMM, "00", false).setDontOptimize(true);
asm.addLabel("regx").setDontOptimize(true);
asm.addInstruction("ldx", AsmAddressingMode.IMM, "00", false).setDontOptimize(true);
asm.addLabel("regy").setDontOptimize(true);
asm.addInstruction("ldy", AsmAddressingMode.IMM, "00", false).setDontOptimize(true);
} else if(Procedure.InterruptType.HARDWARE_ALL.equals(interruptType) || Procedure.InterruptType.HARDWARE_CLOBBER.equals(interruptType)) {
// Any non-clobbered registers load is later removed by {@link Pass4InterruptClobberFix}
asm.addLabel(new AsmParameterLabel(new LabelRef("rega"))).setDontOptimize(true);
asm.addInstruction("lda", AsmAddressingMode.IMM, new AsmParameterConstant(new ConstantInteger( 0l), ProgramScopeRef.ROOT, program), false).setDontOptimize(true);
asm.addLabel(new AsmParameterLabel(new LabelRef("regx"))).setDontOptimize(true);
asm.addInstruction("ldx", AsmAddressingMode.IMM, new AsmParameterConstant(new ConstantInteger( 0l), ProgramScopeRef.ROOT, program), false).setDontOptimize(true);
asm.addLabel(new AsmParameterLabel(new LabelRef("regy"))).setDontOptimize(true);
asm.addInstruction("ldy", AsmAddressingMode.IMM, new AsmParameterConstant(new ConstantInteger( 0l), ProgramScopeRef.ROOT, program), false).setDontOptimize(true);
asm.addInstruction("rti", AsmAddressingMode.NON, null, false);
} else if(Procedure.InterruptType.HARDWARE_NONE.equals(interruptType)) {
asm.addInstruction("rti", AsmAddressingMode.NON, null, false);
} else if(Procedure.InterruptType.HARDWARE_CLOBBER.equals(interruptType)) {
asm.addLabel("rega").setDontOptimize(true);
asm.addInstruction("lda", AsmAddressingMode.IMM, "00", false).setDontOptimize(true);
asm.addLabel("regx").setDontOptimize(true);
asm.addInstruction("ldx", AsmAddressingMode.IMM, "00", false).setDontOptimize(true);
asm.addLabel("regy").setDontOptimize(true);
asm.addInstruction("ldy", AsmAddressingMode.IMM, "00", false).setDontOptimize(true);
asm.addInstruction("rti", AsmAddressingMode.NON, null, false);
} else {
throw new RuntimeException("Interrupt Type not supported " + statement);
}
@ -595,7 +589,7 @@ public class Pass4CodeGeneration {
asm.startSegment( scope, toFirstStatement.getIndex(), segmentSrc);
asm.getCurrentSegment().setPhiTransitionId(transition.getTransitionId());
for(ControlFlowBlock fBlock : transition.getFromBlocks()) {
asm.addLabel((toBlock.getLabel().getLocalName() + "_from_" + fBlock.getLabel().getLocalName()).replace('@', 'b').replace(':', '_'));
asm.addLabel(new AsmParameterLabelTransition(fBlock.getLabel(), toBlock.getLabel()));
}
List<PhiTransitions.PhiTransition.PhiAssignment> assignments = transition.getAssignments();
for(PhiTransitions.PhiTransition.PhiAssignment assignment : assignments) {

View File

@ -32,8 +32,8 @@ public class Pass5RedundantLabelElimination extends Pass5AsmOptimization {
} else if(line instanceof AsmInstruction) {
AsmInstruction instruction = (AsmInstruction) line;
if(instruction.getType().isJump()) {
String labelStr = instruction.getParameter().getAsm();
if(!labelStr.contains("!")) {
AsmParameter labelStr = instruction.getParameter();
if(!labelStr.getAsm().contains("!")) {
// If redundant - Replace with the shortest
for(RedundantLabels redundantLabels : redundantLabelSet) {
if(redundantLabels.getScope().equals(currentScope) && redundantLabels.isRedundant(labelStr)) {
@ -45,8 +45,8 @@ public class Pass5RedundantLabelElimination extends Pass5AsmOptimization {
}
} else if(line instanceof AsmLabel) {
AsmLabel label = (AsmLabel) line;
String labelStr = label.getLabel();
if(!labelStr.contains("!")) {
AsmParameter labelStr = label.getLabel();
if(!labelStr.getAsm().contains("!")) {
for(RedundantLabels redundantLabels : redundantLabelSet) {
if(redundantLabels.getScope().equals(currentScope) && redundantLabels.isRedundant(labelStr)) {
removeLines.add(label);
@ -79,8 +79,8 @@ public class Pass5RedundantLabelElimination extends Pass5AsmOptimization {
currentScope = "";
} else if(line instanceof AsmLabel) {
AsmLabel label = (AsmLabel) line;
String labelStr = label.getLabel();
if(!labelStr.contains("!")) {
AsmParameter labelStr = label.getLabel();
if(!labelStr.getAsm().contains("!")) {
if(current == null) {
current = new RedundantLabels(currentScope, labelStr);
} else {
@ -105,18 +105,18 @@ public class Pass5RedundantLabelElimination extends Pass5AsmOptimization {
private String scope;
private String keep;
private AsmParameter keep;
private Set<String> redundant;
private Set<AsmParameter> redundant;
public RedundantLabels(String scope, String label) {
RedundantLabels(String scope, AsmParameter label) {
this.scope = scope;
this.keep = label;
this.redundant = new LinkedHashSet<>();
}
public void add(String label) {
if(keep.length() < label.length()) {
public void add(AsmParameter label) {
if(keep.getAsm().length() < label.getAsm().length()) {
redundant.add(label);
} else {
redundant.add(keep);
@ -132,11 +132,11 @@ public class Pass5RedundantLabelElimination extends Pass5AsmOptimization {
return scope;
}
public String getKeep() {
AsmParameter getKeep() {
return keep;
}
public boolean isRedundant(String labelStr) {
boolean isRedundant(AsmParameter labelStr) {
return redundant.contains(labelStr);
}
}