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

Added support for #pragma emulator() specifying which emulator to execute.

This commit is contained in:
jespergravgaard 2020-05-09 08:12:28 +02:00
parent 7e859fa8ae
commit c3a9ced0f5
14 changed files with 1006 additions and 892 deletions

View File

@ -393,7 +393,19 @@ public class KickC implements Callable<Void> {
// Assemble the asm-file if instructed // Assemble the asm-file if instructed
String prgFileName = outputFileNameBase + ".prg"; String prgFileName = outputFileNameBase + ".prg";
Path prgPath = outputDir.resolve(prgFileName); Path prgPath = outputDir.resolve(prgFileName);
if(assemble || execute || debug || (emulator != null)) {
// Find emulator - if set by #pragma
if(emulator == null) {
if(program.getEmulatorCommand() != null)
emulator = program.getEmulatorCommand();
else if(debug) {
emulator = "C64Debugger";
} else if(execute) {
emulator = "x64sc";
}
}
if(assemble || emulator != null) {
Path kasmLogPath = outputDir.resolve(outputFileNameBase + ".klog"); Path kasmLogPath = outputDir.resolve(outputFileNameBase + ".klog");
System.out.println("Assembling to " + prgPath.toString()); System.out.println("Assembling to " + prgPath.toString());
String[] assembleCommand = {asmPath.toString(), "-log", kasmLogPath.toString(), "-o", prgPath.toString(), "-vicesymbols", "-showmem", "-debugdump"}; String[] assembleCommand = {asmPath.toString(), "-log", kasmLogPath.toString(), "-o", prgPath.toString(), "-vicesymbols", "-showmem", "-debugdump"};
@ -422,26 +434,22 @@ public class KickC implements Callable<Void> {
} }
} }
if(debug) {
emulator = "C64Debugger";
}
if(execute) {
emulator = "x64sc";
}
String emuOptions = "";
if(emulator.equals("C64Debugger")) {
Path viceSymbolsPath = outputDir.resolve(outputFileNameBase + ".vs");
emuOptions = "-symbols " + viceSymbolsPath + " -wait 2500" + " ";
}
// The program names used by VICE emulators
List<String> viceEmus = Arrays.asList("x64", "x64sc", "x128", "x64dtv", "xcbm2", "xcbm5x0", "xpet", "xplus4", "xscpu64", "xvic");
if(viceEmus.contains(emulator)) {
Path viceSymbolsPath = outputDir.resolve(outputFileNameBase + ".vs");
emuOptions = "-moncommands " + viceSymbolsPath.toAbsolutePath().toString() + " ";
}
// Execute the prg-file if instructed // Execute the prg-file if instructed
if(emulator != null) { if(emulator != null) {
// Find commandline options for the emulator
String emuOptions = "";
if(emulator.equals("C64Debugger")) {
Path viceSymbolsPath = outputDir.resolve(outputFileNameBase + ".vs");
emuOptions = "-symbols " + viceSymbolsPath + " -wait 2500" + " ";
}
// The program names used by VICE emulators
List<String> viceEmus = Arrays.asList("x64", "x64sc", "x128", "x64dtv", "xcbm2", "xcbm5x0", "xpet", "xplus4", "xscpu64", "xvic");
if(viceEmus.contains(emulator)) {
Path viceSymbolsPath = outputDir.resolve(outputFileNameBase + ".vs");
emuOptions = "-moncommands " + viceSymbolsPath.toAbsolutePath().toString() + " ";
}
System.out.println("Executing " + prgPath + " using " + emulator); System.out.println("Executing " + prgPath + " using " + emulator);
String executeCommand = emulator + " " + emuOptions + prgPath.toAbsolutePath().toString(); String executeCommand = emulator + " " + emuOptions + prgPath.toAbsolutePath().toString();
if(verbose) { if(verbose) {

View File

@ -49,6 +49,8 @@ public class Program {
private Path linkScriptFilePath; private Path linkScriptFilePath;
/** Body to any custom link script file used for linking (STATIC) */ /** Body to any custom link script file used for linking (STATIC) */
private String linkScriptBody; private String linkScriptBody;
/** The program name for the emulator to pass the compiled program to. */
private String emulatorCommand;
/** Absolute start address of the code. Null to start ad 0x080d. PASS 0-5 (STATIC) */ /** Absolute start address of the code. Null to start ad 0x080d. PASS 0-5 (STATIC) */
private Number programPc; private Number programPc;
@ -506,6 +508,14 @@ public class Program {
return programPc; return programPc;
} }
public void setEmulatorCommand(String emulatorCommand) {
this.emulatorCommand = emulatorCommand;
}
public String getEmulatorCommand() {
return emulatorCommand;
}
public CompileLog getLog() { public CompileLog getLog() {
return log; return log;
} }

View File

@ -66,6 +66,7 @@ RESERVE:'reserve' ;
PC:'pc'; PC:'pc';
TARGET:'target'; TARGET:'target';
LINK:'link'; LINK:'link';
EMULATOR:'emulator';
CPU:'cpu'; CPU:'cpu';
CODESEG:'code_seg'; CODESEG:'code_seg';
DATASEG:'data_seg'; DATASEG:'data_seg';

View File

@ -41,124 +41,125 @@ RESERVE=40
PC=41 PC=41
TARGET=42 TARGET=42
LINK=43 LINK=43
CPU=44 EMULATOR=44
CODESEG=45 CPU=45
DATASEG=46 CODESEG=46
ENCODING=47 DATASEG=47
CONST=48 ENCODING=48
EXTERN=49 CONST=49
EXPORT=50 EXTERN=50
ALIGN=51 EXPORT=51
INLINE=52 ALIGN=52
VOLATILE=53 INLINE=53
STATIC=54 VOLATILE=54
INTERRUPT=55 STATIC=55
REGISTER=56 INTERRUPT=56
ADDRESS=57 REGISTER=57
ADDRESS_ZEROPAGE=58 ADDRESS=58
ADDRESS_MAINMEM=59 ADDRESS_ZEROPAGE=59
FORM_SSA=60 ADDRESS_MAINMEM=60
FORM_MA=61 FORM_SSA=61
INTRINSIC=62 FORM_MA=62
CALLING=63 INTRINSIC=63
CALLINGCONVENTION=64 CALLING=64
VARMODEL=65 CALLINGCONVENTION=65
IF=66 VARMODEL=66
ELSE=67 IF=67
WHILE=68 ELSE=68
DO=69 WHILE=69
FOR=70 DO=70
SWITCH=71 FOR=71
RETURN=72 SWITCH=72
BREAK=73 RETURN=73
CONTINUE=74 BREAK=74
ASM=75 CONTINUE=75
DEFAULT=76 ASM=76
CASE=77 DEFAULT=77
STRUCT=78 CASE=78
ENUM=79 STRUCT=79
SIZEOF=80 ENUM=80
TYPEID=81 SIZEOF=81
DEFINED=82 TYPEID=82
KICKASM=83 DEFINED=83
RESOURCE=84 KICKASM=84
USES=85 RESOURCE=85
CLOBBERS=86 USES=86
BYTES=87 CLOBBERS=87
CYCLES=88 BYTES=88
LOGIC_NOT=89 CYCLES=89
SIGNEDNESS=90 LOGIC_NOT=90
SIMPLETYPE=91 SIGNEDNESS=91
BOOLEAN=92 SIMPLETYPE=92
KICKASM_BODY=93 BOOLEAN=93
IMPORT=94 KICKASM_BODY=94
INCLUDE=95 IMPORT=95
PRAGMA=96 INCLUDE=96
DEFINE=97 PRAGMA=97
DEFINE_CONTINUE=98 DEFINE=98
UNDEF=99 DEFINE_CONTINUE=99
IFDEF=100 UNDEF=100
IFNDEF=101 IFDEF=101
IFIF=102 IFNDEF=102
ELIF=103 IFIF=103
IFELSE=104 ELIF=104
ENDIF=105 IFELSE=105
NUMBER=106 ENDIF=106
NUMFLOAT=107 NUMBER=107
BINFLOAT=108 NUMFLOAT=108
DECFLOAT=109 BINFLOAT=109
HEXFLOAT=110 DECFLOAT=110
NUMINT=111 HEXFLOAT=111
BININTEGER=112 NUMINT=112
DECINTEGER=113 BININTEGER=113
HEXINTEGER=114 DECINTEGER=114
NAME=115 HEXINTEGER=115
STRING=116 NAME=116
CHAR=117 STRING=117
WS=118 CHAR=118
COMMENT_LINE=119 WS=119
COMMENT_BLOCK=120 COMMENT_LINE=120
ASM_BYTE=121 COMMENT_BLOCK=121
ASM_MNEMONIC=122 ASM_BYTE=122
ASM_IMM=123 ASM_MNEMONIC=123
ASM_COLON=124 ASM_IMM=124
ASM_COMMA=125 ASM_COLON=125
ASM_PAR_BEGIN=126 ASM_COMMA=126
ASM_PAR_END=127 ASM_PAR_BEGIN=127
ASM_BRACKET_BEGIN=128 ASM_PAR_END=128
ASM_BRACKET_END=129 ASM_BRACKET_BEGIN=129
ASM_DOT=130 ASM_BRACKET_END=130
ASM_SHIFT_LEFT=131 ASM_DOT=131
ASM_SHIFT_RIGHT=132 ASM_SHIFT_LEFT=132
ASM_PLUS=133 ASM_SHIFT_RIGHT=133
ASM_MINUS=134 ASM_PLUS=134
ASM_LESS_THAN=135 ASM_MINUS=135
ASM_GREATER_THAN=136 ASM_LESS_THAN=136
ASM_MULTIPLY=137 ASM_GREATER_THAN=137
ASM_DIVIDE=138 ASM_MULTIPLY=138
ASM_CURLY_BEGIN=139 ASM_DIVIDE=139
ASM_CURLY_END=140 ASM_CURLY_BEGIN=140
ASM_NUMBER=141 ASM_CURLY_END=141
ASM_NUMFLOAT=142 ASM_NUMBER=142
ASM_BINFLOAT=143 ASM_NUMFLOAT=143
ASM_DECFLOAT=144 ASM_BINFLOAT=144
ASM_HEXFLOAT=145 ASM_DECFLOAT=145
ASM_NUMINT=146 ASM_HEXFLOAT=146
ASM_BININTEGER=147 ASM_NUMINT=147
ASM_DECINTEGER=148 ASM_BININTEGER=148
ASM_HEXINTEGER=149 ASM_DECINTEGER=149
ASM_CHAR=150 ASM_HEXINTEGER=150
ASM_MULTI_REL=151 ASM_CHAR=151
ASM_MULTI_NAME=152 ASM_MULTI_REL=152
ASM_NAME=153 ASM_MULTI_NAME=153
ASM_WS=154 ASM_NAME=154
ASM_COMMENT_LINE=155 ASM_WS=155
ASM_COMMENT_BLOCK=156 ASM_COMMENT_LINE=156
IMPORT_SYSTEMFILE=157 ASM_COMMENT_BLOCK=157
IMPORT_LOCALFILE=158 IMPORT_SYSTEMFILE=158
IMPORT_WS=159 IMPORT_LOCALFILE=159
IMPORT_COMMENT_LINE=160 IMPORT_WS=160
IMPORT_COMMENT_BLOCK=161 IMPORT_COMMENT_LINE=161
IMPORT_COMMENT_BLOCK=162
';'=8 ';'=8
'..'=11 '..'=11
'...'=12 '...'=12
@ -183,61 +184,62 @@ IMPORT_COMMENT_BLOCK=161
'pc'=41 'pc'=41
'target'=42 'target'=42
'link'=43 'link'=43
'cpu'=44 'emulator'=44
'code_seg'=45 'cpu'=45
'data_seg'=46 'code_seg'=46
'encoding'=47 'data_seg'=47
'const'=48 'encoding'=48
'extern'=49 'const'=49
'export'=50 'extern'=50
'align'=51 'export'=51
'inline'=52 'align'=52
'volatile'=53 'inline'=53
'static'=54 'volatile'=54
'interrupt'=55 'static'=55
'register'=56 'interrupt'=56
'__address'=57 'register'=57
'__zp'=58 '__address'=58
'__mem'=59 '__zp'=59
'__ssa'=60 '__mem'=60
'__ma'=61 '__ssa'=61
'__intrinsic'=62 '__ma'=62
'calling'=63 '__intrinsic'=63
'var_model'=65 'calling'=64
'if'=66 'var_model'=66
'else'=67 'if'=67
'while'=68 'else'=68
'do'=69 'while'=69
'for'=70 'do'=70
'switch'=71 'for'=71
'return'=72 'switch'=72
'break'=73 'return'=73
'continue'=74 'break'=74
'asm'=75 'continue'=75
'default'=76 'asm'=76
'case'=77 'default'=77
'struct'=78 'case'=78
'enum'=79 'struct'=79
'sizeof'=80 'enum'=80
'typeid'=81 'sizeof'=81
'defined'=82 'typeid'=82
'kickasm'=83 'defined'=83
'resource'=84 'kickasm'=84
'uses'=85 'resource'=85
'clobbers'=86 'uses'=86
'bytes'=87 'clobbers'=87
'cycles'=88 'bytes'=88
'!'=89 'cycles'=89
'#import'=94 '!'=90
'#include'=95 '#import'=95
'#pragma'=96 '#include'=96
'#define'=97 '#pragma'=97
'#undef'=99 '#define'=98
'#ifdef'=100 '#undef'=100
'#ifndef'=101 '#ifdef'=101
'#if'=102 '#ifndef'=102
'#elif'=103 '#if'=103
'#else'=104 '#elif'=104
'#endif'=105 '#else'=105
'.byte'=121 '#endif'=106
'#'=123 '.byte'=122
'#'=124

View File

@ -151,6 +151,7 @@ globalDirective
| (PRAGMA TARGET) PAR_BEGIN NAME PAR_END #globalDirectivePlatform | (PRAGMA TARGET) PAR_BEGIN NAME PAR_END #globalDirectivePlatform
| (PRAGMA CPU) PAR_BEGIN NAME PAR_END #globalDirectiveCpu | (PRAGMA CPU) PAR_BEGIN NAME PAR_END #globalDirectiveCpu
| (PRAGMA LINK) PAR_BEGIN STRING PAR_END #globalDirectiveLinkScript | (PRAGMA LINK) PAR_BEGIN STRING PAR_END #globalDirectiveLinkScript
| (PRAGMA EMULATOR) PAR_BEGIN STRING PAR_END #globalDirectiveEmulator
| (PRAGMA CODESEG) PAR_BEGIN NAME PAR_END #globalDirectiveCodeSeg | (PRAGMA CODESEG) PAR_BEGIN NAME PAR_END #globalDirectiveCodeSeg
| (PRAGMA DATASEG) PAR_BEGIN NAME PAR_END #globalDirectiveDataSeg | (PRAGMA DATASEG) PAR_BEGIN NAME PAR_END #globalDirectiveDataSeg
| (PRAGMA ENCODING) PAR_BEGIN NAME PAR_END #globalDirectiveEncoding | (PRAGMA ENCODING) PAR_BEGIN NAME PAR_END #globalDirectiveEncoding

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@ -159,6 +159,7 @@ IMPORT_LOCALFILE=158
IMPORT_WS=159 IMPORT_WS=159
IMPORT_COMMENT_LINE=160 IMPORT_COMMENT_LINE=160
IMPORT_COMMENT_BLOCK=161 IMPORT_COMMENT_BLOCK=161
EMULATOR=162
';'=8 ';'=8
'..'=11 '..'=11
'...'=12 '...'=12

View File

@ -577,6 +577,18 @@ public class KickCParserBaseListener implements KickCParserListener {
* <p>The default implementation does nothing.</p> * <p>The default implementation does nothing.</p>
*/ */
@Override public void exitGlobalDirectiveLinkScript(KickCParser.GlobalDirectiveLinkScriptContext ctx) { } @Override public void exitGlobalDirectiveLinkScript(KickCParser.GlobalDirectiveLinkScriptContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterGlobalDirectiveEmulator(KickCParser.GlobalDirectiveEmulatorContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitGlobalDirectiveEmulator(KickCParser.GlobalDirectiveEmulatorContext ctx) { }
/** /**
* {@inheritDoc} * {@inheritDoc}
* *

View File

@ -342,6 +342,13 @@ public class KickCParserBaseVisitor<T> extends AbstractParseTreeVisitor<T> imple
* {@link #visitChildren} on {@code ctx}.</p> * {@link #visitChildren} on {@code ctx}.</p>
*/ */
@Override public T visitGlobalDirectiveLinkScript(KickCParser.GlobalDirectiveLinkScriptContext ctx) { return visitChildren(ctx); } @Override public T visitGlobalDirectiveLinkScript(KickCParser.GlobalDirectiveLinkScriptContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitGlobalDirectiveEmulator(KickCParser.GlobalDirectiveEmulatorContext ctx) { return visitChildren(ctx); }
/** /**
* {@inheritDoc} * {@inheritDoc}
* *

View File

@ -531,6 +531,18 @@ public interface KickCParserListener extends ParseTreeListener {
* @param ctx the parse tree * @param ctx the parse tree
*/ */
void exitGlobalDirectiveLinkScript(KickCParser.GlobalDirectiveLinkScriptContext ctx); void exitGlobalDirectiveLinkScript(KickCParser.GlobalDirectiveLinkScriptContext ctx);
/**
* Enter a parse tree produced by the {@code globalDirectiveEmulator}
* labeled alternative in {@link KickCParser#globalDirective}.
* @param ctx the parse tree
*/
void enterGlobalDirectiveEmulator(KickCParser.GlobalDirectiveEmulatorContext ctx);
/**
* Exit a parse tree produced by the {@code globalDirectiveEmulator}
* labeled alternative in {@link KickCParser#globalDirective}.
* @param ctx the parse tree
*/
void exitGlobalDirectiveEmulator(KickCParser.GlobalDirectiveEmulatorContext ctx);
/** /**
* Enter a parse tree produced by the {@code globalDirectiveCodeSeg} * Enter a parse tree produced by the {@code globalDirectiveCodeSeg}
* labeled alternative in {@link KickCParser#globalDirective}. * labeled alternative in {@link KickCParser#globalDirective}.

View File

@ -320,6 +320,13 @@ public interface KickCParserVisitor<T> extends ParseTreeVisitor<T> {
* @return the visitor result * @return the visitor result
*/ */
T visitGlobalDirectiveLinkScript(KickCParser.GlobalDirectiveLinkScriptContext ctx); T visitGlobalDirectiveLinkScript(KickCParser.GlobalDirectiveLinkScriptContext ctx);
/**
* Visit a parse tree produced by the {@code globalDirectiveEmulator}
* labeled alternative in {@link KickCParser#globalDirective}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitGlobalDirectiveEmulator(KickCParser.GlobalDirectiveEmulatorContext ctx);
/** /**
* Visit a parse tree produced by the {@code globalDirectiveCodeSeg} * Visit a parse tree produced by the {@code globalDirectiveCodeSeg}
* labeled alternative in {@link KickCParser#globalDirective}. * labeled alternative in {@link KickCParser#globalDirective}.

View File

@ -136,6 +136,14 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
return null; return null;
} }
@Override
public Object visitGlobalDirectiveEmulator(KickCParser.GlobalDirectiveEmulatorContext ctx) {
String emuName = ctx.STRING().getText();
emuName = emuName.substring(1, emuName.length() - 1);
program.setEmulatorCommand(emuName);
return null;
}
@Override @Override
public Object visitGlobalDirectiveReserve(KickCParser.GlobalDirectiveReserveContext ctx) { public Object visitGlobalDirectiveReserve(KickCParser.GlobalDirectiveReserveContext ctx) {
List<Integer> reservedZps = new ArrayList<>(); List<Integer> reservedZps = new ArrayList<>();

View File

@ -1,5 +1,6 @@
// Random walk with color fading for Commodore Plus/4 / C16 // Random walk with color fading for Commodore Plus/4 / C16
#pragma link("plus4.ld") #pragma link("plus4.ld")
#pragma emulator("xplus4")
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>