diff --git a/src/main/java/dk/camelot64/kickc/asm/AsmProgram.java b/src/main/java/dk/camelot64/kickc/asm/AsmProgram.java index 7b0950e61..3d57bab75 100644 --- a/src/main/java/dk/camelot64/kickc/asm/AsmProgram.java +++ b/src/main/java/dk/camelot64/kickc/asm/AsmProgram.java @@ -3,27 +3,52 @@ package dk.camelot64.kickc.asm; import dk.camelot64.kickc.asm.parser.AsmClobber; import java.util.ArrayList; +import java.util.Collection; import java.util.List; -/** A 6502 assembler program */ +/** + * A 6502 assembler program + */ public class AsmProgram { - private List lines; + /** + * The segments of the program. The segments hold the ASM lines. + */ + private List segments; - private int nextIndex; + /** + * The index of the next segment. + */ + private int nextSegmentIndex; + + /** + * The index of the next line. + */ + private int nextLineIndex; public AsmProgram() { - this.lines = new ArrayList<>(); - this.nextIndex = 0; + this.segments = new ArrayList<>(); + this.nextLineIndex = 0; + this.nextSegmentIndex = 0; } - public List getLines() { - return lines; + public Collection getSegments() { + return segments; + } + + public AsmSegment startSegment(Integer statementIndex, String source) { + AsmSegment segment = new AsmSegment(nextSegmentIndex++, statementIndex, source); + segments.add(segment); + return segment; + } + + public AsmSegment getCurrentSegment() { + return segments.get(segments.size() - 1); } public void addLine(AsmLine line) { - line.setIndex(nextIndex++); - lines.add(line); + line.setIndex(nextLineIndex++); + getCurrentSegment().addLine(line); } public void addComment(String comment) { @@ -39,18 +64,53 @@ public class AsmProgram { addLine(new AsmInstruction(instructionType, parameter)); } + + /** + * Get the number of bytes the segment occupies in memory. + * Calculated by adding up the bytes of each ASM segment in the program. + * + * @return The number of bytes + */ + public int getBytes() { + int bytes = 0; + for (AsmSegment segment : segments) { + bytes += segment.getBytes(); + } + return bytes; + } + + /** + * Get the number of cycles it takes to execute the segment + * Calculated by adding up the cycles of each ASM segments in the program. + * + * @return The number of cycles + */ + public double getCycles() { + double cycles = 0.0; + for (AsmSegment segment : segments) { + cycles += segment.getCycles(); + } + return cycles; + } + + + /** + * Get the CPU registers clobbered by the instructions of the fragment + * + * @return The clobbered registers + */ + public AsmClobber getClobber() { + AsmClobber clobber = new AsmClobber(); + for (AsmSegment segment : segments) { + clobber.add(segment.getClobber()); + } + return clobber; + } + public String toString(boolean comments) { - StringBuffer out = new StringBuffer(); - for (AsmLine line : lines) { - if(line instanceof AsmComment && !comments) { - if(!((AsmComment) line).getComment().contains("Fragment")) { - continue; - } - } - if(line instanceof AsmComment || line instanceof AsmInstruction) { - out.append(" "); - } - out.append(line.getAsm()+"\n"); + StringBuilder out = new StringBuilder(); + for (AsmSegment segment : segments) { + out.append(segment.toString(comments)); } return out.toString(); } @@ -60,19 +120,5 @@ public class AsmProgram { return toString(true); } - /** - * Get the CPU registers clobbered by the instructions of the fragment - * @return The clobbered registers - */ - public AsmClobber getClobber() { - AsmClobber clobber = new AsmClobber(); - for (AsmLine line : lines) { - if(line instanceof AsmInstruction) { - AsmInstructionType instructionType = ((AsmInstruction) line).getType(); - AsmClobber lineClobber = instructionType.getClobber(); - clobber.add(lineClobber); - } - } - return clobber; - } + } diff --git a/src/main/java/dk/camelot64/kickc/asm/AsmProgramStaticRegisterValues.java b/src/main/java/dk/camelot64/kickc/asm/AsmProgramStaticRegisterValues.java index 81bf27378..a530886b6 100644 --- a/src/main/java/dk/camelot64/kickc/asm/AsmProgramStaticRegisterValues.java +++ b/src/main/java/dk/camelot64/kickc/asm/AsmProgramStaticRegisterValues.java @@ -28,76 +28,83 @@ public class AsmProgramStaticRegisterValues { private void initValues() { AsmRegisterValues current = new AsmRegisterValues(); - for (AsmLine line : program.getLines()) { - if (line instanceof AsmLabel) { - current = new AsmRegisterValues(); - } else if (line instanceof AsmInstruction) { - AsmInstruction instruction = (AsmInstruction) line; - values.put(instruction, current); - current = new AsmRegisterValues(current); - AsmInstructionType instructionType = instruction.getType(); - AsmClobber clobber = instructionType.getClobber(); - if (clobber.isClobberA()) { - current.setA(null); - } - if (clobber.isClobberX()) { - current.setX(null); - } - if (clobber.isClobberY()) { - current.setY(null); - } - if (clobber.isClobberC()) { - current.setC(null); - } - if (clobber.isClobberN()) { - current.setN(null); - } - if (clobber.isClobberV()) { - current.setV(null); - } - if (clobber.isClobberZ()) { - current.setZ(null); - } - if (instructionType.getMnemnonic().equals("lda") && instructionType.getAddressingMode().equals(AsmAddressingMode.IMM)) { - try { - int immValue = Integer.parseInt(instruction.getParameter()); - current.setZ(immValue == 0); - current.setN(immValue > 127); - current.setA(immValue); - } catch (NumberFormatException e) { - // ignore - } - } - if (instructionType.getMnemnonic().equals("ldx") && instructionType.getAddressingMode().equals(AsmAddressingMode.IMM)) { - try { - int immValue = Integer.parseInt(instruction.getParameter()); - current.setZ(immValue == 0); - current.setN(immValue > 127); - current.setX(immValue); - } catch (NumberFormatException e) { - // ignore - } - } - if (instructionType.getMnemnonic().equals("ldy") && instructionType.getAddressingMode().equals(AsmAddressingMode.IMM)) { - try { - int immValue = Integer.parseInt(instruction.getParameter()); - current.setZ(immValue == 0); - current.setN(immValue > 127); - current.setY(immValue); - } catch (NumberFormatException e) { - // ignore - } - } - if (instructionType.getMnemnonic().equals("sec")) { - current.setC(Boolean.TRUE); - } - if (instructionType.getMnemnonic().equals("clc")) { - current.setC(Boolean.FALSE); - } + for (AsmSegment segment : program.getSegments()) { + for (AsmLine line : segment.getLines()) { + current = updateStaticRegisterValues(current, line); } } } + private AsmRegisterValues updateStaticRegisterValues(AsmRegisterValues current, AsmLine line) { + if (line instanceof AsmLabel) { + current = new AsmRegisterValues(); + } else if (line instanceof AsmInstruction) { + AsmInstruction instruction = (AsmInstruction) line; + values.put(instruction, current); + current = new AsmRegisterValues(current); + AsmInstructionType instructionType = instruction.getType(); + AsmClobber clobber = instructionType.getClobber(); + if (clobber.isClobberA()) { + current.setA(null); + } + if (clobber.isClobberX()) { + current.setX(null); + } + if (clobber.isClobberY()) { + current.setY(null); + } + if (clobber.isClobberC()) { + current.setC(null); + } + if (clobber.isClobberN()) { + current.setN(null); + } + if (clobber.isClobberV()) { + current.setV(null); + } + if (clobber.isClobberZ()) { + current.setZ(null); + } + if (instructionType.getMnemnonic().equals("lda") && instructionType.getAddressingMode().equals(AsmAddressingMode.IMM)) { + try { + int immValue = Integer.parseInt(instruction.getParameter()); + current.setZ(immValue == 0); + current.setN(immValue > 127); + current.setA(immValue); + } catch (NumberFormatException e) { + // ignore + } + } + if (instructionType.getMnemnonic().equals("ldx") && instructionType.getAddressingMode().equals(AsmAddressingMode.IMM)) { + try { + int immValue = Integer.parseInt(instruction.getParameter()); + current.setZ(immValue == 0); + current.setN(immValue > 127); + current.setX(immValue); + } catch (NumberFormatException e) { + // ignore + } + } + if (instructionType.getMnemnonic().equals("ldy") && instructionType.getAddressingMode().equals(AsmAddressingMode.IMM)) { + try { + int immValue = Integer.parseInt(instruction.getParameter()); + current.setZ(immValue == 0); + current.setN(immValue > 127); + current.setY(immValue); + } catch (NumberFormatException e) { + // ignore + } + } + if (instructionType.getMnemnonic().equals("sec")) { + current.setC(Boolean.TRUE); + } + if (instructionType.getMnemnonic().equals("clc")) { + current.setC(Boolean.FALSE); + } + } + return current; + } + /** * Known values of registers/flags at an instruction. null where value is unknown. */ diff --git a/src/main/java/dk/camelot64/kickc/asm/AsmSegment.java b/src/main/java/dk/camelot64/kickc/asm/AsmSegment.java new file mode 100644 index 000000000..2410259b6 --- /dev/null +++ b/src/main/java/dk/camelot64/kickc/asm/AsmSegment.java @@ -0,0 +1,147 @@ +package dk.camelot64.kickc.asm; + +import dk.camelot64.kickc.asm.parser.AsmClobber; + +import java.util.ArrayList; +import java.util.List; + +/** + * A segment of an ASM program. The segment has a number of methods/attributes that describe the lines of the segment. + * Typically each ICL statement becomes a single ASM segment through the AsmFragment subsystem. + */ +public class AsmSegment { + + /** + * The lines of the segment. + */ + private List lines; + + /** + * Index of the segment. + */ + private int index; + + /** + * Index of the ICL statement that the segment is generated from, + */ + private Integer statementIdx; + + /** + * Readable name of the ICL source of the segment. + */ + private String source; + + /** + * Readable name of the fragment used to generate the segment. + */ + private String fragment; + + public AsmSegment(int index, Integer statementIdx, String source) { + this.lines = new ArrayList<>(); + this.index = index; + this.statementIdx = statementIdx; + this.source = source; + } + + public List getLines() { + return lines; + } + + public void addLine(AsmLine line) { + lines.add(line); + } + + public int getIndex() { + return index; + } + + public Integer getStatementIdx() { + return statementIdx; + } + + public String getSource() { + return source; + } + + public void setFragment(String fragment) { + this.fragment = fragment; + } + + + /** + * Get the number of bytes the segment occupies in memory. + * Per default calculated by adding up the bytes of each ASM line in the segment. + * + * @return The number of bytes + */ + public int getBytes() { + int bytes = 0; + for (AsmLine line : lines) { + bytes += line.getLineBytes(); + } + return bytes; + } + + /** + * Get the number of cycles it takes to execute the segment + * Per default calculated by adding up the cycles of each ASM line in the segment. + * + * @return The number of cycles + */ + public double getCycles() { + double cycles = 0.0; + for (AsmLine line : lines) { + cycles += line.getLineCycles(); + } + return cycles; + } + + /** + * Get the registers clobbered when executing the segment + * Per default calculated by adding up the clobber of each ASM line in the segment. + * + * @return The registers clobbered + */ + public AsmClobber getClobber() { + AsmClobber clobber = new AsmClobber(); + for (AsmLine line : lines) { + if (line instanceof AsmInstruction) { + clobber.add(((AsmInstruction) line).getType().getClobber()); + } + } + return clobber; + } + + public String toString(boolean comments) { + StringBuffer out = new StringBuffer(); + if (comments) { + out.append("//SEG").append(getIndex()); + if (source != null) { + out.append(" ").append(source); + } + if (fragment!=null) { + out.append(" -- "); + out.append(fragment).append(" "); + } + out.append("\n"); + } + for (AsmLine line : lines) { + if (line instanceof AsmComment && !comments) { + if (!((AsmComment) line).getComment().contains("Fragment")) { + continue; + } + } + if (line instanceof AsmComment || line instanceof AsmInstruction) { + out.append(" "); + } + out.append(line.getAsm() + "\n"); + } + return out.toString(); + } + + @Override + public String toString() { + return toString(true); + } + +} diff --git a/src/main/java/dk/camelot64/kickc/icl/Program.java b/src/main/java/dk/camelot64/kickc/icl/Program.java index 6c418bcb9..429cc24b5 100644 --- a/src/main/java/dk/camelot64/kickc/icl/Program.java +++ b/src/main/java/dk/camelot64/kickc/icl/Program.java @@ -25,7 +25,7 @@ public class Program { /** Information about loops. */ private NaturalLoopSet loopSet; - /** The register allocation for the vairalbes used during ASM code generation. */ + /** The register allocation for the variables used during ASM code generation. */ private RegisterAllocation allocation; /** The live ranges of all variables. */ private LiveRangeVariables liveRangeVariables; diff --git a/src/main/java/dk/camelot64/kickc/passes/Pass3AssertNoCpuClobber.java b/src/main/java/dk/camelot64/kickc/passes/Pass3AssertNoCpuClobber.java index 2fe909992..3022fffba 100644 --- a/src/main/java/dk/camelot64/kickc/passes/Pass3AssertNoCpuClobber.java +++ b/src/main/java/dk/camelot64/kickc/passes/Pass3AssertNoCpuClobber.java @@ -54,7 +54,7 @@ public class Pass3AssertNoCpuClobber extends Pass2Base { continue; } if(aliveVarRegister.equals(register)) { - registerCycles += countCycles(asm); + registerCycles += asm.getCycles(); } if(assignedVars.contains(aliveVar)) { // No need to register that is assigned by the statement - it will be clobbered @@ -77,17 +77,6 @@ public class Pass3AssertNoCpuClobber extends Pass2Base { return clobberProblem; } - private int countCycles(AsmProgram asm) { - int instructionCycles = 0; - for (AsmLine asmLine : asm.getLines()) { - if(asmLine instanceof AsmInstruction) { - double lineCycles = ((AsmInstruction) asmLine).getType().getCycles(); - instructionCycles += lineCycles; - } - } - return instructionCycles; - } - /** * Get the variables assigned to by a specific statement diff --git a/src/main/java/dk/camelot64/kickc/passes/Pass4CodeGeneration.java b/src/main/java/dk/camelot64/kickc/passes/Pass4CodeGeneration.java index 9617622de..c1d8159af 100644 --- a/src/main/java/dk/camelot64/kickc/passes/Pass4CodeGeneration.java +++ b/src/main/java/dk/camelot64/kickc/passes/Pass4CodeGeneration.java @@ -31,6 +31,7 @@ public class Pass4CodeGeneration { // Generate entry points (if needed) genBlockEntryPoints(asm, block); // Generate label + asm.startSegment(null, block.getLabel().getFullName()); asm.addLabel(block.getLabel().getFullName().replace('@', 'B').replace(':', '_')); // Generate statements genStatements(asm, block); @@ -51,7 +52,9 @@ public class Pass4CodeGeneration { AsmCodegenAluState aluState = new AsmCodegenAluState(); while (statementsIt.hasNext()) { Statement statement = statementsIt.next(); - generateStatementAsm(asm, block, statement, aluState); + if(!(statement instanceof StatementPhiBlock)) { + generateStatementAsm(asm, block, statement, aluState); + } } } @@ -66,6 +69,8 @@ public class Pass4CodeGeneration { */ public void generateStatementAsm(AsmProgram asm, ControlFlowBlock block, Statement statement, AsmCodegenAluState aluState) { + asm.startSegment(statement.getIndex(), statement.toString(program)); + // IF the previous statement was added to the ALU register - generate the composite ASM fragment if (aluState.hasAluAssignment()) { StatementAssignment assignmentAlu = aluState.getAluAssignment(); @@ -74,7 +79,7 @@ public class Pass4CodeGeneration { } StatementAssignment assignment = (StatementAssignment) statement; AsmFragment asmFragment = new AsmFragment(assignment, assignmentAlu, program); - asm.addComment(statement.toString(program) + " // " + asmFragment.getSignature()); + asm.getCurrentSegment().setFragment(asmFragment.getSignature()); asmFragment.generate(asm); aluState.clear(); return; @@ -100,13 +105,13 @@ public class Pass4CodeGeneration { asm.addComment(lValue.toString(program) + " = " + assignment.getrValue2().toString(program) + " // register copy " + getRegister(lValue)); } else { AsmFragment asmFragment = new AsmFragment(assignment, program); - asm.addComment(statement.toString(program) + " // " + asmFragment.getSignature()); + asm.getCurrentSegment().setFragment(asmFragment.getSignature()); asmFragment.generate(asm); } } } else if (statement instanceof StatementConditionalJump) { AsmFragment asmFragment = new AsmFragment((StatementConditionalJump) statement, block, program, getGraph()); - asm.addComment(statement.toString(program) + " // " + asmFragment.getSignature()); + asm.getCurrentSegment().setFragment(asmFragment.getSignature()); asmFragment.generate(asm); } else if (statement instanceof StatementCall) { StatementCall call = (StatementCall) statement; @@ -168,6 +173,8 @@ public class Pass4CodeGeneration { } private void genBlockPhiTransition(AsmProgram asm, ControlFlowBlock fromBlock, ControlFlowBlock toBlock) { + Statement toFirstStatement = toBlock.getStatements().get(0); + asm.startSegment(toFirstStatement.getIndex(), "["+toFirstStatement.getIndex()+"]"+" phi from " + fromBlock.getLabel().getFullName()+" to "+toBlock.getLabel().getFullName()); asm.addLabel((toBlock.getLabel().getFullName() + "_from_" + fromBlock.getLabel().getLocalName()).replace('@', 'B').replace(':', '_')); if (toBlock.hasPhiBlock()) { StatementPhiBlock phiBlock = toBlock.getPhiBlock(); @@ -183,7 +190,7 @@ public class Pass4CodeGeneration { }); for (StatementPhiBlock.PhiRValue phiRValue : phiRValues) { if (phiRValue.getPredecessor().equals(fromBlock.getLabel())) { - genAsmMove(asm, phiVariable.getVariable(), phiRValue.getrValue()); + genAsmMove(asm, phiVariable.getVariable(), phiRValue.getrValue(), phiBlock); break; } } @@ -200,12 +207,13 @@ public class Pass4CodeGeneration { } } - private void genAsmMove(AsmProgram asm, LValue lValue, RValue rValue) { + private void genAsmMove(AsmProgram asm, LValue lValue, RValue rValue, Statement statement) { + asm.startSegment(statement.getIndex(), "["+statement.getIndex() + "] phi " +lValue.toString(program) + " = " + rValue.toString(program)); if (isRegisterCopy(lValue, rValue)) { - asm.addComment(lValue.toString(program) + " = " + rValue.toString(program) + " // register copy " + getRegister(lValue)); + asm.getCurrentSegment().setFragment("register_copy"); } else { AsmFragment asmFragment = new AsmFragment(lValue, rValue, program); - asm.addComment(lValue.toString(program) + " = " + rValue.toString(program) + " // " + asmFragment.getSignature()); + asm.getCurrentSegment().setFragment(asmFragment.getSignature()); asmFragment.generate(asm); } } diff --git a/src/main/java/dk/camelot64/kickc/passes/Pass5AsmOptimization.java b/src/main/java/dk/camelot64/kickc/passes/Pass5AsmOptimization.java index 699c9a3e6..6493fed1e 100644 --- a/src/main/java/dk/camelot64/kickc/passes/Pass5AsmOptimization.java +++ b/src/main/java/dk/camelot64/kickc/passes/Pass5AsmOptimization.java @@ -3,12 +3,15 @@ package dk.camelot64.kickc.passes; import dk.camelot64.kickc.CompileLog; import dk.camelot64.kickc.asm.AsmLine; import dk.camelot64.kickc.asm.AsmProgram; +import dk.camelot64.kickc.asm.AsmSegment; import dk.camelot64.kickc.icl.Program; +import java.util.Collection; import java.util.Iterator; import java.util.List; -/** Optimization performed on Assembler Code (Asm Code). +/** + * Optimization performed on Assembler Code (Asm Code). * Optimizations are performed repeatedly until none of them yield any result **/ public abstract class Pass5AsmOptimization { @@ -37,11 +40,14 @@ public abstract class Pass5AsmOptimization { } public void remove(List remove) { - for (Iterator iterator = getAsmProgram().getLines().iterator(); iterator.hasNext(); ) { - AsmLine line = iterator.next(); - if (remove.contains(line)) { - log.append("Removing instruction "+line.getAsm()); - iterator.remove(); + Collection segments = getAsmProgram().getSegments(); + for (AsmSegment segment : segments) { + for (Iterator iterator = segment.getLines().iterator(); iterator.hasNext(); ) { + AsmLine line = iterator.next(); + if (remove.contains(line)) { + log.append("Removing instruction " + line.getAsm()); + iterator.remove(); + } } } } diff --git a/src/main/java/dk/camelot64/kickc/passes/Pass5NextJumpElimination.java b/src/main/java/dk/camelot64/kickc/passes/Pass5NextJumpElimination.java index 1f2eaad79..69bd86366 100644 --- a/src/main/java/dk/camelot64/kickc/passes/Pass5NextJumpElimination.java +++ b/src/main/java/dk/camelot64/kickc/passes/Pass5NextJumpElimination.java @@ -1,16 +1,15 @@ package dk.camelot64.kickc.passes; import dk.camelot64.kickc.CompileLog; -import dk.camelot64.kickc.asm.AsmInstruction; -import dk.camelot64.kickc.asm.AsmLabel; -import dk.camelot64.kickc.asm.AsmLine; -import dk.camelot64.kickc.asm.AsmProgram; +import dk.camelot64.kickc.asm.*; import dk.camelot64.kickc.icl.Program; import java.util.ArrayList; import java.util.List; -/** Optimize assembler code by removing jumps to labels immediately following the jump */ +/** + * Optimize assembler code by removing jumps to labels immediately following the jump + */ public class Pass5NextJumpElimination extends Pass5AsmOptimization { public Pass5NextJumpElimination(Program program, CompileLog log) { @@ -20,23 +19,26 @@ public class Pass5NextJumpElimination extends Pass5AsmOptimization { public boolean optimize() { List removeLines = new ArrayList<>(); AsmInstruction candidate = null; - for (AsmLine line : getAsmProgram().getLines()) { - if(candidate!=null) { - if(line instanceof AsmLabel) { - if(((AsmLabel) line).getLabel().equals(candidate.getParameter())) { - removeLines.add(candidate); + for (AsmSegment segment : getAsmProgram().getSegments()) { + for (AsmLine line : segment.getLines()) { + if (candidate != null) { + if (line instanceof AsmLabel) { + if (((AsmLabel) line).getLabel().equals(candidate.getParameter())) { + removeLines.add(candidate); + } + } + } + if (line instanceof AsmInstruction) { + candidate = null; + AsmInstruction instruction = (AsmInstruction) line; + if (instruction.getType().isJump()) { + candidate = instruction; } } } - if(line instanceof AsmInstruction) { - candidate = null; - AsmInstruction instruction = (AsmInstruction) line; - if(instruction.getType().isJump()) { - candidate = instruction; - } - } + } remove(removeLines); - return removeLines.size()>0; + return removeLines.size() > 0; } } diff --git a/src/main/java/dk/camelot64/kickc/passes/Pass5UnnecesaryLoadElimination.java b/src/main/java/dk/camelot64/kickc/passes/Pass5UnnecesaryLoadElimination.java index b8941239b..5c6a0a004 100644 --- a/src/main/java/dk/camelot64/kickc/passes/Pass5UnnecesaryLoadElimination.java +++ b/src/main/java/dk/camelot64/kickc/passes/Pass5UnnecesaryLoadElimination.java @@ -8,7 +8,9 @@ import dk.camelot64.kickc.icl.Program; import java.util.ArrayList; import java.util.List; -/** Maps out register values entering all instructions. Removes unnecessary loads / clears / sets */ +/** + * Maps out register values entering all instructions. Removes unnecessary loads / clears / sets + */ public class Pass5UnnecesaryLoadElimination extends Pass5AsmOptimization { public Pass5UnnecesaryLoadElimination(Program program, CompileLog log) { @@ -19,59 +21,62 @@ public class Pass5UnnecesaryLoadElimination extends Pass5AsmOptimization { public boolean optimize() { AsmProgramStaticRegisterValues staticValues = new AsmProgramStaticRegisterValues(getAsmProgram()); List removes = new ArrayList<>(); - for (AsmLine line : getAsmProgram().getLines()) { - if(line instanceof AsmInstruction) { - AsmInstruction instruction = (AsmInstruction) line; - AsmInstructionType instructionType = instruction.getType(); - if(instructionType.getMnemnonic().equals("lda") && instructionType.getAddressingMode().equals(AsmAddressingMode.IMM)) { - try { - int immValue = Integer.parseInt(instruction.getParameter()); + + for (AsmSegment segment : getAsmProgram().getSegments()) { + for (AsmLine line : segment.getLines()) { + if (line instanceof AsmInstruction) { + AsmInstruction instruction = (AsmInstruction) line; + AsmInstructionType instructionType = instruction.getType(); + if (instructionType.getMnemnonic().equals("lda") && instructionType.getAddressingMode().equals(AsmAddressingMode.IMM)) { + try { + int immValue = Integer.parseInt(instruction.getParameter()); + AsmProgramStaticRegisterValues.AsmRegisterValues instructionValues = staticValues.getValues(instruction); + if (instructionValues.getA() != null && instructionValues.getA().equals(immValue)) { + removes.add(instruction); + } + } catch (NumberFormatException e) { + // ignore + } + } + if (instructionType.getMnemnonic().equals("ldx") && instructionType.getAddressingMode().equals(AsmAddressingMode.IMM)) { + try { + int immValue = Integer.parseInt(instruction.getParameter()); + AsmProgramStaticRegisterValues.AsmRegisterValues instructionValues = staticValues.getValues(instruction); + if (instructionValues.getX() != null && instructionValues.getX().equals(immValue)) { + removes.add(instruction); + } + } catch (NumberFormatException e) { + // ignore + } + + } + if (instructionType.getMnemnonic().equals("ldy") && instructionType.getAddressingMode().equals(AsmAddressingMode.IMM)) { + try { + int immValue = Integer.parseInt(instruction.getParameter()); + AsmProgramStaticRegisterValues.AsmRegisterValues instructionValues = staticValues.getValues(instruction); + if (instructionValues.getY() != null && instructionValues.getY().equals(immValue)) { + removes.add(instruction); + } + } catch (NumberFormatException e) { + // ignore + } + } + if (instructionType.getMnemnonic().equals("clc")) { AsmProgramStaticRegisterValues.AsmRegisterValues instructionValues = staticValues.getValues(instruction); - if (instructionValues.getA() != null && instructionValues.getA().equals(immValue)) { + if (Boolean.FALSE.equals(instructionValues.getC())) { removes.add(instruction); } - } catch (NumberFormatException e) { - // ignore } - } - if(instructionType.getMnemnonic().equals("ldx") && instructionType.getAddressingMode().equals(AsmAddressingMode.IMM)) { - try { - int immValue = Integer.parseInt(instruction.getParameter()); - AsmProgramStaticRegisterValues.AsmRegisterValues instructionValues = staticValues.getValues(instruction); - if(instructionValues.getX()!=null && instructionValues.getX().equals(immValue)) { - removes.add(instruction); - } - } catch (NumberFormatException e) { - // ignore - } - - } - if(instructionType.getMnemnonic().equals("ldy") && instructionType.getAddressingMode().equals(AsmAddressingMode.IMM)) { - try { - int immValue = Integer.parseInt(instruction.getParameter()); - AsmProgramStaticRegisterValues.AsmRegisterValues instructionValues = staticValues.getValues(instruction); - if(instructionValues.getY()!=null && instructionValues.getY().equals(immValue)) { - removes.add(instruction); - } - } catch (NumberFormatException e) { - // ignore - } - } - if(instructionType.getMnemnonic().equals("clc")) { - AsmProgramStaticRegisterValues.AsmRegisterValues instructionValues = staticValues.getValues(instruction); - if(Boolean.FALSE.equals(instructionValues.getC())) { - removes.add(instruction); - } - } - if(instructionType.getMnemnonic().equals("sec")) { - AsmProgramStaticRegisterValues.AsmRegisterValues instructionValues = staticValues.getValues(instruction); - if(Boolean.TRUE.equals(instructionValues.getC())) { - removes.add(instruction); + if (instructionType.getMnemnonic().equals("sec")) { + AsmProgramStaticRegisterValues.AsmRegisterValues instructionValues = staticValues.getValues(instruction); + if (Boolean.TRUE.equals(instructionValues.getC())) { + removes.add(instruction); + } } } } } remove(removes); - return removes.size()>0; + return removes.size() > 0; } } diff --git a/src/main/java/dk/camelot64/kickc/test/ref/bresenham.log b/src/main/java/dk/camelot64/kickc/test/ref/bresenham.log index c07ba72d5..85e4a927a 100644 --- a/src/main/java/dk/camelot64/kickc/test/ref/bresenham.log +++ b/src/main/java/dk/camelot64/kickc/test/ref/bresenham.log @@ -1126,66 +1126,74 @@ zp byte:5 [ e#3 e#5 e#1 e#2 ] zp byte:6 [ y#2 y#4 y#1 ] INITIAL ASM +//SEG0 @BEGIN BBEGIN: +//SEG1 [0] phi from @BEGIN to @1 B1_from_BBEGIN: - // (byte) y#2 = (byte) 0 // zpby1=coby1 +//SEG2 [0] phi (byte) y#2 = (byte) 0 -- zpby1=coby1 lda #0 sta 6 - // (byte) e#3 = (byte) 12 // zpby1=coby1 +//SEG3 [0] phi (byte) e#3 = (byte) 12 -- zpby1=coby1 lda #12 sta 5 - // (byte) x#2 = (byte) 0 // zpby1=coby1 +//SEG4 [0] phi (byte) x#2 = (byte) 0 -- zpby1=coby1 lda #0 sta 4 - // (byte*) cursor#3 = (word) 1024 // zpptrby1=cowo1 +//SEG5 [0] phi (byte*) cursor#3 = (word) 1024 -- zpptrby1=cowo1 lda #<1024 sta 2 lda #>1024 sta 2+1 jmp B1 +//SEG6 [0] phi from @3 to @1 B1_from_B3: - // (byte) y#2 = (byte) y#4 // register copy zp byte:6 - // (byte) e#3 = (byte) e#5 // register copy zp byte:5 - // (byte) x#2 = (byte) x#1 // register copy zp byte:4 - // (byte*) cursor#3 = (byte*) cursor#5 // register copy zp ptr byte:2 +//SEG7 [0] phi (byte) y#2 = (byte) y#4 -- register_copy +//SEG8 [0] phi (byte) e#3 = (byte) e#5 -- register_copy +//SEG9 [0] phi (byte) x#2 = (byte) x#1 -- register_copy +//SEG10 [0] phi (byte*) cursor#3 = (byte*) cursor#5 -- register_copy jmp B1 +//SEG11 @1 B1: - // [1] *((byte*) cursor#3) ← (byte) 81 [ cursor#3 x#2 e#3 y#2 ] // _star_zpptrby1=coby1 +//SEG12 [1] *((byte*) cursor#3) ← (byte) 81 [ cursor#3 x#2 e#3 y#2 ] -- _star_zpptrby1=coby1 ldy #0 lda #81 sta (2),y - // [2] (byte) x#1 ← (byte) x#2 + (byte) 1 [ x#1 cursor#3 e#3 y#2 ] // zpby1=zpby1_plus_1 +//SEG13 [2] (byte) x#1 ← (byte) x#2 + (byte) 1 [ x#1 cursor#3 e#3 y#2 ] -- zpby1=zpby1_plus_1 inc 4 - // [3] (byte*) cursor#1 ← (byte*) cursor#3 + (byte) 1 [ x#1 e#3 cursor#1 y#2 ] // zpptrby1=zpptrby1_plus_1 +//SEG14 [3] (byte*) cursor#1 ← (byte*) cursor#3 + (byte) 1 [ x#1 e#3 cursor#1 y#2 ] -- zpptrby1=zpptrby1_plus_1 inc 2 bne !+ inc 2+1 !: - // [4] (byte) e#1 ← (byte) e#3 + (byte) 24 [ x#1 e#1 cursor#1 y#2 ] // zpby1=zpby1_plus_coby1 +//SEG15 [4] (byte) e#1 ← (byte) e#3 + (byte) 24 [ x#1 e#1 cursor#1 y#2 ] -- zpby1=zpby1_plus_coby1 lda 5 clc adc #24 sta 5 - // [5] if((byte) 39<(byte) e#1) goto @2 [ x#1 e#1 cursor#1 y#2 ] // coby1_lt_zpby1_then_la1 +//SEG16 [5] if((byte) 39<(byte) e#1) goto @2 [ x#1 e#1 cursor#1 y#2 ] -- coby1_lt_zpby1_then_la1 lda #39 cmp 5 bcc B2 +//SEG17 [6] phi from @1 to @3 B3_from_B1: - // (byte) y#4 = (byte) y#2 // register copy zp byte:6 - // (byte) e#5 = (byte) e#1 // register copy zp byte:5 - // (byte*) cursor#5 = (byte*) cursor#1 // register copy zp ptr byte:2 +//SEG18 [6] phi (byte) y#4 = (byte) y#2 -- register_copy +//SEG19 [6] phi (byte) e#5 = (byte) e#1 -- register_copy +//SEG20 [6] phi (byte*) cursor#5 = (byte*) cursor#1 -- register_copy jmp B3 +//SEG21 @3 B3: - // [7] if((byte) x#1<(byte) 40) goto @1 [ cursor#5 x#1 e#5 y#4 ] // zpby1_lt_coby1_then_la1 +//SEG22 [7] if((byte) x#1<(byte) 40) goto @1 [ cursor#5 x#1 e#5 y#4 ] -- zpby1_lt_coby1_then_la1 lda 4 cmp #40 bcc B1_from_B3 jmp BEND +//SEG23 @END BEND: +//SEG24 @2 B2: - // [8] (byte) y#1 ← (byte) y#2 + (byte) 1 [ x#1 e#1 cursor#1 y#1 ] // zpby1=zpby1_plus_1 +//SEG25 [8] (byte) y#1 ← (byte) y#2 + (byte) 1 [ x#1 e#1 cursor#1 y#1 ] -- zpby1=zpby1_plus_1 inc 6 - // [9] (byte*) cursor#2 ← (byte*) cursor#1 + (byte) 40 [ x#1 e#1 cursor#2 y#1 ] // zpptrby1=zpptrby1_plus_coby1 +//SEG26 [9] (byte*) cursor#2 ← (byte*) cursor#1 + (byte) 40 [ x#1 e#1 cursor#2 y#1 ] -- zpptrby1=zpptrby1_plus_coby1 lda 2 clc adc #40 @@ -1193,15 +1201,16 @@ B2: bcc !+ inc 2+1 !: - // [10] (byte) e#2 ← (byte) e#1 - (byte) 39 [ x#1 cursor#2 e#2 y#1 ] // zpby1=zpby1_minus_coby1 +//SEG27 [10] (byte) e#2 ← (byte) e#1 - (byte) 39 [ x#1 cursor#2 e#2 y#1 ] -- zpby1=zpby1_minus_coby1 lda 5 sec sbc #39 sta 5 +//SEG28 [6] phi from @2 to @3 B3_from_B2: - // (byte) y#4 = (byte) y#1 // register copy zp byte:6 - // (byte) e#5 = (byte) e#2 // register copy zp byte:5 - // (byte*) cursor#5 = (byte*) cursor#2 // register copy zp ptr byte:2 +//SEG29 [6] phi (byte) y#4 = (byte) y#1 -- register_copy +//SEG30 [6] phi (byte) e#5 = (byte) e#2 -- register_copy +//SEG31 [6] phi (byte*) cursor#5 = (byte*) cursor#2 -- register_copy jmp B3 Removing instruction jmp B1 @@ -1209,63 +1218,71 @@ Removing instruction jmp B3 Removing instruction jmp BEND Succesful ASM optimization Pass5NextJumpElimination ASSEMBLER +//SEG0 @BEGIN BBEGIN: +//SEG1 [0] phi from @BEGIN to @1 B1_from_BBEGIN: - // (byte) y#2 = (byte) 0 // zpby1=coby1 +//SEG2 [0] phi (byte) y#2 = (byte) 0 -- zpby1=coby1 lda #0 sta 6 - // (byte) e#3 = (byte) 12 // zpby1=coby1 +//SEG3 [0] phi (byte) e#3 = (byte) 12 -- zpby1=coby1 lda #12 sta 5 - // (byte) x#2 = (byte) 0 // zpby1=coby1 +//SEG4 [0] phi (byte) x#2 = (byte) 0 -- zpby1=coby1 lda #0 sta 4 - // (byte*) cursor#3 = (word) 1024 // zpptrby1=cowo1 +//SEG5 [0] phi (byte*) cursor#3 = (word) 1024 -- zpptrby1=cowo1 lda #<1024 sta 2 lda #>1024 sta 2+1 jmp B1 +//SEG6 [0] phi from @3 to @1 B1_from_B3: - // (byte) y#2 = (byte) y#4 // register copy zp byte:6 - // (byte) e#3 = (byte) e#5 // register copy zp byte:5 - // (byte) x#2 = (byte) x#1 // register copy zp byte:4 - // (byte*) cursor#3 = (byte*) cursor#5 // register copy zp ptr byte:2 +//SEG7 [0] phi (byte) y#2 = (byte) y#4 -- register_copy +//SEG8 [0] phi (byte) e#3 = (byte) e#5 -- register_copy +//SEG9 [0] phi (byte) x#2 = (byte) x#1 -- register_copy +//SEG10 [0] phi (byte*) cursor#3 = (byte*) cursor#5 -- register_copy +//SEG11 @1 B1: - // [1] *((byte*) cursor#3) ← (byte) 81 [ cursor#3 x#2 e#3 y#2 ] // _star_zpptrby1=coby1 +//SEG12 [1] *((byte*) cursor#3) ← (byte) 81 [ cursor#3 x#2 e#3 y#2 ] -- _star_zpptrby1=coby1 ldy #0 lda #81 sta (2),y - // [2] (byte) x#1 ← (byte) x#2 + (byte) 1 [ x#1 cursor#3 e#3 y#2 ] // zpby1=zpby1_plus_1 +//SEG13 [2] (byte) x#1 ← (byte) x#2 + (byte) 1 [ x#1 cursor#3 e#3 y#2 ] -- zpby1=zpby1_plus_1 inc 4 - // [3] (byte*) cursor#1 ← (byte*) cursor#3 + (byte) 1 [ x#1 e#3 cursor#1 y#2 ] // zpptrby1=zpptrby1_plus_1 +//SEG14 [3] (byte*) cursor#1 ← (byte*) cursor#3 + (byte) 1 [ x#1 e#3 cursor#1 y#2 ] -- zpptrby1=zpptrby1_plus_1 inc 2 bne !+ inc 2+1 !: - // [4] (byte) e#1 ← (byte) e#3 + (byte) 24 [ x#1 e#1 cursor#1 y#2 ] // zpby1=zpby1_plus_coby1 +//SEG15 [4] (byte) e#1 ← (byte) e#3 + (byte) 24 [ x#1 e#1 cursor#1 y#2 ] -- zpby1=zpby1_plus_coby1 lda 5 clc adc #24 sta 5 - // [5] if((byte) 39<(byte) e#1) goto @2 [ x#1 e#1 cursor#1 y#2 ] // coby1_lt_zpby1_then_la1 +//SEG16 [5] if((byte) 39<(byte) e#1) goto @2 [ x#1 e#1 cursor#1 y#2 ] -- coby1_lt_zpby1_then_la1 lda #39 cmp 5 bcc B2 +//SEG17 [6] phi from @1 to @3 B3_from_B1: - // (byte) y#4 = (byte) y#2 // register copy zp byte:6 - // (byte) e#5 = (byte) e#1 // register copy zp byte:5 - // (byte*) cursor#5 = (byte*) cursor#1 // register copy zp ptr byte:2 +//SEG18 [6] phi (byte) y#4 = (byte) y#2 -- register_copy +//SEG19 [6] phi (byte) e#5 = (byte) e#1 -- register_copy +//SEG20 [6] phi (byte*) cursor#5 = (byte*) cursor#1 -- register_copy +//SEG21 @3 B3: - // [7] if((byte) x#1<(byte) 40) goto @1 [ cursor#5 x#1 e#5 y#4 ] // zpby1_lt_coby1_then_la1 +//SEG22 [7] if((byte) x#1<(byte) 40) goto @1 [ cursor#5 x#1 e#5 y#4 ] -- zpby1_lt_coby1_then_la1 lda 4 cmp #40 bcc B1_from_B3 +//SEG23 @END BEND: +//SEG24 @2 B2: - // [8] (byte) y#1 ← (byte) y#2 + (byte) 1 [ x#1 e#1 cursor#1 y#1 ] // zpby1=zpby1_plus_1 +//SEG25 [8] (byte) y#1 ← (byte) y#2 + (byte) 1 [ x#1 e#1 cursor#1 y#1 ] -- zpby1=zpby1_plus_1 inc 6 - // [9] (byte*) cursor#2 ← (byte*) cursor#1 + (byte) 40 [ x#1 e#1 cursor#2 y#1 ] // zpptrby1=zpptrby1_plus_coby1 +//SEG26 [9] (byte*) cursor#2 ← (byte*) cursor#1 + (byte) 40 [ x#1 e#1 cursor#2 y#1 ] -- zpptrby1=zpptrby1_plus_coby1 lda 2 clc adc #40 @@ -1273,76 +1290,85 @@ B2: bcc !+ inc 2+1 !: - // [10] (byte) e#2 ← (byte) e#1 - (byte) 39 [ x#1 cursor#2 e#2 y#1 ] // zpby1=zpby1_minus_coby1 +//SEG27 [10] (byte) e#2 ← (byte) e#1 - (byte) 39 [ x#1 cursor#2 e#2 y#1 ] -- zpby1=zpby1_minus_coby1 lda 5 sec sbc #39 sta 5 +//SEG28 [6] phi from @2 to @3 B3_from_B2: - // (byte) y#4 = (byte) y#1 // register copy zp byte:6 - // (byte) e#5 = (byte) e#2 // register copy zp byte:5 - // (byte*) cursor#5 = (byte*) cursor#2 // register copy zp ptr byte:2 +//SEG29 [6] phi (byte) y#4 = (byte) y#1 -- register_copy +//SEG30 [6] phi (byte) e#5 = (byte) e#2 -- register_copy +//SEG31 [6] phi (byte*) cursor#5 = (byte*) cursor#2 -- register_copy jmp B3 Removing instruction jmp B1 Succesful ASM optimization Pass5NextJumpElimination ASSEMBLER +//SEG0 @BEGIN BBEGIN: +//SEG1 [0] phi from @BEGIN to @1 B1_from_BBEGIN: - // (byte) y#2 = (byte) 0 // zpby1=coby1 +//SEG2 [0] phi (byte) y#2 = (byte) 0 -- zpby1=coby1 lda #0 sta 6 - // (byte) e#3 = (byte) 12 // zpby1=coby1 +//SEG3 [0] phi (byte) e#3 = (byte) 12 -- zpby1=coby1 lda #12 sta 5 - // (byte) x#2 = (byte) 0 // zpby1=coby1 +//SEG4 [0] phi (byte) x#2 = (byte) 0 -- zpby1=coby1 lda #0 sta 4 - // (byte*) cursor#3 = (word) 1024 // zpptrby1=cowo1 +//SEG5 [0] phi (byte*) cursor#3 = (word) 1024 -- zpptrby1=cowo1 lda #<1024 sta 2 lda #>1024 sta 2+1 +//SEG6 [0] phi from @3 to @1 B1_from_B3: - // (byte) y#2 = (byte) y#4 // register copy zp byte:6 - // (byte) e#3 = (byte) e#5 // register copy zp byte:5 - // (byte) x#2 = (byte) x#1 // register copy zp byte:4 - // (byte*) cursor#3 = (byte*) cursor#5 // register copy zp ptr byte:2 +//SEG7 [0] phi (byte) y#2 = (byte) y#4 -- register_copy +//SEG8 [0] phi (byte) e#3 = (byte) e#5 -- register_copy +//SEG9 [0] phi (byte) x#2 = (byte) x#1 -- register_copy +//SEG10 [0] phi (byte*) cursor#3 = (byte*) cursor#5 -- register_copy +//SEG11 @1 B1: - // [1] *((byte*) cursor#3) ← (byte) 81 [ cursor#3 x#2 e#3 y#2 ] // _star_zpptrby1=coby1 +//SEG12 [1] *((byte*) cursor#3) ← (byte) 81 [ cursor#3 x#2 e#3 y#2 ] -- _star_zpptrby1=coby1 ldy #0 lda #81 sta (2),y - // [2] (byte) x#1 ← (byte) x#2 + (byte) 1 [ x#1 cursor#3 e#3 y#2 ] // zpby1=zpby1_plus_1 +//SEG13 [2] (byte) x#1 ← (byte) x#2 + (byte) 1 [ x#1 cursor#3 e#3 y#2 ] -- zpby1=zpby1_plus_1 inc 4 - // [3] (byte*) cursor#1 ← (byte*) cursor#3 + (byte) 1 [ x#1 e#3 cursor#1 y#2 ] // zpptrby1=zpptrby1_plus_1 +//SEG14 [3] (byte*) cursor#1 ← (byte*) cursor#3 + (byte) 1 [ x#1 e#3 cursor#1 y#2 ] -- zpptrby1=zpptrby1_plus_1 inc 2 bne !+ inc 2+1 !: - // [4] (byte) e#1 ← (byte) e#3 + (byte) 24 [ x#1 e#1 cursor#1 y#2 ] // zpby1=zpby1_plus_coby1 +//SEG15 [4] (byte) e#1 ← (byte) e#3 + (byte) 24 [ x#1 e#1 cursor#1 y#2 ] -- zpby1=zpby1_plus_coby1 lda 5 clc adc #24 sta 5 - // [5] if((byte) 39<(byte) e#1) goto @2 [ x#1 e#1 cursor#1 y#2 ] // coby1_lt_zpby1_then_la1 +//SEG16 [5] if((byte) 39<(byte) e#1) goto @2 [ x#1 e#1 cursor#1 y#2 ] -- coby1_lt_zpby1_then_la1 lda #39 cmp 5 bcc B2 +//SEG17 [6] phi from @1 to @3 B3_from_B1: - // (byte) y#4 = (byte) y#2 // register copy zp byte:6 - // (byte) e#5 = (byte) e#1 // register copy zp byte:5 - // (byte*) cursor#5 = (byte*) cursor#1 // register copy zp ptr byte:2 +//SEG18 [6] phi (byte) y#4 = (byte) y#2 -- register_copy +//SEG19 [6] phi (byte) e#5 = (byte) e#1 -- register_copy +//SEG20 [6] phi (byte*) cursor#5 = (byte*) cursor#1 -- register_copy +//SEG21 @3 B3: - // [7] if((byte) x#1<(byte) 40) goto @1 [ cursor#5 x#1 e#5 y#4 ] // zpby1_lt_coby1_then_la1 +//SEG22 [7] if((byte) x#1<(byte) 40) goto @1 [ cursor#5 x#1 e#5 y#4 ] -- zpby1_lt_coby1_then_la1 lda 4 cmp #40 bcc B1_from_B3 +//SEG23 @END BEND: +//SEG24 @2 B2: - // [8] (byte) y#1 ← (byte) y#2 + (byte) 1 [ x#1 e#1 cursor#1 y#1 ] // zpby1=zpby1_plus_1 +//SEG25 [8] (byte) y#1 ← (byte) y#2 + (byte) 1 [ x#1 e#1 cursor#1 y#1 ] -- zpby1=zpby1_plus_1 inc 6 - // [9] (byte*) cursor#2 ← (byte*) cursor#1 + (byte) 40 [ x#1 e#1 cursor#2 y#1 ] // zpptrby1=zpptrby1_plus_coby1 +//SEG26 [9] (byte*) cursor#2 ← (byte*) cursor#1 + (byte) 40 [ x#1 e#1 cursor#2 y#1 ] -- zpptrby1=zpptrby1_plus_coby1 lda 2 clc adc #40 @@ -1350,15 +1376,16 @@ B2: bcc !+ inc 2+1 !: - // [10] (byte) e#2 ← (byte) e#1 - (byte) 39 [ x#1 cursor#2 e#2 y#1 ] // zpby1=zpby1_minus_coby1 +//SEG27 [10] (byte) e#2 ← (byte) e#1 - (byte) 39 [ x#1 cursor#2 e#2 y#1 ] -- zpby1=zpby1_minus_coby1 lda 5 sec sbc #39 sta 5 +//SEG28 [6] phi from @2 to @3 B3_from_B2: - // (byte) y#4 = (byte) y#1 // register copy zp byte:6 - // (byte) e#5 = (byte) e#2 // register copy zp byte:5 - // (byte*) cursor#5 = (byte*) cursor#2 // register copy zp ptr byte:2 +//SEG29 [6] phi (byte) y#4 = (byte) y#1 -- register_copy +//SEG30 [6] phi (byte) e#5 = (byte) e#2 -- register_copy +//SEG31 [6] phi (byte*) cursor#5 = (byte*) cursor#2 -- register_copy jmp B3 FINAL SYMBOL TABLE @@ -1399,62 +1426,70 @@ zp byte:5 [ e#3 e#5 e#1 e#2 ] zp byte:6 [ y#2 y#4 y#1 ] FINAL CODE +//SEG0 @BEGIN BBEGIN: +//SEG1 [0] phi from @BEGIN to @1 B1_from_BBEGIN: - // (byte) y#2 = (byte) 0 // zpby1=coby1 +//SEG2 [0] phi (byte) y#2 = (byte) 0 -- zpby1=coby1 lda #0 sta 6 - // (byte) e#3 = (byte) 12 // zpby1=coby1 +//SEG3 [0] phi (byte) e#3 = (byte) 12 -- zpby1=coby1 lda #12 sta 5 - // (byte) x#2 = (byte) 0 // zpby1=coby1 +//SEG4 [0] phi (byte) x#2 = (byte) 0 -- zpby1=coby1 lda #0 sta 4 - // (byte*) cursor#3 = (word) 1024 // zpptrby1=cowo1 +//SEG5 [0] phi (byte*) cursor#3 = (word) 1024 -- zpptrby1=cowo1 lda #<1024 sta 2 lda #>1024 sta 2+1 +//SEG6 [0] phi from @3 to @1 B1_from_B3: - // (byte) y#2 = (byte) y#4 // register copy zp byte:6 - // (byte) e#3 = (byte) e#5 // register copy zp byte:5 - // (byte) x#2 = (byte) x#1 // register copy zp byte:4 - // (byte*) cursor#3 = (byte*) cursor#5 // register copy zp ptr byte:2 +//SEG7 [0] phi (byte) y#2 = (byte) y#4 -- register_copy +//SEG8 [0] phi (byte) e#3 = (byte) e#5 -- register_copy +//SEG9 [0] phi (byte) x#2 = (byte) x#1 -- register_copy +//SEG10 [0] phi (byte*) cursor#3 = (byte*) cursor#5 -- register_copy +//SEG11 @1 B1: - // [1] *((byte*) cursor#3) ← (byte) 81 [ cursor#3 x#2 e#3 y#2 ] // _star_zpptrby1=coby1 +//SEG12 [1] *((byte*) cursor#3) ← (byte) 81 [ cursor#3 x#2 e#3 y#2 ] -- _star_zpptrby1=coby1 ldy #0 lda #81 sta (2),y - // [2] (byte) x#1 ← (byte) x#2 + (byte) 1 [ x#1 cursor#3 e#3 y#2 ] // zpby1=zpby1_plus_1 +//SEG13 [2] (byte) x#1 ← (byte) x#2 + (byte) 1 [ x#1 cursor#3 e#3 y#2 ] -- zpby1=zpby1_plus_1 inc 4 - // [3] (byte*) cursor#1 ← (byte*) cursor#3 + (byte) 1 [ x#1 e#3 cursor#1 y#2 ] // zpptrby1=zpptrby1_plus_1 +//SEG14 [3] (byte*) cursor#1 ← (byte*) cursor#3 + (byte) 1 [ x#1 e#3 cursor#1 y#2 ] -- zpptrby1=zpptrby1_plus_1 inc 2 bne !+ inc 2+1 !: - // [4] (byte) e#1 ← (byte) e#3 + (byte) 24 [ x#1 e#1 cursor#1 y#2 ] // zpby1=zpby1_plus_coby1 +//SEG15 [4] (byte) e#1 ← (byte) e#3 + (byte) 24 [ x#1 e#1 cursor#1 y#2 ] -- zpby1=zpby1_plus_coby1 lda 5 clc adc #24 sta 5 - // [5] if((byte) 39<(byte) e#1) goto @2 [ x#1 e#1 cursor#1 y#2 ] // coby1_lt_zpby1_then_la1 +//SEG16 [5] if((byte) 39<(byte) e#1) goto @2 [ x#1 e#1 cursor#1 y#2 ] -- coby1_lt_zpby1_then_la1 lda #39 cmp 5 bcc B2 +//SEG17 [6] phi from @1 to @3 B3_from_B1: - // (byte) y#4 = (byte) y#2 // register copy zp byte:6 - // (byte) e#5 = (byte) e#1 // register copy zp byte:5 - // (byte*) cursor#5 = (byte*) cursor#1 // register copy zp ptr byte:2 +//SEG18 [6] phi (byte) y#4 = (byte) y#2 -- register_copy +//SEG19 [6] phi (byte) e#5 = (byte) e#1 -- register_copy +//SEG20 [6] phi (byte*) cursor#5 = (byte*) cursor#1 -- register_copy +//SEG21 @3 B3: - // [7] if((byte) x#1<(byte) 40) goto @1 [ cursor#5 x#1 e#5 y#4 ] // zpby1_lt_coby1_then_la1 +//SEG22 [7] if((byte) x#1<(byte) 40) goto @1 [ cursor#5 x#1 e#5 y#4 ] -- zpby1_lt_coby1_then_la1 lda 4 cmp #40 bcc B1_from_B3 +//SEG23 @END BEND: +//SEG24 @2 B2: - // [8] (byte) y#1 ← (byte) y#2 + (byte) 1 [ x#1 e#1 cursor#1 y#1 ] // zpby1=zpby1_plus_1 +//SEG25 [8] (byte) y#1 ← (byte) y#2 + (byte) 1 [ x#1 e#1 cursor#1 y#1 ] -- zpby1=zpby1_plus_1 inc 6 - // [9] (byte*) cursor#2 ← (byte*) cursor#1 + (byte) 40 [ x#1 e#1 cursor#2 y#1 ] // zpptrby1=zpptrby1_plus_coby1 +//SEG26 [9] (byte*) cursor#2 ← (byte*) cursor#1 + (byte) 40 [ x#1 e#1 cursor#2 y#1 ] -- zpptrby1=zpptrby1_plus_coby1 lda 2 clc adc #40 @@ -1462,14 +1497,15 @@ B2: bcc !+ inc 2+1 !: - // [10] (byte) e#2 ← (byte) e#1 - (byte) 39 [ x#1 cursor#2 e#2 y#1 ] // zpby1=zpby1_minus_coby1 +//SEG27 [10] (byte) e#2 ← (byte) e#1 - (byte) 39 [ x#1 cursor#2 e#2 y#1 ] -- zpby1=zpby1_minus_coby1 lda 5 sec sbc #39 sta 5 +//SEG28 [6] phi from @2 to @3 B3_from_B2: - // (byte) y#4 = (byte) y#1 // register copy zp byte:6 - // (byte) e#5 = (byte) e#2 // register copy zp byte:5 - // (byte*) cursor#5 = (byte*) cursor#2 // register copy zp ptr byte:2 +//SEG29 [6] phi (byte) y#4 = (byte) y#1 -- register_copy +//SEG30 [6] phi (byte) e#5 = (byte) e#2 -- register_copy +//SEG31 [6] phi (byte*) cursor#5 = (byte*) cursor#2 -- register_copy jmp B3 diff --git a/src/main/java/dk/camelot64/kickc/test/ref/fibmem.log b/src/main/java/dk/camelot64/kickc/test/ref/fibmem.log index d1e0d0c70..87c7bfdcd 100644 --- a/src/main/java/dk/camelot64/kickc/test/ref/fibmem.log +++ b/src/main/java/dk/camelot64/kickc/test/ref/fibmem.log @@ -466,132 +466,147 @@ zp byte:5 [ $4 ] Coalescing zero page register [ zp byte:3 [ $1 ] ] with [ zp byte:5 [ $4 ] ] INITIAL ASM +//SEG0 @BEGIN BBEGIN: - // [0] *((word) 4352) ← (byte) 0 [ ] // _star_cowo1=coby2 +//SEG1 [0] *((word) 4352) ← (byte) 0 [ ] -- _star_cowo1=coby2 lda #0 sta 4352 - // [1] *((word) 4353) ← (byte) 1 [ ] // _star_cowo1=coby2 +//SEG2 [1] *((word) 4353) ← (byte) 1 [ ] -- _star_cowo1=coby2 lda #1 sta 4353 +//SEG3 [2] phi from @BEGIN to @1 B1_from_BBEGIN: - // (byte) i#2 = (byte) 0 // zpby1=coby1 +//SEG4 [2] phi (byte) i#2 = (byte) 0 -- zpby1=coby1 lda #0 sta 2 jmp B1 +//SEG5 [2] phi from @1 to @1 B1_from_B1: - // (byte) i#2 = (byte) i#1 // register copy zp byte:2 +//SEG6 [2] phi (byte) i#2 = (byte) i#1 -- register_copy jmp B1 +//SEG7 @1 B1: - // [3] (byte~) $1 ← (word) 4352 *idx (byte) i#2 [ i#2 $1 ] // zpby1=cowo1_staridx_zpby2 +//SEG8 [3] (byte~) $1 ← (word) 4352 *idx (byte) i#2 [ i#2 $1 ] -- zpby1=cowo1_staridx_zpby2 ldx 2 lda 4352,x sta 3 - // [4] (byte~) $3 ← (word) 4353 *idx (byte) i#2 [ i#2 $1 $3 ] // zpby1=cowo1_staridx_zpby2 +//SEG9 [4] (byte~) $3 ← (word) 4353 *idx (byte) i#2 [ i#2 $1 $3 ] -- zpby1=cowo1_staridx_zpby2 ldx 2 lda 4353,x sta 4 - // [5] (byte~) $4 ← (byte~) $1 + (byte~) $3 [ i#2 $4 ] // zpby1=zpby2_plus_zpby3 +//SEG10 [5] (byte~) $4 ← (byte~) $1 + (byte~) $3 [ i#2 $4 ] -- zpby1=zpby2_plus_zpby3 lda 3 clc adc 4 sta 5 - // [6] *((word) 4354 + (byte) i#2) ← (byte~) $4 [ i#2 ] // cowo1_staridx_zpby1=zpby2 +//SEG11 [6] *((word) 4354 + (byte) i#2) ← (byte~) $4 [ i#2 ] -- cowo1_staridx_zpby1=zpby2 lda 5 ldx 2 sta 4354,x - // [7] (byte) i#1 ← (byte) i#2 + (byte) 1 [ i#1 ] // zpby1=zpby1_plus_1 +//SEG12 [7] (byte) i#1 ← (byte) i#2 + (byte) 1 [ i#1 ] -- zpby1=zpby1_plus_1 inc 2 - // [8] if((byte) i#1<(byte) 15) goto @1 [ i#1 ] // zpby1_lt_coby1_then_la1 +//SEG13 [8] if((byte) i#1<(byte) 15) goto @1 [ i#1 ] -- zpby1_lt_coby1_then_la1 lda 2 cmp #15 bcc B1_from_B1 jmp BEND +//SEG14 @END BEND: Removing instruction jmp B1 Removing instruction jmp BEND Succesful ASM optimization Pass5NextJumpElimination ASSEMBLER +//SEG0 @BEGIN BBEGIN: - // [0] *((word) 4352) ← (byte) 0 [ ] // _star_cowo1=coby2 +//SEG1 [0] *((word) 4352) ← (byte) 0 [ ] -- _star_cowo1=coby2 lda #0 sta 4352 - // [1] *((word) 4353) ← (byte) 1 [ ] // _star_cowo1=coby2 +//SEG2 [1] *((word) 4353) ← (byte) 1 [ ] -- _star_cowo1=coby2 lda #1 sta 4353 +//SEG3 [2] phi from @BEGIN to @1 B1_from_BBEGIN: - // (byte) i#2 = (byte) 0 // zpby1=coby1 +//SEG4 [2] phi (byte) i#2 = (byte) 0 -- zpby1=coby1 lda #0 sta 2 jmp B1 +//SEG5 [2] phi from @1 to @1 B1_from_B1: - // (byte) i#2 = (byte) i#1 // register copy zp byte:2 +//SEG6 [2] phi (byte) i#2 = (byte) i#1 -- register_copy +//SEG7 @1 B1: - // [3] (byte~) $1 ← (word) 4352 *idx (byte) i#2 [ i#2 $1 ] // zpby1=cowo1_staridx_zpby2 +//SEG8 [3] (byte~) $1 ← (word) 4352 *idx (byte) i#2 [ i#2 $1 ] -- zpby1=cowo1_staridx_zpby2 ldx 2 lda 4352,x sta 3 - // [4] (byte~) $3 ← (word) 4353 *idx (byte) i#2 [ i#2 $1 $3 ] // zpby1=cowo1_staridx_zpby2 +//SEG9 [4] (byte~) $3 ← (word) 4353 *idx (byte) i#2 [ i#2 $1 $3 ] -- zpby1=cowo1_staridx_zpby2 ldx 2 lda 4353,x sta 4 - // [5] (byte~) $4 ← (byte~) $1 + (byte~) $3 [ i#2 $4 ] // zpby1=zpby2_plus_zpby3 +//SEG10 [5] (byte~) $4 ← (byte~) $1 + (byte~) $3 [ i#2 $4 ] -- zpby1=zpby2_plus_zpby3 lda 3 clc adc 4 sta 5 - // [6] *((word) 4354 + (byte) i#2) ← (byte~) $4 [ i#2 ] // cowo1_staridx_zpby1=zpby2 +//SEG11 [6] *((word) 4354 + (byte) i#2) ← (byte~) $4 [ i#2 ] -- cowo1_staridx_zpby1=zpby2 lda 5 ldx 2 sta 4354,x - // [7] (byte) i#1 ← (byte) i#2 + (byte) 1 [ i#1 ] // zpby1=zpby1_plus_1 +//SEG12 [7] (byte) i#1 ← (byte) i#2 + (byte) 1 [ i#1 ] -- zpby1=zpby1_plus_1 inc 2 - // [8] if((byte) i#1<(byte) 15) goto @1 [ i#1 ] // zpby1_lt_coby1_then_la1 +//SEG13 [8] if((byte) i#1<(byte) 15) goto @1 [ i#1 ] -- zpby1_lt_coby1_then_la1 lda 2 cmp #15 bcc B1_from_B1 +//SEG14 @END BEND: Removing instruction jmp B1 Succesful ASM optimization Pass5NextJumpElimination ASSEMBLER +//SEG0 @BEGIN BBEGIN: - // [0] *((word) 4352) ← (byte) 0 [ ] // _star_cowo1=coby2 +//SEG1 [0] *((word) 4352) ← (byte) 0 [ ] -- _star_cowo1=coby2 lda #0 sta 4352 - // [1] *((word) 4353) ← (byte) 1 [ ] // _star_cowo1=coby2 +//SEG2 [1] *((word) 4353) ← (byte) 1 [ ] -- _star_cowo1=coby2 lda #1 sta 4353 +//SEG3 [2] phi from @BEGIN to @1 B1_from_BBEGIN: - // (byte) i#2 = (byte) 0 // zpby1=coby1 +//SEG4 [2] phi (byte) i#2 = (byte) 0 -- zpby1=coby1 lda #0 sta 2 +//SEG5 [2] phi from @1 to @1 B1_from_B1: - // (byte) i#2 = (byte) i#1 // register copy zp byte:2 +//SEG6 [2] phi (byte) i#2 = (byte) i#1 -- register_copy +//SEG7 @1 B1: - // [3] (byte~) $1 ← (word) 4352 *idx (byte) i#2 [ i#2 $1 ] // zpby1=cowo1_staridx_zpby2 +//SEG8 [3] (byte~) $1 ← (word) 4352 *idx (byte) i#2 [ i#2 $1 ] -- zpby1=cowo1_staridx_zpby2 ldx 2 lda 4352,x sta 3 - // [4] (byte~) $3 ← (word) 4353 *idx (byte) i#2 [ i#2 $1 $3 ] // zpby1=cowo1_staridx_zpby2 +//SEG9 [4] (byte~) $3 ← (word) 4353 *idx (byte) i#2 [ i#2 $1 $3 ] -- zpby1=cowo1_staridx_zpby2 ldx 2 lda 4353,x sta 4 - // [5] (byte~) $4 ← (byte~) $1 + (byte~) $3 [ i#2 $4 ] // zpby1=zpby2_plus_zpby3 +//SEG10 [5] (byte~) $4 ← (byte~) $1 + (byte~) $3 [ i#2 $4 ] -- zpby1=zpby2_plus_zpby3 lda 3 clc adc 4 sta 5 - // [6] *((word) 4354 + (byte) i#2) ← (byte~) $4 [ i#2 ] // cowo1_staridx_zpby1=zpby2 +//SEG11 [6] *((word) 4354 + (byte) i#2) ← (byte~) $4 [ i#2 ] -- cowo1_staridx_zpby1=zpby2 lda 5 ldx 2 sta 4354,x - // [7] (byte) i#1 ← (byte) i#2 + (byte) 1 [ i#1 ] // zpby1=zpby1_plus_1 +//SEG12 [7] (byte) i#1 ← (byte) i#2 + (byte) 1 [ i#1 ] -- zpby1=zpby1_plus_1 inc 2 - // [8] if((byte) i#1<(byte) 15) goto @1 [ i#1 ] // zpby1_lt_coby1_then_la1 +//SEG13 [8] if((byte) i#1<(byte) 15) goto @1 [ i#1 ] -- zpby1_lt_coby1_then_la1 lda 2 cmp #15 bcc B1_from_B1 +//SEG14 @END BEND: FINAL SYMBOL TABLE @@ -611,42 +626,47 @@ zp byte:3 [ $1 $4 ] zp byte:4 [ $3 ] FINAL CODE +//SEG0 @BEGIN BBEGIN: - // [0] *((word) 4352) ← (byte) 0 [ ] // _star_cowo1=coby2 +//SEG1 [0] *((word) 4352) ← (byte) 0 [ ] -- _star_cowo1=coby2 lda #0 sta 4352 - // [1] *((word) 4353) ← (byte) 1 [ ] // _star_cowo1=coby2 +//SEG2 [1] *((word) 4353) ← (byte) 1 [ ] -- _star_cowo1=coby2 lda #1 sta 4353 +//SEG3 [2] phi from @BEGIN to @1 B1_from_BBEGIN: - // (byte) i#2 = (byte) 0 // zpby1=coby1 +//SEG4 [2] phi (byte) i#2 = (byte) 0 -- zpby1=coby1 lda #0 sta 2 +//SEG5 [2] phi from @1 to @1 B1_from_B1: - // (byte) i#2 = (byte) i#1 // register copy zp byte:2 +//SEG6 [2] phi (byte) i#2 = (byte) i#1 -- register_copy +//SEG7 @1 B1: - // [3] (byte~) $1 ← (word) 4352 *idx (byte) i#2 [ i#2 $1 ] // zpby1=cowo1_staridx_zpby2 +//SEG8 [3] (byte~) $1 ← (word) 4352 *idx (byte) i#2 [ i#2 $1 ] -- zpby1=cowo1_staridx_zpby2 ldx 2 lda 4352,x sta 3 - // [4] (byte~) $3 ← (word) 4353 *idx (byte) i#2 [ i#2 $1 $3 ] // zpby1=cowo1_staridx_zpby2 +//SEG9 [4] (byte~) $3 ← (word) 4353 *idx (byte) i#2 [ i#2 $1 $3 ] -- zpby1=cowo1_staridx_zpby2 ldx 2 lda 4353,x sta 4 - // [5] (byte~) $4 ← (byte~) $1 + (byte~) $3 [ i#2 $4 ] // zpby1=zpby2_plus_zpby3 +//SEG10 [5] (byte~) $4 ← (byte~) $1 + (byte~) $3 [ i#2 $4 ] -- zpby1=zpby2_plus_zpby3 lda 3 clc adc 4 sta 5 - // [6] *((word) 4354 + (byte) i#2) ← (byte~) $4 [ i#2 ] // cowo1_staridx_zpby1=zpby2 +//SEG11 [6] *((word) 4354 + (byte) i#2) ← (byte~) $4 [ i#2 ] -- cowo1_staridx_zpby1=zpby2 lda 5 ldx 2 sta 4354,x - // [7] (byte) i#1 ← (byte) i#2 + (byte) 1 [ i#1 ] // zpby1=zpby1_plus_1 +//SEG12 [7] (byte) i#1 ← (byte) i#2 + (byte) 1 [ i#1 ] -- zpby1=zpby1_plus_1 inc 2 - // [8] if((byte) i#1<(byte) 15) goto @1 [ i#1 ] // zpby1_lt_coby1_then_la1 +//SEG13 [8] if((byte) i#1<(byte) 15) goto @1 [ i#1 ] -- zpby1_lt_coby1_then_la1 lda 2 cmp #15 bcc B1_from_B1 +//SEG14 @END BEND: diff --git a/src/main/java/dk/camelot64/kickc/test/ref/flipper-rex2.log b/src/main/java/dk/camelot64/kickc/test/ref/flipper-rex2.log index 5487a237d..294aa4d6b 100644 --- a/src/main/java/dk/camelot64/kickc/test/ref/flipper-rex2.log +++ b/src/main/java/dk/camelot64/kickc/test/ref/flipper-rex2.log @@ -4221,114 +4221,141 @@ Coalescing zero page register [ zp byte:6 [ plot::i#2 plot::i#3 plot::i#1 flip:: Coalescing zero page register [ zp byte:7 [ plot::x#2 plot::x#1 ] ] with [ zp byte:10 [ flip::dstIdx#3 flip::dstIdx#5 flip::dstIdx#2 flip::dstIdx#1 ] ] Coalescing zero page register [ zp byte:11 [ flip::c#2 flip::c#1 ] ] with [ zp byte:16 [ plot::$3 ] ] INITIAL ASM +//SEG0 @BEGIN BBEGIN: +//SEG1 [0] call main param-assignment [ ] jsr main jmp BEND +//SEG2 @END BEND: +//SEG3 main main: +//SEG4 [1] call prepare param-assignment [ ] jsr prepare +//SEG5 [2] phi from main to main::@3 main__B3_from_main: - // (byte) main::c#2 = (byte) 25 // zpby1=coby1 +//SEG6 [2] phi (byte) main::c#2 = (byte) 25 -- zpby1=coby1 lda #25 sta 2 jmp main__B3 +//SEG7 [2] phi from main::@11 to main::@3 main__B3_from_B11: - // (byte) main::c#2 = (byte) 25 // zpby1=coby1 +//SEG8 [2] phi (byte) main::c#2 = (byte) 25 -- zpby1=coby1 lda #25 sta 2 jmp main__B3 +//SEG9 [2] phi from main::@3 to main::@3 main__B3_from_B3: jmp main__B3 +//SEG10 [2] phi from main::@6 to main::@3 main__B3_from_B6: - // (byte) main::c#2 = (byte) main::c#1 // register copy zp byte:2 +//SEG11 [2] phi (byte) main::c#2 = (byte) main::c#1 -- register_copy jmp main__B3 +//SEG12 main::@3 main__B3: - // [3] (byte~) main::$1 ← * (word) 53266 [ main::$1 main::c#2 ] // zpby1=_star_cowo1 +//SEG13 [3] (byte~) main::$1 ← * (word) 53266 [ main::$1 main::c#2 ] -- zpby1=_star_cowo1 lda 53266 sta 14 - // [4] if((byte~) main::$1!=(byte) 254) goto main::@3 [ main::c#2 ] // zpby1_neq_coby1_then_la1 +//SEG14 [4] if((byte~) main::$1!=(byte) 254) goto main::@3 [ main::c#2 ] -- zpby1_neq_coby1_then_la1 lda 14 cmp #254 bne main__B3_from_B3 jmp main__B4 +//SEG15 main::@4 main__B4: - // [5] (byte~) main::$3 ← * (word) 53266 [ main::$3 main::c#2 ] // zpby1=_star_cowo1 +//SEG16 [5] (byte~) main::$3 ← * (word) 53266 [ main::$3 main::c#2 ] -- zpby1=_star_cowo1 lda 53266 sta 15 - // [6] if((byte~) main::$3!=(byte) 255) goto main::@4 [ main::c#2 ] // zpby1_neq_coby1_then_la1 +//SEG17 [6] if((byte~) main::$3!=(byte) 255) goto main::@4 [ main::c#2 ] -- zpby1_neq_coby1_then_la1 lda 15 cmp #255 bne main__B4 jmp main__B6 +//SEG18 main::@6 main__B6: - // [7] (byte) main::c#1 ← -- (byte) main::c#2 [ main::c#1 ] // zpby1=_dec_zpby1 +//SEG19 [7] (byte) main::c#1 ← -- (byte) main::c#2 [ main::c#1 ] -- zpby1=_dec_zpby1 dec 2 - // [8] if((byte) main::c#1!=(byte) 0) goto main::@3 [ main::c#1 ] // zpby1_neq_0_then_la1 +//SEG20 [8] if((byte) main::c#1!=(byte) 0) goto main::@3 [ main::c#1 ] -- zpby1_neq_0_then_la1 lda 2 bne main__B3_from_B6 jmp main__B7 +//SEG21 main::@7 main__B7: +//SEG22 [9] call flip param-assignment [ ] jsr flip jmp main__B10 +//SEG23 main::@10 main__B10: +//SEG24 [10] call plot param-assignment [ ] jsr plot jmp main__B11 +//SEG25 main::@11 main__B11: - // [11] if(true) goto main::@3 [ ] // true_then_la1 +//SEG26 [11] if(true) goto main::@3 [ ] -- true_then_la1 jmp main__B3_from_B11 jmp main__Breturn +//SEG27 main::@return main__Breturn: +//SEG28 [12] return [ ] rts +//SEG29 plot plot: +//SEG30 [13] phi from plot to plot::@1 plot__B1_from_plot: - // (byte) plot::y#2 = (byte) 16 // zpby1=coby1 +//SEG31 [13] phi (byte) plot::y#2 = (byte) 16 -- zpby1=coby1 lda #16 sta 5 - // (byte*) plot::line#2 = (word) 1236 // zpptrby1=cowo1 +//SEG32 [13] phi (byte*) plot::line#2 = (word) 1236 -- zpptrby1=cowo1 lda #<1236 sta 3 lda #>1236 sta 3+1 - // (byte) plot::i#3 = (byte) 0 // zpby1=coby1 +//SEG33 [13] phi (byte) plot::i#3 = (byte) 0 -- zpby1=coby1 lda #0 sta 6 jmp plot__B1 +//SEG34 [13] phi from plot::@3 to plot::@1 plot__B1_from_B3: - // (byte) plot::y#2 = (byte) plot::y#1 // register copy zp byte:5 - // (byte*) plot::line#2 = (byte*) plot::line#1 // register copy zp ptr byte:3 - // (byte) plot::i#3 = (byte) plot::i#1 // register copy zp byte:6 +//SEG35 [13] phi (byte) plot::y#2 = (byte) plot::y#1 -- register_copy +//SEG36 [13] phi (byte*) plot::line#2 = (byte*) plot::line#1 -- register_copy +//SEG37 [13] phi (byte) plot::i#3 = (byte) plot::i#1 -- register_copy jmp plot__B1 +//SEG38 plot::@1 plot__B1: +//SEG39 [14] phi from plot::@1 to plot::@2 plot__B2_from_B1: - // (byte) plot::x#2 = (byte) 0 // zpby1=coby1 +//SEG40 [14] phi (byte) plot::x#2 = (byte) 0 -- zpby1=coby1 lda #0 sta 7 - // (byte) plot::i#2 = (byte) plot::i#3 // register copy zp byte:6 +//SEG41 [14] phi (byte) plot::i#2 = (byte) plot::i#3 -- register_copy jmp plot__B2 +//SEG42 [14] phi from plot::@2 to plot::@2 plot__B2_from_B2: - // (byte) plot::x#2 = (byte) plot::x#1 // register copy zp byte:7 - // (byte) plot::i#2 = (byte) plot::i#1 // register copy zp byte:6 +//SEG43 [14] phi (byte) plot::x#2 = (byte) plot::x#1 -- register_copy +//SEG44 [14] phi (byte) plot::i#2 = (byte) plot::i#1 -- register_copy jmp plot__B2 +//SEG45 plot::@2 plot__B2: - // [15] (byte~) plot::$3 ← (word) 4096 *idx (byte) plot::i#2 [ plot::i#2 plot::line#2 plot::x#2 plot::$3 plot::y#2 ] // zpby1=cowo1_staridx_zpby2 +//SEG46 [15] (byte~) plot::$3 ← (word) 4096 *idx (byte) plot::i#2 [ plot::i#2 plot::line#2 plot::x#2 plot::$3 plot::y#2 ] -- zpby1=cowo1_staridx_zpby2 ldx 6 lda 4096,x sta 16 - // [16] *((byte*) plot::line#2 + (byte) plot::x#2) ← (byte~) plot::$3 [ plot::i#2 plot::line#2 plot::x#2 plot::y#2 ] // zpptrby1_staridx_zpby1=zpby2 +//SEG47 [16] *((byte*) plot::line#2 + (byte) plot::x#2) ← (byte~) plot::$3 [ plot::i#2 plot::line#2 plot::x#2 plot::y#2 ] -- zpptrby1_staridx_zpby1=zpby2 lda 16 ldy 7 sta (3),y - // [17] (byte) plot::i#1 ← ++ (byte) plot::i#2 [ plot::i#1 plot::line#2 plot::x#2 plot::y#2 ] // zpby1=_inc_zpby1 +//SEG48 [17] (byte) plot::i#1 ← ++ (byte) plot::i#2 [ plot::i#1 plot::line#2 plot::x#2 plot::y#2 ] -- zpby1=_inc_zpby1 inc 6 - // [18] (byte) plot::x#1 ← ++ (byte) plot::x#2 [ plot::i#1 plot::x#1 plot::line#2 plot::y#2 ] // zpby1=_inc_zpby1 +//SEG49 [18] (byte) plot::x#1 ← ++ (byte) plot::x#2 [ plot::i#1 plot::x#1 plot::line#2 plot::y#2 ] -- zpby1=_inc_zpby1 inc 7 - // [19] if((byte) plot::x#1<(byte) 16) goto plot::@2 [ plot::i#1 plot::x#1 plot::line#2 plot::y#2 ] // zpby1_lt_coby1_then_la1 +//SEG50 [19] if((byte) plot::x#1<(byte) 16) goto plot::@2 [ plot::i#1 plot::x#1 plot::line#2 plot::y#2 ] -- zpby1_lt_coby1_then_la1 lda 7 cmp #16 bcc plot__B2_from_B2 jmp plot__B3 +//SEG51 plot::@3 plot__B3: - // [20] (byte*) plot::line#1 ← (byte*) plot::line#2 + (byte) 40 [ plot::i#1 plot::line#1 plot::y#2 ] // zpptrby1=zpptrby1_plus_coby1 +//SEG52 [20] (byte*) plot::line#1 ← (byte*) plot::line#2 + (byte) 40 [ plot::i#1 plot::line#1 plot::y#2 ] -- zpptrby1=zpptrby1_plus_coby1 lda 3 clc adc #40 @@ -4336,120 +4363,141 @@ plot__B3: bcc !+ inc 3+1 !: - // [21] (byte) plot::y#1 ← -- (byte) plot::y#2 [ plot::i#1 plot::line#1 plot::y#1 ] // zpby1=_dec_zpby1 +//SEG53 [21] (byte) plot::y#1 ← -- (byte) plot::y#2 [ plot::i#1 plot::line#1 plot::y#1 ] -- zpby1=_dec_zpby1 dec 5 - // [22] if((byte) plot::y#1!=(byte) 0) goto plot::@1 [ plot::i#1 plot::line#1 plot::y#1 ] // zpby1_neq_0_then_la1 +//SEG54 [22] if((byte) plot::y#1!=(byte) 0) goto plot::@1 [ plot::i#1 plot::line#1 plot::y#1 ] -- zpby1_neq_0_then_la1 lda 5 bne plot__B1_from_B3 jmp plot__Breturn +//SEG55 plot::@return plot__Breturn: +//SEG56 [23] return [ ] rts +//SEG57 flip flip: +//SEG58 [24] phi from flip to flip::@1 flip__B1_from_flip: - // (byte) flip::r#2 = (byte) 16 // zpby1=coby1 +//SEG59 [24] phi (byte) flip::r#2 = (byte) 16 -- zpby1=coby1 lda #16 sta 8 - // (byte) flip::dstIdx#5 = (byte) 15 // zpby1=coby1 +//SEG60 [24] phi (byte) flip::dstIdx#5 = (byte) 15 -- zpby1=coby1 lda #15 sta 10 - // (byte) flip::srcIdx#3 = (byte) 0 // zpby1=coby1 +//SEG61 [24] phi (byte) flip::srcIdx#3 = (byte) 0 -- zpby1=coby1 lda #0 sta 9 jmp flip__B1 +//SEG62 [24] phi from flip::@4 to flip::@1 flip__B1_from_B4: - // (byte) flip::r#2 = (byte) flip::r#1 // register copy zp byte:8 - // (byte) flip::dstIdx#5 = (byte) flip::dstIdx#2 // register copy zp byte:10 - // (byte) flip::srcIdx#3 = (byte) flip::srcIdx#1 // register copy zp byte:9 +//SEG63 [24] phi (byte) flip::r#2 = (byte) flip::r#1 -- register_copy +//SEG64 [24] phi (byte) flip::dstIdx#5 = (byte) flip::dstIdx#2 -- register_copy +//SEG65 [24] phi (byte) flip::srcIdx#3 = (byte) flip::srcIdx#1 -- register_copy jmp flip__B1 +//SEG66 flip::@1 flip__B1: +//SEG67 [25] phi from flip::@1 to flip::@2 flip__B2_from_B1: - // (byte) flip::c#2 = (byte) 16 // zpby1=coby1 +//SEG68 [25] phi (byte) flip::c#2 = (byte) 16 -- zpby1=coby1 lda #16 sta 11 - // (byte) flip::dstIdx#3 = (byte) flip::dstIdx#5 // register copy zp byte:10 - // (byte) flip::srcIdx#2 = (byte) flip::srcIdx#3 // register copy zp byte:9 +//SEG69 [25] phi (byte) flip::dstIdx#3 = (byte) flip::dstIdx#5 -- register_copy +//SEG70 [25] phi (byte) flip::srcIdx#2 = (byte) flip::srcIdx#3 -- register_copy jmp flip__B2 +//SEG71 [25] phi from flip::@2 to flip::@2 flip__B2_from_B2: - // (byte) flip::c#2 = (byte) flip::c#1 // register copy zp byte:11 - // (byte) flip::dstIdx#3 = (byte) flip::dstIdx#1 // register copy zp byte:10 - // (byte) flip::srcIdx#2 = (byte) flip::srcIdx#1 // register copy zp byte:9 +//SEG72 [25] phi (byte) flip::c#2 = (byte) flip::c#1 -- register_copy +//SEG73 [25] phi (byte) flip::dstIdx#3 = (byte) flip::dstIdx#1 -- register_copy +//SEG74 [25] phi (byte) flip::srcIdx#2 = (byte) flip::srcIdx#1 -- register_copy jmp flip__B2 +//SEG75 flip::@2 flip__B2: - // [26] (byte~) flip::$0 ← (word) 4096 *idx (byte) flip::srcIdx#2 [ flip::srcIdx#2 flip::dstIdx#3 flip::$0 flip::c#2 flip::r#2 ] // zpby1=cowo1_staridx_zpby2 +//SEG76 [26] (byte~) flip::$0 ← (word) 4096 *idx (byte) flip::srcIdx#2 [ flip::srcIdx#2 flip::dstIdx#3 flip::$0 flip::c#2 flip::r#2 ] -- zpby1=cowo1_staridx_zpby2 ldx 9 lda 4096,x sta 17 - // [27] *((word) 4352 + (byte) flip::dstIdx#3) ← (byte~) flip::$0 [ flip::srcIdx#2 flip::dstIdx#3 flip::c#2 flip::r#2 ] // cowo1_staridx_zpby1=zpby2 +//SEG77 [27] *((word) 4352 + (byte) flip::dstIdx#3) ← (byte~) flip::$0 [ flip::srcIdx#2 flip::dstIdx#3 flip::c#2 flip::r#2 ] -- cowo1_staridx_zpby1=zpby2 lda 17 ldx 10 sta 4352,x - // [28] (byte) flip::srcIdx#1 ← ++ (byte) flip::srcIdx#2 [ flip::srcIdx#1 flip::dstIdx#3 flip::c#2 flip::r#2 ] // zpby1=_inc_zpby1 +//SEG78 [28] (byte) flip::srcIdx#1 ← ++ (byte) flip::srcIdx#2 [ flip::srcIdx#1 flip::dstIdx#3 flip::c#2 flip::r#2 ] -- zpby1=_inc_zpby1 inc 9 - // [29] (byte) flip::dstIdx#1 ← (byte) flip::dstIdx#3 + (byte) 16 [ flip::srcIdx#1 flip::dstIdx#1 flip::c#2 flip::r#2 ] // zpby1=zpby1_plus_coby1 +//SEG79 [29] (byte) flip::dstIdx#1 ← (byte) flip::dstIdx#3 + (byte) 16 [ flip::srcIdx#1 flip::dstIdx#1 flip::c#2 flip::r#2 ] -- zpby1=zpby1_plus_coby1 lda 10 clc adc #16 sta 10 - // [30] (byte) flip::c#1 ← -- (byte) flip::c#2 [ flip::srcIdx#1 flip::dstIdx#1 flip::c#1 flip::r#2 ] // zpby1=_dec_zpby1 +//SEG80 [30] (byte) flip::c#1 ← -- (byte) flip::c#2 [ flip::srcIdx#1 flip::dstIdx#1 flip::c#1 flip::r#2 ] -- zpby1=_dec_zpby1 dec 11 - // [31] if((byte) flip::c#1!=(byte) 0) goto flip::@2 [ flip::srcIdx#1 flip::dstIdx#1 flip::c#1 flip::r#2 ] // zpby1_neq_0_then_la1 +//SEG81 [31] if((byte) flip::c#1!=(byte) 0) goto flip::@2 [ flip::srcIdx#1 flip::dstIdx#1 flip::c#1 flip::r#2 ] -- zpby1_neq_0_then_la1 lda 11 bne flip__B2_from_B2 jmp flip__B4 +//SEG82 flip::@4 flip__B4: - // [32] (byte) flip::dstIdx#2 ← -- (byte) flip::dstIdx#1 [ flip::srcIdx#1 flip::dstIdx#2 flip::r#2 ] // zpby1=_dec_zpby1 +//SEG83 [32] (byte) flip::dstIdx#2 ← -- (byte) flip::dstIdx#1 [ flip::srcIdx#1 flip::dstIdx#2 flip::r#2 ] -- zpby1=_dec_zpby1 dec 10 - // [33] (byte) flip::r#1 ← -- (byte) flip::r#2 [ flip::srcIdx#1 flip::dstIdx#2 flip::r#1 ] // zpby1=_dec_zpby1 +//SEG84 [33] (byte) flip::r#1 ← -- (byte) flip::r#2 [ flip::srcIdx#1 flip::dstIdx#2 flip::r#1 ] -- zpby1=_dec_zpby1 dec 8 - // [34] if((byte) flip::r#1!=(byte) 0) goto flip::@1 [ flip::srcIdx#1 flip::dstIdx#2 flip::r#1 ] // zpby1_neq_0_then_la1 +//SEG85 [34] if((byte) flip::r#1!=(byte) 0) goto flip::@1 [ flip::srcIdx#1 flip::dstIdx#2 flip::r#1 ] -- zpby1_neq_0_then_la1 lda 8 bne flip__B1_from_B4 +//SEG86 [35] phi from flip::@4 to flip::@3 flip__B3_from_B4: - // (byte) flip::i#2 = (byte) 0 // zpby1=coby1 +//SEG87 [35] phi (byte) flip::i#2 = (byte) 0 -- zpby1=coby1 lda #0 sta 12 jmp flip__B3 +//SEG88 [35] phi from flip::@3 to flip::@3 flip__B3_from_B3: - // (byte) flip::i#2 = (byte) flip::i#1 // register copy zp byte:12 +//SEG89 [35] phi (byte) flip::i#2 = (byte) flip::i#1 -- register_copy jmp flip__B3 +//SEG90 flip::@3 flip__B3: - // [36] (byte~) flip::$4 ← (word) 4352 *idx (byte) flip::i#2 [ flip::i#2 flip::$4 ] // zpby1=cowo1_staridx_zpby2 +//SEG91 [36] (byte~) flip::$4 ← (word) 4352 *idx (byte) flip::i#2 [ flip::i#2 flip::$4 ] -- zpby1=cowo1_staridx_zpby2 ldx 12 lda 4352,x sta 18 - // [37] *((word) 4096 + (byte) flip::i#2) ← (byte~) flip::$4 [ flip::i#2 ] // cowo1_staridx_zpby1=zpby2 +//SEG92 [37] *((word) 4096 + (byte) flip::i#2) ← (byte~) flip::$4 [ flip::i#2 ] -- cowo1_staridx_zpby1=zpby2 lda 18 ldx 12 sta 4096,x - // [38] (byte) flip::i#1 ← ++ (byte) flip::i#2 [ flip::i#1 ] // zpby1=_inc_zpby1 +//SEG93 [38] (byte) flip::i#1 ← ++ (byte) flip::i#2 [ flip::i#1 ] -- zpby1=_inc_zpby1 inc 12 - // [39] if((byte) flip::i#1!=(byte) 0) goto flip::@3 [ flip::i#1 ] // zpby1_neq_0_then_la1 +//SEG94 [39] if((byte) flip::i#1!=(byte) 0) goto flip::@3 [ flip::i#1 ] -- zpby1_neq_0_then_la1 lda 12 bne flip__B3_from_B3 jmp flip__Breturn +//SEG95 flip::@return flip__Breturn: +//SEG96 [40] return [ ] rts +//SEG97 prepare prepare: +//SEG98 [41] phi from prepare to prepare::@1 prepare__B1_from_prepare: - // (byte) prepare::i#2 = (byte) 0 // zpby1=coby1 +//SEG99 [41] phi (byte) prepare::i#2 = (byte) 0 -- zpby1=coby1 lda #0 sta 13 jmp prepare__B1 +//SEG100 [41] phi from prepare::@1 to prepare::@1 prepare__B1_from_B1: - // (byte) prepare::i#2 = (byte) prepare::i#1 // register copy zp byte:13 +//SEG101 [41] phi (byte) prepare::i#2 = (byte) prepare::i#1 -- register_copy jmp prepare__B1 +//SEG102 prepare::@1 prepare__B1: - // [42] *((word) 4096 + (byte) prepare::i#2) ← (byte) prepare::i#2 [ prepare::i#2 ] // cowo1_staridx_zpby1=zpby1 +//SEG103 [42] *((word) 4096 + (byte) prepare::i#2) ← (byte) prepare::i#2 [ prepare::i#2 ] -- cowo1_staridx_zpby1=zpby1 ldx 13 txa sta 4096,x - // [43] (byte) prepare::i#1 ← ++ (byte) prepare::i#2 [ prepare::i#1 ] // zpby1=_inc_zpby1 +//SEG104 [43] (byte) prepare::i#1 ← ++ (byte) prepare::i#2 [ prepare::i#1 ] -- zpby1=_inc_zpby1 inc 13 - // [44] if((byte) prepare::i#1!=(byte) 0) goto prepare::@1 [ prepare::i#1 ] // zpby1_neq_0_then_la1 +//SEG105 [44] if((byte) prepare::i#1!=(byte) 0) goto prepare::@1 [ prepare::i#1 ] -- zpby1_neq_0_then_la1 lda 13 bne prepare__B1_from_B1 jmp prepare__Breturn +//SEG106 prepare::@return prepare__Breturn: +//SEG107 [45] return [ ] rts Removing instruction jmp BEND @@ -4473,103 +4521,130 @@ Removing instruction jmp prepare__B1 Removing instruction jmp prepare__Breturn Succesful ASM optimization Pass5NextJumpElimination ASSEMBLER +//SEG0 @BEGIN BBEGIN: +//SEG1 [0] call main param-assignment [ ] jsr main +//SEG2 @END BEND: +//SEG3 main main: +//SEG4 [1] call prepare param-assignment [ ] jsr prepare +//SEG5 [2] phi from main to main::@3 main__B3_from_main: - // (byte) main::c#2 = (byte) 25 // zpby1=coby1 +//SEG6 [2] phi (byte) main::c#2 = (byte) 25 -- zpby1=coby1 lda #25 sta 2 jmp main__B3 +//SEG7 [2] phi from main::@11 to main::@3 main__B3_from_B11: - // (byte) main::c#2 = (byte) 25 // zpby1=coby1 +//SEG8 [2] phi (byte) main::c#2 = (byte) 25 -- zpby1=coby1 lda #25 sta 2 jmp main__B3 +//SEG9 [2] phi from main::@3 to main::@3 main__B3_from_B3: jmp main__B3 +//SEG10 [2] phi from main::@6 to main::@3 main__B3_from_B6: - // (byte) main::c#2 = (byte) main::c#1 // register copy zp byte:2 +//SEG11 [2] phi (byte) main::c#2 = (byte) main::c#1 -- register_copy +//SEG12 main::@3 main__B3: - // [3] (byte~) main::$1 ← * (word) 53266 [ main::$1 main::c#2 ] // zpby1=_star_cowo1 +//SEG13 [3] (byte~) main::$1 ← * (word) 53266 [ main::$1 main::c#2 ] -- zpby1=_star_cowo1 lda 53266 sta 14 - // [4] if((byte~) main::$1!=(byte) 254) goto main::@3 [ main::c#2 ] // zpby1_neq_coby1_then_la1 +//SEG14 [4] if((byte~) main::$1!=(byte) 254) goto main::@3 [ main::c#2 ] -- zpby1_neq_coby1_then_la1 lda 14 cmp #254 bne main__B3_from_B3 +//SEG15 main::@4 main__B4: - // [5] (byte~) main::$3 ← * (word) 53266 [ main::$3 main::c#2 ] // zpby1=_star_cowo1 +//SEG16 [5] (byte~) main::$3 ← * (word) 53266 [ main::$3 main::c#2 ] -- zpby1=_star_cowo1 lda 53266 sta 15 - // [6] if((byte~) main::$3!=(byte) 255) goto main::@4 [ main::c#2 ] // zpby1_neq_coby1_then_la1 +//SEG17 [6] if((byte~) main::$3!=(byte) 255) goto main::@4 [ main::c#2 ] -- zpby1_neq_coby1_then_la1 lda 15 cmp #255 bne main__B4 +//SEG18 main::@6 main__B6: - // [7] (byte) main::c#1 ← -- (byte) main::c#2 [ main::c#1 ] // zpby1=_dec_zpby1 +//SEG19 [7] (byte) main::c#1 ← -- (byte) main::c#2 [ main::c#1 ] -- zpby1=_dec_zpby1 dec 2 - // [8] if((byte) main::c#1!=(byte) 0) goto main::@3 [ main::c#1 ] // zpby1_neq_0_then_la1 +//SEG20 [8] if((byte) main::c#1!=(byte) 0) goto main::@3 [ main::c#1 ] -- zpby1_neq_0_then_la1 lda 2 bne main__B3_from_B6 +//SEG21 main::@7 main__B7: +//SEG22 [9] call flip param-assignment [ ] jsr flip +//SEG23 main::@10 main__B10: +//SEG24 [10] call plot param-assignment [ ] jsr plot +//SEG25 main::@11 main__B11: - // [11] if(true) goto main::@3 [ ] // true_then_la1 +//SEG26 [11] if(true) goto main::@3 [ ] -- true_then_la1 jmp main__B3_from_B11 +//SEG27 main::@return main__Breturn: +//SEG28 [12] return [ ] rts +//SEG29 plot plot: +//SEG30 [13] phi from plot to plot::@1 plot__B1_from_plot: - // (byte) plot::y#2 = (byte) 16 // zpby1=coby1 +//SEG31 [13] phi (byte) plot::y#2 = (byte) 16 -- zpby1=coby1 lda #16 sta 5 - // (byte*) plot::line#2 = (word) 1236 // zpptrby1=cowo1 +//SEG32 [13] phi (byte*) plot::line#2 = (word) 1236 -- zpptrby1=cowo1 lda #<1236 sta 3 lda #>1236 sta 3+1 - // (byte) plot::i#3 = (byte) 0 // zpby1=coby1 +//SEG33 [13] phi (byte) plot::i#3 = (byte) 0 -- zpby1=coby1 lda #0 sta 6 jmp plot__B1 +//SEG34 [13] phi from plot::@3 to plot::@1 plot__B1_from_B3: - // (byte) plot::y#2 = (byte) plot::y#1 // register copy zp byte:5 - // (byte*) plot::line#2 = (byte*) plot::line#1 // register copy zp ptr byte:3 - // (byte) plot::i#3 = (byte) plot::i#1 // register copy zp byte:6 +//SEG35 [13] phi (byte) plot::y#2 = (byte) plot::y#1 -- register_copy +//SEG36 [13] phi (byte*) plot::line#2 = (byte*) plot::line#1 -- register_copy +//SEG37 [13] phi (byte) plot::i#3 = (byte) plot::i#1 -- register_copy +//SEG38 plot::@1 plot__B1: +//SEG39 [14] phi from plot::@1 to plot::@2 plot__B2_from_B1: - // (byte) plot::x#2 = (byte) 0 // zpby1=coby1 +//SEG40 [14] phi (byte) plot::x#2 = (byte) 0 -- zpby1=coby1 lda #0 sta 7 - // (byte) plot::i#2 = (byte) plot::i#3 // register copy zp byte:6 +//SEG41 [14] phi (byte) plot::i#2 = (byte) plot::i#3 -- register_copy jmp plot__B2 +//SEG42 [14] phi from plot::@2 to plot::@2 plot__B2_from_B2: - // (byte) plot::x#2 = (byte) plot::x#1 // register copy zp byte:7 - // (byte) plot::i#2 = (byte) plot::i#1 // register copy zp byte:6 +//SEG43 [14] phi (byte) plot::x#2 = (byte) plot::x#1 -- register_copy +//SEG44 [14] phi (byte) plot::i#2 = (byte) plot::i#1 -- register_copy +//SEG45 plot::@2 plot__B2: - // [15] (byte~) plot::$3 ← (word) 4096 *idx (byte) plot::i#2 [ plot::i#2 plot::line#2 plot::x#2 plot::$3 plot::y#2 ] // zpby1=cowo1_staridx_zpby2 +//SEG46 [15] (byte~) plot::$3 ← (word) 4096 *idx (byte) plot::i#2 [ plot::i#2 plot::line#2 plot::x#2 plot::$3 plot::y#2 ] -- zpby1=cowo1_staridx_zpby2 ldx 6 lda 4096,x sta 16 - // [16] *((byte*) plot::line#2 + (byte) plot::x#2) ← (byte~) plot::$3 [ plot::i#2 plot::line#2 plot::x#2 plot::y#2 ] // zpptrby1_staridx_zpby1=zpby2 +//SEG47 [16] *((byte*) plot::line#2 + (byte) plot::x#2) ← (byte~) plot::$3 [ plot::i#2 plot::line#2 plot::x#2 plot::y#2 ] -- zpptrby1_staridx_zpby1=zpby2 lda 16 ldy 7 sta (3),y - // [17] (byte) plot::i#1 ← ++ (byte) plot::i#2 [ plot::i#1 plot::line#2 plot::x#2 plot::y#2 ] // zpby1=_inc_zpby1 +//SEG48 [17] (byte) plot::i#1 ← ++ (byte) plot::i#2 [ plot::i#1 plot::line#2 plot::x#2 plot::y#2 ] -- zpby1=_inc_zpby1 inc 6 - // [18] (byte) plot::x#1 ← ++ (byte) plot::x#2 [ plot::i#1 plot::x#1 plot::line#2 plot::y#2 ] // zpby1=_inc_zpby1 +//SEG49 [18] (byte) plot::x#1 ← ++ (byte) plot::x#2 [ plot::i#1 plot::x#1 plot::line#2 plot::y#2 ] -- zpby1=_inc_zpby1 inc 7 - // [19] if((byte) plot::x#1<(byte) 16) goto plot::@2 [ plot::i#1 plot::x#1 plot::line#2 plot::y#2 ] // zpby1_lt_coby1_then_la1 +//SEG50 [19] if((byte) plot::x#1<(byte) 16) goto plot::@2 [ plot::i#1 plot::x#1 plot::line#2 plot::y#2 ] -- zpby1_lt_coby1_then_la1 lda 7 cmp #16 bcc plot__B2_from_B2 +//SEG51 plot::@3 plot__B3: - // [20] (byte*) plot::line#1 ← (byte*) plot::line#2 + (byte) 40 [ plot::i#1 plot::line#1 plot::y#2 ] // zpptrby1=zpptrby1_plus_coby1 +//SEG52 [20] (byte*) plot::line#1 ← (byte*) plot::line#2 + (byte) 40 [ plot::i#1 plot::line#1 plot::y#2 ] -- zpptrby1=zpptrby1_plus_coby1 lda 3 clc adc #40 @@ -4577,112 +4652,133 @@ plot__B3: bcc !+ inc 3+1 !: - // [21] (byte) plot::y#1 ← -- (byte) plot::y#2 [ plot::i#1 plot::line#1 plot::y#1 ] // zpby1=_dec_zpby1 +//SEG53 [21] (byte) plot::y#1 ← -- (byte) plot::y#2 [ plot::i#1 plot::line#1 plot::y#1 ] -- zpby1=_dec_zpby1 dec 5 - // [22] if((byte) plot::y#1!=(byte) 0) goto plot::@1 [ plot::i#1 plot::line#1 plot::y#1 ] // zpby1_neq_0_then_la1 +//SEG54 [22] if((byte) plot::y#1!=(byte) 0) goto plot::@1 [ plot::i#1 plot::line#1 plot::y#1 ] -- zpby1_neq_0_then_la1 lda 5 bne plot__B1_from_B3 +//SEG55 plot::@return plot__Breturn: +//SEG56 [23] return [ ] rts +//SEG57 flip flip: +//SEG58 [24] phi from flip to flip::@1 flip__B1_from_flip: - // (byte) flip::r#2 = (byte) 16 // zpby1=coby1 +//SEG59 [24] phi (byte) flip::r#2 = (byte) 16 -- zpby1=coby1 lda #16 sta 8 - // (byte) flip::dstIdx#5 = (byte) 15 // zpby1=coby1 +//SEG60 [24] phi (byte) flip::dstIdx#5 = (byte) 15 -- zpby1=coby1 lda #15 sta 10 - // (byte) flip::srcIdx#3 = (byte) 0 // zpby1=coby1 +//SEG61 [24] phi (byte) flip::srcIdx#3 = (byte) 0 -- zpby1=coby1 lda #0 sta 9 jmp flip__B1 +//SEG62 [24] phi from flip::@4 to flip::@1 flip__B1_from_B4: - // (byte) flip::r#2 = (byte) flip::r#1 // register copy zp byte:8 - // (byte) flip::dstIdx#5 = (byte) flip::dstIdx#2 // register copy zp byte:10 - // (byte) flip::srcIdx#3 = (byte) flip::srcIdx#1 // register copy zp byte:9 +//SEG63 [24] phi (byte) flip::r#2 = (byte) flip::r#1 -- register_copy +//SEG64 [24] phi (byte) flip::dstIdx#5 = (byte) flip::dstIdx#2 -- register_copy +//SEG65 [24] phi (byte) flip::srcIdx#3 = (byte) flip::srcIdx#1 -- register_copy +//SEG66 flip::@1 flip__B1: +//SEG67 [25] phi from flip::@1 to flip::@2 flip__B2_from_B1: - // (byte) flip::c#2 = (byte) 16 // zpby1=coby1 +//SEG68 [25] phi (byte) flip::c#2 = (byte) 16 -- zpby1=coby1 lda #16 sta 11 - // (byte) flip::dstIdx#3 = (byte) flip::dstIdx#5 // register copy zp byte:10 - // (byte) flip::srcIdx#2 = (byte) flip::srcIdx#3 // register copy zp byte:9 +//SEG69 [25] phi (byte) flip::dstIdx#3 = (byte) flip::dstIdx#5 -- register_copy +//SEG70 [25] phi (byte) flip::srcIdx#2 = (byte) flip::srcIdx#3 -- register_copy jmp flip__B2 +//SEG71 [25] phi from flip::@2 to flip::@2 flip__B2_from_B2: - // (byte) flip::c#2 = (byte) flip::c#1 // register copy zp byte:11 - // (byte) flip::dstIdx#3 = (byte) flip::dstIdx#1 // register copy zp byte:10 - // (byte) flip::srcIdx#2 = (byte) flip::srcIdx#1 // register copy zp byte:9 +//SEG72 [25] phi (byte) flip::c#2 = (byte) flip::c#1 -- register_copy +//SEG73 [25] phi (byte) flip::dstIdx#3 = (byte) flip::dstIdx#1 -- register_copy +//SEG74 [25] phi (byte) flip::srcIdx#2 = (byte) flip::srcIdx#1 -- register_copy +//SEG75 flip::@2 flip__B2: - // [26] (byte~) flip::$0 ← (word) 4096 *idx (byte) flip::srcIdx#2 [ flip::srcIdx#2 flip::dstIdx#3 flip::$0 flip::c#2 flip::r#2 ] // zpby1=cowo1_staridx_zpby2 +//SEG76 [26] (byte~) flip::$0 ← (word) 4096 *idx (byte) flip::srcIdx#2 [ flip::srcIdx#2 flip::dstIdx#3 flip::$0 flip::c#2 flip::r#2 ] -- zpby1=cowo1_staridx_zpby2 ldx 9 lda 4096,x sta 17 - // [27] *((word) 4352 + (byte) flip::dstIdx#3) ← (byte~) flip::$0 [ flip::srcIdx#2 flip::dstIdx#3 flip::c#2 flip::r#2 ] // cowo1_staridx_zpby1=zpby2 +//SEG77 [27] *((word) 4352 + (byte) flip::dstIdx#3) ← (byte~) flip::$0 [ flip::srcIdx#2 flip::dstIdx#3 flip::c#2 flip::r#2 ] -- cowo1_staridx_zpby1=zpby2 lda 17 ldx 10 sta 4352,x - // [28] (byte) flip::srcIdx#1 ← ++ (byte) flip::srcIdx#2 [ flip::srcIdx#1 flip::dstIdx#3 flip::c#2 flip::r#2 ] // zpby1=_inc_zpby1 +//SEG78 [28] (byte) flip::srcIdx#1 ← ++ (byte) flip::srcIdx#2 [ flip::srcIdx#1 flip::dstIdx#3 flip::c#2 flip::r#2 ] -- zpby1=_inc_zpby1 inc 9 - // [29] (byte) flip::dstIdx#1 ← (byte) flip::dstIdx#3 + (byte) 16 [ flip::srcIdx#1 flip::dstIdx#1 flip::c#2 flip::r#2 ] // zpby1=zpby1_plus_coby1 +//SEG79 [29] (byte) flip::dstIdx#1 ← (byte) flip::dstIdx#3 + (byte) 16 [ flip::srcIdx#1 flip::dstIdx#1 flip::c#2 flip::r#2 ] -- zpby1=zpby1_plus_coby1 lda 10 clc adc #16 sta 10 - // [30] (byte) flip::c#1 ← -- (byte) flip::c#2 [ flip::srcIdx#1 flip::dstIdx#1 flip::c#1 flip::r#2 ] // zpby1=_dec_zpby1 +//SEG80 [30] (byte) flip::c#1 ← -- (byte) flip::c#2 [ flip::srcIdx#1 flip::dstIdx#1 flip::c#1 flip::r#2 ] -- zpby1=_dec_zpby1 dec 11 - // [31] if((byte) flip::c#1!=(byte) 0) goto flip::@2 [ flip::srcIdx#1 flip::dstIdx#1 flip::c#1 flip::r#2 ] // zpby1_neq_0_then_la1 +//SEG81 [31] if((byte) flip::c#1!=(byte) 0) goto flip::@2 [ flip::srcIdx#1 flip::dstIdx#1 flip::c#1 flip::r#2 ] -- zpby1_neq_0_then_la1 lda 11 bne flip__B2_from_B2 +//SEG82 flip::@4 flip__B4: - // [32] (byte) flip::dstIdx#2 ← -- (byte) flip::dstIdx#1 [ flip::srcIdx#1 flip::dstIdx#2 flip::r#2 ] // zpby1=_dec_zpby1 +//SEG83 [32] (byte) flip::dstIdx#2 ← -- (byte) flip::dstIdx#1 [ flip::srcIdx#1 flip::dstIdx#2 flip::r#2 ] -- zpby1=_dec_zpby1 dec 10 - // [33] (byte) flip::r#1 ← -- (byte) flip::r#2 [ flip::srcIdx#1 flip::dstIdx#2 flip::r#1 ] // zpby1=_dec_zpby1 +//SEG84 [33] (byte) flip::r#1 ← -- (byte) flip::r#2 [ flip::srcIdx#1 flip::dstIdx#2 flip::r#1 ] -- zpby1=_dec_zpby1 dec 8 - // [34] if((byte) flip::r#1!=(byte) 0) goto flip::@1 [ flip::srcIdx#1 flip::dstIdx#2 flip::r#1 ] // zpby1_neq_0_then_la1 +//SEG85 [34] if((byte) flip::r#1!=(byte) 0) goto flip::@1 [ flip::srcIdx#1 flip::dstIdx#2 flip::r#1 ] -- zpby1_neq_0_then_la1 lda 8 bne flip__B1_from_B4 +//SEG86 [35] phi from flip::@4 to flip::@3 flip__B3_from_B4: - // (byte) flip::i#2 = (byte) 0 // zpby1=coby1 +//SEG87 [35] phi (byte) flip::i#2 = (byte) 0 -- zpby1=coby1 lda #0 sta 12 jmp flip__B3 +//SEG88 [35] phi from flip::@3 to flip::@3 flip__B3_from_B3: - // (byte) flip::i#2 = (byte) flip::i#1 // register copy zp byte:12 +//SEG89 [35] phi (byte) flip::i#2 = (byte) flip::i#1 -- register_copy +//SEG90 flip::@3 flip__B3: - // [36] (byte~) flip::$4 ← (word) 4352 *idx (byte) flip::i#2 [ flip::i#2 flip::$4 ] // zpby1=cowo1_staridx_zpby2 +//SEG91 [36] (byte~) flip::$4 ← (word) 4352 *idx (byte) flip::i#2 [ flip::i#2 flip::$4 ] -- zpby1=cowo1_staridx_zpby2 ldx 12 lda 4352,x sta 18 - // [37] *((word) 4096 + (byte) flip::i#2) ← (byte~) flip::$4 [ flip::i#2 ] // cowo1_staridx_zpby1=zpby2 +//SEG92 [37] *((word) 4096 + (byte) flip::i#2) ← (byte~) flip::$4 [ flip::i#2 ] -- cowo1_staridx_zpby1=zpby2 lda 18 ldx 12 sta 4096,x - // [38] (byte) flip::i#1 ← ++ (byte) flip::i#2 [ flip::i#1 ] // zpby1=_inc_zpby1 +//SEG93 [38] (byte) flip::i#1 ← ++ (byte) flip::i#2 [ flip::i#1 ] -- zpby1=_inc_zpby1 inc 12 - // [39] if((byte) flip::i#1!=(byte) 0) goto flip::@3 [ flip::i#1 ] // zpby1_neq_0_then_la1 +//SEG94 [39] if((byte) flip::i#1!=(byte) 0) goto flip::@3 [ flip::i#1 ] -- zpby1_neq_0_then_la1 lda 12 bne flip__B3_from_B3 +//SEG95 flip::@return flip__Breturn: +//SEG96 [40] return [ ] rts +//SEG97 prepare prepare: +//SEG98 [41] phi from prepare to prepare::@1 prepare__B1_from_prepare: - // (byte) prepare::i#2 = (byte) 0 // zpby1=coby1 +//SEG99 [41] phi (byte) prepare::i#2 = (byte) 0 -- zpby1=coby1 lda #0 sta 13 jmp prepare__B1 +//SEG100 [41] phi from prepare::@1 to prepare::@1 prepare__B1_from_B1: - // (byte) prepare::i#2 = (byte) prepare::i#1 // register copy zp byte:13 +//SEG101 [41] phi (byte) prepare::i#2 = (byte) prepare::i#1 -- register_copy +//SEG102 prepare::@1 prepare__B1: - // [42] *((word) 4096 + (byte) prepare::i#2) ← (byte) prepare::i#2 [ prepare::i#2 ] // cowo1_staridx_zpby1=zpby1 +//SEG103 [42] *((word) 4096 + (byte) prepare::i#2) ← (byte) prepare::i#2 [ prepare::i#2 ] -- cowo1_staridx_zpby1=zpby1 ldx 13 txa sta 4096,x - // [43] (byte) prepare::i#1 ← ++ (byte) prepare::i#2 [ prepare::i#1 ] // zpby1=_inc_zpby1 +//SEG104 [43] (byte) prepare::i#1 ← ++ (byte) prepare::i#2 [ prepare::i#1 ] -- zpby1=_inc_zpby1 inc 13 - // [44] if((byte) prepare::i#1!=(byte) 0) goto prepare::@1 [ prepare::i#1 ] // zpby1_neq_0_then_la1 +//SEG105 [44] if((byte) prepare::i#1!=(byte) 0) goto prepare::@1 [ prepare::i#1 ] -- zpby1_neq_0_then_la1 lda 13 bne prepare__B1_from_B1 +//SEG106 prepare::@return prepare__Breturn: +//SEG107 [45] return [ ] rts Removing instruction jmp main__B3 @@ -4694,100 +4790,127 @@ Removing instruction jmp flip__B3 Removing instruction jmp prepare__B1 Succesful ASM optimization Pass5NextJumpElimination ASSEMBLER +//SEG0 @BEGIN BBEGIN: +//SEG1 [0] call main param-assignment [ ] jsr main +//SEG2 @END BEND: +//SEG3 main main: +//SEG4 [1] call prepare param-assignment [ ] jsr prepare +//SEG5 [2] phi from main to main::@3 main__B3_from_main: - // (byte) main::c#2 = (byte) 25 // zpby1=coby1 +//SEG6 [2] phi (byte) main::c#2 = (byte) 25 -- zpby1=coby1 lda #25 sta 2 jmp main__B3 +//SEG7 [2] phi from main::@11 to main::@3 main__B3_from_B11: - // (byte) main::c#2 = (byte) 25 // zpby1=coby1 +//SEG8 [2] phi (byte) main::c#2 = (byte) 25 -- zpby1=coby1 lda #25 sta 2 jmp main__B3 +//SEG9 [2] phi from main::@3 to main::@3 main__B3_from_B3: +//SEG10 [2] phi from main::@6 to main::@3 main__B3_from_B6: - // (byte) main::c#2 = (byte) main::c#1 // register copy zp byte:2 +//SEG11 [2] phi (byte) main::c#2 = (byte) main::c#1 -- register_copy +//SEG12 main::@3 main__B3: - // [3] (byte~) main::$1 ← * (word) 53266 [ main::$1 main::c#2 ] // zpby1=_star_cowo1 +//SEG13 [3] (byte~) main::$1 ← * (word) 53266 [ main::$1 main::c#2 ] -- zpby1=_star_cowo1 lda 53266 sta 14 - // [4] if((byte~) main::$1!=(byte) 254) goto main::@3 [ main::c#2 ] // zpby1_neq_coby1_then_la1 +//SEG14 [4] if((byte~) main::$1!=(byte) 254) goto main::@3 [ main::c#2 ] -- zpby1_neq_coby1_then_la1 lda 14 cmp #254 bne main__B3_from_B3 +//SEG15 main::@4 main__B4: - // [5] (byte~) main::$3 ← * (word) 53266 [ main::$3 main::c#2 ] // zpby1=_star_cowo1 +//SEG16 [5] (byte~) main::$3 ← * (word) 53266 [ main::$3 main::c#2 ] -- zpby1=_star_cowo1 lda 53266 sta 15 - // [6] if((byte~) main::$3!=(byte) 255) goto main::@4 [ main::c#2 ] // zpby1_neq_coby1_then_la1 +//SEG17 [6] if((byte~) main::$3!=(byte) 255) goto main::@4 [ main::c#2 ] -- zpby1_neq_coby1_then_la1 lda 15 cmp #255 bne main__B4 +//SEG18 main::@6 main__B6: - // [7] (byte) main::c#1 ← -- (byte) main::c#2 [ main::c#1 ] // zpby1=_dec_zpby1 +//SEG19 [7] (byte) main::c#1 ← -- (byte) main::c#2 [ main::c#1 ] -- zpby1=_dec_zpby1 dec 2 - // [8] if((byte) main::c#1!=(byte) 0) goto main::@3 [ main::c#1 ] // zpby1_neq_0_then_la1 +//SEG20 [8] if((byte) main::c#1!=(byte) 0) goto main::@3 [ main::c#1 ] -- zpby1_neq_0_then_la1 lda 2 bne main__B3_from_B6 +//SEG21 main::@7 main__B7: +//SEG22 [9] call flip param-assignment [ ] jsr flip +//SEG23 main::@10 main__B10: +//SEG24 [10] call plot param-assignment [ ] jsr plot +//SEG25 main::@11 main__B11: - // [11] if(true) goto main::@3 [ ] // true_then_la1 +//SEG26 [11] if(true) goto main::@3 [ ] -- true_then_la1 jmp main__B3_from_B11 +//SEG27 main::@return main__Breturn: +//SEG28 [12] return [ ] rts +//SEG29 plot plot: +//SEG30 [13] phi from plot to plot::@1 plot__B1_from_plot: - // (byte) plot::y#2 = (byte) 16 // zpby1=coby1 +//SEG31 [13] phi (byte) plot::y#2 = (byte) 16 -- zpby1=coby1 lda #16 sta 5 - // (byte*) plot::line#2 = (word) 1236 // zpptrby1=cowo1 +//SEG32 [13] phi (byte*) plot::line#2 = (word) 1236 -- zpptrby1=cowo1 lda #<1236 sta 3 lda #>1236 sta 3+1 - // (byte) plot::i#3 = (byte) 0 // zpby1=coby1 +//SEG33 [13] phi (byte) plot::i#3 = (byte) 0 -- zpby1=coby1 lda #0 sta 6 +//SEG34 [13] phi from plot::@3 to plot::@1 plot__B1_from_B3: - // (byte) plot::y#2 = (byte) plot::y#1 // register copy zp byte:5 - // (byte*) plot::line#2 = (byte*) plot::line#1 // register copy zp ptr byte:3 - // (byte) plot::i#3 = (byte) plot::i#1 // register copy zp byte:6 +//SEG35 [13] phi (byte) plot::y#2 = (byte) plot::y#1 -- register_copy +//SEG36 [13] phi (byte*) plot::line#2 = (byte*) plot::line#1 -- register_copy +//SEG37 [13] phi (byte) plot::i#3 = (byte) plot::i#1 -- register_copy +//SEG38 plot::@1 plot__B1: +//SEG39 [14] phi from plot::@1 to plot::@2 plot__B2_from_B1: - // (byte) plot::x#2 = (byte) 0 // zpby1=coby1 +//SEG40 [14] phi (byte) plot::x#2 = (byte) 0 -- zpby1=coby1 lda #0 sta 7 - // (byte) plot::i#2 = (byte) plot::i#3 // register copy zp byte:6 +//SEG41 [14] phi (byte) plot::i#2 = (byte) plot::i#3 -- register_copy +//SEG42 [14] phi from plot::@2 to plot::@2 plot__B2_from_B2: - // (byte) plot::x#2 = (byte) plot::x#1 // register copy zp byte:7 - // (byte) plot::i#2 = (byte) plot::i#1 // register copy zp byte:6 +//SEG43 [14] phi (byte) plot::x#2 = (byte) plot::x#1 -- register_copy +//SEG44 [14] phi (byte) plot::i#2 = (byte) plot::i#1 -- register_copy +//SEG45 plot::@2 plot__B2: - // [15] (byte~) plot::$3 ← (word) 4096 *idx (byte) plot::i#2 [ plot::i#2 plot::line#2 plot::x#2 plot::$3 plot::y#2 ] // zpby1=cowo1_staridx_zpby2 +//SEG46 [15] (byte~) plot::$3 ← (word) 4096 *idx (byte) plot::i#2 [ plot::i#2 plot::line#2 plot::x#2 plot::$3 plot::y#2 ] -- zpby1=cowo1_staridx_zpby2 ldx 6 lda 4096,x sta 16 - // [16] *((byte*) plot::line#2 + (byte) plot::x#2) ← (byte~) plot::$3 [ plot::i#2 plot::line#2 plot::x#2 plot::y#2 ] // zpptrby1_staridx_zpby1=zpby2 +//SEG47 [16] *((byte*) plot::line#2 + (byte) plot::x#2) ← (byte~) plot::$3 [ plot::i#2 plot::line#2 plot::x#2 plot::y#2 ] -- zpptrby1_staridx_zpby1=zpby2 lda 16 ldy 7 sta (3),y - // [17] (byte) plot::i#1 ← ++ (byte) plot::i#2 [ plot::i#1 plot::line#2 plot::x#2 plot::y#2 ] // zpby1=_inc_zpby1 +//SEG48 [17] (byte) plot::i#1 ← ++ (byte) plot::i#2 [ plot::i#1 plot::line#2 plot::x#2 plot::y#2 ] -- zpby1=_inc_zpby1 inc 6 - // [18] (byte) plot::x#1 ← ++ (byte) plot::x#2 [ plot::i#1 plot::x#1 plot::line#2 plot::y#2 ] // zpby1=_inc_zpby1 +//SEG49 [18] (byte) plot::x#1 ← ++ (byte) plot::x#2 [ plot::i#1 plot::x#1 plot::line#2 plot::y#2 ] -- zpby1=_inc_zpby1 inc 7 - // [19] if((byte) plot::x#1<(byte) 16) goto plot::@2 [ plot::i#1 plot::x#1 plot::line#2 plot::y#2 ] // zpby1_lt_coby1_then_la1 +//SEG50 [19] if((byte) plot::x#1<(byte) 16) goto plot::@2 [ plot::i#1 plot::x#1 plot::line#2 plot::y#2 ] -- zpby1_lt_coby1_then_la1 lda 7 cmp #16 bcc plot__B2_from_B2 +//SEG51 plot::@3 plot__B3: - // [20] (byte*) plot::line#1 ← (byte*) plot::line#2 + (byte) 40 [ plot::i#1 plot::line#1 plot::y#2 ] // zpptrby1=zpptrby1_plus_coby1 +//SEG52 [20] (byte*) plot::line#1 ← (byte*) plot::line#2 + (byte) 40 [ plot::i#1 plot::line#1 plot::y#2 ] -- zpptrby1=zpptrby1_plus_coby1 lda 3 clc adc #40 @@ -4795,206 +4918,254 @@ plot__B3: bcc !+ inc 3+1 !: - // [21] (byte) plot::y#1 ← -- (byte) plot::y#2 [ plot::i#1 plot::line#1 plot::y#1 ] // zpby1=_dec_zpby1 +//SEG53 [21] (byte) plot::y#1 ← -- (byte) plot::y#2 [ plot::i#1 plot::line#1 plot::y#1 ] -- zpby1=_dec_zpby1 dec 5 - // [22] if((byte) plot::y#1!=(byte) 0) goto plot::@1 [ plot::i#1 plot::line#1 plot::y#1 ] // zpby1_neq_0_then_la1 +//SEG54 [22] if((byte) plot::y#1!=(byte) 0) goto plot::@1 [ plot::i#1 plot::line#1 plot::y#1 ] -- zpby1_neq_0_then_la1 lda 5 bne plot__B1_from_B3 +//SEG55 plot::@return plot__Breturn: +//SEG56 [23] return [ ] rts +//SEG57 flip flip: +//SEG58 [24] phi from flip to flip::@1 flip__B1_from_flip: - // (byte) flip::r#2 = (byte) 16 // zpby1=coby1 +//SEG59 [24] phi (byte) flip::r#2 = (byte) 16 -- zpby1=coby1 lda #16 sta 8 - // (byte) flip::dstIdx#5 = (byte) 15 // zpby1=coby1 +//SEG60 [24] phi (byte) flip::dstIdx#5 = (byte) 15 -- zpby1=coby1 lda #15 sta 10 - // (byte) flip::srcIdx#3 = (byte) 0 // zpby1=coby1 +//SEG61 [24] phi (byte) flip::srcIdx#3 = (byte) 0 -- zpby1=coby1 lda #0 sta 9 +//SEG62 [24] phi from flip::@4 to flip::@1 flip__B1_from_B4: - // (byte) flip::r#2 = (byte) flip::r#1 // register copy zp byte:8 - // (byte) flip::dstIdx#5 = (byte) flip::dstIdx#2 // register copy zp byte:10 - // (byte) flip::srcIdx#3 = (byte) flip::srcIdx#1 // register copy zp byte:9 +//SEG63 [24] phi (byte) flip::r#2 = (byte) flip::r#1 -- register_copy +//SEG64 [24] phi (byte) flip::dstIdx#5 = (byte) flip::dstIdx#2 -- register_copy +//SEG65 [24] phi (byte) flip::srcIdx#3 = (byte) flip::srcIdx#1 -- register_copy +//SEG66 flip::@1 flip__B1: +//SEG67 [25] phi from flip::@1 to flip::@2 flip__B2_from_B1: - // (byte) flip::c#2 = (byte) 16 // zpby1=coby1 +//SEG68 [25] phi (byte) flip::c#2 = (byte) 16 -- zpby1=coby1 lda #16 sta 11 - // (byte) flip::dstIdx#3 = (byte) flip::dstIdx#5 // register copy zp byte:10 - // (byte) flip::srcIdx#2 = (byte) flip::srcIdx#3 // register copy zp byte:9 +//SEG69 [25] phi (byte) flip::dstIdx#3 = (byte) flip::dstIdx#5 -- register_copy +//SEG70 [25] phi (byte) flip::srcIdx#2 = (byte) flip::srcIdx#3 -- register_copy +//SEG71 [25] phi from flip::@2 to flip::@2 flip__B2_from_B2: - // (byte) flip::c#2 = (byte) flip::c#1 // register copy zp byte:11 - // (byte) flip::dstIdx#3 = (byte) flip::dstIdx#1 // register copy zp byte:10 - // (byte) flip::srcIdx#2 = (byte) flip::srcIdx#1 // register copy zp byte:9 +//SEG72 [25] phi (byte) flip::c#2 = (byte) flip::c#1 -- register_copy +//SEG73 [25] phi (byte) flip::dstIdx#3 = (byte) flip::dstIdx#1 -- register_copy +//SEG74 [25] phi (byte) flip::srcIdx#2 = (byte) flip::srcIdx#1 -- register_copy +//SEG75 flip::@2 flip__B2: - // [26] (byte~) flip::$0 ← (word) 4096 *idx (byte) flip::srcIdx#2 [ flip::srcIdx#2 flip::dstIdx#3 flip::$0 flip::c#2 flip::r#2 ] // zpby1=cowo1_staridx_zpby2 +//SEG76 [26] (byte~) flip::$0 ← (word) 4096 *idx (byte) flip::srcIdx#2 [ flip::srcIdx#2 flip::dstIdx#3 flip::$0 flip::c#2 flip::r#2 ] -- zpby1=cowo1_staridx_zpby2 ldx 9 lda 4096,x sta 17 - // [27] *((word) 4352 + (byte) flip::dstIdx#3) ← (byte~) flip::$0 [ flip::srcIdx#2 flip::dstIdx#3 flip::c#2 flip::r#2 ] // cowo1_staridx_zpby1=zpby2 +//SEG77 [27] *((word) 4352 + (byte) flip::dstIdx#3) ← (byte~) flip::$0 [ flip::srcIdx#2 flip::dstIdx#3 flip::c#2 flip::r#2 ] -- cowo1_staridx_zpby1=zpby2 lda 17 ldx 10 sta 4352,x - // [28] (byte) flip::srcIdx#1 ← ++ (byte) flip::srcIdx#2 [ flip::srcIdx#1 flip::dstIdx#3 flip::c#2 flip::r#2 ] // zpby1=_inc_zpby1 +//SEG78 [28] (byte) flip::srcIdx#1 ← ++ (byte) flip::srcIdx#2 [ flip::srcIdx#1 flip::dstIdx#3 flip::c#2 flip::r#2 ] -- zpby1=_inc_zpby1 inc 9 - // [29] (byte) flip::dstIdx#1 ← (byte) flip::dstIdx#3 + (byte) 16 [ flip::srcIdx#1 flip::dstIdx#1 flip::c#2 flip::r#2 ] // zpby1=zpby1_plus_coby1 +//SEG79 [29] (byte) flip::dstIdx#1 ← (byte) flip::dstIdx#3 + (byte) 16 [ flip::srcIdx#1 flip::dstIdx#1 flip::c#2 flip::r#2 ] -- zpby1=zpby1_plus_coby1 lda 10 clc adc #16 sta 10 - // [30] (byte) flip::c#1 ← -- (byte) flip::c#2 [ flip::srcIdx#1 flip::dstIdx#1 flip::c#1 flip::r#2 ] // zpby1=_dec_zpby1 +//SEG80 [30] (byte) flip::c#1 ← -- (byte) flip::c#2 [ flip::srcIdx#1 flip::dstIdx#1 flip::c#1 flip::r#2 ] -- zpby1=_dec_zpby1 dec 11 - // [31] if((byte) flip::c#1!=(byte) 0) goto flip::@2 [ flip::srcIdx#1 flip::dstIdx#1 flip::c#1 flip::r#2 ] // zpby1_neq_0_then_la1 +//SEG81 [31] if((byte) flip::c#1!=(byte) 0) goto flip::@2 [ flip::srcIdx#1 flip::dstIdx#1 flip::c#1 flip::r#2 ] -- zpby1_neq_0_then_la1 lda 11 bne flip__B2_from_B2 +//SEG82 flip::@4 flip__B4: - // [32] (byte) flip::dstIdx#2 ← -- (byte) flip::dstIdx#1 [ flip::srcIdx#1 flip::dstIdx#2 flip::r#2 ] // zpby1=_dec_zpby1 +//SEG83 [32] (byte) flip::dstIdx#2 ← -- (byte) flip::dstIdx#1 [ flip::srcIdx#1 flip::dstIdx#2 flip::r#2 ] -- zpby1=_dec_zpby1 dec 10 - // [33] (byte) flip::r#1 ← -- (byte) flip::r#2 [ flip::srcIdx#1 flip::dstIdx#2 flip::r#1 ] // zpby1=_dec_zpby1 +//SEG84 [33] (byte) flip::r#1 ← -- (byte) flip::r#2 [ flip::srcIdx#1 flip::dstIdx#2 flip::r#1 ] -- zpby1=_dec_zpby1 dec 8 - // [34] if((byte) flip::r#1!=(byte) 0) goto flip::@1 [ flip::srcIdx#1 flip::dstIdx#2 flip::r#1 ] // zpby1_neq_0_then_la1 +//SEG85 [34] if((byte) flip::r#1!=(byte) 0) goto flip::@1 [ flip::srcIdx#1 flip::dstIdx#2 flip::r#1 ] -- zpby1_neq_0_then_la1 lda 8 bne flip__B1_from_B4 +//SEG86 [35] phi from flip::@4 to flip::@3 flip__B3_from_B4: - // (byte) flip::i#2 = (byte) 0 // zpby1=coby1 +//SEG87 [35] phi (byte) flip::i#2 = (byte) 0 -- zpby1=coby1 lda #0 sta 12 +//SEG88 [35] phi from flip::@3 to flip::@3 flip__B3_from_B3: - // (byte) flip::i#2 = (byte) flip::i#1 // register copy zp byte:12 +//SEG89 [35] phi (byte) flip::i#2 = (byte) flip::i#1 -- register_copy +//SEG90 flip::@3 flip__B3: - // [36] (byte~) flip::$4 ← (word) 4352 *idx (byte) flip::i#2 [ flip::i#2 flip::$4 ] // zpby1=cowo1_staridx_zpby2 +//SEG91 [36] (byte~) flip::$4 ← (word) 4352 *idx (byte) flip::i#2 [ flip::i#2 flip::$4 ] -- zpby1=cowo1_staridx_zpby2 ldx 12 lda 4352,x sta 18 - // [37] *((word) 4096 + (byte) flip::i#2) ← (byte~) flip::$4 [ flip::i#2 ] // cowo1_staridx_zpby1=zpby2 +//SEG92 [37] *((word) 4096 + (byte) flip::i#2) ← (byte~) flip::$4 [ flip::i#2 ] -- cowo1_staridx_zpby1=zpby2 lda 18 ldx 12 sta 4096,x - // [38] (byte) flip::i#1 ← ++ (byte) flip::i#2 [ flip::i#1 ] // zpby1=_inc_zpby1 +//SEG93 [38] (byte) flip::i#1 ← ++ (byte) flip::i#2 [ flip::i#1 ] -- zpby1=_inc_zpby1 inc 12 - // [39] if((byte) flip::i#1!=(byte) 0) goto flip::@3 [ flip::i#1 ] // zpby1_neq_0_then_la1 +//SEG94 [39] if((byte) flip::i#1!=(byte) 0) goto flip::@3 [ flip::i#1 ] -- zpby1_neq_0_then_la1 lda 12 bne flip__B3_from_B3 +//SEG95 flip::@return flip__Breturn: +//SEG96 [40] return [ ] rts +//SEG97 prepare prepare: +//SEG98 [41] phi from prepare to prepare::@1 prepare__B1_from_prepare: - // (byte) prepare::i#2 = (byte) 0 // zpby1=coby1 +//SEG99 [41] phi (byte) prepare::i#2 = (byte) 0 -- zpby1=coby1 lda #0 sta 13 +//SEG100 [41] phi from prepare::@1 to prepare::@1 prepare__B1_from_B1: - // (byte) prepare::i#2 = (byte) prepare::i#1 // register copy zp byte:13 +//SEG101 [41] phi (byte) prepare::i#2 = (byte) prepare::i#1 -- register_copy +//SEG102 prepare::@1 prepare__B1: - // [42] *((word) 4096 + (byte) prepare::i#2) ← (byte) prepare::i#2 [ prepare::i#2 ] // cowo1_staridx_zpby1=zpby1 +//SEG103 [42] *((word) 4096 + (byte) prepare::i#2) ← (byte) prepare::i#2 [ prepare::i#2 ] -- cowo1_staridx_zpby1=zpby1 ldx 13 txa sta 4096,x - // [43] (byte) prepare::i#1 ← ++ (byte) prepare::i#2 [ prepare::i#1 ] // zpby1=_inc_zpby1 +//SEG104 [43] (byte) prepare::i#1 ← ++ (byte) prepare::i#2 [ prepare::i#1 ] -- zpby1=_inc_zpby1 inc 13 - // [44] if((byte) prepare::i#1!=(byte) 0) goto prepare::@1 [ prepare::i#1 ] // zpby1_neq_0_then_la1 +//SEG105 [44] if((byte) prepare::i#1!=(byte) 0) goto prepare::@1 [ prepare::i#1 ] -- zpby1_neq_0_then_la1 lda 13 bne prepare__B1_from_B1 +//SEG106 prepare::@return prepare__Breturn: +//SEG107 [45] return [ ] rts Removing instruction jmp main__B3 Succesful ASM optimization Pass5NextJumpElimination ASSEMBLER +//SEG0 @BEGIN BBEGIN: +//SEG1 [0] call main param-assignment [ ] jsr main +//SEG2 @END BEND: +//SEG3 main main: +//SEG4 [1] call prepare param-assignment [ ] jsr prepare +//SEG5 [2] phi from main to main::@3 main__B3_from_main: - // (byte) main::c#2 = (byte) 25 // zpby1=coby1 +//SEG6 [2] phi (byte) main::c#2 = (byte) 25 -- zpby1=coby1 lda #25 sta 2 jmp main__B3 +//SEG7 [2] phi from main::@11 to main::@3 main__B3_from_B11: - // (byte) main::c#2 = (byte) 25 // zpby1=coby1 +//SEG8 [2] phi (byte) main::c#2 = (byte) 25 -- zpby1=coby1 lda #25 sta 2 +//SEG9 [2] phi from main::@3 to main::@3 main__B3_from_B3: +//SEG10 [2] phi from main::@6 to main::@3 main__B3_from_B6: - // (byte) main::c#2 = (byte) main::c#1 // register copy zp byte:2 +//SEG11 [2] phi (byte) main::c#2 = (byte) main::c#1 -- register_copy +//SEG12 main::@3 main__B3: - // [3] (byte~) main::$1 ← * (word) 53266 [ main::$1 main::c#2 ] // zpby1=_star_cowo1 +//SEG13 [3] (byte~) main::$1 ← * (word) 53266 [ main::$1 main::c#2 ] -- zpby1=_star_cowo1 lda 53266 sta 14 - // [4] if((byte~) main::$1!=(byte) 254) goto main::@3 [ main::c#2 ] // zpby1_neq_coby1_then_la1 +//SEG14 [4] if((byte~) main::$1!=(byte) 254) goto main::@3 [ main::c#2 ] -- zpby1_neq_coby1_then_la1 lda 14 cmp #254 bne main__B3_from_B3 +//SEG15 main::@4 main__B4: - // [5] (byte~) main::$3 ← * (word) 53266 [ main::$3 main::c#2 ] // zpby1=_star_cowo1 +//SEG16 [5] (byte~) main::$3 ← * (word) 53266 [ main::$3 main::c#2 ] -- zpby1=_star_cowo1 lda 53266 sta 15 - // [6] if((byte~) main::$3!=(byte) 255) goto main::@4 [ main::c#2 ] // zpby1_neq_coby1_then_la1 +//SEG17 [6] if((byte~) main::$3!=(byte) 255) goto main::@4 [ main::c#2 ] -- zpby1_neq_coby1_then_la1 lda 15 cmp #255 bne main__B4 +//SEG18 main::@6 main__B6: - // [7] (byte) main::c#1 ← -- (byte) main::c#2 [ main::c#1 ] // zpby1=_dec_zpby1 +//SEG19 [7] (byte) main::c#1 ← -- (byte) main::c#2 [ main::c#1 ] -- zpby1=_dec_zpby1 dec 2 - // [8] if((byte) main::c#1!=(byte) 0) goto main::@3 [ main::c#1 ] // zpby1_neq_0_then_la1 +//SEG20 [8] if((byte) main::c#1!=(byte) 0) goto main::@3 [ main::c#1 ] -- zpby1_neq_0_then_la1 lda 2 bne main__B3_from_B6 +//SEG21 main::@7 main__B7: +//SEG22 [9] call flip param-assignment [ ] jsr flip +//SEG23 main::@10 main__B10: +//SEG24 [10] call plot param-assignment [ ] jsr plot +//SEG25 main::@11 main__B11: - // [11] if(true) goto main::@3 [ ] // true_then_la1 +//SEG26 [11] if(true) goto main::@3 [ ] -- true_then_la1 jmp main__B3_from_B11 +//SEG27 main::@return main__Breturn: +//SEG28 [12] return [ ] rts +//SEG29 plot plot: +//SEG30 [13] phi from plot to plot::@1 plot__B1_from_plot: - // (byte) plot::y#2 = (byte) 16 // zpby1=coby1 +//SEG31 [13] phi (byte) plot::y#2 = (byte) 16 -- zpby1=coby1 lda #16 sta 5 - // (byte*) plot::line#2 = (word) 1236 // zpptrby1=cowo1 +//SEG32 [13] phi (byte*) plot::line#2 = (word) 1236 -- zpptrby1=cowo1 lda #<1236 sta 3 lda #>1236 sta 3+1 - // (byte) plot::i#3 = (byte) 0 // zpby1=coby1 +//SEG33 [13] phi (byte) plot::i#3 = (byte) 0 -- zpby1=coby1 lda #0 sta 6 +//SEG34 [13] phi from plot::@3 to plot::@1 plot__B1_from_B3: - // (byte) plot::y#2 = (byte) plot::y#1 // register copy zp byte:5 - // (byte*) plot::line#2 = (byte*) plot::line#1 // register copy zp ptr byte:3 - // (byte) plot::i#3 = (byte) plot::i#1 // register copy zp byte:6 +//SEG35 [13] phi (byte) plot::y#2 = (byte) plot::y#1 -- register_copy +//SEG36 [13] phi (byte*) plot::line#2 = (byte*) plot::line#1 -- register_copy +//SEG37 [13] phi (byte) plot::i#3 = (byte) plot::i#1 -- register_copy +//SEG38 plot::@1 plot__B1: +//SEG39 [14] phi from plot::@1 to plot::@2 plot__B2_from_B1: - // (byte) plot::x#2 = (byte) 0 // zpby1=coby1 +//SEG40 [14] phi (byte) plot::x#2 = (byte) 0 -- zpby1=coby1 lda #0 sta 7 - // (byte) plot::i#2 = (byte) plot::i#3 // register copy zp byte:6 +//SEG41 [14] phi (byte) plot::i#2 = (byte) plot::i#3 -- register_copy +//SEG42 [14] phi from plot::@2 to plot::@2 plot__B2_from_B2: - // (byte) plot::x#2 = (byte) plot::x#1 // register copy zp byte:7 - // (byte) plot::i#2 = (byte) plot::i#1 // register copy zp byte:6 +//SEG43 [14] phi (byte) plot::x#2 = (byte) plot::x#1 -- register_copy +//SEG44 [14] phi (byte) plot::i#2 = (byte) plot::i#1 -- register_copy +//SEG45 plot::@2 plot__B2: - // [15] (byte~) plot::$3 ← (word) 4096 *idx (byte) plot::i#2 [ plot::i#2 plot::line#2 plot::x#2 plot::$3 plot::y#2 ] // zpby1=cowo1_staridx_zpby2 +//SEG46 [15] (byte~) plot::$3 ← (word) 4096 *idx (byte) plot::i#2 [ plot::i#2 plot::line#2 plot::x#2 plot::$3 plot::y#2 ] -- zpby1=cowo1_staridx_zpby2 ldx 6 lda 4096,x sta 16 - // [16] *((byte*) plot::line#2 + (byte) plot::x#2) ← (byte~) plot::$3 [ plot::i#2 plot::line#2 plot::x#2 plot::y#2 ] // zpptrby1_staridx_zpby1=zpby2 +//SEG47 [16] *((byte*) plot::line#2 + (byte) plot::x#2) ← (byte~) plot::$3 [ plot::i#2 plot::line#2 plot::x#2 plot::y#2 ] -- zpptrby1_staridx_zpby1=zpby2 lda 16 ldy 7 sta (3),y - // [17] (byte) plot::i#1 ← ++ (byte) plot::i#2 [ plot::i#1 plot::line#2 plot::x#2 plot::y#2 ] // zpby1=_inc_zpby1 +//SEG48 [17] (byte) plot::i#1 ← ++ (byte) plot::i#2 [ plot::i#1 plot::line#2 plot::x#2 plot::y#2 ] -- zpby1=_inc_zpby1 inc 6 - // [18] (byte) plot::x#1 ← ++ (byte) plot::x#2 [ plot::i#1 plot::x#1 plot::line#2 plot::y#2 ] // zpby1=_inc_zpby1 +//SEG49 [18] (byte) plot::x#1 ← ++ (byte) plot::x#2 [ plot::i#1 plot::x#1 plot::line#2 plot::y#2 ] -- zpby1=_inc_zpby1 inc 7 - // [19] if((byte) plot::x#1<(byte) 16) goto plot::@2 [ plot::i#1 plot::x#1 plot::line#2 plot::y#2 ] // zpby1_lt_coby1_then_la1 +//SEG50 [19] if((byte) plot::x#1<(byte) 16) goto plot::@2 [ plot::i#1 plot::x#1 plot::line#2 plot::y#2 ] -- zpby1_lt_coby1_then_la1 lda 7 cmp #16 bcc plot__B2_from_B2 +//SEG51 plot::@3 plot__B3: - // [20] (byte*) plot::line#1 ← (byte*) plot::line#2 + (byte) 40 [ plot::i#1 plot::line#1 plot::y#2 ] // zpptrby1=zpptrby1_plus_coby1 +//SEG52 [20] (byte*) plot::line#1 ← (byte*) plot::line#2 + (byte) 40 [ plot::i#1 plot::line#1 plot::y#2 ] -- zpptrby1=zpptrby1_plus_coby1 lda 3 clc adc #40 @@ -5002,108 +5173,129 @@ plot__B3: bcc !+ inc 3+1 !: - // [21] (byte) plot::y#1 ← -- (byte) plot::y#2 [ plot::i#1 plot::line#1 plot::y#1 ] // zpby1=_dec_zpby1 +//SEG53 [21] (byte) plot::y#1 ← -- (byte) plot::y#2 [ plot::i#1 plot::line#1 plot::y#1 ] -- zpby1=_dec_zpby1 dec 5 - // [22] if((byte) plot::y#1!=(byte) 0) goto plot::@1 [ plot::i#1 plot::line#1 plot::y#1 ] // zpby1_neq_0_then_la1 +//SEG54 [22] if((byte) plot::y#1!=(byte) 0) goto plot::@1 [ plot::i#1 plot::line#1 plot::y#1 ] -- zpby1_neq_0_then_la1 lda 5 bne plot__B1_from_B3 +//SEG55 plot::@return plot__Breturn: +//SEG56 [23] return [ ] rts +//SEG57 flip flip: +//SEG58 [24] phi from flip to flip::@1 flip__B1_from_flip: - // (byte) flip::r#2 = (byte) 16 // zpby1=coby1 +//SEG59 [24] phi (byte) flip::r#2 = (byte) 16 -- zpby1=coby1 lda #16 sta 8 - // (byte) flip::dstIdx#5 = (byte) 15 // zpby1=coby1 +//SEG60 [24] phi (byte) flip::dstIdx#5 = (byte) 15 -- zpby1=coby1 lda #15 sta 10 - // (byte) flip::srcIdx#3 = (byte) 0 // zpby1=coby1 +//SEG61 [24] phi (byte) flip::srcIdx#3 = (byte) 0 -- zpby1=coby1 lda #0 sta 9 +//SEG62 [24] phi from flip::@4 to flip::@1 flip__B1_from_B4: - // (byte) flip::r#2 = (byte) flip::r#1 // register copy zp byte:8 - // (byte) flip::dstIdx#5 = (byte) flip::dstIdx#2 // register copy zp byte:10 - // (byte) flip::srcIdx#3 = (byte) flip::srcIdx#1 // register copy zp byte:9 +//SEG63 [24] phi (byte) flip::r#2 = (byte) flip::r#1 -- register_copy +//SEG64 [24] phi (byte) flip::dstIdx#5 = (byte) flip::dstIdx#2 -- register_copy +//SEG65 [24] phi (byte) flip::srcIdx#3 = (byte) flip::srcIdx#1 -- register_copy +//SEG66 flip::@1 flip__B1: +//SEG67 [25] phi from flip::@1 to flip::@2 flip__B2_from_B1: - // (byte) flip::c#2 = (byte) 16 // zpby1=coby1 +//SEG68 [25] phi (byte) flip::c#2 = (byte) 16 -- zpby1=coby1 lda #16 sta 11 - // (byte) flip::dstIdx#3 = (byte) flip::dstIdx#5 // register copy zp byte:10 - // (byte) flip::srcIdx#2 = (byte) flip::srcIdx#3 // register copy zp byte:9 +//SEG69 [25] phi (byte) flip::dstIdx#3 = (byte) flip::dstIdx#5 -- register_copy +//SEG70 [25] phi (byte) flip::srcIdx#2 = (byte) flip::srcIdx#3 -- register_copy +//SEG71 [25] phi from flip::@2 to flip::@2 flip__B2_from_B2: - // (byte) flip::c#2 = (byte) flip::c#1 // register copy zp byte:11 - // (byte) flip::dstIdx#3 = (byte) flip::dstIdx#1 // register copy zp byte:10 - // (byte) flip::srcIdx#2 = (byte) flip::srcIdx#1 // register copy zp byte:9 +//SEG72 [25] phi (byte) flip::c#2 = (byte) flip::c#1 -- register_copy +//SEG73 [25] phi (byte) flip::dstIdx#3 = (byte) flip::dstIdx#1 -- register_copy +//SEG74 [25] phi (byte) flip::srcIdx#2 = (byte) flip::srcIdx#1 -- register_copy +//SEG75 flip::@2 flip__B2: - // [26] (byte~) flip::$0 ← (word) 4096 *idx (byte) flip::srcIdx#2 [ flip::srcIdx#2 flip::dstIdx#3 flip::$0 flip::c#2 flip::r#2 ] // zpby1=cowo1_staridx_zpby2 +//SEG76 [26] (byte~) flip::$0 ← (word) 4096 *idx (byte) flip::srcIdx#2 [ flip::srcIdx#2 flip::dstIdx#3 flip::$0 flip::c#2 flip::r#2 ] -- zpby1=cowo1_staridx_zpby2 ldx 9 lda 4096,x sta 17 - // [27] *((word) 4352 + (byte) flip::dstIdx#3) ← (byte~) flip::$0 [ flip::srcIdx#2 flip::dstIdx#3 flip::c#2 flip::r#2 ] // cowo1_staridx_zpby1=zpby2 +//SEG77 [27] *((word) 4352 + (byte) flip::dstIdx#3) ← (byte~) flip::$0 [ flip::srcIdx#2 flip::dstIdx#3 flip::c#2 flip::r#2 ] -- cowo1_staridx_zpby1=zpby2 lda 17 ldx 10 sta 4352,x - // [28] (byte) flip::srcIdx#1 ← ++ (byte) flip::srcIdx#2 [ flip::srcIdx#1 flip::dstIdx#3 flip::c#2 flip::r#2 ] // zpby1=_inc_zpby1 +//SEG78 [28] (byte) flip::srcIdx#1 ← ++ (byte) flip::srcIdx#2 [ flip::srcIdx#1 flip::dstIdx#3 flip::c#2 flip::r#2 ] -- zpby1=_inc_zpby1 inc 9 - // [29] (byte) flip::dstIdx#1 ← (byte) flip::dstIdx#3 + (byte) 16 [ flip::srcIdx#1 flip::dstIdx#1 flip::c#2 flip::r#2 ] // zpby1=zpby1_plus_coby1 +//SEG79 [29] (byte) flip::dstIdx#1 ← (byte) flip::dstIdx#3 + (byte) 16 [ flip::srcIdx#1 flip::dstIdx#1 flip::c#2 flip::r#2 ] -- zpby1=zpby1_plus_coby1 lda 10 clc adc #16 sta 10 - // [30] (byte) flip::c#1 ← -- (byte) flip::c#2 [ flip::srcIdx#1 flip::dstIdx#1 flip::c#1 flip::r#2 ] // zpby1=_dec_zpby1 +//SEG80 [30] (byte) flip::c#1 ← -- (byte) flip::c#2 [ flip::srcIdx#1 flip::dstIdx#1 flip::c#1 flip::r#2 ] -- zpby1=_dec_zpby1 dec 11 - // [31] if((byte) flip::c#1!=(byte) 0) goto flip::@2 [ flip::srcIdx#1 flip::dstIdx#1 flip::c#1 flip::r#2 ] // zpby1_neq_0_then_la1 +//SEG81 [31] if((byte) flip::c#1!=(byte) 0) goto flip::@2 [ flip::srcIdx#1 flip::dstIdx#1 flip::c#1 flip::r#2 ] -- zpby1_neq_0_then_la1 lda 11 bne flip__B2_from_B2 +//SEG82 flip::@4 flip__B4: - // [32] (byte) flip::dstIdx#2 ← -- (byte) flip::dstIdx#1 [ flip::srcIdx#1 flip::dstIdx#2 flip::r#2 ] // zpby1=_dec_zpby1 +//SEG83 [32] (byte) flip::dstIdx#2 ← -- (byte) flip::dstIdx#1 [ flip::srcIdx#1 flip::dstIdx#2 flip::r#2 ] -- zpby1=_dec_zpby1 dec 10 - // [33] (byte) flip::r#1 ← -- (byte) flip::r#2 [ flip::srcIdx#1 flip::dstIdx#2 flip::r#1 ] // zpby1=_dec_zpby1 +//SEG84 [33] (byte) flip::r#1 ← -- (byte) flip::r#2 [ flip::srcIdx#1 flip::dstIdx#2 flip::r#1 ] -- zpby1=_dec_zpby1 dec 8 - // [34] if((byte) flip::r#1!=(byte) 0) goto flip::@1 [ flip::srcIdx#1 flip::dstIdx#2 flip::r#1 ] // zpby1_neq_0_then_la1 +//SEG85 [34] if((byte) flip::r#1!=(byte) 0) goto flip::@1 [ flip::srcIdx#1 flip::dstIdx#2 flip::r#1 ] -- zpby1_neq_0_then_la1 lda 8 bne flip__B1_from_B4 +//SEG86 [35] phi from flip::@4 to flip::@3 flip__B3_from_B4: - // (byte) flip::i#2 = (byte) 0 // zpby1=coby1 +//SEG87 [35] phi (byte) flip::i#2 = (byte) 0 -- zpby1=coby1 lda #0 sta 12 +//SEG88 [35] phi from flip::@3 to flip::@3 flip__B3_from_B3: - // (byte) flip::i#2 = (byte) flip::i#1 // register copy zp byte:12 +//SEG89 [35] phi (byte) flip::i#2 = (byte) flip::i#1 -- register_copy +//SEG90 flip::@3 flip__B3: - // [36] (byte~) flip::$4 ← (word) 4352 *idx (byte) flip::i#2 [ flip::i#2 flip::$4 ] // zpby1=cowo1_staridx_zpby2 +//SEG91 [36] (byte~) flip::$4 ← (word) 4352 *idx (byte) flip::i#2 [ flip::i#2 flip::$4 ] -- zpby1=cowo1_staridx_zpby2 ldx 12 lda 4352,x sta 18 - // [37] *((word) 4096 + (byte) flip::i#2) ← (byte~) flip::$4 [ flip::i#2 ] // cowo1_staridx_zpby1=zpby2 +//SEG92 [37] *((word) 4096 + (byte) flip::i#2) ← (byte~) flip::$4 [ flip::i#2 ] -- cowo1_staridx_zpby1=zpby2 lda 18 ldx 12 sta 4096,x - // [38] (byte) flip::i#1 ← ++ (byte) flip::i#2 [ flip::i#1 ] // zpby1=_inc_zpby1 +//SEG93 [38] (byte) flip::i#1 ← ++ (byte) flip::i#2 [ flip::i#1 ] -- zpby1=_inc_zpby1 inc 12 - // [39] if((byte) flip::i#1!=(byte) 0) goto flip::@3 [ flip::i#1 ] // zpby1_neq_0_then_la1 +//SEG94 [39] if((byte) flip::i#1!=(byte) 0) goto flip::@3 [ flip::i#1 ] -- zpby1_neq_0_then_la1 lda 12 bne flip__B3_from_B3 +//SEG95 flip::@return flip__Breturn: +//SEG96 [40] return [ ] rts +//SEG97 prepare prepare: +//SEG98 [41] phi from prepare to prepare::@1 prepare__B1_from_prepare: - // (byte) prepare::i#2 = (byte) 0 // zpby1=coby1 +//SEG99 [41] phi (byte) prepare::i#2 = (byte) 0 -- zpby1=coby1 lda #0 sta 13 +//SEG100 [41] phi from prepare::@1 to prepare::@1 prepare__B1_from_B1: - // (byte) prepare::i#2 = (byte) prepare::i#1 // register copy zp byte:13 +//SEG101 [41] phi (byte) prepare::i#2 = (byte) prepare::i#1 -- register_copy +//SEG102 prepare::@1 prepare__B1: - // [42] *((word) 4096 + (byte) prepare::i#2) ← (byte) prepare::i#2 [ prepare::i#2 ] // cowo1_staridx_zpby1=zpby1 +//SEG103 [42] *((word) 4096 + (byte) prepare::i#2) ← (byte) prepare::i#2 [ prepare::i#2 ] -- cowo1_staridx_zpby1=zpby1 ldx 13 txa sta 4096,x - // [43] (byte) prepare::i#1 ← ++ (byte) prepare::i#2 [ prepare::i#1 ] // zpby1=_inc_zpby1 +//SEG104 [43] (byte) prepare::i#1 ← ++ (byte) prepare::i#2 [ prepare::i#1 ] -- zpby1=_inc_zpby1 inc 13 - // [44] if((byte) prepare::i#1!=(byte) 0) goto prepare::@1 [ prepare::i#1 ] // zpby1_neq_0_then_la1 +//SEG105 [44] if((byte) prepare::i#1!=(byte) 0) goto prepare::@1 [ prepare::i#1 ] -- zpby1_neq_0_then_la1 lda 13 bne prepare__B1_from_B1 +//SEG106 prepare::@return prepare__Breturn: +//SEG107 [45] return [ ] rts FINAL SYMBOL TABLE @@ -5186,99 +5378,126 @@ zp byte:11 [ flip::c#2 flip::c#1 plot::$3 ] zp byte:17 [ flip::$0 ] FINAL CODE +//SEG0 @BEGIN BBEGIN: +//SEG1 [0] call main param-assignment [ ] jsr main +//SEG2 @END BEND: +//SEG3 main main: +//SEG4 [1] call prepare param-assignment [ ] jsr prepare +//SEG5 [2] phi from main to main::@3 main__B3_from_main: - // (byte) main::c#2 = (byte) 25 // zpby1=coby1 +//SEG6 [2] phi (byte) main::c#2 = (byte) 25 -- zpby1=coby1 lda #25 sta 2 jmp main__B3 +//SEG7 [2] phi from main::@11 to main::@3 main__B3_from_B11: - // (byte) main::c#2 = (byte) 25 // zpby1=coby1 +//SEG8 [2] phi (byte) main::c#2 = (byte) 25 -- zpby1=coby1 lda #25 sta 2 +//SEG9 [2] phi from main::@3 to main::@3 main__B3_from_B3: +//SEG10 [2] phi from main::@6 to main::@3 main__B3_from_B6: - // (byte) main::c#2 = (byte) main::c#1 // register copy zp byte:2 +//SEG11 [2] phi (byte) main::c#2 = (byte) main::c#1 -- register_copy +//SEG12 main::@3 main__B3: - // [3] (byte~) main::$1 ← * (word) 53266 [ main::$1 main::c#2 ] // zpby1=_star_cowo1 +//SEG13 [3] (byte~) main::$1 ← * (word) 53266 [ main::$1 main::c#2 ] -- zpby1=_star_cowo1 lda 53266 sta 14 - // [4] if((byte~) main::$1!=(byte) 254) goto main::@3 [ main::c#2 ] // zpby1_neq_coby1_then_la1 +//SEG14 [4] if((byte~) main::$1!=(byte) 254) goto main::@3 [ main::c#2 ] -- zpby1_neq_coby1_then_la1 lda 14 cmp #254 bne main__B3_from_B3 +//SEG15 main::@4 main__B4: - // [5] (byte~) main::$3 ← * (word) 53266 [ main::$3 main::c#2 ] // zpby1=_star_cowo1 +//SEG16 [5] (byte~) main::$3 ← * (word) 53266 [ main::$3 main::c#2 ] -- zpby1=_star_cowo1 lda 53266 sta 15 - // [6] if((byte~) main::$3!=(byte) 255) goto main::@4 [ main::c#2 ] // zpby1_neq_coby1_then_la1 +//SEG17 [6] if((byte~) main::$3!=(byte) 255) goto main::@4 [ main::c#2 ] -- zpby1_neq_coby1_then_la1 lda 15 cmp #255 bne main__B4 +//SEG18 main::@6 main__B6: - // [7] (byte) main::c#1 ← -- (byte) main::c#2 [ main::c#1 ] // zpby1=_dec_zpby1 +//SEG19 [7] (byte) main::c#1 ← -- (byte) main::c#2 [ main::c#1 ] -- zpby1=_dec_zpby1 dec 2 - // [8] if((byte) main::c#1!=(byte) 0) goto main::@3 [ main::c#1 ] // zpby1_neq_0_then_la1 +//SEG20 [8] if((byte) main::c#1!=(byte) 0) goto main::@3 [ main::c#1 ] -- zpby1_neq_0_then_la1 lda 2 bne main__B3_from_B6 +//SEG21 main::@7 main__B7: +//SEG22 [9] call flip param-assignment [ ] jsr flip +//SEG23 main::@10 main__B10: +//SEG24 [10] call plot param-assignment [ ] jsr plot +//SEG25 main::@11 main__B11: - // [11] if(true) goto main::@3 [ ] // true_then_la1 +//SEG26 [11] if(true) goto main::@3 [ ] -- true_then_la1 jmp main__B3_from_B11 +//SEG27 main::@return main__Breturn: +//SEG28 [12] return [ ] rts +//SEG29 plot plot: +//SEG30 [13] phi from plot to plot::@1 plot__B1_from_plot: - // (byte) plot::y#2 = (byte) 16 // zpby1=coby1 +//SEG31 [13] phi (byte) plot::y#2 = (byte) 16 -- zpby1=coby1 lda #16 sta 5 - // (byte*) plot::line#2 = (word) 1236 // zpptrby1=cowo1 +//SEG32 [13] phi (byte*) plot::line#2 = (word) 1236 -- zpptrby1=cowo1 lda #<1236 sta 3 lda #>1236 sta 3+1 - // (byte) plot::i#3 = (byte) 0 // zpby1=coby1 +//SEG33 [13] phi (byte) plot::i#3 = (byte) 0 -- zpby1=coby1 lda #0 sta 6 +//SEG34 [13] phi from plot::@3 to plot::@1 plot__B1_from_B3: - // (byte) plot::y#2 = (byte) plot::y#1 // register copy zp byte:5 - // (byte*) plot::line#2 = (byte*) plot::line#1 // register copy zp ptr byte:3 - // (byte) plot::i#3 = (byte) plot::i#1 // register copy zp byte:6 +//SEG35 [13] phi (byte) plot::y#2 = (byte) plot::y#1 -- register_copy +//SEG36 [13] phi (byte*) plot::line#2 = (byte*) plot::line#1 -- register_copy +//SEG37 [13] phi (byte) plot::i#3 = (byte) plot::i#1 -- register_copy +//SEG38 plot::@1 plot__B1: +//SEG39 [14] phi from plot::@1 to plot::@2 plot__B2_from_B1: - // (byte) plot::x#2 = (byte) 0 // zpby1=coby1 +//SEG40 [14] phi (byte) plot::x#2 = (byte) 0 -- zpby1=coby1 lda #0 sta 7 - // (byte) plot::i#2 = (byte) plot::i#3 // register copy zp byte:6 +//SEG41 [14] phi (byte) plot::i#2 = (byte) plot::i#3 -- register_copy +//SEG42 [14] phi from plot::@2 to plot::@2 plot__B2_from_B2: - // (byte) plot::x#2 = (byte) plot::x#1 // register copy zp byte:7 - // (byte) plot::i#2 = (byte) plot::i#1 // register copy zp byte:6 +//SEG43 [14] phi (byte) plot::x#2 = (byte) plot::x#1 -- register_copy +//SEG44 [14] phi (byte) plot::i#2 = (byte) plot::i#1 -- register_copy +//SEG45 plot::@2 plot__B2: - // [15] (byte~) plot::$3 ← (word) 4096 *idx (byte) plot::i#2 [ plot::i#2 plot::line#2 plot::x#2 plot::$3 plot::y#2 ] // zpby1=cowo1_staridx_zpby2 +//SEG46 [15] (byte~) plot::$3 ← (word) 4096 *idx (byte) plot::i#2 [ plot::i#2 plot::line#2 plot::x#2 plot::$3 plot::y#2 ] -- zpby1=cowo1_staridx_zpby2 ldx 6 lda 4096,x sta 16 - // [16] *((byte*) plot::line#2 + (byte) plot::x#2) ← (byte~) plot::$3 [ plot::i#2 plot::line#2 plot::x#2 plot::y#2 ] // zpptrby1_staridx_zpby1=zpby2 +//SEG47 [16] *((byte*) plot::line#2 + (byte) plot::x#2) ← (byte~) plot::$3 [ plot::i#2 plot::line#2 plot::x#2 plot::y#2 ] -- zpptrby1_staridx_zpby1=zpby2 lda 16 ldy 7 sta (3),y - // [17] (byte) plot::i#1 ← ++ (byte) plot::i#2 [ plot::i#1 plot::line#2 plot::x#2 plot::y#2 ] // zpby1=_inc_zpby1 +//SEG48 [17] (byte) plot::i#1 ← ++ (byte) plot::i#2 [ plot::i#1 plot::line#2 plot::x#2 plot::y#2 ] -- zpby1=_inc_zpby1 inc 6 - // [18] (byte) plot::x#1 ← ++ (byte) plot::x#2 [ plot::i#1 plot::x#1 plot::line#2 plot::y#2 ] // zpby1=_inc_zpby1 +//SEG49 [18] (byte) plot::x#1 ← ++ (byte) plot::x#2 [ plot::i#1 plot::x#1 plot::line#2 plot::y#2 ] -- zpby1=_inc_zpby1 inc 7 - // [19] if((byte) plot::x#1<(byte) 16) goto plot::@2 [ plot::i#1 plot::x#1 plot::line#2 plot::y#2 ] // zpby1_lt_coby1_then_la1 +//SEG50 [19] if((byte) plot::x#1<(byte) 16) goto plot::@2 [ plot::i#1 plot::x#1 plot::line#2 plot::y#2 ] -- zpby1_lt_coby1_then_la1 lda 7 cmp #16 bcc plot__B2_from_B2 +//SEG51 plot::@3 plot__B3: - // [20] (byte*) plot::line#1 ← (byte*) plot::line#2 + (byte) 40 [ plot::i#1 plot::line#1 plot::y#2 ] // zpptrby1=zpptrby1_plus_coby1 +//SEG52 [20] (byte*) plot::line#1 ← (byte*) plot::line#2 + (byte) 40 [ plot::i#1 plot::line#1 plot::y#2 ] -- zpptrby1=zpptrby1_plus_coby1 lda 3 clc adc #40 @@ -5286,107 +5505,128 @@ plot__B3: bcc !+ inc 3+1 !: - // [21] (byte) plot::y#1 ← -- (byte) plot::y#2 [ plot::i#1 plot::line#1 plot::y#1 ] // zpby1=_dec_zpby1 +//SEG53 [21] (byte) plot::y#1 ← -- (byte) plot::y#2 [ plot::i#1 plot::line#1 plot::y#1 ] -- zpby1=_dec_zpby1 dec 5 - // [22] if((byte) plot::y#1!=(byte) 0) goto plot::@1 [ plot::i#1 plot::line#1 plot::y#1 ] // zpby1_neq_0_then_la1 +//SEG54 [22] if((byte) plot::y#1!=(byte) 0) goto plot::@1 [ plot::i#1 plot::line#1 plot::y#1 ] -- zpby1_neq_0_then_la1 lda 5 bne plot__B1_from_B3 +//SEG55 plot::@return plot__Breturn: +//SEG56 [23] return [ ] rts +//SEG57 flip flip: +//SEG58 [24] phi from flip to flip::@1 flip__B1_from_flip: - // (byte) flip::r#2 = (byte) 16 // zpby1=coby1 +//SEG59 [24] phi (byte) flip::r#2 = (byte) 16 -- zpby1=coby1 lda #16 sta 8 - // (byte) flip::dstIdx#5 = (byte) 15 // zpby1=coby1 +//SEG60 [24] phi (byte) flip::dstIdx#5 = (byte) 15 -- zpby1=coby1 lda #15 sta 10 - // (byte) flip::srcIdx#3 = (byte) 0 // zpby1=coby1 +//SEG61 [24] phi (byte) flip::srcIdx#3 = (byte) 0 -- zpby1=coby1 lda #0 sta 9 +//SEG62 [24] phi from flip::@4 to flip::@1 flip__B1_from_B4: - // (byte) flip::r#2 = (byte) flip::r#1 // register copy zp byte:8 - // (byte) flip::dstIdx#5 = (byte) flip::dstIdx#2 // register copy zp byte:10 - // (byte) flip::srcIdx#3 = (byte) flip::srcIdx#1 // register copy zp byte:9 +//SEG63 [24] phi (byte) flip::r#2 = (byte) flip::r#1 -- register_copy +//SEG64 [24] phi (byte) flip::dstIdx#5 = (byte) flip::dstIdx#2 -- register_copy +//SEG65 [24] phi (byte) flip::srcIdx#3 = (byte) flip::srcIdx#1 -- register_copy +//SEG66 flip::@1 flip__B1: +//SEG67 [25] phi from flip::@1 to flip::@2 flip__B2_from_B1: - // (byte) flip::c#2 = (byte) 16 // zpby1=coby1 +//SEG68 [25] phi (byte) flip::c#2 = (byte) 16 -- zpby1=coby1 lda #16 sta 11 - // (byte) flip::dstIdx#3 = (byte) flip::dstIdx#5 // register copy zp byte:10 - // (byte) flip::srcIdx#2 = (byte) flip::srcIdx#3 // register copy zp byte:9 +//SEG69 [25] phi (byte) flip::dstIdx#3 = (byte) flip::dstIdx#5 -- register_copy +//SEG70 [25] phi (byte) flip::srcIdx#2 = (byte) flip::srcIdx#3 -- register_copy +//SEG71 [25] phi from flip::@2 to flip::@2 flip__B2_from_B2: - // (byte) flip::c#2 = (byte) flip::c#1 // register copy zp byte:11 - // (byte) flip::dstIdx#3 = (byte) flip::dstIdx#1 // register copy zp byte:10 - // (byte) flip::srcIdx#2 = (byte) flip::srcIdx#1 // register copy zp byte:9 +//SEG72 [25] phi (byte) flip::c#2 = (byte) flip::c#1 -- register_copy +//SEG73 [25] phi (byte) flip::dstIdx#3 = (byte) flip::dstIdx#1 -- register_copy +//SEG74 [25] phi (byte) flip::srcIdx#2 = (byte) flip::srcIdx#1 -- register_copy +//SEG75 flip::@2 flip__B2: - // [26] (byte~) flip::$0 ← (word) 4096 *idx (byte) flip::srcIdx#2 [ flip::srcIdx#2 flip::dstIdx#3 flip::$0 flip::c#2 flip::r#2 ] // zpby1=cowo1_staridx_zpby2 +//SEG76 [26] (byte~) flip::$0 ← (word) 4096 *idx (byte) flip::srcIdx#2 [ flip::srcIdx#2 flip::dstIdx#3 flip::$0 flip::c#2 flip::r#2 ] -- zpby1=cowo1_staridx_zpby2 ldx 9 lda 4096,x sta 17 - // [27] *((word) 4352 + (byte) flip::dstIdx#3) ← (byte~) flip::$0 [ flip::srcIdx#2 flip::dstIdx#3 flip::c#2 flip::r#2 ] // cowo1_staridx_zpby1=zpby2 +//SEG77 [27] *((word) 4352 + (byte) flip::dstIdx#3) ← (byte~) flip::$0 [ flip::srcIdx#2 flip::dstIdx#3 flip::c#2 flip::r#2 ] -- cowo1_staridx_zpby1=zpby2 lda 17 ldx 10 sta 4352,x - // [28] (byte) flip::srcIdx#1 ← ++ (byte) flip::srcIdx#2 [ flip::srcIdx#1 flip::dstIdx#3 flip::c#2 flip::r#2 ] // zpby1=_inc_zpby1 +//SEG78 [28] (byte) flip::srcIdx#1 ← ++ (byte) flip::srcIdx#2 [ flip::srcIdx#1 flip::dstIdx#3 flip::c#2 flip::r#2 ] -- zpby1=_inc_zpby1 inc 9 - // [29] (byte) flip::dstIdx#1 ← (byte) flip::dstIdx#3 + (byte) 16 [ flip::srcIdx#1 flip::dstIdx#1 flip::c#2 flip::r#2 ] // zpby1=zpby1_plus_coby1 +//SEG79 [29] (byte) flip::dstIdx#1 ← (byte) flip::dstIdx#3 + (byte) 16 [ flip::srcIdx#1 flip::dstIdx#1 flip::c#2 flip::r#2 ] -- zpby1=zpby1_plus_coby1 lda 10 clc adc #16 sta 10 - // [30] (byte) flip::c#1 ← -- (byte) flip::c#2 [ flip::srcIdx#1 flip::dstIdx#1 flip::c#1 flip::r#2 ] // zpby1=_dec_zpby1 +//SEG80 [30] (byte) flip::c#1 ← -- (byte) flip::c#2 [ flip::srcIdx#1 flip::dstIdx#1 flip::c#1 flip::r#2 ] -- zpby1=_dec_zpby1 dec 11 - // [31] if((byte) flip::c#1!=(byte) 0) goto flip::@2 [ flip::srcIdx#1 flip::dstIdx#1 flip::c#1 flip::r#2 ] // zpby1_neq_0_then_la1 +//SEG81 [31] if((byte) flip::c#1!=(byte) 0) goto flip::@2 [ flip::srcIdx#1 flip::dstIdx#1 flip::c#1 flip::r#2 ] -- zpby1_neq_0_then_la1 lda 11 bne flip__B2_from_B2 +//SEG82 flip::@4 flip__B4: - // [32] (byte) flip::dstIdx#2 ← -- (byte) flip::dstIdx#1 [ flip::srcIdx#1 flip::dstIdx#2 flip::r#2 ] // zpby1=_dec_zpby1 +//SEG83 [32] (byte) flip::dstIdx#2 ← -- (byte) flip::dstIdx#1 [ flip::srcIdx#1 flip::dstIdx#2 flip::r#2 ] -- zpby1=_dec_zpby1 dec 10 - // [33] (byte) flip::r#1 ← -- (byte) flip::r#2 [ flip::srcIdx#1 flip::dstIdx#2 flip::r#1 ] // zpby1=_dec_zpby1 +//SEG84 [33] (byte) flip::r#1 ← -- (byte) flip::r#2 [ flip::srcIdx#1 flip::dstIdx#2 flip::r#1 ] -- zpby1=_dec_zpby1 dec 8 - // [34] if((byte) flip::r#1!=(byte) 0) goto flip::@1 [ flip::srcIdx#1 flip::dstIdx#2 flip::r#1 ] // zpby1_neq_0_then_la1 +//SEG85 [34] if((byte) flip::r#1!=(byte) 0) goto flip::@1 [ flip::srcIdx#1 flip::dstIdx#2 flip::r#1 ] -- zpby1_neq_0_then_la1 lda 8 bne flip__B1_from_B4 +//SEG86 [35] phi from flip::@4 to flip::@3 flip__B3_from_B4: - // (byte) flip::i#2 = (byte) 0 // zpby1=coby1 +//SEG87 [35] phi (byte) flip::i#2 = (byte) 0 -- zpby1=coby1 lda #0 sta 12 +//SEG88 [35] phi from flip::@3 to flip::@3 flip__B3_from_B3: - // (byte) flip::i#2 = (byte) flip::i#1 // register copy zp byte:12 +//SEG89 [35] phi (byte) flip::i#2 = (byte) flip::i#1 -- register_copy +//SEG90 flip::@3 flip__B3: - // [36] (byte~) flip::$4 ← (word) 4352 *idx (byte) flip::i#2 [ flip::i#2 flip::$4 ] // zpby1=cowo1_staridx_zpby2 +//SEG91 [36] (byte~) flip::$4 ← (word) 4352 *idx (byte) flip::i#2 [ flip::i#2 flip::$4 ] -- zpby1=cowo1_staridx_zpby2 ldx 12 lda 4352,x sta 18 - // [37] *((word) 4096 + (byte) flip::i#2) ← (byte~) flip::$4 [ flip::i#2 ] // cowo1_staridx_zpby1=zpby2 +//SEG92 [37] *((word) 4096 + (byte) flip::i#2) ← (byte~) flip::$4 [ flip::i#2 ] -- cowo1_staridx_zpby1=zpby2 lda 18 ldx 12 sta 4096,x - // [38] (byte) flip::i#1 ← ++ (byte) flip::i#2 [ flip::i#1 ] // zpby1=_inc_zpby1 +//SEG93 [38] (byte) flip::i#1 ← ++ (byte) flip::i#2 [ flip::i#1 ] -- zpby1=_inc_zpby1 inc 12 - // [39] if((byte) flip::i#1!=(byte) 0) goto flip::@3 [ flip::i#1 ] // zpby1_neq_0_then_la1 +//SEG94 [39] if((byte) flip::i#1!=(byte) 0) goto flip::@3 [ flip::i#1 ] -- zpby1_neq_0_then_la1 lda 12 bne flip__B3_from_B3 +//SEG95 flip::@return flip__Breturn: +//SEG96 [40] return [ ] rts +//SEG97 prepare prepare: +//SEG98 [41] phi from prepare to prepare::@1 prepare__B1_from_prepare: - // (byte) prepare::i#2 = (byte) 0 // zpby1=coby1 +//SEG99 [41] phi (byte) prepare::i#2 = (byte) 0 -- zpby1=coby1 lda #0 sta 13 +//SEG100 [41] phi from prepare::@1 to prepare::@1 prepare__B1_from_B1: - // (byte) prepare::i#2 = (byte) prepare::i#1 // register copy zp byte:13 +//SEG101 [41] phi (byte) prepare::i#2 = (byte) prepare::i#1 -- register_copy +//SEG102 prepare::@1 prepare__B1: - // [42] *((word) 4096 + (byte) prepare::i#2) ← (byte) prepare::i#2 [ prepare::i#2 ] // cowo1_staridx_zpby1=zpby1 +//SEG103 [42] *((word) 4096 + (byte) prepare::i#2) ← (byte) prepare::i#2 [ prepare::i#2 ] -- cowo1_staridx_zpby1=zpby1 ldx 13 txa sta 4096,x - // [43] (byte) prepare::i#1 ← ++ (byte) prepare::i#2 [ prepare::i#1 ] // zpby1=_inc_zpby1 +//SEG104 [43] (byte) prepare::i#1 ← ++ (byte) prepare::i#2 [ prepare::i#1 ] -- zpby1=_inc_zpby1 inc 13 - // [44] if((byte) prepare::i#1!=(byte) 0) goto prepare::@1 [ prepare::i#1 ] // zpby1_neq_0_then_la1 +//SEG105 [44] if((byte) prepare::i#1!=(byte) 0) goto prepare::@1 [ prepare::i#1 ] -- zpby1_neq_0_then_la1 lda 13 bne prepare__B1_from_B1 +//SEG106 prepare::@return prepare__Breturn: +//SEG107 [45] return [ ] rts diff --git a/src/main/java/dk/camelot64/kickc/test/ref/loopmin.log b/src/main/java/dk/camelot64/kickc/test/ref/loopmin.log index 39f11698f..0337d4204 100644 --- a/src/main/java/dk/camelot64/kickc/test/ref/loopmin.log +++ b/src/main/java/dk/camelot64/kickc/test/ref/loopmin.log @@ -383,9 +383,9 @@ zp byte:3 [ s#2 s#4 s#1 ] Uplifting max weight 49.5 live range equivalence class zp byte:3 [ s#2 s#4 s#1 ] Uplift to reg byte a resulted in clobber. -Register Cycles: reg byte x 28 +Register Cycles: reg byte x 29 Uplift to reg byte x succesfull. -Register Cycles: reg byte y 28 +Register Cycles: reg byte y 29 Uplift to reg byte y succesfull. REGISTER UPLIFTING (byte) i @@ -400,45 +400,54 @@ zp byte:2 [ i#2 i#1 ] zp byte:3 [ s#2 s#4 s#1 ] INITIAL ASM +//SEG0 @BEGIN BBEGIN: +//SEG1 [0] phi from @BEGIN to @1 B1_from_BBEGIN: - // (byte) s#2 = (byte) 0 // zpby1=coby1 +//SEG2 [0] phi (byte) s#2 = (byte) 0 -- zpby1=coby1 lda #0 sta 3 - // (byte) i#2 = (byte) 10 // zpby1=coby1 +//SEG3 [0] phi (byte) i#2 = (byte) 10 -- zpby1=coby1 lda #10 sta 2 jmp B1 +//SEG4 [0] phi from @3 to @1 B1_from_B3: - // (byte) s#2 = (byte) s#4 // register copy zp byte:3 - // (byte) i#2 = (byte) i#1 // register copy zp byte:2 +//SEG5 [0] phi (byte) s#2 = (byte) s#4 -- register_copy +//SEG6 [0] phi (byte) i#2 = (byte) i#1 -- register_copy jmp B1 +//SEG7 @1 B1: - // [1] if((byte) i#2>(byte) 5) goto @2 [ i#2 s#2 ] // zpby1_gt_coby1_then_la1 +//SEG8 [1] if((byte) i#2>(byte) 5) goto @2 [ i#2 s#2 ] -- zpby1_gt_coby1_then_la1 lda 2 cmp #5 beq !+ bcs B2 !: +//SEG9 [2] phi from @1 to @3 B3_from_B1: - // (byte) s#4 = (byte) s#2 // register copy zp byte:3 +//SEG10 [2] phi (byte) s#4 = (byte) s#2 -- register_copy jmp B3 +//SEG11 @3 B3: - // [3] (byte) i#1 ← -- (byte) i#2 [ i#1 s#4 ] // zpby1=_dec_zpby1 +//SEG12 [3] (byte) i#1 ← -- (byte) i#2 [ i#1 s#4 ] -- zpby1=_dec_zpby1 dec 2 - // [4] if((byte) i#1>(byte) 0) goto @1 [ i#1 s#4 ] // zpby1_gt_0_then_la1 +//SEG13 [4] if((byte) i#1>(byte) 0) goto @1 [ i#1 s#4 ] -- zpby1_gt_0_then_la1 lda 2 bne B1_from_B3 jmp BEND +//SEG14 @END BEND: +//SEG15 @2 B2: - // [5] (byte) s#1 ← (byte) s#2 + (byte) i#2 [ i#2 s#1 ] // zpby1=zpby1_plus_zpby2 +//SEG16 [5] (byte) s#1 ← (byte) s#2 + (byte) i#2 [ i#2 s#1 ] -- zpby1=zpby1_plus_zpby2 lda 3 clc adc 2 sta 3 +//SEG17 [2] phi from @2 to @3 B3_from_B2: - // (byte) s#4 = (byte) s#1 // register copy zp byte:3 +//SEG18 [2] phi (byte) s#4 = (byte) s#1 -- register_copy jmp B3 Removing instruction jmp B1 @@ -446,82 +455,100 @@ Removing instruction jmp B3 Removing instruction jmp BEND Succesful ASM optimization Pass5NextJumpElimination ASSEMBLER +//SEG0 @BEGIN BBEGIN: +//SEG1 [0] phi from @BEGIN to @1 B1_from_BBEGIN: - // (byte) s#2 = (byte) 0 // zpby1=coby1 +//SEG2 [0] phi (byte) s#2 = (byte) 0 -- zpby1=coby1 lda #0 sta 3 - // (byte) i#2 = (byte) 10 // zpby1=coby1 +//SEG3 [0] phi (byte) i#2 = (byte) 10 -- zpby1=coby1 lda #10 sta 2 jmp B1 +//SEG4 [0] phi from @3 to @1 B1_from_B3: - // (byte) s#2 = (byte) s#4 // register copy zp byte:3 - // (byte) i#2 = (byte) i#1 // register copy zp byte:2 +//SEG5 [0] phi (byte) s#2 = (byte) s#4 -- register_copy +//SEG6 [0] phi (byte) i#2 = (byte) i#1 -- register_copy +//SEG7 @1 B1: - // [1] if((byte) i#2>(byte) 5) goto @2 [ i#2 s#2 ] // zpby1_gt_coby1_then_la1 +//SEG8 [1] if((byte) i#2>(byte) 5) goto @2 [ i#2 s#2 ] -- zpby1_gt_coby1_then_la1 lda 2 cmp #5 beq !+ bcs B2 !: +//SEG9 [2] phi from @1 to @3 B3_from_B1: - // (byte) s#4 = (byte) s#2 // register copy zp byte:3 +//SEG10 [2] phi (byte) s#4 = (byte) s#2 -- register_copy +//SEG11 @3 B3: - // [3] (byte) i#1 ← -- (byte) i#2 [ i#1 s#4 ] // zpby1=_dec_zpby1 +//SEG12 [3] (byte) i#1 ← -- (byte) i#2 [ i#1 s#4 ] -- zpby1=_dec_zpby1 dec 2 - // [4] if((byte) i#1>(byte) 0) goto @1 [ i#1 s#4 ] // zpby1_gt_0_then_la1 +//SEG13 [4] if((byte) i#1>(byte) 0) goto @1 [ i#1 s#4 ] -- zpby1_gt_0_then_la1 lda 2 bne B1_from_B3 +//SEG14 @END BEND: +//SEG15 @2 B2: - // [5] (byte) s#1 ← (byte) s#2 + (byte) i#2 [ i#2 s#1 ] // zpby1=zpby1_plus_zpby2 +//SEG16 [5] (byte) s#1 ← (byte) s#2 + (byte) i#2 [ i#2 s#1 ] -- zpby1=zpby1_plus_zpby2 lda 3 clc adc 2 sta 3 +//SEG17 [2] phi from @2 to @3 B3_from_B2: - // (byte) s#4 = (byte) s#1 // register copy zp byte:3 +//SEG18 [2] phi (byte) s#4 = (byte) s#1 -- register_copy jmp B3 Removing instruction jmp B1 Succesful ASM optimization Pass5NextJumpElimination ASSEMBLER +//SEG0 @BEGIN BBEGIN: +//SEG1 [0] phi from @BEGIN to @1 B1_from_BBEGIN: - // (byte) s#2 = (byte) 0 // zpby1=coby1 +//SEG2 [0] phi (byte) s#2 = (byte) 0 -- zpby1=coby1 lda #0 sta 3 - // (byte) i#2 = (byte) 10 // zpby1=coby1 +//SEG3 [0] phi (byte) i#2 = (byte) 10 -- zpby1=coby1 lda #10 sta 2 +//SEG4 [0] phi from @3 to @1 B1_from_B3: - // (byte) s#2 = (byte) s#4 // register copy zp byte:3 - // (byte) i#2 = (byte) i#1 // register copy zp byte:2 +//SEG5 [0] phi (byte) s#2 = (byte) s#4 -- register_copy +//SEG6 [0] phi (byte) i#2 = (byte) i#1 -- register_copy +//SEG7 @1 B1: - // [1] if((byte) i#2>(byte) 5) goto @2 [ i#2 s#2 ] // zpby1_gt_coby1_then_la1 +//SEG8 [1] if((byte) i#2>(byte) 5) goto @2 [ i#2 s#2 ] -- zpby1_gt_coby1_then_la1 lda 2 cmp #5 beq !+ bcs B2 !: +//SEG9 [2] phi from @1 to @3 B3_from_B1: - // (byte) s#4 = (byte) s#2 // register copy zp byte:3 +//SEG10 [2] phi (byte) s#4 = (byte) s#2 -- register_copy +//SEG11 @3 B3: - // [3] (byte) i#1 ← -- (byte) i#2 [ i#1 s#4 ] // zpby1=_dec_zpby1 +//SEG12 [3] (byte) i#1 ← -- (byte) i#2 [ i#1 s#4 ] -- zpby1=_dec_zpby1 dec 2 - // [4] if((byte) i#1>(byte) 0) goto @1 [ i#1 s#4 ] // zpby1_gt_0_then_la1 +//SEG13 [4] if((byte) i#1>(byte) 0) goto @1 [ i#1 s#4 ] -- zpby1_gt_0_then_la1 lda 2 bne B1_from_B3 +//SEG14 @END BEND: +//SEG15 @2 B2: - // [5] (byte) s#1 ← (byte) s#2 + (byte) i#2 [ i#2 s#1 ] // zpby1=zpby1_plus_zpby2 +//SEG16 [5] (byte) s#1 ← (byte) s#2 + (byte) i#2 [ i#2 s#1 ] -- zpby1=zpby1_plus_zpby2 lda 3 clc adc 2 sta 3 +//SEG17 [2] phi from @2 to @3 B3_from_B2: - // (byte) s#4 = (byte) s#1 // register copy zp byte:3 +//SEG18 [2] phi (byte) s#4 = (byte) s#1 -- register_copy jmp B3 FINAL SYMBOL TABLE @@ -542,40 +569,49 @@ zp byte:2 [ i#2 i#1 ] zp byte:3 [ s#2 s#4 s#1 ] FINAL CODE +//SEG0 @BEGIN BBEGIN: +//SEG1 [0] phi from @BEGIN to @1 B1_from_BBEGIN: - // (byte) s#2 = (byte) 0 // zpby1=coby1 +//SEG2 [0] phi (byte) s#2 = (byte) 0 -- zpby1=coby1 lda #0 sta 3 - // (byte) i#2 = (byte) 10 // zpby1=coby1 +//SEG3 [0] phi (byte) i#2 = (byte) 10 -- zpby1=coby1 lda #10 sta 2 +//SEG4 [0] phi from @3 to @1 B1_from_B3: - // (byte) s#2 = (byte) s#4 // register copy zp byte:3 - // (byte) i#2 = (byte) i#1 // register copy zp byte:2 +//SEG5 [0] phi (byte) s#2 = (byte) s#4 -- register_copy +//SEG6 [0] phi (byte) i#2 = (byte) i#1 -- register_copy +//SEG7 @1 B1: - // [1] if((byte) i#2>(byte) 5) goto @2 [ i#2 s#2 ] // zpby1_gt_coby1_then_la1 +//SEG8 [1] if((byte) i#2>(byte) 5) goto @2 [ i#2 s#2 ] -- zpby1_gt_coby1_then_la1 lda 2 cmp #5 beq !+ bcs B2 !: +//SEG9 [2] phi from @1 to @3 B3_from_B1: - // (byte) s#4 = (byte) s#2 // register copy zp byte:3 +//SEG10 [2] phi (byte) s#4 = (byte) s#2 -- register_copy +//SEG11 @3 B3: - // [3] (byte) i#1 ← -- (byte) i#2 [ i#1 s#4 ] // zpby1=_dec_zpby1 +//SEG12 [3] (byte) i#1 ← -- (byte) i#2 [ i#1 s#4 ] -- zpby1=_dec_zpby1 dec 2 - // [4] if((byte) i#1>(byte) 0) goto @1 [ i#1 s#4 ] // zpby1_gt_0_then_la1 +//SEG13 [4] if((byte) i#1>(byte) 0) goto @1 [ i#1 s#4 ] -- zpby1_gt_0_then_la1 lda 2 bne B1_from_B3 +//SEG14 @END BEND: +//SEG15 @2 B2: - // [5] (byte) s#1 ← (byte) s#2 + (byte) i#2 [ i#2 s#1 ] // zpby1=zpby1_plus_zpby2 +//SEG16 [5] (byte) s#1 ← (byte) s#2 + (byte) i#2 [ i#2 s#1 ] -- zpby1=zpby1_plus_zpby2 lda 3 clc adc 2 sta 3 +//SEG17 [2] phi from @2 to @3 B3_from_B2: - // (byte) s#4 = (byte) s#1 // register copy zp byte:3 +//SEG18 [2] phi (byte) s#4 = (byte) s#1 -- register_copy jmp B3 diff --git a/src/main/java/dk/camelot64/kickc/test/ref/loopnest.log b/src/main/java/dk/camelot64/kickc/test/ref/loopnest.log index bf0abe07d..93814c187 100644 --- a/src/main/java/dk/camelot64/kickc/test/ref/loopnest.log +++ b/src/main/java/dk/camelot64/kickc/test/ref/loopnest.log @@ -753,51 +753,68 @@ zp byte:2 [ main::i#2 main::i#1 ] zp byte:3 [ nest::j#2 nest::j#1 ] INITIAL ASM +//SEG0 @BEGIN BBEGIN: +//SEG1 [0] call main param-assignment [ ] jsr main jmp BEND +//SEG2 @END BEND: +//SEG3 main main: +//SEG4 [1] phi from main to main::@1 main__B1_from_main: - // (byte) main::i#2 = (byte) 100 // zpby1=coby1 +//SEG5 [1] phi (byte) main::i#2 = (byte) 100 -- zpby1=coby1 lda #100 sta 2 jmp main__B1 +//SEG6 [1] phi from main::@3 to main::@1 main__B1_from_B3: - // (byte) main::i#2 = (byte) main::i#1 // register copy zp byte:2 +//SEG7 [1] phi (byte) main::i#2 = (byte) main::i#1 -- register_copy jmp main__B1 +//SEG8 main::@1 main__B1: +//SEG9 [2] call nest param-assignment [ main::i#2 ] jsr nest jmp main__B3 +//SEG10 main::@3 main__B3: - // [3] (byte) main::i#1 ← -- (byte) main::i#2 [ main::i#1 ] // zpby1=_dec_zpby1 +//SEG11 [3] (byte) main::i#1 ← -- (byte) main::i#2 [ main::i#1 ] -- zpby1=_dec_zpby1 dec 2 - // [4] if((byte) main::i#1>(byte) 0) goto main::@1 [ main::i#1 ] // zpby1_gt_0_then_la1 +//SEG12 [4] if((byte) main::i#1>(byte) 0) goto main::@1 [ main::i#1 ] -- zpby1_gt_0_then_la1 lda 2 bne main__B1_from_B3 jmp main__Breturn +//SEG13 main::@return main__Breturn: +//SEG14 [5] return [ ] rts +//SEG15 nest nest: +//SEG16 [6] phi from nest to nest::@1 nest__B1_from_nest: - // (byte) nest::j#2 = (byte) 100 // zpby1=coby1 +//SEG17 [6] phi (byte) nest::j#2 = (byte) 100 -- zpby1=coby1 lda #100 sta 3 jmp nest__B1 +//SEG18 [6] phi from nest::@1 to nest::@1 nest__B1_from_B1: - // (byte) nest::j#2 = (byte) nest::j#1 // register copy zp byte:3 +//SEG19 [6] phi (byte) nest::j#2 = (byte) nest::j#1 -- register_copy jmp nest__B1 +//SEG20 nest::@1 nest__B1: - // [7] *((word) 1024) ← (byte) nest::j#2 [ main::i#2 nest::j#2 ] // _star_cowo1=zpby1 +//SEG21 [7] *((word) 1024) ← (byte) nest::j#2 [ main::i#2 nest::j#2 ] -- _star_cowo1=zpby1 lda 3 sta 1024 - // [8] (byte) nest::j#1 ← -- (byte) nest::j#2 [ main::i#2 nest::j#1 ] // zpby1=_dec_zpby1 +//SEG22 [8] (byte) nest::j#1 ← -- (byte) nest::j#2 [ main::i#2 nest::j#1 ] -- zpby1=_dec_zpby1 dec 3 - // [9] if((byte) nest::j#1>(byte) 0) goto nest::@1 [ main::i#2 nest::j#1 ] // zpby1_gt_0_then_la1 +//SEG23 [9] if((byte) nest::j#1>(byte) 0) goto nest::@1 [ main::i#2 nest::j#1 ] -- zpby1_gt_0_then_la1 lda 3 bne nest__B1_from_B1 jmp nest__Breturn +//SEG24 nest::@return nest__Breturn: +//SEG25 [10] return [ main::i#2 ] rts Removing instruction jmp BEND @@ -808,88 +825,122 @@ Removing instruction jmp nest__B1 Removing instruction jmp nest__Breturn Succesful ASM optimization Pass5NextJumpElimination ASSEMBLER +//SEG0 @BEGIN BBEGIN: +//SEG1 [0] call main param-assignment [ ] jsr main +//SEG2 @END BEND: +//SEG3 main main: +//SEG4 [1] phi from main to main::@1 main__B1_from_main: - // (byte) main::i#2 = (byte) 100 // zpby1=coby1 +//SEG5 [1] phi (byte) main::i#2 = (byte) 100 -- zpby1=coby1 lda #100 sta 2 jmp main__B1 +//SEG6 [1] phi from main::@3 to main::@1 main__B1_from_B3: - // (byte) main::i#2 = (byte) main::i#1 // register copy zp byte:2 +//SEG7 [1] phi (byte) main::i#2 = (byte) main::i#1 -- register_copy +//SEG8 main::@1 main__B1: +//SEG9 [2] call nest param-assignment [ main::i#2 ] jsr nest +//SEG10 main::@3 main__B3: - // [3] (byte) main::i#1 ← -- (byte) main::i#2 [ main::i#1 ] // zpby1=_dec_zpby1 +//SEG11 [3] (byte) main::i#1 ← -- (byte) main::i#2 [ main::i#1 ] -- zpby1=_dec_zpby1 dec 2 - // [4] if((byte) main::i#1>(byte) 0) goto main::@1 [ main::i#1 ] // zpby1_gt_0_then_la1 +//SEG12 [4] if((byte) main::i#1>(byte) 0) goto main::@1 [ main::i#1 ] -- zpby1_gt_0_then_la1 lda 2 bne main__B1_from_B3 +//SEG13 main::@return main__Breturn: +//SEG14 [5] return [ ] rts +//SEG15 nest nest: +//SEG16 [6] phi from nest to nest::@1 nest__B1_from_nest: - // (byte) nest::j#2 = (byte) 100 // zpby1=coby1 +//SEG17 [6] phi (byte) nest::j#2 = (byte) 100 -- zpby1=coby1 lda #100 sta 3 jmp nest__B1 +//SEG18 [6] phi from nest::@1 to nest::@1 nest__B1_from_B1: - // (byte) nest::j#2 = (byte) nest::j#1 // register copy zp byte:3 +//SEG19 [6] phi (byte) nest::j#2 = (byte) nest::j#1 -- register_copy +//SEG20 nest::@1 nest__B1: - // [7] *((word) 1024) ← (byte) nest::j#2 [ main::i#2 nest::j#2 ] // _star_cowo1=zpby1 +//SEG21 [7] *((word) 1024) ← (byte) nest::j#2 [ main::i#2 nest::j#2 ] -- _star_cowo1=zpby1 lda 3 sta 1024 - // [8] (byte) nest::j#1 ← -- (byte) nest::j#2 [ main::i#2 nest::j#1 ] // zpby1=_dec_zpby1 +//SEG22 [8] (byte) nest::j#1 ← -- (byte) nest::j#2 [ main::i#2 nest::j#1 ] -- zpby1=_dec_zpby1 dec 3 - // [9] if((byte) nest::j#1>(byte) 0) goto nest::@1 [ main::i#2 nest::j#1 ] // zpby1_gt_0_then_la1 +//SEG23 [9] if((byte) nest::j#1>(byte) 0) goto nest::@1 [ main::i#2 nest::j#1 ] -- zpby1_gt_0_then_la1 lda 3 bne nest__B1_from_B1 +//SEG24 nest::@return nest__Breturn: +//SEG25 [10] return [ main::i#2 ] rts Removing instruction jmp main__B1 Removing instruction jmp nest__B1 Succesful ASM optimization Pass5NextJumpElimination ASSEMBLER +//SEG0 @BEGIN BBEGIN: +//SEG1 [0] call main param-assignment [ ] jsr main +//SEG2 @END BEND: +//SEG3 main main: +//SEG4 [1] phi from main to main::@1 main__B1_from_main: - // (byte) main::i#2 = (byte) 100 // zpby1=coby1 +//SEG5 [1] phi (byte) main::i#2 = (byte) 100 -- zpby1=coby1 lda #100 sta 2 +//SEG6 [1] phi from main::@3 to main::@1 main__B1_from_B3: - // (byte) main::i#2 = (byte) main::i#1 // register copy zp byte:2 +//SEG7 [1] phi (byte) main::i#2 = (byte) main::i#1 -- register_copy +//SEG8 main::@1 main__B1: +//SEG9 [2] call nest param-assignment [ main::i#2 ] jsr nest +//SEG10 main::@3 main__B3: - // [3] (byte) main::i#1 ← -- (byte) main::i#2 [ main::i#1 ] // zpby1=_dec_zpby1 +//SEG11 [3] (byte) main::i#1 ← -- (byte) main::i#2 [ main::i#1 ] -- zpby1=_dec_zpby1 dec 2 - // [4] if((byte) main::i#1>(byte) 0) goto main::@1 [ main::i#1 ] // zpby1_gt_0_then_la1 +//SEG12 [4] if((byte) main::i#1>(byte) 0) goto main::@1 [ main::i#1 ] -- zpby1_gt_0_then_la1 lda 2 bne main__B1_from_B3 +//SEG13 main::@return main__Breturn: +//SEG14 [5] return [ ] rts +//SEG15 nest nest: +//SEG16 [6] phi from nest to nest::@1 nest__B1_from_nest: - // (byte) nest::j#2 = (byte) 100 // zpby1=coby1 +//SEG17 [6] phi (byte) nest::j#2 = (byte) 100 -- zpby1=coby1 lda #100 sta 3 +//SEG18 [6] phi from nest::@1 to nest::@1 nest__B1_from_B1: - // (byte) nest::j#2 = (byte) nest::j#1 // register copy zp byte:3 +//SEG19 [6] phi (byte) nest::j#2 = (byte) nest::j#1 -- register_copy +//SEG20 nest::@1 nest__B1: - // [7] *((word) 1024) ← (byte) nest::j#2 [ main::i#2 nest::j#2 ] // _star_cowo1=zpby1 +//SEG21 [7] *((word) 1024) ← (byte) nest::j#2 [ main::i#2 nest::j#2 ] -- _star_cowo1=zpby1 lda 3 sta 1024 - // [8] (byte) nest::j#1 ← -- (byte) nest::j#2 [ main::i#2 nest::j#1 ] // zpby1=_dec_zpby1 +//SEG22 [8] (byte) nest::j#1 ← -- (byte) nest::j#2 [ main::i#2 nest::j#1 ] -- zpby1=_dec_zpby1 dec 3 - // [9] if((byte) nest::j#1>(byte) 0) goto nest::@1 [ main::i#2 nest::j#1 ] // zpby1_gt_0_then_la1 +//SEG23 [9] if((byte) nest::j#1>(byte) 0) goto nest::@1 [ main::i#2 nest::j#1 ] -- zpby1_gt_0_then_la1 lda 3 bne nest__B1_from_B1 +//SEG24 nest::@return nest__Breturn: +//SEG25 [10] return [ main::i#2 ] rts FINAL SYMBOL TABLE @@ -914,42 +965,59 @@ zp byte:2 [ main::i#2 main::i#1 ] zp byte:3 [ nest::j#2 nest::j#1 ] FINAL CODE +//SEG0 @BEGIN BBEGIN: +//SEG1 [0] call main param-assignment [ ] jsr main +//SEG2 @END BEND: +//SEG3 main main: +//SEG4 [1] phi from main to main::@1 main__B1_from_main: - // (byte) main::i#2 = (byte) 100 // zpby1=coby1 +//SEG5 [1] phi (byte) main::i#2 = (byte) 100 -- zpby1=coby1 lda #100 sta 2 +//SEG6 [1] phi from main::@3 to main::@1 main__B1_from_B3: - // (byte) main::i#2 = (byte) main::i#1 // register copy zp byte:2 +//SEG7 [1] phi (byte) main::i#2 = (byte) main::i#1 -- register_copy +//SEG8 main::@1 main__B1: +//SEG9 [2] call nest param-assignment [ main::i#2 ] jsr nest +//SEG10 main::@3 main__B3: - // [3] (byte) main::i#1 ← -- (byte) main::i#2 [ main::i#1 ] // zpby1=_dec_zpby1 +//SEG11 [3] (byte) main::i#1 ← -- (byte) main::i#2 [ main::i#1 ] -- zpby1=_dec_zpby1 dec 2 - // [4] if((byte) main::i#1>(byte) 0) goto main::@1 [ main::i#1 ] // zpby1_gt_0_then_la1 +//SEG12 [4] if((byte) main::i#1>(byte) 0) goto main::@1 [ main::i#1 ] -- zpby1_gt_0_then_la1 lda 2 bne main__B1_from_B3 +//SEG13 main::@return main__Breturn: +//SEG14 [5] return [ ] rts +//SEG15 nest nest: +//SEG16 [6] phi from nest to nest::@1 nest__B1_from_nest: - // (byte) nest::j#2 = (byte) 100 // zpby1=coby1 +//SEG17 [6] phi (byte) nest::j#2 = (byte) 100 -- zpby1=coby1 lda #100 sta 3 +//SEG18 [6] phi from nest::@1 to nest::@1 nest__B1_from_B1: - // (byte) nest::j#2 = (byte) nest::j#1 // register copy zp byte:3 +//SEG19 [6] phi (byte) nest::j#2 = (byte) nest::j#1 -- register_copy +//SEG20 nest::@1 nest__B1: - // [7] *((word) 1024) ← (byte) nest::j#2 [ main::i#2 nest::j#2 ] // _star_cowo1=zpby1 +//SEG21 [7] *((word) 1024) ← (byte) nest::j#2 [ main::i#2 nest::j#2 ] -- _star_cowo1=zpby1 lda 3 sta 1024 - // [8] (byte) nest::j#1 ← -- (byte) nest::j#2 [ main::i#2 nest::j#1 ] // zpby1=_dec_zpby1 +//SEG22 [8] (byte) nest::j#1 ← -- (byte) nest::j#2 [ main::i#2 nest::j#1 ] -- zpby1=_dec_zpby1 dec 3 - // [9] if((byte) nest::j#1>(byte) 0) goto nest::@1 [ main::i#2 nest::j#1 ] // zpby1_gt_0_then_la1 +//SEG23 [9] if((byte) nest::j#1>(byte) 0) goto nest::@1 [ main::i#2 nest::j#1 ] -- zpby1_gt_0_then_la1 lda 3 bne nest__B1_from_B1 +//SEG24 nest::@return nest__Breturn: +//SEG25 [10] return [ main::i#2 ] rts diff --git a/src/main/java/dk/camelot64/kickc/test/ref/loopnest2.log b/src/main/java/dk/camelot64/kickc/test/ref/loopnest2.log index 7f3df11d5..f1e27a593 100644 --- a/src/main/java/dk/camelot64/kickc/test/ref/loopnest2.log +++ b/src/main/java/dk/camelot64/kickc/test/ref/loopnest2.log @@ -1881,120 +1881,157 @@ zp byte:6 [ nest2::i#2 nest2::i#1 ] zp byte:7 [ nest2::j#2 nest2::j#1 ] INITIAL ASM +//SEG0 @BEGIN BBEGIN: +//SEG1 [0] call main param-assignment [ ] jsr main jmp BEND +//SEG2 @END BEND: +//SEG3 main main: +//SEG4 [1] phi from main to main::@1 main__B1_from_main: - // (byte) main::i#2 = (byte) 100 // zpby1=coby1 +//SEG5 [1] phi (byte) main::i#2 = (byte) 100 -- zpby1=coby1 lda #100 sta 2 jmp main__B1 +//SEG6 [1] phi from main::@3 to main::@1 main__B1_from_B3: - // (byte) main::i#2 = (byte) main::i#1 // register copy zp byte:2 +//SEG7 [1] phi (byte) main::i#2 = (byte) main::i#1 -- register_copy jmp main__B1 +//SEG8 main::@1 main__B1: +//SEG9 [2] phi from main::@1 to main::@2 main__B2_from_B1: - // (byte) main::j#2 = (byte) 100 // zpby1=coby1 +//SEG10 [2] phi (byte) main::j#2 = (byte) 100 -- zpby1=coby1 lda #100 sta 3 jmp main__B2 +//SEG11 [2] phi from main::@5 to main::@2 main__B2_from_B5: - // (byte) main::j#2 = (byte) main::j#1 // register copy zp byte:3 +//SEG12 [2] phi (byte) main::j#2 = (byte) main::j#1 -- register_copy jmp main__B2 +//SEG13 main::@2 main__B2: +//SEG14 [3] call nest1 param-assignment [ main::j#2 main::i#2 ] jsr nest1 jmp main__B5 +//SEG15 main::@5 main__B5: - // [4] (byte) main::j#1 ← -- (byte) main::j#2 [ main::j#1 main::i#2 ] // zpby1=_dec_zpby1 +//SEG16 [4] (byte) main::j#1 ← -- (byte) main::j#2 [ main::j#1 main::i#2 ] -- zpby1=_dec_zpby1 dec 3 - // [5] if((byte) main::j#1>(byte) 0) goto main::@2 [ main::j#1 main::i#2 ] // zpby1_gt_0_then_la1 +//SEG17 [5] if((byte) main::j#1>(byte) 0) goto main::@2 [ main::j#1 main::i#2 ] -- zpby1_gt_0_then_la1 lda 3 bne main__B2_from_B5 jmp main__B3 +//SEG18 main::@3 main__B3: - // [6] (byte) main::i#1 ← -- (byte) main::i#2 [ main::i#1 ] // zpby1=_dec_zpby1 +//SEG19 [6] (byte) main::i#1 ← -- (byte) main::i#2 [ main::i#1 ] -- zpby1=_dec_zpby1 dec 2 - // [7] if((byte) main::i#1>(byte) 0) goto main::@1 [ main::i#1 ] // zpby1_gt_0_then_la1 +//SEG20 [7] if((byte) main::i#1>(byte) 0) goto main::@1 [ main::i#1 ] -- zpby1_gt_0_then_la1 lda 2 bne main__B1_from_B3 jmp main__Breturn +//SEG21 main::@return main__Breturn: +//SEG22 [8] return [ ] rts +//SEG23 nest1 nest1: +//SEG24 [9] phi from nest1 to nest1::@1 nest1__B1_from_nest1: - // (byte) nest1::i#2 = (byte) 100 // zpby1=coby1 +//SEG25 [9] phi (byte) nest1::i#2 = (byte) 100 -- zpby1=coby1 lda #100 sta 4 jmp nest1__B1 +//SEG26 [9] phi from nest1::@3 to nest1::@1 nest1__B1_from_B3: - // (byte) nest1::i#2 = (byte) nest1::i#1 // register copy zp byte:4 +//SEG27 [9] phi (byte) nest1::i#2 = (byte) nest1::i#1 -- register_copy jmp nest1__B1 +//SEG28 nest1::@1 nest1__B1: +//SEG29 [10] phi from nest1::@1 to nest1::@2 nest1__B2_from_B1: - // (byte) nest1::j#2 = (byte) 100 // zpby1=coby1 +//SEG30 [10] phi (byte) nest1::j#2 = (byte) 100 -- zpby1=coby1 lda #100 sta 5 jmp nest1__B2 +//SEG31 [10] phi from nest1::@5 to nest1::@2 nest1__B2_from_B5: - // (byte) nest1::j#2 = (byte) nest1::j#1 // register copy zp byte:5 +//SEG32 [10] phi (byte) nest1::j#2 = (byte) nest1::j#1 -- register_copy jmp nest1__B2 +//SEG33 nest1::@2 nest1__B2: +//SEG34 [11] call nest2 param-assignment [ main::j#2 main::i#2 nest1::j#2 nest1::i#2 ] jsr nest2 jmp nest1__B5 +//SEG35 nest1::@5 nest1__B5: - // [12] (byte) nest1::j#1 ← -- (byte) nest1::j#2 [ main::j#2 main::i#2 nest1::j#1 nest1::i#2 ] // zpby1=_dec_zpby1 +//SEG36 [12] (byte) nest1::j#1 ← -- (byte) nest1::j#2 [ main::j#2 main::i#2 nest1::j#1 nest1::i#2 ] -- zpby1=_dec_zpby1 dec 5 - // [13] if((byte) nest1::j#1>(byte) 0) goto nest1::@2 [ main::j#2 main::i#2 nest1::j#1 nest1::i#2 ] // zpby1_gt_0_then_la1 +//SEG37 [13] if((byte) nest1::j#1>(byte) 0) goto nest1::@2 [ main::j#2 main::i#2 nest1::j#1 nest1::i#2 ] -- zpby1_gt_0_then_la1 lda 5 bne nest1__B2_from_B5 jmp nest1__B3 +//SEG38 nest1::@3 nest1__B3: - // [14] (byte) nest1::i#1 ← -- (byte) nest1::i#2 [ main::j#2 main::i#2 nest1::i#1 ] // zpby1=_dec_zpby1 +//SEG39 [14] (byte) nest1::i#1 ← -- (byte) nest1::i#2 [ main::j#2 main::i#2 nest1::i#1 ] -- zpby1=_dec_zpby1 dec 4 - // [15] if((byte) nest1::i#1>(byte) 0) goto nest1::@1 [ main::j#2 main::i#2 nest1::i#1 ] // zpby1_gt_0_then_la1 +//SEG40 [15] if((byte) nest1::i#1>(byte) 0) goto nest1::@1 [ main::j#2 main::i#2 nest1::i#1 ] -- zpby1_gt_0_then_la1 lda 4 bne nest1__B1_from_B3 jmp nest1__Breturn +//SEG41 nest1::@return nest1__Breturn: +//SEG42 [16] return [ main::j#2 main::i#2 ] rts +//SEG43 nest2 nest2: +//SEG44 [17] phi from nest2 to nest2::@1 nest2__B1_from_nest2: - // (byte) nest2::i#2 = (byte) 100 // zpby1=coby1 +//SEG45 [17] phi (byte) nest2::i#2 = (byte) 100 -- zpby1=coby1 lda #100 sta 6 jmp nest2__B1 +//SEG46 [17] phi from nest2::@3 to nest2::@1 nest2__B1_from_B3: - // (byte) nest2::i#2 = (byte) nest2::i#1 // register copy zp byte:6 +//SEG47 [17] phi (byte) nest2::i#2 = (byte) nest2::i#1 -- register_copy jmp nest2__B1 +//SEG48 nest2::@1 nest2__B1: +//SEG49 [18] phi from nest2::@1 to nest2::@2 nest2__B2_from_B1: - // (byte) nest2::j#2 = (byte) 100 // zpby1=coby1 +//SEG50 [18] phi (byte) nest2::j#2 = (byte) 100 -- zpby1=coby1 lda #100 sta 7 jmp nest2__B2 +//SEG51 [18] phi from nest2::@2 to nest2::@2 nest2__B2_from_B2: - // (byte) nest2::j#2 = (byte) nest2::j#1 // register copy zp byte:7 +//SEG52 [18] phi (byte) nest2::j#2 = (byte) nest2::j#1 -- register_copy jmp nest2__B2 +//SEG53 nest2::@2 nest2__B2: - // [19] *((word) 1024) ← (byte) nest2::j#2 [ main::j#2 main::i#2 nest1::j#2 nest1::i#2 nest2::j#2 nest2::i#2 ] // _star_cowo1=zpby1 +//SEG54 [19] *((word) 1024) ← (byte) nest2::j#2 [ main::j#2 main::i#2 nest1::j#2 nest1::i#2 nest2::j#2 nest2::i#2 ] -- _star_cowo1=zpby1 lda 7 sta 1024 - // [20] (byte) nest2::j#1 ← -- (byte) nest2::j#2 [ main::j#2 main::i#2 nest1::j#2 nest1::i#2 nest2::j#1 nest2::i#2 ] // zpby1=_dec_zpby1 +//SEG55 [20] (byte) nest2::j#1 ← -- (byte) nest2::j#2 [ main::j#2 main::i#2 nest1::j#2 nest1::i#2 nest2::j#1 nest2::i#2 ] -- zpby1=_dec_zpby1 dec 7 - // [21] if((byte) nest2::j#1>(byte) 0) goto nest2::@2 [ main::j#2 main::i#2 nest1::j#2 nest1::i#2 nest2::j#1 nest2::i#2 ] // zpby1_gt_0_then_la1 +//SEG56 [21] if((byte) nest2::j#1>(byte) 0) goto nest2::@2 [ main::j#2 main::i#2 nest1::j#2 nest1::i#2 nest2::j#1 nest2::i#2 ] -- zpby1_gt_0_then_la1 lda 7 bne nest2__B2_from_B2 jmp nest2__B3 +//SEG57 nest2::@3 nest2__B3: - // [22] (byte) nest2::i#1 ← -- (byte) nest2::i#2 [ main::j#2 main::i#2 nest1::j#2 nest1::i#2 nest2::i#1 ] // zpby1=_dec_zpby1 +//SEG58 [22] (byte) nest2::i#1 ← -- (byte) nest2::i#2 [ main::j#2 main::i#2 nest1::j#2 nest1::i#2 nest2::i#1 ] -- zpby1=_dec_zpby1 dec 6 - // [23] if((byte) nest2::i#1>(byte) 0) goto nest2::@1 [ main::j#2 main::i#2 nest1::j#2 nest1::i#2 nest2::i#1 ] // zpby1_gt_0_then_la1 +//SEG59 [23] if((byte) nest2::i#1>(byte) 0) goto nest2::@1 [ main::j#2 main::i#2 nest1::j#2 nest1::i#2 nest2::i#1 ] -- zpby1_gt_0_then_la1 lda 6 bne nest2__B1_from_B3 jmp nest2__Breturn +//SEG60 nest2::@return nest2__Breturn: +//SEG61 [24] return [ main::j#2 main::i#2 nest1::j#2 nest1::i#2 ] rts Removing instruction jmp BEND @@ -2014,105 +2051,142 @@ Removing instruction jmp nest2__B3 Removing instruction jmp nest2__Breturn Succesful ASM optimization Pass5NextJumpElimination ASSEMBLER +//SEG0 @BEGIN BBEGIN: +//SEG1 [0] call main param-assignment [ ] jsr main +//SEG2 @END BEND: +//SEG3 main main: +//SEG4 [1] phi from main to main::@1 main__B1_from_main: - // (byte) main::i#2 = (byte) 100 // zpby1=coby1 +//SEG5 [1] phi (byte) main::i#2 = (byte) 100 -- zpby1=coby1 lda #100 sta 2 jmp main__B1 +//SEG6 [1] phi from main::@3 to main::@1 main__B1_from_B3: - // (byte) main::i#2 = (byte) main::i#1 // register copy zp byte:2 +//SEG7 [1] phi (byte) main::i#2 = (byte) main::i#1 -- register_copy +//SEG8 main::@1 main__B1: +//SEG9 [2] phi from main::@1 to main::@2 main__B2_from_B1: - // (byte) main::j#2 = (byte) 100 // zpby1=coby1 +//SEG10 [2] phi (byte) main::j#2 = (byte) 100 -- zpby1=coby1 lda #100 sta 3 jmp main__B2 +//SEG11 [2] phi from main::@5 to main::@2 main__B2_from_B5: - // (byte) main::j#2 = (byte) main::j#1 // register copy zp byte:3 +//SEG12 [2] phi (byte) main::j#2 = (byte) main::j#1 -- register_copy +//SEG13 main::@2 main__B2: +//SEG14 [3] call nest1 param-assignment [ main::j#2 main::i#2 ] jsr nest1 +//SEG15 main::@5 main__B5: - // [4] (byte) main::j#1 ← -- (byte) main::j#2 [ main::j#1 main::i#2 ] // zpby1=_dec_zpby1 +//SEG16 [4] (byte) main::j#1 ← -- (byte) main::j#2 [ main::j#1 main::i#2 ] -- zpby1=_dec_zpby1 dec 3 - // [5] if((byte) main::j#1>(byte) 0) goto main::@2 [ main::j#1 main::i#2 ] // zpby1_gt_0_then_la1 +//SEG17 [5] if((byte) main::j#1>(byte) 0) goto main::@2 [ main::j#1 main::i#2 ] -- zpby1_gt_0_then_la1 lda 3 bne main__B2_from_B5 +//SEG18 main::@3 main__B3: - // [6] (byte) main::i#1 ← -- (byte) main::i#2 [ main::i#1 ] // zpby1=_dec_zpby1 +//SEG19 [6] (byte) main::i#1 ← -- (byte) main::i#2 [ main::i#1 ] -- zpby1=_dec_zpby1 dec 2 - // [7] if((byte) main::i#1>(byte) 0) goto main::@1 [ main::i#1 ] // zpby1_gt_0_then_la1 +//SEG20 [7] if((byte) main::i#1>(byte) 0) goto main::@1 [ main::i#1 ] -- zpby1_gt_0_then_la1 lda 2 bne main__B1_from_B3 +//SEG21 main::@return main__Breturn: +//SEG22 [8] return [ ] rts +//SEG23 nest1 nest1: +//SEG24 [9] phi from nest1 to nest1::@1 nest1__B1_from_nest1: - // (byte) nest1::i#2 = (byte) 100 // zpby1=coby1 +//SEG25 [9] phi (byte) nest1::i#2 = (byte) 100 -- zpby1=coby1 lda #100 sta 4 jmp nest1__B1 +//SEG26 [9] phi from nest1::@3 to nest1::@1 nest1__B1_from_B3: - // (byte) nest1::i#2 = (byte) nest1::i#1 // register copy zp byte:4 +//SEG27 [9] phi (byte) nest1::i#2 = (byte) nest1::i#1 -- register_copy +//SEG28 nest1::@1 nest1__B1: +//SEG29 [10] phi from nest1::@1 to nest1::@2 nest1__B2_from_B1: - // (byte) nest1::j#2 = (byte) 100 // zpby1=coby1 +//SEG30 [10] phi (byte) nest1::j#2 = (byte) 100 -- zpby1=coby1 lda #100 sta 5 jmp nest1__B2 +//SEG31 [10] phi from nest1::@5 to nest1::@2 nest1__B2_from_B5: - // (byte) nest1::j#2 = (byte) nest1::j#1 // register copy zp byte:5 +//SEG32 [10] phi (byte) nest1::j#2 = (byte) nest1::j#1 -- register_copy +//SEG33 nest1::@2 nest1__B2: +//SEG34 [11] call nest2 param-assignment [ main::j#2 main::i#2 nest1::j#2 nest1::i#2 ] jsr nest2 +//SEG35 nest1::@5 nest1__B5: - // [12] (byte) nest1::j#1 ← -- (byte) nest1::j#2 [ main::j#2 main::i#2 nest1::j#1 nest1::i#2 ] // zpby1=_dec_zpby1 +//SEG36 [12] (byte) nest1::j#1 ← -- (byte) nest1::j#2 [ main::j#2 main::i#2 nest1::j#1 nest1::i#2 ] -- zpby1=_dec_zpby1 dec 5 - // [13] if((byte) nest1::j#1>(byte) 0) goto nest1::@2 [ main::j#2 main::i#2 nest1::j#1 nest1::i#2 ] // zpby1_gt_0_then_la1 +//SEG37 [13] if((byte) nest1::j#1>(byte) 0) goto nest1::@2 [ main::j#2 main::i#2 nest1::j#1 nest1::i#2 ] -- zpby1_gt_0_then_la1 lda 5 bne nest1__B2_from_B5 +//SEG38 nest1::@3 nest1__B3: - // [14] (byte) nest1::i#1 ← -- (byte) nest1::i#2 [ main::j#2 main::i#2 nest1::i#1 ] // zpby1=_dec_zpby1 +//SEG39 [14] (byte) nest1::i#1 ← -- (byte) nest1::i#2 [ main::j#2 main::i#2 nest1::i#1 ] -- zpby1=_dec_zpby1 dec 4 - // [15] if((byte) nest1::i#1>(byte) 0) goto nest1::@1 [ main::j#2 main::i#2 nest1::i#1 ] // zpby1_gt_0_then_la1 +//SEG40 [15] if((byte) nest1::i#1>(byte) 0) goto nest1::@1 [ main::j#2 main::i#2 nest1::i#1 ] -- zpby1_gt_0_then_la1 lda 4 bne nest1__B1_from_B3 +//SEG41 nest1::@return nest1__Breturn: +//SEG42 [16] return [ main::j#2 main::i#2 ] rts +//SEG43 nest2 nest2: +//SEG44 [17] phi from nest2 to nest2::@1 nest2__B1_from_nest2: - // (byte) nest2::i#2 = (byte) 100 // zpby1=coby1 +//SEG45 [17] phi (byte) nest2::i#2 = (byte) 100 -- zpby1=coby1 lda #100 sta 6 jmp nest2__B1 +//SEG46 [17] phi from nest2::@3 to nest2::@1 nest2__B1_from_B3: - // (byte) nest2::i#2 = (byte) nest2::i#1 // register copy zp byte:6 +//SEG47 [17] phi (byte) nest2::i#2 = (byte) nest2::i#1 -- register_copy +//SEG48 nest2::@1 nest2__B1: +//SEG49 [18] phi from nest2::@1 to nest2::@2 nest2__B2_from_B1: - // (byte) nest2::j#2 = (byte) 100 // zpby1=coby1 +//SEG50 [18] phi (byte) nest2::j#2 = (byte) 100 -- zpby1=coby1 lda #100 sta 7 jmp nest2__B2 +//SEG51 [18] phi from nest2::@2 to nest2::@2 nest2__B2_from_B2: - // (byte) nest2::j#2 = (byte) nest2::j#1 // register copy zp byte:7 +//SEG52 [18] phi (byte) nest2::j#2 = (byte) nest2::j#1 -- register_copy +//SEG53 nest2::@2 nest2__B2: - // [19] *((word) 1024) ← (byte) nest2::j#2 [ main::j#2 main::i#2 nest1::j#2 nest1::i#2 nest2::j#2 nest2::i#2 ] // _star_cowo1=zpby1 +//SEG54 [19] *((word) 1024) ← (byte) nest2::j#2 [ main::j#2 main::i#2 nest1::j#2 nest1::i#2 nest2::j#2 nest2::i#2 ] -- _star_cowo1=zpby1 lda 7 sta 1024 - // [20] (byte) nest2::j#1 ← -- (byte) nest2::j#2 [ main::j#2 main::i#2 nest1::j#2 nest1::i#2 nest2::j#1 nest2::i#2 ] // zpby1=_dec_zpby1 +//SEG55 [20] (byte) nest2::j#1 ← -- (byte) nest2::j#2 [ main::j#2 main::i#2 nest1::j#2 nest1::i#2 nest2::j#1 nest2::i#2 ] -- zpby1=_dec_zpby1 dec 7 - // [21] if((byte) nest2::j#1>(byte) 0) goto nest2::@2 [ main::j#2 main::i#2 nest1::j#2 nest1::i#2 nest2::j#1 nest2::i#2 ] // zpby1_gt_0_then_la1 +//SEG56 [21] if((byte) nest2::j#1>(byte) 0) goto nest2::@2 [ main::j#2 main::i#2 nest1::j#2 nest1::i#2 nest2::j#1 nest2::i#2 ] -- zpby1_gt_0_then_la1 lda 7 bne nest2__B2_from_B2 +//SEG57 nest2::@3 nest2__B3: - // [22] (byte) nest2::i#1 ← -- (byte) nest2::i#2 [ main::j#2 main::i#2 nest1::j#2 nest1::i#2 nest2::i#1 ] // zpby1=_dec_zpby1 +//SEG58 [22] (byte) nest2::i#1 ← -- (byte) nest2::i#2 [ main::j#2 main::i#2 nest1::j#2 nest1::i#2 nest2::i#1 ] -- zpby1=_dec_zpby1 dec 6 - // [23] if((byte) nest2::i#1>(byte) 0) goto nest2::@1 [ main::j#2 main::i#2 nest1::j#2 nest1::i#2 nest2::i#1 ] // zpby1_gt_0_then_la1 +//SEG59 [23] if((byte) nest2::i#1>(byte) 0) goto nest2::@1 [ main::j#2 main::i#2 nest1::j#2 nest1::i#2 nest2::i#1 ] -- zpby1_gt_0_then_la1 lda 6 bne nest2__B1_from_B3 +//SEG60 nest2::@return nest2__Breturn: +//SEG61 [24] return [ main::j#2 main::i#2 nest1::j#2 nest1::i#2 ] rts Removing instruction jmp main__B1 @@ -2123,99 +2197,136 @@ Removing instruction jmp nest2__B1 Removing instruction jmp nest2__B2 Succesful ASM optimization Pass5NextJumpElimination ASSEMBLER +//SEG0 @BEGIN BBEGIN: +//SEG1 [0] call main param-assignment [ ] jsr main +//SEG2 @END BEND: +//SEG3 main main: +//SEG4 [1] phi from main to main::@1 main__B1_from_main: - // (byte) main::i#2 = (byte) 100 // zpby1=coby1 +//SEG5 [1] phi (byte) main::i#2 = (byte) 100 -- zpby1=coby1 lda #100 sta 2 +//SEG6 [1] phi from main::@3 to main::@1 main__B1_from_B3: - // (byte) main::i#2 = (byte) main::i#1 // register copy zp byte:2 +//SEG7 [1] phi (byte) main::i#2 = (byte) main::i#1 -- register_copy +//SEG8 main::@1 main__B1: +//SEG9 [2] phi from main::@1 to main::@2 main__B2_from_B1: - // (byte) main::j#2 = (byte) 100 // zpby1=coby1 +//SEG10 [2] phi (byte) main::j#2 = (byte) 100 -- zpby1=coby1 lda #100 sta 3 +//SEG11 [2] phi from main::@5 to main::@2 main__B2_from_B5: - // (byte) main::j#2 = (byte) main::j#1 // register copy zp byte:3 +//SEG12 [2] phi (byte) main::j#2 = (byte) main::j#1 -- register_copy +//SEG13 main::@2 main__B2: +//SEG14 [3] call nest1 param-assignment [ main::j#2 main::i#2 ] jsr nest1 +//SEG15 main::@5 main__B5: - // [4] (byte) main::j#1 ← -- (byte) main::j#2 [ main::j#1 main::i#2 ] // zpby1=_dec_zpby1 +//SEG16 [4] (byte) main::j#1 ← -- (byte) main::j#2 [ main::j#1 main::i#2 ] -- zpby1=_dec_zpby1 dec 3 - // [5] if((byte) main::j#1>(byte) 0) goto main::@2 [ main::j#1 main::i#2 ] // zpby1_gt_0_then_la1 +//SEG17 [5] if((byte) main::j#1>(byte) 0) goto main::@2 [ main::j#1 main::i#2 ] -- zpby1_gt_0_then_la1 lda 3 bne main__B2_from_B5 +//SEG18 main::@3 main__B3: - // [6] (byte) main::i#1 ← -- (byte) main::i#2 [ main::i#1 ] // zpby1=_dec_zpby1 +//SEG19 [6] (byte) main::i#1 ← -- (byte) main::i#2 [ main::i#1 ] -- zpby1=_dec_zpby1 dec 2 - // [7] if((byte) main::i#1>(byte) 0) goto main::@1 [ main::i#1 ] // zpby1_gt_0_then_la1 +//SEG20 [7] if((byte) main::i#1>(byte) 0) goto main::@1 [ main::i#1 ] -- zpby1_gt_0_then_la1 lda 2 bne main__B1_from_B3 +//SEG21 main::@return main__Breturn: +//SEG22 [8] return [ ] rts +//SEG23 nest1 nest1: +//SEG24 [9] phi from nest1 to nest1::@1 nest1__B1_from_nest1: - // (byte) nest1::i#2 = (byte) 100 // zpby1=coby1 +//SEG25 [9] phi (byte) nest1::i#2 = (byte) 100 -- zpby1=coby1 lda #100 sta 4 +//SEG26 [9] phi from nest1::@3 to nest1::@1 nest1__B1_from_B3: - // (byte) nest1::i#2 = (byte) nest1::i#1 // register copy zp byte:4 +//SEG27 [9] phi (byte) nest1::i#2 = (byte) nest1::i#1 -- register_copy +//SEG28 nest1::@1 nest1__B1: +//SEG29 [10] phi from nest1::@1 to nest1::@2 nest1__B2_from_B1: - // (byte) nest1::j#2 = (byte) 100 // zpby1=coby1 +//SEG30 [10] phi (byte) nest1::j#2 = (byte) 100 -- zpby1=coby1 lda #100 sta 5 +//SEG31 [10] phi from nest1::@5 to nest1::@2 nest1__B2_from_B5: - // (byte) nest1::j#2 = (byte) nest1::j#1 // register copy zp byte:5 +//SEG32 [10] phi (byte) nest1::j#2 = (byte) nest1::j#1 -- register_copy +//SEG33 nest1::@2 nest1__B2: +//SEG34 [11] call nest2 param-assignment [ main::j#2 main::i#2 nest1::j#2 nest1::i#2 ] jsr nest2 +//SEG35 nest1::@5 nest1__B5: - // [12] (byte) nest1::j#1 ← -- (byte) nest1::j#2 [ main::j#2 main::i#2 nest1::j#1 nest1::i#2 ] // zpby1=_dec_zpby1 +//SEG36 [12] (byte) nest1::j#1 ← -- (byte) nest1::j#2 [ main::j#2 main::i#2 nest1::j#1 nest1::i#2 ] -- zpby1=_dec_zpby1 dec 5 - // [13] if((byte) nest1::j#1>(byte) 0) goto nest1::@2 [ main::j#2 main::i#2 nest1::j#1 nest1::i#2 ] // zpby1_gt_0_then_la1 +//SEG37 [13] if((byte) nest1::j#1>(byte) 0) goto nest1::@2 [ main::j#2 main::i#2 nest1::j#1 nest1::i#2 ] -- zpby1_gt_0_then_la1 lda 5 bne nest1__B2_from_B5 +//SEG38 nest1::@3 nest1__B3: - // [14] (byte) nest1::i#1 ← -- (byte) nest1::i#2 [ main::j#2 main::i#2 nest1::i#1 ] // zpby1=_dec_zpby1 +//SEG39 [14] (byte) nest1::i#1 ← -- (byte) nest1::i#2 [ main::j#2 main::i#2 nest1::i#1 ] -- zpby1=_dec_zpby1 dec 4 - // [15] if((byte) nest1::i#1>(byte) 0) goto nest1::@1 [ main::j#2 main::i#2 nest1::i#1 ] // zpby1_gt_0_then_la1 +//SEG40 [15] if((byte) nest1::i#1>(byte) 0) goto nest1::@1 [ main::j#2 main::i#2 nest1::i#1 ] -- zpby1_gt_0_then_la1 lda 4 bne nest1__B1_from_B3 +//SEG41 nest1::@return nest1__Breturn: +//SEG42 [16] return [ main::j#2 main::i#2 ] rts +//SEG43 nest2 nest2: +//SEG44 [17] phi from nest2 to nest2::@1 nest2__B1_from_nest2: - // (byte) nest2::i#2 = (byte) 100 // zpby1=coby1 +//SEG45 [17] phi (byte) nest2::i#2 = (byte) 100 -- zpby1=coby1 lda #100 sta 6 +//SEG46 [17] phi from nest2::@3 to nest2::@1 nest2__B1_from_B3: - // (byte) nest2::i#2 = (byte) nest2::i#1 // register copy zp byte:6 +//SEG47 [17] phi (byte) nest2::i#2 = (byte) nest2::i#1 -- register_copy +//SEG48 nest2::@1 nest2__B1: +//SEG49 [18] phi from nest2::@1 to nest2::@2 nest2__B2_from_B1: - // (byte) nest2::j#2 = (byte) 100 // zpby1=coby1 +//SEG50 [18] phi (byte) nest2::j#2 = (byte) 100 -- zpby1=coby1 lda #100 sta 7 +//SEG51 [18] phi from nest2::@2 to nest2::@2 nest2__B2_from_B2: - // (byte) nest2::j#2 = (byte) nest2::j#1 // register copy zp byte:7 +//SEG52 [18] phi (byte) nest2::j#2 = (byte) nest2::j#1 -- register_copy +//SEG53 nest2::@2 nest2__B2: - // [19] *((word) 1024) ← (byte) nest2::j#2 [ main::j#2 main::i#2 nest1::j#2 nest1::i#2 nest2::j#2 nest2::i#2 ] // _star_cowo1=zpby1 +//SEG54 [19] *((word) 1024) ← (byte) nest2::j#2 [ main::j#2 main::i#2 nest1::j#2 nest1::i#2 nest2::j#2 nest2::i#2 ] -- _star_cowo1=zpby1 lda 7 sta 1024 - // [20] (byte) nest2::j#1 ← -- (byte) nest2::j#2 [ main::j#2 main::i#2 nest1::j#2 nest1::i#2 nest2::j#1 nest2::i#2 ] // zpby1=_dec_zpby1 +//SEG55 [20] (byte) nest2::j#1 ← -- (byte) nest2::j#2 [ main::j#2 main::i#2 nest1::j#2 nest1::i#2 nest2::j#1 nest2::i#2 ] -- zpby1=_dec_zpby1 dec 7 - // [21] if((byte) nest2::j#1>(byte) 0) goto nest2::@2 [ main::j#2 main::i#2 nest1::j#2 nest1::i#2 nest2::j#1 nest2::i#2 ] // zpby1_gt_0_then_la1 +//SEG56 [21] if((byte) nest2::j#1>(byte) 0) goto nest2::@2 [ main::j#2 main::i#2 nest1::j#2 nest1::i#2 nest2::j#1 nest2::i#2 ] -- zpby1_gt_0_then_la1 lda 7 bne nest2__B2_from_B2 +//SEG57 nest2::@3 nest2__B3: - // [22] (byte) nest2::i#1 ← -- (byte) nest2::i#2 [ main::j#2 main::i#2 nest1::j#2 nest1::i#2 nest2::i#1 ] // zpby1=_dec_zpby1 +//SEG58 [22] (byte) nest2::i#1 ← -- (byte) nest2::i#2 [ main::j#2 main::i#2 nest1::j#2 nest1::i#2 nest2::i#1 ] -- zpby1=_dec_zpby1 dec 6 - // [23] if((byte) nest2::i#1>(byte) 0) goto nest2::@1 [ main::j#2 main::i#2 nest1::j#2 nest1::i#2 nest2::i#1 ] // zpby1_gt_0_then_la1 +//SEG59 [23] if((byte) nest2::i#1>(byte) 0) goto nest2::@1 [ main::j#2 main::i#2 nest1::j#2 nest1::i#2 nest2::i#1 ] -- zpby1_gt_0_then_la1 lda 6 bne nest2__B1_from_B3 +//SEG60 nest2::@return nest2__Breturn: +//SEG61 [24] return [ main::j#2 main::i#2 nest1::j#2 nest1::i#2 ] rts FINAL SYMBOL TABLE @@ -2266,98 +2377,135 @@ zp byte:6 [ nest2::i#2 nest2::i#1 ] zp byte:7 [ nest2::j#2 nest2::j#1 ] FINAL CODE +//SEG0 @BEGIN BBEGIN: +//SEG1 [0] call main param-assignment [ ] jsr main +//SEG2 @END BEND: +//SEG3 main main: +//SEG4 [1] phi from main to main::@1 main__B1_from_main: - // (byte) main::i#2 = (byte) 100 // zpby1=coby1 +//SEG5 [1] phi (byte) main::i#2 = (byte) 100 -- zpby1=coby1 lda #100 sta 2 +//SEG6 [1] phi from main::@3 to main::@1 main__B1_from_B3: - // (byte) main::i#2 = (byte) main::i#1 // register copy zp byte:2 +//SEG7 [1] phi (byte) main::i#2 = (byte) main::i#1 -- register_copy +//SEG8 main::@1 main__B1: +//SEG9 [2] phi from main::@1 to main::@2 main__B2_from_B1: - // (byte) main::j#2 = (byte) 100 // zpby1=coby1 +//SEG10 [2] phi (byte) main::j#2 = (byte) 100 -- zpby1=coby1 lda #100 sta 3 +//SEG11 [2] phi from main::@5 to main::@2 main__B2_from_B5: - // (byte) main::j#2 = (byte) main::j#1 // register copy zp byte:3 +//SEG12 [2] phi (byte) main::j#2 = (byte) main::j#1 -- register_copy +//SEG13 main::@2 main__B2: +//SEG14 [3] call nest1 param-assignment [ main::j#2 main::i#2 ] jsr nest1 +//SEG15 main::@5 main__B5: - // [4] (byte) main::j#1 ← -- (byte) main::j#2 [ main::j#1 main::i#2 ] // zpby1=_dec_zpby1 +//SEG16 [4] (byte) main::j#1 ← -- (byte) main::j#2 [ main::j#1 main::i#2 ] -- zpby1=_dec_zpby1 dec 3 - // [5] if((byte) main::j#1>(byte) 0) goto main::@2 [ main::j#1 main::i#2 ] // zpby1_gt_0_then_la1 +//SEG17 [5] if((byte) main::j#1>(byte) 0) goto main::@2 [ main::j#1 main::i#2 ] -- zpby1_gt_0_then_la1 lda 3 bne main__B2_from_B5 +//SEG18 main::@3 main__B3: - // [6] (byte) main::i#1 ← -- (byte) main::i#2 [ main::i#1 ] // zpby1=_dec_zpby1 +//SEG19 [6] (byte) main::i#1 ← -- (byte) main::i#2 [ main::i#1 ] -- zpby1=_dec_zpby1 dec 2 - // [7] if((byte) main::i#1>(byte) 0) goto main::@1 [ main::i#1 ] // zpby1_gt_0_then_la1 +//SEG20 [7] if((byte) main::i#1>(byte) 0) goto main::@1 [ main::i#1 ] -- zpby1_gt_0_then_la1 lda 2 bne main__B1_from_B3 +//SEG21 main::@return main__Breturn: +//SEG22 [8] return [ ] rts +//SEG23 nest1 nest1: +//SEG24 [9] phi from nest1 to nest1::@1 nest1__B1_from_nest1: - // (byte) nest1::i#2 = (byte) 100 // zpby1=coby1 +//SEG25 [9] phi (byte) nest1::i#2 = (byte) 100 -- zpby1=coby1 lda #100 sta 4 +//SEG26 [9] phi from nest1::@3 to nest1::@1 nest1__B1_from_B3: - // (byte) nest1::i#2 = (byte) nest1::i#1 // register copy zp byte:4 +//SEG27 [9] phi (byte) nest1::i#2 = (byte) nest1::i#1 -- register_copy +//SEG28 nest1::@1 nest1__B1: +//SEG29 [10] phi from nest1::@1 to nest1::@2 nest1__B2_from_B1: - // (byte) nest1::j#2 = (byte) 100 // zpby1=coby1 +//SEG30 [10] phi (byte) nest1::j#2 = (byte) 100 -- zpby1=coby1 lda #100 sta 5 +//SEG31 [10] phi from nest1::@5 to nest1::@2 nest1__B2_from_B5: - // (byte) nest1::j#2 = (byte) nest1::j#1 // register copy zp byte:5 +//SEG32 [10] phi (byte) nest1::j#2 = (byte) nest1::j#1 -- register_copy +//SEG33 nest1::@2 nest1__B2: +//SEG34 [11] call nest2 param-assignment [ main::j#2 main::i#2 nest1::j#2 nest1::i#2 ] jsr nest2 +//SEG35 nest1::@5 nest1__B5: - // [12] (byte) nest1::j#1 ← -- (byte) nest1::j#2 [ main::j#2 main::i#2 nest1::j#1 nest1::i#2 ] // zpby1=_dec_zpby1 +//SEG36 [12] (byte) nest1::j#1 ← -- (byte) nest1::j#2 [ main::j#2 main::i#2 nest1::j#1 nest1::i#2 ] -- zpby1=_dec_zpby1 dec 5 - // [13] if((byte) nest1::j#1>(byte) 0) goto nest1::@2 [ main::j#2 main::i#2 nest1::j#1 nest1::i#2 ] // zpby1_gt_0_then_la1 +//SEG37 [13] if((byte) nest1::j#1>(byte) 0) goto nest1::@2 [ main::j#2 main::i#2 nest1::j#1 nest1::i#2 ] -- zpby1_gt_0_then_la1 lda 5 bne nest1__B2_from_B5 +//SEG38 nest1::@3 nest1__B3: - // [14] (byte) nest1::i#1 ← -- (byte) nest1::i#2 [ main::j#2 main::i#2 nest1::i#1 ] // zpby1=_dec_zpby1 +//SEG39 [14] (byte) nest1::i#1 ← -- (byte) nest1::i#2 [ main::j#2 main::i#2 nest1::i#1 ] -- zpby1=_dec_zpby1 dec 4 - // [15] if((byte) nest1::i#1>(byte) 0) goto nest1::@1 [ main::j#2 main::i#2 nest1::i#1 ] // zpby1_gt_0_then_la1 +//SEG40 [15] if((byte) nest1::i#1>(byte) 0) goto nest1::@1 [ main::j#2 main::i#2 nest1::i#1 ] -- zpby1_gt_0_then_la1 lda 4 bne nest1__B1_from_B3 +//SEG41 nest1::@return nest1__Breturn: +//SEG42 [16] return [ main::j#2 main::i#2 ] rts +//SEG43 nest2 nest2: +//SEG44 [17] phi from nest2 to nest2::@1 nest2__B1_from_nest2: - // (byte) nest2::i#2 = (byte) 100 // zpby1=coby1 +//SEG45 [17] phi (byte) nest2::i#2 = (byte) 100 -- zpby1=coby1 lda #100 sta 6 +//SEG46 [17] phi from nest2::@3 to nest2::@1 nest2__B1_from_B3: - // (byte) nest2::i#2 = (byte) nest2::i#1 // register copy zp byte:6 +//SEG47 [17] phi (byte) nest2::i#2 = (byte) nest2::i#1 -- register_copy +//SEG48 nest2::@1 nest2__B1: +//SEG49 [18] phi from nest2::@1 to nest2::@2 nest2__B2_from_B1: - // (byte) nest2::j#2 = (byte) 100 // zpby1=coby1 +//SEG50 [18] phi (byte) nest2::j#2 = (byte) 100 -- zpby1=coby1 lda #100 sta 7 +//SEG51 [18] phi from nest2::@2 to nest2::@2 nest2__B2_from_B2: - // (byte) nest2::j#2 = (byte) nest2::j#1 // register copy zp byte:7 +//SEG52 [18] phi (byte) nest2::j#2 = (byte) nest2::j#1 -- register_copy +//SEG53 nest2::@2 nest2__B2: - // [19] *((word) 1024) ← (byte) nest2::j#2 [ main::j#2 main::i#2 nest1::j#2 nest1::i#2 nest2::j#2 nest2::i#2 ] // _star_cowo1=zpby1 +//SEG54 [19] *((word) 1024) ← (byte) nest2::j#2 [ main::j#2 main::i#2 nest1::j#2 nest1::i#2 nest2::j#2 nest2::i#2 ] -- _star_cowo1=zpby1 lda 7 sta 1024 - // [20] (byte) nest2::j#1 ← -- (byte) nest2::j#2 [ main::j#2 main::i#2 nest1::j#2 nest1::i#2 nest2::j#1 nest2::i#2 ] // zpby1=_dec_zpby1 +//SEG55 [20] (byte) nest2::j#1 ← -- (byte) nest2::j#2 [ main::j#2 main::i#2 nest1::j#2 nest1::i#2 nest2::j#1 nest2::i#2 ] -- zpby1=_dec_zpby1 dec 7 - // [21] if((byte) nest2::j#1>(byte) 0) goto nest2::@2 [ main::j#2 main::i#2 nest1::j#2 nest1::i#2 nest2::j#1 nest2::i#2 ] // zpby1_gt_0_then_la1 +//SEG56 [21] if((byte) nest2::j#1>(byte) 0) goto nest2::@2 [ main::j#2 main::i#2 nest1::j#2 nest1::i#2 nest2::j#1 nest2::i#2 ] -- zpby1_gt_0_then_la1 lda 7 bne nest2__B2_from_B2 +//SEG57 nest2::@3 nest2__B3: - // [22] (byte) nest2::i#1 ← -- (byte) nest2::i#2 [ main::j#2 main::i#2 nest1::j#2 nest1::i#2 nest2::i#1 ] // zpby1=_dec_zpby1 +//SEG58 [22] (byte) nest2::i#1 ← -- (byte) nest2::i#2 [ main::j#2 main::i#2 nest1::j#2 nest1::i#2 nest2::i#1 ] -- zpby1=_dec_zpby1 dec 6 - // [23] if((byte) nest2::i#1>(byte) 0) goto nest2::@1 [ main::j#2 main::i#2 nest1::j#2 nest1::i#2 nest2::i#1 ] // zpby1_gt_0_then_la1 +//SEG59 [23] if((byte) nest2::i#1>(byte) 0) goto nest2::@1 [ main::j#2 main::i#2 nest1::j#2 nest1::i#2 nest2::i#1 ] -- zpby1_gt_0_then_la1 lda 6 bne nest2__B1_from_B3 +//SEG60 nest2::@return nest2__Breturn: +//SEG61 [24] return [ main::j#2 main::i#2 nest1::j#2 nest1::i#2 ] rts diff --git a/src/main/java/dk/camelot64/kickc/test/ref/loopsplit.log b/src/main/java/dk/camelot64/kickc/test/ref/loopsplit.log index f18caf8e3..35a1b314d 100644 --- a/src/main/java/dk/camelot64/kickc/test/ref/loopsplit.log +++ b/src/main/java/dk/camelot64/kickc/test/ref/loopsplit.log @@ -537,9 +537,9 @@ zp byte:3 [ main::s#3 main::s#1 main::s#2 ] Uplifting max weight 55.0 live range equivalence class zp byte:3 [ main::s#3 main::s#1 main::s#2 ] Uplift to reg byte a resulted in clobber. -Register Cycles: reg byte x 23 +Register Cycles: reg byte x 24 Uplift to reg byte x succesfull. -Register Cycles: reg byte y 23 +Register Cycles: reg byte y 24 Uplift to reg byte y succesfull. REGISTER UPLIFTING (void()) main() @@ -555,49 +555,62 @@ zp byte:2 [ main::i#2 main::i#1 ] zp byte:3 [ main::s#3 main::s#1 main::s#2 ] INITIAL ASM +//SEG0 @BEGIN BBEGIN: +//SEG1 [0] call main param-assignment [ ] jsr main jmp BEND +//SEG2 @END BEND: +//SEG3 main main: +//SEG4 [1] phi from main to main::@1 main__B1_from_main: - // (byte) main::s#3 = (byte) 0 // zpby1=coby1 +//SEG5 [1] phi (byte) main::s#3 = (byte) 0 -- zpby1=coby1 lda #0 sta 3 - // (byte) main::i#2 = (byte) 100 // zpby1=coby1 +//SEG6 [1] phi (byte) main::i#2 = (byte) 100 -- zpby1=coby1 lda #100 sta 2 jmp main__B1 +//SEG7 main::@1 main__B1: - // [2] (byte) main::i#1 ← -- (byte) main::i#2 [ main::i#1 main::s#3 ] // zpby1=_dec_zpby1 +//SEG8 [2] (byte) main::i#1 ← -- (byte) main::i#2 [ main::i#1 main::s#3 ] -- zpby1=_dec_zpby1 dec 2 - // [3] if((byte) main::i#1>(byte) 0) goto main::@2 [ main::i#1 main::s#3 ] // zpby1_gt_0_then_la1 +//SEG9 [3] if((byte) main::i#1>(byte) 0) goto main::@2 [ main::i#1 main::s#3 ] -- zpby1_gt_0_then_la1 lda 2 bne main__B2 jmp main__Breturn +//SEG10 main::@return main__Breturn: +//SEG11 [4] return [ ] rts +//SEG12 main::@2 main__B2: - // [5] if((byte) main::i#1>(byte) 50) goto main::@4 [ main::i#1 main::s#3 ] // zpby1_gt_coby1_then_la1 +//SEG13 [5] if((byte) main::i#1>(byte) 50) goto main::@4 [ main::i#1 main::s#3 ] -- zpby1_gt_coby1_then_la1 lda 2 cmp #50 beq !+ bcs main__B4 !: jmp main__B5 +//SEG14 main::@5 main__B5: - // [6] (byte) main::s#2 ← -- (byte) main::s#3 [ main::i#1 main::s#2 ] // zpby1=_dec_zpby1 +//SEG15 [6] (byte) main::s#2 ← -- (byte) main::s#3 [ main::i#1 main::s#2 ] -- zpby1=_dec_zpby1 dec 3 +//SEG16 [1] phi from main::@5 to main::@1 main__B1_from_B5: - // (byte) main::s#3 = (byte) main::s#2 // register copy zp byte:3 - // (byte) main::i#2 = (byte) main::i#1 // register copy zp byte:2 +//SEG17 [1] phi (byte) main::s#3 = (byte) main::s#2 -- register_copy +//SEG18 [1] phi (byte) main::i#2 = (byte) main::i#1 -- register_copy jmp main__B1 +//SEG19 main::@4 main__B4: - // [7] (byte) main::s#1 ← ++ (byte) main::s#3 [ main::i#1 main::s#1 ] // zpby1=_inc_zpby1 +//SEG20 [7] (byte) main::s#1 ← ++ (byte) main::s#3 [ main::i#1 main::s#1 ] -- zpby1=_inc_zpby1 inc 3 +//SEG21 [1] phi from main::@4 to main::@1 main__B1_from_B4: - // (byte) main::s#3 = (byte) main::s#1 // register copy zp byte:3 - // (byte) main::i#2 = (byte) main::i#1 // register copy zp byte:2 +//SEG22 [1] phi (byte) main::s#3 = (byte) main::s#1 -- register_copy +//SEG23 [1] phi (byte) main::i#2 = (byte) main::i#1 -- register_copy jmp main__B1 Removing instruction jmp BEND @@ -606,45 +619,58 @@ Removing instruction jmp main__Breturn Removing instruction jmp main__B5 Succesful ASM optimization Pass5NextJumpElimination ASSEMBLER +//SEG0 @BEGIN BBEGIN: +//SEG1 [0] call main param-assignment [ ] jsr main +//SEG2 @END BEND: +//SEG3 main main: +//SEG4 [1] phi from main to main::@1 main__B1_from_main: - // (byte) main::s#3 = (byte) 0 // zpby1=coby1 +//SEG5 [1] phi (byte) main::s#3 = (byte) 0 -- zpby1=coby1 lda #0 sta 3 - // (byte) main::i#2 = (byte) 100 // zpby1=coby1 +//SEG6 [1] phi (byte) main::i#2 = (byte) 100 -- zpby1=coby1 lda #100 sta 2 +//SEG7 main::@1 main__B1: - // [2] (byte) main::i#1 ← -- (byte) main::i#2 [ main::i#1 main::s#3 ] // zpby1=_dec_zpby1 +//SEG8 [2] (byte) main::i#1 ← -- (byte) main::i#2 [ main::i#1 main::s#3 ] -- zpby1=_dec_zpby1 dec 2 - // [3] if((byte) main::i#1>(byte) 0) goto main::@2 [ main::i#1 main::s#3 ] // zpby1_gt_0_then_la1 +//SEG9 [3] if((byte) main::i#1>(byte) 0) goto main::@2 [ main::i#1 main::s#3 ] -- zpby1_gt_0_then_la1 lda 2 bne main__B2 +//SEG10 main::@return main__Breturn: +//SEG11 [4] return [ ] rts +//SEG12 main::@2 main__B2: - // [5] if((byte) main::i#1>(byte) 50) goto main::@4 [ main::i#1 main::s#3 ] // zpby1_gt_coby1_then_la1 +//SEG13 [5] if((byte) main::i#1>(byte) 50) goto main::@4 [ main::i#1 main::s#3 ] -- zpby1_gt_coby1_then_la1 lda 2 cmp #50 beq !+ bcs main__B4 !: +//SEG14 main::@5 main__B5: - // [6] (byte) main::s#2 ← -- (byte) main::s#3 [ main::i#1 main::s#2 ] // zpby1=_dec_zpby1 +//SEG15 [6] (byte) main::s#2 ← -- (byte) main::s#3 [ main::i#1 main::s#2 ] -- zpby1=_dec_zpby1 dec 3 +//SEG16 [1] phi from main::@5 to main::@1 main__B1_from_B5: - // (byte) main::s#3 = (byte) main::s#2 // register copy zp byte:3 - // (byte) main::i#2 = (byte) main::i#1 // register copy zp byte:2 +//SEG17 [1] phi (byte) main::s#3 = (byte) main::s#2 -- register_copy +//SEG18 [1] phi (byte) main::i#2 = (byte) main::i#1 -- register_copy jmp main__B1 +//SEG19 main::@4 main__B4: - // [7] (byte) main::s#1 ← ++ (byte) main::s#3 [ main::i#1 main::s#1 ] // zpby1=_inc_zpby1 +//SEG20 [7] (byte) main::s#1 ← ++ (byte) main::s#3 [ main::i#1 main::s#1 ] -- zpby1=_inc_zpby1 inc 3 +//SEG21 [1] phi from main::@4 to main::@1 main__B1_from_B4: - // (byte) main::s#3 = (byte) main::s#1 // register copy zp byte:3 - // (byte) main::i#2 = (byte) main::i#1 // register copy zp byte:2 +//SEG22 [1] phi (byte) main::s#3 = (byte) main::s#1 -- register_copy +//SEG23 [1] phi (byte) main::i#2 = (byte) main::i#1 -- register_copy jmp main__B1 FINAL SYMBOL TABLE @@ -668,44 +694,57 @@ zp byte:2 [ main::i#2 main::i#1 ] zp byte:3 [ main::s#3 main::s#1 main::s#2 ] FINAL CODE +//SEG0 @BEGIN BBEGIN: +//SEG1 [0] call main param-assignment [ ] jsr main +//SEG2 @END BEND: +//SEG3 main main: +//SEG4 [1] phi from main to main::@1 main__B1_from_main: - // (byte) main::s#3 = (byte) 0 // zpby1=coby1 +//SEG5 [1] phi (byte) main::s#3 = (byte) 0 -- zpby1=coby1 lda #0 sta 3 - // (byte) main::i#2 = (byte) 100 // zpby1=coby1 +//SEG6 [1] phi (byte) main::i#2 = (byte) 100 -- zpby1=coby1 lda #100 sta 2 +//SEG7 main::@1 main__B1: - // [2] (byte) main::i#1 ← -- (byte) main::i#2 [ main::i#1 main::s#3 ] // zpby1=_dec_zpby1 +//SEG8 [2] (byte) main::i#1 ← -- (byte) main::i#2 [ main::i#1 main::s#3 ] -- zpby1=_dec_zpby1 dec 2 - // [3] if((byte) main::i#1>(byte) 0) goto main::@2 [ main::i#1 main::s#3 ] // zpby1_gt_0_then_la1 +//SEG9 [3] if((byte) main::i#1>(byte) 0) goto main::@2 [ main::i#1 main::s#3 ] -- zpby1_gt_0_then_la1 lda 2 bne main__B2 +//SEG10 main::@return main__Breturn: +//SEG11 [4] return [ ] rts +//SEG12 main::@2 main__B2: - // [5] if((byte) main::i#1>(byte) 50) goto main::@4 [ main::i#1 main::s#3 ] // zpby1_gt_coby1_then_la1 +//SEG13 [5] if((byte) main::i#1>(byte) 50) goto main::@4 [ main::i#1 main::s#3 ] -- zpby1_gt_coby1_then_la1 lda 2 cmp #50 beq !+ bcs main__B4 !: +//SEG14 main::@5 main__B5: - // [6] (byte) main::s#2 ← -- (byte) main::s#3 [ main::i#1 main::s#2 ] // zpby1=_dec_zpby1 +//SEG15 [6] (byte) main::s#2 ← -- (byte) main::s#3 [ main::i#1 main::s#2 ] -- zpby1=_dec_zpby1 dec 3 +//SEG16 [1] phi from main::@5 to main::@1 main__B1_from_B5: - // (byte) main::s#3 = (byte) main::s#2 // register copy zp byte:3 - // (byte) main::i#2 = (byte) main::i#1 // register copy zp byte:2 +//SEG17 [1] phi (byte) main::s#3 = (byte) main::s#2 -- register_copy +//SEG18 [1] phi (byte) main::i#2 = (byte) main::i#1 -- register_copy jmp main__B1 +//SEG19 main::@4 main__B4: - // [7] (byte) main::s#1 ← ++ (byte) main::s#3 [ main::i#1 main::s#1 ] // zpby1=_inc_zpby1 +//SEG20 [7] (byte) main::s#1 ← ++ (byte) main::s#3 [ main::i#1 main::s#1 ] -- zpby1=_inc_zpby1 inc 3 +//SEG21 [1] phi from main::@4 to main::@1 main__B1_from_B4: - // (byte) main::s#3 = (byte) main::s#1 // register copy zp byte:3 - // (byte) main::i#2 = (byte) main::i#1 // register copy zp byte:2 +//SEG22 [1] phi (byte) main::s#3 = (byte) main::s#1 -- register_copy +//SEG23 [1] phi (byte) main::i#2 = (byte) main::i#1 -- register_copy jmp main__B1 diff --git a/src/main/java/dk/camelot64/kickc/test/ref/minus.log b/src/main/java/dk/camelot64/kickc/test/ref/minus.log index f55cdc4a1..a19c58165 100644 --- a/src/main/java/dk/camelot64/kickc/test/ref/minus.log +++ b/src/main/java/dk/camelot64/kickc/test/ref/minus.log @@ -326,90 +326,105 @@ zp byte:2 [ i#2 i#1 ] zp byte:3 [ $1 ] INITIAL ASM +//SEG0 @BEGIN BBEGIN: +//SEG1 [0] phi from @BEGIN to @1 B1_from_BBEGIN: - // (byte) i#2 = (byte) 5 // zpby1=coby1 +//SEG2 [0] phi (byte) i#2 = (byte) 5 -- zpby1=coby1 lda #5 sta 2 jmp B1 +//SEG3 [0] phi from @1 to @1 B1_from_B1: - // (byte) i#2 = (byte) i#1 // register copy zp byte:2 +//SEG4 [0] phi (byte) i#2 = (byte) i#1 -- register_copy jmp B1 +//SEG5 @1 B1: - // [1] (byte~) $1 ← (byte) i#2 + (byte) 4 [ i#2 $1 ] // zpby1=zpby2_plus_coby1 +//SEG6 [1] (byte~) $1 ← (byte) i#2 + (byte) 4 [ i#2 $1 ] -- zpby1=zpby2_plus_coby1 lda 2 clc adc #4 sta 3 - // [2] *((word) 4352 + (byte) i#2) ← (byte~) $1 [ i#2 ] // cowo1_staridx_zpby1=zpby2 +//SEG7 [2] *((word) 4352 + (byte) i#2) ← (byte~) $1 [ i#2 ] -- cowo1_staridx_zpby1=zpby2 lda 3 ldx 2 sta 4352,x - // [3] (byte) i#1 ← (byte) i#2 + (byte) 1 [ i#1 ] // zpby1=zpby1_plus_1 +//SEG8 [3] (byte) i#1 ← (byte) i#2 + (byte) 1 [ i#1 ] -- zpby1=zpby1_plus_1 inc 2 - // [4] if((byte) i#1<(byte) 10) goto @1 [ i#1 ] // zpby1_lt_coby1_then_la1 +//SEG9 [4] if((byte) i#1<(byte) 10) goto @1 [ i#1 ] -- zpby1_lt_coby1_then_la1 lda 2 cmp #10 bcc B1_from_B1 jmp BEND +//SEG10 @END BEND: Removing instruction jmp B1 Removing instruction jmp BEND Succesful ASM optimization Pass5NextJumpElimination ASSEMBLER +//SEG0 @BEGIN BBEGIN: +//SEG1 [0] phi from @BEGIN to @1 B1_from_BBEGIN: - // (byte) i#2 = (byte) 5 // zpby1=coby1 +//SEG2 [0] phi (byte) i#2 = (byte) 5 -- zpby1=coby1 lda #5 sta 2 jmp B1 +//SEG3 [0] phi from @1 to @1 B1_from_B1: - // (byte) i#2 = (byte) i#1 // register copy zp byte:2 +//SEG4 [0] phi (byte) i#2 = (byte) i#1 -- register_copy +//SEG5 @1 B1: - // [1] (byte~) $1 ← (byte) i#2 + (byte) 4 [ i#2 $1 ] // zpby1=zpby2_plus_coby1 +//SEG6 [1] (byte~) $1 ← (byte) i#2 + (byte) 4 [ i#2 $1 ] -- zpby1=zpby2_plus_coby1 lda 2 clc adc #4 sta 3 - // [2] *((word) 4352 + (byte) i#2) ← (byte~) $1 [ i#2 ] // cowo1_staridx_zpby1=zpby2 +//SEG7 [2] *((word) 4352 + (byte) i#2) ← (byte~) $1 [ i#2 ] -- cowo1_staridx_zpby1=zpby2 lda 3 ldx 2 sta 4352,x - // [3] (byte) i#1 ← (byte) i#2 + (byte) 1 [ i#1 ] // zpby1=zpby1_plus_1 +//SEG8 [3] (byte) i#1 ← (byte) i#2 + (byte) 1 [ i#1 ] -- zpby1=zpby1_plus_1 inc 2 - // [4] if((byte) i#1<(byte) 10) goto @1 [ i#1 ] // zpby1_lt_coby1_then_la1 +//SEG9 [4] if((byte) i#1<(byte) 10) goto @1 [ i#1 ] -- zpby1_lt_coby1_then_la1 lda 2 cmp #10 bcc B1_from_B1 +//SEG10 @END BEND: Removing instruction jmp B1 Succesful ASM optimization Pass5NextJumpElimination ASSEMBLER +//SEG0 @BEGIN BBEGIN: +//SEG1 [0] phi from @BEGIN to @1 B1_from_BBEGIN: - // (byte) i#2 = (byte) 5 // zpby1=coby1 +//SEG2 [0] phi (byte) i#2 = (byte) 5 -- zpby1=coby1 lda #5 sta 2 +//SEG3 [0] phi from @1 to @1 B1_from_B1: - // (byte) i#2 = (byte) i#1 // register copy zp byte:2 +//SEG4 [0] phi (byte) i#2 = (byte) i#1 -- register_copy +//SEG5 @1 B1: - // [1] (byte~) $1 ← (byte) i#2 + (byte) 4 [ i#2 $1 ] // zpby1=zpby2_plus_coby1 +//SEG6 [1] (byte~) $1 ← (byte) i#2 + (byte) 4 [ i#2 $1 ] -- zpby1=zpby2_plus_coby1 lda 2 clc adc #4 sta 3 - // [2] *((word) 4352 + (byte) i#2) ← (byte~) $1 [ i#2 ] // cowo1_staridx_zpby1=zpby2 +//SEG7 [2] *((word) 4352 + (byte) i#2) ← (byte~) $1 [ i#2 ] -- cowo1_staridx_zpby1=zpby2 lda 3 ldx 2 sta 4352,x - // [3] (byte) i#1 ← (byte) i#2 + (byte) 1 [ i#1 ] // zpby1=zpby1_plus_1 +//SEG8 [3] (byte) i#1 ← (byte) i#2 + (byte) 1 [ i#1 ] -- zpby1=zpby1_plus_1 inc 2 - // [4] if((byte) i#1<(byte) 10) goto @1 [ i#1 ] // zpby1_lt_coby1_then_la1 +//SEG9 [4] if((byte) i#1<(byte) 10) goto @1 [ i#1 ] -- zpby1_lt_coby1_then_la1 lda 2 cmp #10 bcc B1_from_B1 +//SEG10 @END BEND: FINAL SYMBOL TABLE @@ -426,28 +441,33 @@ zp byte:2 [ i#2 i#1 ] zp byte:3 [ $1 ] FINAL CODE +//SEG0 @BEGIN BBEGIN: +//SEG1 [0] phi from @BEGIN to @1 B1_from_BBEGIN: - // (byte) i#2 = (byte) 5 // zpby1=coby1 +//SEG2 [0] phi (byte) i#2 = (byte) 5 -- zpby1=coby1 lda #5 sta 2 +//SEG3 [0] phi from @1 to @1 B1_from_B1: - // (byte) i#2 = (byte) i#1 // register copy zp byte:2 +//SEG4 [0] phi (byte) i#2 = (byte) i#1 -- register_copy +//SEG5 @1 B1: - // [1] (byte~) $1 ← (byte) i#2 + (byte) 4 [ i#2 $1 ] // zpby1=zpby2_plus_coby1 +//SEG6 [1] (byte~) $1 ← (byte) i#2 + (byte) 4 [ i#2 $1 ] -- zpby1=zpby2_plus_coby1 lda 2 clc adc #4 sta 3 - // [2] *((word) 4352 + (byte) i#2) ← (byte~) $1 [ i#2 ] // cowo1_staridx_zpby1=zpby2 +//SEG7 [2] *((word) 4352 + (byte) i#2) ← (byte~) $1 [ i#2 ] -- cowo1_staridx_zpby1=zpby2 lda 3 ldx 2 sta 4352,x - // [3] (byte) i#1 ← (byte) i#2 + (byte) 1 [ i#1 ] // zpby1=zpby1_plus_1 +//SEG8 [3] (byte) i#1 ← (byte) i#2 + (byte) 1 [ i#1 ] -- zpby1=zpby1_plus_1 inc 2 - // [4] if((byte) i#1<(byte) 10) goto @1 [ i#1 ] // zpby1_lt_coby1_then_la1 +//SEG9 [4] if((byte) i#1<(byte) 10) goto @1 [ i#1 ] -- zpby1_lt_coby1_then_la1 lda 2 cmp #10 bcc B1_from_B1 +//SEG10 @END BEND: diff --git a/src/main/java/dk/camelot64/kickc/test/ref/ptrtest.log b/src/main/java/dk/camelot64/kickc/test/ref/ptrtest.log index 2893d71d8..f5d1aab31 100644 --- a/src/main/java/dk/camelot64/kickc/test/ref/ptrtest.log +++ b/src/main/java/dk/camelot64/kickc/test/ref/ptrtest.log @@ -1947,153 +1947,194 @@ Coalescing zero page register [ zp byte:2 [ lvaluevar::i#2 lvaluevar::i#1 rvalue Coalescing zero page register [ zp byte:2 [ lvaluevar::i#2 lvaluevar::i#1 rvaluevar::i#2 rvaluevar::i#1 rvalue::i#2 rvalue::i#1 lvalue::i#2 lvalue::i#1 rvaluevar::b#0 rvalue::b#0 rvalue::b#1 ] ] with [ zp byte:13 [ rvalue::b#2 ] ] Coalescing zero page register [ zp ptr byte:3 [ lvaluevar::screen#2 lvaluevar::screen#1 ] ] with [ zp ptr byte:6 [ rvaluevar::screen#2 rvaluevar::screen#1 ] ] INITIAL ASM +//SEG0 @BEGIN BBEGIN: +//SEG1 [0] call main param-assignment [ ] jsr main jmp BEND +//SEG2 @END BEND: +//SEG3 main main: +//SEG4 [1] call lvalue param-assignment [ ] jsr lvalue jmp main__B1 +//SEG5 main::@1 main__B1: +//SEG6 [2] call rvalue param-assignment [ ] jsr rvalue jmp main__B2 +//SEG7 main::@2 main__B2: +//SEG8 [3] call rvaluevar param-assignment [ ] jsr rvaluevar jmp main__B3 +//SEG9 main::@3 main__B3: +//SEG10 [4] call lvaluevar param-assignment [ ] jsr lvaluevar jmp main__Breturn +//SEG11 main::@return main__Breturn: +//SEG12 [5] return [ ] rts +//SEG13 lvaluevar lvaluevar: +//SEG14 [6] phi from lvaluevar to lvaluevar::@1 lvaluevar__B1_from_lvaluevar: - // (byte*) lvaluevar::screen#2 = (word) 1024 // zpptrby1=cowo1 +//SEG15 [6] phi (byte*) lvaluevar::screen#2 = (word) 1024 -- zpptrby1=cowo1 lda #<1024 sta 3 lda #>1024 sta 3+1 - // (byte) lvaluevar::i#2 = (byte) 2 // zpby1=coby1 +//SEG16 [6] phi (byte) lvaluevar::i#2 = (byte) 2 -- zpby1=coby1 lda #2 sta 2 jmp lvaluevar__B1 +//SEG17 lvaluevar::@1 lvaluevar__B1: - // [7] if((byte) lvaluevar::i#2<(byte) 10) goto lvaluevar::@2 [ lvaluevar::i#2 lvaluevar::screen#2 ] // zpby1_lt_coby1_then_la1 +//SEG18 [7] if((byte) lvaluevar::i#2<(byte) 10) goto lvaluevar::@2 [ lvaluevar::i#2 lvaluevar::screen#2 ] -- zpby1_lt_coby1_then_la1 lda 2 cmp #10 bcc lvaluevar__B2 jmp lvaluevar__Breturn +//SEG19 lvaluevar::@return lvaluevar__Breturn: +//SEG20 [8] return [ ] rts +//SEG21 lvaluevar::@2 lvaluevar__B2: - // [9] *((byte*) lvaluevar::screen#2) ← (byte) 4 [ lvaluevar::i#2 lvaluevar::screen#2 ] // _star_zpptrby1=coby1 +//SEG22 [9] *((byte*) lvaluevar::screen#2) ← (byte) 4 [ lvaluevar::i#2 lvaluevar::screen#2 ] -- _star_zpptrby1=coby1 ldy #0 lda #4 sta (3),y - // [10] (byte*) lvaluevar::screen#1 ← ++ (byte*) lvaluevar::screen#2 [ lvaluevar::screen#1 lvaluevar::i#2 ] // zpptrby1=_inc_zpptrby1 +//SEG23 [10] (byte*) lvaluevar::screen#1 ← ++ (byte*) lvaluevar::screen#2 [ lvaluevar::screen#1 lvaluevar::i#2 ] -- zpptrby1=_inc_zpptrby1 inc 3 bne !+ inc 3+1 !: - // [11] (byte) lvaluevar::i#1 ← ++ (byte) lvaluevar::i#2 [ lvaluevar::i#1 lvaluevar::screen#1 ] // zpby1=_inc_zpby1 +//SEG24 [11] (byte) lvaluevar::i#1 ← ++ (byte) lvaluevar::i#2 [ lvaluevar::i#1 lvaluevar::screen#1 ] -- zpby1=_inc_zpby1 inc 2 +//SEG25 [6] phi from lvaluevar::@2 to lvaluevar::@1 lvaluevar__B1_from_B2: - // (byte*) lvaluevar::screen#2 = (byte*) lvaluevar::screen#1 // register copy zp ptr byte:3 - // (byte) lvaluevar::i#2 = (byte) lvaluevar::i#1 // register copy zp byte:2 +//SEG26 [6] phi (byte*) lvaluevar::screen#2 = (byte*) lvaluevar::screen#1 -- register_copy +//SEG27 [6] phi (byte) lvaluevar::i#2 = (byte) lvaluevar::i#1 -- register_copy jmp lvaluevar__B1 +//SEG28 rvaluevar rvaluevar: +//SEG29 [12] phi from rvaluevar to rvaluevar::@1 rvaluevar__B1_from_rvaluevar: - // (byte*) rvaluevar::screen#2 = (word) 1024 // zpptrby1=cowo1 +//SEG30 [12] phi (byte*) rvaluevar::screen#2 = (word) 1024 -- zpptrby1=cowo1 lda #<1024 sta 6 lda #>1024 sta 6+1 - // (byte) rvaluevar::i#2 = (byte) 2 // zpby1=coby1 +//SEG31 [12] phi (byte) rvaluevar::i#2 = (byte) 2 -- zpby1=coby1 lda #2 sta 5 jmp rvaluevar__B1 +//SEG32 rvaluevar::@1 rvaluevar__B1: - // [13] if((byte) rvaluevar::i#2<(byte) 10) goto rvaluevar::@2 [ rvaluevar::i#2 rvaluevar::screen#2 ] // zpby1_lt_coby1_then_la1 +//SEG33 [13] if((byte) rvaluevar::i#2<(byte) 10) goto rvaluevar::@2 [ rvaluevar::i#2 rvaluevar::screen#2 ] -- zpby1_lt_coby1_then_la1 lda 5 cmp #10 bcc rvaluevar__B2 jmp rvaluevar__Breturn +//SEG34 rvaluevar::@return rvaluevar__Breturn: +//SEG35 [14] return [ ] rts +//SEG36 rvaluevar::@2 rvaluevar__B2: - // [15] (byte) rvaluevar::b#0 ← * (byte*) rvaluevar::screen#2 [ rvaluevar::i#2 rvaluevar::screen#2 ] // zpby1=_star_zpptrby1 +//SEG37 [15] (byte) rvaluevar::b#0 ← * (byte*) rvaluevar::screen#2 [ rvaluevar::i#2 rvaluevar::screen#2 ] -- zpby1=_star_zpptrby1 ldy #0 lda (6),y sta 10 - // [16] (byte*) rvaluevar::screen#1 ← ++ (byte*) rvaluevar::screen#2 [ rvaluevar::screen#1 rvaluevar::i#2 ] // zpptrby1=_inc_zpptrby1 +//SEG38 [16] (byte*) rvaluevar::screen#1 ← ++ (byte*) rvaluevar::screen#2 [ rvaluevar::screen#1 rvaluevar::i#2 ] -- zpptrby1=_inc_zpptrby1 inc 6 bne !+ inc 6+1 !: - // [17] (byte) rvaluevar::i#1 ← ++ (byte) rvaluevar::i#2 [ rvaluevar::i#1 rvaluevar::screen#1 ] // zpby1=_inc_zpby1 +//SEG39 [17] (byte) rvaluevar::i#1 ← ++ (byte) rvaluevar::i#2 [ rvaluevar::i#1 rvaluevar::screen#1 ] -- zpby1=_inc_zpby1 inc 5 +//SEG40 [12] phi from rvaluevar::@2 to rvaluevar::@1 rvaluevar__B1_from_B2: - // (byte*) rvaluevar::screen#2 = (byte*) rvaluevar::screen#1 // register copy zp ptr byte:6 - // (byte) rvaluevar::i#2 = (byte) rvaluevar::i#1 // register copy zp byte:5 +//SEG41 [12] phi (byte*) rvaluevar::screen#2 = (byte*) rvaluevar::screen#1 -- register_copy +//SEG42 [12] phi (byte) rvaluevar::i#2 = (byte) rvaluevar::i#1 -- register_copy jmp rvaluevar__B1 +//SEG43 rvalue rvalue: - // [18] (byte) rvalue::b#0 ← * (word) 1024 [ ] // zpby1=_star_cowo1 +//SEG44 [18] (byte) rvalue::b#0 ← * (word) 1024 [ ] -- zpby1=_star_cowo1 lda 1024 sta 11 - // [19] (byte) rvalue::b#1 ← * (word) 1025 [ ] // zpby1=_star_cowo1 +//SEG45 [19] (byte) rvalue::b#1 ← * (word) 1025 [ ] -- zpby1=_star_cowo1 lda 1025 sta 12 +//SEG46 [20] phi from rvalue to rvalue::@1 rvalue__B1_from_rvalue: - // (byte) rvalue::i#2 = (byte) 2 // zpby1=coby1 +//SEG47 [20] phi (byte) rvalue::i#2 = (byte) 2 -- zpby1=coby1 lda #2 sta 8 jmp rvalue__B1 +//SEG48 rvalue::@1 rvalue__B1: - // [21] if((byte) rvalue::i#2<(byte) 10) goto rvalue::@2 [ rvalue::i#2 ] // zpby1_lt_coby1_then_la1 +//SEG49 [21] if((byte) rvalue::i#2<(byte) 10) goto rvalue::@2 [ rvalue::i#2 ] -- zpby1_lt_coby1_then_la1 lda 8 cmp #10 bcc rvalue__B2 jmp rvalue__Breturn +//SEG50 rvalue::@return rvalue__Breturn: +//SEG51 [22] return [ ] rts +//SEG52 rvalue::@2 rvalue__B2: - // [23] (byte) rvalue::b#2 ← (word) 1024 *idx (byte) rvalue::i#2 [ rvalue::i#2 ] // zpby1=cowo1_staridx_zpby2 +//SEG53 [23] (byte) rvalue::b#2 ← (word) 1024 *idx (byte) rvalue::i#2 [ rvalue::i#2 ] -- zpby1=cowo1_staridx_zpby2 ldx 8 lda 1024,x sta 13 - // [24] (byte) rvalue::i#1 ← ++ (byte) rvalue::i#2 [ rvalue::i#1 ] // zpby1=_inc_zpby1 +//SEG54 [24] (byte) rvalue::i#1 ← ++ (byte) rvalue::i#2 [ rvalue::i#1 ] -- zpby1=_inc_zpby1 inc 8 +//SEG55 [20] phi from rvalue::@2 to rvalue::@1 rvalue__B1_from_B2: - // (byte) rvalue::i#2 = (byte) rvalue::i#1 // register copy zp byte:8 +//SEG56 [20] phi (byte) rvalue::i#2 = (byte) rvalue::i#1 -- register_copy jmp rvalue__B1 +//SEG57 lvalue lvalue: - // [25] *((word) 1024) ← (byte) 1 [ ] // _star_cowo1=coby2 +//SEG58 [25] *((word) 1024) ← (byte) 1 [ ] -- _star_cowo1=coby2 lda #1 sta 1024 - // [26] *((word) 1025) ← (byte) 2 [ ] // _star_cowo1=coby2 +//SEG59 [26] *((word) 1025) ← (byte) 2 [ ] -- _star_cowo1=coby2 lda #2 sta 1025 +//SEG60 [27] phi from lvalue to lvalue::@1 lvalue__B1_from_lvalue: - // (byte) lvalue::i#2 = (byte) 2 // zpby1=coby1 +//SEG61 [27] phi (byte) lvalue::i#2 = (byte) 2 -- zpby1=coby1 lda #2 sta 9 jmp lvalue__B1 +//SEG62 lvalue::@1 lvalue__B1: - // [28] if((byte) lvalue::i#2<(byte) 10) goto lvalue::@2 [ lvalue::i#2 ] // zpby1_lt_coby1_then_la1 +//SEG63 [28] if((byte) lvalue::i#2<(byte) 10) goto lvalue::@2 [ lvalue::i#2 ] -- zpby1_lt_coby1_then_la1 lda 9 cmp #10 bcc lvalue__B2 jmp lvalue__Breturn +//SEG64 lvalue::@return lvalue__Breturn: +//SEG65 [29] return [ ] rts +//SEG66 lvalue::@2 lvalue__B2: - // [30] *((word) 1024 + (byte) lvalue::i#2) ← (byte) 3 [ lvalue::i#2 ] // cowo1_staridx_zpby1=coby2 +//SEG67 [30] *((word) 1024 + (byte) lvalue::i#2) ← (byte) 3 [ lvalue::i#2 ] -- cowo1_staridx_zpby1=coby2 lda #3 ldx 9 sta 1024,x - // [31] (byte) lvalue::i#1 ← ++ (byte) lvalue::i#2 [ lvalue::i#1 ] // zpby1=_inc_zpby1 +//SEG68 [31] (byte) lvalue::i#1 ← ++ (byte) lvalue::i#2 [ lvalue::i#1 ] -- zpby1=_inc_zpby1 inc 9 +//SEG69 [27] phi from lvalue::@2 to lvalue::@1 lvalue__B1_from_B2: - // (byte) lvalue::i#2 = (byte) lvalue::i#1 // register copy zp byte:9 +//SEG70 [27] phi (byte) lvalue::i#2 = (byte) lvalue::i#1 -- register_copy jmp lvalue__B1 Removing instruction jmp BEND @@ -2111,140 +2152,181 @@ Removing instruction jmp lvalue__B1 Removing instruction jmp lvalue__Breturn Succesful ASM optimization Pass5NextJumpElimination ASSEMBLER +//SEG0 @BEGIN BBEGIN: +//SEG1 [0] call main param-assignment [ ] jsr main +//SEG2 @END BEND: +//SEG3 main main: +//SEG4 [1] call lvalue param-assignment [ ] jsr lvalue +//SEG5 main::@1 main__B1: +//SEG6 [2] call rvalue param-assignment [ ] jsr rvalue +//SEG7 main::@2 main__B2: +//SEG8 [3] call rvaluevar param-assignment [ ] jsr rvaluevar +//SEG9 main::@3 main__B3: +//SEG10 [4] call lvaluevar param-assignment [ ] jsr lvaluevar +//SEG11 main::@return main__Breturn: +//SEG12 [5] return [ ] rts +//SEG13 lvaluevar lvaluevar: +//SEG14 [6] phi from lvaluevar to lvaluevar::@1 lvaluevar__B1_from_lvaluevar: - // (byte*) lvaluevar::screen#2 = (word) 1024 // zpptrby1=cowo1 +//SEG15 [6] phi (byte*) lvaluevar::screen#2 = (word) 1024 -- zpptrby1=cowo1 lda #<1024 sta 3 lda #>1024 sta 3+1 - // (byte) lvaluevar::i#2 = (byte) 2 // zpby1=coby1 +//SEG16 [6] phi (byte) lvaluevar::i#2 = (byte) 2 -- zpby1=coby1 lda #2 sta 2 +//SEG17 lvaluevar::@1 lvaluevar__B1: - // [7] if((byte) lvaluevar::i#2<(byte) 10) goto lvaluevar::@2 [ lvaluevar::i#2 lvaluevar::screen#2 ] // zpby1_lt_coby1_then_la1 +//SEG18 [7] if((byte) lvaluevar::i#2<(byte) 10) goto lvaluevar::@2 [ lvaluevar::i#2 lvaluevar::screen#2 ] -- zpby1_lt_coby1_then_la1 lda 2 cmp #10 bcc lvaluevar__B2 +//SEG19 lvaluevar::@return lvaluevar__Breturn: +//SEG20 [8] return [ ] rts +//SEG21 lvaluevar::@2 lvaluevar__B2: - // [9] *((byte*) lvaluevar::screen#2) ← (byte) 4 [ lvaluevar::i#2 lvaluevar::screen#2 ] // _star_zpptrby1=coby1 +//SEG22 [9] *((byte*) lvaluevar::screen#2) ← (byte) 4 [ lvaluevar::i#2 lvaluevar::screen#2 ] -- _star_zpptrby1=coby1 ldy #0 lda #4 sta (3),y - // [10] (byte*) lvaluevar::screen#1 ← ++ (byte*) lvaluevar::screen#2 [ lvaluevar::screen#1 lvaluevar::i#2 ] // zpptrby1=_inc_zpptrby1 +//SEG23 [10] (byte*) lvaluevar::screen#1 ← ++ (byte*) lvaluevar::screen#2 [ lvaluevar::screen#1 lvaluevar::i#2 ] -- zpptrby1=_inc_zpptrby1 inc 3 bne !+ inc 3+1 !: - // [11] (byte) lvaluevar::i#1 ← ++ (byte) lvaluevar::i#2 [ lvaluevar::i#1 lvaluevar::screen#1 ] // zpby1=_inc_zpby1 +//SEG24 [11] (byte) lvaluevar::i#1 ← ++ (byte) lvaluevar::i#2 [ lvaluevar::i#1 lvaluevar::screen#1 ] -- zpby1=_inc_zpby1 inc 2 +//SEG25 [6] phi from lvaluevar::@2 to lvaluevar::@1 lvaluevar__B1_from_B2: - // (byte*) lvaluevar::screen#2 = (byte*) lvaluevar::screen#1 // register copy zp ptr byte:3 - // (byte) lvaluevar::i#2 = (byte) lvaluevar::i#1 // register copy zp byte:2 +//SEG26 [6] phi (byte*) lvaluevar::screen#2 = (byte*) lvaluevar::screen#1 -- register_copy +//SEG27 [6] phi (byte) lvaluevar::i#2 = (byte) lvaluevar::i#1 -- register_copy jmp lvaluevar__B1 +//SEG28 rvaluevar rvaluevar: +//SEG29 [12] phi from rvaluevar to rvaluevar::@1 rvaluevar__B1_from_rvaluevar: - // (byte*) rvaluevar::screen#2 = (word) 1024 // zpptrby1=cowo1 +//SEG30 [12] phi (byte*) rvaluevar::screen#2 = (word) 1024 -- zpptrby1=cowo1 lda #<1024 sta 6 lda #>1024 sta 6+1 - // (byte) rvaluevar::i#2 = (byte) 2 // zpby1=coby1 +//SEG31 [12] phi (byte) rvaluevar::i#2 = (byte) 2 -- zpby1=coby1 lda #2 sta 5 +//SEG32 rvaluevar::@1 rvaluevar__B1: - // [13] if((byte) rvaluevar::i#2<(byte) 10) goto rvaluevar::@2 [ rvaluevar::i#2 rvaluevar::screen#2 ] // zpby1_lt_coby1_then_la1 +//SEG33 [13] if((byte) rvaluevar::i#2<(byte) 10) goto rvaluevar::@2 [ rvaluevar::i#2 rvaluevar::screen#2 ] -- zpby1_lt_coby1_then_la1 lda 5 cmp #10 bcc rvaluevar__B2 +//SEG34 rvaluevar::@return rvaluevar__Breturn: +//SEG35 [14] return [ ] rts +//SEG36 rvaluevar::@2 rvaluevar__B2: - // [15] (byte) rvaluevar::b#0 ← * (byte*) rvaluevar::screen#2 [ rvaluevar::i#2 rvaluevar::screen#2 ] // zpby1=_star_zpptrby1 +//SEG37 [15] (byte) rvaluevar::b#0 ← * (byte*) rvaluevar::screen#2 [ rvaluevar::i#2 rvaluevar::screen#2 ] -- zpby1=_star_zpptrby1 ldy #0 lda (6),y sta 10 - // [16] (byte*) rvaluevar::screen#1 ← ++ (byte*) rvaluevar::screen#2 [ rvaluevar::screen#1 rvaluevar::i#2 ] // zpptrby1=_inc_zpptrby1 +//SEG38 [16] (byte*) rvaluevar::screen#1 ← ++ (byte*) rvaluevar::screen#2 [ rvaluevar::screen#1 rvaluevar::i#2 ] -- zpptrby1=_inc_zpptrby1 inc 6 bne !+ inc 6+1 !: - // [17] (byte) rvaluevar::i#1 ← ++ (byte) rvaluevar::i#2 [ rvaluevar::i#1 rvaluevar::screen#1 ] // zpby1=_inc_zpby1 +//SEG39 [17] (byte) rvaluevar::i#1 ← ++ (byte) rvaluevar::i#2 [ rvaluevar::i#1 rvaluevar::screen#1 ] -- zpby1=_inc_zpby1 inc 5 +//SEG40 [12] phi from rvaluevar::@2 to rvaluevar::@1 rvaluevar__B1_from_B2: - // (byte*) rvaluevar::screen#2 = (byte*) rvaluevar::screen#1 // register copy zp ptr byte:6 - // (byte) rvaluevar::i#2 = (byte) rvaluevar::i#1 // register copy zp byte:5 +//SEG41 [12] phi (byte*) rvaluevar::screen#2 = (byte*) rvaluevar::screen#1 -- register_copy +//SEG42 [12] phi (byte) rvaluevar::i#2 = (byte) rvaluevar::i#1 -- register_copy jmp rvaluevar__B1 +//SEG43 rvalue rvalue: - // [18] (byte) rvalue::b#0 ← * (word) 1024 [ ] // zpby1=_star_cowo1 +//SEG44 [18] (byte) rvalue::b#0 ← * (word) 1024 [ ] -- zpby1=_star_cowo1 lda 1024 sta 11 - // [19] (byte) rvalue::b#1 ← * (word) 1025 [ ] // zpby1=_star_cowo1 +//SEG45 [19] (byte) rvalue::b#1 ← * (word) 1025 [ ] -- zpby1=_star_cowo1 lda 1025 sta 12 +//SEG46 [20] phi from rvalue to rvalue::@1 rvalue__B1_from_rvalue: - // (byte) rvalue::i#2 = (byte) 2 // zpby1=coby1 +//SEG47 [20] phi (byte) rvalue::i#2 = (byte) 2 -- zpby1=coby1 lda #2 sta 8 +//SEG48 rvalue::@1 rvalue__B1: - // [21] if((byte) rvalue::i#2<(byte) 10) goto rvalue::@2 [ rvalue::i#2 ] // zpby1_lt_coby1_then_la1 +//SEG49 [21] if((byte) rvalue::i#2<(byte) 10) goto rvalue::@2 [ rvalue::i#2 ] -- zpby1_lt_coby1_then_la1 lda 8 cmp #10 bcc rvalue__B2 +//SEG50 rvalue::@return rvalue__Breturn: +//SEG51 [22] return [ ] rts +//SEG52 rvalue::@2 rvalue__B2: - // [23] (byte) rvalue::b#2 ← (word) 1024 *idx (byte) rvalue::i#2 [ rvalue::i#2 ] // zpby1=cowo1_staridx_zpby2 +//SEG53 [23] (byte) rvalue::b#2 ← (word) 1024 *idx (byte) rvalue::i#2 [ rvalue::i#2 ] -- zpby1=cowo1_staridx_zpby2 ldx 8 lda 1024,x sta 13 - // [24] (byte) rvalue::i#1 ← ++ (byte) rvalue::i#2 [ rvalue::i#1 ] // zpby1=_inc_zpby1 +//SEG54 [24] (byte) rvalue::i#1 ← ++ (byte) rvalue::i#2 [ rvalue::i#1 ] -- zpby1=_inc_zpby1 inc 8 +//SEG55 [20] phi from rvalue::@2 to rvalue::@1 rvalue__B1_from_B2: - // (byte) rvalue::i#2 = (byte) rvalue::i#1 // register copy zp byte:8 +//SEG56 [20] phi (byte) rvalue::i#2 = (byte) rvalue::i#1 -- register_copy jmp rvalue__B1 +//SEG57 lvalue lvalue: - // [25] *((word) 1024) ← (byte) 1 [ ] // _star_cowo1=coby2 +//SEG58 [25] *((word) 1024) ← (byte) 1 [ ] -- _star_cowo1=coby2 lda #1 sta 1024 - // [26] *((word) 1025) ← (byte) 2 [ ] // _star_cowo1=coby2 +//SEG59 [26] *((word) 1025) ← (byte) 2 [ ] -- _star_cowo1=coby2 lda #2 sta 1025 +//SEG60 [27] phi from lvalue to lvalue::@1 lvalue__B1_from_lvalue: - // (byte) lvalue::i#2 = (byte) 2 // zpby1=coby1 +//SEG61 [27] phi (byte) lvalue::i#2 = (byte) 2 -- zpby1=coby1 lda #2 sta 9 +//SEG62 lvalue::@1 lvalue__B1: - // [28] if((byte) lvalue::i#2<(byte) 10) goto lvalue::@2 [ lvalue::i#2 ] // zpby1_lt_coby1_then_la1 +//SEG63 [28] if((byte) lvalue::i#2<(byte) 10) goto lvalue::@2 [ lvalue::i#2 ] -- zpby1_lt_coby1_then_la1 lda 9 cmp #10 bcc lvalue__B2 +//SEG64 lvalue::@return lvalue__Breturn: +//SEG65 [29] return [ ] rts +//SEG66 lvalue::@2 lvalue__B2: - // [30] *((word) 1024 + (byte) lvalue::i#2) ← (byte) 3 [ lvalue::i#2 ] // cowo1_staridx_zpby1=coby2 +//SEG67 [30] *((word) 1024 + (byte) lvalue::i#2) ← (byte) 3 [ lvalue::i#2 ] -- cowo1_staridx_zpby1=coby2 lda #3 ldx 9 sta 1024,x - // [31] (byte) lvalue::i#1 ← ++ (byte) lvalue::i#2 [ lvalue::i#1 ] // zpby1=_inc_zpby1 +//SEG68 [31] (byte) lvalue::i#1 ← ++ (byte) lvalue::i#2 [ lvalue::i#1 ] -- zpby1=_inc_zpby1 inc 9 +//SEG69 [27] phi from lvalue::@2 to lvalue::@1 lvalue__B1_from_B2: - // (byte) lvalue::i#2 = (byte) lvalue::i#1 // register copy zp byte:9 +//SEG70 [27] phi (byte) lvalue::i#2 = (byte) lvalue::i#1 -- register_copy jmp lvalue__B1 FINAL SYMBOL TABLE @@ -2303,139 +2385,180 @@ zp byte:2 [ lvaluevar::i#2 lvaluevar::i#1 rvaluevar::i#2 rvaluevar::i#1 rvalue:: zp ptr byte:3 [ lvaluevar::screen#2 lvaluevar::screen#1 rvaluevar::screen#2 rvaluevar::screen#1 ] FINAL CODE +//SEG0 @BEGIN BBEGIN: +//SEG1 [0] call main param-assignment [ ] jsr main +//SEG2 @END BEND: +//SEG3 main main: +//SEG4 [1] call lvalue param-assignment [ ] jsr lvalue +//SEG5 main::@1 main__B1: +//SEG6 [2] call rvalue param-assignment [ ] jsr rvalue +//SEG7 main::@2 main__B2: +//SEG8 [3] call rvaluevar param-assignment [ ] jsr rvaluevar +//SEG9 main::@3 main__B3: +//SEG10 [4] call lvaluevar param-assignment [ ] jsr lvaluevar +//SEG11 main::@return main__Breturn: +//SEG12 [5] return [ ] rts +//SEG13 lvaluevar lvaluevar: +//SEG14 [6] phi from lvaluevar to lvaluevar::@1 lvaluevar__B1_from_lvaluevar: - // (byte*) lvaluevar::screen#2 = (word) 1024 // zpptrby1=cowo1 +//SEG15 [6] phi (byte*) lvaluevar::screen#2 = (word) 1024 -- zpptrby1=cowo1 lda #<1024 sta 3 lda #>1024 sta 3+1 - // (byte) lvaluevar::i#2 = (byte) 2 // zpby1=coby1 +//SEG16 [6] phi (byte) lvaluevar::i#2 = (byte) 2 -- zpby1=coby1 lda #2 sta 2 +//SEG17 lvaluevar::@1 lvaluevar__B1: - // [7] if((byte) lvaluevar::i#2<(byte) 10) goto lvaluevar::@2 [ lvaluevar::i#2 lvaluevar::screen#2 ] // zpby1_lt_coby1_then_la1 +//SEG18 [7] if((byte) lvaluevar::i#2<(byte) 10) goto lvaluevar::@2 [ lvaluevar::i#2 lvaluevar::screen#2 ] -- zpby1_lt_coby1_then_la1 lda 2 cmp #10 bcc lvaluevar__B2 +//SEG19 lvaluevar::@return lvaluevar__Breturn: +//SEG20 [8] return [ ] rts +//SEG21 lvaluevar::@2 lvaluevar__B2: - // [9] *((byte*) lvaluevar::screen#2) ← (byte) 4 [ lvaluevar::i#2 lvaluevar::screen#2 ] // _star_zpptrby1=coby1 +//SEG22 [9] *((byte*) lvaluevar::screen#2) ← (byte) 4 [ lvaluevar::i#2 lvaluevar::screen#2 ] -- _star_zpptrby1=coby1 ldy #0 lda #4 sta (3),y - // [10] (byte*) lvaluevar::screen#1 ← ++ (byte*) lvaluevar::screen#2 [ lvaluevar::screen#1 lvaluevar::i#2 ] // zpptrby1=_inc_zpptrby1 +//SEG23 [10] (byte*) lvaluevar::screen#1 ← ++ (byte*) lvaluevar::screen#2 [ lvaluevar::screen#1 lvaluevar::i#2 ] -- zpptrby1=_inc_zpptrby1 inc 3 bne !+ inc 3+1 !: - // [11] (byte) lvaluevar::i#1 ← ++ (byte) lvaluevar::i#2 [ lvaluevar::i#1 lvaluevar::screen#1 ] // zpby1=_inc_zpby1 +//SEG24 [11] (byte) lvaluevar::i#1 ← ++ (byte) lvaluevar::i#2 [ lvaluevar::i#1 lvaluevar::screen#1 ] -- zpby1=_inc_zpby1 inc 2 +//SEG25 [6] phi from lvaluevar::@2 to lvaluevar::@1 lvaluevar__B1_from_B2: - // (byte*) lvaluevar::screen#2 = (byte*) lvaluevar::screen#1 // register copy zp ptr byte:3 - // (byte) lvaluevar::i#2 = (byte) lvaluevar::i#1 // register copy zp byte:2 +//SEG26 [6] phi (byte*) lvaluevar::screen#2 = (byte*) lvaluevar::screen#1 -- register_copy +//SEG27 [6] phi (byte) lvaluevar::i#2 = (byte) lvaluevar::i#1 -- register_copy jmp lvaluevar__B1 +//SEG28 rvaluevar rvaluevar: +//SEG29 [12] phi from rvaluevar to rvaluevar::@1 rvaluevar__B1_from_rvaluevar: - // (byte*) rvaluevar::screen#2 = (word) 1024 // zpptrby1=cowo1 +//SEG30 [12] phi (byte*) rvaluevar::screen#2 = (word) 1024 -- zpptrby1=cowo1 lda #<1024 sta 6 lda #>1024 sta 6+1 - // (byte) rvaluevar::i#2 = (byte) 2 // zpby1=coby1 +//SEG31 [12] phi (byte) rvaluevar::i#2 = (byte) 2 -- zpby1=coby1 lda #2 sta 5 +//SEG32 rvaluevar::@1 rvaluevar__B1: - // [13] if((byte) rvaluevar::i#2<(byte) 10) goto rvaluevar::@2 [ rvaluevar::i#2 rvaluevar::screen#2 ] // zpby1_lt_coby1_then_la1 +//SEG33 [13] if((byte) rvaluevar::i#2<(byte) 10) goto rvaluevar::@2 [ rvaluevar::i#2 rvaluevar::screen#2 ] -- zpby1_lt_coby1_then_la1 lda 5 cmp #10 bcc rvaluevar__B2 +//SEG34 rvaluevar::@return rvaluevar__Breturn: +//SEG35 [14] return [ ] rts +//SEG36 rvaluevar::@2 rvaluevar__B2: - // [15] (byte) rvaluevar::b#0 ← * (byte*) rvaluevar::screen#2 [ rvaluevar::i#2 rvaluevar::screen#2 ] // zpby1=_star_zpptrby1 +//SEG37 [15] (byte) rvaluevar::b#0 ← * (byte*) rvaluevar::screen#2 [ rvaluevar::i#2 rvaluevar::screen#2 ] -- zpby1=_star_zpptrby1 ldy #0 lda (6),y sta 10 - // [16] (byte*) rvaluevar::screen#1 ← ++ (byte*) rvaluevar::screen#2 [ rvaluevar::screen#1 rvaluevar::i#2 ] // zpptrby1=_inc_zpptrby1 +//SEG38 [16] (byte*) rvaluevar::screen#1 ← ++ (byte*) rvaluevar::screen#2 [ rvaluevar::screen#1 rvaluevar::i#2 ] -- zpptrby1=_inc_zpptrby1 inc 6 bne !+ inc 6+1 !: - // [17] (byte) rvaluevar::i#1 ← ++ (byte) rvaluevar::i#2 [ rvaluevar::i#1 rvaluevar::screen#1 ] // zpby1=_inc_zpby1 +//SEG39 [17] (byte) rvaluevar::i#1 ← ++ (byte) rvaluevar::i#2 [ rvaluevar::i#1 rvaluevar::screen#1 ] -- zpby1=_inc_zpby1 inc 5 +//SEG40 [12] phi from rvaluevar::@2 to rvaluevar::@1 rvaluevar__B1_from_B2: - // (byte*) rvaluevar::screen#2 = (byte*) rvaluevar::screen#1 // register copy zp ptr byte:6 - // (byte) rvaluevar::i#2 = (byte) rvaluevar::i#1 // register copy zp byte:5 +//SEG41 [12] phi (byte*) rvaluevar::screen#2 = (byte*) rvaluevar::screen#1 -- register_copy +//SEG42 [12] phi (byte) rvaluevar::i#2 = (byte) rvaluevar::i#1 -- register_copy jmp rvaluevar__B1 +//SEG43 rvalue rvalue: - // [18] (byte) rvalue::b#0 ← * (word) 1024 [ ] // zpby1=_star_cowo1 +//SEG44 [18] (byte) rvalue::b#0 ← * (word) 1024 [ ] -- zpby1=_star_cowo1 lda 1024 sta 11 - // [19] (byte) rvalue::b#1 ← * (word) 1025 [ ] // zpby1=_star_cowo1 +//SEG45 [19] (byte) rvalue::b#1 ← * (word) 1025 [ ] -- zpby1=_star_cowo1 lda 1025 sta 12 +//SEG46 [20] phi from rvalue to rvalue::@1 rvalue__B1_from_rvalue: - // (byte) rvalue::i#2 = (byte) 2 // zpby1=coby1 +//SEG47 [20] phi (byte) rvalue::i#2 = (byte) 2 -- zpby1=coby1 lda #2 sta 8 +//SEG48 rvalue::@1 rvalue__B1: - // [21] if((byte) rvalue::i#2<(byte) 10) goto rvalue::@2 [ rvalue::i#2 ] // zpby1_lt_coby1_then_la1 +//SEG49 [21] if((byte) rvalue::i#2<(byte) 10) goto rvalue::@2 [ rvalue::i#2 ] -- zpby1_lt_coby1_then_la1 lda 8 cmp #10 bcc rvalue__B2 +//SEG50 rvalue::@return rvalue__Breturn: +//SEG51 [22] return [ ] rts +//SEG52 rvalue::@2 rvalue__B2: - // [23] (byte) rvalue::b#2 ← (word) 1024 *idx (byte) rvalue::i#2 [ rvalue::i#2 ] // zpby1=cowo1_staridx_zpby2 +//SEG53 [23] (byte) rvalue::b#2 ← (word) 1024 *idx (byte) rvalue::i#2 [ rvalue::i#2 ] -- zpby1=cowo1_staridx_zpby2 ldx 8 lda 1024,x sta 13 - // [24] (byte) rvalue::i#1 ← ++ (byte) rvalue::i#2 [ rvalue::i#1 ] // zpby1=_inc_zpby1 +//SEG54 [24] (byte) rvalue::i#1 ← ++ (byte) rvalue::i#2 [ rvalue::i#1 ] -- zpby1=_inc_zpby1 inc 8 +//SEG55 [20] phi from rvalue::@2 to rvalue::@1 rvalue__B1_from_B2: - // (byte) rvalue::i#2 = (byte) rvalue::i#1 // register copy zp byte:8 +//SEG56 [20] phi (byte) rvalue::i#2 = (byte) rvalue::i#1 -- register_copy jmp rvalue__B1 +//SEG57 lvalue lvalue: - // [25] *((word) 1024) ← (byte) 1 [ ] // _star_cowo1=coby2 +//SEG58 [25] *((word) 1024) ← (byte) 1 [ ] -- _star_cowo1=coby2 lda #1 sta 1024 - // [26] *((word) 1025) ← (byte) 2 [ ] // _star_cowo1=coby2 +//SEG59 [26] *((word) 1025) ← (byte) 2 [ ] -- _star_cowo1=coby2 lda #2 sta 1025 +//SEG60 [27] phi from lvalue to lvalue::@1 lvalue__B1_from_lvalue: - // (byte) lvalue::i#2 = (byte) 2 // zpby1=coby1 +//SEG61 [27] phi (byte) lvalue::i#2 = (byte) 2 -- zpby1=coby1 lda #2 sta 9 +//SEG62 lvalue::@1 lvalue__B1: - // [28] if((byte) lvalue::i#2<(byte) 10) goto lvalue::@2 [ lvalue::i#2 ] // zpby1_lt_coby1_then_la1 +//SEG63 [28] if((byte) lvalue::i#2<(byte) 10) goto lvalue::@2 [ lvalue::i#2 ] -- zpby1_lt_coby1_then_la1 lda 9 cmp #10 bcc lvalue__B2 +//SEG64 lvalue::@return lvalue__Breturn: +//SEG65 [29] return [ ] rts +//SEG66 lvalue::@2 lvalue__B2: - // [30] *((word) 1024 + (byte) lvalue::i#2) ← (byte) 3 [ lvalue::i#2 ] // cowo1_staridx_zpby1=coby2 +//SEG67 [30] *((word) 1024 + (byte) lvalue::i#2) ← (byte) 3 [ lvalue::i#2 ] -- cowo1_staridx_zpby1=coby2 lda #3 ldx 9 sta 1024,x - // [31] (byte) lvalue::i#1 ← ++ (byte) lvalue::i#2 [ lvalue::i#1 ] // zpby1=_inc_zpby1 +//SEG68 [31] (byte) lvalue::i#1 ← ++ (byte) lvalue::i#2 [ lvalue::i#1 ] -- zpby1=_inc_zpby1 inc 9 +//SEG69 [27] phi from lvalue::@2 to lvalue::@1 lvalue__B1_from_B2: - // (byte) lvalue::i#2 = (byte) lvalue::i#1 // register copy zp byte:9 +//SEG70 [27] phi (byte) lvalue::i#2 = (byte) lvalue::i#1 -- register_copy jmp lvalue__B1 diff --git a/src/main/java/dk/camelot64/kickc/test/ref/summin.log b/src/main/java/dk/camelot64/kickc/test/ref/summin.log index 0d96871ce..9e9e172ba 100644 --- a/src/main/java/dk/camelot64/kickc/test/ref/summin.log +++ b/src/main/java/dk/camelot64/kickc/test/ref/summin.log @@ -426,48 +426,59 @@ Coalescing zero page register [ zp byte:2 [ sum::a#2 ] ] with [ zp byte:5 [ s2#0 Coalescing zero page register [ zp byte:2 [ sum::a#2 s2#0 ] ] with [ zp byte:6 [ s3#0 ] ] Coalescing zero page register [ zp byte:2 [ sum::a#2 s2#0 s3#0 ] ] with [ zp byte:7 [ sum::return#0 ] ] INITIAL ASM +//SEG0 @BEGIN BBEGIN: +//SEG1 [0] call sum param-assignment [ sum::return#0 s1#0 ] +//SEG2 [5] phi from @BEGIN to sum sum_from_BBEGIN: - // (byte) sum::b#2 = (byte) 2 // zpby1=coby1 +//SEG3 [5] phi (byte) sum::b#2 = (byte) 2 -- zpby1=coby1 lda #2 sta 3 - // (byte) sum::a#2 = (byte) 1 // zpby1=coby1 +//SEG4 [5] phi (byte) sum::a#2 = (byte) 1 -- zpby1=coby1 lda #1 sta 2 jsr sum jmp B2 +//SEG5 @2 B2: - // [1] (byte) s1#0 ← (byte) sum::return#0 [ sum::return#0 s1#0 ] // zpby1=zpby2 +//SEG6 [1] (byte) s1#0 ← (byte) sum::return#0 [ sum::return#0 s1#0 ] -- zpby1=zpby2 lda 7 sta 4 +//SEG7 [2] call sum param-assignment [ sum::return#0 s1#0 ] +//SEG8 [5] phi from @2 to sum sum_from_B2: - // (byte) sum::b#2 = (byte) 13 // zpby1=coby1 +//SEG9 [5] phi (byte) sum::b#2 = (byte) 13 -- zpby1=coby1 lda #13 sta 3 - // (byte) sum::a#2 = (byte) 9 // zpby1=coby1 +//SEG10 [5] phi (byte) sum::a#2 = (byte) 9 -- zpby1=coby1 lda #9 sta 2 jsr sum jmp B3 +//SEG11 @3 B3: - // [3] (byte) s2#0 ← (byte) sum::return#0 [ s1#0 s2#0 ] // zpby1=zpby2 +//SEG12 [3] (byte) s2#0 ← (byte) sum::return#0 [ s1#0 s2#0 ] -- zpby1=zpby2 lda 7 sta 5 - // [4] (byte) s3#0 ← (byte) s1#0 + (byte) s2#0 [ ] // zpby1=zpby2_plus_zpby3 +//SEG13 [4] (byte) s3#0 ← (byte) s1#0 + (byte) s2#0 [ ] -- zpby1=zpby2_plus_zpby3 lda 4 clc adc 5 sta 6 jmp BEND +//SEG14 @END BEND: +//SEG15 sum sum: - // [6] (byte) sum::return#0 ← (byte) sum::a#2 + (byte) sum::b#2 [ sum::return#0 s1#0 ] // zpby1=zpby2_plus_zpby3 +//SEG16 [6] (byte) sum::return#0 ← (byte) sum::a#2 + (byte) sum::b#2 [ sum::return#0 s1#0 ] -- zpby1=zpby2_plus_zpby3 lda 2 clc adc 3 sta 7 jmp sum__Breturn +//SEG17 sum::@return sum__Breturn: +//SEG18 [7] return [ sum::return#0 s1#0 ] rts Removing instruction jmp B2 @@ -476,44 +487,55 @@ Removing instruction jmp BEND Removing instruction jmp sum__Breturn Succesful ASM optimization Pass5NextJumpElimination ASSEMBLER +//SEG0 @BEGIN BBEGIN: +//SEG1 [0] call sum param-assignment [ sum::return#0 s1#0 ] +//SEG2 [5] phi from @BEGIN to sum sum_from_BBEGIN: - // (byte) sum::b#2 = (byte) 2 // zpby1=coby1 +//SEG3 [5] phi (byte) sum::b#2 = (byte) 2 -- zpby1=coby1 lda #2 sta 3 - // (byte) sum::a#2 = (byte) 1 // zpby1=coby1 +//SEG4 [5] phi (byte) sum::a#2 = (byte) 1 -- zpby1=coby1 lda #1 sta 2 jsr sum +//SEG5 @2 B2: - // [1] (byte) s1#0 ← (byte) sum::return#0 [ sum::return#0 s1#0 ] // zpby1=zpby2 +//SEG6 [1] (byte) s1#0 ← (byte) sum::return#0 [ sum::return#0 s1#0 ] -- zpby1=zpby2 lda 7 sta 4 +//SEG7 [2] call sum param-assignment [ sum::return#0 s1#0 ] +//SEG8 [5] phi from @2 to sum sum_from_B2: - // (byte) sum::b#2 = (byte) 13 // zpby1=coby1 +//SEG9 [5] phi (byte) sum::b#2 = (byte) 13 -- zpby1=coby1 lda #13 sta 3 - // (byte) sum::a#2 = (byte) 9 // zpby1=coby1 +//SEG10 [5] phi (byte) sum::a#2 = (byte) 9 -- zpby1=coby1 lda #9 sta 2 jsr sum +//SEG11 @3 B3: - // [3] (byte) s2#0 ← (byte) sum::return#0 [ s1#0 s2#0 ] // zpby1=zpby2 +//SEG12 [3] (byte) s2#0 ← (byte) sum::return#0 [ s1#0 s2#0 ] -- zpby1=zpby2 lda 7 sta 5 - // [4] (byte) s3#0 ← (byte) s1#0 + (byte) s2#0 [ ] // zpby1=zpby2_plus_zpby3 +//SEG13 [4] (byte) s3#0 ← (byte) s1#0 + (byte) s2#0 [ ] -- zpby1=zpby2_plus_zpby3 lda 4 clc adc 5 sta 6 +//SEG14 @END BEND: +//SEG15 sum sum: - // [6] (byte) sum::return#0 ← (byte) sum::a#2 + (byte) sum::b#2 [ sum::return#0 s1#0 ] // zpby1=zpby2_plus_zpby3 +//SEG16 [6] (byte) sum::return#0 ← (byte) sum::a#2 + (byte) sum::b#2 [ sum::return#0 s1#0 ] -- zpby1=zpby2_plus_zpby3 lda 2 clc adc 3 sta 7 +//SEG17 sum::@return sum__Breturn: +//SEG18 [7] return [ sum::return#0 s1#0 ] rts FINAL SYMBOL TABLE @@ -541,43 +563,54 @@ zp byte:3 [ sum::b#2 ] zp byte:4 [ s1#0 ] FINAL CODE +//SEG0 @BEGIN BBEGIN: +//SEG1 [0] call sum param-assignment [ sum::return#0 s1#0 ] +//SEG2 [5] phi from @BEGIN to sum sum_from_BBEGIN: - // (byte) sum::b#2 = (byte) 2 // zpby1=coby1 +//SEG3 [5] phi (byte) sum::b#2 = (byte) 2 -- zpby1=coby1 lda #2 sta 3 - // (byte) sum::a#2 = (byte) 1 // zpby1=coby1 +//SEG4 [5] phi (byte) sum::a#2 = (byte) 1 -- zpby1=coby1 lda #1 sta 2 jsr sum +//SEG5 @2 B2: - // [1] (byte) s1#0 ← (byte) sum::return#0 [ sum::return#0 s1#0 ] // zpby1=zpby2 +//SEG6 [1] (byte) s1#0 ← (byte) sum::return#0 [ sum::return#0 s1#0 ] -- zpby1=zpby2 lda 7 sta 4 +//SEG7 [2] call sum param-assignment [ sum::return#0 s1#0 ] +//SEG8 [5] phi from @2 to sum sum_from_B2: - // (byte) sum::b#2 = (byte) 13 // zpby1=coby1 +//SEG9 [5] phi (byte) sum::b#2 = (byte) 13 -- zpby1=coby1 lda #13 sta 3 - // (byte) sum::a#2 = (byte) 9 // zpby1=coby1 +//SEG10 [5] phi (byte) sum::a#2 = (byte) 9 -- zpby1=coby1 lda #9 sta 2 jsr sum +//SEG11 @3 B3: - // [3] (byte) s2#0 ← (byte) sum::return#0 [ s1#0 s2#0 ] // zpby1=zpby2 +//SEG12 [3] (byte) s2#0 ← (byte) sum::return#0 [ s1#0 s2#0 ] -- zpby1=zpby2 lda 7 sta 5 - // [4] (byte) s3#0 ← (byte) s1#0 + (byte) s2#0 [ ] // zpby1=zpby2_plus_zpby3 +//SEG13 [4] (byte) s3#0 ← (byte) s1#0 + (byte) s2#0 [ ] -- zpby1=zpby2_plus_zpby3 lda 4 clc adc 5 sta 6 +//SEG14 @END BEND: +//SEG15 sum sum: - // [6] (byte) sum::return#0 ← (byte) sum::a#2 + (byte) sum::b#2 [ sum::return#0 s1#0 ] // zpby1=zpby2_plus_zpby3 +//SEG16 [6] (byte) sum::return#0 ← (byte) sum::a#2 + (byte) sum::b#2 [ sum::return#0 s1#0 ] -- zpby1=zpby2_plus_zpby3 lda 2 clc adc 3 sta 7 +//SEG17 sum::@return sum__Breturn: +//SEG18 [7] return [ sum::return#0 s1#0 ] rts diff --git a/src/main/java/dk/camelot64/kickc/test/ref/useglobal.log b/src/main/java/dk/camelot64/kickc/test/ref/useglobal.log index 0be2d4542..88eb91b5b 100644 --- a/src/main/java/dk/camelot64/kickc/test/ref/useglobal.log +++ b/src/main/java/dk/camelot64/kickc/test/ref/useglobal.log @@ -213,30 +213,42 @@ REGISTER UPLIFTING INITIAL ASM +//SEG0 @BEGIN BBEGIN: +//SEG1 [0] call main param-assignment [ ] jsr main jmp BEND +//SEG2 @END BEND: +//SEG3 main main: - // [1] *((word) 1024) ← (byte) 1 [ ] // _star_cowo1=coby2 +//SEG4 [1] *((word) 1024) ← (byte) 1 [ ] -- _star_cowo1=coby2 lda #1 sta 1024 jmp main__Breturn +//SEG5 main::@return main__Breturn: +//SEG6 [2] return [ ] rts Removing instruction jmp BEND Removing instruction jmp main__Breturn Succesful ASM optimization Pass5NextJumpElimination ASSEMBLER +//SEG0 @BEGIN BBEGIN: +//SEG1 [0] call main param-assignment [ ] jsr main +//SEG2 @END BEND: +//SEG3 main main: - // [1] *((word) 1024) ← (byte) 1 [ ] // _star_cowo1=coby2 +//SEG4 [1] *((word) 1024) ← (byte) 1 [ ] -- _star_cowo1=coby2 lda #1 sta 1024 +//SEG5 main::@return main__Breturn: +//SEG6 [2] return [ ] rts FINAL SYMBOL TABLE @@ -248,13 +260,19 @@ FINAL SYMBOL TABLE FINAL CODE +//SEG0 @BEGIN BBEGIN: +//SEG1 [0] call main param-assignment [ ] jsr main +//SEG2 @END BEND: +//SEG3 main main: - // [1] *((word) 1024) ← (byte) 1 [ ] // _star_cowo1=coby2 +//SEG4 [1] *((word) 1024) ← (byte) 1 [ ] -- _star_cowo1=coby2 lda #1 sta 1024 +//SEG5 main::@return main__Breturn: +//SEG6 [2] return [ ] rts