mirror of
https://gitlab.com/camelot/kickc.git
synced 2024-12-26 03:32:23 +00:00
Added support for #include <> syntax. Closes #381
This commit is contained in:
parent
8dac19aca0
commit
5ff8fce61d
@ -18,7 +18,8 @@ public class SourceLoader {
|
||||
|
||||
public static File loadFile(String fileName, Path currentPath, Program program) {
|
||||
List<String> searchPaths = new ArrayList<>();
|
||||
searchPaths.add(currentPath.toString());
|
||||
if(currentPath != null)
|
||||
searchPaths.add(currentPath.toString());
|
||||
searchPaths.addAll(program.getImportPaths());
|
||||
for(String importPath : searchPaths) {
|
||||
if(!importPath.endsWith("/")) {
|
||||
|
@ -290,6 +290,8 @@ public class AsmFragmentInstanceSpecFactory {
|
||||
integerValue = ((ConstantInteger) constantLiteral).getValue();
|
||||
} else if(constantLiteral instanceof ConstantPointer) {
|
||||
integerValue = ((ConstantPointer) constantLiteral).getValue();
|
||||
} else if(constantLiteral instanceof ConstantChar) {
|
||||
integerValue = ((ConstantChar) constantLiteral).getInteger();
|
||||
} else {
|
||||
throw new InternalError("Not implemented " + constantLiteral);
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
package dk.camelot64.kickc.parser;
|
||||
|
||||
import dk.camelot64.kickc.SourceLoader;
|
||||
import dk.camelot64.kickc.preprocessor.CPreprocessor;
|
||||
import dk.camelot64.kickc.model.CompileError;
|
||||
import dk.camelot64.kickc.model.Program;
|
||||
import dk.camelot64.kickc.preprocessor.CPreprocessor;
|
||||
import org.antlr.v4.runtime.*;
|
||||
|
||||
import java.io.File;
|
||||
@ -112,6 +112,7 @@ public class CParser {
|
||||
|
||||
/**
|
||||
* Get the C parser
|
||||
*
|
||||
* @return The C parser
|
||||
*/
|
||||
public KickCParser getParser() {
|
||||
@ -152,8 +153,9 @@ public class CParser {
|
||||
*
|
||||
* @param fileName The file name of the file
|
||||
*/
|
||||
public void loadCFile(String fileName) {
|
||||
loadCFile(fileName, getCurrentSourceFolderPath());
|
||||
public void loadCFile(String fileName, boolean isSystem) {
|
||||
final Path currentSourceFolderPath = isSystem ? null : getCurrentSourceFolderPath();
|
||||
loadCFile(fileName, currentSourceFolderPath);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -165,10 +167,10 @@ public class CParser {
|
||||
*/
|
||||
private void loadCFile(String fileName, Path currentPath) {
|
||||
try {
|
||||
if(fileName.startsWith("\"")) {
|
||||
fileName = fileName.substring(1, fileName.length()-1);
|
||||
if(fileName.startsWith("\"") || fileName.startsWith("<")) {
|
||||
fileName = fileName.substring(1, fileName.length() - 1);
|
||||
}
|
||||
if(!fileName.endsWith(".kc")) {
|
||||
if(!fileName.endsWith(".kc") && !fileName.contains(".")) {
|
||||
fileName += ".kc";
|
||||
}
|
||||
File file = SourceLoader.loadFile(fileName, currentPath, program);
|
||||
@ -192,6 +194,7 @@ public class CParser {
|
||||
|
||||
/**
|
||||
* Add source code at the start of the token stream being parsed.
|
||||
*
|
||||
* @param charStream The char stream containing the source code to add
|
||||
* @return The lexer for reading the source tokens of the added source
|
||||
*/
|
||||
|
@ -117,10 +117,6 @@ SIMPLETYPE: 'byte' | 'word' | 'dword' | 'bool' | 'char' | 'short' | 'int' | 'lon
|
||||
BOOLEAN : 'true' | 'false';
|
||||
KICKASM_BODY: '{{' .*? '}}';
|
||||
|
||||
// Strings and chars - with special handling of imports
|
||||
STRING : '"' ('\\"' | ~'"')* '"' [z]?([ps][mu]?)?[z]? { if(importEnter) { importEnter=false; cParser.loadCFile(getText()); } } ;
|
||||
CHAR : '\'' ('\\'['"rfn] | ~'\'' ) '\'';
|
||||
|
||||
// Preprocessor
|
||||
IMPORT: '#import' { importEnter=true; } ;
|
||||
INCLUDE: '#include' { importEnter=true; } ;
|
||||
@ -154,6 +150,11 @@ NAME : NAME_START NAME_CHAR* {if(cParser.isTypedef(getText())) setType(TYPEDEFNA
|
||||
fragment NAME_START : [a-zA-Z_];
|
||||
fragment NAME_CHAR : [a-zA-Z0-9_];
|
||||
|
||||
// Strings and chars - with special handling of imports
|
||||
SYSTEMFILE : '<' [a-zA-Z0-9_./\\]+ '>' { if(importEnter) { importEnter=false; cParser.loadCFile(getText(), true); } } ;
|
||||
STRING : '"' ('\\"' | ~'"')* '"' [z]?([ps][mu]?)?[z]? { if(importEnter) { importEnter=false; cParser.loadCFile(getText(), false); } } ;
|
||||
CHAR : '\'' ('\\'['"rfn] | ~'\'' ) '\'';
|
||||
|
||||
// White space on hidden channel 1
|
||||
WS : [ \t\r\n\u00a0]+ -> channel(1);
|
||||
// Comments on hidden channel 2
|
||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
@ -89,69 +89,70 @@ SIGNEDNESS=88
|
||||
SIMPLETYPE=89
|
||||
BOOLEAN=90
|
||||
KICKASM_BODY=91
|
||||
STRING=92
|
||||
CHAR=93
|
||||
IMPORT=94
|
||||
INCLUDE=95
|
||||
PRAGMA=96
|
||||
DEFINE=97
|
||||
DEFINE_CONTINUE=98
|
||||
UNDEF=99
|
||||
IFDEF=100
|
||||
IFNDEF=101
|
||||
IFIF=102
|
||||
ELIF=103
|
||||
IFELSE=104
|
||||
ENDIF=105
|
||||
NUMBER=106
|
||||
NUMFLOAT=107
|
||||
BINFLOAT=108
|
||||
DECFLOAT=109
|
||||
HEXFLOAT=110
|
||||
NUMINT=111
|
||||
BININTEGER=112
|
||||
DECINTEGER=113
|
||||
HEXINTEGER=114
|
||||
NAME=115
|
||||
WS=116
|
||||
COMMENT_LINE=117
|
||||
COMMENT_BLOCK=118
|
||||
ASM_BYTE=119
|
||||
ASM_MNEMONIC=120
|
||||
ASM_IMM=121
|
||||
ASM_COLON=122
|
||||
ASM_COMMA=123
|
||||
ASM_PAR_BEGIN=124
|
||||
ASM_PAR_END=125
|
||||
ASM_BRACKET_BEGIN=126
|
||||
ASM_BRACKET_END=127
|
||||
ASM_DOT=128
|
||||
ASM_SHIFT_LEFT=129
|
||||
ASM_SHIFT_RIGHT=130
|
||||
ASM_PLUS=131
|
||||
ASM_MINUS=132
|
||||
ASM_LESS_THAN=133
|
||||
ASM_GREATER_THAN=134
|
||||
ASM_MULTIPLY=135
|
||||
ASM_DIVIDE=136
|
||||
ASM_CURLY_BEGIN=137
|
||||
ASM_CURLY_END=138
|
||||
ASM_NUMBER=139
|
||||
ASM_NUMFLOAT=140
|
||||
ASM_BINFLOAT=141
|
||||
ASM_DECFLOAT=142
|
||||
ASM_HEXFLOAT=143
|
||||
ASM_NUMINT=144
|
||||
ASM_BININTEGER=145
|
||||
ASM_DECINTEGER=146
|
||||
ASM_HEXINTEGER=147
|
||||
ASM_CHAR=148
|
||||
ASM_MULTI_REL=149
|
||||
ASM_MULTI_NAME=150
|
||||
ASM_NAME=151
|
||||
ASM_WS=152
|
||||
ASM_COMMENT_LINE=153
|
||||
ASM_COMMENT_BLOCK=154
|
||||
IMPORT=92
|
||||
INCLUDE=93
|
||||
PRAGMA=94
|
||||
DEFINE=95
|
||||
DEFINE_CONTINUE=96
|
||||
UNDEF=97
|
||||
IFDEF=98
|
||||
IFNDEF=99
|
||||
IFIF=100
|
||||
ELIF=101
|
||||
IFELSE=102
|
||||
ENDIF=103
|
||||
NUMBER=104
|
||||
NUMFLOAT=105
|
||||
BINFLOAT=106
|
||||
DECFLOAT=107
|
||||
HEXFLOAT=108
|
||||
NUMINT=109
|
||||
BININTEGER=110
|
||||
DECINTEGER=111
|
||||
HEXINTEGER=112
|
||||
NAME=113
|
||||
SYSTEMFILE=114
|
||||
STRING=115
|
||||
CHAR=116
|
||||
WS=117
|
||||
COMMENT_LINE=118
|
||||
COMMENT_BLOCK=119
|
||||
ASM_BYTE=120
|
||||
ASM_MNEMONIC=121
|
||||
ASM_IMM=122
|
||||
ASM_COLON=123
|
||||
ASM_COMMA=124
|
||||
ASM_PAR_BEGIN=125
|
||||
ASM_PAR_END=126
|
||||
ASM_BRACKET_BEGIN=127
|
||||
ASM_BRACKET_END=128
|
||||
ASM_DOT=129
|
||||
ASM_SHIFT_LEFT=130
|
||||
ASM_SHIFT_RIGHT=131
|
||||
ASM_PLUS=132
|
||||
ASM_MINUS=133
|
||||
ASM_LESS_THAN=134
|
||||
ASM_GREATER_THAN=135
|
||||
ASM_MULTIPLY=136
|
||||
ASM_DIVIDE=137
|
||||
ASM_CURLY_BEGIN=138
|
||||
ASM_CURLY_END=139
|
||||
ASM_NUMBER=140
|
||||
ASM_NUMFLOAT=141
|
||||
ASM_BINFLOAT=142
|
||||
ASM_DECFLOAT=143
|
||||
ASM_HEXFLOAT=144
|
||||
ASM_NUMINT=145
|
||||
ASM_BININTEGER=146
|
||||
ASM_DECINTEGER=147
|
||||
ASM_HEXINTEGER=148
|
||||
ASM_CHAR=149
|
||||
ASM_MULTI_REL=150
|
||||
ASM_MULTI_NAME=151
|
||||
ASM_NAME=152
|
||||
ASM_WS=153
|
||||
ASM_COMMENT_LINE=154
|
||||
ASM_COMMENT_BLOCK=155
|
||||
';'=8
|
||||
'..'=11
|
||||
'?'=12
|
||||
@ -219,16 +220,16 @@ ASM_COMMENT_BLOCK=154
|
||||
'bytes'=85
|
||||
'cycles'=86
|
||||
'!'=87
|
||||
'#import'=94
|
||||
'#include'=95
|
||||
'#pragma'=96
|
||||
'#define'=97
|
||||
'#undef'=99
|
||||
'#ifdef'=100
|
||||
'#ifndef'=101
|
||||
'#if'=102
|
||||
'#elif'=103
|
||||
'#else'=104
|
||||
'#endif'=105
|
||||
'.byte'=119
|
||||
'#'=121
|
||||
'#import'=92
|
||||
'#include'=93
|
||||
'#pragma'=94
|
||||
'#define'=95
|
||||
'#undef'=97
|
||||
'#ifdef'=98
|
||||
'#ifndef'=99
|
||||
'#if'=100
|
||||
'#elif'=101
|
||||
'#else'=102
|
||||
'#endif'=103
|
||||
'.byte'=120
|
||||
'#'=122
|
||||
|
@ -37,6 +37,7 @@ declOrImport
|
||||
importDecl
|
||||
: IMPORT STRING #importFile
|
||||
| INCLUDE STRING #includeFile
|
||||
| INCLUDE SYSTEMFILE #includeSystem
|
||||
;
|
||||
|
||||
decl
|
||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
@ -89,69 +89,70 @@ SIGNEDNESS=88
|
||||
SIMPLETYPE=89
|
||||
BOOLEAN=90
|
||||
KICKASM_BODY=91
|
||||
STRING=92
|
||||
CHAR=93
|
||||
IMPORT=94
|
||||
INCLUDE=95
|
||||
PRAGMA=96
|
||||
DEFINE=97
|
||||
DEFINE_CONTINUE=98
|
||||
UNDEF=99
|
||||
IFDEF=100
|
||||
IFNDEF=101
|
||||
IFIF=102
|
||||
ELIF=103
|
||||
IFELSE=104
|
||||
ENDIF=105
|
||||
NUMBER=106
|
||||
NUMFLOAT=107
|
||||
BINFLOAT=108
|
||||
DECFLOAT=109
|
||||
HEXFLOAT=110
|
||||
NUMINT=111
|
||||
BININTEGER=112
|
||||
DECINTEGER=113
|
||||
HEXINTEGER=114
|
||||
NAME=115
|
||||
WS=116
|
||||
COMMENT_LINE=117
|
||||
COMMENT_BLOCK=118
|
||||
ASM_BYTE=119
|
||||
ASM_MNEMONIC=120
|
||||
ASM_IMM=121
|
||||
ASM_COLON=122
|
||||
ASM_COMMA=123
|
||||
ASM_PAR_BEGIN=124
|
||||
ASM_PAR_END=125
|
||||
ASM_BRACKET_BEGIN=126
|
||||
ASM_BRACKET_END=127
|
||||
ASM_DOT=128
|
||||
ASM_SHIFT_LEFT=129
|
||||
ASM_SHIFT_RIGHT=130
|
||||
ASM_PLUS=131
|
||||
ASM_MINUS=132
|
||||
ASM_LESS_THAN=133
|
||||
ASM_GREATER_THAN=134
|
||||
ASM_MULTIPLY=135
|
||||
ASM_DIVIDE=136
|
||||
ASM_CURLY_BEGIN=137
|
||||
ASM_CURLY_END=138
|
||||
ASM_NUMBER=139
|
||||
ASM_NUMFLOAT=140
|
||||
ASM_BINFLOAT=141
|
||||
ASM_DECFLOAT=142
|
||||
ASM_HEXFLOAT=143
|
||||
ASM_NUMINT=144
|
||||
ASM_BININTEGER=145
|
||||
ASM_DECINTEGER=146
|
||||
ASM_HEXINTEGER=147
|
||||
ASM_CHAR=148
|
||||
ASM_MULTI_REL=149
|
||||
ASM_MULTI_NAME=150
|
||||
ASM_NAME=151
|
||||
ASM_WS=152
|
||||
ASM_COMMENT_LINE=153
|
||||
ASM_COMMENT_BLOCK=154
|
||||
IMPORT=92
|
||||
INCLUDE=93
|
||||
PRAGMA=94
|
||||
DEFINE=95
|
||||
DEFINE_CONTINUE=96
|
||||
UNDEF=97
|
||||
IFDEF=98
|
||||
IFNDEF=99
|
||||
IFIF=100
|
||||
ELIF=101
|
||||
IFELSE=102
|
||||
ENDIF=103
|
||||
NUMBER=104
|
||||
NUMFLOAT=105
|
||||
BINFLOAT=106
|
||||
DECFLOAT=107
|
||||
HEXFLOAT=108
|
||||
NUMINT=109
|
||||
BININTEGER=110
|
||||
DECINTEGER=111
|
||||
HEXINTEGER=112
|
||||
NAME=113
|
||||
SYSTEMFILE=114
|
||||
STRING=115
|
||||
CHAR=116
|
||||
WS=117
|
||||
COMMENT_LINE=118
|
||||
COMMENT_BLOCK=119
|
||||
ASM_BYTE=120
|
||||
ASM_MNEMONIC=121
|
||||
ASM_IMM=122
|
||||
ASM_COLON=123
|
||||
ASM_COMMA=124
|
||||
ASM_PAR_BEGIN=125
|
||||
ASM_PAR_END=126
|
||||
ASM_BRACKET_BEGIN=127
|
||||
ASM_BRACKET_END=128
|
||||
ASM_DOT=129
|
||||
ASM_SHIFT_LEFT=130
|
||||
ASM_SHIFT_RIGHT=131
|
||||
ASM_PLUS=132
|
||||
ASM_MINUS=133
|
||||
ASM_LESS_THAN=134
|
||||
ASM_GREATER_THAN=135
|
||||
ASM_MULTIPLY=136
|
||||
ASM_DIVIDE=137
|
||||
ASM_CURLY_BEGIN=138
|
||||
ASM_CURLY_END=139
|
||||
ASM_NUMBER=140
|
||||
ASM_NUMFLOAT=141
|
||||
ASM_BINFLOAT=142
|
||||
ASM_DECFLOAT=143
|
||||
ASM_HEXFLOAT=144
|
||||
ASM_NUMINT=145
|
||||
ASM_BININTEGER=146
|
||||
ASM_DECINTEGER=147
|
||||
ASM_HEXINTEGER=148
|
||||
ASM_CHAR=149
|
||||
ASM_MULTI_REL=150
|
||||
ASM_MULTI_NAME=151
|
||||
ASM_NAME=152
|
||||
ASM_WS=153
|
||||
ASM_COMMENT_LINE=154
|
||||
ASM_COMMENT_BLOCK=155
|
||||
';'=8
|
||||
'..'=11
|
||||
'?'=12
|
||||
@ -219,16 +220,16 @@ ASM_COMMENT_BLOCK=154
|
||||
'bytes'=85
|
||||
'cycles'=86
|
||||
'!'=87
|
||||
'#import'=94
|
||||
'#include'=95
|
||||
'#pragma'=96
|
||||
'#define'=97
|
||||
'#undef'=99
|
||||
'#ifdef'=100
|
||||
'#ifndef'=101
|
||||
'#if'=102
|
||||
'#elif'=103
|
||||
'#else'=104
|
||||
'#endif'=105
|
||||
'.byte'=119
|
||||
'#'=121
|
||||
'#import'=92
|
||||
'#include'=93
|
||||
'#pragma'=94
|
||||
'#define'=95
|
||||
'#undef'=97
|
||||
'#ifdef'=98
|
||||
'#ifndef'=99
|
||||
'#if'=100
|
||||
'#elif'=101
|
||||
'#else'=102
|
||||
'#endif'=103
|
||||
'.byte'=120
|
||||
'#'=122
|
||||
|
@ -85,6 +85,18 @@ public class KickCParserBaseListener implements KickCParserListener {
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void exitIncludeFile(KickCParser.IncludeFileContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void enterIncludeSystem(KickCParser.IncludeSystemContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void exitIncludeSystem(KickCParser.IncludeSystemContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
|
@ -55,6 +55,13 @@ public class KickCParserBaseVisitor<T> extends AbstractParseTreeVisitor<T> imple
|
||||
* {@link #visitChildren} on {@code ctx}.</p>
|
||||
*/
|
||||
@Override public T visitIncludeFile(KickCParser.IncludeFileContext ctx) { return visitChildren(ctx); }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation returns the result of calling
|
||||
* {@link #visitChildren} on {@code ctx}.</p>
|
||||
*/
|
||||
@Override public T visitIncludeSystem(KickCParser.IncludeSystemContext ctx) { return visitChildren(ctx); }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
|
@ -73,6 +73,18 @@ public interface KickCParserListener extends ParseTreeListener {
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void exitIncludeFile(KickCParser.IncludeFileContext ctx);
|
||||
/**
|
||||
* Enter a parse tree produced by the {@code includeSystem}
|
||||
* labeled alternative in {@link KickCParser#importDecl}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void enterIncludeSystem(KickCParser.IncludeSystemContext ctx);
|
||||
/**
|
||||
* Exit a parse tree produced by the {@code includeSystem}
|
||||
* labeled alternative in {@link KickCParser#importDecl}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void exitIncludeSystem(KickCParser.IncludeSystemContext ctx);
|
||||
/**
|
||||
* Enter a parse tree produced by {@link KickCParser#decl}.
|
||||
* @param ctx the parse tree
|
||||
|
@ -50,6 +50,13 @@ public interface KickCParserVisitor<T> extends ParseTreeVisitor<T> {
|
||||
* @return the visitor result
|
||||
*/
|
||||
T visitIncludeFile(KickCParser.IncludeFileContext ctx);
|
||||
/**
|
||||
* Visit a parse tree produced by the {@code includeSystem}
|
||||
* labeled alternative in {@link KickCParser#importDecl}.
|
||||
* @param ctx the parse tree
|
||||
* @return the visitor result
|
||||
*/
|
||||
T visitIncludeSystem(KickCParser.IncludeSystemContext ctx);
|
||||
/**
|
||||
* Visit a parse tree produced by {@link KickCParser#decl}.
|
||||
* @param ctx the parse tree
|
||||
|
@ -111,6 +111,16 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object visitIncludeSystem(KickCParser.IncludeSystemContext ctx) {
|
||||
String includeName = ctx.SYSTEMFILE().getText();
|
||||
String includeFileName = includeName.substring(1, includeName.length() - 1);
|
||||
if(program.getLog().isVerboseParse()) {
|
||||
program.getLog().append("Including system" + includeFileName);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object visitGlobalDirectiveVarModel(KickCParser.GlobalDirectiveVarModelContext ctx) {
|
||||
List<TerminalNode> settingNodes = new ArrayList<>(ctx.NAME());
|
||||
|
@ -37,6 +37,16 @@ public class TestPrograms {
|
||||
public TestPrograms() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIncludes2() throws IOException, URISyntaxException {
|
||||
compileAndCompare("complex/includes/includes-2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIncludes1() throws IOException, URISyntaxException {
|
||||
compileAndCompare("complex/includes/includes-1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCStyleDeclVarMultiple() throws IOException, URISyntaxException {
|
||||
compileAndCompare("cstyle-decl-var-multiple");
|
||||
|
11
src/test/kc/complex/includes/includes-1.kc
Normal file
11
src/test/kc/complex/includes/includes-1.kc
Normal file
@ -0,0 +1,11 @@
|
||||
// Includes a system library - ignores the local file with the same name
|
||||
|
||||
#include <string>
|
||||
|
||||
char* STR = "camelot!";
|
||||
|
||||
char* const SCREEN = 0x0400;
|
||||
|
||||
void main() {
|
||||
SCREEN [0] = (char) strlen(STR);
|
||||
}
|
11
src/test/kc/complex/includes/includes-2.kc
Normal file
11
src/test/kc/complex/includes/includes-2.kc
Normal file
@ -0,0 +1,11 @@
|
||||
// Includes a local file with the same name as a system library
|
||||
|
||||
#include "string"
|
||||
|
||||
char* STR = "camelot!";
|
||||
|
||||
char* const SCREEN = 0x0400;
|
||||
|
||||
void main() {
|
||||
SCREEN [0] = (char) strlen(STR);
|
||||
}
|
5
src/test/kc/complex/includes/string.kc
Normal file
5
src/test/kc/complex/includes/string.kc
Normal file
@ -0,0 +1,5 @@
|
||||
// A local stdlib include file
|
||||
|
||||
unsigned int strlen(char *str) {
|
||||
return 'x';
|
||||
}
|
53
src/test/ref/complex/includes/includes-1.asm
Normal file
53
src/test/ref/complex/includes/includes-1.asm
Normal file
@ -0,0 +1,53 @@
|
||||
// Includes a system library - ignores the local file with the same name
|
||||
.pc = $801 "Basic"
|
||||
:BasicUpstart(main)
|
||||
.pc = $80d "Program"
|
||||
.label SCREEN = $400
|
||||
main: {
|
||||
.label __0 = 4
|
||||
// strlen(STR)
|
||||
jsr strlen
|
||||
// strlen(STR)
|
||||
// (char) strlen(STR)
|
||||
lda.z __0
|
||||
// SCREEN [0] = (char) strlen(STR)
|
||||
sta SCREEN
|
||||
// }
|
||||
rts
|
||||
}
|
||||
// Computes the length of the string str up to but not including the terminating null character.
|
||||
// strlen(byte* zp(2) str)
|
||||
strlen: {
|
||||
.label len = 4
|
||||
.label str = 2
|
||||
.label return = 4
|
||||
lda #<0
|
||||
sta.z len
|
||||
sta.z len+1
|
||||
lda #<STR
|
||||
sta.z str
|
||||
lda #>STR
|
||||
sta.z str+1
|
||||
__b1:
|
||||
// while(*str)
|
||||
ldy #0
|
||||
lda (str),y
|
||||
cmp #0
|
||||
bne __b2
|
||||
// }
|
||||
rts
|
||||
__b2:
|
||||
// len++;
|
||||
inc.z len
|
||||
bne !+
|
||||
inc.z len+1
|
||||
!:
|
||||
// str++;
|
||||
inc.z str
|
||||
bne !+
|
||||
inc.z str+1
|
||||
!:
|
||||
jmp __b1
|
||||
}
|
||||
STR: .text "camelot!"
|
||||
.byte 0
|
41
src/test/ref/complex/includes/includes-1.cfg
Normal file
41
src/test/ref/complex/includes/includes-1.cfg
Normal file
@ -0,0 +1,41 @@
|
||||
@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] phi()
|
||||
[5] call strlen
|
||||
[6] (word) strlen::return#2 ← (word) strlen::len#2
|
||||
to:main::@1
|
||||
main::@1: scope:[main] from main
|
||||
[7] (word~) main::$0 ← (word) strlen::return#2
|
||||
[8] (byte~) main::$1 ← (byte)(word~) main::$0
|
||||
[9] *((const nomodify byte*) SCREEN) ← (byte~) main::$1
|
||||
to:main::@return
|
||||
main::@return: scope:[main] from main::@1
|
||||
[10] return
|
||||
to:@return
|
||||
|
||||
(word()) strlen((byte*) strlen::str)
|
||||
strlen: scope:[strlen] from main
|
||||
[11] phi()
|
||||
to:strlen::@1
|
||||
strlen::@1: scope:[strlen] from strlen strlen::@2
|
||||
[12] (word) strlen::len#2 ← phi( strlen/(word) 0 strlen::@2/(word) strlen::len#1 )
|
||||
[12] (byte*) strlen::str#2 ← phi( strlen/(const byte*) STR strlen::@2/(byte*) strlen::str#0 )
|
||||
[13] if((byte) 0!=*((byte*) strlen::str#2)) goto strlen::@2
|
||||
to:strlen::@return
|
||||
strlen::@return: scope:[strlen] from strlen::@1
|
||||
[14] return
|
||||
to:@return
|
||||
strlen::@2: scope:[strlen] from strlen::@1
|
||||
[15] (word) strlen::len#1 ← ++ (word) strlen::len#2
|
||||
[16] (byte*) strlen::str#0 ← ++ (byte*) strlen::str#2
|
||||
to:strlen::@1
|
619
src/test/ref/complex/includes/includes-1.log
Normal file
619
src/test/ref/complex/includes/includes-1.log
Normal file
@ -0,0 +1,619 @@
|
||||
Warning! Adding boolean cast to non-boolean condition *((byte*) strcpy::src)
|
||||
Warning! Adding boolean cast to non-boolean condition *((byte*) strlen::str)
|
||||
Identified constant variable (byte*) STR
|
||||
Culled Empty Block (label) @1
|
||||
Culled Empty Block (label) @2
|
||||
Culled Empty Block (label) @3
|
||||
Culled Empty Block (label) @4
|
||||
Culled Empty Block (label) strlen::@4
|
||||
Culled Empty Block (label) strlen::@5
|
||||
Culled Empty Block (label) strlen::@6
|
||||
Culled Empty Block (label) strlen::@7
|
||||
Culled Empty Block (label) @5
|
||||
|
||||
CONTROL FLOW GRAPH SSA
|
||||
@begin: scope:[] from
|
||||
to:@6
|
||||
|
||||
(word()) strlen((byte*) strlen::str)
|
||||
strlen: scope:[strlen] from main
|
||||
(byte*) strlen::str#4 ← phi( main/(byte*) strlen::str#1 )
|
||||
(word) strlen::len#0 ← (word) 0
|
||||
to:strlen::@1
|
||||
strlen::@1: scope:[strlen] from strlen strlen::@2
|
||||
(word) strlen::len#4 ← phi( strlen/(word) strlen::len#0 strlen::@2/(word) strlen::len#1 )
|
||||
(byte*) strlen::str#2 ← phi( strlen/(byte*) strlen::str#4 strlen::@2/(byte*) strlen::str#0 )
|
||||
(bool~) strlen::$0 ← (number) 0 != *((byte*) strlen::str#2)
|
||||
if((bool~) strlen::$0) goto strlen::@2
|
||||
to:strlen::@3
|
||||
strlen::@2: scope:[strlen] from strlen::@1
|
||||
(byte*) strlen::str#3 ← phi( strlen::@1/(byte*) strlen::str#2 )
|
||||
(word) strlen::len#2 ← phi( strlen::@1/(word) strlen::len#4 )
|
||||
(word) strlen::len#1 ← ++ (word) strlen::len#2
|
||||
(byte*) strlen::str#0 ← ++ (byte*) strlen::str#3
|
||||
to:strlen::@1
|
||||
strlen::@3: scope:[strlen] from strlen::@1
|
||||
(word) strlen::len#3 ← phi( strlen::@1/(word) strlen::len#4 )
|
||||
(word) strlen::return#0 ← (word) strlen::len#3
|
||||
to:strlen::@return
|
||||
strlen::@return: scope:[strlen] from strlen::@3
|
||||
(word) strlen::return#3 ← phi( strlen::@3/(word) strlen::return#0 )
|
||||
(word) strlen::return#1 ← (word) strlen::return#3
|
||||
return
|
||||
to:@return
|
||||
|
||||
(void()) main()
|
||||
main: scope:[main] from @6
|
||||
(byte*) strlen::str#1 ← (const byte*) STR
|
||||
call strlen
|
||||
(word) strlen::return#2 ← (word) strlen::return#1
|
||||
to:main::@1
|
||||
main::@1: scope:[main] from main
|
||||
(word) strlen::return#4 ← phi( main/(word) strlen::return#2 )
|
||||
(word~) main::$0 ← (word) strlen::return#4
|
||||
(byte~) main::$1 ← ((byte)) (word~) main::$0
|
||||
*((const nomodify byte*) SCREEN + (number) 0) ← (byte~) main::$1
|
||||
to:main::@return
|
||||
main::@return: scope:[main] from main::@1
|
||||
return
|
||||
to:@return
|
||||
@6: scope:[] from @begin
|
||||
call main
|
||||
to:@7
|
||||
@7: scope:[] from @6
|
||||
to:@end
|
||||
@end: scope:[] from @7
|
||||
|
||||
SYMBOL TABLE SSA
|
||||
(label) @6
|
||||
(label) @7
|
||||
(label) @begin
|
||||
(label) @end
|
||||
(const nomodify byte*) SCREEN = (byte*)(number) $400
|
||||
(const byte*) STR = (byte*) "camelot!"
|
||||
(void()) main()
|
||||
(word~) main::$0
|
||||
(byte~) main::$1
|
||||
(label) main::@1
|
||||
(label) main::@return
|
||||
(word()) strlen((byte*) strlen::str)
|
||||
(bool~) strlen::$0
|
||||
(label) strlen::@1
|
||||
(label) strlen::@2
|
||||
(label) strlen::@3
|
||||
(label) strlen::@return
|
||||
(word) strlen::len
|
||||
(word) strlen::len#0
|
||||
(word) strlen::len#1
|
||||
(word) strlen::len#2
|
||||
(word) strlen::len#3
|
||||
(word) strlen::len#4
|
||||
(word) strlen::return
|
||||
(word) strlen::return#0
|
||||
(word) strlen::return#1
|
||||
(word) strlen::return#2
|
||||
(word) strlen::return#3
|
||||
(word) strlen::return#4
|
||||
(byte*) strlen::str
|
||||
(byte*) strlen::str#0
|
||||
(byte*) strlen::str#1
|
||||
(byte*) strlen::str#2
|
||||
(byte*) strlen::str#3
|
||||
(byte*) strlen::str#4
|
||||
|
||||
Adding number conversion cast (unumber) 0 in (bool~) strlen::$0 ← (number) 0 != *((byte*) strlen::str#2)
|
||||
Adding number conversion cast (unumber) 0 in *((const nomodify byte*) SCREEN + (number) 0) ← (byte~) main::$1
|
||||
Successful SSA optimization PassNAddNumberTypeConversions
|
||||
Inlining cast (byte~) main::$1 ← (byte)(word~) main::$0
|
||||
Successful SSA optimization Pass2InlineCast
|
||||
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
|
||||
Alias strlen::len#2 = strlen::len#4 strlen::len#3 strlen::return#0 strlen::return#3 strlen::return#1
|
||||
Alias strlen::str#2 = strlen::str#3
|
||||
Alias strlen::return#2 = strlen::return#4
|
||||
Successful SSA optimization Pass2AliasElimination
|
||||
Identical Phi Values (byte*) strlen::str#4 (byte*) strlen::str#1
|
||||
Successful SSA optimization Pass2IdenticalPhiElimination
|
||||
Simple Condition (bool~) strlen::$0 [4] if((byte) 0!=*((byte*) strlen::str#2)) goto strlen::@2
|
||||
Successful SSA optimization Pass2ConditionalJumpSimplification
|
||||
Constant (const word) strlen::len#0 = 0
|
||||
Constant (const byte*) strlen::str#1 = STR
|
||||
Successful SSA optimization Pass2ConstantIdentification
|
||||
Simplifying expression containing zero SCREEN in [13] *((const nomodify byte*) SCREEN + (byte) 0) ← (byte~) main::$1
|
||||
Successful SSA optimization PassNSimplifyExpressionWithZero
|
||||
Inlining constant with var siblings (const word) strlen::len#0
|
||||
Inlining constant with var siblings (const byte*) strlen::str#1
|
||||
Constant inlined strlen::len#0 = (word) 0
|
||||
Constant inlined strlen::str#1 = (const byte*) STR
|
||||
Successful SSA optimization Pass2ConstantInlining
|
||||
Adding NOP phi() at start of @begin
|
||||
Adding NOP phi() at start of @6
|
||||
Adding NOP phi() at start of @7
|
||||
Adding NOP phi() at start of @end
|
||||
Adding NOP phi() at start of main
|
||||
Adding NOP phi() at start of strlen
|
||||
Adding NOP phi() at start of strlen::@3
|
||||
CALL GRAPH
|
||||
Calls in [] to main:2
|
||||
Calls in [main] to strlen:6
|
||||
|
||||
Created 2 initial phi equivalence classes
|
||||
Coalesced [19] strlen::str#5 ← strlen::str#0
|
||||
Coalesced [20] strlen::len#5 ← strlen::len#1
|
||||
Coalesced down to 2 phi equivalence classes
|
||||
Culled Empty Block (label) @7
|
||||
Culled Empty Block (label) strlen::@3
|
||||
Renumbering block @6 to @1
|
||||
Adding NOP phi() at start of @begin
|
||||
Adding NOP phi() at start of @1
|
||||
Adding NOP phi() at start of @end
|
||||
Adding NOP phi() at start of main
|
||||
Adding NOP phi() at start of strlen
|
||||
|
||||
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] phi()
|
||||
[5] call strlen
|
||||
[6] (word) strlen::return#2 ← (word) strlen::len#2
|
||||
to:main::@1
|
||||
main::@1: scope:[main] from main
|
||||
[7] (word~) main::$0 ← (word) strlen::return#2
|
||||
[8] (byte~) main::$1 ← (byte)(word~) main::$0
|
||||
[9] *((const nomodify byte*) SCREEN) ← (byte~) main::$1
|
||||
to:main::@return
|
||||
main::@return: scope:[main] from main::@1
|
||||
[10] return
|
||||
to:@return
|
||||
|
||||
(word()) strlen((byte*) strlen::str)
|
||||
strlen: scope:[strlen] from main
|
||||
[11] phi()
|
||||
to:strlen::@1
|
||||
strlen::@1: scope:[strlen] from strlen strlen::@2
|
||||
[12] (word) strlen::len#2 ← phi( strlen/(word) 0 strlen::@2/(word) strlen::len#1 )
|
||||
[12] (byte*) strlen::str#2 ← phi( strlen/(const byte*) STR strlen::@2/(byte*) strlen::str#0 )
|
||||
[13] if((byte) 0!=*((byte*) strlen::str#2)) goto strlen::@2
|
||||
to:strlen::@return
|
||||
strlen::@return: scope:[strlen] from strlen::@1
|
||||
[14] return
|
||||
to:@return
|
||||
strlen::@2: scope:[strlen] from strlen::@1
|
||||
[15] (word) strlen::len#1 ← ++ (word) strlen::len#2
|
||||
[16] (byte*) strlen::str#0 ← ++ (byte*) strlen::str#2
|
||||
to:strlen::@1
|
||||
|
||||
|
||||
VARIABLE REGISTER WEIGHTS
|
||||
(void()) main()
|
||||
(word~) main::$0 11.0
|
||||
(byte~) main::$1 22.0
|
||||
(word()) strlen((byte*) strlen::str)
|
||||
(word) strlen::len
|
||||
(word) strlen::len#1 1001.0
|
||||
(word) strlen::len#2 503.25
|
||||
(word) strlen::return
|
||||
(word) strlen::return#2 22.0
|
||||
(byte*) strlen::str
|
||||
(byte*) strlen::str#0 2002.0
|
||||
(byte*) strlen::str#2 1001.0
|
||||
|
||||
Initial phi equivalence classes
|
||||
[ strlen::str#2 strlen::str#0 ]
|
||||
[ strlen::len#2 strlen::len#1 ]
|
||||
Added variable strlen::return#2 to live range equivalence class [ strlen::return#2 ]
|
||||
Added variable main::$0 to live range equivalence class [ main::$0 ]
|
||||
Added variable main::$1 to live range equivalence class [ main::$1 ]
|
||||
Complete equivalence classes
|
||||
[ strlen::str#2 strlen::str#0 ]
|
||||
[ strlen::len#2 strlen::len#1 ]
|
||||
[ strlen::return#2 ]
|
||||
[ main::$0 ]
|
||||
[ main::$1 ]
|
||||
Allocated zp[2]:2 [ strlen::str#2 strlen::str#0 ]
|
||||
Allocated zp[2]:4 [ strlen::len#2 strlen::len#1 ]
|
||||
Allocated zp[2]:6 [ strlen::return#2 ]
|
||||
Allocated zp[2]:8 [ main::$0 ]
|
||||
Allocated zp[1]:10 [ main::$1 ]
|
||||
|
||||
INITIAL ASM
|
||||
Target platform is c64basic / MOS6502X
|
||||
// File Comments
|
||||
// Includes a system library - ignores the local file with the same name
|
||||
// Upstart
|
||||
.pc = $801 "Basic"
|
||||
:BasicUpstart(__bbegin)
|
||||
.pc = $80d "Program"
|
||||
// Global Constants & labels
|
||||
.label SCREEN = $400
|
||||
// @begin
|
||||
__bbegin:
|
||||
// [1] phi from @begin to @1 [phi:@begin->@1]
|
||||
__b1_from___bbegin:
|
||||
jmp __b1
|
||||
// @1
|
||||
__b1:
|
||||
// [2] call main
|
||||
// [4] phi from @1 to main [phi:@1->main]
|
||||
main_from___b1:
|
||||
jsr main
|
||||
// [3] phi from @1 to @end [phi:@1->@end]
|
||||
__bend_from___b1:
|
||||
jmp __bend
|
||||
// @end
|
||||
__bend:
|
||||
// main
|
||||
main: {
|
||||
.label __0 = 8
|
||||
.label __1 = $a
|
||||
// [5] call strlen
|
||||
// [11] phi from main to strlen [phi:main->strlen]
|
||||
strlen_from_main:
|
||||
jsr strlen
|
||||
// [6] (word) strlen::return#2 ← (word) strlen::len#2 -- vwuz1=vwuz2
|
||||
lda.z strlen.len
|
||||
sta.z strlen.return
|
||||
lda.z strlen.len+1
|
||||
sta.z strlen.return+1
|
||||
jmp __b1
|
||||
// main::@1
|
||||
__b1:
|
||||
// [7] (word~) main::$0 ← (word) strlen::return#2 -- vwuz1=vwuz2
|
||||
lda.z strlen.return
|
||||
sta.z __0
|
||||
lda.z strlen.return+1
|
||||
sta.z __0+1
|
||||
// [8] (byte~) main::$1 ← (byte)(word~) main::$0 -- vbuz1=_byte_vwuz2
|
||||
lda.z __0
|
||||
sta.z __1
|
||||
// [9] *((const nomodify byte*) SCREEN) ← (byte~) main::$1 -- _deref_pbuc1=vbuz1
|
||||
lda.z __1
|
||||
sta SCREEN
|
||||
jmp __breturn
|
||||
// main::@return
|
||||
__breturn:
|
||||
// [10] return
|
||||
rts
|
||||
}
|
||||
// strlen
|
||||
// Computes the length of the string str up to but not including the terminating null character.
|
||||
// strlen(byte* zp(2) str)
|
||||
strlen: {
|
||||
.label len = 4
|
||||
.label str = 2
|
||||
.label return = 6
|
||||
// [12] phi from strlen to strlen::@1 [phi:strlen->strlen::@1]
|
||||
__b1_from_strlen:
|
||||
// [12] phi (word) strlen::len#2 = (word) 0 [phi:strlen->strlen::@1#0] -- vwuz1=vwuc1
|
||||
lda #<0
|
||||
sta.z len
|
||||
lda #>0
|
||||
sta.z len+1
|
||||
// [12] phi (byte*) strlen::str#2 = (const byte*) STR [phi:strlen->strlen::@1#1] -- pbuz1=pbuc1
|
||||
lda #<STR
|
||||
sta.z str
|
||||
lda #>STR
|
||||
sta.z str+1
|
||||
jmp __b1
|
||||
// strlen::@1
|
||||
__b1:
|
||||
// [13] if((byte) 0!=*((byte*) strlen::str#2)) goto strlen::@2 -- vbuc1_neq__deref_pbuz1_then_la1
|
||||
ldy #0
|
||||
lda (str),y
|
||||
cmp #0
|
||||
bne __b2
|
||||
jmp __breturn
|
||||
// strlen::@return
|
||||
__breturn:
|
||||
// [14] return
|
||||
rts
|
||||
// strlen::@2
|
||||
__b2:
|
||||
// [15] (word) strlen::len#1 ← ++ (word) strlen::len#2 -- vwuz1=_inc_vwuz1
|
||||
inc.z len
|
||||
bne !+
|
||||
inc.z len+1
|
||||
!:
|
||||
// [16] (byte*) strlen::str#0 ← ++ (byte*) strlen::str#2 -- pbuz1=_inc_pbuz1
|
||||
inc.z str
|
||||
bne !+
|
||||
inc.z str+1
|
||||
!:
|
||||
// [12] phi from strlen::@2 to strlen::@1 [phi:strlen::@2->strlen::@1]
|
||||
__b1_from___b2:
|
||||
// [12] phi (word) strlen::len#2 = (word) strlen::len#1 [phi:strlen::@2->strlen::@1#0] -- register_copy
|
||||
// [12] phi (byte*) strlen::str#2 = (byte*) strlen::str#0 [phi:strlen::@2->strlen::@1#1] -- register_copy
|
||||
jmp __b1
|
||||
}
|
||||
// File Data
|
||||
STR: .text "camelot!"
|
||||
.byte 0
|
||||
|
||||
REGISTER UPLIFT POTENTIAL REGISTERS
|
||||
Statement [6] (word) strlen::return#2 ← (word) strlen::len#2 [ strlen::return#2 ] ( main:2 [ strlen::return#2 ] { { strlen::return#2 = strlen::len#2 } } ) always clobbers reg byte a
|
||||
Statement [7] (word~) main::$0 ← (word) strlen::return#2 [ main::$0 ] ( main:2 [ main::$0 ] { } ) always clobbers reg byte a
|
||||
Statement [8] (byte~) main::$1 ← (byte)(word~) main::$0 [ main::$1 ] ( main:2 [ main::$1 ] { } ) always clobbers reg byte a
|
||||
Statement [13] if((byte) 0!=*((byte*) strlen::str#2)) goto strlen::@2 [ strlen::len#2 strlen::str#2 ] ( main:2::strlen:5 [ strlen::len#2 strlen::str#2 ] { { strlen::return#2 = strlen::len#2 } } ) always clobbers reg byte a reg byte y
|
||||
Potential registers zp[2]:2 [ strlen::str#2 strlen::str#0 ] : zp[2]:2 ,
|
||||
Potential registers zp[2]:4 [ strlen::len#2 strlen::len#1 ] : zp[2]:4 ,
|
||||
Potential registers zp[2]:6 [ strlen::return#2 ] : zp[2]:6 ,
|
||||
Potential registers zp[2]:8 [ main::$0 ] : zp[2]:8 ,
|
||||
Potential registers zp[1]:10 [ main::$1 ] : zp[1]:10 , reg byte a , reg byte x , reg byte y ,
|
||||
|
||||
REGISTER UPLIFT SCOPES
|
||||
Uplift Scope [strlen] 3,003: zp[2]:2 [ strlen::str#2 strlen::str#0 ] 1,504.25: zp[2]:4 [ strlen::len#2 strlen::len#1 ] 22: zp[2]:6 [ strlen::return#2 ]
|
||||
Uplift Scope [main] 22: zp[1]:10 [ main::$1 ] 11: zp[2]:8 [ main::$0 ]
|
||||
Uplift Scope []
|
||||
|
||||
Uplifting [strlen] best 733 combination zp[2]:2 [ strlen::str#2 strlen::str#0 ] zp[2]:4 [ strlen::len#2 strlen::len#1 ] zp[2]:6 [ strlen::return#2 ]
|
||||
Uplifting [main] best 727 combination reg byte a [ main::$1 ] zp[2]:8 [ main::$0 ]
|
||||
Uplifting [] best 727 combination
|
||||
Coalescing zero page register [ zp[2]:4 [ strlen::len#2 strlen::len#1 ] ] with [ zp[2]:6 [ strlen::return#2 ] ] - score: 1
|
||||
Coalescing zero page register [ zp[2]:4 [ strlen::len#2 strlen::len#1 strlen::return#2 ] ] with [ zp[2]:8 [ main::$0 ] ] - score: 1
|
||||
|
||||
ASSEMBLER BEFORE OPTIMIZATION
|
||||
// File Comments
|
||||
// Includes a system library - ignores the local file with the same name
|
||||
// Upstart
|
||||
.pc = $801 "Basic"
|
||||
:BasicUpstart(__bbegin)
|
||||
.pc = $80d "Program"
|
||||
// Global Constants & labels
|
||||
.label SCREEN = $400
|
||||
// @begin
|
||||
__bbegin:
|
||||
// [1] phi from @begin to @1 [phi:@begin->@1]
|
||||
__b1_from___bbegin:
|
||||
jmp __b1
|
||||
// @1
|
||||
__b1:
|
||||
// [2] call main
|
||||
// [4] phi from @1 to main [phi:@1->main]
|
||||
main_from___b1:
|
||||
jsr main
|
||||
// [3] phi from @1 to @end [phi:@1->@end]
|
||||
__bend_from___b1:
|
||||
jmp __bend
|
||||
// @end
|
||||
__bend:
|
||||
// main
|
||||
main: {
|
||||
.label __0 = 4
|
||||
// [5] call strlen
|
||||
// [11] phi from main to strlen [phi:main->strlen]
|
||||
strlen_from_main:
|
||||
jsr strlen
|
||||
// [6] (word) strlen::return#2 ← (word) strlen::len#2
|
||||
jmp __b1
|
||||
// main::@1
|
||||
__b1:
|
||||
// [7] (word~) main::$0 ← (word) strlen::return#2
|
||||
// [8] (byte~) main::$1 ← (byte)(word~) main::$0 -- vbuaa=_byte_vwuz1
|
||||
lda.z __0
|
||||
// [9] *((const nomodify byte*) SCREEN) ← (byte~) main::$1 -- _deref_pbuc1=vbuaa
|
||||
sta SCREEN
|
||||
jmp __breturn
|
||||
// main::@return
|
||||
__breturn:
|
||||
// [10] return
|
||||
rts
|
||||
}
|
||||
// strlen
|
||||
// Computes the length of the string str up to but not including the terminating null character.
|
||||
// strlen(byte* zp(2) str)
|
||||
strlen: {
|
||||
.label len = 4
|
||||
.label str = 2
|
||||
.label return = 4
|
||||
// [12] phi from strlen to strlen::@1 [phi:strlen->strlen::@1]
|
||||
__b1_from_strlen:
|
||||
// [12] phi (word) strlen::len#2 = (word) 0 [phi:strlen->strlen::@1#0] -- vwuz1=vwuc1
|
||||
lda #<0
|
||||
sta.z len
|
||||
lda #>0
|
||||
sta.z len+1
|
||||
// [12] phi (byte*) strlen::str#2 = (const byte*) STR [phi:strlen->strlen::@1#1] -- pbuz1=pbuc1
|
||||
lda #<STR
|
||||
sta.z str
|
||||
lda #>STR
|
||||
sta.z str+1
|
||||
jmp __b1
|
||||
// strlen::@1
|
||||
__b1:
|
||||
// [13] if((byte) 0!=*((byte*) strlen::str#2)) goto strlen::@2 -- vbuc1_neq__deref_pbuz1_then_la1
|
||||
ldy #0
|
||||
lda (str),y
|
||||
cmp #0
|
||||
bne __b2
|
||||
jmp __breturn
|
||||
// strlen::@return
|
||||
__breturn:
|
||||
// [14] return
|
||||
rts
|
||||
// strlen::@2
|
||||
__b2:
|
||||
// [15] (word) strlen::len#1 ← ++ (word) strlen::len#2 -- vwuz1=_inc_vwuz1
|
||||
inc.z len
|
||||
bne !+
|
||||
inc.z len+1
|
||||
!:
|
||||
// [16] (byte*) strlen::str#0 ← ++ (byte*) strlen::str#2 -- pbuz1=_inc_pbuz1
|
||||
inc.z str
|
||||
bne !+
|
||||
inc.z str+1
|
||||
!:
|
||||
// [12] phi from strlen::@2 to strlen::@1 [phi:strlen::@2->strlen::@1]
|
||||
__b1_from___b2:
|
||||
// [12] phi (word) strlen::len#2 = (word) strlen::len#1 [phi:strlen::@2->strlen::@1#0] -- register_copy
|
||||
// [12] phi (byte*) strlen::str#2 = (byte*) strlen::str#0 [phi:strlen::@2->strlen::@1#1] -- register_copy
|
||||
jmp __b1
|
||||
}
|
||||
// File Data
|
||||
STR: .text "camelot!"
|
||||
.byte 0
|
||||
|
||||
ASSEMBLER OPTIMIZATIONS
|
||||
Removing instruction jmp __b1
|
||||
Removing instruction jmp __bend
|
||||
Removing instruction jmp __b1
|
||||
Removing instruction jmp __breturn
|
||||
Removing instruction jmp __b1
|
||||
Removing instruction jmp __breturn
|
||||
Succesful ASM optimization Pass5NextJumpElimination
|
||||
Removing instruction lda #>0
|
||||
Succesful ASM optimization Pass5UnnecesaryLoadElimination
|
||||
Removing instruction __b1_from___bbegin:
|
||||
Removing instruction __b1:
|
||||
Removing instruction main_from___b1:
|
||||
Removing instruction __bend_from___b1:
|
||||
Succesful ASM optimization Pass5RedundantLabelElimination
|
||||
Removing instruction __bend:
|
||||
Removing instruction strlen_from_main:
|
||||
Removing instruction __b1:
|
||||
Removing instruction __breturn:
|
||||
Removing instruction __b1_from_strlen:
|
||||
Removing instruction __breturn:
|
||||
Removing instruction __b1_from___b2:
|
||||
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 byte*) STR = (byte*) "camelot!"
|
||||
(void()) main()
|
||||
(word~) main::$0 zp[2]:4 11.0
|
||||
(byte~) main::$1 reg byte a 22.0
|
||||
(label) main::@1
|
||||
(label) main::@return
|
||||
(word()) strlen((byte*) strlen::str)
|
||||
(label) strlen::@1
|
||||
(label) strlen::@2
|
||||
(label) strlen::@return
|
||||
(word) strlen::len
|
||||
(word) strlen::len#1 len zp[2]:4 1001.0
|
||||
(word) strlen::len#2 len zp[2]:4 503.25
|
||||
(word) strlen::return
|
||||
(word) strlen::return#2 return zp[2]:4 22.0
|
||||
(byte*) strlen::str
|
||||
(byte*) strlen::str#0 str zp[2]:2 2002.0
|
||||
(byte*) strlen::str#2 str zp[2]:2 1001.0
|
||||
|
||||
zp[2]:2 [ strlen::str#2 strlen::str#0 ]
|
||||
zp[2]:4 [ strlen::len#2 strlen::len#1 strlen::return#2 main::$0 ]
|
||||
reg byte a [ main::$1 ]
|
||||
|
||||
|
||||
FINAL ASSEMBLER
|
||||
Score: 605
|
||||
|
||||
// File Comments
|
||||
// Includes a system library - ignores the local file with the same name
|
||||
// Upstart
|
||||
.pc = $801 "Basic"
|
||||
:BasicUpstart(main)
|
||||
.pc = $80d "Program"
|
||||
// Global Constants & labels
|
||||
.label SCREEN = $400
|
||||
// @begin
|
||||
// [1] phi from @begin to @1 [phi:@begin->@1]
|
||||
// @1
|
||||
// [2] call main
|
||||
// [4] phi from @1 to main [phi:@1->main]
|
||||
// [3] phi from @1 to @end [phi:@1->@end]
|
||||
// @end
|
||||
// main
|
||||
main: {
|
||||
.label __0 = 4
|
||||
// strlen(STR)
|
||||
// [5] call strlen
|
||||
// [11] phi from main to strlen [phi:main->strlen]
|
||||
jsr strlen
|
||||
// strlen(STR)
|
||||
// [6] (word) strlen::return#2 ← (word) strlen::len#2
|
||||
// main::@1
|
||||
// [7] (word~) main::$0 ← (word) strlen::return#2
|
||||
// (char) strlen(STR)
|
||||
// [8] (byte~) main::$1 ← (byte)(word~) main::$0 -- vbuaa=_byte_vwuz1
|
||||
lda.z __0
|
||||
// SCREEN [0] = (char) strlen(STR)
|
||||
// [9] *((const nomodify byte*) SCREEN) ← (byte~) main::$1 -- _deref_pbuc1=vbuaa
|
||||
sta SCREEN
|
||||
// main::@return
|
||||
// }
|
||||
// [10] return
|
||||
rts
|
||||
}
|
||||
// strlen
|
||||
// Computes the length of the string str up to but not including the terminating null character.
|
||||
// strlen(byte* zp(2) str)
|
||||
strlen: {
|
||||
.label len = 4
|
||||
.label str = 2
|
||||
.label return = 4
|
||||
// [12] phi from strlen to strlen::@1 [phi:strlen->strlen::@1]
|
||||
// [12] phi (word) strlen::len#2 = (word) 0 [phi:strlen->strlen::@1#0] -- vwuz1=vwuc1
|
||||
lda #<0
|
||||
sta.z len
|
||||
sta.z len+1
|
||||
// [12] phi (byte*) strlen::str#2 = (const byte*) STR [phi:strlen->strlen::@1#1] -- pbuz1=pbuc1
|
||||
lda #<STR
|
||||
sta.z str
|
||||
lda #>STR
|
||||
sta.z str+1
|
||||
// strlen::@1
|
||||
__b1:
|
||||
// while(*str)
|
||||
// [13] if((byte) 0!=*((byte*) strlen::str#2)) goto strlen::@2 -- vbuc1_neq__deref_pbuz1_then_la1
|
||||
ldy #0
|
||||
lda (str),y
|
||||
cmp #0
|
||||
bne __b2
|
||||
// strlen::@return
|
||||
// }
|
||||
// [14] return
|
||||
rts
|
||||
// strlen::@2
|
||||
__b2:
|
||||
// len++;
|
||||
// [15] (word) strlen::len#1 ← ++ (word) strlen::len#2 -- vwuz1=_inc_vwuz1
|
||||
inc.z len
|
||||
bne !+
|
||||
inc.z len+1
|
||||
!:
|
||||
// str++;
|
||||
// [16] (byte*) strlen::str#0 ← ++ (byte*) strlen::str#2 -- pbuz1=_inc_pbuz1
|
||||
inc.z str
|
||||
bne !+
|
||||
inc.z str+1
|
||||
!:
|
||||
// [12] phi from strlen::@2 to strlen::@1 [phi:strlen::@2->strlen::@1]
|
||||
// [12] phi (word) strlen::len#2 = (word) strlen::len#1 [phi:strlen::@2->strlen::@1#0] -- register_copy
|
||||
// [12] phi (byte*) strlen::str#2 = (byte*) strlen::str#0 [phi:strlen::@2->strlen::@1#1] -- register_copy
|
||||
jmp __b1
|
||||
}
|
||||
// File Data
|
||||
STR: .text "camelot!"
|
||||
.byte 0
|
||||
|
26
src/test/ref/complex/includes/includes-1.sym
Normal file
26
src/test/ref/complex/includes/includes-1.sym
Normal file
@ -0,0 +1,26 @@
|
||||
(label) @1
|
||||
(label) @begin
|
||||
(label) @end
|
||||
(const nomodify byte*) SCREEN = (byte*) 1024
|
||||
(const byte*) STR = (byte*) "camelot!"
|
||||
(void()) main()
|
||||
(word~) main::$0 zp[2]:4 11.0
|
||||
(byte~) main::$1 reg byte a 22.0
|
||||
(label) main::@1
|
||||
(label) main::@return
|
||||
(word()) strlen((byte*) strlen::str)
|
||||
(label) strlen::@1
|
||||
(label) strlen::@2
|
||||
(label) strlen::@return
|
||||
(word) strlen::len
|
||||
(word) strlen::len#1 len zp[2]:4 1001.0
|
||||
(word) strlen::len#2 len zp[2]:4 503.25
|
||||
(word) strlen::return
|
||||
(word) strlen::return#2 return zp[2]:4 22.0
|
||||
(byte*) strlen::str
|
||||
(byte*) strlen::str#0 str zp[2]:2 2002.0
|
||||
(byte*) strlen::str#2 str zp[2]:2 1001.0
|
||||
|
||||
zp[2]:2 [ strlen::str#2 strlen::str#0 ]
|
||||
zp[2]:4 [ strlen::len#2 strlen::len#1 strlen::return#2 main::$0 ]
|
||||
reg byte a [ main::$1 ]
|
19
src/test/ref/complex/includes/includes-2.asm
Normal file
19
src/test/ref/complex/includes/includes-2.asm
Normal file
@ -0,0 +1,19 @@
|
||||
// Includes a local file with the same name as a system library
|
||||
.pc = $801 "Basic"
|
||||
:BasicUpstart(main)
|
||||
.pc = $80d "Program"
|
||||
.label SCREEN = $400
|
||||
main: {
|
||||
// strlen(STR)
|
||||
jsr strlen
|
||||
// SCREEN [0] = (char) strlen(STR)
|
||||
lda #strlen.return
|
||||
sta SCREEN
|
||||
// }
|
||||
rts
|
||||
}
|
||||
// A local stdlib include file
|
||||
strlen: {
|
||||
.label return = 'x'
|
||||
rts
|
||||
}
|
29
src/test/ref/complex/includes/includes-2.cfg
Normal file
29
src/test/ref/complex/includes/includes-2.cfg
Normal file
@ -0,0 +1,29 @@
|
||||
@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] phi()
|
||||
[5] call strlen
|
||||
to:main::@1
|
||||
main::@1: scope:[main] from main
|
||||
[6] *((const nomodify byte*) SCREEN) ← (byte)(const word) strlen::return#0
|
||||
to:main::@return
|
||||
main::@return: scope:[main] from main::@1
|
||||
[7] return
|
||||
to:@return
|
||||
|
||||
(word()) strlen((byte*) strlen::str)
|
||||
strlen: scope:[strlen] from main
|
||||
[8] phi()
|
||||
to:strlen::@return
|
||||
strlen::@return: scope:[strlen] from strlen
|
||||
[9] return
|
||||
to:@return
|
363
src/test/ref/complex/includes/includes-2.log
Normal file
363
src/test/ref/complex/includes/includes-2.log
Normal file
@ -0,0 +1,363 @@
|
||||
Identified constant variable (byte*) STR
|
||||
Culled Empty Block (label) strlen::@1
|
||||
Culled Empty Block (label) @1
|
||||
|
||||
CONTROL FLOW GRAPH SSA
|
||||
@begin: scope:[] from
|
||||
to:@2
|
||||
|
||||
(word()) strlen((byte*) strlen::str)
|
||||
strlen: scope:[strlen] from main
|
||||
(word) strlen::return#0 ← (byte) 'x'
|
||||
to:strlen::@return
|
||||
strlen::@return: scope:[strlen] from strlen
|
||||
(word) strlen::return#3 ← phi( strlen/(word) strlen::return#0 )
|
||||
(word) strlen::return#1 ← (word) strlen::return#3
|
||||
return
|
||||
to:@return
|
||||
|
||||
(void()) main()
|
||||
main: scope:[main] from @2
|
||||
(byte*) strlen::str#0 ← (const byte*) STR
|
||||
call strlen
|
||||
(word) strlen::return#2 ← (word) strlen::return#1
|
||||
to:main::@1
|
||||
main::@1: scope:[main] from main
|
||||
(word) strlen::return#4 ← phi( main/(word) strlen::return#2 )
|
||||
(word~) main::$0 ← (word) strlen::return#4
|
||||
(byte~) main::$1 ← ((byte)) (word~) main::$0
|
||||
*((const nomodify byte*) SCREEN + (number) 0) ← (byte~) main::$1
|
||||
to:main::@return
|
||||
main::@return: scope:[main] from main::@1
|
||||
return
|
||||
to:@return
|
||||
@2: scope:[] from @begin
|
||||
call main
|
||||
to:@3
|
||||
@3: scope:[] from @2
|
||||
to:@end
|
||||
@end: scope:[] from @3
|
||||
|
||||
SYMBOL TABLE SSA
|
||||
(label) @2
|
||||
(label) @3
|
||||
(label) @begin
|
||||
(label) @end
|
||||
(const nomodify byte*) SCREEN = (byte*)(number) $400
|
||||
(const byte*) STR = (byte*) "camelot!"
|
||||
(void()) main()
|
||||
(word~) main::$0
|
||||
(byte~) main::$1
|
||||
(label) main::@1
|
||||
(label) main::@return
|
||||
(word()) strlen((byte*) strlen::str)
|
||||
(label) strlen::@return
|
||||
(word) strlen::return
|
||||
(word) strlen::return#0
|
||||
(word) strlen::return#1
|
||||
(word) strlen::return#2
|
||||
(word) strlen::return#3
|
||||
(word) strlen::return#4
|
||||
(byte*) strlen::str
|
||||
(byte*) strlen::str#0
|
||||
|
||||
Adding number conversion cast (unumber) 0 in *((const nomodify byte*) SCREEN + (number) 0) ← (byte~) main::$1
|
||||
Successful SSA optimization PassNAddNumberTypeConversions
|
||||
Inlining cast (byte~) main::$1 ← (byte)(word~) main::$0
|
||||
Successful SSA optimization Pass2InlineCast
|
||||
Simplifying constant pointer cast (byte*) 1024
|
||||
Simplifying constant integer cast 0
|
||||
Successful SSA optimization PassNCastSimplification
|
||||
Finalized unsigned number type (byte) 0
|
||||
Successful SSA optimization PassNFinalizeNumberTypeConversions
|
||||
Alias strlen::return#0 = strlen::return#3 strlen::return#1
|
||||
Alias strlen::return#2 = strlen::return#4
|
||||
Successful SSA optimization Pass2AliasElimination
|
||||
Constant (const word) strlen::return#0 = 'x'
|
||||
Constant (const byte*) strlen::str#0 = STR
|
||||
Successful SSA optimization Pass2ConstantIdentification
|
||||
Constant (const word) strlen::return#2 = strlen::return#0
|
||||
Successful SSA optimization Pass2ConstantIdentification
|
||||
Constant (const word) main::$0 = strlen::return#2
|
||||
Successful SSA optimization Pass2ConstantIdentification
|
||||
Constant (const byte) main::$1 = (byte)main::$0
|
||||
Successful SSA optimization Pass2ConstantIdentification
|
||||
Simplifying expression containing zero SCREEN in [7] *((const nomodify byte*) SCREEN + (byte) 0) ← (const byte) main::$1
|
||||
Successful SSA optimization PassNSimplifyExpressionWithZero
|
||||
Eliminating unused constant (const byte*) strlen::str#0
|
||||
Successful SSA optimization PassNEliminateUnusedVars
|
||||
Eliminating unused constant (const byte*) STR
|
||||
Successful SSA optimization PassNEliminateUnusedVars
|
||||
Inlining constant with different constant siblings (const word) strlen::return#2
|
||||
Constant inlined main::$1 = (byte)(const word) strlen::return#0
|
||||
Constant inlined strlen::return#2 = (const word) strlen::return#0
|
||||
Constant inlined main::$0 = (const word) strlen::return#0
|
||||
Successful SSA optimization Pass2ConstantInlining
|
||||
Adding NOP phi() at start of @begin
|
||||
Adding NOP phi() at start of @2
|
||||
Adding NOP phi() at start of @3
|
||||
Adding NOP phi() at start of @end
|
||||
Adding NOP phi() at start of main
|
||||
Adding NOP phi() at start of strlen
|
||||
CALL GRAPH
|
||||
Calls in [] to main:2
|
||||
Calls in [main] to strlen:6
|
||||
|
||||
Created 0 initial phi equivalence classes
|
||||
Coalesced down to 0 phi equivalence classes
|
||||
Culled Empty Block (label) @3
|
||||
Renumbering block @2 to @1
|
||||
Adding NOP phi() at start of @begin
|
||||
Adding NOP phi() at start of @1
|
||||
Adding NOP phi() at start of @end
|
||||
Adding NOP phi() at start of main
|
||||
Adding NOP phi() at start of strlen
|
||||
|
||||
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] phi()
|
||||
[5] call strlen
|
||||
to:main::@1
|
||||
main::@1: scope:[main] from main
|
||||
[6] *((const nomodify byte*) SCREEN) ← (byte)(const word) strlen::return#0
|
||||
to:main::@return
|
||||
main::@return: scope:[main] from main::@1
|
||||
[7] return
|
||||
to:@return
|
||||
|
||||
(word()) strlen((byte*) strlen::str)
|
||||
strlen: scope:[strlen] from main
|
||||
[8] phi()
|
||||
to:strlen::@return
|
||||
strlen::@return: scope:[strlen] from strlen
|
||||
[9] return
|
||||
to:@return
|
||||
|
||||
|
||||
VARIABLE REGISTER WEIGHTS
|
||||
(void()) main()
|
||||
(word()) strlen((byte*) strlen::str)
|
||||
(word) strlen::return
|
||||
(byte*) strlen::str
|
||||
|
||||
Initial phi equivalence classes
|
||||
Complete equivalence classes
|
||||
|
||||
INITIAL ASM
|
||||
Target platform is c64basic / MOS6502X
|
||||
// File Comments
|
||||
// Includes a local file with the same name as a system library
|
||||
// Upstart
|
||||
.pc = $801 "Basic"
|
||||
:BasicUpstart(__bbegin)
|
||||
.pc = $80d "Program"
|
||||
// Global Constants & labels
|
||||
.label SCREEN = $400
|
||||
// @begin
|
||||
__bbegin:
|
||||
// [1] phi from @begin to @1 [phi:@begin->@1]
|
||||
__b1_from___bbegin:
|
||||
jmp __b1
|
||||
// @1
|
||||
__b1:
|
||||
// [2] call main
|
||||
// [4] phi from @1 to main [phi:@1->main]
|
||||
main_from___b1:
|
||||
jsr main
|
||||
// [3] phi from @1 to @end [phi:@1->@end]
|
||||
__bend_from___b1:
|
||||
jmp __bend
|
||||
// @end
|
||||
__bend:
|
||||
// main
|
||||
main: {
|
||||
// [5] call strlen
|
||||
// [8] phi from main to strlen [phi:main->strlen]
|
||||
strlen_from_main:
|
||||
jsr strlen
|
||||
jmp __b1
|
||||
// main::@1
|
||||
__b1:
|
||||
// [6] *((const nomodify byte*) SCREEN) ← (byte)(const word) strlen::return#0 -- _deref_pbuc1=vbuc2
|
||||
lda #strlen.return
|
||||
sta SCREEN
|
||||
jmp __breturn
|
||||
// main::@return
|
||||
__breturn:
|
||||
// [7] return
|
||||
rts
|
||||
}
|
||||
// strlen
|
||||
// A local stdlib include file
|
||||
strlen: {
|
||||
.label return = 'x'
|
||||
jmp __breturn
|
||||
// strlen::@return
|
||||
__breturn:
|
||||
// [9] return
|
||||
rts
|
||||
}
|
||||
// File Data
|
||||
|
||||
REGISTER UPLIFT POTENTIAL REGISTERS
|
||||
Statement [6] *((const nomodify byte*) SCREEN) ← (byte)(const word) strlen::return#0 [ ] ( main:2 [ ] { } ) always clobbers reg byte a
|
||||
|
||||
REGISTER UPLIFT SCOPES
|
||||
Uplift Scope [strlen]
|
||||
Uplift Scope [main]
|
||||
Uplift Scope []
|
||||
|
||||
Uplifting [strlen] best 72 combination
|
||||
Uplifting [main] best 72 combination
|
||||
Uplifting [] best 72 combination
|
||||
|
||||
ASSEMBLER BEFORE OPTIMIZATION
|
||||
// File Comments
|
||||
// Includes a local file with the same name as a system library
|
||||
// Upstart
|
||||
.pc = $801 "Basic"
|
||||
:BasicUpstart(__bbegin)
|
||||
.pc = $80d "Program"
|
||||
// Global Constants & labels
|
||||
.label SCREEN = $400
|
||||
// @begin
|
||||
__bbegin:
|
||||
// [1] phi from @begin to @1 [phi:@begin->@1]
|
||||
__b1_from___bbegin:
|
||||
jmp __b1
|
||||
// @1
|
||||
__b1:
|
||||
// [2] call main
|
||||
// [4] phi from @1 to main [phi:@1->main]
|
||||
main_from___b1:
|
||||
jsr main
|
||||
// [3] phi from @1 to @end [phi:@1->@end]
|
||||
__bend_from___b1:
|
||||
jmp __bend
|
||||
// @end
|
||||
__bend:
|
||||
// main
|
||||
main: {
|
||||
// [5] call strlen
|
||||
// [8] phi from main to strlen [phi:main->strlen]
|
||||
strlen_from_main:
|
||||
jsr strlen
|
||||
jmp __b1
|
||||
// main::@1
|
||||
__b1:
|
||||
// [6] *((const nomodify byte*) SCREEN) ← (byte)(const word) strlen::return#0 -- _deref_pbuc1=vbuc2
|
||||
lda #strlen.return
|
||||
sta SCREEN
|
||||
jmp __breturn
|
||||
// main::@return
|
||||
__breturn:
|
||||
// [7] return
|
||||
rts
|
||||
}
|
||||
// strlen
|
||||
// A local stdlib include file
|
||||
strlen: {
|
||||
.label return = 'x'
|
||||
jmp __breturn
|
||||
// strlen::@return
|
||||
__breturn:
|
||||
// [9] return
|
||||
rts
|
||||
}
|
||||
// File Data
|
||||
|
||||
ASSEMBLER OPTIMIZATIONS
|
||||
Removing instruction jmp __b1
|
||||
Removing instruction jmp __bend
|
||||
Removing instruction jmp __b1
|
||||
Removing instruction jmp __breturn
|
||||
Removing instruction jmp __breturn
|
||||
Succesful ASM optimization Pass5NextJumpElimination
|
||||
Removing instruction __b1_from___bbegin:
|
||||
Removing instruction __b1:
|
||||
Removing instruction main_from___b1:
|
||||
Removing instruction __bend_from___b1:
|
||||
Succesful ASM optimization Pass5RedundantLabelElimination
|
||||
Removing instruction __bend:
|
||||
Removing instruction strlen_from_main:
|
||||
Removing instruction __b1:
|
||||
Removing instruction __breturn:
|
||||
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
|
||||
(void()) main()
|
||||
(label) main::@1
|
||||
(label) main::@return
|
||||
(word()) strlen((byte*) strlen::str)
|
||||
(label) strlen::@return
|
||||
(word) strlen::return
|
||||
(const word) strlen::return#0 return = (byte) 'x'
|
||||
(byte*) strlen::str
|
||||
|
||||
|
||||
|
||||
FINAL ASSEMBLER
|
||||
Score: 24
|
||||
|
||||
// File Comments
|
||||
// Includes a local file with the same name as a system library
|
||||
// Upstart
|
||||
.pc = $801 "Basic"
|
||||
:BasicUpstart(main)
|
||||
.pc = $80d "Program"
|
||||
// Global Constants & labels
|
||||
.label SCREEN = $400
|
||||
// @begin
|
||||
// [1] phi from @begin to @1 [phi:@begin->@1]
|
||||
// @1
|
||||
// [2] call main
|
||||
// [4] phi from @1 to main [phi:@1->main]
|
||||
// [3] phi from @1 to @end [phi:@1->@end]
|
||||
// @end
|
||||
// main
|
||||
main: {
|
||||
// strlen(STR)
|
||||
// [5] call strlen
|
||||
// [8] phi from main to strlen [phi:main->strlen]
|
||||
jsr strlen
|
||||
// main::@1
|
||||
// SCREEN [0] = (char) strlen(STR)
|
||||
// [6] *((const nomodify byte*) SCREEN) ← (byte)(const word) strlen::return#0 -- _deref_pbuc1=vbuc2
|
||||
lda #strlen.return
|
||||
sta SCREEN
|
||||
// main::@return
|
||||
// }
|
||||
// [7] return
|
||||
rts
|
||||
}
|
||||
// strlen
|
||||
// A local stdlib include file
|
||||
strlen: {
|
||||
.label return = 'x'
|
||||
// strlen::@return
|
||||
// [9] return
|
||||
rts
|
||||
}
|
||||
// File Data
|
||||
|
13
src/test/ref/complex/includes/includes-2.sym
Normal file
13
src/test/ref/complex/includes/includes-2.sym
Normal file
@ -0,0 +1,13 @@
|
||||
(label) @1
|
||||
(label) @begin
|
||||
(label) @end
|
||||
(const nomodify byte*) SCREEN = (byte*) 1024
|
||||
(void()) main()
|
||||
(label) main::@1
|
||||
(label) main::@return
|
||||
(word()) strlen((byte*) strlen::str)
|
||||
(label) strlen::@return
|
||||
(word) strlen::return
|
||||
(const word) strlen::return#0 return = (byte) 'x'
|
||||
(byte*) strlen::str
|
||||
|
Loading…
Reference in New Issue
Block a user