mirror of
https://gitlab.com/camelot/kickc.git
synced 2025-02-13 13:33:32 +00:00
Rafactoring pass 2
This commit is contained in:
parent
9864995afb
commit
5d988dd859
@ -231,12 +231,12 @@ public class Compiler {
|
||||
|
||||
private void pass2Optimize() {
|
||||
List<Pass2SsaOptimization> optimizations = new ArrayList<>();
|
||||
optimizations.add(new PassNAddTypeConversionAssignment(program));
|
||||
optimizations.add(new PassNAddNumberTypeConversions(program));
|
||||
optimizations.add(new PassNAddArrayNumberTypeConversions(program));
|
||||
optimizations.add(new PassNDowngradeBytePlusWord(program));
|
||||
optimizations.add(new PassNTypeInference(program));
|
||||
optimizations.add(new PassNTypeIdSimplification(program));
|
||||
optimizations.add(new Pass2SizeOfSimplification(program));
|
||||
optimizations.add(new Pass2CullEmptyBlocks(program));
|
||||
optimizations.add(new PassNStatementIndices(program));
|
||||
optimizations.add(new PassNVariableReferenceInfos(program));
|
||||
@ -257,21 +257,18 @@ public class Compiler {
|
||||
optimizations.add(new Pass2FixInlineConstructorsNew(program));
|
||||
optimizations.add(new PassNAddTypeConversionAssignment(program));
|
||||
optimizations.add(new Pass2TypeInference(program));
|
||||
optimizations.add(new PassNEliminateUnusedVars(program, true));
|
||||
optimizations.add(new Pass2EliminateRedundantCasts(program));
|
||||
optimizations.add(new Pass2EliminateUnusedBlocks(program));
|
||||
optimizations.add(new Pass2RangeResolving(program));
|
||||
optimizations.add(new Pass2ComparisonOptimization(program));
|
||||
optimizations.add(new Pass2ConstantCallPointerIdentification(program));
|
||||
optimizations.add(new Pass2SizeOfSimplification(program));
|
||||
optimizations.add(new Pass2InlineCast(program));
|
||||
optimizations.add(new PassNCastSimplification(program));
|
||||
optimizations.add(new PassNStatementIndices(program));
|
||||
optimizations.add(new PassNVariableReferenceInfos(program));
|
||||
optimizations.add(new Pass2InlineDerefIdx(program));
|
||||
optimizations.add(new Pass2DeInlineWordDerefIdx(program));
|
||||
optimizations.add(new PassNSimplifyConstantZero(program));
|
||||
optimizations.add(new PassNSimplifyExpressionWithZero(program));
|
||||
optimizations.add(new PassNEliminateUnusedVars(program, true));
|
||||
optimizations.add(new Pass2EliminateUnusedBlocks(program));
|
||||
pass2Execute(optimizations);
|
||||
}
|
||||
|
||||
|
@ -63,7 +63,6 @@ public class TestPrograms {
|
||||
|
||||
*/
|
||||
|
||||
|
||||
@Test
|
||||
public void testHex2Dec() throws IOException, URISyntaxException {
|
||||
compileAndCompare("hex2dec");
|
||||
|
@ -4,15 +4,15 @@
|
||||
.pc = $80d "Program"
|
||||
main: {
|
||||
.label SCREEN = $400
|
||||
.label _1 = 2
|
||||
.label _3 = 2
|
||||
.label _0 = 2
|
||||
.label _2 = 2
|
||||
lda #<msg1
|
||||
sta first.msg
|
||||
lda #>msg1
|
||||
sta first.msg+1
|
||||
jsr first
|
||||
ldy #0
|
||||
lda (_1),y
|
||||
lda (_0),y
|
||||
sta SCREEN
|
||||
lda #<msg2
|
||||
sta first.msg
|
||||
@ -20,7 +20,7 @@ main: {
|
||||
sta first.msg+1
|
||||
jsr first
|
||||
ldy #0
|
||||
lda (_3),y
|
||||
lda (_2),y
|
||||
sta SCREEN+1
|
||||
rts
|
||||
}
|
||||
|
@ -545,9 +545,9 @@ append: {
|
||||
bne !+
|
||||
lda sub
|
||||
cmp value
|
||||
beq b2
|
||||
!:
|
||||
bcc b2
|
||||
beq b2
|
||||
rts
|
||||
b2:
|
||||
ldy #0
|
||||
|
@ -22,7 +22,7 @@ main: {
|
||||
}
|
||||
// Print points
|
||||
print_points: {
|
||||
.label pointXpos1__0 = 9
|
||||
.label point = 9
|
||||
.label i = 2
|
||||
jsr print_cls
|
||||
lda #<$400
|
||||
@ -42,15 +42,15 @@ print_points: {
|
||||
tya
|
||||
clc
|
||||
adc #<points
|
||||
sta pointXpos1__0
|
||||
sta point
|
||||
lda #>points
|
||||
adc #0
|
||||
sta pointXpos1__0+1
|
||||
sta point+1
|
||||
ldx points,y
|
||||
jsr print_byte
|
||||
jsr print_str
|
||||
ldy #1
|
||||
lda (pointXpos1__0),y
|
||||
lda (point),y
|
||||
tax
|
||||
jsr print_byte
|
||||
jsr print_ln
|
||||
@ -168,7 +168,7 @@ print_cls: {
|
||||
}
|
||||
// Initialize points
|
||||
init_points: {
|
||||
.label pointXpos1__0 = 3
|
||||
.label getPoint1_return = 3
|
||||
.label pos = 2
|
||||
lda #$a
|
||||
sta pos
|
||||
@ -180,17 +180,17 @@ init_points: {
|
||||
tya
|
||||
clc
|
||||
adc #<points
|
||||
sta pointXpos1__0
|
||||
sta getPoint1_return
|
||||
lda #>points
|
||||
adc #0
|
||||
sta pointXpos1__0+1
|
||||
sta getPoint1_return+1
|
||||
lda pos
|
||||
sta points,y
|
||||
lda #$a
|
||||
clc
|
||||
adc pos
|
||||
ldy #1
|
||||
sta (pointXpos1__0),y
|
||||
sta (getPoint1_return),y
|
||||
clc
|
||||
adc #$a
|
||||
sta pos
|
||||
|
@ -301,7 +301,6 @@ print_ln: {
|
||||
// printEntry(byte* zeropage(4) entry)
|
||||
printEntry: {
|
||||
.label entry = 4
|
||||
.label entryBufDisk1__0 = 4
|
||||
lda print_line_cursor
|
||||
sta print_char_cursor
|
||||
lda print_line_cursor+1
|
||||
@ -312,10 +311,10 @@ printEntry: {
|
||||
sta print_str.str+1
|
||||
jsr print_str
|
||||
ldy #0
|
||||
lda (entryBufDisk1__0),y
|
||||
lda (entry),y
|
||||
sta print_word.w
|
||||
iny
|
||||
lda (entryBufDisk1__0),y
|
||||
lda (entry),y
|
||||
sta print_word.w+1
|
||||
jsr print_word
|
||||
lda print_line_cursor
|
||||
@ -333,10 +332,10 @@ printEntry: {
|
||||
sta print_str.str+1
|
||||
jsr print_str
|
||||
ldy #2
|
||||
lda (entryBufDisk1__0),y
|
||||
lda (entry),y
|
||||
sta print_word.w
|
||||
iny
|
||||
lda (entryBufDisk1__0),y
|
||||
lda (entry),y
|
||||
sta print_word.w+1
|
||||
jsr print_word
|
||||
lda print_line_cursor
|
||||
@ -354,10 +353,10 @@ printEntry: {
|
||||
sta print_str.str+1
|
||||
jsr print_str
|
||||
ldy #4
|
||||
lda (entryBufDisk1__0),y
|
||||
lda (entry),y
|
||||
sta print_word.w
|
||||
iny
|
||||
lda (entryBufDisk1__0),y
|
||||
lda (entry),y
|
||||
sta print_word.w+1
|
||||
jsr print_word
|
||||
lda print_line_cursor
|
||||
@ -375,10 +374,10 @@ printEntry: {
|
||||
sta print_str.str+1
|
||||
jsr print_str
|
||||
ldy #6
|
||||
lda (entryBufDisk1__0),y
|
||||
lda (entry),y
|
||||
sta print_word.w
|
||||
iny
|
||||
lda (entryBufDisk1__0),y
|
||||
lda (entry),y
|
||||
sta print_word.w+1
|
||||
jsr print_word
|
||||
lda print_line_cursor
|
||||
@ -396,7 +395,7 @@ printEntry: {
|
||||
sta print_str.str+1
|
||||
jsr print_str
|
||||
ldy #8
|
||||
lda (entryBufDisk1__0),y
|
||||
lda (entry),y
|
||||
tax
|
||||
jsr print_byte
|
||||
lda print_line_cursor
|
||||
@ -414,7 +413,7 @@ printEntry: {
|
||||
sta print_str.str+1
|
||||
jsr print_str
|
||||
ldy #9
|
||||
lda (entryBufDisk1__0),y
|
||||
lda (entry),y
|
||||
tax
|
||||
jsr print_byte
|
||||
lda print_line_cursor
|
||||
@ -432,7 +431,7 @@ printEntry: {
|
||||
sta print_str.str+1
|
||||
jsr print_str
|
||||
ldy #$a
|
||||
lda (entryBufDisk1__0),y
|
||||
lda (entry),y
|
||||
tax
|
||||
jsr print_byte
|
||||
lda print_line_cursor
|
||||
@ -450,7 +449,7 @@ printEntry: {
|
||||
sta print_str.str+1
|
||||
jsr print_str
|
||||
ldy #$b
|
||||
lda (entryBufDisk1__0),y
|
||||
lda (entry),y
|
||||
tax
|
||||
jsr print_byte
|
||||
lda print_line_cursor
|
||||
@ -468,10 +467,10 @@ printEntry: {
|
||||
sta print_str.str+1
|
||||
jsr print_str
|
||||
ldy #$c
|
||||
lda (entryBufDisk1__0),y
|
||||
lda (entry),y
|
||||
sta print_word.w
|
||||
iny
|
||||
lda (entryBufDisk1__0),y
|
||||
lda (entry),y
|
||||
sta print_word.w+1
|
||||
jsr print_word
|
||||
lda print_line_cursor
|
||||
@ -489,7 +488,7 @@ printEntry: {
|
||||
sta print_str.str+1
|
||||
jsr print_str
|
||||
ldy #$e
|
||||
lda (entryBufDisk1__0),y
|
||||
lda (entry),y
|
||||
tax
|
||||
jsr print_byte
|
||||
lda print_line_cursor
|
||||
@ -507,7 +506,7 @@ printEntry: {
|
||||
sta print_str.str+1
|
||||
jsr print_str
|
||||
ldy #$f
|
||||
lda (entryBufDisk1__0),y
|
||||
lda (entry),y
|
||||
tax
|
||||
jsr print_byte
|
||||
lda print_line_cursor
|
||||
@ -525,7 +524,7 @@ printEntry: {
|
||||
sta print_str.str+1
|
||||
jsr print_str
|
||||
ldy #$10
|
||||
lda (entryBufDisk1__0),y
|
||||
lda (entry),y
|
||||
tax
|
||||
jsr print_byte
|
||||
lda print_line_cursor
|
||||
@ -543,7 +542,7 @@ printEntry: {
|
||||
sta print_str.str+1
|
||||
jsr print_str
|
||||
ldy #$11
|
||||
lda (entryBufDisk1__0),y
|
||||
lda (entry),y
|
||||
tax
|
||||
jsr print_byte
|
||||
lda print_line_cursor
|
||||
@ -616,7 +615,6 @@ initEntry: {
|
||||
.label _7 = 6
|
||||
.label _17 = 6
|
||||
.label entry = 2
|
||||
.label entryBufDisk1__0 = 2
|
||||
txa
|
||||
clc
|
||||
adc #<$1111
|
||||
@ -626,10 +624,10 @@ initEntry: {
|
||||
sta _1+1
|
||||
ldy #0
|
||||
lda _1
|
||||
sta (entryBufDisk1__0),y
|
||||
sta (entry),y
|
||||
iny
|
||||
lda _1+1
|
||||
sta (entryBufDisk1__0),y
|
||||
sta (entry),y
|
||||
txa
|
||||
clc
|
||||
adc #<$2222
|
||||
@ -639,10 +637,10 @@ initEntry: {
|
||||
sta _3+1
|
||||
ldy #2
|
||||
lda _3
|
||||
sta (entryBufDisk1__0),y
|
||||
sta (entry),y
|
||||
iny
|
||||
lda _3+1
|
||||
sta (entryBufDisk1__0),y
|
||||
sta (entry),y
|
||||
txa
|
||||
clc
|
||||
adc #<$3333
|
||||
@ -652,10 +650,10 @@ initEntry: {
|
||||
sta _5+1
|
||||
ldy #4
|
||||
lda _5
|
||||
sta (entryBufDisk1__0),y
|
||||
sta (entry),y
|
||||
iny
|
||||
lda _5+1
|
||||
sta (entryBufDisk1__0),y
|
||||
sta (entry),y
|
||||
txa
|
||||
clc
|
||||
adc #<$4444
|
||||
@ -665,30 +663,30 @@ initEntry: {
|
||||
sta _7+1
|
||||
ldy #6
|
||||
lda _7
|
||||
sta (entryBufDisk1__0),y
|
||||
sta (entry),y
|
||||
iny
|
||||
lda _7+1
|
||||
sta (entryBufDisk1__0),y
|
||||
sta (entry),y
|
||||
txa
|
||||
clc
|
||||
adc #$55
|
||||
ldy #8
|
||||
sta (entryBufDisk1__0),y
|
||||
sta (entry),y
|
||||
txa
|
||||
clc
|
||||
adc #$66
|
||||
ldy #9
|
||||
sta (entryBufDisk1__0),y
|
||||
sta (entry),y
|
||||
txa
|
||||
clc
|
||||
adc #$77
|
||||
ldy #$a
|
||||
sta (entryBufDisk1__0),y
|
||||
sta (entry),y
|
||||
txa
|
||||
clc
|
||||
adc #$88
|
||||
ldy #$b
|
||||
sta (entryBufDisk1__0),y
|
||||
sta (entry),y
|
||||
txa
|
||||
clc
|
||||
adc #<$9999
|
||||
@ -698,30 +696,30 @@ initEntry: {
|
||||
sta _17+1
|
||||
ldy #$c
|
||||
lda _17
|
||||
sta (entryBufDisk1__0),y
|
||||
sta (entry),y
|
||||
iny
|
||||
lda _17+1
|
||||
sta (entryBufDisk1__0),y
|
||||
sta (entry),y
|
||||
txa
|
||||
clc
|
||||
adc #$aa
|
||||
ldy #$e
|
||||
sta (entryBufDisk1__0),y
|
||||
sta (entry),y
|
||||
txa
|
||||
clc
|
||||
adc #$bb
|
||||
ldy #$f
|
||||
sta (entryBufDisk1__0),y
|
||||
sta (entry),y
|
||||
txa
|
||||
clc
|
||||
adc #$cc
|
||||
ldy #$10
|
||||
sta (entryBufDisk1__0),y
|
||||
sta (entry),y
|
||||
txa
|
||||
clc
|
||||
adc #$dd
|
||||
ldy #$11
|
||||
sta (entryBufDisk1__0),y
|
||||
sta (entry),y
|
||||
rts
|
||||
}
|
||||
// Perform binary multiplication of two unsigned 8-bit bytes into a 16-bit unsigned word
|
||||
|
@ -2,10 +2,10 @@
|
||||
.pc = $801 "Basic"
|
||||
:BasicUpstart(main)
|
||||
.pc = $80d "Program"
|
||||
.label SCREEN = $400
|
||||
.const SIZEOF_BYTE = 1
|
||||
.const SIZEOF_WORD = 2
|
||||
.const SIZEOF_POINTER = 2
|
||||
.label SCREEN = $400
|
||||
.const SIZEOF_NUMBER = $ff
|
||||
main: {
|
||||
.const sz = $f
|
||||
|
@ -205,9 +205,9 @@ compare: {
|
||||
bne !+
|
||||
lda w1
|
||||
cmp w2
|
||||
beq b11
|
||||
!:
|
||||
bcc b11
|
||||
beq b11
|
||||
lda #TT
|
||||
sta r
|
||||
jmp b22
|
||||
@ -247,9 +247,9 @@ compare: {
|
||||
bne !+
|
||||
lda w2
|
||||
cmp w1
|
||||
beq b13
|
||||
!:
|
||||
bcc b13
|
||||
beq b13
|
||||
lda #TT
|
||||
sta r
|
||||
jmp b24
|
||||
|
Loading…
x
Reference in New Issue
Block a user