From f794626be65d40099cb5ee8b2ec924e665348b4b Mon Sep 17 00:00:00 2001 From: jespergravgaard Date: Sat, 8 Aug 2020 02:25:11 +0200 Subject: [PATCH] Added support for specifying default string encoding in platform definition. Closes #503 --- src/main/java/dk/camelot64/kickc/Compiler.java | 9 +++++++-- .../dk/camelot64/kickc/model/TargetPlatform.java | 14 ++++++++++++++ .../kickc/parser/CTargetPlatformParser.java | 6 ++++++ .../passes/Pass0GenerateStatementSequence.java | 5 +++-- src/main/kc/target/atari2600.tgt | 1 + src/main/kc/target/atarixl.tgt | 1 + src/test/kc/examples/atarixl/helloxl.c | 1 - 7 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/main/java/dk/camelot64/kickc/Compiler.java b/src/main/java/dk/camelot64/kickc/Compiler.java index 53a5c9ea5..8bcedcb44 100644 --- a/src/main/java/dk/camelot64/kickc/Compiler.java +++ b/src/main/java/dk/camelot64/kickc/Compiler.java @@ -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(); diff --git a/src/main/java/dk/camelot64/kickc/model/TargetPlatform.java b/src/main/java/dk/camelot64/kickc/model/TargetPlatform.java index 4a7f6f145..cce011a7f 100644 --- a/src/main/java/dk/camelot64/kickc/model/TargetPlatform.java +++ b/src/main/java/dk/camelot64/kickc/model/TargetPlatform.java @@ -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 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; + } + } diff --git a/src/main/java/dk/camelot64/kickc/parser/CTargetPlatformParser.java b/src/main/java/dk/camelot64/kickc/parser/CTargetPlatformParser.java index ce84f9538..30e83bf8e 100644 --- a/src/main/java/dk/camelot64/kickc/parser/CTargetPlatformParser.java +++ b/src/main/java/dk/camelot64/kickc/parser/CTargetPlatformParser.java @@ -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) { diff --git a/src/main/java/dk/camelot64/kickc/passes/Pass0GenerateStatementSequence.java b/src/main/java/dk/camelot64/kickc/passes/Pass0GenerateStatementSequence.java index 87bf9ee64..a5e3ca3bd 100644 --- a/src/main/java/dk/camelot64/kickc/passes/Pass0GenerateStatementSequence.java +++ b/src/main/java/dk/camelot64/kickc/passes/Pass0GenerateStatementSequence.java @@ -44,13 +44,14 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor(); 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