mirror of
https://gitlab.com/camelot/kickc.git
synced 2025-01-11 04:29:53 +00:00
Better label naming when creating intermediate labels
This commit is contained in:
parent
4c0a9cd241
commit
88c7ed453a
@ -17,7 +17,7 @@ public class StatementPhi implements StatementLValue {
|
|||||||
/** The versioned variable being assigned a value by the statement. */
|
/** The versioned variable being assigned a value by the statement. */
|
||||||
private VariableRef lValue;
|
private VariableRef lValue;
|
||||||
|
|
||||||
/** The previous version of the rValue from predeccesor control blocks. */
|
/** The previous version of the rValue from predecessor control blocks. */
|
||||||
private List<PreviousSymbol> previousVersions;
|
private List<PreviousSymbol> previousVersions;
|
||||||
|
|
||||||
public StatementPhi(VariableRef lValue) {
|
public StatementPhi(VariableRef lValue) {
|
||||||
|
@ -27,6 +27,13 @@ public class Pass1GenerateControlFlowGraph {
|
|||||||
sequence.addStatement(new StatementLabel(scope.addLabel(END_BLOCK_NAME).getRef()));
|
sequence.addStatement(new StatementLabel(scope.addLabel(END_BLOCK_NAME).getRef()));
|
||||||
for (Statement statement : sequence.getStatements()) {
|
for (Statement statement : sequence.getStatements()) {
|
||||||
ControlFlowBlock currentBlock = blockStack.peek();
|
ControlFlowBlock currentBlock = blockStack.peek();
|
||||||
|
Symbol currentBlockLabel = scope.getSymbol(currentBlock.getLabel());
|
||||||
|
Scope currentBlockScope;
|
||||||
|
if(currentBlockLabel instanceof Procedure) {
|
||||||
|
currentBlockScope = (Scope) currentBlockLabel;
|
||||||
|
} else {
|
||||||
|
currentBlockScope = currentBlockLabel.getScope();
|
||||||
|
}
|
||||||
if(statement instanceof StatementLabel) {
|
if(statement instanceof StatementLabel) {
|
||||||
StatementLabel statementLabel = (StatementLabel) statement;
|
StatementLabel statementLabel = (StatementLabel) statement;
|
||||||
ControlFlowBlock nextBlock = getOrCreateBlock(statementLabel.getLabel());
|
ControlFlowBlock nextBlock = getOrCreateBlock(statementLabel.getLabel());
|
||||||
@ -37,14 +44,14 @@ public class Pass1GenerateControlFlowGraph {
|
|||||||
StatementJump statementJump = (StatementJump) statement;
|
StatementJump statementJump = (StatementJump) statement;
|
||||||
ControlFlowBlock jmpBlock = getOrCreateBlock(statementJump.getDestination());
|
ControlFlowBlock jmpBlock = getOrCreateBlock(statementJump.getDestination());
|
||||||
currentBlock.setDefaultSuccessor(jmpBlock.getLabel());
|
currentBlock.setDefaultSuccessor(jmpBlock.getLabel());
|
||||||
ControlFlowBlock nextBlock = getOrCreateBlock(scope.addLabelIntermediate().getRef());
|
ControlFlowBlock nextBlock = getOrCreateBlock(currentBlockScope.addLabelIntermediate().getRef());
|
||||||
blockStack.pop();
|
blockStack.pop();
|
||||||
blockStack.push(nextBlock);
|
blockStack.push(nextBlock);
|
||||||
} else if(statement instanceof StatementConditionalJump) {
|
} else if(statement instanceof StatementConditionalJump) {
|
||||||
currentBlock.addStatement(statement);
|
currentBlock.addStatement(statement);
|
||||||
StatementConditionalJump statementConditionalJump = (StatementConditionalJump) statement;
|
StatementConditionalJump statementConditionalJump = (StatementConditionalJump) statement;
|
||||||
ControlFlowBlock jmpBlock = getOrCreateBlock(statementConditionalJump.getDestination());
|
ControlFlowBlock jmpBlock = getOrCreateBlock(statementConditionalJump.getDestination());
|
||||||
ControlFlowBlock nextBlock = getOrCreateBlock(scope.addLabelIntermediate().getRef());
|
ControlFlowBlock nextBlock = getOrCreateBlock(currentBlockScope.addLabelIntermediate().getRef());
|
||||||
currentBlock.setDefaultSuccessor(nextBlock.getLabel());
|
currentBlock.setDefaultSuccessor(nextBlock.getLabel());
|
||||||
currentBlock.setConditionalSuccessor(jmpBlock.getLabel());
|
currentBlock.setConditionalSuccessor(jmpBlock.getLabel());
|
||||||
blockStack.pop();
|
blockStack.pop();
|
||||||
@ -60,7 +67,7 @@ public class Pass1GenerateControlFlowGraph {
|
|||||||
} else if(statement instanceof StatementProcedureEnd) {
|
} else if(statement instanceof StatementProcedureEnd) {
|
||||||
// Procedure strategy implemented is currently variable-based transfer of parameters/return values
|
// Procedure strategy implemented is currently variable-based transfer of parameters/return values
|
||||||
currentBlock.setDefaultSuccessor(new Label("@RETURN", scope, false).getRef());
|
currentBlock.setDefaultSuccessor(new Label("@RETURN", scope, false).getRef());
|
||||||
ControlFlowBlock nextBlock = getOrCreateBlock(scope.addLabelIntermediate().getRef());
|
ControlFlowBlock nextBlock = getOrCreateBlock(currentBlockScope.addLabelIntermediate().getRef());
|
||||||
blockStack.pop();
|
blockStack.pop();
|
||||||
ControlFlowBlock prevBlock = blockStack.pop();
|
ControlFlowBlock prevBlock = blockStack.pop();
|
||||||
prevBlock.setDefaultSuccessor(nextBlock.getLabel());
|
prevBlock.setDefaultSuccessor(nextBlock.getLabel());
|
||||||
|
@ -44,7 +44,14 @@ public class Pass1ProcedureCallParameters extends ControlFlowGraphCopyVisitor {
|
|||||||
copyCall.setProcedure(procedureRef);
|
copyCall.setProcedure(procedureRef);
|
||||||
addStatementToCurrentBlock(copyCall);
|
addStatementToCurrentBlock(copyCall);
|
||||||
getCurrentBlock().setCallSuccessor(procedure.getLabel().getRef());
|
getCurrentBlock().setCallSuccessor(procedure.getLabel().getRef());
|
||||||
splitCurrentBlock(scope.addLabelIntermediate().getRef());
|
Symbol currentBlockSymbol = scope.getSymbol(getCurrentBlock().getLabel());
|
||||||
|
Scope currentBlockScope;
|
||||||
|
if(currentBlockSymbol instanceof Procedure) {
|
||||||
|
currentBlockScope = (Scope) currentBlockSymbol;
|
||||||
|
} else {
|
||||||
|
currentBlockScope = currentBlockSymbol.getScope();
|
||||||
|
}
|
||||||
|
splitCurrentBlock(currentBlockScope.addLabelIntermediate().getRef());
|
||||||
if(!SymbolTypeBasic.VOID.equals(procedure.getReturnType())) {
|
if(!SymbolTypeBasic.VOID.equals(procedure.getReturnType())) {
|
||||||
addStatementToCurrentBlock(new StatementAssignment(origCall.getlValue(), procReturnVarRef));
|
addStatementToCurrentBlock(new StatementAssignment(origCall.getlValue(), procReturnVarRef));
|
||||||
} else {
|
} else {
|
||||||
|
@ -6,9 +6,9 @@ main:
|
|||||||
main__B2_from_main:
|
main__B2_from_main:
|
||||||
ldx #25
|
ldx #25
|
||||||
jmp main__B2
|
jmp main__B2
|
||||||
main__B2_from_B18:
|
main__B2_from_B12:
|
||||||
ldx #25
|
ldx #25
|
||||||
main__B2_from_B2:
|
main__B2_from_B6:
|
||||||
main__B2:
|
main__B2:
|
||||||
main__B3:
|
main__B3:
|
||||||
lda 53266
|
lda 53266
|
||||||
@ -18,16 +18,16 @@ main__B4:
|
|||||||
lda 53266
|
lda 53266
|
||||||
cmp #255
|
cmp #255
|
||||||
bne main__main__B4
|
bne main__main__B4
|
||||||
B2:
|
main__B6:
|
||||||
dex
|
dex
|
||||||
cpx #0
|
cpx #0
|
||||||
bne main__B2_from_B2
|
bne main__B2_from_B6
|
||||||
B3:
|
main__B7:
|
||||||
jsr flip
|
jsr flip
|
||||||
B17:
|
main__B11:
|
||||||
jsr plot
|
jsr plot
|
||||||
B18:
|
main__B12:
|
||||||
jmp main__B2_from_B18
|
jmp main__B2_from_B12
|
||||||
main__Breturn:
|
main__Breturn:
|
||||||
rts
|
rts
|
||||||
plot:
|
plot:
|
||||||
@ -39,7 +39,7 @@ plot__B1_from_plot:
|
|||||||
sta 101
|
sta 101
|
||||||
lda #>1236
|
lda #>1236
|
||||||
sta 101+1
|
sta 101+1
|
||||||
plot__B1_from_B12:
|
plot__B1_from_B3:
|
||||||
plot__B1:
|
plot__B1:
|
||||||
plot__B2_from_B1:
|
plot__B2_from_B1:
|
||||||
ldy #0
|
ldy #0
|
||||||
@ -51,7 +51,7 @@ plot__B2:
|
|||||||
iny
|
iny
|
||||||
cpy #16
|
cpy #16
|
||||||
bcc plot__B2_from_B2
|
bcc plot__B2_from_B2
|
||||||
B12:
|
plot__B3:
|
||||||
lda 101
|
lda 101
|
||||||
clc
|
clc
|
||||||
adc #40
|
adc #40
|
||||||
@ -61,7 +61,7 @@ B12:
|
|||||||
!:
|
!:
|
||||||
dec 100
|
dec 100
|
||||||
lda 100
|
lda 100
|
||||||
bne plot__B1_from_B12
|
bne plot__B1_from_B3
|
||||||
plot__Breturn:
|
plot__Breturn:
|
||||||
rts
|
rts
|
||||||
flip:
|
flip:
|
||||||
@ -70,7 +70,7 @@ flip__B1_from_flip:
|
|||||||
sta 104
|
sta 104
|
||||||
ldx #0
|
ldx #0
|
||||||
ldy #15
|
ldy #15
|
||||||
flip__B1_from_B8:
|
flip__B1_from_B4:
|
||||||
flip__B1:
|
flip__B1:
|
||||||
flip__B2_from_B1:
|
flip__B2_from_B1:
|
||||||
lda #16
|
lda #16
|
||||||
@ -87,12 +87,12 @@ flip__B2:
|
|||||||
dec 103
|
dec 103
|
||||||
lda 103
|
lda 103
|
||||||
bne flip__B2_from_B2
|
bne flip__B2_from_B2
|
||||||
B8:
|
flip__B4:
|
||||||
dey
|
dey
|
||||||
dec 104
|
dec 104
|
||||||
lda 104
|
lda 104
|
||||||
bne flip__B1_from_B8
|
bne flip__B1_from_B4
|
||||||
flip__B3_from_B8:
|
flip__B3_from_B4:
|
||||||
ldx #0
|
ldx #0
|
||||||
flip__B3_from_B3:
|
flip__B3_from_B3:
|
||||||
flip__B3:
|
flip__B3:
|
||||||
|
@ -4,8 +4,8 @@
|
|||||||
main: from @BEGIN
|
main: from @BEGIN
|
||||||
call prepare param-assignment
|
call prepare param-assignment
|
||||||
to:main::@2
|
to:main::@2
|
||||||
main::@2: from @18 @2 main
|
main::@2: from main main::@12 main::@6
|
||||||
(byte) main::c#2 ← phi( @2/(byte) main::c#1 @18/(byte) 25 main/(byte) 25 )
|
(byte) main::c#2 ← phi( main/(byte) 25 main::@6/(byte) main::c#1 main::@12/(byte) 25 )
|
||||||
to:main::@3
|
to:main::@3
|
||||||
main::@3: from main::@2 main::@3
|
main::@3: from main::@2 main::@3
|
||||||
(byte~) main::$1 ← * (word) 53266
|
(byte~) main::$1 ← * (word) 53266
|
||||||
@ -14,21 +14,21 @@ main::@3: from main::@2 main::@3
|
|||||||
main::@4: from main::@3 main::@4
|
main::@4: from main::@3 main::@4
|
||||||
(byte~) main::$3 ← * (word) 53266
|
(byte~) main::$3 ← * (word) 53266
|
||||||
if((byte~) main::$3!=(byte) 255) goto main::@4
|
if((byte~) main::$3!=(byte) 255) goto main::@4
|
||||||
to:@2
|
to:main::@6
|
||||||
@2: from main::@4
|
main::@6: from main::@4
|
||||||
(byte) main::c#1 ← -- (byte) main::c#2
|
(byte) main::c#1 ← -- (byte) main::c#2
|
||||||
if((byte) main::c#1!=(byte) 0) goto main::@2
|
if((byte) main::c#1!=(byte) 0) goto main::@2
|
||||||
to:@3
|
to:main::@7
|
||||||
@3: from @2
|
main::@7: from main::@6
|
||||||
call flip param-assignment
|
call flip param-assignment
|
||||||
to:@17
|
to:main::@11
|
||||||
@17: from @3
|
main::@11: from main::@7
|
||||||
call plot param-assignment
|
call plot param-assignment
|
||||||
to:@18
|
to:main::@12
|
||||||
@18: from @17
|
main::@12: from main::@11
|
||||||
if(true) goto main::@2
|
if(true) goto main::@2
|
||||||
to:main::@return
|
to:main::@return
|
||||||
main::@return: from @18
|
main::@return: from main::@12
|
||||||
return
|
return
|
||||||
to:@RETURN
|
to:@RETURN
|
||||||
prepare: from main
|
prepare: from main
|
||||||
@ -42,12 +42,12 @@ prepare::@1: from prepare prepare::@1
|
|||||||
prepare::@return: from prepare::@1
|
prepare::@return: from prepare::@1
|
||||||
return
|
return
|
||||||
to:@RETURN
|
to:@RETURN
|
||||||
flip: from @3
|
flip: from main::@7
|
||||||
to:flip::@1
|
to:flip::@1
|
||||||
flip::@1: from @8 flip
|
flip::@1: from flip flip::@4
|
||||||
(byte) flip::r#2 ← phi( @8/(byte) flip::r#1 flip/(byte) 16 )
|
(byte) flip::r#2 ← phi( flip/(byte) 16 flip::@4/(byte) flip::r#1 )
|
||||||
(byte) flip::srcIdx#3 ← phi( @8/(byte) flip::srcIdx#1 flip/(byte) 0 )
|
(byte) flip::srcIdx#3 ← phi( flip/(byte) 0 flip::@4/(byte) flip::srcIdx#1 )
|
||||||
(byte) flip::dstIdx#5 ← phi( @8/(byte) flip::dstIdx#2 flip/(byte) 15 )
|
(byte) flip::dstIdx#5 ← phi( flip/(byte) 15 flip::@4/(byte) flip::dstIdx#2 )
|
||||||
to:flip::@2
|
to:flip::@2
|
||||||
flip::@2: from flip::@1 flip::@2
|
flip::@2: from flip::@1 flip::@2
|
||||||
(byte) flip::c#2 ← phi( flip::@1/(byte) 16 flip::@2/(byte) flip::c#1 )
|
(byte) flip::c#2 ← phi( flip::@1/(byte) 16 flip::@2/(byte) flip::c#1 )
|
||||||
@ -59,14 +59,14 @@ flip::@2: from flip::@1 flip::@2
|
|||||||
(byte) flip::dstIdx#1 ← (byte) flip::dstIdx#3 + (byte) 16
|
(byte) flip::dstIdx#1 ← (byte) flip::dstIdx#3 + (byte) 16
|
||||||
(byte) flip::c#1 ← -- (byte) flip::c#2
|
(byte) flip::c#1 ← -- (byte) flip::c#2
|
||||||
if((byte) flip::c#1!=(byte) 0) goto flip::@2
|
if((byte) flip::c#1!=(byte) 0) goto flip::@2
|
||||||
to:@8
|
to:flip::@4
|
||||||
@8: from flip::@2
|
flip::@4: from flip::@2
|
||||||
(byte) flip::dstIdx#2 ← -- (byte) flip::dstIdx#1
|
(byte) flip::dstIdx#2 ← -- (byte) flip::dstIdx#1
|
||||||
(byte) flip::r#1 ← -- (byte) flip::r#2
|
(byte) flip::r#1 ← -- (byte) flip::r#2
|
||||||
if((byte) flip::r#1!=(byte) 0) goto flip::@1
|
if((byte) flip::r#1!=(byte) 0) goto flip::@1
|
||||||
to:flip::@3
|
to:flip::@3
|
||||||
flip::@3: from @8 flip::@3
|
flip::@3: from flip::@3 flip::@4
|
||||||
(byte) flip::i#2 ← phi( @8/(byte) 0 flip::@3/(byte) flip::i#1 )
|
(byte) flip::i#2 ← phi( flip::@3/(byte) flip::i#1 flip::@4/(byte) 0 )
|
||||||
(byte~) flip::$4 ← (word) 4352 *idx (byte) flip::i#2
|
(byte~) flip::$4 ← (word) 4352 *idx (byte) flip::i#2
|
||||||
*((word) 4096 + (byte) flip::i#2) ← (byte~) flip::$4
|
*((word) 4096 + (byte) flip::i#2) ← (byte~) flip::$4
|
||||||
(byte) flip::i#1 ← ++ (byte) flip::i#2
|
(byte) flip::i#1 ← ++ (byte) flip::i#2
|
||||||
@ -75,12 +75,12 @@ flip::@3: from @8 flip::@3
|
|||||||
flip::@return: from flip::@3
|
flip::@return: from flip::@3
|
||||||
return
|
return
|
||||||
to:@RETURN
|
to:@RETURN
|
||||||
plot: from @17
|
plot: from main::@11
|
||||||
to:plot::@1
|
to:plot::@1
|
||||||
plot::@1: from @12 plot
|
plot::@1: from plot plot::@3
|
||||||
(byte) plot::y#2 ← phi( @12/(byte) plot::y#1 plot/(byte) 16 )
|
(byte) plot::y#2 ← phi( plot/(byte) 16 plot::@3/(byte) plot::y#1 )
|
||||||
(byte) plot::i#3 ← phi( @12/(byte) plot::i#1 plot/(byte) 0 )
|
(byte) plot::i#3 ← phi( plot/(byte) 0 plot::@3/(byte) plot::i#1 )
|
||||||
(byte*) plot::line#2 ← phi( @12/(byte*) plot::line#1 plot/(word) 1236 )
|
(byte*) plot::line#2 ← phi( plot/(word) 1236 plot::@3/(byte*) plot::line#1 )
|
||||||
to:plot::@2
|
to:plot::@2
|
||||||
plot::@2: from plot::@1 plot::@2
|
plot::@2: from plot::@1 plot::@2
|
||||||
(byte) plot::x#2 ← phi( plot::@1/(byte) 0 plot::@2/(byte) plot::x#1 )
|
(byte) plot::x#2 ← phi( plot::@1/(byte) 0 plot::@2/(byte) plot::x#1 )
|
||||||
@ -90,13 +90,13 @@ plot::@2: from plot::@1 plot::@2
|
|||||||
(byte) plot::i#1 ← ++ (byte) plot::i#2
|
(byte) plot::i#1 ← ++ (byte) plot::i#2
|
||||||
(byte) plot::x#1 ← ++ (byte) plot::x#2
|
(byte) plot::x#1 ← ++ (byte) plot::x#2
|
||||||
if((byte) plot::x#1<(byte) 16) goto plot::@2
|
if((byte) plot::x#1<(byte) 16) goto plot::@2
|
||||||
to:@12
|
to:plot::@3
|
||||||
@12: from plot::@2
|
plot::@3: from plot::@2
|
||||||
(byte*) plot::line#1 ← (byte*) plot::line#2 + (byte) 40
|
(byte*) plot::line#1 ← (byte*) plot::line#2 + (byte) 40
|
||||||
(byte) plot::y#1 ← -- (byte) plot::y#2
|
(byte) plot::y#1 ← -- (byte) plot::y#2
|
||||||
if((byte) plot::y#1!=(byte) 0) goto plot::@1
|
if((byte) plot::y#1!=(byte) 0) goto plot::@1
|
||||||
to:plot::@return
|
to:plot::@return
|
||||||
plot::@return: from @12
|
plot::@return: from plot::@3
|
||||||
return
|
return
|
||||||
to:@RETURN
|
to:@RETURN
|
||||||
@END: from @BEGIN
|
@END: from @BEGIN
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1,9 +1,3 @@
|
|||||||
(label) @12
|
|
||||||
(label) @17
|
|
||||||
(label) @18
|
|
||||||
(label) @2
|
|
||||||
(label) @3
|
|
||||||
(label) @8
|
|
||||||
(label) @BEGIN
|
(label) @BEGIN
|
||||||
(label) @END
|
(label) @END
|
||||||
(byte*) RASTER
|
(byte*) RASTER
|
||||||
@ -16,6 +10,7 @@
|
|||||||
(label) flip::@1
|
(label) flip::@1
|
||||||
(label) flip::@2
|
(label) flip::@2
|
||||||
(label) flip::@3
|
(label) flip::@3
|
||||||
|
(label) flip::@4
|
||||||
(label) flip::@return
|
(label) flip::@return
|
||||||
(byte) flip::c
|
(byte) flip::c
|
||||||
(byte) flip::c#1 zp byte:103
|
(byte) flip::c#1 zp byte:103
|
||||||
@ -39,9 +34,13 @@
|
|||||||
(void()) main()
|
(void()) main()
|
||||||
(byte~) main::$1 reg byte a
|
(byte~) main::$1 reg byte a
|
||||||
(byte~) main::$3 reg byte a
|
(byte~) main::$3 reg byte a
|
||||||
|
(label) main::@11
|
||||||
|
(label) main::@12
|
||||||
(label) main::@2
|
(label) main::@2
|
||||||
(label) main::@3
|
(label) main::@3
|
||||||
(label) main::@4
|
(label) main::@4
|
||||||
|
(label) main::@6
|
||||||
|
(label) main::@7
|
||||||
(label) main::@return
|
(label) main::@return
|
||||||
(byte) main::c
|
(byte) main::c
|
||||||
(byte) main::c#1 reg byte x
|
(byte) main::c#1 reg byte x
|
||||||
@ -51,6 +50,7 @@
|
|||||||
(byte~) plot::$3 reg byte a
|
(byte~) plot::$3 reg byte a
|
||||||
(label) plot::@1
|
(label) plot::@1
|
||||||
(label) plot::@2
|
(label) plot::@2
|
||||||
|
(label) plot::@3
|
||||||
(label) plot::@return
|
(label) plot::@return
|
||||||
(byte) plot::i
|
(byte) plot::i
|
||||||
(byte) plot::i#1 reg byte x
|
(byte) plot::i#1 reg byte x
|
||||||
|
Loading…
x
Reference in New Issue
Block a user