1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-12-28 01:29:44 +00:00

Added support for specifying default string encoding in platform definition. Closes #503

This commit is contained in:
jespergravgaard 2020-08-08 02:25:11 +02:00
parent 58cc08e0d0
commit f794626be6
7 changed files with 32 additions and 5 deletions

View File

@ -6,6 +6,7 @@ import dk.camelot64.kickc.model.CompileError;
import dk.camelot64.kickc.model.ProcedureCompilation;
import dk.camelot64.kickc.model.Program;
import dk.camelot64.kickc.model.symbols.Procedure;
import dk.camelot64.kickc.model.values.StringEncoding;
import dk.camelot64.kickc.parser.CParser;
import dk.camelot64.kickc.parser.KickCParser;
import dk.camelot64.kickc.passes.*;
@ -171,9 +172,13 @@ public class Compiler {
callingConvention = Procedure.CallingConvention.PHI_CALL;
}
Pass0GenerateStatementSequence pass0GenerateStatementSequence = new Pass0GenerateStatementSequence(cParser, cFileContext, program, callingConvention);
pass0GenerateStatementSequence.generate();
// Find encoding
StringEncoding encoding = program.getTargetPlatform().getEncoding();
if(encoding==null)
encoding = StringEncoding.SCREENCODE_MIXED;
Pass0GenerateStatementSequence pass0GenerateStatementSequence = new Pass0GenerateStatementSequence(cParser, cFileContext, program, callingConvention, encoding);
pass0GenerateStatementSequence.generate();
pass1GenerateSSA();
pass2Optimize();

View File

@ -1,5 +1,7 @@
package dk.camelot64.kickc.model;
import dk.camelot64.kickc.model.values.StringEncoding;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
@ -33,6 +35,9 @@ public class TargetPlatform {
/** The output file extension. */
private String outFileExtension;
/** The default string encoding. */
private StringEncoding encoding;
/** A number of preprocessor macro defines. */
private Map<String, String> defines = null;
@ -126,4 +131,13 @@ public class TargetPlatform {
public void setVariableBuilderConfig(VariableBuilderConfig variableBuilderConfig) {
this.variableBuilderConfig = variableBuilderConfig;
}
public StringEncoding getEncoding() {
return encoding;
}
public void setEncoding(StringEncoding encoding) {
this.encoding = encoding;
}
}

View File

@ -7,6 +7,7 @@ import dk.camelot64.kickc.model.TargetCpu;
import dk.camelot64.kickc.model.TargetPlatform;
import dk.camelot64.kickc.model.VariableBuilderConfig;
import dk.camelot64.kickc.model.statements.StatementSource;
import dk.camelot64.kickc.model.values.StringEncoding;
import javax.json.*;
import javax.json.stream.JsonParsingException;
@ -53,6 +54,11 @@ public class CTargetPlatformParser {
if(outExtension != null)
targetPlatform.setOutFileExtension(outExtension);
}
{
final String encoding = platformJson.getString("encoding", null);
if(encoding != null)
targetPlatform.setEncoding(StringEncoding.fromName(encoding.toUpperCase()));
}
{
final JsonArray zpReserves = platformJson.getJsonArray("zp_reserve");
if(zpReserves != null) {

View File

@ -44,13 +44,14 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
/** The memory area used by default for variables. */
private Variable.MemoryArea defaultMemoryArea;
public Pass0GenerateStatementSequence(CParser cParser, KickCParser.FileContext fileCtx, Program program, Procedure.CallingConvention initialCallingConvention) {
public Pass0GenerateStatementSequence(CParser cParser, KickCParser.FileContext fileCtx, Program program, Procedure.CallingConvention initialCallingConvention, StringEncoding defaultEncoding) {
this.cParser = cParser;
this.fileCtx = fileCtx;
this.program = program;
this.scopeStack = new Stack<>();
this.defaultMemoryArea = Variable.MemoryArea.ZEROPAGE_MEMORY;
this.currentCallingConvention = initialCallingConvention;
this.currentEncoding = defaultEncoding;
scopeStack.push(program.getScope());
}
@ -2323,7 +2324,7 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
}
/** The current string encoding used if no explicit encoding is specified. */
private StringEncoding currentEncoding = StringEncoding.SCREENCODE_MIXED;
private StringEncoding currentEncoding;
@Override
public RValue visitExprString(KickCParser.ExprStringContext ctx) {

View File

@ -4,6 +4,7 @@
"cpu": "MOS6502X",
"emulator": "stella",
"zp_reserve": [ "0x00..0x7f" ],
"encoding": "screencode_atari",
"defines": {
"__ATARI2600__": 1
}

View File

@ -3,6 +3,7 @@
"link": "atarixl.ld",
"cpu": "MOS6502X",
"emulator": "atari800 -xl",
"encoding": "screencode_atari",
"defines": {
"__ATARIXL__": 1
}

View File

@ -4,7 +4,6 @@
// Display Lists atariarchives.org/mapping/appendix8.php
#pragma target(atarixl)
#pragma encoding(screencode_atari)
#pragma emulator("65XEDebugger")
#include <atari-xl.h>