mirror of
https://gitlab.com/camelot/kickc.git
synced 2025-01-11 04:29:53 +00:00
Fixed problem with typedef enum. Closes #686
This commit is contained in:
parent
8c77cbb45a
commit
d372383d48
@ -1938,7 +1938,7 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
|
||||
this.currentEnum = null;
|
||||
// Copy all members to upper-level scope
|
||||
Scope parentScope = getCurrentScope();
|
||||
while(parentScope instanceof StructDefinition) parentScope = parentScope.getScope();
|
||||
while(parentScope instanceof StructDefinition || parentScope instanceof TypeDefsScope) parentScope = parentScope.getScope();
|
||||
for(Variable member : enumDefinition.getAllConstants(false)) {
|
||||
parentScope.add(Variable.createConstant(member.getLocalName(), SymbolType.BYTE, parentScope, member.getInitValue(), currentDataSegment));
|
||||
}
|
||||
|
@ -1901,6 +1901,11 @@ public class TestProgramsFast extends TestPrograms {
|
||||
compileAndCompare("pointer-const-typedef.c");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTypedef8() throws IOException {
|
||||
compileAndCompare("typedef-8.c");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTypedef7() throws IOException {
|
||||
compileAndCompare("typedef-7.c");
|
||||
|
13
src/test/kc/typedef-8.c
Normal file
13
src/test/kc/typedef-8.c
Normal file
@ -0,0 +1,13 @@
|
||||
// Test typedef enum
|
||||
|
||||
typedef enum BOOL_T {
|
||||
FALSE = 0,
|
||||
TRUE
|
||||
} bool_t;
|
||||
|
||||
bool_t * SCREEN = (bool_t*)0x0400;
|
||||
|
||||
void main() {
|
||||
bool_t exe = FALSE;
|
||||
*SCREEN = exe;
|
||||
}
|
19
src/test/ref/typedef-8.asm
Normal file
19
src/test/ref/typedef-8.asm
Normal file
@ -0,0 +1,19 @@
|
||||
// Test typedef enum
|
||||
// Commodore 64 PRG executable file
|
||||
.file [name="typedef-8.prg", type="prg", segments="Program"]
|
||||
.segmentdef Program [segments="Basic, Code, Data"]
|
||||
.segmentdef Basic [start=$0801]
|
||||
.segmentdef Code [start=$80d]
|
||||
.segmentdef Data [startAfter="Code"]
|
||||
.segment Basic
|
||||
:BasicUpstart(main)
|
||||
.const FALSE = 0
|
||||
.label SCREEN = $400
|
||||
.segment Code
|
||||
main: {
|
||||
// *SCREEN = exe
|
||||
lda #FALSE
|
||||
sta SCREEN
|
||||
// }
|
||||
rts
|
||||
}
|
8
src/test/ref/typedef-8.cfg
Normal file
8
src/test/ref/typedef-8.cfg
Normal file
@ -0,0 +1,8 @@
|
||||
|
||||
void main()
|
||||
main: scope:[main] from
|
||||
[0] *SCREEN = FALSE
|
||||
to:main::@return
|
||||
main::@return: scope:[main] from main
|
||||
[1] return
|
||||
to:@return
|
150
src/test/ref/typedef-8.log
Normal file
150
src/test/ref/typedef-8.log
Normal file
@ -0,0 +1,150 @@
|
||||
Inlined call call __init
|
||||
|
||||
CONTROL FLOW GRAPH SSA
|
||||
|
||||
void main()
|
||||
main: scope:[main] from __start::@1
|
||||
*SCREEN = main::exe
|
||||
to:main::@return
|
||||
main::@return: scope:[main] from main
|
||||
return
|
||||
to:@return
|
||||
|
||||
void __start()
|
||||
__start: scope:[__start] from
|
||||
to:__start::__init1
|
||||
__start::__init1: scope:[__start] from __start
|
||||
to:__start::@1
|
||||
__start::@1: scope:[__start] from __start::__init1
|
||||
call main
|
||||
to:__start::@2
|
||||
__start::@2: scope:[__start] from __start::@1
|
||||
to:__start::@return
|
||||
__start::@return: scope:[__start] from __start::@2
|
||||
return
|
||||
to:@return
|
||||
|
||||
SYMBOL TABLE SSA
|
||||
constant byte FALSE = 0
|
||||
constant byte* SCREEN = (byte*)$400
|
||||
void __start()
|
||||
void main()
|
||||
constant byte main::exe = FALSE
|
||||
|
||||
Simplifying constant pointer cast (byte*) 1024
|
||||
Successful SSA optimization PassNCastSimplification
|
||||
Removing unused procedure __start
|
||||
Removing unused procedure block __start
|
||||
Removing unused procedure block __start::__init1
|
||||
Removing unused procedure block __start::@1
|
||||
Removing unused procedure block __start::@2
|
||||
Removing unused procedure block __start::@return
|
||||
Successful SSA optimization PassNEliminateEmptyStart
|
||||
Constant inlined main::exe = FALSE
|
||||
Successful SSA optimization Pass2ConstantInlining
|
||||
Finalized unsigned number type (byte) 0
|
||||
Successful SSA optimization PassNFinalizeNumberTypeConversions
|
||||
CALL GRAPH
|
||||
|
||||
Created 0 initial phi equivalence classes
|
||||
Coalesced down to 0 phi equivalence classes
|
||||
|
||||
FINAL CONTROL FLOW GRAPH
|
||||
|
||||
void main()
|
||||
main: scope:[main] from
|
||||
[0] *SCREEN = FALSE
|
||||
to:main::@return
|
||||
main::@return: scope:[main] from main
|
||||
[1] return
|
||||
to:@return
|
||||
|
||||
|
||||
VARIABLE REGISTER WEIGHTS
|
||||
void main()
|
||||
|
||||
Initial phi equivalence classes
|
||||
Complete equivalence classes
|
||||
REGISTER UPLIFT POTENTIAL REGISTERS
|
||||
Statement [0] *SCREEN = FALSE [ ] ( [ ] { } ) always clobbers reg byte a
|
||||
|
||||
REGISTER UPLIFT SCOPES
|
||||
Uplift Scope [main]
|
||||
Uplift Scope []
|
||||
|
||||
Uplifting [main] best 15 combination
|
||||
Uplifting [] best 15 combination
|
||||
|
||||
ASSEMBLER BEFORE OPTIMIZATION
|
||||
// File Comments
|
||||
// Test typedef enum
|
||||
// Upstart
|
||||
// Commodore 64 PRG executable file
|
||||
.file [name="typedef-8.prg", type="prg", segments="Program"]
|
||||
.segmentdef Program [segments="Basic, Code, Data"]
|
||||
.segmentdef Basic [start=$0801]
|
||||
.segmentdef Code [start=$80d]
|
||||
.segmentdef Data [startAfter="Code"]
|
||||
.segment Basic
|
||||
:BasicUpstart(main)
|
||||
// Global Constants & labels
|
||||
.const FALSE = 0
|
||||
.label SCREEN = $400
|
||||
.segment Code
|
||||
// main
|
||||
main: {
|
||||
// [0] *SCREEN = FALSE -- _deref_pbuc1=vbuc2
|
||||
lda #FALSE
|
||||
sta SCREEN
|
||||
jmp __breturn
|
||||
// main::@return
|
||||
__breturn:
|
||||
// [1] return
|
||||
rts
|
||||
}
|
||||
// File Data
|
||||
|
||||
ASSEMBLER OPTIMIZATIONS
|
||||
Removing instruction jmp __breturn
|
||||
Succesful ASM optimization Pass5NextJumpElimination
|
||||
Removing instruction __breturn:
|
||||
Succesful ASM optimization Pass5UnusedLabelElimination
|
||||
|
||||
FINAL SYMBOL TABLE
|
||||
constant byte FALSE = 0
|
||||
constant byte* SCREEN = (byte*) 1024
|
||||
void main()
|
||||
|
||||
|
||||
|
||||
FINAL ASSEMBLER
|
||||
Score: 12
|
||||
|
||||
// File Comments
|
||||
// Test typedef enum
|
||||
// Upstart
|
||||
// Commodore 64 PRG executable file
|
||||
.file [name="typedef-8.prg", type="prg", segments="Program"]
|
||||
.segmentdef Program [segments="Basic, Code, Data"]
|
||||
.segmentdef Basic [start=$0801]
|
||||
.segmentdef Code [start=$80d]
|
||||
.segmentdef Data [startAfter="Code"]
|
||||
.segment Basic
|
||||
:BasicUpstart(main)
|
||||
// Global Constants & labels
|
||||
.const FALSE = 0
|
||||
.label SCREEN = $400
|
||||
.segment Code
|
||||
// main
|
||||
main: {
|
||||
// *SCREEN = exe
|
||||
// [0] *SCREEN = FALSE -- _deref_pbuc1=vbuc2
|
||||
lda #FALSE
|
||||
sta SCREEN
|
||||
// main::@return
|
||||
// }
|
||||
// [1] return
|
||||
rts
|
||||
}
|
||||
// File Data
|
||||
|
4
src/test/ref/typedef-8.sym
Normal file
4
src/test/ref/typedef-8.sym
Normal file
@ -0,0 +1,4 @@
|
||||
constant byte FALSE = 0
|
||||
constant byte* SCREEN = (byte*) 1024
|
||||
void main()
|
||||
|
Loading…
x
Reference in New Issue
Block a user