From 8bb0ae904f6e0ece2fc42b9a5cdc78284a664fe2 Mon Sep 17 00:00:00 2001 From: Sven Van de Velde Date: Tue, 11 Apr 2023 10:13:41 +0200 Subject: [PATCH] - processed some of the comments. - documentation fixes. --- .../java/dk/camelot64/kickc/model/Bank.java | 8 +++++ .../dk/camelot64/kickc/model/Directive.java | 11 +++++-- .../dk/camelot64/kickc/model/Program.java | 7 ---- .../kickc/model/symbols/Procedure.java | 13 +++----- .../camelot64/kickc/model/symbols/Scope.java | 2 +- .../Pass0GenerateStatementSequence.java | 33 +++++++++---------- .../kickc/passes/Pass4CodeGeneration.java | 4 +-- 7 files changed, 40 insertions(+), 38 deletions(-) diff --git a/src/main/java/dk/camelot64/kickc/model/Bank.java b/src/main/java/dk/camelot64/kickc/model/Bank.java index c51312740..ec111abb3 100644 --- a/src/main/java/dk/camelot64/kickc/model/Bank.java +++ b/src/main/java/dk/camelot64/kickc/model/Bank.java @@ -108,6 +108,14 @@ public class Bank { private final String bankArea; // The bank method to apply. private Long bank; // The bank number. + /** + * Creates a new Bank which collects the necessary data to handle banking. + * For example, on the Commander X16, RAM is banked from address 0xA000 till 0xBFFF. + * Zeropage 0x00 configures this banked RAM, with a number from 0x00 till 0xff. + * So banked RAM is is a bankArea, and the bank is a configurable bank number in the bankArea. + * @param bankArea A bank area is a memory range that is banked on a target platform. + * @param bank A bank is a number that defines a bank configuration in a bank area. + */ public Bank(String bankArea, Long bank) { this.bankArea = bankArea; this.bank = bank; diff --git a/src/main/java/dk/camelot64/kickc/model/Directive.java b/src/main/java/dk/camelot64/kickc/model/Directive.java index fe4728cb7..4b43f7d4b 100644 --- a/src/main/java/dk/camelot64/kickc/model/Directive.java +++ b/src/main/java/dk/camelot64/kickc/model/Directive.java @@ -43,11 +43,16 @@ public class Directive { public Inline() { super("inline"); } } - /** Function declared banked. */ + /** + * Creates a new Bank which collects the necessary data to handle banking. + * For example, on the Commander X16, RAM is banked from address 0xA000 till 0xBFFF. + * Zeropage 0x00 configures this banked RAM, with a number from 0x00 till 0xff. + * So banked RAM is is a bankArea, and the bank is a configurable bank number in the bankArea. + */ static public class Bank extends Directive { - private String bankArea; - private Long bank; + private String bankArea; // A bank area is a memory range that is banked on a target platform. + private Long bank; // A bank is a number that defines a bank configuration in a bank area. public Bank(String bankArea, Long bank) { super("bank" ); diff --git a/src/main/java/dk/camelot64/kickc/model/Program.java b/src/main/java/dk/camelot64/kickc/model/Program.java index 000cad6bd..c42debf3d 100644 --- a/src/main/java/dk/camelot64/kickc/model/Program.java +++ b/src/main/java/dk/camelot64/kickc/model/Program.java @@ -106,7 +106,6 @@ public class Program { /** The register weight of all variables describing how much the variable would theoretically gain from being in a register. PASS 3-5 (CACHED ON-DEMAND) */ private VariableRegisterWeights variableRegisterWeights; /** All #pragma code segments. Collected during parsing. These are used by the bank() pragmas to validate if the code segment exists during compilation.*/ - private final Map pragmaCodeSegs; public Program() { this.outputFileManager = new OutputFileManager(); @@ -119,8 +118,6 @@ public class Program { this.asmResourceFiles = new ArrayList<>(); this.reservedZps = new ArrayList<>(); this.procedureCompilations = new LinkedHashMap<>(); - this.pragmaCodeSegs = new HashMap<>(); // Used to collect all pragma code segments. - } /** @@ -540,8 +537,4 @@ public class Program { sizeInfo.append(getAsm().getSizeInfo()); return sizeInfo.toString(); } - - public Map getPragmaCodeSegs() { - return pragmaCodeSegs; - } } diff --git a/src/main/java/dk/camelot64/kickc/model/symbols/Procedure.java b/src/main/java/dk/camelot64/kickc/model/symbols/Procedure.java index e3eac7744..a154a2ca0 100644 --- a/src/main/java/dk/camelot64/kickc/model/symbols/Procedure.java +++ b/src/main/java/dk/camelot64/kickc/model/symbols/Procedure.java @@ -34,7 +34,7 @@ public class Procedure extends Scope { private List comments; /** Reserved zeropage addresses. */ private List reservedZps; - /** The data and code segment to put the procedure into. */ + /** The data and code segment to put the procedure into. When null the procedure is not assigned to the code segment. */ private String segmentCode; /** The list of constructor procedures for this procedure. The constructor procedures are called during program initialization. */ private final List constructorRefs; @@ -42,7 +42,9 @@ public class Procedure extends Scope { private boolean isConstructor; /** The source of the procedure definition. */ private StatementSource definitionSource; - /** The bank segment information. Collected during parsing. These are used to compare with the current currentBank to decide a near or a far call, and to keep inline calling routines.*/ + /** The bank segment information. Collected during parsing. These are used to compare with the current currentBank to decide a near or a far call, and to keep inline calling routines. + * When this value is null, the procedure is not allocated to a bank. + */ private Bank bankLocation; @@ -106,7 +108,6 @@ public class Procedure extends Scope { this.interruptType = null; this.comments = new ArrayList<>(); this.segmentCode = segmentCode; - this.segmentData = segmentData; // The parameter dataSegment was foreseen, but never implemented. this.callingConvention = callingConvention; this.constructorRefs = new ArrayList<>(); this.isConstructor = false; @@ -136,10 +137,6 @@ public class Procedure extends Scope { this.segmentCode = segmentCode; } - public void setCodeSegment(String codeSegment) { - this.segmentCode = segmentCode; - } - public List getParameterNames() { return parameterNames; } @@ -300,7 +297,7 @@ public class Procedure extends Scope { res.append("__intrinsic "); } if(isDeclaredBanked()) { - res.append("__bank(").append("bank").append(") "); + res.append("__bank(").append(this.getBankArea()).append(", ").append(this.getBank()).append(") "); } if(!callingConvention.equals(CallingConvention.PHI_CALL)) { res.append(getCallingConvention().getName()).append(" "); diff --git a/src/main/java/dk/camelot64/kickc/model/symbols/Scope.java b/src/main/java/dk/camelot64/kickc/model/symbols/Scope.java index b950128f7..0ef0c0345 100644 --- a/src/main/java/dk/camelot64/kickc/model/symbols/Scope.java +++ b/src/main/java/dk/camelot64/kickc/model/symbols/Scope.java @@ -26,7 +26,7 @@ public abstract class Scope implements Symbol { private int blockCount = 1; private Scope parentScope; private String fullName; - protected String segmentData; + private String segmentData; public Scope(String name, Scope parentScope, String segmentData) { this.name = name; diff --git a/src/main/java/dk/camelot64/kickc/passes/Pass0GenerateStatementSequence.java b/src/main/java/dk/camelot64/kickc/passes/Pass0GenerateStatementSequence.java index 5d4965219..e9d6cadec 100644 --- a/src/main/java/dk/camelot64/kickc/passes/Pass0GenerateStatementSequence.java +++ b/src/main/java/dk/camelot64/kickc/passes/Pass0GenerateStatementSequence.java @@ -289,11 +289,10 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor effectiveDirectives = varDecl.getDeclDirectives(); final List declComments = varDecl.getDeclComments(); varDecl.exitVar(); - VariableBuilder varBuilder = new VariableBuilder(varName, getCurrentScope(), false, false, effectiveType, effectiveDirectives, currentDataSegment, program.getTargetPlatform().getVariableBuilderConfig()); + VariableBuilder varBuilder = new VariableBuilder(varName, getCurrentScope(), false, false, effectiveType, effectiveDirectives, currentSegmentData, program.getTargetPlatform().getVariableBuilderConfig()); Variable variable = varBuilder.build(); if(isStructMember && (initializer != null)) throw new CompileError("Initializer not supported inside structs " + effectiveType.toCDecl(), declSource); @@ -1180,7 +1179,7 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor parameters = procedure.getParameters(); @@ -590,7 +590,7 @@ public class Pass4CodeGeneration { Variable master = variable.getPhiMaster(); if (master != null) { if (parameters.contains(master) || master.getLocalName().equals("return")) { - variable.setDataSegment("Data"); + variable.setDataSegment(Scope.SEGMENT_DATA_DEFAULT); } } }