mirror of
https://gitlab.com/camelot/kickc.git
synced 2025-02-20 00:29:10 +00:00
Added support for block comments.
This commit is contained in:
parent
f0d77acb29
commit
af54695232
@ -7,8 +7,11 @@ public class AsmComment implements AsmLine {
|
||||
|
||||
private int index;
|
||||
|
||||
public AsmComment(String comment) {
|
||||
private boolean isBlock;
|
||||
|
||||
public AsmComment(String comment, boolean isBlock) {
|
||||
this.comment = comment;
|
||||
this.isBlock = isBlock;
|
||||
}
|
||||
|
||||
public String getComment() {
|
||||
@ -27,8 +30,13 @@ public class AsmComment implements AsmLine {
|
||||
|
||||
@Override
|
||||
public String getAsm() {
|
||||
if(isBlock) {
|
||||
return "/*" + comment + "*/";
|
||||
|
||||
} else {
|
||||
return "//" + comment;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIndex() {
|
||||
@ -47,6 +55,7 @@ public class AsmComment implements AsmLine {
|
||||
|
||||
/**
|
||||
* Get the number of lines the comment has
|
||||
*
|
||||
* @return The number of lines
|
||||
*/
|
||||
public long getLineCount() {
|
||||
@ -54,5 +63,4 @@ public class AsmComment implements AsmLine {
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -52,8 +52,8 @@ public class AsmProgram {
|
||||
getCurrentSegment().addLine(line);
|
||||
}
|
||||
|
||||
public void addComment(String comment) {
|
||||
addLine(new AsmComment(comment));
|
||||
public void addComment(String comment, boolean isBlock) {
|
||||
addLine(new AsmComment(comment, isBlock));
|
||||
}
|
||||
|
||||
public AsmLabel addLabel(String label) {
|
||||
|
@ -12,10 +12,12 @@ public class Comment {
|
||||
/** Empty comments collection. */
|
||||
public static final ArrayList<Comment> NO_COMMENTS = new ArrayList<>();
|
||||
|
||||
|
||||
/** The comment. */
|
||||
private String comment;
|
||||
|
||||
/** Specifies whether the comment is a block-comment. If false the comment is a single-line comment. */
|
||||
private boolean isBlock;
|
||||
|
||||
/** The index of the hidden parser token containing the comment.
|
||||
* Used to prevent comments from being included multiple times.
|
||||
*/
|
||||
@ -36,4 +38,12 @@ public class Comment {
|
||||
public void setTokenIndex(int tokenIndex) {
|
||||
this.tokenIndex = tokenIndex;
|
||||
}
|
||||
|
||||
public boolean isBlock() {
|
||||
return isBlock;
|
||||
}
|
||||
|
||||
public void setBlock(boolean block) {
|
||||
isBlock = block;
|
||||
}
|
||||
}
|
||||
|
@ -947,11 +947,17 @@ public class Pass0GenerateStatementSequence extends KickCBaseVisitor<Object> {
|
||||
comments = new ArrayList<>();
|
||||
}
|
||||
} else if(hiddenToken.getChannel() == CHANNEL_COMMENTS) {
|
||||
boolean isBlock = false;
|
||||
String text = hiddenToken.getText();
|
||||
if(text.startsWith("//")) {
|
||||
text = text.substring(2);
|
||||
}
|
||||
if(text.startsWith("/*")) {
|
||||
text = text.substring(2, text.length()-2);
|
||||
isBlock = true;
|
||||
}
|
||||
Comment comment = new Comment(text);
|
||||
comment.setBlock(isBlock);
|
||||
comment.setTokenIndex(hiddenToken.getTokenIndex());
|
||||
comments.add( comment);
|
||||
}
|
||||
|
@ -190,7 +190,7 @@ public class Pass4CodeGeneration {
|
||||
*/
|
||||
private void generateComments(AsmProgram asm, List<Comment> comments) {
|
||||
for(Comment comment : comments) {
|
||||
asm.addComment(comment.getComment());
|
||||
asm.addComment(comment.getComment(), comment.isBlock());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -44,6 +44,11 @@ public class TestPrograms {
|
||||
AsmFragmentTemplateUsages.logUsages(log, false, false, false, false, false, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCommentsBlock() throws IOException, URISyntaxException {
|
||||
compileAndCompare("test-comments-block");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCommentsLoop() throws IOException, URISyntaxException {
|
||||
compileAndCompare("test-comments-loop");
|
||||
|
31
src/test/kc/test-comments-block.kc
Normal file
31
src/test/kc/test-comments-block.kc
Normal file
@ -0,0 +1,31 @@
|
||||
/* Tests that block comments are compiled correctly
|
||||
* Has a bunch of comments that will be moved into the generated ASM
|
||||
*/
|
||||
|
||||
// The C64 screen
|
||||
const byte* SCREEN = $400;
|
||||
|
||||
// One of the bytes used for addition
|
||||
byte a = 'a';
|
||||
|
||||
/* The program entry point */
|
||||
void main() {
|
||||
byte i = 0;
|
||||
// Do some sums
|
||||
for(byte b: 0..10 ) {
|
||||
// Output the result on the screen
|
||||
SCREEN[i++] = sum(a, b);
|
||||
}
|
||||
}
|
||||
|
||||
/** Adds up two bytes and returns the result
|
||||
* a - the first byte
|
||||
* b - the second byte
|
||||
* Returns the sum pf the two bytes
|
||||
*/
|
||||
byte sum( byte a, byte b) {
|
||||
// calculate the sum
|
||||
byte r = a+b;
|
||||
// return the sum
|
||||
return r;
|
||||
}
|
36
src/test/ref/test-comments-block.asm
Normal file
36
src/test/ref/test-comments-block.asm
Normal file
@ -0,0 +1,36 @@
|
||||
/* Tests that block comments are compiled correctly
|
||||
* Has a bunch of comments that will be moved into the generated ASM
|
||||
*/
|
||||
.pc = $801 "Basic"
|
||||
:BasicUpstart(main)
|
||||
.pc = $80d "Program"
|
||||
// The C64 screen
|
||||
.label SCREEN = $400
|
||||
// One of the bytes used for addition
|
||||
.const a = 'a'
|
||||
/* The program entry point */
|
||||
main: {
|
||||
ldx #0
|
||||
ldy #0
|
||||
// Do some sums
|
||||
b1:
|
||||
jsr sum
|
||||
// Output the result on the screen
|
||||
sta SCREEN,x
|
||||
inx
|
||||
iny
|
||||
cpy #$b
|
||||
bne b1
|
||||
rts
|
||||
}
|
||||
/** Adds up two bytes and returns the result
|
||||
* a - the first byte
|
||||
* b - the second byte
|
||||
* Returns the sum pf the two bytes
|
||||
*/
|
||||
sum: {
|
||||
tya
|
||||
clc
|
||||
adc #a
|
||||
rts
|
||||
}
|
35
src/test/ref/test-comments-block.cfg
Normal file
35
src/test/ref/test-comments-block.cfg
Normal file
@ -0,0 +1,35 @@
|
||||
@begin: scope:[] from
|
||||
[0] phi()
|
||||
to:@2
|
||||
@2: scope:[] from @begin
|
||||
[1] phi()
|
||||
[2] call main
|
||||
to:@end
|
||||
@end: scope:[] from @2
|
||||
[3] phi()
|
||||
main: scope:[main] from @2
|
||||
[4] phi()
|
||||
to:main::@1
|
||||
main::@1: scope:[main] from main main::@3
|
||||
[5] (byte) main::i#2 ← phi( main/(byte/signed byte/word/signed word/dword/signed dword) 0 main::@3/(byte) main::i#1 )
|
||||
[5] (byte) main::b#2 ← phi( main/(byte/signed byte/word/signed word/dword/signed dword) 0 main::@3/(byte) main::b#1 )
|
||||
[6] (byte) sum::b#0 ← (byte) main::b#2
|
||||
[7] call sum
|
||||
[8] (byte) sum::return#0 ← (byte) sum::return#1
|
||||
to:main::@3
|
||||
main::@3: scope:[main] from main::@1
|
||||
[9] (byte~) main::$0 ← (byte) sum::return#0
|
||||
[10] *((const byte*) SCREEN#0 + (byte) main::i#2) ← (byte~) main::$0
|
||||
[11] (byte) main::i#1 ← ++ (byte) main::i#2
|
||||
[12] (byte) main::b#1 ← ++ (byte) main::b#2
|
||||
[13] if((byte) main::b#1!=(byte/signed byte/word/signed word/dword/signed dword) 11) goto main::@1
|
||||
to:main::@return
|
||||
main::@return: scope:[main] from main::@3
|
||||
[14] return
|
||||
to:@return
|
||||
sum: scope:[sum] from main::@1
|
||||
[15] (byte) sum::return#1 ← (const byte) a#0 + (byte) sum::b#0
|
||||
to:sum::@return
|
||||
sum::@return: scope:[sum] from sum
|
||||
[16] return
|
||||
to:@return
|
591
src/test/ref/test-comments-block.log
Normal file
591
src/test/ref/test-comments-block.log
Normal file
@ -0,0 +1,591 @@
|
||||
|
||||
CONTROL FLOW GRAPH SSA
|
||||
@begin: scope:[] from
|
||||
(byte*) SCREEN#0 ← ((byte*)) (word/signed word/dword/signed dword) 1024
|
||||
(byte) a#0 ← (byte) 'a'
|
||||
to:@2
|
||||
main: scope:[main] from @2
|
||||
(byte) a#2 ← phi( @2/(byte) a#4 )
|
||||
(byte) main::i#0 ← (byte/signed byte/word/signed word/dword/signed dword) 0
|
||||
(byte) main::b#0 ← (byte/signed byte/word/signed word/dword/signed dword) 0
|
||||
to:main::@1
|
||||
main::@1: scope:[main] from main main::@3
|
||||
(byte) main::i#3 ← phi( main/(byte) main::i#0 main::@3/(byte) main::i#1 )
|
||||
(byte) main::b#2 ← phi( main/(byte) main::b#0 main::@3/(byte) main::b#1 )
|
||||
(byte) a#1 ← phi( main/(byte) a#2 main::@3/(byte) a#3 )
|
||||
(byte) sum::a#0 ← (byte) a#1
|
||||
(byte) sum::b#0 ← (byte) main::b#2
|
||||
call sum
|
||||
(byte) sum::return#0 ← (byte) sum::return#2
|
||||
to:main::@3
|
||||
main::@3: scope:[main] from main::@1
|
||||
(byte) a#3 ← phi( main::@1/(byte) a#1 )
|
||||
(byte) main::b#3 ← phi( main::@1/(byte) main::b#2 )
|
||||
(byte) main::i#2 ← phi( main::@1/(byte) main::i#3 )
|
||||
(byte) sum::return#3 ← phi( main::@1/(byte) sum::return#0 )
|
||||
(byte~) main::$0 ← (byte) sum::return#3
|
||||
*((byte*) SCREEN#0 + (byte) main::i#2) ← (byte~) main::$0
|
||||
(byte) main::i#1 ← ++ (byte) main::i#2
|
||||
(byte) main::b#1 ← (byte) main::b#3 + rangenext(0,10)
|
||||
(bool~) main::$1 ← (byte) main::b#1 != rangelast(0,10)
|
||||
if((bool~) main::$1) goto main::@1
|
||||
to:main::@return
|
||||
main::@return: scope:[main] from main::@3
|
||||
return
|
||||
to:@return
|
||||
sum: scope:[sum] from main::@1
|
||||
(byte) sum::b#1 ← phi( main::@1/(byte) sum::b#0 )
|
||||
(byte) sum::a#1 ← phi( main::@1/(byte) sum::a#0 )
|
||||
(byte~) sum::$0 ← (byte) sum::a#1 + (byte) sum::b#1
|
||||
(byte) sum::r#0 ← (byte~) sum::$0
|
||||
(byte) sum::return#1 ← (byte) sum::r#0
|
||||
to:sum::@return
|
||||
sum::@return: scope:[sum] from sum
|
||||
(byte) sum::return#4 ← phi( sum/(byte) sum::return#1 )
|
||||
(byte) sum::return#2 ← (byte) sum::return#4
|
||||
return
|
||||
to:@return
|
||||
@2: scope:[] from @begin
|
||||
(byte) a#4 ← phi( @begin/(byte) a#0 )
|
||||
call main
|
||||
to:@3
|
||||
@3: scope:[] from @2
|
||||
to:@end
|
||||
@end: scope:[] from @3
|
||||
|
||||
SYMBOL TABLE SSA
|
||||
(label) @2
|
||||
(label) @3
|
||||
(label) @begin
|
||||
(label) @end
|
||||
(byte*) SCREEN
|
||||
(byte*) SCREEN#0
|
||||
(byte) a
|
||||
(byte) a#0
|
||||
(byte) a#1
|
||||
(byte) a#2
|
||||
(byte) a#3
|
||||
(byte) a#4
|
||||
(void()) main()
|
||||
(byte~) main::$0
|
||||
(bool~) main::$1
|
||||
(label) main::@1
|
||||
(label) main::@3
|
||||
(label) main::@return
|
||||
(byte) main::b
|
||||
(byte) main::b#0
|
||||
(byte) main::b#1
|
||||
(byte) main::b#2
|
||||
(byte) main::b#3
|
||||
(byte) main::i
|
||||
(byte) main::i#0
|
||||
(byte) main::i#1
|
||||
(byte) main::i#2
|
||||
(byte) main::i#3
|
||||
(byte()) sum((byte) sum::a , (byte) sum::b)
|
||||
(byte~) sum::$0
|
||||
(label) sum::@return
|
||||
(byte) sum::a
|
||||
(byte) sum::a#0
|
||||
(byte) sum::a#1
|
||||
(byte) sum::b
|
||||
(byte) sum::b#0
|
||||
(byte) sum::b#1
|
||||
(byte) sum::r
|
||||
(byte) sum::r#0
|
||||
(byte) sum::return
|
||||
(byte) sum::return#0
|
||||
(byte) sum::return#1
|
||||
(byte) sum::return#2
|
||||
(byte) sum::return#3
|
||||
(byte) sum::return#4
|
||||
|
||||
Culled Empty Block (label) @3
|
||||
Successful SSA optimization Pass2CullEmptyBlocks
|
||||
Alias (byte) sum::return#0 = (byte) sum::return#3
|
||||
Alias (byte) main::i#2 = (byte) main::i#3
|
||||
Alias (byte) main::b#2 = (byte) main::b#3
|
||||
Alias (byte) a#1 = (byte) a#3
|
||||
Alias (byte) sum::return#1 = (byte) sum::r#0 (byte~) sum::$0 (byte) sum::return#4 (byte) sum::return#2
|
||||
Alias (byte) a#0 = (byte) a#4
|
||||
Successful SSA optimization Pass2AliasElimination
|
||||
Self Phi Eliminated (byte) a#1
|
||||
Successful SSA optimization Pass2SelfPhiElimination
|
||||
Redundant Phi (byte) a#2 (byte) a#0
|
||||
Redundant Phi (byte) a#1 (byte) a#2
|
||||
Redundant Phi (byte) sum::a#1 (byte) sum::a#0
|
||||
Redundant Phi (byte) sum::b#1 (byte) sum::b#0
|
||||
Successful SSA optimization Pass2RedundantPhiElimination
|
||||
Simple Condition (bool~) main::$1 [16] if((byte) main::b#1!=rangelast(0,10)) goto main::@1
|
||||
Successful SSA optimization Pass2ConditionalJumpSimplification
|
||||
Constant (const byte*) SCREEN#0 = ((byte*))1024
|
||||
Constant (const byte) a#0 = 'a'
|
||||
Constant (const byte) main::i#0 = 0
|
||||
Constant (const byte) main::b#0 = 0
|
||||
Successful SSA optimization Pass2ConstantIdentification
|
||||
Constant (const byte) sum::a#0 = a#0
|
||||
Successful SSA optimization Pass2ConstantIdentification
|
||||
Resolved ranged next value main::b#1 ← ++ main::b#2 to ++
|
||||
Resolved ranged comparison value if(main::b#1!=rangelast(0,10)) goto main::@1 to (byte/signed byte/word/signed word/dword/signed dword) 11
|
||||
Inlining constant with var siblings (const byte) main::i#0
|
||||
Inlining constant with var siblings (const byte) main::b#0
|
||||
Constant inlined main::i#0 = (byte/signed byte/word/signed word/dword/signed dword) 0
|
||||
Constant inlined sum::a#0 = (const byte) a#0
|
||||
Constant inlined main::b#0 = (byte/signed byte/word/signed word/dword/signed dword) 0
|
||||
Successful SSA optimization Pass2ConstantInlining
|
||||
Added new block during phi lifting main::@4(between main::@3 and main::@1)
|
||||
Adding NOP phi() at start of @begin
|
||||
Adding NOP phi() at start of @2
|
||||
Adding NOP phi() at start of @end
|
||||
Adding NOP phi() at start of main
|
||||
CALL GRAPH
|
||||
Calls in [] to main:2
|
||||
Calls in [main] to sum:7
|
||||
|
||||
Created 2 initial phi equivalence classes
|
||||
Coalesced [15] main::b#4 ← main::b#1
|
||||
Coalesced [16] main::i#4 ← main::i#1
|
||||
Coalesced down to 2 phi equivalence classes
|
||||
Culled Empty Block (label) main::@4
|
||||
Adding NOP phi() at start of @begin
|
||||
Adding NOP phi() at start of @2
|
||||
Adding NOP phi() at start of @end
|
||||
Adding NOP phi() at start of main
|
||||
|
||||
FINAL CONTROL FLOW GRAPH
|
||||
@begin: scope:[] from
|
||||
[0] phi()
|
||||
to:@2
|
||||
@2: scope:[] from @begin
|
||||
[1] phi()
|
||||
[2] call main
|
||||
to:@end
|
||||
@end: scope:[] from @2
|
||||
[3] phi()
|
||||
main: scope:[main] from @2
|
||||
[4] phi()
|
||||
to:main::@1
|
||||
main::@1: scope:[main] from main main::@3
|
||||
[5] (byte) main::i#2 ← phi( main/(byte/signed byte/word/signed word/dword/signed dword) 0 main::@3/(byte) main::i#1 )
|
||||
[5] (byte) main::b#2 ← phi( main/(byte/signed byte/word/signed word/dword/signed dword) 0 main::@3/(byte) main::b#1 )
|
||||
[6] (byte) sum::b#0 ← (byte) main::b#2
|
||||
[7] call sum
|
||||
[8] (byte) sum::return#0 ← (byte) sum::return#1
|
||||
to:main::@3
|
||||
main::@3: scope:[main] from main::@1
|
||||
[9] (byte~) main::$0 ← (byte) sum::return#0
|
||||
[10] *((const byte*) SCREEN#0 + (byte) main::i#2) ← (byte~) main::$0
|
||||
[11] (byte) main::i#1 ← ++ (byte) main::i#2
|
||||
[12] (byte) main::b#1 ← ++ (byte) main::b#2
|
||||
[13] if((byte) main::b#1!=(byte/signed byte/word/signed word/dword/signed dword) 11) goto main::@1
|
||||
to:main::@return
|
||||
main::@return: scope:[main] from main::@3
|
||||
[14] return
|
||||
to:@return
|
||||
sum: scope:[sum] from main::@1
|
||||
[15] (byte) sum::return#1 ← (const byte) a#0 + (byte) sum::b#0
|
||||
to:sum::@return
|
||||
sum::@return: scope:[sum] from sum
|
||||
[16] return
|
||||
to:@return
|
||||
|
||||
|
||||
VARIABLE REGISTER WEIGHTS
|
||||
(byte*) SCREEN
|
||||
(byte) a
|
||||
(void()) main()
|
||||
(byte~) main::$0 22.0
|
||||
(byte) main::b
|
||||
(byte) main::b#1 16.5
|
||||
(byte) main::b#2 4.714285714285714
|
||||
(byte) main::i
|
||||
(byte) main::i#1 7.333333333333333
|
||||
(byte) main::i#2 5.5
|
||||
(byte()) sum((byte) sum::a , (byte) sum::b)
|
||||
(byte) sum::a
|
||||
(byte) sum::b
|
||||
(byte) sum::b#0 13.0
|
||||
(byte) sum::r
|
||||
(byte) sum::return
|
||||
(byte) sum::return#0 22.0
|
||||
(byte) sum::return#1 4.333333333333333
|
||||
|
||||
Initial phi equivalence classes
|
||||
[ main::b#2 main::b#1 ]
|
||||
[ main::i#2 main::i#1 ]
|
||||
Added variable sum::b#0 to zero page equivalence class [ sum::b#0 ]
|
||||
Added variable sum::return#0 to zero page equivalence class [ sum::return#0 ]
|
||||
Added variable main::$0 to zero page equivalence class [ main::$0 ]
|
||||
Added variable sum::return#1 to zero page equivalence class [ sum::return#1 ]
|
||||
Complete equivalence classes
|
||||
[ main::b#2 main::b#1 ]
|
||||
[ main::i#2 main::i#1 ]
|
||||
[ sum::b#0 ]
|
||||
[ sum::return#0 ]
|
||||
[ main::$0 ]
|
||||
[ sum::return#1 ]
|
||||
Allocated zp ZP_BYTE:2 [ main::b#2 main::b#1 ]
|
||||
Allocated zp ZP_BYTE:3 [ main::i#2 main::i#1 ]
|
||||
Allocated zp ZP_BYTE:4 [ sum::b#0 ]
|
||||
Allocated zp ZP_BYTE:5 [ sum::return#0 ]
|
||||
Allocated zp ZP_BYTE:6 [ main::$0 ]
|
||||
Allocated zp ZP_BYTE:7 [ sum::return#1 ]
|
||||
|
||||
INITIAL ASM
|
||||
//SEG0 File Comments
|
||||
/* Tests that block comments are compiled correctly
|
||||
* Has a bunch of comments that will be moved into the generated ASM
|
||||
*/
|
||||
//SEG1 Basic Upstart
|
||||
.pc = $801 "Basic"
|
||||
:BasicUpstart(bbegin)
|
||||
.pc = $80d "Program"
|
||||
//SEG2 Global Constants & labels
|
||||
// The C64 screen
|
||||
.label SCREEN = $400
|
||||
// One of the bytes used for addition
|
||||
.const a = 'a'
|
||||
//SEG3 @begin
|
||||
bbegin:
|
||||
//SEG4 [1] phi from @begin to @2 [phi:@begin->@2]
|
||||
b2_from_bbegin:
|
||||
jmp b2
|
||||
//SEG5 @2
|
||||
b2:
|
||||
//SEG6 [2] call main
|
||||
//SEG7 [4] phi from @2 to main [phi:@2->main]
|
||||
main_from_b2:
|
||||
jsr main
|
||||
//SEG8 [3] phi from @2 to @end [phi:@2->@end]
|
||||
bend_from_b2:
|
||||
jmp bend
|
||||
//SEG9 @end
|
||||
bend:
|
||||
//SEG10 main
|
||||
/* The program entry point */
|
||||
main: {
|
||||
.label _0 = 6
|
||||
.label i = 3
|
||||
.label b = 2
|
||||
//SEG11 [5] phi from main to main::@1 [phi:main->main::@1]
|
||||
b1_from_main:
|
||||
//SEG12 [5] phi (byte) main::i#2 = (byte/signed byte/word/signed word/dword/signed dword) 0 [phi:main->main::@1#0] -- vbuz1=vbuc1
|
||||
lda #0
|
||||
sta i
|
||||
//SEG13 [5] phi (byte) main::b#2 = (byte/signed byte/word/signed word/dword/signed dword) 0 [phi:main->main::@1#1] -- vbuz1=vbuc1
|
||||
lda #0
|
||||
sta b
|
||||
jmp b1
|
||||
// Do some sums
|
||||
//SEG14 [5] phi from main::@3 to main::@1 [phi:main::@3->main::@1]
|
||||
b1_from_b3:
|
||||
//SEG15 [5] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@3->main::@1#0] -- register_copy
|
||||
//SEG16 [5] phi (byte) main::b#2 = (byte) main::b#1 [phi:main::@3->main::@1#1] -- register_copy
|
||||
jmp b1
|
||||
//SEG17 main::@1
|
||||
b1:
|
||||
//SEG18 [6] (byte) sum::b#0 ← (byte) main::b#2 -- vbuz1=vbuz2
|
||||
lda b
|
||||
sta sum.b
|
||||
//SEG19 [7] call sum
|
||||
jsr sum
|
||||
//SEG20 [8] (byte) sum::return#0 ← (byte) sum::return#1 -- vbuz1=vbuz2
|
||||
lda sum.return_1
|
||||
sta sum.return
|
||||
jmp b3
|
||||
//SEG21 main::@3
|
||||
b3:
|
||||
//SEG22 [9] (byte~) main::$0 ← (byte) sum::return#0 -- vbuz1=vbuz2
|
||||
lda sum.return
|
||||
sta _0
|
||||
//SEG23 [10] *((const byte*) SCREEN#0 + (byte) main::i#2) ← (byte~) main::$0 -- pbuc1_derefidx_vbuz1=vbuz2
|
||||
// Output the result on the screen
|
||||
lda _0
|
||||
ldy i
|
||||
sta SCREEN,y
|
||||
//SEG24 [11] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuz1=_inc_vbuz1
|
||||
inc i
|
||||
//SEG25 [12] (byte) main::b#1 ← ++ (byte) main::b#2 -- vbuz1=_inc_vbuz1
|
||||
inc b
|
||||
//SEG26 [13] if((byte) main::b#1!=(byte/signed byte/word/signed word/dword/signed dword) 11) goto main::@1 -- vbuz1_neq_vbuc1_then_la1
|
||||
lda b
|
||||
cmp #$b
|
||||
bne b1_from_b3
|
||||
jmp breturn
|
||||
//SEG27 main::@return
|
||||
breturn:
|
||||
//SEG28 [14] return
|
||||
rts
|
||||
}
|
||||
//SEG29 sum
|
||||
/** Adds up two bytes and returns the result
|
||||
* a - the first byte
|
||||
* b - the second byte
|
||||
* Returns the sum pf the two bytes
|
||||
*/
|
||||
sum: {
|
||||
.label b = 4
|
||||
.label return = 5
|
||||
.label return_1 = 7
|
||||
//SEG30 [15] (byte) sum::return#1 ← (const byte) a#0 + (byte) sum::b#0 -- vbuz1=vbuc1_plus_vbuz2
|
||||
lda #a
|
||||
clc
|
||||
adc b
|
||||
sta return_1
|
||||
jmp breturn
|
||||
//SEG31 sum::@return
|
||||
breturn:
|
||||
//SEG32 [16] return
|
||||
rts
|
||||
}
|
||||
|
||||
REGISTER UPLIFT POTENTIAL REGISTERS
|
||||
Statement [15] (byte) sum::return#1 ← (const byte) a#0 + (byte) sum::b#0 [ sum::return#1 ] ( main:2::sum:7 [ main::b#2 main::i#2 sum::return#1 ] ) always clobbers reg byte a
|
||||
Removing always clobbered register reg byte a as potential for zp ZP_BYTE:2 [ main::b#2 main::b#1 ]
|
||||
Removing always clobbered register reg byte a as potential for zp ZP_BYTE:3 [ main::i#2 main::i#1 ]
|
||||
Statement [15] (byte) sum::return#1 ← (const byte) a#0 + (byte) sum::b#0 [ sum::return#1 ] ( main:2::sum:7 [ main::b#2 main::i#2 sum::return#1 ] ) always clobbers reg byte a
|
||||
Potential registers zp ZP_BYTE:2 [ main::b#2 main::b#1 ] : zp ZP_BYTE:2 , reg byte x , reg byte y ,
|
||||
Potential registers zp ZP_BYTE:3 [ main::i#2 main::i#1 ] : zp ZP_BYTE:3 , reg byte x , reg byte y ,
|
||||
Potential registers zp ZP_BYTE:4 [ sum::b#0 ] : zp ZP_BYTE:4 , reg byte a , reg byte x , reg byte y ,
|
||||
Potential registers zp ZP_BYTE:5 [ sum::return#0 ] : zp ZP_BYTE:5 , reg byte a , reg byte x , reg byte y ,
|
||||
Potential registers zp ZP_BYTE:6 [ main::$0 ] : zp ZP_BYTE:6 , reg byte a , reg byte x , reg byte y ,
|
||||
Potential registers zp ZP_BYTE:7 [ sum::return#1 ] : zp ZP_BYTE:7 , reg byte a , reg byte x , reg byte y ,
|
||||
|
||||
REGISTER UPLIFT SCOPES
|
||||
Uplift Scope [main] 22: zp ZP_BYTE:6 [ main::$0 ] 21.21: zp ZP_BYTE:2 [ main::b#2 main::b#1 ] 12.83: zp ZP_BYTE:3 [ main::i#2 main::i#1 ]
|
||||
Uplift Scope [sum] 22: zp ZP_BYTE:5 [ sum::return#0 ] 13: zp ZP_BYTE:4 [ sum::b#0 ] 4.33: zp ZP_BYTE:7 [ sum::return#1 ]
|
||||
Uplift Scope []
|
||||
|
||||
Uplifting [main] best 512 combination reg byte a [ main::$0 ] reg byte y [ main::b#2 main::b#1 ] reg byte x [ main::i#2 main::i#1 ]
|
||||
Uplifting [sum] best 388 combination reg byte a [ sum::return#0 ] reg byte y [ sum::b#0 ] reg byte a [ sum::return#1 ]
|
||||
Uplifting [] best 388 combination
|
||||
|
||||
ASSEMBLER BEFORE OPTIMIZATION
|
||||
//SEG0 File Comments
|
||||
/* Tests that block comments are compiled correctly
|
||||
* Has a bunch of comments that will be moved into the generated ASM
|
||||
*/
|
||||
//SEG1 Basic Upstart
|
||||
.pc = $801 "Basic"
|
||||
:BasicUpstart(bbegin)
|
||||
.pc = $80d "Program"
|
||||
//SEG2 Global Constants & labels
|
||||
// The C64 screen
|
||||
.label SCREEN = $400
|
||||
// One of the bytes used for addition
|
||||
.const a = 'a'
|
||||
//SEG3 @begin
|
||||
bbegin:
|
||||
//SEG4 [1] phi from @begin to @2 [phi:@begin->@2]
|
||||
b2_from_bbegin:
|
||||
jmp b2
|
||||
//SEG5 @2
|
||||
b2:
|
||||
//SEG6 [2] call main
|
||||
//SEG7 [4] phi from @2 to main [phi:@2->main]
|
||||
main_from_b2:
|
||||
jsr main
|
||||
//SEG8 [3] phi from @2 to @end [phi:@2->@end]
|
||||
bend_from_b2:
|
||||
jmp bend
|
||||
//SEG9 @end
|
||||
bend:
|
||||
//SEG10 main
|
||||
/* The program entry point */
|
||||
main: {
|
||||
//SEG11 [5] phi from main to main::@1 [phi:main->main::@1]
|
||||
b1_from_main:
|
||||
//SEG12 [5] phi (byte) main::i#2 = (byte/signed byte/word/signed word/dword/signed dword) 0 [phi:main->main::@1#0] -- vbuxx=vbuc1
|
||||
ldx #0
|
||||
//SEG13 [5] phi (byte) main::b#2 = (byte/signed byte/word/signed word/dword/signed dword) 0 [phi:main->main::@1#1] -- vbuyy=vbuc1
|
||||
ldy #0
|
||||
jmp b1
|
||||
// Do some sums
|
||||
//SEG14 [5] phi from main::@3 to main::@1 [phi:main::@3->main::@1]
|
||||
b1_from_b3:
|
||||
//SEG15 [5] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@3->main::@1#0] -- register_copy
|
||||
//SEG16 [5] phi (byte) main::b#2 = (byte) main::b#1 [phi:main::@3->main::@1#1] -- register_copy
|
||||
jmp b1
|
||||
//SEG17 main::@1
|
||||
b1:
|
||||
//SEG18 [6] (byte) sum::b#0 ← (byte) main::b#2
|
||||
//SEG19 [7] call sum
|
||||
jsr sum
|
||||
//SEG20 [8] (byte) sum::return#0 ← (byte) sum::return#1
|
||||
jmp b3
|
||||
//SEG21 main::@3
|
||||
b3:
|
||||
//SEG22 [9] (byte~) main::$0 ← (byte) sum::return#0
|
||||
//SEG23 [10] *((const byte*) SCREEN#0 + (byte) main::i#2) ← (byte~) main::$0 -- pbuc1_derefidx_vbuxx=vbuaa
|
||||
// Output the result on the screen
|
||||
sta SCREEN,x
|
||||
//SEG24 [11] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuxx=_inc_vbuxx
|
||||
inx
|
||||
//SEG25 [12] (byte) main::b#1 ← ++ (byte) main::b#2 -- vbuyy=_inc_vbuyy
|
||||
iny
|
||||
//SEG26 [13] if((byte) main::b#1!=(byte/signed byte/word/signed word/dword/signed dword) 11) goto main::@1 -- vbuyy_neq_vbuc1_then_la1
|
||||
cpy #$b
|
||||
bne b1_from_b3
|
||||
jmp breturn
|
||||
//SEG27 main::@return
|
||||
breturn:
|
||||
//SEG28 [14] return
|
||||
rts
|
||||
}
|
||||
//SEG29 sum
|
||||
/** Adds up two bytes and returns the result
|
||||
* a - the first byte
|
||||
* b - the second byte
|
||||
* Returns the sum pf the two bytes
|
||||
*/
|
||||
sum: {
|
||||
//SEG30 [15] (byte) sum::return#1 ← (const byte) a#0 + (byte) sum::b#0 -- vbuaa=vbuc1_plus_vbuyy
|
||||
tya
|
||||
clc
|
||||
adc #a
|
||||
jmp breturn
|
||||
//SEG31 sum::@return
|
||||
breturn:
|
||||
//SEG32 [16] return
|
||||
rts
|
||||
}
|
||||
|
||||
ASSEMBLER OPTIMIZATIONS
|
||||
Removing instruction jmp b2
|
||||
Removing instruction jmp bend
|
||||
Removing instruction jmp b1
|
||||
Removing instruction jmp b3
|
||||
Removing instruction jmp breturn
|
||||
Removing instruction jmp breturn
|
||||
Succesful ASM optimization Pass5NextJumpElimination
|
||||
Replacing label b1_from_b3 with b1
|
||||
Removing instruction b2_from_bbegin:
|
||||
Removing instruction b2:
|
||||
Removing instruction main_from_b2:
|
||||
Removing instruction bend_from_b2:
|
||||
Removing instruction b1_from_b3:
|
||||
Succesful ASM optimization Pass5RedundantLabelElimination
|
||||
Removing instruction bend:
|
||||
Removing instruction b1_from_main:
|
||||
Removing instruction b3:
|
||||
Removing instruction breturn:
|
||||
Removing instruction breturn:
|
||||
Succesful ASM optimization Pass5UnusedLabelElimination
|
||||
Updating BasicUpstart to call main directly
|
||||
Removing instruction jsr main
|
||||
Succesful ASM optimization Pass5SkipBegin
|
||||
Removing instruction jmp b1
|
||||
Succesful ASM optimization Pass5NextJumpElimination
|
||||
Removing instruction bbegin:
|
||||
Succesful ASM optimization Pass5UnusedLabelElimination
|
||||
|
||||
FINAL SYMBOL TABLE
|
||||
(label) @2
|
||||
(label) @begin
|
||||
(label) @end
|
||||
(byte*) SCREEN
|
||||
(const byte*) SCREEN#0 SCREEN = ((byte*))(word/signed word/dword/signed dword) 1024
|
||||
(byte) a
|
||||
(const byte) a#0 a = (byte) 'a'
|
||||
(void()) main()
|
||||
(byte~) main::$0 reg byte a 22.0
|
||||
(label) main::@1
|
||||
(label) main::@3
|
||||
(label) main::@return
|
||||
(byte) main::b
|
||||
(byte) main::b#1 reg byte y 16.5
|
||||
(byte) main::b#2 reg byte y 4.714285714285714
|
||||
(byte) main::i
|
||||
(byte) main::i#1 reg byte x 7.333333333333333
|
||||
(byte) main::i#2 reg byte x 5.5
|
||||
(byte()) sum((byte) sum::a , (byte) sum::b)
|
||||
(label) sum::@return
|
||||
(byte) sum::a
|
||||
(byte) sum::b
|
||||
(byte) sum::b#0 reg byte y 13.0
|
||||
(byte) sum::r
|
||||
(byte) sum::return
|
||||
(byte) sum::return#0 reg byte a 22.0
|
||||
(byte) sum::return#1 reg byte a 4.333333333333333
|
||||
|
||||
reg byte y [ main::b#2 main::b#1 ]
|
||||
reg byte x [ main::i#2 main::i#1 ]
|
||||
reg byte y [ sum::b#0 ]
|
||||
reg byte a [ sum::return#0 ]
|
||||
reg byte a [ main::$0 ]
|
||||
reg byte a [ sum::return#1 ]
|
||||
|
||||
|
||||
FINAL ASSEMBLER
|
||||
Score: 253
|
||||
|
||||
//SEG0 File Comments
|
||||
/* Tests that block comments are compiled correctly
|
||||
* Has a bunch of comments that will be moved into the generated ASM
|
||||
*/
|
||||
//SEG1 Basic Upstart
|
||||
.pc = $801 "Basic"
|
||||
:BasicUpstart(main)
|
||||
.pc = $80d "Program"
|
||||
//SEG2 Global Constants & labels
|
||||
// The C64 screen
|
||||
.label SCREEN = $400
|
||||
// One of the bytes used for addition
|
||||
.const a = 'a'
|
||||
//SEG3 @begin
|
||||
//SEG4 [1] phi from @begin to @2 [phi:@begin->@2]
|
||||
//SEG5 @2
|
||||
//SEG6 [2] call main
|
||||
//SEG7 [4] phi from @2 to main [phi:@2->main]
|
||||
//SEG8 [3] phi from @2 to @end [phi:@2->@end]
|
||||
//SEG9 @end
|
||||
//SEG10 main
|
||||
/* The program entry point */
|
||||
main: {
|
||||
//SEG11 [5] phi from main to main::@1 [phi:main->main::@1]
|
||||
//SEG12 [5] phi (byte) main::i#2 = (byte/signed byte/word/signed word/dword/signed dword) 0 [phi:main->main::@1#0] -- vbuxx=vbuc1
|
||||
ldx #0
|
||||
//SEG13 [5] phi (byte) main::b#2 = (byte/signed byte/word/signed word/dword/signed dword) 0 [phi:main->main::@1#1] -- vbuyy=vbuc1
|
||||
ldy #0
|
||||
// Do some sums
|
||||
//SEG14 [5] phi from main::@3 to main::@1 [phi:main::@3->main::@1]
|
||||
//SEG15 [5] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@3->main::@1#0] -- register_copy
|
||||
//SEG16 [5] phi (byte) main::b#2 = (byte) main::b#1 [phi:main::@3->main::@1#1] -- register_copy
|
||||
//SEG17 main::@1
|
||||
b1:
|
||||
//SEG18 [6] (byte) sum::b#0 ← (byte) main::b#2
|
||||
//SEG19 [7] call sum
|
||||
jsr sum
|
||||
//SEG20 [8] (byte) sum::return#0 ← (byte) sum::return#1
|
||||
//SEG21 main::@3
|
||||
//SEG22 [9] (byte~) main::$0 ← (byte) sum::return#0
|
||||
//SEG23 [10] *((const byte*) SCREEN#0 + (byte) main::i#2) ← (byte~) main::$0 -- pbuc1_derefidx_vbuxx=vbuaa
|
||||
// Output the result on the screen
|
||||
sta SCREEN,x
|
||||
//SEG24 [11] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuxx=_inc_vbuxx
|
||||
inx
|
||||
//SEG25 [12] (byte) main::b#1 ← ++ (byte) main::b#2 -- vbuyy=_inc_vbuyy
|
||||
iny
|
||||
//SEG26 [13] if((byte) main::b#1!=(byte/signed byte/word/signed word/dword/signed dword) 11) goto main::@1 -- vbuyy_neq_vbuc1_then_la1
|
||||
cpy #$b
|
||||
bne b1
|
||||
//SEG27 main::@return
|
||||
//SEG28 [14] return
|
||||
rts
|
||||
}
|
||||
//SEG29 sum
|
||||
/** Adds up two bytes and returns the result
|
||||
* a - the first byte
|
||||
* b - the second byte
|
||||
* Returns the sum pf the two bytes
|
||||
*/
|
||||
sum: {
|
||||
//SEG30 [15] (byte) sum::return#1 ← (const byte) a#0 + (byte) sum::b#0 -- vbuaa=vbuc1_plus_vbuyy
|
||||
tya
|
||||
clc
|
||||
adc #a
|
||||
//SEG31 sum::@return
|
||||
//SEG32 [16] return
|
||||
rts
|
||||
}
|
||||
|
34
src/test/ref/test-comments-block.sym
Normal file
34
src/test/ref/test-comments-block.sym
Normal file
@ -0,0 +1,34 @@
|
||||
(label) @2
|
||||
(label) @begin
|
||||
(label) @end
|
||||
(byte*) SCREEN
|
||||
(const byte*) SCREEN#0 SCREEN = ((byte*))(word/signed word/dword/signed dword) 1024
|
||||
(byte) a
|
||||
(const byte) a#0 a = (byte) 'a'
|
||||
(void()) main()
|
||||
(byte~) main::$0 reg byte a 22.0
|
||||
(label) main::@1
|
||||
(label) main::@3
|
||||
(label) main::@return
|
||||
(byte) main::b
|
||||
(byte) main::b#1 reg byte y 16.5
|
||||
(byte) main::b#2 reg byte y 4.714285714285714
|
||||
(byte) main::i
|
||||
(byte) main::i#1 reg byte x 7.333333333333333
|
||||
(byte) main::i#2 reg byte x 5.5
|
||||
(byte()) sum((byte) sum::a , (byte) sum::b)
|
||||
(label) sum::@return
|
||||
(byte) sum::a
|
||||
(byte) sum::b
|
||||
(byte) sum::b#0 reg byte y 13.0
|
||||
(byte) sum::r
|
||||
(byte) sum::return
|
||||
(byte) sum::return#0 reg byte a 22.0
|
||||
(byte) sum::return#1 reg byte a 4.333333333333333
|
||||
|
||||
reg byte y [ main::b#2 main::b#1 ]
|
||||
reg byte x [ main::i#2 main::i#1 ]
|
||||
reg byte y [ sum::b#0 ]
|
||||
reg byte a [ sum::return#0 ]
|
||||
reg byte a [ main::$0 ]
|
||||
reg byte a [ sum::return#1 ]
|
Loading…
x
Reference in New Issue
Block a user