1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-12-26 03:32:23 +00:00

Added support for typedefs with const/volatile directives. Closes #375

This commit is contained in:
Jesper Gravgaard 2020-03-30 13:25:52 +02:00
parent e3b54f34d7
commit 607f740f8b
27 changed files with 1352 additions and 79 deletions

View File

@ -640,10 +640,12 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
for(Directive directive : directives) {
if(directive instanceof Directive.Const || directive instanceof Directive.Volatile) {
// Type directive
this.declType.getTypeDirectives().add(directive);
if(!this.declType.getTypeDirectives().contains(directive))
this.declType.getTypeDirectives().add(directive);
} else {
// general directive
this.declDirectives.add(directive);
if(!this.declDirectives.contains(directive))
this.declDirectives.add(directive);
}
}
}
@ -1773,11 +1775,33 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
Variable typeDefVariable = typeDefScope.getVar(ctx.getText());
if(typeDefVariable != null) {
varDecl.setDeclType(typeDefVariable.getType());
// Handle pointer types by creating sub-decltypes
VariableDeclaration.VariableDeclType declType = varDecl.getDeclType();
SymbolType type = typeDefVariable.getType();
while(type instanceof SymbolTypePointer) {
VariableDeclaration.VariableDeclType elementDeclType = new VariableDeclaration.VariableDeclType();
SymbolType elementType = ((SymbolTypePointer) type).getElementType();
elementDeclType.setType(elementType);
declType.setElementDeclType(elementDeclType);
type = elementType;
declType = elementDeclType;
}
if(typeDefVariable.getArraySpec() != null)
varDecl.getDeclType().setArraySpec(typeDefVariable.getArraySpec());
if(typeDefVariable.isNoModify() || typeDefVariable.isVolatile() || typeDefVariable.isToNoModify() || typeDefVariable.isToVolatile())
// TODO: Handle type directives correctly
throw new InternalError("Typedef with type directives not supported!");
if(typeDefVariable.isNoModify())
varDecl.getDeclType().getTypeDirectives().add(new Directive.Const());
if(typeDefVariable.isVolatile())
varDecl.getDeclType().getTypeDirectives().add(new Directive.Volatile());
if(typeDefVariable.isToNoModify()) {
// Find sub-type and add const
varDecl.getDeclType().getElementDeclType().getTypeDirectives().add(new Directive.Const());
}
if(typeDefVariable.isToVolatile()) {
// Find sub-type and add volatile
varDecl.getDeclType().getElementDeclType().getTypeDirectives().add(new Directive.Volatile());
}
return null;
}
throw new CompileError("Unknown type " + ctx.getText(), new StatementSource(ctx));

View File

@ -941,20 +941,30 @@ public class TestPrograms {
compileAndCompare("enum-0");
}
//@Test
//public void testPointerConstTypedef() throws IOException, URISyntaxException {
// compileAndCompare("pointer-const-typedef");
//}
@Test
public void testPointerConstTypedef() throws IOException, URISyntaxException {
compileAndCompare("pointer-const-typedef");
}
//@Test
//public void testTypedef5() throws IOException, URISyntaxException {
// compileAndCompare("typedef-5");
//}
@Test
public void testTypedef7() throws IOException, URISyntaxException {
compileAndCompare("typedef-7");
}
//@Test
//public void testTypedef4() throws IOException, URISyntaxException {
// compileAndCompare("typedef-4");
//}
@Test
public void testTypedef6() throws IOException, URISyntaxException {
compileAndCompare("typedef-6");
}
@Test
public void testTypedef5() throws IOException, URISyntaxException {
compileAndCompare("typedef-5");
}
@Test
public void testTypedef4() throws IOException, URISyntaxException {
compileAndCompare("typedef-4");
}
@Test
public void testTypedef3() throws IOException, URISyntaxException {

View File

@ -0,0 +1,13 @@
// Failing number type resolving in ternary operator
// Currently fails in the ternary operator with number-issues if integer literal is not specified!
void main() {
char* BASIC = 0xa000;
char* SCREEN = 0x0400;
for( char i: 0..7 ) {
char glyph_bits = BASIC[i];
char glyph_bit = (glyph_bits&0x80)?1:0;
SCREEN[i] = glyph_bit;
}
}

View File

@ -1,12 +1,14 @@
// Typedef a const type
// Typedef const/volatile type
char* const SCREEN = 0x0400;
typedef const char C;
typedef volatile char V;
C c = 'c';
const C c = 'c';
volatile V v = 'v';
void main() {
SCREEN[0] = c++;
SCREEN[1] = c++;
SCREEN[0] = c;
SCREEN[1] = v;
}

View File

@ -1,11 +1,14 @@
// Typedef a const type and instantiate a pointer to it
// Typedef a const/volatile type and instantiate a pointer to it
char* const SCREEN = 0x0400;
typedef const char C;
typedef volatile char V;
C * cp = 0xa003;
V * vp = 0xa004;
void main() {
SCREEN[0] = *cp;
SCREEN[1] = *vp;
}

14
src/test/kc/typedef-6.kc Normal file
View File

@ -0,0 +1,14 @@
// Typedef pointer to const/volatile type and instantiate it
char* const SCREEN = 0x0400;
typedef const char * C;
typedef volatile char * V;
C cp = 0xa003;
V vp = 0xa004;
void main() {
SCREEN[0] = *cp;
SCREEN[1] = *vp;
}

14
src/test/kc/typedef-7.kc Normal file
View File

@ -0,0 +1,14 @@
// Typedef pointer to const/volatile type and instantiate it to const variable
char* const SCREEN = 0x0400;
typedef const char * C;
typedef volatile char * V;
const C cp = 0xa003;
const V vp = 0xa004;
void main() {
SCREEN[0] = *cp;
SCREEN[1] = *vp;
}

View File

@ -4,6 +4,7 @@
.pc = $80d "Program"
// Const pointer
.label cp0 = $400
.label cp1 = $400
.label cp2 = $400
// Const pointer to const
.label cpc0 = $400
@ -13,7 +14,6 @@
.label pc0 = $400
.label pc1 = $400
.label pc2 = $400
.label cp1 = $400
.label SCREEN = $400
main: {
// SCREEN[idx++] = *pc0

View File

@ -11,14 +11,14 @@
(void()) main()
main: scope:[main] from @1
[4] *((const byte*) SCREEN) ← *((const to_nomodify byte*) pc0)
[5] *((const byte*) SCREEN+(byte) 1) ← *((const byte*) pc1)
[6] *((const byte*) SCREEN+(byte) 2) ← *((const byte*) pc2)
[5] *((const byte*) SCREEN+(byte) 1) ← *((const to_nomodify byte*) pc1)
[6] *((const byte*) SCREEN+(byte) 2) ← *((const to_nomodify byte*) pc2)
[7] *((const byte*) SCREEN+(byte) 3) ← *((const nomodify byte*) cp0)
[8] *((const byte*) SCREEN+(byte) 4) ← *((const byte*) cp1)
[8] *((const byte*) SCREEN+(byte) 4) ← *((const nomodify byte*) cp1)
[9] *((const byte*) SCREEN+(byte) 5) ← *((const nomodify byte*) cp2)
[10] *((const byte*) SCREEN+(byte) 6) ← *((const nomodify to_nomodify byte*) cpc0)
[11] *((const byte*) SCREEN+(byte) 7) ← *((const nomodify byte*) cpc1)
[12] *((const byte*) SCREEN+(byte) 8) ← *((const nomodify byte*) cpc2)
[11] *((const byte*) SCREEN+(byte) 7) ← *((const nomodify to_nomodify byte*) cpc1)
[12] *((const byte*) SCREEN+(byte) 8) ← *((const nomodify to_nomodify byte*) cpc2)
to:main::@return
main::@return: scope:[main] from main
[13] return

View File

@ -1,7 +1,6 @@
Identified constant variable (to_nomodify byte*) pc0
Identified constant variable (byte*) pc1
Identified constant variable (byte*) pc2
Identified constant variable (byte*) cp1
Identified constant variable (to_nomodify byte*) pc1
Identified constant variable (to_nomodify byte*) pc2
Identified constant variable (byte*) SCREEN
CONTROL FLOW GRAPH SSA
@ -13,21 +12,21 @@ main: scope:[main] from @1
(byte) main::idx#0 ← (byte) 0
*((const byte*) SCREEN + (byte) main::idx#0) ← *((const to_nomodify byte*) pc0)
(byte) main::idx#1 ← ++ (byte) main::idx#0
*((const byte*) SCREEN + (byte) main::idx#1) ← *((const byte*) pc1)
*((const byte*) SCREEN + (byte) main::idx#1) ← *((const to_nomodify byte*) pc1)
(byte) main::idx#2 ← ++ (byte) main::idx#1
*((const byte*) SCREEN + (byte) main::idx#2) ← *((const byte*) pc2)
*((const byte*) SCREEN + (byte) main::idx#2) ← *((const to_nomodify byte*) pc2)
(byte) main::idx#3 ← ++ (byte) main::idx#2
*((const byte*) SCREEN + (byte) main::idx#3) ← *((const nomodify byte*) cp0)
(byte) main::idx#4 ← ++ (byte) main::idx#3
*((const byte*) SCREEN + (byte) main::idx#4) ← *((const byte*) cp1)
*((const byte*) SCREEN + (byte) main::idx#4) ← *((const nomodify byte*) cp1)
(byte) main::idx#5 ← ++ (byte) main::idx#4
*((const byte*) SCREEN + (byte) main::idx#5) ← *((const nomodify byte*) cp2)
(byte) main::idx#6 ← ++ (byte) main::idx#5
*((const byte*) SCREEN + (byte) main::idx#6) ← *((const nomodify to_nomodify byte*) cpc0)
(byte) main::idx#7 ← ++ (byte) main::idx#6
*((const byte*) SCREEN + (byte) main::idx#7) ← *((const nomodify byte*) cpc1)
*((const byte*) SCREEN + (byte) main::idx#7) ← *((const nomodify to_nomodify byte*) cpc1)
(byte) main::idx#8 ← ++ (byte) main::idx#7
*((const byte*) SCREEN + (byte) main::idx#8) ← *((const nomodify byte*) cpc2)
*((const byte*) SCREEN + (byte) main::idx#8) ← *((const nomodify to_nomodify byte*) cpc2)
(byte) main::idx#9 ← ++ (byte) main::idx#8
to:main::@return
main::@return: scope:[main] from main
@ -47,11 +46,11 @@ SYMBOL TABLE SSA
(label) @end
(const byte*) SCREEN = (byte*)(number) $400
(const nomodify byte*) cp0 = (byte*)(number) $400
(const byte*) cp1 = (byte*)(number) $400
(const nomodify byte*) cp1 = (byte*)(number) $400
(const nomodify byte*) cp2 = (byte*)(number) $400
(const nomodify to_nomodify byte*) cpc0 = (byte*)(number) $400
(const nomodify byte*) cpc1 = (byte*)(number) $400
(const nomodify byte*) cpc2 = (byte*)(number) $400
(const nomodify to_nomodify byte*) cpc1 = (byte*)(number) $400
(const nomodify to_nomodify byte*) cpc2 = (byte*)(number) $400
(void()) main()
(label) main::@return
(byte) main::idx
@ -66,8 +65,8 @@ SYMBOL TABLE SSA
(byte) main::idx#8
(byte) main::idx#9
(const to_nomodify byte*) pc0 = (byte*)(number) $400
(const byte*) pc1 = (byte*)(number) $400
(const byte*) pc2 = (byte*)(number) $400
(const to_nomodify byte*) pc1 = (byte*)(number) $400
(const to_nomodify byte*) pc2 = (byte*)(number) $400
Simplifying constant pointer cast (byte*) 1024
Simplifying constant pointer cast (byte*) 1024
@ -191,14 +190,14 @@ FINAL CONTROL FLOW GRAPH
(void()) main()
main: scope:[main] from @1
[4] *((const byte*) SCREEN) ← *((const to_nomodify byte*) pc0)
[5] *((const byte*) SCREEN+(byte) 1) ← *((const byte*) pc1)
[6] *((const byte*) SCREEN+(byte) 2) ← *((const byte*) pc2)
[5] *((const byte*) SCREEN+(byte) 1) ← *((const to_nomodify byte*) pc1)
[6] *((const byte*) SCREEN+(byte) 2) ← *((const to_nomodify byte*) pc2)
[7] *((const byte*) SCREEN+(byte) 3) ← *((const nomodify byte*) cp0)
[8] *((const byte*) SCREEN+(byte) 4) ← *((const byte*) cp1)
[8] *((const byte*) SCREEN+(byte) 4) ← *((const nomodify byte*) cp1)
[9] *((const byte*) SCREEN+(byte) 5) ← *((const nomodify byte*) cp2)
[10] *((const byte*) SCREEN+(byte) 6) ← *((const nomodify to_nomodify byte*) cpc0)
[11] *((const byte*) SCREEN+(byte) 7) ← *((const nomodify byte*) cpc1)
[12] *((const byte*) SCREEN+(byte) 8) ← *((const nomodify byte*) cpc2)
[11] *((const byte*) SCREEN+(byte) 7) ← *((const nomodify to_nomodify byte*) cpc1)
[12] *((const byte*) SCREEN+(byte) 8) ← *((const nomodify to_nomodify byte*) cpc2)
to:main::@return
main::@return: scope:[main] from main
[13] return
@ -223,6 +222,7 @@ Target platform is c64basic / MOS6502X
// Global Constants & labels
// Const pointer
.label cp0 = $400
.label cp1 = $400
.label cp2 = $400
// Const pointer to const
.label cpc0 = $400
@ -232,7 +232,6 @@ Target platform is c64basic / MOS6502X
.label pc0 = $400
.label pc1 = $400
.label pc2 = $400
.label cp1 = $400
.label SCREEN = $400
// @begin
__bbegin:
@ -253,16 +252,16 @@ main: {
// [4] *((const byte*) SCREEN) ← *((const to_nomodify byte*) pc0) -- _deref_pbuc1=_deref_pbuc2
lda pc0
sta SCREEN
// [5] *((const byte*) SCREEN+(byte) 1) ← *((const byte*) pc1) -- _deref_pbuc1=_deref_pbuc2
// [5] *((const byte*) SCREEN+(byte) 1) ← *((const to_nomodify byte*) pc1) -- _deref_pbuc1=_deref_pbuc2
lda pc1
sta SCREEN+1
// [6] *((const byte*) SCREEN+(byte) 2) ← *((const byte*) pc2) -- _deref_pbuc1=_deref_pbuc2
// [6] *((const byte*) SCREEN+(byte) 2) ← *((const to_nomodify byte*) pc2) -- _deref_pbuc1=_deref_pbuc2
lda pc2
sta SCREEN+2
// [7] *((const byte*) SCREEN+(byte) 3) ← *((const nomodify byte*) cp0) -- _deref_pbuc1=_deref_pbuc2
lda cp0
sta SCREEN+3
// [8] *((const byte*) SCREEN+(byte) 4) ← *((const byte*) cp1) -- _deref_pbuc1=_deref_pbuc2
// [8] *((const byte*) SCREEN+(byte) 4) ← *((const nomodify byte*) cp1) -- _deref_pbuc1=_deref_pbuc2
lda cp1
sta SCREEN+4
// [9] *((const byte*) SCREEN+(byte) 5) ← *((const nomodify byte*) cp2) -- _deref_pbuc1=_deref_pbuc2
@ -271,10 +270,10 @@ main: {
// [10] *((const byte*) SCREEN+(byte) 6) ← *((const nomodify to_nomodify byte*) cpc0) -- _deref_pbuc1=_deref_pbuc2
lda cpc0
sta SCREEN+6
// [11] *((const byte*) SCREEN+(byte) 7) ← *((const nomodify byte*) cpc1) -- _deref_pbuc1=_deref_pbuc2
// [11] *((const byte*) SCREEN+(byte) 7) ← *((const nomodify to_nomodify byte*) cpc1) -- _deref_pbuc1=_deref_pbuc2
lda cpc1
sta SCREEN+7
// [12] *((const byte*) SCREEN+(byte) 8) ← *((const nomodify byte*) cpc2) -- _deref_pbuc1=_deref_pbuc2
// [12] *((const byte*) SCREEN+(byte) 8) ← *((const nomodify to_nomodify byte*) cpc2) -- _deref_pbuc1=_deref_pbuc2
lda cpc2
sta SCREEN+8
jmp __breturn
@ -287,14 +286,14 @@ main: {
REGISTER UPLIFT POTENTIAL REGISTERS
Statement [4] *((const byte*) SCREEN) ← *((const to_nomodify byte*) pc0) [ ] ( main:2 [ ] { } ) always clobbers reg byte a
Statement [5] *((const byte*) SCREEN+(byte) 1) ← *((const byte*) pc1) [ ] ( main:2 [ ] { } ) always clobbers reg byte a
Statement [6] *((const byte*) SCREEN+(byte) 2) ← *((const byte*) pc2) [ ] ( main:2 [ ] { } ) always clobbers reg byte a
Statement [5] *((const byte*) SCREEN+(byte) 1) ← *((const to_nomodify byte*) pc1) [ ] ( main:2 [ ] { } ) always clobbers reg byte a
Statement [6] *((const byte*) SCREEN+(byte) 2) ← *((const to_nomodify byte*) pc2) [ ] ( main:2 [ ] { } ) always clobbers reg byte a
Statement [7] *((const byte*) SCREEN+(byte) 3) ← *((const nomodify byte*) cp0) [ ] ( main:2 [ ] { } ) always clobbers reg byte a
Statement [8] *((const byte*) SCREEN+(byte) 4) ← *((const byte*) cp1) [ ] ( main:2 [ ] { } ) always clobbers reg byte a
Statement [8] *((const byte*) SCREEN+(byte) 4) ← *((const nomodify byte*) cp1) [ ] ( main:2 [ ] { } ) always clobbers reg byte a
Statement [9] *((const byte*) SCREEN+(byte) 5) ← *((const nomodify byte*) cp2) [ ] ( main:2 [ ] { } ) always clobbers reg byte a
Statement [10] *((const byte*) SCREEN+(byte) 6) ← *((const nomodify to_nomodify byte*) cpc0) [ ] ( main:2 [ ] { } ) always clobbers reg byte a
Statement [11] *((const byte*) SCREEN+(byte) 7) ← *((const nomodify byte*) cpc1) [ ] ( main:2 [ ] { } ) always clobbers reg byte a
Statement [12] *((const byte*) SCREEN+(byte) 8) ← *((const nomodify byte*) cpc2) [ ] ( main:2 [ ] { } ) always clobbers reg byte a
Statement [11] *((const byte*) SCREEN+(byte) 7) ← *((const nomodify to_nomodify byte*) cpc1) [ ] ( main:2 [ ] { } ) always clobbers reg byte a
Statement [12] *((const byte*) SCREEN+(byte) 8) ← *((const nomodify to_nomodify byte*) cpc2) [ ] ( main:2 [ ] { } ) always clobbers reg byte a
REGISTER UPLIFT SCOPES
Uplift Scope [main]
@ -313,6 +312,7 @@ ASSEMBLER BEFORE OPTIMIZATION
// Global Constants & labels
// Const pointer
.label cp0 = $400
.label cp1 = $400
.label cp2 = $400
// Const pointer to const
.label cpc0 = $400
@ -322,7 +322,6 @@ ASSEMBLER BEFORE OPTIMIZATION
.label pc0 = $400
.label pc1 = $400
.label pc2 = $400
.label cp1 = $400
.label SCREEN = $400
// @begin
__bbegin:
@ -343,16 +342,16 @@ main: {
// [4] *((const byte*) SCREEN) ← *((const to_nomodify byte*) pc0) -- _deref_pbuc1=_deref_pbuc2
lda pc0
sta SCREEN
// [5] *((const byte*) SCREEN+(byte) 1) ← *((const byte*) pc1) -- _deref_pbuc1=_deref_pbuc2
// [5] *((const byte*) SCREEN+(byte) 1) ← *((const to_nomodify byte*) pc1) -- _deref_pbuc1=_deref_pbuc2
lda pc1
sta SCREEN+1
// [6] *((const byte*) SCREEN+(byte) 2) ← *((const byte*) pc2) -- _deref_pbuc1=_deref_pbuc2
// [6] *((const byte*) SCREEN+(byte) 2) ← *((const to_nomodify byte*) pc2) -- _deref_pbuc1=_deref_pbuc2
lda pc2
sta SCREEN+2
// [7] *((const byte*) SCREEN+(byte) 3) ← *((const nomodify byte*) cp0) -- _deref_pbuc1=_deref_pbuc2
lda cp0
sta SCREEN+3
// [8] *((const byte*) SCREEN+(byte) 4) ← *((const byte*) cp1) -- _deref_pbuc1=_deref_pbuc2
// [8] *((const byte*) SCREEN+(byte) 4) ← *((const nomodify byte*) cp1) -- _deref_pbuc1=_deref_pbuc2
lda cp1
sta SCREEN+4
// [9] *((const byte*) SCREEN+(byte) 5) ← *((const nomodify byte*) cp2) -- _deref_pbuc1=_deref_pbuc2
@ -361,10 +360,10 @@ main: {
// [10] *((const byte*) SCREEN+(byte) 6) ← *((const nomodify to_nomodify byte*) cpc0) -- _deref_pbuc1=_deref_pbuc2
lda cpc0
sta SCREEN+6
// [11] *((const byte*) SCREEN+(byte) 7) ← *((const nomodify byte*) cpc1) -- _deref_pbuc1=_deref_pbuc2
// [11] *((const byte*) SCREEN+(byte) 7) ← *((const nomodify to_nomodify byte*) cpc1) -- _deref_pbuc1=_deref_pbuc2
lda cpc1
sta SCREEN+7
// [12] *((const byte*) SCREEN+(byte) 8) ← *((const nomodify byte*) cpc2) -- _deref_pbuc1=_deref_pbuc2
// [12] *((const byte*) SCREEN+(byte) 8) ← *((const nomodify to_nomodify byte*) cpc2) -- _deref_pbuc1=_deref_pbuc2
lda cpc2
sta SCREEN+8
jmp __breturn
@ -399,17 +398,17 @@ FINAL SYMBOL TABLE
(label) @end
(const byte*) SCREEN = (byte*) 1024
(const nomodify byte*) cp0 = (byte*) 1024
(const byte*) cp1 = (byte*) 1024
(const nomodify byte*) cp1 = (byte*) 1024
(const nomodify byte*) cp2 = (byte*) 1024
(const nomodify to_nomodify byte*) cpc0 = (byte*) 1024
(const nomodify byte*) cpc1 = (byte*) 1024
(const nomodify byte*) cpc2 = (byte*) 1024
(const nomodify to_nomodify byte*) cpc1 = (byte*) 1024
(const nomodify to_nomodify byte*) cpc2 = (byte*) 1024
(void()) main()
(label) main::@return
(byte) main::idx
(const to_nomodify byte*) pc0 = (byte*) 1024
(const byte*) pc1 = (byte*) 1024
(const byte*) pc2 = (byte*) 1024
(const to_nomodify byte*) pc1 = (byte*) 1024
(const to_nomodify byte*) pc2 = (byte*) 1024
@ -425,6 +424,7 @@ Score: 78
// Global Constants & labels
// Const pointer
.label cp0 = $400
.label cp1 = $400
.label cp2 = $400
// Const pointer to const
.label cpc0 = $400
@ -434,7 +434,6 @@ Score: 78
.label pc0 = $400
.label pc1 = $400
.label pc2 = $400
.label cp1 = $400
.label SCREEN = $400
// @begin
// [1] phi from @begin to @1 [phi:@begin->@1]
@ -449,11 +448,11 @@ main: {
lda pc0
sta SCREEN
// SCREEN[idx++] = *pc1
// [5] *((const byte*) SCREEN+(byte) 1) ← *((const byte*) pc1) -- _deref_pbuc1=_deref_pbuc2
// [5] *((const byte*) SCREEN+(byte) 1) ← *((const to_nomodify byte*) pc1) -- _deref_pbuc1=_deref_pbuc2
lda pc1
sta SCREEN+1
// SCREEN[idx++] = *pc2
// [6] *((const byte*) SCREEN+(byte) 2) ← *((const byte*) pc2) -- _deref_pbuc1=_deref_pbuc2
// [6] *((const byte*) SCREEN+(byte) 2) ← *((const to_nomodify byte*) pc2) -- _deref_pbuc1=_deref_pbuc2
lda pc2
sta SCREEN+2
// SCREEN[idx++] = *cp0
@ -461,7 +460,7 @@ main: {
lda cp0
sta SCREEN+3
// SCREEN[idx++] = *cp1
// [8] *((const byte*) SCREEN+(byte) 4) ← *((const byte*) cp1) -- _deref_pbuc1=_deref_pbuc2
// [8] *((const byte*) SCREEN+(byte) 4) ← *((const nomodify byte*) cp1) -- _deref_pbuc1=_deref_pbuc2
lda cp1
sta SCREEN+4
// SCREEN[idx++] = *cp2
@ -473,11 +472,11 @@ main: {
lda cpc0
sta SCREEN+6
// SCREEN[idx++] = *cpc1
// [11] *((const byte*) SCREEN+(byte) 7) ← *((const nomodify byte*) cpc1) -- _deref_pbuc1=_deref_pbuc2
// [11] *((const byte*) SCREEN+(byte) 7) ← *((const nomodify to_nomodify byte*) cpc1) -- _deref_pbuc1=_deref_pbuc2
lda cpc1
sta SCREEN+7
// SCREEN[idx++] = *cpc2
// [12] *((const byte*) SCREEN+(byte) 8) ← *((const nomodify byte*) cpc2) -- _deref_pbuc1=_deref_pbuc2
// [12] *((const byte*) SCREEN+(byte) 8) ← *((const nomodify to_nomodify byte*) cpc2) -- _deref_pbuc1=_deref_pbuc2
lda cpc2
sta SCREEN+8
// main::@return

View File

@ -3,15 +3,15 @@
(label) @end
(const byte*) SCREEN = (byte*) 1024
(const nomodify byte*) cp0 = (byte*) 1024
(const byte*) cp1 = (byte*) 1024
(const nomodify byte*) cp1 = (byte*) 1024
(const nomodify byte*) cp2 = (byte*) 1024
(const nomodify to_nomodify byte*) cpc0 = (byte*) 1024
(const nomodify byte*) cpc1 = (byte*) 1024
(const nomodify byte*) cpc2 = (byte*) 1024
(const nomodify to_nomodify byte*) cpc1 = (byte*) 1024
(const nomodify to_nomodify byte*) cpc2 = (byte*) 1024
(void()) main()
(label) main::@return
(byte) main::idx
(const to_nomodify byte*) pc0 = (byte*) 1024
(const byte*) pc1 = (byte*) 1024
(const byte*) pc2 = (byte*) 1024
(const to_nomodify byte*) pc1 = (byte*) 1024
(const to_nomodify byte*) pc2 = (byte*) 1024

View File

@ -0,0 +1,23 @@
// Typedef const/volatile type
.pc = $801 "Basic"
:BasicUpstart(__bbegin)
.pc = $80d "Program"
.label SCREEN = $400
.const c = 'c'
.label v = 2
__bbegin:
// v = 'v'
lda #'v'
sta.z v
jsr main
rts
main: {
// SCREEN[0] = c
lda #c
sta SCREEN
// SCREEN[0] = v
lda.z v
sta SCREEN
// }
rts
}

View File

@ -0,0 +1,18 @@
@begin: scope:[] from
[0] (volatile byte) v ← (byte) 'v'
to:@1
@1: scope:[] from @begin
[1] phi()
[2] call main
to:@end
@end: scope:[] from @1
[3] phi()
(void()) main()
main: scope:[main] from @1
[4] *((const nomodify byte*) SCREEN) ← (const nomodify byte) c
[5] *((const nomodify byte*) SCREEN) ← (volatile byte) v
to:main::@return
main::@return: scope:[main] from main
[6] return
to:@return

263
src/test/ref/typedef-4.log Normal file
View File

@ -0,0 +1,263 @@
CONTROL FLOW GRAPH SSA
@begin: scope:[] from
(volatile byte) v ← (byte) 'v'
to:@1
(void()) main()
main: scope:[main] from @1
*((const nomodify byte*) SCREEN + (number) 0) ← (const nomodify byte) c
*((const nomodify byte*) SCREEN + (number) 0) ← (volatile byte) v
to:main::@return
main::@return: scope:[main] from main
return
to:@return
@1: scope:[] from @begin
call main
to:@2
@2: scope:[] from @1
to:@end
@end: scope:[] from @2
SYMBOL TABLE SSA
(label) @1
(label) @2
(label) @begin
(label) @end
(const nomodify byte*) SCREEN = (byte*)(number) $400
(const nomodify byte) c = (byte) 'c'
(void()) main()
(label) main::@return
(volatile byte) v loadstore
Adding number conversion cast (unumber) 0 in *((const nomodify byte*) SCREEN + (number) 0) ← (const nomodify byte) c
Adding number conversion cast (unumber) 0 in *((const nomodify byte*) SCREEN + (number) 0) ← (volatile byte) v
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant pointer cast (byte*) 1024
Simplifying constant integer cast 0
Simplifying constant integer cast 0
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) 0
Finalized unsigned number type (byte) 0
Successful SSA optimization PassNFinalizeNumberTypeConversions
Simplifying expression containing zero SCREEN in [1] *((const nomodify byte*) SCREEN + (byte) 0) ← (const nomodify byte) c
Simplifying expression containing zero SCREEN in [2] *((const nomodify byte*) SCREEN + (byte) 0) ← (volatile byte) v
Successful SSA optimization PassNSimplifyExpressionWithZero
Adding NOP phi() at start of @1
Adding NOP phi() at start of @2
Adding NOP phi() at start of @end
CALL GRAPH
Calls in [] to main:2
Created 0 initial phi equivalence classes
Coalesced down to 0 phi equivalence classes
Culled Empty Block (label) @2
Adding NOP phi() at start of @1
Adding NOP phi() at start of @end
FINAL CONTROL FLOW GRAPH
@begin: scope:[] from
[0] (volatile byte) v ← (byte) 'v'
to:@1
@1: scope:[] from @begin
[1] phi()
[2] call main
to:@end
@end: scope:[] from @1
[3] phi()
(void()) main()
main: scope:[main] from @1
[4] *((const nomodify byte*) SCREEN) ← (const nomodify byte) c
[5] *((const nomodify byte*) SCREEN) ← (volatile byte) v
to:main::@return
main::@return: scope:[main] from main
[6] return
to:@return
VARIABLE REGISTER WEIGHTS
(void()) main()
(volatile byte) v loadstore 4.333333333333333
Initial phi equivalence classes
Added variable v to live range equivalence class [ v ]
Complete equivalence classes
[ v ]
Allocated zp[1]:2 [ v ]
INITIAL ASM
Target platform is c64basic / MOS6502X
// File Comments
// Typedef const/volatile type
// Upstart
.pc = $801 "Basic"
:BasicUpstart(__bbegin)
.pc = $80d "Program"
// Global Constants & labels
.label SCREEN = $400
.const c = 'c'
.label v = 2
// @begin
__bbegin:
// [0] (volatile byte) v ← (byte) 'v' -- vbuz1=vbuc1
lda #'v'
sta.z v
// [1] phi from @begin to @1 [phi:@begin->@1]
__b1_from___bbegin:
jmp __b1
// @1
__b1:
// [2] call main
jsr main
// [3] phi from @1 to @end [phi:@1->@end]
__bend_from___b1:
jmp __bend
// @end
__bend:
// main
main: {
// [4] *((const nomodify byte*) SCREEN) ← (const nomodify byte) c -- _deref_pbuc1=vbuc2
lda #c
sta SCREEN
// [5] *((const nomodify byte*) SCREEN) ← (volatile byte) v -- _deref_pbuc1=vbuz1
lda.z v
sta SCREEN
jmp __breturn
// main::@return
__breturn:
// [6] return
rts
}
// File Data
REGISTER UPLIFT POTENTIAL REGISTERS
Statement [0] (volatile byte) v ← (byte) 'v' [ v ] ( [ v ] { } ) always clobbers reg byte a
Statement [4] *((const nomodify byte*) SCREEN) ← (const nomodify byte) c [ v ] ( main:2 [ v ] { } ) always clobbers reg byte a
Statement [5] *((const nomodify byte*) SCREEN) ← (volatile byte) v [ ] ( main:2 [ ] { } ) always clobbers reg byte a
Potential registers zp[1]:2 [ v ] : zp[1]:2 ,
REGISTER UPLIFT SCOPES
Uplift Scope [] 4.33: zp[1]:2 [ v ]
Uplift Scope [main]
Uplifting [] best 39 combination zp[1]:2 [ v ]
Uplifting [main] best 39 combination
Attempting to uplift remaining variables inzp[1]:2 [ v ]
Uplifting [] best 39 combination zp[1]:2 [ v ]
ASSEMBLER BEFORE OPTIMIZATION
// File Comments
// Typedef const/volatile type
// Upstart
.pc = $801 "Basic"
:BasicUpstart(__bbegin)
.pc = $80d "Program"
// Global Constants & labels
.label SCREEN = $400
.const c = 'c'
.label v = 2
// @begin
__bbegin:
// [0] (volatile byte) v ← (byte) 'v' -- vbuz1=vbuc1
lda #'v'
sta.z v
// [1] phi from @begin to @1 [phi:@begin->@1]
__b1_from___bbegin:
jmp __b1
// @1
__b1:
// [2] call main
jsr main
// [3] phi from @1 to @end [phi:@1->@end]
__bend_from___b1:
jmp __bend
// @end
__bend:
// main
main: {
// [4] *((const nomodify byte*) SCREEN) ← (const nomodify byte) c -- _deref_pbuc1=vbuc2
lda #c
sta SCREEN
// [5] *((const nomodify byte*) SCREEN) ← (volatile byte) v -- _deref_pbuc1=vbuz1
lda.z v
sta SCREEN
jmp __breturn
// main::@return
__breturn:
// [6] return
rts
}
// File Data
ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __b1
Removing instruction jmp __bend
Removing instruction jmp __breturn
Succesful ASM optimization Pass5NextJumpElimination
Removing instruction __b1_from___bbegin:
Removing instruction __bend_from___b1:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction __b1:
Removing instruction __bend:
Removing instruction __breturn:
Succesful ASM optimization Pass5UnusedLabelElimination
Adding RTS to root block
Succesful ASM optimization Pass5AddMainRts
FINAL SYMBOL TABLE
(label) @1
(label) @begin
(label) @end
(const nomodify byte*) SCREEN = (byte*) 1024
(const nomodify byte) c = (byte) 'c'
(void()) main()
(label) main::@return
(volatile byte) v loadstore zp[1]:2 4.333333333333333
zp[1]:2 [ v ]
FINAL ASSEMBLER
Score: 36
// File Comments
// Typedef const/volatile type
// Upstart
.pc = $801 "Basic"
:BasicUpstart(__bbegin)
.pc = $80d "Program"
// Global Constants & labels
.label SCREEN = $400
.const c = 'c'
.label v = 2
// @begin
__bbegin:
// v = 'v'
// [0] (volatile byte) v ← (byte) 'v' -- vbuz1=vbuc1
lda #'v'
sta.z v
// [1] phi from @begin to @1 [phi:@begin->@1]
// @1
// [2] call main
jsr main
rts
// [3] phi from @1 to @end [phi:@1->@end]
// @end
// main
main: {
// SCREEN[0] = c
// [4] *((const nomodify byte*) SCREEN) ← (const nomodify byte) c -- _deref_pbuc1=vbuc2
lda #c
sta SCREEN
// SCREEN[0] = v
// [5] *((const nomodify byte*) SCREEN) ← (volatile byte) v -- _deref_pbuc1=vbuz1
lda.z v
sta SCREEN
// main::@return
// }
// [6] return
rts
}
// File Data

View File

@ -0,0 +1,10 @@
(label) @1
(label) @begin
(label) @end
(const nomodify byte*) SCREEN = (byte*) 1024
(const nomodify byte) c = (byte) 'c'
(void()) main()
(label) main::@return
(volatile byte) v loadstore zp[1]:2 4.333333333333333
zp[1]:2 [ v ]

View File

@ -0,0 +1,17 @@
// Typedef a const/volatile type and instantiate a pointer to it
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
.label SCREEN = $400
.label cp = $a003
.label vp = $a004
main: {
// SCREEN[0] = *cp
lda cp
sta SCREEN
// SCREEN[1] = *vp
lda vp
sta SCREEN+1
// }
rts
}

View File

@ -0,0 +1,18 @@
@begin: scope:[] from
[0] phi()
to:@1
@1: scope:[] from @begin
[1] phi()
[2] call main
to:@end
@end: scope:[] from @1
[3] phi()
(void()) main()
main: scope:[main] from @1
[4] *((const nomodify byte*) SCREEN) ← *((const to_nomodify byte*) cp)
[5] *((const nomodify byte*) SCREEN+(byte) 1) ← *((const to_volatile byte*) vp)
to:main::@return
main::@return: scope:[main] from main
[6] return
to:@return

250
src/test/ref/typedef-5.log Normal file
View File

@ -0,0 +1,250 @@
Identified constant variable (to_nomodify byte*) cp
Identified constant variable (to_volatile byte*) vp
CONTROL FLOW GRAPH SSA
@begin: scope:[] from
to:@1
(void()) main()
main: scope:[main] from @1
*((const nomodify byte*) SCREEN + (number) 0) ← *((const to_nomodify byte*) cp)
*((const nomodify byte*) SCREEN + (number) 1) ← *((const to_volatile byte*) vp)
to:main::@return
main::@return: scope:[main] from main
return
to:@return
@1: scope:[] from @begin
call main
to:@2
@2: scope:[] from @1
to:@end
@end: scope:[] from @2
SYMBOL TABLE SSA
(label) @1
(label) @2
(label) @begin
(label) @end
(const nomodify byte*) SCREEN = (byte*)(number) $400
(const to_nomodify byte*) cp = (byte*)(number) $a003
(void()) main()
(label) main::@return
(const to_volatile byte*) vp = (byte*)(number) $a004
Adding number conversion cast (unumber) 0 in *((const nomodify byte*) SCREEN + (number) 0) ← *((const to_nomodify byte*) cp)
Adding number conversion cast (unumber) 1 in *((const nomodify byte*) SCREEN + (number) 1) ← *((const to_volatile byte*) vp)
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant pointer cast (byte*) 1024
Simplifying constant pointer cast (byte*) 40963
Simplifying constant pointer cast (byte*) 40964
Simplifying constant integer cast 0
Simplifying constant integer cast 1
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) 0
Finalized unsigned number type (byte) 1
Successful SSA optimization PassNFinalizeNumberTypeConversions
Simplifying expression containing zero SCREEN in [0] *((const nomodify byte*) SCREEN + (byte) 0) ← *((const to_nomodify byte*) cp)
Successful SSA optimization PassNSimplifyExpressionWithZero
Consolidated array index constant in *(SCREEN+1)
Successful SSA optimization Pass2ConstantAdditionElimination
Adding NOP phi() at start of @begin
Adding NOP phi() at start of @1
Adding NOP phi() at start of @2
Adding NOP phi() at start of @end
CALL GRAPH
Calls in [] to main:2
Created 0 initial phi equivalence classes
Coalesced down to 0 phi equivalence classes
Culled Empty Block (label) @2
Adding NOP phi() at start of @begin
Adding NOP phi() at start of @1
Adding NOP phi() at start of @end
FINAL CONTROL FLOW GRAPH
@begin: scope:[] from
[0] phi()
to:@1
@1: scope:[] from @begin
[1] phi()
[2] call main
to:@end
@end: scope:[] from @1
[3] phi()
(void()) main()
main: scope:[main] from @1
[4] *((const nomodify byte*) SCREEN) ← *((const to_nomodify byte*) cp)
[5] *((const nomodify byte*) SCREEN+(byte) 1) ← *((const to_volatile byte*) vp)
to:main::@return
main::@return: scope:[main] from main
[6] return
to:@return
VARIABLE REGISTER WEIGHTS
(void()) main()
Initial phi equivalence classes
Complete equivalence classes
INITIAL ASM
Target platform is c64basic / MOS6502X
// File Comments
// Typedef a const/volatile type and instantiate a pointer to it
// Upstart
.pc = $801 "Basic"
:BasicUpstart(__bbegin)
.pc = $80d "Program"
// Global Constants & labels
.label SCREEN = $400
.label cp = $a003
.label vp = $a004
// @begin
__bbegin:
// [1] phi from @begin to @1 [phi:@begin->@1]
__b1_from___bbegin:
jmp __b1
// @1
__b1:
// [2] call main
jsr main
// [3] phi from @1 to @end [phi:@1->@end]
__bend_from___b1:
jmp __bend
// @end
__bend:
// main
main: {
// [4] *((const nomodify byte*) SCREEN) ← *((const to_nomodify byte*) cp) -- _deref_pbuc1=_deref_pbuc2
lda cp
sta SCREEN
// [5] *((const nomodify byte*) SCREEN+(byte) 1) ← *((const to_volatile byte*) vp) -- _deref_pbuc1=_deref_pbuc2
lda vp
sta SCREEN+1
jmp __breturn
// main::@return
__breturn:
// [6] return
rts
}
// File Data
REGISTER UPLIFT POTENTIAL REGISTERS
Statement [4] *((const nomodify byte*) SCREEN) ← *((const to_nomodify byte*) cp) [ ] ( main:2 [ ] { } ) always clobbers reg byte a
Statement [5] *((const nomodify byte*) SCREEN+(byte) 1) ← *((const to_volatile byte*) vp) [ ] ( main:2 [ ] { } ) always clobbers reg byte a
REGISTER UPLIFT SCOPES
Uplift Scope [main]
Uplift Scope []
Uplifting [main] best 37 combination
Uplifting [] best 37 combination
ASSEMBLER BEFORE OPTIMIZATION
// File Comments
// Typedef a const/volatile type and instantiate a pointer to it
// Upstart
.pc = $801 "Basic"
:BasicUpstart(__bbegin)
.pc = $80d "Program"
// Global Constants & labels
.label SCREEN = $400
.label cp = $a003
.label vp = $a004
// @begin
__bbegin:
// [1] phi from @begin to @1 [phi:@begin->@1]
__b1_from___bbegin:
jmp __b1
// @1
__b1:
// [2] call main
jsr main
// [3] phi from @1 to @end [phi:@1->@end]
__bend_from___b1:
jmp __bend
// @end
__bend:
// main
main: {
// [4] *((const nomodify byte*) SCREEN) ← *((const to_nomodify byte*) cp) -- _deref_pbuc1=_deref_pbuc2
lda cp
sta SCREEN
// [5] *((const nomodify byte*) SCREEN+(byte) 1) ← *((const to_volatile byte*) vp) -- _deref_pbuc1=_deref_pbuc2
lda vp
sta SCREEN+1
jmp __breturn
// main::@return
__breturn:
// [6] return
rts
}
// File Data
ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __b1
Removing instruction jmp __bend
Removing instruction jmp __breturn
Succesful ASM optimization Pass5NextJumpElimination
Removing instruction __b1_from___bbegin:
Removing instruction __b1:
Removing instruction __bend_from___b1:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction __bend:
Removing instruction __breturn:
Succesful ASM optimization Pass5UnusedLabelElimination
Updating BasicUpstart to call main directly
Removing instruction jsr main
Succesful ASM optimization Pass5SkipBegin
Removing instruction __bbegin:
Succesful ASM optimization Pass5UnusedLabelElimination
FINAL SYMBOL TABLE
(label) @1
(label) @begin
(label) @end
(const nomodify byte*) SCREEN = (byte*) 1024
(const to_nomodify byte*) cp = (byte*) 40963
(void()) main()
(label) main::@return
(const to_volatile byte*) vp = (byte*) 40964
FINAL ASSEMBLER
Score: 22
// File Comments
// Typedef a const/volatile type and instantiate a pointer to it
// Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
// Global Constants & labels
.label SCREEN = $400
.label cp = $a003
.label vp = $a004
// @begin
// [1] phi from @begin to @1 [phi:@begin->@1]
// @1
// [2] call main
// [3] phi from @1 to @end [phi:@1->@end]
// @end
// main
main: {
// SCREEN[0] = *cp
// [4] *((const nomodify byte*) SCREEN) ← *((const to_nomodify byte*) cp) -- _deref_pbuc1=_deref_pbuc2
lda cp
sta SCREEN
// SCREEN[1] = *vp
// [5] *((const nomodify byte*) SCREEN+(byte) 1) ← *((const to_volatile byte*) vp) -- _deref_pbuc1=_deref_pbuc2
lda vp
sta SCREEN+1
// main::@return
// }
// [6] return
rts
}
// File Data

View File

@ -0,0 +1,9 @@
(label) @1
(label) @begin
(label) @end
(const nomodify byte*) SCREEN = (byte*) 1024
(const to_nomodify byte*) cp = (byte*) 40963
(void()) main()
(label) main::@return
(const to_volatile byte*) vp = (byte*) 40964

View File

@ -0,0 +1,17 @@
// Typedef pointer to const/volatile type and instantiate it
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
.label SCREEN = $400
.label cp = $a003
.label vp = $a004
main: {
// SCREEN[0] = *cp
lda cp
sta SCREEN
// SCREEN[1] = *vp
lda vp
sta SCREEN+1
// }
rts
}

View File

@ -0,0 +1,18 @@
@begin: scope:[] from
[0] phi()
to:@1
@1: scope:[] from @begin
[1] phi()
[2] call main
to:@end
@end: scope:[] from @1
[3] phi()
(void()) main()
main: scope:[main] from @1
[4] *((const nomodify byte*) SCREEN) ← *((const to_nomodify byte*) cp)
[5] *((const nomodify byte*) SCREEN+(byte) 1) ← *((const to_volatile byte*) vp)
to:main::@return
main::@return: scope:[main] from main
[6] return
to:@return

250
src/test/ref/typedef-6.log Normal file
View File

@ -0,0 +1,250 @@
Identified constant variable (to_nomodify byte*) cp
Identified constant variable (to_volatile byte*) vp
CONTROL FLOW GRAPH SSA
@begin: scope:[] from
to:@1
(void()) main()
main: scope:[main] from @1
*((const nomodify byte*) SCREEN + (number) 0) ← *((const to_nomodify byte*) cp)
*((const nomodify byte*) SCREEN + (number) 1) ← *((const to_volatile byte*) vp)
to:main::@return
main::@return: scope:[main] from main
return
to:@return
@1: scope:[] from @begin
call main
to:@2
@2: scope:[] from @1
to:@end
@end: scope:[] from @2
SYMBOL TABLE SSA
(label) @1
(label) @2
(label) @begin
(label) @end
(const nomodify byte*) SCREEN = (byte*)(number) $400
(const to_nomodify byte*) cp = (byte*)(number) $a003
(void()) main()
(label) main::@return
(const to_volatile byte*) vp = (byte*)(number) $a004
Adding number conversion cast (unumber) 0 in *((const nomodify byte*) SCREEN + (number) 0) ← *((const to_nomodify byte*) cp)
Adding number conversion cast (unumber) 1 in *((const nomodify byte*) SCREEN + (number) 1) ← *((const to_volatile byte*) vp)
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant pointer cast (byte*) 1024
Simplifying constant pointer cast (byte*) 40963
Simplifying constant pointer cast (byte*) 40964
Simplifying constant integer cast 0
Simplifying constant integer cast 1
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) 0
Finalized unsigned number type (byte) 1
Successful SSA optimization PassNFinalizeNumberTypeConversions
Simplifying expression containing zero SCREEN in [0] *((const nomodify byte*) SCREEN + (byte) 0) ← *((const to_nomodify byte*) cp)
Successful SSA optimization PassNSimplifyExpressionWithZero
Consolidated array index constant in *(SCREEN+1)
Successful SSA optimization Pass2ConstantAdditionElimination
Adding NOP phi() at start of @begin
Adding NOP phi() at start of @1
Adding NOP phi() at start of @2
Adding NOP phi() at start of @end
CALL GRAPH
Calls in [] to main:2
Created 0 initial phi equivalence classes
Coalesced down to 0 phi equivalence classes
Culled Empty Block (label) @2
Adding NOP phi() at start of @begin
Adding NOP phi() at start of @1
Adding NOP phi() at start of @end
FINAL CONTROL FLOW GRAPH
@begin: scope:[] from
[0] phi()
to:@1
@1: scope:[] from @begin
[1] phi()
[2] call main
to:@end
@end: scope:[] from @1
[3] phi()
(void()) main()
main: scope:[main] from @1
[4] *((const nomodify byte*) SCREEN) ← *((const to_nomodify byte*) cp)
[5] *((const nomodify byte*) SCREEN+(byte) 1) ← *((const to_volatile byte*) vp)
to:main::@return
main::@return: scope:[main] from main
[6] return
to:@return
VARIABLE REGISTER WEIGHTS
(void()) main()
Initial phi equivalence classes
Complete equivalence classes
INITIAL ASM
Target platform is c64basic / MOS6502X
// File Comments
// Typedef pointer to const/volatile type and instantiate it
// Upstart
.pc = $801 "Basic"
:BasicUpstart(__bbegin)
.pc = $80d "Program"
// Global Constants & labels
.label SCREEN = $400
.label cp = $a003
.label vp = $a004
// @begin
__bbegin:
// [1] phi from @begin to @1 [phi:@begin->@1]
__b1_from___bbegin:
jmp __b1
// @1
__b1:
// [2] call main
jsr main
// [3] phi from @1 to @end [phi:@1->@end]
__bend_from___b1:
jmp __bend
// @end
__bend:
// main
main: {
// [4] *((const nomodify byte*) SCREEN) ← *((const to_nomodify byte*) cp) -- _deref_pbuc1=_deref_pbuc2
lda cp
sta SCREEN
// [5] *((const nomodify byte*) SCREEN+(byte) 1) ← *((const to_volatile byte*) vp) -- _deref_pbuc1=_deref_pbuc2
lda vp
sta SCREEN+1
jmp __breturn
// main::@return
__breturn:
// [6] return
rts
}
// File Data
REGISTER UPLIFT POTENTIAL REGISTERS
Statement [4] *((const nomodify byte*) SCREEN) ← *((const to_nomodify byte*) cp) [ ] ( main:2 [ ] { } ) always clobbers reg byte a
Statement [5] *((const nomodify byte*) SCREEN+(byte) 1) ← *((const to_volatile byte*) vp) [ ] ( main:2 [ ] { } ) always clobbers reg byte a
REGISTER UPLIFT SCOPES
Uplift Scope [main]
Uplift Scope []
Uplifting [main] best 37 combination
Uplifting [] best 37 combination
ASSEMBLER BEFORE OPTIMIZATION
// File Comments
// Typedef pointer to const/volatile type and instantiate it
// Upstart
.pc = $801 "Basic"
:BasicUpstart(__bbegin)
.pc = $80d "Program"
// Global Constants & labels
.label SCREEN = $400
.label cp = $a003
.label vp = $a004
// @begin
__bbegin:
// [1] phi from @begin to @1 [phi:@begin->@1]
__b1_from___bbegin:
jmp __b1
// @1
__b1:
// [2] call main
jsr main
// [3] phi from @1 to @end [phi:@1->@end]
__bend_from___b1:
jmp __bend
// @end
__bend:
// main
main: {
// [4] *((const nomodify byte*) SCREEN) ← *((const to_nomodify byte*) cp) -- _deref_pbuc1=_deref_pbuc2
lda cp
sta SCREEN
// [5] *((const nomodify byte*) SCREEN+(byte) 1) ← *((const to_volatile byte*) vp) -- _deref_pbuc1=_deref_pbuc2
lda vp
sta SCREEN+1
jmp __breturn
// main::@return
__breturn:
// [6] return
rts
}
// File Data
ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __b1
Removing instruction jmp __bend
Removing instruction jmp __breturn
Succesful ASM optimization Pass5NextJumpElimination
Removing instruction __b1_from___bbegin:
Removing instruction __b1:
Removing instruction __bend_from___b1:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction __bend:
Removing instruction __breturn:
Succesful ASM optimization Pass5UnusedLabelElimination
Updating BasicUpstart to call main directly
Removing instruction jsr main
Succesful ASM optimization Pass5SkipBegin
Removing instruction __bbegin:
Succesful ASM optimization Pass5UnusedLabelElimination
FINAL SYMBOL TABLE
(label) @1
(label) @begin
(label) @end
(const nomodify byte*) SCREEN = (byte*) 1024
(const to_nomodify byte*) cp = (byte*) 40963
(void()) main()
(label) main::@return
(const to_volatile byte*) vp = (byte*) 40964
FINAL ASSEMBLER
Score: 22
// File Comments
// Typedef pointer to const/volatile type and instantiate it
// Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
// Global Constants & labels
.label SCREEN = $400
.label cp = $a003
.label vp = $a004
// @begin
// [1] phi from @begin to @1 [phi:@begin->@1]
// @1
// [2] call main
// [3] phi from @1 to @end [phi:@1->@end]
// @end
// main
main: {
// SCREEN[0] = *cp
// [4] *((const nomodify byte*) SCREEN) ← *((const to_nomodify byte*) cp) -- _deref_pbuc1=_deref_pbuc2
lda cp
sta SCREEN
// SCREEN[1] = *vp
// [5] *((const nomodify byte*) SCREEN+(byte) 1) ← *((const to_volatile byte*) vp) -- _deref_pbuc1=_deref_pbuc2
lda vp
sta SCREEN+1
// main::@return
// }
// [6] return
rts
}
// File Data

View File

@ -0,0 +1,9 @@
(label) @1
(label) @begin
(label) @end
(const nomodify byte*) SCREEN = (byte*) 1024
(const to_nomodify byte*) cp = (byte*) 40963
(void()) main()
(label) main::@return
(const to_volatile byte*) vp = (byte*) 40964

View File

@ -0,0 +1,17 @@
// Typedef pointer to const/volatile type and instantiate it to const variable
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
.label SCREEN = $400
.label cp = $a003
.label vp = $a004
main: {
// SCREEN[0] = *cp
lda cp
sta SCREEN
// SCREEN[1] = *vp
lda vp
sta SCREEN+1
// }
rts
}

View File

@ -0,0 +1,18 @@
@begin: scope:[] from
[0] phi()
to:@1
@1: scope:[] from @begin
[1] phi()
[2] call main
to:@end
@end: scope:[] from @1
[3] phi()
(void()) main()
main: scope:[main] from @1
[4] *((const nomodify byte*) SCREEN) ← *((const nomodify to_nomodify byte*) cp)
[5] *((const nomodify byte*) SCREEN+(byte) 1) ← *((const nomodify to_volatile byte*) vp)
to:main::@return
main::@return: scope:[main] from main
[6] return
to:@return

248
src/test/ref/typedef-7.log Normal file
View File

@ -0,0 +1,248 @@
CONTROL FLOW GRAPH SSA
@begin: scope:[] from
to:@1
(void()) main()
main: scope:[main] from @1
*((const nomodify byte*) SCREEN + (number) 0) ← *((const nomodify to_nomodify byte*) cp)
*((const nomodify byte*) SCREEN + (number) 1) ← *((const nomodify to_volatile byte*) vp)
to:main::@return
main::@return: scope:[main] from main
return
to:@return
@1: scope:[] from @begin
call main
to:@2
@2: scope:[] from @1
to:@end
@end: scope:[] from @2
SYMBOL TABLE SSA
(label) @1
(label) @2
(label) @begin
(label) @end
(const nomodify byte*) SCREEN = (byte*)(number) $400
(const nomodify to_nomodify byte*) cp = (byte*)(number) $a003
(void()) main()
(label) main::@return
(const nomodify to_volatile byte*) vp = (byte*)(number) $a004
Adding number conversion cast (unumber) 0 in *((const nomodify byte*) SCREEN + (number) 0) ← *((const nomodify to_nomodify byte*) cp)
Adding number conversion cast (unumber) 1 in *((const nomodify byte*) SCREEN + (number) 1) ← *((const nomodify to_volatile byte*) vp)
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant pointer cast (byte*) 1024
Simplifying constant pointer cast (byte*) 40963
Simplifying constant pointer cast (byte*) 40964
Simplifying constant integer cast 0
Simplifying constant integer cast 1
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) 0
Finalized unsigned number type (byte) 1
Successful SSA optimization PassNFinalizeNumberTypeConversions
Simplifying expression containing zero SCREEN in [0] *((const nomodify byte*) SCREEN + (byte) 0) ← *((const nomodify to_nomodify byte*) cp)
Successful SSA optimization PassNSimplifyExpressionWithZero
Consolidated array index constant in *(SCREEN+1)
Successful SSA optimization Pass2ConstantAdditionElimination
Adding NOP phi() at start of @begin
Adding NOP phi() at start of @1
Adding NOP phi() at start of @2
Adding NOP phi() at start of @end
CALL GRAPH
Calls in [] to main:2
Created 0 initial phi equivalence classes
Coalesced down to 0 phi equivalence classes
Culled Empty Block (label) @2
Adding NOP phi() at start of @begin
Adding NOP phi() at start of @1
Adding NOP phi() at start of @end
FINAL CONTROL FLOW GRAPH
@begin: scope:[] from
[0] phi()
to:@1
@1: scope:[] from @begin
[1] phi()
[2] call main
to:@end
@end: scope:[] from @1
[3] phi()
(void()) main()
main: scope:[main] from @1
[4] *((const nomodify byte*) SCREEN) ← *((const nomodify to_nomodify byte*) cp)
[5] *((const nomodify byte*) SCREEN+(byte) 1) ← *((const nomodify to_volatile byte*) vp)
to:main::@return
main::@return: scope:[main] from main
[6] return
to:@return
VARIABLE REGISTER WEIGHTS
(void()) main()
Initial phi equivalence classes
Complete equivalence classes
INITIAL ASM
Target platform is c64basic / MOS6502X
// File Comments
// Typedef pointer to const/volatile type and instantiate it to const variable
// Upstart
.pc = $801 "Basic"
:BasicUpstart(__bbegin)
.pc = $80d "Program"
// Global Constants & labels
.label SCREEN = $400
.label cp = $a003
.label vp = $a004
// @begin
__bbegin:
// [1] phi from @begin to @1 [phi:@begin->@1]
__b1_from___bbegin:
jmp __b1
// @1
__b1:
// [2] call main
jsr main
// [3] phi from @1 to @end [phi:@1->@end]
__bend_from___b1:
jmp __bend
// @end
__bend:
// main
main: {
// [4] *((const nomodify byte*) SCREEN) ← *((const nomodify to_nomodify byte*) cp) -- _deref_pbuc1=_deref_pbuc2
lda cp
sta SCREEN
// [5] *((const nomodify byte*) SCREEN+(byte) 1) ← *((const nomodify to_volatile byte*) vp) -- _deref_pbuc1=_deref_pbuc2
lda vp
sta SCREEN+1
jmp __breturn
// main::@return
__breturn:
// [6] return
rts
}
// File Data
REGISTER UPLIFT POTENTIAL REGISTERS
Statement [4] *((const nomodify byte*) SCREEN) ← *((const nomodify to_nomodify byte*) cp) [ ] ( main:2 [ ] { } ) always clobbers reg byte a
Statement [5] *((const nomodify byte*) SCREEN+(byte) 1) ← *((const nomodify to_volatile byte*) vp) [ ] ( main:2 [ ] { } ) always clobbers reg byte a
REGISTER UPLIFT SCOPES
Uplift Scope [main]
Uplift Scope []
Uplifting [main] best 37 combination
Uplifting [] best 37 combination
ASSEMBLER BEFORE OPTIMIZATION
// File Comments
// Typedef pointer to const/volatile type and instantiate it to const variable
// Upstart
.pc = $801 "Basic"
:BasicUpstart(__bbegin)
.pc = $80d "Program"
// Global Constants & labels
.label SCREEN = $400
.label cp = $a003
.label vp = $a004
// @begin
__bbegin:
// [1] phi from @begin to @1 [phi:@begin->@1]
__b1_from___bbegin:
jmp __b1
// @1
__b1:
// [2] call main
jsr main
// [3] phi from @1 to @end [phi:@1->@end]
__bend_from___b1:
jmp __bend
// @end
__bend:
// main
main: {
// [4] *((const nomodify byte*) SCREEN) ← *((const nomodify to_nomodify byte*) cp) -- _deref_pbuc1=_deref_pbuc2
lda cp
sta SCREEN
// [5] *((const nomodify byte*) SCREEN+(byte) 1) ← *((const nomodify to_volatile byte*) vp) -- _deref_pbuc1=_deref_pbuc2
lda vp
sta SCREEN+1
jmp __breturn
// main::@return
__breturn:
// [6] return
rts
}
// File Data
ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __b1
Removing instruction jmp __bend
Removing instruction jmp __breturn
Succesful ASM optimization Pass5NextJumpElimination
Removing instruction __b1_from___bbegin:
Removing instruction __b1:
Removing instruction __bend_from___b1:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction __bend:
Removing instruction __breturn:
Succesful ASM optimization Pass5UnusedLabelElimination
Updating BasicUpstart to call main directly
Removing instruction jsr main
Succesful ASM optimization Pass5SkipBegin
Removing instruction __bbegin:
Succesful ASM optimization Pass5UnusedLabelElimination
FINAL SYMBOL TABLE
(label) @1
(label) @begin
(label) @end
(const nomodify byte*) SCREEN = (byte*) 1024
(const nomodify to_nomodify byte*) cp = (byte*) 40963
(void()) main()
(label) main::@return
(const nomodify to_volatile byte*) vp = (byte*) 40964
FINAL ASSEMBLER
Score: 22
// File Comments
// Typedef pointer to const/volatile type and instantiate it to const variable
// Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
// Global Constants & labels
.label SCREEN = $400
.label cp = $a003
.label vp = $a004
// @begin
// [1] phi from @begin to @1 [phi:@begin->@1]
// @1
// [2] call main
// [3] phi from @1 to @end [phi:@1->@end]
// @end
// main
main: {
// SCREEN[0] = *cp
// [4] *((const nomodify byte*) SCREEN) ← *((const nomodify to_nomodify byte*) cp) -- _deref_pbuc1=_deref_pbuc2
lda cp
sta SCREEN
// SCREEN[1] = *vp
// [5] *((const nomodify byte*) SCREEN+(byte) 1) ← *((const nomodify to_volatile byte*) vp) -- _deref_pbuc1=_deref_pbuc2
lda vp
sta SCREEN+1
// main::@return
// }
// [6] return
rts
}
// File Data

View File

@ -0,0 +1,9 @@
(label) @1
(label) @begin
(label) @end
(const nomodify byte*) SCREEN = (byte*) 1024
(const nomodify to_nomodify byte*) cp = (byte*) 40963
(void()) main()
(label) main::@return
(const nomodify to_volatile byte*) vp = (byte*) 40964