1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-11-20 02:32:36 +00:00

Removed comments from ASM output

This commit is contained in:
Jesper Gravgaard 2017-07-16 09:41:27 +02:00
parent 67b4257ad9
commit f6eeb5ff83
6 changed files with 20 additions and 90 deletions

View File

@ -2,11 +2,9 @@ Features
- Move the main code into a main() function, and disallow code outside functions. The main function per default has no parameters and exits with RTS.
- Implement Register Allocation (that utilize real registers - and non-zeropage memory)
- Add Fixed Point number types
- Create a proper main function for the compiler
- Add a for loop for(init;condition;increment) {stmt} -> { init; do { stmt; increment } while (condition) }
- Add imports
- Add structs
- Add ++/-- incrementing/decrementing operators.
- Let { stmt } introduce a new anonymous scope.
- Add preprocessing / find a way to allow some functions to run at compile time
- Implement inline compilation of functions (and a mechanism for choosing which methods / calls to inline)
@ -14,20 +12,22 @@ Features
- Add ability to call KC code from ASM. (Maybe declare some functions external to ensure their interface is well defined. Maybe generate ASM call stubs.)
- Add inline ASM (maybe?)
- Handle long branches
+ Create a proper main function for the compiler
+ Add ++/-- incrementing/decrementing operators.
Process/Code Structure Improvement
- Make each phase return a separate object graph (allowing for keeeping the history in memory & performing rollbacks)
- Implemenent Assertions for the output of different phases (ensuring that the result of the phase is consistent)
- Refactor Expression Operator Implementation & Evaluation into one class per operator
- Improve error messages to give better context
- Offer to compile resulting ASM with KickAssembler
+ Implemenent Assertions for the output of different phases (ensuring that the result of the phase is consistent)
Testing
- Test that the parse tree for specific KC syntax is as expected. Use a print function for the parse tree to generate output for comparison.
- Test the ICL result of a specific phase on a specific ICL input. Create an ICL syntax for parsing directly to ICL and a printer for the syntax.
- Test the ASM program output resulting from compiling specific KC program input.
- Emulate/Run the ASM for a specific KC program compiled. Compare the emulated ASM output to output calculated by executing directly on the KC tree.
- Add assert statements to the language. Create KC programs that test the compiler by compiling, running and testing assertions.
+ Test the ASM program output resulting from compiling specific KC program input.
Optimizations
- Optimize phi transitions by ensuring that identical phi-transitions with regards to register allocation are collected into a single transition.

View File

@ -8,6 +8,10 @@ public class AsmComment implements AsmLine {
this.comment = comment;
}
public String getComment() {
return comment;
}
@Override
public int getLineBytes() {
return 0;

View File

@ -33,10 +33,14 @@ public class AsmProgram {
addLine(new AsmInstruction(instructionType, parameter, 1));
}
@Override
public String toString() {
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(" ");
}
@ -45,4 +49,9 @@ public class AsmProgram {
return out.toString();
}
@Override
public String toString() {
return toString(true);
}
}

View File

@ -40,7 +40,7 @@ public class TestCompilationOutput {
CharStream input = CharStreams.fromFileName(inputPath);
Compiler compiler = new Compiler();
Compiler.CompilationResult output = compiler.compile(input);
assertOutput(fileName, ".asm", output.getAsmProgram().toString());
assertOutput(fileName, ".asm", output.getAsmProgram().toString(false));
assertOutput(fileName, ".sym", output.getSymbols().getSymbolTableContents());
assertOutput(fileName, ".cfg", output.getGraph().toString());
assertOutput(fileName, ".log", output.getLog().toString());

View File

@ -1,46 +1,35 @@
BBEGIN:
B1_from_BBEGIN:
// (byte) y#2 = (byte) 0 // zpby1=coby1
lda #0
sta 14
// (byte) e#3 = (byte) 12 // zpby1=coby1
lda #12
sta 13
// (byte) x#2 = (byte) 0 // zpby1=coby1
lda #0
sta 12
// (byte*) cursor#3 = (word) 1024 // zpptrby1=cowo1
lda #<1024
sta 10
lda #>1024
sta 10+1
jmp B1
B1_from_B3:
// (byte) y#2 = (byte) y#5 // zpby1=zpby2
lda 18
sta 14
// (byte) e#3 = (byte) e#5 // zpby1=zpby2
lda 15
sta 13
// (byte) x#2 = (byte) x#1 // zpby1=zpby2
lda 2
sta 12
// (byte*) cursor#3 = (byte*) cursor#5 // zpptrby1=zpptrby2
lda 16
sta 10
lda 16+1
sta 10+1
B1:
// *((byte*) cursor#3) (byte) 81 // zpiby1=coby1
ldy #0
lda #81
sta (10),y
// (byte) x#1 (byte) x#2 + (byte) 1 // zpby1=zpby2_plus_1
lda 12
clc
adc #1
sta 2
// (byte*) cursor#1 (byte*) cursor#3 + (byte) 1 // zpptrby1=zpptrby2_plus_1
lda 10
clc
adc #1
@ -48,40 +37,32 @@ B1:
lda 10+1
adc #0
sta 3+1
// (byte) e#1 (byte) e#3 + (byte) 24 // zpby1=zpby2_plus_coby1
lda 13
clc
adc #24
sta 5
// if((byte) 39<(byte) e#1) goto @2 // coby1_lt_zpby1_then_la1
lda #39
cmp 5
bcc B2
B3_from_B1:
// (byte) y#5 = (byte) y#2 // zpby1=zpby2
lda 14
sta 18
// (byte*) cursor#5 = (byte*) cursor#1 // zpptrby1=zpptrby2
lda 3
sta 16
lda 3+1
sta 16+1
// (byte) e#5 = (byte) e#1 // zpby1=zpby2
lda 5
sta 15
B3:
// if((byte) x#1<(byte) 40) goto @1 // zpby1_lt_coby1_then_la1
lda 2
cmp #40
bcc B1_from_B3
BEND:
B2:
// (byte) y#1 (byte) y#2 + (byte) 1 // zpby1=zpby2_plus_1
lda 14
clc
adc #1
sta 6
// (byte*) cursor#2 (byte*) cursor#1 + (byte) 40 // zpptrby1=zpptrby2_plus_coby1
lda #40
clc
adc 3
@ -89,21 +70,17 @@ B2:
lda #0
adc 3+1
sta 7+1
// (byte) e#2 (byte) e#1 - (byte) 39 // zpby1=zpby2_minus_coby1
lda 5
sec
sbc #39
sta 9
B3_from_B2:
// (byte) y#5 = (byte) y#1 // zpby1=zpby2
lda 6
sta 18
// (byte*) cursor#5 = (byte*) cursor#2 // zpptrby1=zpptrby2
lda 7
sta 16
lda 7+1
sta 16+1
// (byte) e#5 = (byte) e#2 // zpby1=zpby2
lda 9
sta 15
jmp B3

View File

@ -1,31 +1,22 @@
BBEGIN:
jsr prepare
B2_from_BBEGIN:
// (byte) c#2 = (byte) 25 // xby=coby1
ldx #25
jmp B2
B2_from_B20:
// (byte) c#2 = (byte) 25 // xby=coby1
ldx #25
B2_from_B6:
// (byte) c#2 = (byte) c#1 // register copy
B2:
B3:
// (byte~) $1 * (word) 53266 // aby=_star_cowo1
lda 53266
// if((byte~) $1!=(byte) 254) goto @3 // aby_neq_coby1_then_la1
cmp #254
bne B3
B4:
// (byte~) $3 * (word) 53266 // aby=_star_cowo1
lda 53266
// if((byte~) $3!=(byte) 255) goto @4 // aby_neq_coby1_then_la1
cmp #255
bne B4
B6:
// (byte) c#1 -- (byte) c#2 // xby=_dec_xby
dex
// if((byte) c#1!=(byte) 0) goto @2 // xby_neq_0_then_la1
cpx #0
bne B2_from_B6
B7:
@ -33,47 +24,30 @@ B7:
B19:
jsr plot
B20:
// if(true) goto @2 // true_then_la1
jmp B2_from_B20
BEND:
plot:
plot__B1_from_plot:
// (byte) plot::y#2 = (byte) 16 // zpby1=coby1
lda #16
sta 100
// (byte) plot::i#3 = (byte) 0 // xby=coby1
ldx #0
// (byte*) plot::line#2 = (word) 1236 // zpptrby1=cowo1
lda #<1236
sta 101
lda #>1236
sta 101+1
plot__B1_from_B15:
// (byte) plot::y#2 = (byte) plot::y#1 // register copy
// (byte) plot::i#3 = (byte) plot::i#1 // register copy
// (byte*) plot::line#2 = (byte*) plot::line#1 // register copy
plot__B1:
plot__B2_from_B1:
// (byte) plot::x#2 = (byte) 0 // yby=coby1
ldy #0
// (byte) plot::i#2 = (byte) plot::i#3 // register copy
plot__B2_from_B2:
// (byte) plot::x#2 = (byte) plot::x#1 // register copy
// (byte) plot::i#2 = (byte) plot::i#1 // register copy
plot__B2:
// (byte~) plot::$3 (word) 4096 *idx (byte) plot::i#2 // aby=cowo1_staridx_xby
lda 4096,x
// *((byte*) plot::line#2 + (byte) plot::x#2) (byte~) plot::$3 // ptr_zpptrby1_yby=aby
sta (101),y
// (byte) plot::i#1 ++ (byte) plot::i#2 // xby=_inc_xby
inx
// (byte) plot::x#1 ++ (byte) plot::x#2 // yby=_inc_yby
iny
// if((byte) plot::x#1<(byte) 16) goto plot::@2 // yby_lt_coby1_then_la1
cpy #16
bcc plot__B2_from_B2
B15:
// (byte*) plot::line#1 (byte*) plot::line#2 + (byte) 40 // zpptrby1=zpptrby1_plus_coby1
lda 101
clc
adc #40
@ -81,92 +55,58 @@ B15:
bcc !+
inc 101+1
!:
// (byte) plot::y#1 -- (byte) plot::y#2 // zpby1=_dec_zpby1
dec 100
// if((byte) plot::y#1!=(byte) 0) goto plot::@1 // zpby1_neq_0_then_la1
lda 100
bne plot__B1_from_B15
plot__Breturn:
rts
flip:
flip__B1_from_flip:
// (byte) flip::r#2 = (byte) 16 // zpby1=coby1
lda #16
sta 104
// (byte) flip::srcIdx#3 = (byte) 0 // xby=coby1
ldx #0
// (byte) flip::dstIdx#5 = (byte) 15 // yby=coby1
ldy #15
flip__B1_from_B11:
// (byte) flip::r#2 = (byte) flip::r#1 // register copy
// (byte) flip::srcIdx#3 = (byte) flip::srcIdx#1 // register copy
// (byte) flip::dstIdx#5 = (byte) flip::dstIdx#2 // register copy
flip__B1:
flip__B2_from_B1:
// (byte) flip::c#2 = (byte) 16 // zpby1=coby1
lda #16
sta 103
// (byte) flip::dstIdx#3 = (byte) flip::dstIdx#5 // register copy
// (byte) flip::srcIdx#2 = (byte) flip::srcIdx#3 // register copy
flip__B2_from_B2:
// (byte) flip::c#2 = (byte) flip::c#1 // register copy
// (byte) flip::dstIdx#3 = (byte) flip::dstIdx#1 // register copy
// (byte) flip::srcIdx#2 = (byte) flip::srcIdx#1 // register copy
flip__B2:
// (byte~) flip::$0 (word) 4096 *idx (byte) flip::srcIdx#2 // aby=cowo1_staridx_xby
lda 4096,x
// *((word) 4352 + (byte) flip::dstIdx#3) (byte~) flip::$0 // ptr_cowo1_yby=aby
sta 4352,y
// (byte) flip::srcIdx#1 ++ (byte) flip::srcIdx#2 // xby=_inc_xby
inx
// (byte) flip::dstIdx#1 (byte) flip::dstIdx#3 + (byte) 16 // yby=yby_plus_coby1
tya
clc
adc #16
tay
// (byte) flip::c#1 -- (byte) flip::c#2 // zpby1=_dec_zpby1
dec 103
// if((byte) flip::c#1!=(byte) 0) goto flip::@2 // zpby1_neq_0_then_la1
lda 103
bne flip__B2_from_B2
B11:
// (byte) flip::dstIdx#2 -- (byte) flip::dstIdx#1 // yby=_dec_yby
dey
// (byte) flip::r#1 -- (byte) flip::r#2 // zpby1=_dec_zpby1
dec 104
// if((byte) flip::r#1!=(byte) 0) goto flip::@1 // zpby1_neq_0_then_la1
lda 104
bne flip__B1_from_B11
flip__B3_from_B11:
// (byte) flip::i#2 = (byte) 0 // xby=coby1
ldx #0
flip__B3_from_B3:
// (byte) flip::i#2 = (byte) flip::i#1 // register copy
flip__B3:
// (byte~) flip::$4 (word) 4352 *idx (byte) flip::i#2 // aby=cowo1_staridx_xby
lda 4352,x
// *((word) 4096 + (byte) flip::i#2) (byte~) flip::$4 // ptr_cowo1_xby=aby
sta 4096,x
// (byte) flip::i#1 ++ (byte) flip::i#2 // xby=_inc_xby
inx
// if((byte) flip::i#1!=(byte) 0) goto flip::@3 // xby_neq_0_then_la1
cpx #0
bne flip__B3_from_B3
flip__Breturn:
rts
prepare:
prepare__B1_from_prepare:
// (byte) prepare::i#2 = (byte) 0 // xby=coby1
ldx #0
prepare__B1_from_B1:
// (byte) prepare::i#2 = (byte) prepare::i#1 // register copy
prepare__B1:
// *((word) 4096 + (byte) prepare::i#2) (byte) prepare::i#2 // ptr_cowo1_xby=xby
txa
sta 4096,x
// (byte) prepare::i#1 ++ (byte) prepare::i#2 // xby=_inc_xby
inx
// if((byte) prepare::i#1!=(byte) 0) goto prepare::@1 // xby_neq_0_then_la1
cpx #0
bne prepare__B1_from_B1
prepare__Breturn: