mirror of
https://gitlab.com/camelot/kickc.git
synced 2024-12-23 13:31:12 +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. */
|
||||
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;
|
||||
|
||||
public StatementPhi(VariableRef lValue) {
|
||||
|
@ -27,6 +27,13 @@ public class Pass1GenerateControlFlowGraph {
|
||||
sequence.addStatement(new StatementLabel(scope.addLabel(END_BLOCK_NAME).getRef()));
|
||||
for (Statement statement : sequence.getStatements()) {
|
||||
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) {
|
||||
StatementLabel statementLabel = (StatementLabel) statement;
|
||||
ControlFlowBlock nextBlock = getOrCreateBlock(statementLabel.getLabel());
|
||||
@ -37,14 +44,14 @@ public class Pass1GenerateControlFlowGraph {
|
||||
StatementJump statementJump = (StatementJump) statement;
|
||||
ControlFlowBlock jmpBlock = getOrCreateBlock(statementJump.getDestination());
|
||||
currentBlock.setDefaultSuccessor(jmpBlock.getLabel());
|
||||
ControlFlowBlock nextBlock = getOrCreateBlock(scope.addLabelIntermediate().getRef());
|
||||
ControlFlowBlock nextBlock = getOrCreateBlock(currentBlockScope.addLabelIntermediate().getRef());
|
||||
blockStack.pop();
|
||||
blockStack.push(nextBlock);
|
||||
} else if(statement instanceof StatementConditionalJump) {
|
||||
currentBlock.addStatement(statement);
|
||||
StatementConditionalJump statementConditionalJump = (StatementConditionalJump) statement;
|
||||
ControlFlowBlock jmpBlock = getOrCreateBlock(statementConditionalJump.getDestination());
|
||||
ControlFlowBlock nextBlock = getOrCreateBlock(scope.addLabelIntermediate().getRef());
|
||||
ControlFlowBlock nextBlock = getOrCreateBlock(currentBlockScope.addLabelIntermediate().getRef());
|
||||
currentBlock.setDefaultSuccessor(nextBlock.getLabel());
|
||||
currentBlock.setConditionalSuccessor(jmpBlock.getLabel());
|
||||
blockStack.pop();
|
||||
@ -60,7 +67,7 @@ public class Pass1GenerateControlFlowGraph {
|
||||
} else if(statement instanceof StatementProcedureEnd) {
|
||||
// Procedure strategy implemented is currently variable-based transfer of parameters/return values
|
||||
currentBlock.setDefaultSuccessor(new Label("@RETURN", scope, false).getRef());
|
||||
ControlFlowBlock nextBlock = getOrCreateBlock(scope.addLabelIntermediate().getRef());
|
||||
ControlFlowBlock nextBlock = getOrCreateBlock(currentBlockScope.addLabelIntermediate().getRef());
|
||||
blockStack.pop();
|
||||
ControlFlowBlock prevBlock = blockStack.pop();
|
||||
prevBlock.setDefaultSuccessor(nextBlock.getLabel());
|
||||
|
@ -44,7 +44,14 @@ public class Pass1ProcedureCallParameters extends ControlFlowGraphCopyVisitor {
|
||||
copyCall.setProcedure(procedureRef);
|
||||
addStatementToCurrentBlock(copyCall);
|
||||
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())) {
|
||||
addStatementToCurrentBlock(new StatementAssignment(origCall.getlValue(), procReturnVarRef));
|
||||
} else {
|
||||
|
@ -6,9 +6,9 @@ main:
|
||||
main__B2_from_main:
|
||||
ldx #25
|
||||
jmp main__B2
|
||||
main__B2_from_B18:
|
||||
main__B2_from_B12:
|
||||
ldx #25
|
||||
main__B2_from_B2:
|
||||
main__B2_from_B6:
|
||||
main__B2:
|
||||
main__B3:
|
||||
lda 53266
|
||||
@ -18,16 +18,16 @@ main__B4:
|
||||
lda 53266
|
||||
cmp #255
|
||||
bne main__main__B4
|
||||
B2:
|
||||
main__B6:
|
||||
dex
|
||||
cpx #0
|
||||
bne main__B2_from_B2
|
||||
B3:
|
||||
bne main__B2_from_B6
|
||||
main__B7:
|
||||
jsr flip
|
||||
B17:
|
||||
main__B11:
|
||||
jsr plot
|
||||
B18:
|
||||
jmp main__B2_from_B18
|
||||
main__B12:
|
||||
jmp main__B2_from_B12
|
||||
main__Breturn:
|
||||
rts
|
||||
plot:
|
||||
@ -39,7 +39,7 @@ plot__B1_from_plot:
|
||||
sta 101
|
||||
lda #>1236
|
||||
sta 101+1
|
||||
plot__B1_from_B12:
|
||||
plot__B1_from_B3:
|
||||
plot__B1:
|
||||
plot__B2_from_B1:
|
||||
ldy #0
|
||||
@ -51,7 +51,7 @@ plot__B2:
|
||||
iny
|
||||
cpy #16
|
||||
bcc plot__B2_from_B2
|
||||
B12:
|
||||
plot__B3:
|
||||
lda 101
|
||||
clc
|
||||
adc #40
|
||||
@ -61,7 +61,7 @@ B12:
|
||||
!:
|
||||
dec 100
|
||||
lda 100
|
||||
bne plot__B1_from_B12
|
||||
bne plot__B1_from_B3
|
||||
plot__Breturn:
|
||||
rts
|
||||
flip:
|
||||
@ -70,7 +70,7 @@ flip__B1_from_flip:
|
||||
sta 104
|
||||
ldx #0
|
||||
ldy #15
|
||||
flip__B1_from_B8:
|
||||
flip__B1_from_B4:
|
||||
flip__B1:
|
||||
flip__B2_from_B1:
|
||||
lda #16
|
||||
@ -87,12 +87,12 @@ flip__B2:
|
||||
dec 103
|
||||
lda 103
|
||||
bne flip__B2_from_B2
|
||||
B8:
|
||||
flip__B4:
|
||||
dey
|
||||
dec 104
|
||||
lda 104
|
||||
bne flip__B1_from_B8
|
||||
flip__B3_from_B8:
|
||||
bne flip__B1_from_B4
|
||||
flip__B3_from_B4:
|
||||
ldx #0
|
||||
flip__B3_from_B3:
|
||||
flip__B3:
|
||||
|
@ -4,8 +4,8 @@
|
||||
main: from @BEGIN
|
||||
call prepare param-assignment
|
||||
to:main::@2
|
||||
main::@2: from @18 @2 main
|
||||
(byte) main::c#2 ← phi( @2/(byte) main::c#1 @18/(byte) 25 main/(byte) 25 )
|
||||
main::@2: from main main::@12 main::@6
|
||||
(byte) main::c#2 ← phi( main/(byte) 25 main::@6/(byte) main::c#1 main::@12/(byte) 25 )
|
||||
to:main::@3
|
||||
main::@3: from main::@2 main::@3
|
||||
(byte~) main::$1 ← * (word) 53266
|
||||
@ -14,21 +14,21 @@ main::@3: from main::@2 main::@3
|
||||
main::@4: from main::@3 main::@4
|
||||
(byte~) main::$3 ← * (word) 53266
|
||||
if((byte~) main::$3!=(byte) 255) goto main::@4
|
||||
to:@2
|
||||
@2: from main::@4
|
||||
to:main::@6
|
||||
main::@6: from main::@4
|
||||
(byte) main::c#1 ← -- (byte) main::c#2
|
||||
if((byte) main::c#1!=(byte) 0) goto main::@2
|
||||
to:@3
|
||||
@3: from @2
|
||||
to:main::@7
|
||||
main::@7: from main::@6
|
||||
call flip param-assignment
|
||||
to:@17
|
||||
@17: from @3
|
||||
to:main::@11
|
||||
main::@11: from main::@7
|
||||
call plot param-assignment
|
||||
to:@18
|
||||
@18: from @17
|
||||
to:main::@12
|
||||
main::@12: from main::@11
|
||||
if(true) goto main::@2
|
||||
to:main::@return
|
||||
main::@return: from @18
|
||||
main::@return: from main::@12
|
||||
return
|
||||
to:@RETURN
|
||||
prepare: from main
|
||||
@ -42,12 +42,12 @@ prepare::@1: from prepare prepare::@1
|
||||
prepare::@return: from prepare::@1
|
||||
return
|
||||
to:@RETURN
|
||||
flip: from @3
|
||||
flip: from main::@7
|
||||
to:flip::@1
|
||||
flip::@1: from @8 flip
|
||||
(byte) flip::r#2 ← phi( @8/(byte) flip::r#1 flip/(byte) 16 )
|
||||
(byte) flip::srcIdx#3 ← phi( @8/(byte) flip::srcIdx#1 flip/(byte) 0 )
|
||||
(byte) flip::dstIdx#5 ← phi( @8/(byte) flip::dstIdx#2 flip/(byte) 15 )
|
||||
flip::@1: from flip flip::@4
|
||||
(byte) flip::r#2 ← phi( flip/(byte) 16 flip::@4/(byte) flip::r#1 )
|
||||
(byte) flip::srcIdx#3 ← phi( flip/(byte) 0 flip::@4/(byte) flip::srcIdx#1 )
|
||||
(byte) flip::dstIdx#5 ← phi( flip/(byte) 15 flip::@4/(byte) flip::dstIdx#2 )
|
||||
to:flip::@2
|
||||
flip::@2: from flip::@1 flip::@2
|
||||
(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::c#1 ← -- (byte) flip::c#2
|
||||
if((byte) flip::c#1!=(byte) 0) goto flip::@2
|
||||
to:@8
|
||||
@8: from flip::@2
|
||||
to:flip::@4
|
||||
flip::@4: from flip::@2
|
||||
(byte) flip::dstIdx#2 ← -- (byte) flip::dstIdx#1
|
||||
(byte) flip::r#1 ← -- (byte) flip::r#2
|
||||
if((byte) flip::r#1!=(byte) 0) goto flip::@1
|
||||
to:flip::@3
|
||||
flip::@3: from @8 flip::@3
|
||||
(byte) flip::i#2 ← phi( @8/(byte) 0 flip::@3/(byte) flip::i#1 )
|
||||
flip::@3: from flip::@3 flip::@4
|
||||
(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
|
||||
*((word) 4096 + (byte) flip::i#2) ← (byte~) flip::$4
|
||||
(byte) flip::i#1 ← ++ (byte) flip::i#2
|
||||
@ -75,12 +75,12 @@ flip::@3: from @8 flip::@3
|
||||
flip::@return: from flip::@3
|
||||
return
|
||||
to:@RETURN
|
||||
plot: from @17
|
||||
plot: from main::@11
|
||||
to:plot::@1
|
||||
plot::@1: from @12 plot
|
||||
(byte) plot::y#2 ← phi( @12/(byte) plot::y#1 plot/(byte) 16 )
|
||||
(byte) plot::i#3 ← phi( @12/(byte) plot::i#1 plot/(byte) 0 )
|
||||
(byte*) plot::line#2 ← phi( @12/(byte*) plot::line#1 plot/(word) 1236 )
|
||||
plot::@1: from plot plot::@3
|
||||
(byte) plot::y#2 ← phi( plot/(byte) 16 plot::@3/(byte) plot::y#1 )
|
||||
(byte) plot::i#3 ← phi( plot/(byte) 0 plot::@3/(byte) plot::i#1 )
|
||||
(byte*) plot::line#2 ← phi( plot/(word) 1236 plot::@3/(byte*) plot::line#1 )
|
||||
to:plot::@2
|
||||
plot::@2: from plot::@1 plot::@2
|
||||
(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::x#1 ← ++ (byte) plot::x#2
|
||||
if((byte) plot::x#1<(byte) 16) goto plot::@2
|
||||
to:@12
|
||||
@12: from plot::@2
|
||||
to:plot::@3
|
||||
plot::@3: from plot::@2
|
||||
(byte*) plot::line#1 ← (byte*) plot::line#2 + (byte) 40
|
||||
(byte) plot::y#1 ← -- (byte) plot::y#2
|
||||
if((byte) plot::y#1!=(byte) 0) goto plot::@1
|
||||
to:plot::@return
|
||||
plot::@return: from @12
|
||||
plot::@return: from plot::@3
|
||||
return
|
||||
to:@RETURN
|
||||
@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) @END
|
||||
(byte*) RASTER
|
||||
@ -16,6 +10,7 @@
|
||||
(label) flip::@1
|
||||
(label) flip::@2
|
||||
(label) flip::@3
|
||||
(label) flip::@4
|
||||
(label) flip::@return
|
||||
(byte) flip::c
|
||||
(byte) flip::c#1 zp byte:103
|
||||
@ -39,9 +34,13 @@
|
||||
(void()) main()
|
||||
(byte~) main::$1 reg byte a
|
||||
(byte~) main::$3 reg byte a
|
||||
(label) main::@11
|
||||
(label) main::@12
|
||||
(label) main::@2
|
||||
(label) main::@3
|
||||
(label) main::@4
|
||||
(label) main::@6
|
||||
(label) main::@7
|
||||
(label) main::@return
|
||||
(byte) main::c
|
||||
(byte) main::c#1 reg byte x
|
||||
@ -51,6 +50,7 @@
|
||||
(byte~) plot::$3 reg byte a
|
||||
(label) plot::@1
|
||||
(label) plot::@2
|
||||
(label) plot::@3
|
||||
(label) plot::@return
|
||||
(byte) plot::i
|
||||
(byte) plot::i#1 reg byte x
|
||||
|
Loading…
Reference in New Issue
Block a user