1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2025-02-16 18:30:37 +00:00

Converted ParamDecl to use declarator. #121

This commit is contained in:
jespergravgaard 2021-05-03 00:24:37 +02:00
parent 7fb310296d
commit d59c5315ec
13 changed files with 2160 additions and 1727 deletions

View File

@ -137,7 +137,7 @@ parameterListDecl
: parameterDecl (COMMA parameterDecl)* ;
parameterDecl
: declType declPointer* NAME #parameterDeclType
: declType declarator #parameterDeclType
| SIMPLETYPE #parameterDeclVoid
| PARAM_LIST #parameterDeclList
;

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@ -8,8 +8,9 @@ options { tokenVocab=KickCLexer; }
@members {
// The C parser
CParser cParser;
// true when a typedef is being created
boolean isTypedef;
public KickCParser(TokenStream input, CParser cParser) {
@ -56,7 +57,7 @@ declaratorInit
;
typeDef
: TYPEDEF declType declarator
: TYPEDEF declType { isTypedef=true; } declarator
;
declType
@ -70,7 +71,7 @@ typeSpecifier
;
declarator
: NAME {if(isTypedef) { Parser.addTypedef($NAME.text); isTypedef=false; } } #declaratorName
: NAME {if(isTypedef) { cParser.addTypedef($NAME.text); isTypedef=false; } } #declaratorName
| declarator PAR_BEGIN parameterListDecl? PAR_END #declaratorProcedure
| declarator BRACKET_BEGIN (expr)? BRACKET_END #declaratorArray
| ASTERISK directive* declarator #declaratorPointer

View File

@ -501,10 +501,8 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
@Override
public Object visitParameterDeclType(KickCParser.ParameterDeclTypeContext ctx) {
this.visit(ctx.declType());
for(KickCParser.DeclPointerContext declPointerContext : ctx.declPointer()) {
this.visit(declPointerContext);
}
String varName = ctx.NAME().getText();
this.visit(ctx.declarator());
String varName = varDecl.getVarName();
VariableBuilder varBuilder = new VariableBuilder(varName, getCurrentScope(), true, varDecl.getEffectiveType(), varDecl.getDeclDirectives(), currentDataSegment, program.getTargetPlatform().getVariableBuilderConfig());
Variable param = varBuilder.build();
varDecl.exitType();

View File

@ -18,7 +18,6 @@ import java.io.*;
import java.lang.management.GarbageCollectorMXBean;
import java.lang.management.ManagementFactory;
import java.lang.management.MemoryUsage;
import java.net.URISyntaxException;
import java.nio.file.FileAlreadyExistsException;
import java.nio.file.Files;
import java.nio.file.Path;
@ -94,11 +93,11 @@ public class TestPrograms {
return log;
}
protected void assertError(String kcFile, String expectError) throws IOException, URISyntaxException {
protected void assertError(String kcFile, String expectError) throws IOException {
assertError(kcFile, expectError, true);
}
protected void assertError(String kcFile, String expectError, boolean expectSource) throws IOException, URISyntaxException {
protected void assertError(String kcFile, String expectError, boolean expectSource) throws IOException {
try {
compileAndCompare(kcFile);
} catch(CompileError e) {

File diff suppressed because it is too large Load Diff

View File

@ -10,362 +10,362 @@ import java.net.URISyntaxException;
*/
public class TestProgramsThorough extends TestPrograms {
@Test
public void testCx16VeralibTilemap8bpp() throws IOException, URISyntaxException {
public void testCx16VeralibTilemap8bpp() throws IOException {
compileAndCompare("examples/cx16/veralib/tilemap_8bpp_16_x_16.c");
}
@Test
public void testCx16VeralibBitmap8bpp() throws IOException, URISyntaxException {
public void testCx16VeralibBitmap8bpp() throws IOException {
compileAndCompare("examples/cx16/veralib/bitmap_8bpp_320_x_240.c");
}
@Test
public void testCx16BankAddressing() throws IOException, URISyntaxException {
public void testCx16BankAddressing() throws IOException {
compileAndCompare("examples/cx16/cx16-bankaddressing.c");
}
//@Test
//public void testCx16SpaceDemo() throws IOException, URISyntaxException {
//public void testCx16SpaceDemo() throws IOException {
// compileAndCompare("examples/cx16/spacedemo/spacedemo.c");
//}
@Test
public void testCx16LoadFileInBank() throws IOException, URISyntaxException {
public void testCx16LoadFileInBank() throws IOException {
compileAndCompare("examples/cx16/cx16-bankload.c");
}
@Test
public void testCx16VeraLayers() throws IOException, URISyntaxException {
public void testCx16VeraLayers() throws IOException {
compileAndCompare("examples/cx16/cx16-veralayers.c");
}
@Test
public void testCx16TileMap() throws IOException, URISyntaxException {
public void testCx16TileMap() throws IOException {
compileAndCompare("examples/cx16/cx16-tilemap.c");
}
@Test
public void testCx16Sprites() throws IOException, URISyntaxException {
public void testCx16Sprites() throws IOException {
compileAndCompare("examples/cx16/cx16-sprites.c");
}
@Test
public void testCx16Text() throws IOException, URISyntaxException {
public void testCx16Text() throws IOException {
compileAndCompare("examples/cx16/cx16-text.c");
}
@Test
public void test32bitRols() throws IOException, URISyntaxException {
public void test32bitRols() throws IOException {
compileAndCompare("32bit-rols.c");
}
@Test
public void testComplexBorderlinePacman() throws IOException, URISyntaxException {
public void testComplexBorderlinePacman() throws IOException {
compileAndCompare("complex/borderline_pacman/pacman.c");
}
@Test
public void testComplexNew30YearsLowResolution() throws IOException, URISyntaxException {
public void testComplexNew30YearsLowResolution() throws IOException {
compileAndCompare("complex/new_30_years_low_resolution/new_30_years_low_resolution.c");
}
@Test
public void testC64DtvGfxExplorer() throws IOException, URISyntaxException {
public void testC64DtvGfxExplorer() throws IOException {
compileAndCompare("c64dtv-gfxexplorer.c", 10);
}
@Test
public void testC64DtvGfxModes() throws IOException, URISyntaxException {
public void testC64DtvGfxModes() throws IOException {
compileAndCompare("c64dtv-gfxmodes.c", 10);
}
@Test
public void testPrintf12() throws IOException, URISyntaxException {
public void testPrintf12() throws IOException {
compileAndCompare("printf-12.c");
}
@Test
public void testPrintf13() throws IOException, URISyntaxException {
public void testPrintf13() throws IOException {
compileAndCompare("printf-13.c");
}
@Test
public void testEightQueensRecursive() throws IOException, URISyntaxException {
public void testEightQueensRecursive() throws IOException {
compileAndCompare("examples/eightqueens/eightqueens-recursive.c");
}
@Test
public void testEightQueens() throws IOException, URISyntaxException {
public void testEightQueens() throws IOException {
compileAndCompare("examples/eightqueens/eightqueens.c");
}
@Test
public void testCpu65CE02EightQueens() throws IOException, URISyntaxException {
public void testCpu65CE02EightQueens() throws IOException {
compileAndCompare("cpu-65ce02-eightqueens.c");
}
@Test
public void testAdventOfCode04() throws IOException, URISyntaxException {
public void testAdventOfCode04() throws IOException {
compileAndCompare("adventofcode/2020-04.c");
}
@Test
public void testAdventOfCode03() throws IOException, URISyntaxException {
public void testAdventOfCode03() throws IOException {
compileAndCompare("adventofcode/2020-03.c");
}
@Test
public void testAdventOfCode02() throws IOException, URISyntaxException {
public void testAdventOfCode02() throws IOException {
compileAndCompare("adventofcode/2020-02.c");
}
@Test
public void testAdventOfCode01() throws IOException, URISyntaxException {
public void testAdventOfCode01() throws IOException {
compileAndCompare("adventofcode/2020-01.c");
}
@Test
public void testDeepNesting() throws IOException, URISyntaxException {
public void testDeepNesting() throws IOException {
compileAndCompare("deep-nesting.c");
}
@Test
public void testMultiply8Bit() throws IOException, URISyntaxException {
public void testMultiply8Bit() throws IOException {
compileAndCompare("test-multiply-8bit.c");
}
@Test
public void testSinusGenScale8() throws IOException, URISyntaxException {
public void testSinusGenScale8() throws IOException {
compileAndCompare("sinusgenscale8.c");
}
@Test
public void test3D() throws IOException, URISyntaxException {
public void test3D() throws IOException {
compileAndCompare("examples/c64/3d/3d.c");
}
@Test
public void testAtariXlMd5() throws IOException, URISyntaxException {
public void testAtariXlMd5() throws IOException {
compileAndCompare("atarixl-md5.c");
}
@Test
public void testMultiply16Bit() throws IOException, URISyntaxException {
public void testMultiply16Bit() throws IOException {
compileAndCompare("test-multiply-16bit.c");
}
@Test
public void testNesConio() throws IOException, URISyntaxException {
public void testNesConio() throws IOException {
compileAndCompare("examples/nes/nes-conio.c");
}
@Test
public void testRand1() throws IOException, URISyntaxException {
public void testRand1() throws IOException {
compileAndCompare("rand-1.c");
}
@Test
public void testScreenShowSpiralBuckets() throws IOException, URISyntaxException {
public void testScreenShowSpiralBuckets() throws IOException {
compileAndCompare("screen-show-spiral-buckets.c");
}
@Test
public void testPrintf2() throws IOException, URISyntaxException {
public void testPrintf2() throws IOException {
compileAndCompare("printf-2.c");
}
@Test
public void testStars1() throws IOException, URISyntaxException {
public void testStars1() throws IOException {
compileAndCompare("stars-1.c");
}
@Test
public void testSinusGen16b() throws IOException, URISyntaxException {
public void testSinusGen16b() throws IOException {
compileAndCompare("sinusgen16b.c");
}
@Test
public void testPrngXorshift() throws IOException, URISyntaxException {
public void testPrngXorshift() throws IOException {
compileAndCompare("prng-xorshift.c");
}
@Test
public void testPlasmaCenter() throws IOException, URISyntaxException {
public void testPlasmaCenter() throws IOException {
compileAndCompare("plasma-center.c");
}
@Test
public void testSemiStruct2() throws IOException, URISyntaxException {
public void testSemiStruct2() throws IOException {
compileAndCompare("semi-struct-2.c");
}
@Test
public void testTypeSigned() throws IOException, URISyntaxException {
public void testTypeSigned() throws IOException {
compileAndCompare("type-signed.c");
}
@Test
public void testDivision() throws IOException, URISyntaxException {
public void testDivision() throws IOException {
compileAndCompare("test-division.c");
}
@Test
public void testScrollLogo() throws IOException, URISyntaxException {
public void testScrollLogo() throws IOException {
compileAndCompare("examples/c64/scrolllogo/scrolllogo.c");
}
@Test
public void testSinusGen8b() throws IOException, URISyntaxException {
public void testSinusGen8b() throws IOException {
compileAndCompare("sinusgen8b.c");
}
@Test
public void testStdlibStringMemChr1() throws IOException, URISyntaxException {
public void testStdlibStringMemChr1() throws IOException {
compileAndCompare("stdlib-string-memchr-1.c");
}
@Test
public void testAtariXlConioTest() throws IOException, URISyntaxException {
public void testAtariXlConioTest() throws IOException {
compileAndCompare("examples/atarixl/atarixl-conio.c");
}
@Test
public void testPrintf16() throws IOException, URISyntaxException {
public void testPrintf16() throws IOException {
compileAndCompare("printf-16.c");
}
@Test
public void testNoRecursionHeavy() throws IOException, URISyntaxException {
public void testNoRecursionHeavy() throws IOException {
compileAndCompare("no-recursion-heavy.c");
}
@Test
public void testBitmapPlot2() throws IOException, URISyntaxException {
public void testBitmapPlot2() throws IOException {
compileAndCompare("bitmap-plot-2.c");
}
@Test
public void testPlasmaUnroll() throws IOException, URISyntaxException {
public void testPlasmaUnroll() throws IOException {
compileAndCompare("examples/c64/plasma/plasma-unroll.c");
}
@Test
public void testPrimes1000() throws IOException, URISyntaxException {
public void testPrimes1000() throws IOException {
compileAndCompare("primes-1000.c");
}
@Test
public void testBitmapPlot1() throws IOException, URISyntaxException {
public void testBitmapPlot1() throws IOException {
compileAndCompare("bitmap-plot-1.c");
}
@Test
public void testSinePlotter() throws IOException, URISyntaxException {
public void testSinePlotter() throws IOException {
compileAndCompare("examples/c64/sinplotter/sine-plotter.c");
}
@Test
public void testSinusSprites() throws IOException, URISyntaxException {
public void testSinusSprites() throws IOException {
compileAndCompare("examples/c64/sinsprites/sinus-sprites.c");
}
@Test
public void testConioNachtScreen() throws IOException, URISyntaxException {
public void testConioNachtScreen() throws IOException {
compileAndCompare("examples/conio/nacht-screen.c");
}
@Test
public void testScreenShowSpiral() throws IOException, URISyntaxException {
public void testScreenShowSpiral() throws IOException {
compileAndCompare("screen-show-spiral.c");
}
@Test
public void testCircleChars() throws IOException, URISyntaxException {
public void testCircleChars() throws IOException {
compileAndCompare("circlechars.c");
}
@Test
public void testPrintfSpeed() throws IOException, URISyntaxException {
public void testPrintfSpeed() throws IOException {
compileAndCompare("printf-speed.c");
}
@Test
public void testRotate() throws IOException, URISyntaxException {
public void testRotate() throws IOException {
compileAndCompare("examples/c64/rotate/rotate.c");
}
@Test
public void testXMega65Logo() throws IOException, URISyntaxException {
public void testXMega65Logo() throws IOException {
compileAndCompare("complex/xmega65/xmega65logo.c");
}
@Test
public void testPlasma() throws IOException, URISyntaxException {
public void testPlasma() throws IOException {
compileAndCompare("examples/c64/plasma/plasma.c");
}
@Test
public void testPaulNelsenSandbox() throws IOException, URISyntaxException {
public void testPaulNelsenSandbox() throws IOException {
compileAndCompare("sandbox.c");
}
@Test
public void testScreenCenterDistance() throws IOException, URISyntaxException {
public void testScreenCenterDistance() throws IOException {
compileAndCompare("screen-center-distance.c");
}
@Test
public void testNesDemo() throws IOException, URISyntaxException {
public void testNesDemo() throws IOException {
compileAndCompare("examples/nes/nes-demo.c");
}
@Test
public void testCordicAtan2Ref() throws IOException, URISyntaxException {
public void testCordicAtan2Ref() throws IOException {
compileAndCompare("cordic-atan2-16-ref.c");
}
@Test
public void testSieve() throws IOException, URISyntaxException {
public void testSieve() throws IOException {
compileAndCompare("sieve.c");
}
@Test
public void testAtoi() throws IOException, URISyntaxException {
public void testAtoi() throws IOException {
compileAndCompare("atoi-1.c");
}
@Test
public void testTextbox() throws IOException, URISyntaxException {
public void testTextbox() throws IOException {
compileAndCompare("textbox.c");
}
@Test
public void testSinusGen8() throws IOException, URISyntaxException {
public void testSinusGen8() throws IOException {
compileAndCompare("sinusgen8.c");
}
@Test
public void testScreenCenterAngle() throws IOException, URISyntaxException {
public void testScreenCenterAngle() throws IOException {
compileAndCompare("screen-center-angle.c");
}
@Test
public void testFastMultiply127() throws IOException, URISyntaxException {
public void testFastMultiply127() throws IOException {
compileAndCompare("fastmultiply-127.c");
}
@Test
public void testComparisons() throws IOException, URISyntaxException {
public void testComparisons() throws IOException {
compileAndCompare("test-comparisons.c", 10);
}
@Test
public void testChargenAnalysis() throws IOException, URISyntaxException {
public void testChargenAnalysis() throws IOException {
compileAndCompare("examples/c64/chargen/chargen-analysis.c");
}
@Test
public void testLineAnim() throws IOException, URISyntaxException {
public void testLineAnim() throws IOException {
compileAndCompare("line-anim.c");
}

View File

@ -0,0 +1,13 @@
// Procedure Declaration
char f(char a);
void main() {
char * const SCREEN = 0x0400;
SCREEN[0] = f('a');
SCREEN[1] = f('b');
}
char f(char a) {
return a+1;
}

View File

@ -0,0 +1,35 @@
// Procedure Declaration
// Commodore 64 PRG executable file
.file [name="procedure-declare-0.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)
.segment Code
main: {
.label SCREEN = $400
// f('a')
lda #'a'
jsr f
// f('a')
// SCREEN[0] = f('a')
sta SCREEN
// f('b')
lda #'b'
jsr f
// f('b')
// SCREEN[1] = f('b')
sta SCREEN+1
// }
rts
}
// f(byte register(A) a)
f: {
// a+1
clc
adc #1
// }
rts
}

View File

@ -0,0 +1,29 @@
void main()
main: scope:[main] from
[0] phi()
[1] call f
[2] f::return#0 = f::return#2
to:main::@1
main::@1: scope:[main] from main
[3] main::$0 = f::return#0
[4] *main::SCREEN = main::$0
[5] call f
[6] f::return#1 = f::return#2
to:main::@2
main::@2: scope:[main] from main::@1
[7] main::$1 = f::return#1
[8] *(main::SCREEN+1) = main::$1
to:main::@return
main::@return: scope:[main] from main::@2
[9] return
to:@return
byte f(byte f::a)
f: scope:[f] from main main::@1
[10] f::a#2 = phi( main/'a', main::@1/'b' )
[11] f::return#2 = f::a#2 + 1
to:f::@return
f::@return: scope:[f] from f
[12] return
to:@return

View File

@ -0,0 +1,357 @@
CONTROL FLOW GRAPH SSA
void main()
main: scope:[main] from __start
f::a#0 = 'a'
call f
f::return#0 = f::return#3
to:main::@1
main::@1: scope:[main] from main
f::return#4 = phi( main/f::return#0 )
main::$0 = f::return#4
main::SCREEN[0] = main::$0
f::a#1 = 'b'
call f
f::return#1 = f::return#3
to:main::@2
main::@2: scope:[main] from main::@1
f::return#5 = phi( main::@1/f::return#1 )
main::$1 = f::return#5
main::SCREEN[1] = main::$1
to:main::@return
main::@return: scope:[main] from main::@2
return
to:@return
byte f(byte f::a)
f: scope:[f] from main main::@1
f::a#2 = phi( main/f::a#0, main::@1/f::a#1 )
f::$0 = f::a#2 + 1
f::return#2 = f::$0
to:f::@return
f::@return: scope:[f] from f
f::return#6 = phi( f/f::return#2 )
f::return#3 = f::return#6
return
to:@return
void __start()
__start: scope:[__start] from
call main
to:__start::@1
__start::@1: scope:[__start] from __start
to:__start::@return
__start::@return: scope:[__start] from __start::@1
return
to:@return
SYMBOL TABLE SSA
void __start()
byte f(byte f::a)
number~ f::$0
byte f::a
byte f::a#0
byte f::a#1
byte f::a#2
byte f::return
byte f::return#0
byte f::return#1
byte f::return#2
byte f::return#3
byte f::return#4
byte f::return#5
byte f::return#6
void main()
byte~ main::$0
byte~ main::$1
constant byte* const main::SCREEN = (byte*)$400
Adding number conversion cast (unumber) 0 in main::SCREEN[0] = main::$0
Adding number conversion cast (unumber) 1 in main::SCREEN[1] = main::$1
Adding number conversion cast (unumber) 1 in f::$0 = f::a#2 + 1
Adding number conversion cast (unumber) f::$0 in f::$0 = f::a#2 + (unumber)1
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant pointer cast (byte*) 1024
Simplifying constant integer cast 0
Simplifying constant integer cast 1
Simplifying constant integer cast 1
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) 0
Finalized unsigned number type (byte) 1
Finalized unsigned number type (byte) 1
Successful SSA optimization PassNFinalizeNumberTypeConversions
Inferred type updated to byte in f::$0 = f::a#2 + 1
Alias f::return#0 = f::return#4
Alias f::return#1 = f::return#5
Alias f::return#2 = f::$0 f::return#6 f::return#3
Successful SSA optimization Pass2AliasElimination
Constant f::a#0 = 'a'
Constant f::a#1 = 'b'
Successful SSA optimization Pass2ConstantIdentification
Simplifying expression containing zero main::SCREEN in [4] main::SCREEN[0] = main::$0
Successful SSA optimization PassNSimplifyExpressionWithZero
Removing unused procedure __start
Removing unused procedure block __start
Removing unused procedure block __start::@1
Removing unused procedure block __start::@return
Successful SSA optimization PassNEliminateEmptyStart
Inlining constant with var siblings f::a#0
Inlining constant with var siblings f::a#1
Constant inlined f::a#1 = 'b'
Constant inlined f::a#0 = 'a'
Successful SSA optimization Pass2ConstantInlining
Consolidated array index constant in *(main::SCREEN+1)
Successful SSA optimization Pass2ConstantAdditionElimination
Adding NOP phi() at start of main
CALL GRAPH
Calls in [main] to f:1 f:5
Created 1 initial phi equivalence classes
Coalesced down to 1 phi equivalence classes
Adding NOP phi() at start of main
FINAL CONTROL FLOW GRAPH
void main()
main: scope:[main] from
[0] phi()
[1] call f
[2] f::return#0 = f::return#2
to:main::@1
main::@1: scope:[main] from main
[3] main::$0 = f::return#0
[4] *main::SCREEN = main::$0
[5] call f
[6] f::return#1 = f::return#2
to:main::@2
main::@2: scope:[main] from main::@1
[7] main::$1 = f::return#1
[8] *(main::SCREEN+1) = main::$1
to:main::@return
main::@return: scope:[main] from main::@2
[9] return
to:@return
byte f(byte f::a)
f: scope:[f] from main main::@1
[10] f::a#2 = phi( main/'a', main::@1/'b' )
[11] f::return#2 = f::a#2 + 1
to:f::@return
f::@return: scope:[f] from f
[12] return
to:@return
VARIABLE REGISTER WEIGHTS
byte f(byte f::a)
byte f::a
byte f::a#2 11.0
byte f::return
byte f::return#0 4.0
byte f::return#1 4.0
byte f::return#2 3.75
void main()
byte~ main::$0 4.0
byte~ main::$1 4.0
Initial phi equivalence classes
[ f::a#2 ]
Added variable f::return#0 to live range equivalence class [ f::return#0 ]
Added variable main::$0 to live range equivalence class [ main::$0 ]
Added variable f::return#1 to live range equivalence class [ f::return#1 ]
Added variable main::$1 to live range equivalence class [ main::$1 ]
Added variable f::return#2 to live range equivalence class [ f::return#2 ]
Complete equivalence classes
[ f::a#2 ]
[ f::return#0 ]
[ main::$0 ]
[ f::return#1 ]
[ main::$1 ]
[ f::return#2 ]
Allocated zp[1]:2 [ f::a#2 ]
Allocated zp[1]:3 [ f::return#0 ]
Allocated zp[1]:4 [ main::$0 ]
Allocated zp[1]:5 [ f::return#1 ]
Allocated zp[1]:6 [ main::$1 ]
Allocated zp[1]:7 [ f::return#2 ]
REGISTER UPLIFT POTENTIAL REGISTERS
Potential registers zp[1]:2 [ f::a#2 ] : zp[1]:2 , reg byte a , reg byte x , reg byte y ,
Potential registers zp[1]:3 [ f::return#0 ] : zp[1]:3 , reg byte a , reg byte x , reg byte y ,
Potential registers zp[1]:4 [ main::$0 ] : zp[1]:4 , reg byte a , reg byte x , reg byte y ,
Potential registers zp[1]:5 [ f::return#1 ] : zp[1]:5 , reg byte a , reg byte x , reg byte y ,
Potential registers zp[1]:6 [ main::$1 ] : zp[1]:6 , reg byte a , reg byte x , reg byte y ,
Potential registers zp[1]:7 [ f::return#2 ] : zp[1]:7 , reg byte a , reg byte x , reg byte y ,
REGISTER UPLIFT SCOPES
Uplift Scope [f] 11: zp[1]:2 [ f::a#2 ] 4: zp[1]:3 [ f::return#0 ] 4: zp[1]:5 [ f::return#1 ] 3.75: zp[1]:7 [ f::return#2 ]
Uplift Scope [main] 4: zp[1]:4 [ main::$0 ] 4: zp[1]:6 [ main::$1 ]
Uplift Scope []
Uplifting [f] best 64 combination reg byte a [ f::a#2 ] reg byte a [ f::return#0 ] reg byte a [ f::return#1 ] reg byte a [ f::return#2 ]
Limited combination testing to 100 combinations of 256 possible.
Uplifting [main] best 52 combination reg byte a [ main::$0 ] reg byte a [ main::$1 ]
Uplifting [] best 52 combination
ASSEMBLER BEFORE OPTIMIZATION
// File Comments
// Procedure Declaration
// Upstart
// Commodore 64 PRG executable file
.file [name="procedure-declare-0.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
.segment Code
// main
main: {
.label SCREEN = $400
// [1] call f
// [10] phi from main to f [phi:main->f]
f_from_main:
// [10] phi f::a#2 = 'a' [phi:main->f#0] -- vbuaa=vbuc1
lda #'a'
jsr f
// [2] f::return#0 = f::return#2
jmp __b1
// main::@1
__b1:
// [3] main::$0 = f::return#0
// [4] *main::SCREEN = main::$0 -- _deref_pbuc1=vbuaa
sta SCREEN
// [5] call f
// [10] phi from main::@1 to f [phi:main::@1->f]
f_from___b1:
// [10] phi f::a#2 = 'b' [phi:main::@1->f#0] -- vbuaa=vbuc1
lda #'b'
jsr f
// [6] f::return#1 = f::return#2
jmp __b2
// main::@2
__b2:
// [7] main::$1 = f::return#1
// [8] *(main::SCREEN+1) = main::$1 -- _deref_pbuc1=vbuaa
sta SCREEN+1
jmp __breturn
// main::@return
__breturn:
// [9] return
rts
}
// f
// f(byte register(A) a)
f: {
// [11] f::return#2 = f::a#2 + 1 -- vbuaa=vbuaa_plus_1
clc
adc #1
jmp __breturn
// f::@return
__breturn:
// [12] return
rts
}
// File Data
ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __b1
Removing instruction jmp __b2
Removing instruction jmp __breturn
Removing instruction jmp __breturn
Succesful ASM optimization Pass5NextJumpElimination
Removing instruction f_from_main:
Removing instruction __b1:
Removing instruction f_from___b1:
Removing instruction __b2:
Removing instruction __breturn:
Removing instruction __breturn:
Succesful ASM optimization Pass5UnusedLabelElimination
FINAL SYMBOL TABLE
byte f(byte f::a)
byte f::a
byte f::a#2 reg byte a 11.0
byte f::return
byte f::return#0 reg byte a 4.0
byte f::return#1 reg byte a 4.0
byte f::return#2 reg byte a 3.75
void main()
byte~ main::$0 reg byte a 4.0
byte~ main::$1 reg byte a 4.0
constant byte* const main::SCREEN = (byte*) 1024
reg byte a [ f::a#2 ]
reg byte a [ f::return#0 ]
reg byte a [ main::$0 ]
reg byte a [ f::return#1 ]
reg byte a [ main::$1 ]
reg byte a [ f::return#2 ]
FINAL ASSEMBLER
Score: 40
// File Comments
// Procedure Declaration
// Upstart
// Commodore 64 PRG executable file
.file [name="procedure-declare-0.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
.segment Code
// main
main: {
.label SCREEN = $400
// f('a')
// [1] call f
// [10] phi from main to f [phi:main->f]
// [10] phi f::a#2 = 'a' [phi:main->f#0] -- vbuaa=vbuc1
lda #'a'
jsr f
// f('a')
// [2] f::return#0 = f::return#2
// main::@1
// [3] main::$0 = f::return#0
// SCREEN[0] = f('a')
// [4] *main::SCREEN = main::$0 -- _deref_pbuc1=vbuaa
sta SCREEN
// f('b')
// [5] call f
// [10] phi from main::@1 to f [phi:main::@1->f]
// [10] phi f::a#2 = 'b' [phi:main::@1->f#0] -- vbuaa=vbuc1
lda #'b'
jsr f
// f('b')
// [6] f::return#1 = f::return#2
// main::@2
// [7] main::$1 = f::return#1
// SCREEN[1] = f('b')
// [8] *(main::SCREEN+1) = main::$1 -- _deref_pbuc1=vbuaa
sta SCREEN+1
// main::@return
// }
// [9] return
rts
}
// f
// f(byte register(A) a)
f: {
// a+1
// [11] f::return#2 = f::a#2 + 1 -- vbuaa=vbuaa_plus_1
clc
adc #1
// f::@return
// }
// [12] return
rts
}
// File Data

View File

@ -0,0 +1,18 @@
byte f(byte f::a)
byte f::a
byte f::a#2 reg byte a 11.0
byte f::return
byte f::return#0 reg byte a 4.0
byte f::return#1 reg byte a 4.0
byte f::return#2 reg byte a 3.75
void main()
byte~ main::$0 reg byte a 4.0
byte~ main::$1 reg byte a 4.0
constant byte* const main::SCREEN = (byte*) 1024
reg byte a [ f::a#2 ]
reg byte a [ f::return#0 ]
reg byte a [ main::$0 ]
reg byte a [ f::return#1 ]
reg byte a [ main::$1 ]
reg byte a [ f::return#2 ]