1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-09-08 17:54:40 +00:00

Added operator precedence to constant printing - avoiding unnecesary perenthesis

This commit is contained in:
Jesper Gravgaard 2017-10-15 22:39:50 +02:00
parent 7b9e80aaac
commit 46ffa81633
16 changed files with 174 additions and 223 deletions

View File

@ -394,7 +394,9 @@ public class AsmFragment {
} }
} else if (boundValue instanceof Constant) { } else if (boundValue instanceof Constant) {
Constant boundConst = (Constant) boundValue; Constant boundConst = (Constant) boundValue;
return new AsmParameter(Pass4CodeGeneration.getConstantValueAsm(program, boundConst, false), SymbolTypeBasic.BYTE.equals(boundConst.getType(program.getScope()))); String constantValueAsm = Pass4CodeGeneration.getConstantValueAsm(program, boundConst, 99);
boolean constantValueZp = SymbolTypeBasic.BYTE.equals(boundConst.getType(program.getScope()));
return new AsmParameter(constantValueAsm, constantValueZp);
} else if (boundValue instanceof Label) { } else if (boundValue instanceof Label) {
String param = ((Label) boundValue).getLocalName().replace('@', 'b').replace(':', '_').replace("$", "_"); String param = ((Label) boundValue).getLocalName().replace('@', 'b').replace(':', '_').replace("$", "_");
return new AsmParameter(param, false); return new AsmParameter(param, false);

View File

@ -8,25 +8,106 @@ public class Operator {
private String operator; private String operator;
@JsonCreator private int precedence;
public Operator(
@JsonProperty("operator") String operator) { private Type type;
public Operator(String operator, Type type, int precedence) {
this.operator = operator; this.operator = operator;
this.precedence = precedence;
} }
public static Operator getBinary(String op) {
switch (op) {
case "+":
return PLUS;
case "-":
return MINUS;
case "*":
return MULTIPLY;
case "/":
return DIVIDE;
case "==":
return EQ;
case "!=":
return NEQ;
case "<":
return LT;
case "<=":
return LE;
case ">":
return GT;
case ">=":
return GE;
case "*idx":
return STAR_IDX;
default:
throw new RuntimeException("Unknown operator " + op);
}
}
public static Operator getUnary(String op) {
switch (op) {
case "+":
return UNARY_PLUS;
case "-":
return UNARY_MINUS;
case "++":
return INCREMENT;
case "--":
return DECREMENT;
case "!":
return NOT;
case "*":
return STAR;
default:
throw new RuntimeException("Unknown operator " + op);
}
}
public static enum Type {
UNARY, BINARY
}
public static Operator INCREMENT = new Operator("++", Type.UNARY, 1);
public static Operator DECREMENT = new Operator("--", Type.UNARY, 1);
public static Operator UNARY_PLUS = new Operator("+", Type.UNARY, 2);
public static Operator UNARY_MINUS = new Operator("-", Type.UNARY, 2);
public static Operator NOT = new Operator("!", Type.UNARY, 2);
public static Operator STAR = new Operator("*", Type.UNARY, 2);
public static Operator STAR_IDX = new Operator("*idx", Type.BINARY, 2);
public static Operator MULTIPLY = new Operator("*", Type.BINARY, 3);
public static Operator DIVIDE = new Operator("/", Type.BINARY, 3);
public static Operator PLUS = new Operator("+", Type.BINARY, 4);
public static Operator MINUS = new Operator("-", Type.BINARY, 4);
public static Operator LT = new Operator("<", Type.BINARY, 6);
public static Operator LE = new Operator("<=", Type.BINARY, 6);
public static Operator GT = new Operator(">", Type.BINARY, 6);
public static Operator GE = new Operator(">=", Type.BINARY, 6);
public static Operator EQ = new Operator("==", Type.BINARY, 7);
public static Operator NEQ = new Operator("!=", Type.BINARY, 7);
public String getOperator() { public String getOperator() {
return operator; return operator;
} }
public int getPrecedence() {
return precedence;
}
@Override @Override
public String toString() { public String toString() {
return operator ; return operator;
} }
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) {
if (o == null || getClass() != o.getClass()) return false; return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Operator operator1 = (Operator) o; Operator operator1 = (Operator) o;
return operator != null ? operator.equals(operator1.operator) : operator1.operator == null; return operator != null ? operator.equals(operator1.operator) : operator1.operator == null;
} }

View File

@ -78,7 +78,7 @@ public class ParseTreeConstantEvaluator extends KickCBaseVisitor<Constant> {
public Constant visitExprUnary(KickCParser.ExprUnaryContext ctx) { public Constant visitExprUnary(KickCParser.ExprUnaryContext ctx) {
Constant sub = visit(ctx.expr()); Constant sub = visit(ctx.expr());
String op = ((TerminalNode)ctx.getChild(0)).getSymbol().getText(); String op = ((TerminalNode)ctx.getChild(0)).getSymbol().getText();
Operator operator = new Operator(op); Operator operator = Operator.getUnary(op);
return calculateUnary(operator, sub); return calculateUnary(operator, sub);
} }
@ -87,7 +87,7 @@ public class ParseTreeConstantEvaluator extends KickCBaseVisitor<Constant> {
Constant left = this.visit(ctx.expr(0)); Constant left = this.visit(ctx.expr(0));
Constant right = this.visit(ctx.expr(1)); Constant right = this.visit(ctx.expr(1));
String op = ((TerminalNode)ctx.getChild(1)).getSymbol().getText(); String op = ((TerminalNode)ctx.getChild(1)).getSymbol().getText();
Operator operator = new Operator(op); Operator operator = Operator.getBinary(op);
return calculateBinary(operator, left, right); return calculateBinary(operator, left, right);
} }

View File

@ -84,7 +84,7 @@ public class Pass1GenerateStatementSequence extends KickCBaseVisitor<Object> {
PrePostModifierHandler.addPreModifiers(this, ctx.expr()); PrePostModifierHandler.addPreModifiers(this, ctx.expr());
RValue rValue = (RValue) this.visit(ctx.expr()); RValue rValue = (RValue) this.visit(ctx.expr());
VariableRef notExprVar = getCurrentSymbols().addVariableIntermediate().getRef(); VariableRef notExprVar = getCurrentSymbols().addVariableIntermediate().getRef();
sequence.addStatement(new StatementAssignment(notExprVar, null, new Operator("!"), rValue)); sequence.addStatement(new StatementAssignment(notExprVar, null, Operator.NOT, rValue));
PrePostModifierHandler.addPostModifiers(this, ctx.expr()); PrePostModifierHandler.addPostModifiers(this, ctx.expr());
Label elseJumpLabel = getCurrentSymbols().addLabelIntermediate(); Label elseJumpLabel = getCurrentSymbols().addLabelIntermediate();
@ -234,7 +234,7 @@ public class Pass1GenerateStatementSequence extends KickCBaseVisitor<Object> {
// Add increment // Add increment
ConstantInteger beyondLastVal; ConstantInteger beyondLastVal;
if(rangeFirst.getNumber()>rangeLast.getNumber()) { if(rangeFirst.getNumber()>rangeLast.getNumber()) {
Statement stmtInc = new StatementAssignment(lValue.getRef(), new Operator("--"), lValue.getRef()); Statement stmtInc = new StatementAssignment(lValue.getRef(), Operator.DECREMENT, lValue.getRef());
sequence.addStatement(stmtInc); sequence.addStatement(stmtInc);
if(rangeLast.getNumber()==0) { if(rangeLast.getNumber()==0) {
beyondLastVal = new ConstantInteger(255); beyondLastVal = new ConstantInteger(255);
@ -242,7 +242,7 @@ public class Pass1GenerateStatementSequence extends KickCBaseVisitor<Object> {
beyondLastVal = new ConstantInteger(rangeLast.getNumber()-1); beyondLastVal = new ConstantInteger(rangeLast.getNumber()-1);
} }
} else { } else {
Statement stmtInc = new StatementAssignment(lValue.getRef(), new Operator("++"), lValue.getRef()); Statement stmtInc = new StatementAssignment(lValue.getRef(), Operator.INCREMENT, lValue.getRef());
sequence.addStatement(stmtInc); sequence.addStatement(stmtInc);
if(rangeLast.getNumber()==255) { if(rangeLast.getNumber()==255) {
beyondLastVal = new ConstantInteger(0); beyondLastVal = new ConstantInteger(0);
@ -254,7 +254,7 @@ public class Pass1GenerateStatementSequence extends KickCBaseVisitor<Object> {
// Add condition i<last+1 or i<last-1 // Add condition i<last+1 or i<last-1
VariableIntermediate tmpVar = getCurrentSymbols().addVariableIntermediate(); VariableIntermediate tmpVar = getCurrentSymbols().addVariableIntermediate();
VariableRef tmpVarRef = tmpVar.getRef(); VariableRef tmpVarRef = tmpVar.getRef();
Statement stmtTmpVar = new StatementAssignment(tmpVarRef, lValue.getRef(), new Operator("!="), beyondLastVal); Statement stmtTmpVar = new StatementAssignment(tmpVarRef, lValue.getRef(), Operator.NEQ, beyondLastVal);
sequence.addStatement(stmtTmpVar); sequence.addStatement(stmtTmpVar);
// Add jump if condition was met // Add jump if condition was met
Statement doJmpStmt = new StatementConditionalJump(tmpVarRef, repeatLabel.getRef()); Statement doJmpStmt = new StatementConditionalJump(tmpVarRef, repeatLabel.getRef());
@ -461,7 +461,7 @@ public class Pass1GenerateStatementSequence extends KickCBaseVisitor<Object> {
public RValue visitExprArray(KickCParser.ExprArrayContext ctx) { public RValue visitExprArray(KickCParser.ExprArrayContext ctx) {
RValue array = (LValue) visit(ctx.expr(0)); RValue array = (LValue) visit(ctx.expr(0));
RValue index = (RValue) visit(ctx.expr(1)); RValue index = (RValue) visit(ctx.expr(1));
Operator operator = new Operator("*idx"); Operator operator = Operator.STAR_IDX;
VariableIntermediate tmpVar = getCurrentSymbols().addVariableIntermediate(); VariableIntermediate tmpVar = getCurrentSymbols().addVariableIntermediate();
VariableRef tmpVarRef = tmpVar.getRef(); VariableRef tmpVarRef = tmpVar.getRef();
Statement stmt = new StatementAssignment(tmpVarRef, array, operator, index); Statement stmt = new StatementAssignment(tmpVarRef, array, operator, index);
@ -495,7 +495,7 @@ public class Pass1GenerateStatementSequence extends KickCBaseVisitor<Object> {
RValue left = (RValue) this.visit(ctx.expr(0)); RValue left = (RValue) this.visit(ctx.expr(0));
RValue right = (RValue) this.visit(ctx.expr(1)); RValue right = (RValue) this.visit(ctx.expr(1));
String op = ((TerminalNode) ctx.getChild(1)).getSymbol().getText(); String op = ((TerminalNode) ctx.getChild(1)).getSymbol().getText();
Operator operator = new Operator(op); Operator operator = Operator.getBinary(op);
VariableIntermediate tmpVar = getCurrentSymbols().addVariableIntermediate(); VariableIntermediate tmpVar = getCurrentSymbols().addVariableIntermediate();
VariableRef tmpVarRef = tmpVar.getRef(); VariableRef tmpVarRef = tmpVar.getRef();
Statement stmt = new StatementAssignment(tmpVarRef, left, operator, right); Statement stmt = new StatementAssignment(tmpVarRef, left, operator, right);
@ -507,7 +507,7 @@ public class Pass1GenerateStatementSequence extends KickCBaseVisitor<Object> {
public RValue visitExprUnary(KickCParser.ExprUnaryContext ctx) { public RValue visitExprUnary(KickCParser.ExprUnaryContext ctx) {
RValue child = (RValue) this.visit(ctx.expr()); RValue child = (RValue) this.visit(ctx.expr());
String op = ((TerminalNode) ctx.getChild(0)).getSymbol().getText(); String op = ((TerminalNode) ctx.getChild(0)).getSymbol().getText();
Operator operator = new Operator(op); Operator operator = Operator.getUnary(op);
VariableIntermediate tmpVar = getCurrentSymbols().addVariableIntermediate(); VariableIntermediate tmpVar = getCurrentSymbols().addVariableIntermediate();
VariableRef tmpVarRef = tmpVar.getRef(); VariableRef tmpVarRef = tmpVar.getRef();
Statement stmt = new StatementAssignment(tmpVarRef, operator, child); Statement stmt = new StatementAssignment(tmpVarRef, operator, child);
@ -594,7 +594,7 @@ public class Pass1GenerateStatementSequence extends KickCBaseVisitor<Object> {
public Void visitExprPostMod(KickCParser.ExprPostModContext ctx) { public Void visitExprPostMod(KickCParser.ExprPostModContext ctx) {
RValue child = (RValue) mainParser.visit(ctx.expr()); RValue child = (RValue) mainParser.visit(ctx.expr());
String op = ((TerminalNode) ctx.getChild(1)).getSymbol().getText(); String op = ((TerminalNode) ctx.getChild(1)).getSymbol().getText();
Operator operator = new Operator(op); Operator operator = Operator.getUnary(op);
PrePostModifier modifier = new PrePostModifier(child, operator); PrePostModifier modifier = new PrePostModifier(child, operator);
postMods.add(modifier); postMods.add(modifier);
return null; return null;
@ -604,7 +604,7 @@ public class Pass1GenerateStatementSequence extends KickCBaseVisitor<Object> {
public Void visitExprPreMod(KickCParser.ExprPreModContext ctx) { public Void visitExprPreMod(KickCParser.ExprPreModContext ctx) {
RValue child = (RValue) mainParser.visit(ctx.expr()); RValue child = (RValue) mainParser.visit(ctx.expr());
String op = ((TerminalNode) ctx.getChild(0)).getSymbol().getText(); String op = ((TerminalNode) ctx.getChild(0)).getSymbol().getText();
Operator operator = new Operator(op); Operator operator = Operator.getUnary(op);
PrePostModifier modifier = new PrePostModifier(child, operator); PrePostModifier modifier = new PrePostModifier(child, operator);
preMods.add(modifier); preMods.add(modifier);
return null; return null;

View File

@ -64,7 +64,7 @@ public class Pass2ConstantAdditionElimination extends Pass2SsaOptimization {
if(pointerDereferenceIndexed.getPointer() instanceof Constant && pointerDereferenceIndexed.getIndex() instanceof Constant) { if(pointerDereferenceIndexed.getPointer() instanceof Constant && pointerDereferenceIndexed.getIndex() instanceof Constant) {
Constant ptrConstant = (Constant) pointerDereferenceIndexed.getPointer(); Constant ptrConstant = (Constant) pointerDereferenceIndexed.getPointer();
Constant idxConstant = (Constant) pointerDereferenceIndexed.getIndex(); Constant idxConstant = (Constant) pointerDereferenceIndexed.getIndex();
Constant newPtr = new ConstantBinary(ptrConstant, new Operator("+"), idxConstant); Constant newPtr = new ConstantBinary(ptrConstant, Operator.PLUS, idxConstant);
assignment.setlValue(new PointerDereferenceSimple(newPtr)); assignment.setlValue(new PointerDereferenceSimple(newPtr));
getLog().append("Consolidated assigned array index constant in assignment " + assignment.getlValue()); getLog().append("Consolidated assigned array index constant in assignment " + assignment.getlValue());
return true; return true;
@ -74,7 +74,7 @@ public class Pass2ConstantAdditionElimination extends Pass2SsaOptimization {
Constant consolidated = consolidateSubConstants(variable); Constant consolidated = consolidateSubConstants(variable);
if (consolidated != null) { if (consolidated != null) {
Constant ptrConstant = (Constant) pointerDereferenceIndexed.getPointer(); Constant ptrConstant = (Constant) pointerDereferenceIndexed.getPointer();
Constant newPtr = new ConstantBinary(ptrConstant, new Operator("+"), consolidated); Constant newPtr = new ConstantBinary(ptrConstant, Operator.PLUS, consolidated);
pointerDereferenceIndexed.setPointer(newPtr); pointerDereferenceIndexed.setPointer(newPtr);
getLog().append("Consolidated assigned array index constant in assignment " + assignment.getlValue()); getLog().append("Consolidated assigned array index constant in assignment " + assignment.getlValue());
return true; return true;
@ -87,9 +87,9 @@ public class Pass2ConstantAdditionElimination extends Pass2SsaOptimization {
if (assignment.getrValue1() instanceof Constant && assignment.getrValue2() instanceof Constant) { if (assignment.getrValue1() instanceof Constant && assignment.getrValue2() instanceof Constant) {
Constant ptrConstant = (Constant) assignment.getrValue1(); Constant ptrConstant = (Constant) assignment.getrValue1();
Constant idxConstant = (Constant) assignment.getrValue2(); Constant idxConstant = (Constant) assignment.getrValue2();
Constant newPtr = new ConstantBinary(ptrConstant, new Operator("+"), idxConstant); Constant newPtr = new ConstantBinary(ptrConstant, Operator.PLUS, idxConstant);
assignment.setrValue1(null); assignment.setrValue1(null);
assignment.setOperator(new Operator("*")); assignment.setOperator(Operator.STAR);
assignment.setrValue2(newPtr); assignment.setrValue2(newPtr);
getLog().append("Consolidated referenced array index constant in assignment " + assignment.getlValue()); getLog().append("Consolidated referenced array index constant in assignment " + assignment.getlValue());
return true; return true;
@ -99,7 +99,7 @@ public class Pass2ConstantAdditionElimination extends Pass2SsaOptimization {
Constant consolidated = consolidateSubConstants(variable); Constant consolidated = consolidateSubConstants(variable);
if (consolidated != null) { if (consolidated != null) {
Constant ptrConstant = (Constant) assignment.getrValue1(); Constant ptrConstant = (Constant) assignment.getrValue1();
Constant newPtr = new ConstantBinary(ptrConstant, new Operator("+"), consolidated); Constant newPtr = new ConstantBinary(ptrConstant, Operator.PLUS, consolidated);
assignment.setrValue1(newPtr); assignment.setrValue1(newPtr);
getLog().append("Consolidated referenced array index constant in assignment " + assignment.getlValue()); getLog().append("Consolidated referenced array index constant in assignment " + assignment.getlValue());
return true; return true;
@ -114,7 +114,7 @@ public class Pass2ConstantAdditionElimination extends Pass2SsaOptimization {
Constant consolidated = consolidateSubConstants(variable); Constant consolidated = consolidateSubConstants(variable);
if (consolidated != null) { if (consolidated != null) {
Constant const1 = (Constant) assignment.getrValue1(); Constant const1 = (Constant) assignment.getrValue1();
assignment.setrValue1(new ConstantBinary(const1, new Operator("+"), consolidated)); assignment.setrValue1(new ConstantBinary(const1, Operator.PLUS, consolidated));
getLog().append("Consolidated constant in assignment " + assignment.getlValue()); getLog().append("Consolidated constant in assignment " + assignment.getlValue());
return true; return true;
} }
@ -123,7 +123,7 @@ public class Pass2ConstantAdditionElimination extends Pass2SsaOptimization {
Constant consolidated = consolidateSubConstants(variable); Constant consolidated = consolidateSubConstants(variable);
if (consolidated != null) { if (consolidated != null) {
Constant const2 = (Constant) assignment.getrValue2(); Constant const2 = (Constant) assignment.getrValue2();
Constant newNumber = new ConstantBinary(consolidated, new Operator("+"), const2); Constant newNumber = new ConstantBinary(consolidated, Operator.PLUS, const2);
assignment.setrValue2(newNumber); assignment.setrValue2(newNumber);
// Handling of negative consolidated numbers? // Handling of negative consolidated numbers?
getLog().append("Consolidated constant in assignment " + assignment.getlValue()); getLog().append("Consolidated constant in assignment " + assignment.getlValue());
@ -170,7 +170,7 @@ public class Pass2ConstantAdditionElimination extends Pass2SsaOptimization {
if (const1 != null) { if (const1 != null) {
result = const1; result = const1;
if (const2 != null) { if (const2 != null) {
result = new ConstantBinary(const1, new Operator("+"), const2); result = new ConstantBinary(const1, Operator.PLUS, const2);
} }
} else if (const2 != null) { } else if (const2 != null) {
result = const2; result = const2;
@ -188,7 +188,7 @@ public class Pass2ConstantAdditionElimination extends Pass2SsaOptimization {
assignment.setrValue2(assignment.getrValue1()); assignment.setrValue2(assignment.getrValue1());
assignment.setOperator(null); assignment.setOperator(null);
assignment.setrValue1(null); assignment.setrValue1(null);
return new ConstantUnary(new Operator("-"), constant); return new ConstantUnary(Operator.MINUS, constant);
} else { } else {
Constant const1 = null; Constant const1 = null;
if (assignment.getrValue1() instanceof VariableRef) { if (assignment.getrValue1() instanceof VariableRef) {
@ -202,7 +202,7 @@ public class Pass2ConstantAdditionElimination extends Pass2SsaOptimization {
if (const1 != null) { if (const1 != null) {
result = const1; result = const1;
if (const2 != null) { if (const2 != null) {
result = new ConstantBinary(const1, new Operator("-"),const2); result = new ConstantBinary(const1, Operator.MINUS,const2);
} }
} else if (const2 != null) { } else if (const2 != null) {
result = const2; result = const2;

View File

@ -96,7 +96,7 @@ public class Pass2UnaryNotSimplification extends Pass2SsaOptimization {
*/ */
private void createInverse(String newOperator, StatementAssignment assignment, StatementAssignment tempAssignment) { private void createInverse(String newOperator, StatementAssignment assignment, StatementAssignment tempAssignment) {
assignment.setrValue1(tempAssignment.getrValue1()); assignment.setrValue1(tempAssignment.getrValue1());
assignment.setOperator(newOperator==null?null:new Operator(newOperator)); assignment.setOperator(newOperator==null?null:Operator.getBinary(newOperator));
assignment.setrValue2(tempAssignment.getrValue2()); assignment.setrValue2(tempAssignment.getrValue2());
getLog().append("Inversing boolean not "+assignment.toString(getProgram()) +" from "+tempAssignment.toString(getProgram())); getLog().append("Inversing boolean not "+assignment.toString(getProgram()) +" from "+tempAssignment.toString(getProgram()));
} }

View File

@ -91,7 +91,7 @@ public class Pass4CodeGeneration {
for (ConstantVar constantVar : scopeConstants) { for (ConstantVar constantVar : scopeConstants) {
String asmName = constantVar.getAsmName() == null ? constantVar.getLocalName() : constantVar.getAsmName(); String asmName = constantVar.getAsmName() == null ? constantVar.getLocalName() : constantVar.getAsmName();
if (asmName != null && !added.contains(asmName)) { if (asmName != null && !added.contains(asmName)) {
asm.addConstant(asmName.replace("#", "_").replace("$", "_"), getConstantValueAsm(program, constantVar.getValue(), false)); asm.addConstant(asmName.replace("#", "_").replace("$", "_"), getConstantValueAsm(program, constantVar.getValue(), 99));
added.add(asmName); added.add(asmName);
} }
} }
@ -101,11 +101,11 @@ public class Pass4CodeGeneration {
* Get ASM code for a constant value * Get ASM code for a constant value
* *
* @param value The constant value * @param value The constant value
* @param subOperator is this generated inside another operator (needing a parenthesis) * @param precedence The precedence of the outer expression operator. Used to generate perenthesis when needed.
* *
* @return The ASM string representing the constant value * @return The ASM string representing the constant value
*/ */
public static String getConstantValueAsm(Program program, Constant value, boolean subOperator) { public static String getConstantValueAsm(Program program, Constant value, int precedence) {
if (value instanceof ConstantRef) { if (value instanceof ConstantRef) {
value = program.getScope().getConstant((ConstantRef) value); value = program.getScope().getConstant((ConstantRef) value);
} }
@ -117,19 +117,23 @@ public class Pass4CodeGeneration {
return String.format("$%x", ((ConstantInteger) value).getNumber()); return String.format("$%x", ((ConstantInteger) value).getNumber());
} else if (value instanceof ConstantUnary) { } else if (value instanceof ConstantUnary) {
ConstantUnary unary = (ConstantUnary) value; ConstantUnary unary = (ConstantUnary) value;
Operator operator = unary.getOperator();
boolean parenthesis = operator.getPrecedence()>precedence;
return return
(subOperator ? "(" : "") + (parenthesis ? "(" : "") +
unary.getOperator().getOperator() + operator.getOperator() +
getConstantValueAsm(program, unary.getOperand(), true) + getConstantValueAsm(program, unary.getOperand(), operator.getPrecedence()) +
(subOperator ? ")" : ""); (parenthesis? ")" : "");
} else if (value instanceof ConstantBinary) { } else if (value instanceof ConstantBinary) {
ConstantBinary binary = (ConstantBinary) value; ConstantBinary binary = (ConstantBinary) value;
Operator operator = binary.getOperator();
boolean parenthesis = operator.getPrecedence()>precedence;
return return
(subOperator ? "(" : "") + (parenthesis? "(" : "") +
getConstantValueAsm(program, binary.getLeft(), true) + getConstantValueAsm(program, binary.getLeft(), operator.getPrecedence()) +
binary.getOperator().getOperator() + operator.getOperator() +
getConstantValueAsm(program, binary.getRight(), true) + getConstantValueAsm(program, binary.getRight(), operator.getPrecedence()) +
(subOperator ? ")" : ""); (parenthesis? ")" : "");
} else { } else {
throw new RuntimeException("Constant type not supported " + value); throw new RuntimeException("Constant type not supported " + value);
} }

File diff suppressed because one or more lines are too long

View File

@ -14,9 +14,9 @@ main: {
ldx #yd/$2 ldx #yd/$2
lda #$0 lda #$0
sta x sta x
lda #<(SCREEN+($0*$28))+$0 lda #<SCREEN+$0*$28+$0
sta cursor sta cursor
lda #>(SCREEN+($0*$28))+$0 lda #>SCREEN+$0*$28+$0
sta cursor+$1 sta cursor+$1
b1: b1:
ldy #$0 ldy #$0

View File

@ -1462,9 +1462,9 @@ main: {
lda #$0 lda #$0
sta x sta x
//SEG10 [2] phi (byte*) main::cursor#3 = (const byte[1000]) SCREEN#0+(byte) 0*(byte) 40+(byte) 0 -- zpptrby1=cowo1 //SEG10 [2] phi (byte*) main::cursor#3 = (const byte[1000]) SCREEN#0+(byte) 0*(byte) 40+(byte) 0 -- zpptrby1=cowo1
lda #<(SCREEN+($0*$28))+$0 lda #<SCREEN+$0*$28+$0
sta cursor sta cursor
lda #>(SCREEN+($0*$28))+$0 lda #>SCREEN+$0*$28+$0
sta cursor+$1 sta cursor+$1
jmp b1 jmp b1
//SEG11 [2] phi from main::@2 to main::@1 //SEG11 [2] phi from main::@2 to main::@1
@ -1603,9 +1603,9 @@ main: {
lda #$0 lda #$0
sta x sta x
//SEG10 [2] phi (byte*) main::cursor#3 = (const byte[1000]) SCREEN#0+(byte) 0*(byte) 40+(byte) 0 -- zpptrby1=cowo1 //SEG10 [2] phi (byte*) main::cursor#3 = (const byte[1000]) SCREEN#0+(byte) 0*(byte) 40+(byte) 0 -- zpptrby1=cowo1
lda #<(SCREEN+($0*$28))+$0 lda #<SCREEN+$0*$28+$0
sta cursor sta cursor
lda #>(SCREEN+($0*$28))+$0 lda #>SCREEN+$0*$28+$0
sta cursor+$1 sta cursor+$1
jmp b1 jmp b1
//SEG11 [2] phi from main::@2 to main::@1 //SEG11 [2] phi from main::@2 to main::@1
@ -1708,9 +1708,9 @@ main: {
lda #$0 lda #$0
sta x sta x
//SEG10 [2] phi (byte*) main::cursor#3 = (const byte[1000]) SCREEN#0+(byte) 0*(byte) 40+(byte) 0 -- zpptrby1=cowo1 //SEG10 [2] phi (byte*) main::cursor#3 = (const byte[1000]) SCREEN#0+(byte) 0*(byte) 40+(byte) 0 -- zpptrby1=cowo1
lda #<(SCREEN+($0*$28))+$0 lda #<SCREEN+$0*$28+$0
sta cursor sta cursor
lda #>(SCREEN+($0*$28))+$0 lda #>SCREEN+$0*$28+$0
sta cursor+$1 sta cursor+$1
jmp b1 jmp b1
//SEG11 [2] phi from main::@2 to main::@1 //SEG11 [2] phi from main::@2 to main::@1
@ -1806,9 +1806,9 @@ main: {
lda #$0 lda #$0
sta x sta x
//SEG10 [2] phi (byte*) main::cursor#3 = (const byte[1000]) SCREEN#0+(byte) 0*(byte) 40+(byte) 0 -- zpptrby1=cowo1 //SEG10 [2] phi (byte*) main::cursor#3 = (const byte[1000]) SCREEN#0+(byte) 0*(byte) 40+(byte) 0 -- zpptrby1=cowo1
lda #<(SCREEN+($0*$28))+$0 lda #<SCREEN+$0*$28+$0
sta cursor sta cursor
lda #>(SCREEN+($0*$28))+$0 lda #>SCREEN+$0*$28+$0
sta cursor+$1 sta cursor+$1
jmp b1 jmp b1
//SEG11 [2] phi from main::@2 to main::@1 //SEG11 [2] phi from main::@2 to main::@1
@ -1898,9 +1898,9 @@ main: {
lda #$0 lda #$0
sta x sta x
//SEG10 [2] phi (byte*) main::cursor#3 = (const byte[1000]) SCREEN#0+(byte) 0*(byte) 40+(byte) 0 -- zpptrby1=cowo1 //SEG10 [2] phi (byte*) main::cursor#3 = (const byte[1000]) SCREEN#0+(byte) 0*(byte) 40+(byte) 0 -- zpptrby1=cowo1
lda #<(SCREEN+($0*$28))+$0 lda #<SCREEN+$0*$28+$0
sta cursor sta cursor
lda #>(SCREEN+($0*$28))+$0 lda #>SCREEN+$0*$28+$0
sta cursor+$1 sta cursor+$1
//SEG11 [2] phi from main::@2 to main::@1 //SEG11 [2] phi from main::@2 to main::@1
//SEG12 [2] phi (byte) main::y#2 = (byte) main::y#4 -- register_copy //SEG12 [2] phi (byte) main::y#2 = (byte) main::y#4 -- register_copy
@ -2032,9 +2032,9 @@ main: {
lda #$0 lda #$0
sta x sta x
//SEG10 [2] phi (byte*) main::cursor#3 = (const byte[1000]) SCREEN#0+(byte) 0*(byte) 40+(byte) 0 -- zpptrby1=cowo1 //SEG10 [2] phi (byte*) main::cursor#3 = (const byte[1000]) SCREEN#0+(byte) 0*(byte) 40+(byte) 0 -- zpptrby1=cowo1
lda #<(SCREEN+($0*$28))+$0 lda #<SCREEN+$0*$28+$0
sta cursor sta cursor
lda #>(SCREEN+($0*$28))+$0 lda #>SCREEN+$0*$28+$0
sta cursor+$1 sta cursor+$1
//SEG11 [2] phi from main::@2 to main::@1 //SEG11 [2] phi from main::@2 to main::@1
//SEG12 [2] phi (byte) main::y#2 = (byte) main::y#4 -- register_copy //SEG12 [2] phi (byte) main::y#2 = (byte) main::y#4 -- register_copy

View File

@ -10,7 +10,7 @@
sta y sta y
ldy #yd/$2 ldy #yd/$2
ldx #$0 ldx #$0
lda #$0+($0*$28) lda #$0+$0*$28
sta idx sta idx
lda #$0 lda #$0
sta idx+$1 sta idx+$1

View File

@ -1195,7 +1195,7 @@ b1_from_bbegin:
lda #$0 lda #$0
sta x sta x
//SEG6 [0] phi (word) idx#3 = (byte) 0+(byte) 0*(byte) 40 -- zpwo1=coby1 //SEG6 [0] phi (word) idx#3 = (byte) 0+(byte) 0*(byte) 40 -- zpwo1=coby1
lda #$0+($0*$28) lda #$0+$0*$28
sta idx sta idx
lda #$0 lda #$0
sta idx+$1 sta idx+$1
@ -1322,7 +1322,7 @@ b1_from_bbegin:
//SEG5 [0] phi (byte) x#2 = (byte) 0 -- xby=coby1 //SEG5 [0] phi (byte) x#2 = (byte) 0 -- xby=coby1
ldx #$0 ldx #$0
//SEG6 [0] phi (word) idx#3 = (byte) 0+(byte) 0*(byte) 40 -- zpwo1=coby1 //SEG6 [0] phi (word) idx#3 = (byte) 0+(byte) 0*(byte) 40 -- zpwo1=coby1
lda #$0+($0*$28) lda #$0+$0*$28
sta idx sta idx
lda #$0 lda #$0
sta idx+$1 sta idx+$1
@ -1420,7 +1420,7 @@ bbegin:
//SEG5 [0] phi (byte) x#2 = (byte) 0 -- xby=coby1 //SEG5 [0] phi (byte) x#2 = (byte) 0 -- xby=coby1
ldx #$0 ldx #$0
//SEG6 [0] phi (word) idx#3 = (byte) 0+(byte) 0*(byte) 40 -- zpwo1=coby1 //SEG6 [0] phi (word) idx#3 = (byte) 0+(byte) 0*(byte) 40 -- zpwo1=coby1
lda #$0+($0*$28) lda #$0+$0*$28
sta idx sta idx
lda #$0 lda #$0
sta idx+$1 sta idx+$1
@ -1511,7 +1511,7 @@ ASSEMBLER
//SEG5 [0] phi (byte) x#2 = (byte) 0 -- xby=coby1 //SEG5 [0] phi (byte) x#2 = (byte) 0 -- xby=coby1
ldx #$0 ldx #$0
//SEG6 [0] phi (word) idx#3 = (byte) 0+(byte) 0*(byte) 40 -- zpwo1=coby1 //SEG6 [0] phi (word) idx#3 = (byte) 0+(byte) 0*(byte) 40 -- zpwo1=coby1
lda #$0+($0*$28) lda #$0+$0*$28
sta idx sta idx
lda #$0 lda #$0
sta idx+$1 sta idx+$1
@ -1598,7 +1598,7 @@ ASSEMBLER
//SEG5 [0] phi (byte) x#2 = (byte) 0 -- xby=coby1 //SEG5 [0] phi (byte) x#2 = (byte) 0 -- xby=coby1
ldx #$0 ldx #$0
//SEG6 [0] phi (word) idx#3 = (byte) 0+(byte) 0*(byte) 40 -- zpwo1=coby1 //SEG6 [0] phi (word) idx#3 = (byte) 0+(byte) 0*(byte) 40 -- zpwo1=coby1
lda #$0+($0*$28) lda #$0+$0*$28
sta idx sta idx
lda #$0 lda #$0
sta idx+$1 sta idx+$1
@ -1725,7 +1725,7 @@ FINAL CODE
//SEG5 [0] phi (byte) x#2 = (byte) 0 -- xby=coby1 //SEG5 [0] phi (byte) x#2 = (byte) 0 -- xby=coby1
ldx #$0 ldx #$0
//SEG6 [0] phi (word) idx#3 = (byte) 0+(byte) 0*(byte) 40 -- zpwo1=coby1 //SEG6 [0] phi (word) idx#3 = (byte) 0+(byte) 0*(byte) 40 -- zpwo1=coby1
lda #$0+($0*$28) lda #$0+$0*$28
sta idx sta idx
lda #$0 lda #$0
sta idx+$1 sta idx+$1

View File

@ -2,7 +2,7 @@
.const STAR = $51 .const STAR = $51
.const VIC = $d000 .const VIC = $d000
.const RED = $2 .const RED = $2
.const BGCOL = (VIC+($10*$2))+$1 .const BGCOL = VIC+$10*$2+$1
jsr main jsr main
main: { main: {
lda #STAR lda #STAR

View File

@ -645,7 +645,7 @@ INITIAL ASM
.const STAR = $51 .const STAR = $51
.const VIC = $d000 .const VIC = $d000
.const RED = $2 .const RED = $2
.const BGCOL = (VIC+($10*$2))+$1 .const BGCOL = VIC+$10*$2+$1
//SEG1 @begin //SEG1 @begin
bbegin: bbegin:
//SEG2 [0] call main param-assignment [ ] //SEG2 [0] call main param-assignment [ ]
@ -717,7 +717,7 @@ ASSEMBLER
.const STAR = $51 .const STAR = $51
.const VIC = $d000 .const VIC = $d000
.const RED = $2 .const RED = $2
.const BGCOL = (VIC+($10*$2))+$1 .const BGCOL = VIC+$10*$2+$1
//SEG1 @begin //SEG1 @begin
bbegin: bbegin:
//SEG2 [0] call main param-assignment [ ] //SEG2 [0] call main param-assignment [ ]
@ -765,7 +765,7 @@ ASSEMBLER
.const STAR = $51 .const STAR = $51
.const VIC = $d000 .const VIC = $d000
.const RED = $2 .const RED = $2
.const BGCOL = (VIC+($10*$2))+$1 .const BGCOL = VIC+$10*$2+$1
//SEG1 @begin //SEG1 @begin
bbegin: bbegin:
//SEG2 [0] call main param-assignment [ ] //SEG2 [0] call main param-assignment [ ]
@ -814,7 +814,7 @@ ASSEMBLER
.const STAR = $51 .const STAR = $51
.const VIC = $d000 .const VIC = $d000
.const RED = $2 .const RED = $2
.const BGCOL = (VIC+($10*$2))+$1 .const BGCOL = VIC+$10*$2+$1
//SEG1 @begin //SEG1 @begin
//SEG2 [0] call main param-assignment [ ] //SEG2 [0] call main param-assignment [ ]
jsr main jsr main
@ -856,7 +856,7 @@ ASSEMBLER
.const STAR = $51 .const STAR = $51
.const VIC = $d000 .const VIC = $d000
.const RED = $2 .const RED = $2
.const BGCOL = (VIC+($10*$2))+$1 .const BGCOL = VIC+$10*$2+$1
//SEG1 @begin //SEG1 @begin
//SEG2 [0] call main param-assignment [ ] //SEG2 [0] call main param-assignment [ ]
jsr main jsr main
@ -917,7 +917,7 @@ FINAL CODE
.const STAR = $51 .const STAR = $51
.const VIC = $d000 .const VIC = $d000
.const RED = $2 .const RED = $2
.const BGCOL = (VIC+($10*$2))+$1 .const BGCOL = VIC+$10*$2+$1
//SEG1 @begin //SEG1 @begin
//SEG2 [0] call main param-assignment [ ] //SEG2 [0] call main param-assignment [ ]
jsr main jsr main

View File

@ -28,9 +28,9 @@ plot: {
.label y = 4 .label y = 4
lda #$10 lda #$10
sta y sta y
lda #<SCREEN+(($5*$28)+$c) lda #<SCREEN+$5*$28+$c
sta line sta line
lda #>SCREEN+(($5*$28)+$c) lda #>SCREEN+$5*$28+$c
sta line+$1 sta line+$1
ldx #$0 ldx #$0
b1: b1:

View File

@ -4380,9 +4380,9 @@ plot: {
lda #$10 lda #$10
sta y sta y
//SEG35 [15] phi (byte*) plot::line#2 = (const byte[1000]) SCREEN#0+(byte) 5*(byte) 40+(byte) 12 -- zpptrby1=cowo1 //SEG35 [15] phi (byte*) plot::line#2 = (const byte[1000]) SCREEN#0+(byte) 5*(byte) 40+(byte) 12 -- zpptrby1=cowo1
lda #<SCREEN+(($5*$28)+$c) lda #<SCREEN+$5*$28+$c
sta line sta line
lda #>SCREEN+(($5*$28)+$c) lda #>SCREEN+$5*$28+$c
sta line+$1 sta line+$1
//SEG36 [15] phi (byte) plot::i#3 = (byte) 0 -- zpby1=coby1 //SEG36 [15] phi (byte) plot::i#3 = (byte) 0 -- zpby1=coby1
lda #$0 lda #$0
@ -4738,9 +4738,9 @@ plot: {
lda #$10 lda #$10
sta y sta y
//SEG35 [15] phi (byte*) plot::line#2 = (const byte[1000]) SCREEN#0+(byte) 5*(byte) 40+(byte) 12 -- zpptrby1=cowo1 //SEG35 [15] phi (byte*) plot::line#2 = (const byte[1000]) SCREEN#0+(byte) 5*(byte) 40+(byte) 12 -- zpptrby1=cowo1
lda #<SCREEN+(($5*$28)+$c) lda #<SCREEN+$5*$28+$c
sta line sta line
lda #>SCREEN+(($5*$28)+$c) lda #>SCREEN+$5*$28+$c
sta line+$1 sta line+$1
//SEG36 [15] phi (byte) plot::i#3 = (byte) 0 -- xby=coby1 //SEG36 [15] phi (byte) plot::i#3 = (byte) 0 -- xby=coby1
ldx #$0 ldx #$0
@ -5006,9 +5006,9 @@ plot: {
lda #$10 lda #$10
sta y sta y
//SEG35 [15] phi (byte*) plot::line#2 = (const byte[1000]) SCREEN#0+(byte) 5*(byte) 40+(byte) 12 -- zpptrby1=cowo1 //SEG35 [15] phi (byte*) plot::line#2 = (const byte[1000]) SCREEN#0+(byte) 5*(byte) 40+(byte) 12 -- zpptrby1=cowo1
lda #<SCREEN+(($5*$28)+$c) lda #<SCREEN+$5*$28+$c
sta line sta line
lda #>SCREEN+(($5*$28)+$c) lda #>SCREEN+$5*$28+$c
sta line+$1 sta line+$1
//SEG36 [15] phi (byte) plot::i#3 = (byte) 0 -- xby=coby1 //SEG36 [15] phi (byte) plot::i#3 = (byte) 0 -- xby=coby1
ldx #$0 ldx #$0
@ -5254,9 +5254,9 @@ plot: {
lda #$10 lda #$10
sta y sta y
//SEG35 [15] phi (byte*) plot::line#2 = (const byte[1000]) SCREEN#0+(byte) 5*(byte) 40+(byte) 12 -- zpptrby1=cowo1 //SEG35 [15] phi (byte*) plot::line#2 = (const byte[1000]) SCREEN#0+(byte) 5*(byte) 40+(byte) 12 -- zpptrby1=cowo1
lda #<SCREEN+(($5*$28)+$c) lda #<SCREEN+$5*$28+$c
sta line sta line
lda #>SCREEN+(($5*$28)+$c) lda #>SCREEN+$5*$28+$c
sta line+$1 sta line+$1
//SEG36 [15] phi (byte) plot::i#3 = (byte) 0 -- xby=coby1 //SEG36 [15] phi (byte) plot::i#3 = (byte) 0 -- xby=coby1
ldx #$0 ldx #$0
@ -5483,9 +5483,9 @@ plot: {
lda #$10 lda #$10
sta y sta y
//SEG35 [15] phi (byte*) plot::line#2 = (const byte[1000]) SCREEN#0+(byte) 5*(byte) 40+(byte) 12 -- zpptrby1=cowo1 //SEG35 [15] phi (byte*) plot::line#2 = (const byte[1000]) SCREEN#0+(byte) 5*(byte) 40+(byte) 12 -- zpptrby1=cowo1
lda #<SCREEN+(($5*$28)+$c) lda #<SCREEN+$5*$28+$c
sta line sta line
lda #>SCREEN+(($5*$28)+$c) lda #>SCREEN+$5*$28+$c
sta line+$1 sta line+$1
//SEG36 [15] phi (byte) plot::i#3 = (byte) 0 -- xby=coby1 //SEG36 [15] phi (byte) plot::i#3 = (byte) 0 -- xby=coby1
ldx #$0 ldx #$0
@ -5700,9 +5700,9 @@ plot: {
lda #$10 lda #$10
sta y sta y
//SEG35 [15] phi (byte*) plot::line#2 = (const byte[1000]) SCREEN#0+(byte) 5*(byte) 40+(byte) 12 -- zpptrby1=cowo1 //SEG35 [15] phi (byte*) plot::line#2 = (const byte[1000]) SCREEN#0+(byte) 5*(byte) 40+(byte) 12 -- zpptrby1=cowo1
lda #<SCREEN+(($5*$28)+$c) lda #<SCREEN+$5*$28+$c
sta line sta line
lda #>SCREEN+(($5*$28)+$c) lda #>SCREEN+$5*$28+$c
sta line+$1 sta line+$1
//SEG36 [15] phi (byte) plot::i#3 = (byte) 0 -- xby=coby1 //SEG36 [15] phi (byte) plot::i#3 = (byte) 0 -- xby=coby1
ldx #$0 ldx #$0
@ -5915,9 +5915,9 @@ plot: {
lda #$10 lda #$10
sta y sta y
//SEG35 [15] phi (byte*) plot::line#2 = (const byte[1000]) SCREEN#0+(byte) 5*(byte) 40+(byte) 12 -- zpptrby1=cowo1 //SEG35 [15] phi (byte*) plot::line#2 = (const byte[1000]) SCREEN#0+(byte) 5*(byte) 40+(byte) 12 -- zpptrby1=cowo1
lda #<SCREEN+(($5*$28)+$c) lda #<SCREEN+$5*$28+$c
sta line sta line
lda #>SCREEN+(($5*$28)+$c) lda #>SCREEN+$5*$28+$c
sta line+$1 sta line+$1
//SEG36 [15] phi (byte) plot::i#3 = (byte) 0 -- xby=coby1 //SEG36 [15] phi (byte) plot::i#3 = (byte) 0 -- xby=coby1
ldx #$0 ldx #$0
@ -6220,9 +6220,9 @@ plot: {
lda #$10 lda #$10
sta y sta y
//SEG35 [15] phi (byte*) plot::line#2 = (const byte[1000]) SCREEN#0+(byte) 5*(byte) 40+(byte) 12 -- zpptrby1=cowo1 //SEG35 [15] phi (byte*) plot::line#2 = (const byte[1000]) SCREEN#0+(byte) 5*(byte) 40+(byte) 12 -- zpptrby1=cowo1
lda #<SCREEN+(($5*$28)+$c) lda #<SCREEN+$5*$28+$c
sta line sta line
lda #>SCREEN+(($5*$28)+$c) lda #>SCREEN+$5*$28+$c
sta line+$1 sta line+$1
//SEG36 [15] phi (byte) plot::i#3 = (byte) 0 -- xby=coby1 //SEG36 [15] phi (byte) plot::i#3 = (byte) 0 -- xby=coby1
ldx #$0 ldx #$0