mirror of
https://gitlab.com/camelot/kickc.git
synced 2024-12-20 23:30:43 +00:00
Added indexes to ASM lines in AsmProgram
This commit is contained in:
parent
47e8b6b2b9
commit
5d21c6aa97
@ -2,8 +2,11 @@ package dk.camelot64.kickc.asm;
|
||||
|
||||
/** An assember comment */
|
||||
public class AsmComment implements AsmLine {
|
||||
|
||||
private String comment;
|
||||
|
||||
private int index;
|
||||
|
||||
public AsmComment(String comment) {
|
||||
this.comment = comment;
|
||||
}
|
||||
@ -22,21 +25,21 @@ public class AsmComment implements AsmLine {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInvocationCountEstimate() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getEstimatedTotalCycles() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAsm() {
|
||||
return "// "+comment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setIndex(int index) {
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getAsm();
|
||||
|
@ -415,7 +415,7 @@ public class AsmFragment {
|
||||
AsmInstruction instruction;
|
||||
if (paramModeCtx == null) {
|
||||
AsmInstructionType type = AsmInstuctionSet.getInstructionType(ctx.MNEMONIC().getText(), AsmAddressingMode.NON, null);
|
||||
instruction = new AsmInstruction(type, null, 1);
|
||||
instruction = new AsmInstruction(type, null);
|
||||
} else {
|
||||
instruction = (AsmInstruction) this.visit(paramModeCtx);
|
||||
}
|
||||
@ -467,7 +467,7 @@ public class AsmFragment {
|
||||
String mnemonic = instructionCtx.MNEMONIC().getSymbol().getText();
|
||||
String parameter = (String) this.visit(exprCtx);
|
||||
AsmInstructionType type = AsmInstuctionSet.getInstructionType(mnemonic, addressingMode, parameter);
|
||||
return new AsmInstruction(type, parameter, 1);
|
||||
return new AsmInstruction(type, parameter);
|
||||
}
|
||||
|
||||
|
||||
|
@ -7,12 +7,11 @@ public class AsmInstruction implements AsmLine {
|
||||
|
||||
private String parameter;
|
||||
|
||||
private int invocationCountEstimate;
|
||||
private int index;
|
||||
|
||||
public AsmInstruction(AsmInstructionType type, String parameter, int invocationCountEstimate) {
|
||||
public AsmInstruction(AsmInstructionType type, String parameter) {
|
||||
this.type = type;
|
||||
this.parameter = parameter;
|
||||
this.invocationCountEstimate = invocationCountEstimate;
|
||||
}
|
||||
|
||||
public String getParameter() {
|
||||
@ -33,16 +32,6 @@ public class AsmInstruction implements AsmLine {
|
||||
return type.getCycles();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInvocationCountEstimate() {
|
||||
return invocationCountEstimate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getEstimatedTotalCycles() {
|
||||
return getInvocationCountEstimate()*getLineCycles();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAsm() {
|
||||
return type.getAsm(parameter);
|
||||
@ -53,4 +42,13 @@ public class AsmInstruction implements AsmLine {
|
||||
return getAsm();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setIndex(int index) {
|
||||
this.index = index;
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,8 @@ public class AsmLabel implements AsmLine {
|
||||
|
||||
private String label;
|
||||
|
||||
private int index;
|
||||
|
||||
public AsmLabel(String label) {
|
||||
this.label = label;
|
||||
}
|
||||
@ -23,21 +25,21 @@ public class AsmLabel implements AsmLine {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInvocationCountEstimate() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getEstimatedTotalCycles() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAsm() {
|
||||
return label+":";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setIndex(int index) {
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getAsm();
|
||||
|
@ -7,10 +7,9 @@ public interface AsmLine {
|
||||
|
||||
public double getLineCycles();
|
||||
|
||||
public int getInvocationCountEstimate();
|
||||
|
||||
public double getEstimatedTotalCycles();
|
||||
|
||||
public String getAsm();
|
||||
|
||||
public int getIndex();
|
||||
|
||||
void setIndex(int index);
|
||||
}
|
||||
|
@ -10,8 +10,11 @@ public class AsmProgram {
|
||||
|
||||
private List<AsmLine> lines;
|
||||
|
||||
private int nextIndex;
|
||||
|
||||
public AsmProgram() {
|
||||
this.lines = new ArrayList<>();
|
||||
this.nextIndex = 0;
|
||||
}
|
||||
|
||||
public List<AsmLine> getLines() {
|
||||
@ -19,6 +22,7 @@ public class AsmProgram {
|
||||
}
|
||||
|
||||
public void addLine(AsmLine line) {
|
||||
line.setIndex(nextIndex++);
|
||||
lines.add(line);
|
||||
}
|
||||
|
||||
@ -32,7 +36,7 @@ public class AsmProgram {
|
||||
|
||||
public void addInstruction(String mnemonic, AsmAddressingMode addressingMode, String parameter) {
|
||||
AsmInstructionType instructionType = AsmInstuctionSet.getInstructionType(mnemonic, addressingMode, parameter);
|
||||
addLine(new AsmInstruction(instructionType, parameter, 1));
|
||||
addLine(new AsmInstruction(instructionType, parameter));
|
||||
}
|
||||
|
||||
public String toString(boolean comments) {
|
||||
|
Loading…
Reference in New Issue
Block a user