From 20f3529a2d4c52981fcd97a7c7e060fa21bb057c Mon Sep 17 00:00:00 2001 From: Flight_Control Date: Sat, 27 Apr 2024 09:29:05 +0300 Subject: [PATCH] - Optimized namespace prefix logic for global variables and fixed but to also include exported global variables used in logic. - Fixed bug for hasExportAsmLibrary to use the LibraryName always and optimized the code in AsmLibrary.java. - Fixed bug for hasExportAsmLibrary to use the LibraryName always and optimized the code in Pass4CodeGeneration.java. - Optimized naming of asmLibrary labels and names. Labels are to be used in assembler generation only. Names are used for all other purposes. --- .../java/dk/camelot64/kickc/asm/AsmFormat.java | 14 +++++++++----- .../java/dk/camelot64/kickc/asm/AsmLibrary.java | 10 +++++----- .../camelot64/kickc/model/symbols/Variable.java | 15 ++++++++++++--- .../kickc/passes/Pass4CodeGeneration.java | 12 ++++++------ 4 files changed, 32 insertions(+), 19 deletions(-) diff --git a/src/main/java/dk/camelot64/kickc/asm/AsmFormat.java b/src/main/java/dk/camelot64/kickc/asm/AsmFormat.java index 2f1aa2db9..31636d999 100644 --- a/src/main/java/dk/camelot64/kickc/asm/AsmFormat.java +++ b/src/main/java/dk/camelot64/kickc/asm/AsmFormat.java @@ -325,12 +325,16 @@ public class AsmFormat { // Implicit reference to imported .asm library procedure. String namespace = ((Procedure)symbol).getAsmLibraryLabel(); if (namespace != null) - asmName = namespace + "." + asmName; + return namespace + "." + asmName; } else if(symbol instanceof Variable var) { - // Implicit reference to imported global .asm library variable. - String namespace = ((Variable)symbol).getImportAsmLibrary(); - if(namespace != null) - asmName = namespace + "." + asmName; + // Reference to imported global .asm library variable. + String importLibraryName = ((Variable)symbol).getImportAsmLibraryLabel(); + if(importLibraryName != null) + return importLibraryName + "." + asmName; + // Reference to exported global .asm library variable. + String exportLibraryName = ((Variable)symbol).getExportAsmLibraryLabel(); + if(exportLibraryName != null) + return exportLibraryName + "." + asmName; } return asmFix(asmName); } diff --git a/src/main/java/dk/camelot64/kickc/asm/AsmLibrary.java b/src/main/java/dk/camelot64/kickc/asm/AsmLibrary.java index 7d5f61a41..3de8b7442 100644 --- a/src/main/java/dk/camelot64/kickc/asm/AsmLibrary.java +++ b/src/main/java/dk/camelot64/kickc/asm/AsmLibrary.java @@ -244,11 +244,11 @@ public class AsmLibrary extends AsmLine { else return false; } - private boolean hasExportAsmLibrary(Variable constantVar, String exportAsmLibrary) { - String varExportAsmLibrary = constantVar.getExportAsmLibrary(); - if(exportAsmLibrary != null) { - if(varExportAsmLibrary != null) { - return constantVar.getExportAsmLibrary().equals(exportAsmLibrary); + private boolean hasExportAsmLibrary(Variable constantVar, String exportAsmLibraryName) { + if(exportAsmLibraryName != null) { + String varExportAsmLibraryName = constantVar.getExportAsmLibraryName(); + if(varExportAsmLibraryName != null) { + return varExportAsmLibraryName.equals(exportAsmLibraryName); } else { return false; } diff --git a/src/main/java/dk/camelot64/kickc/model/symbols/Variable.java b/src/main/java/dk/camelot64/kickc/model/symbols/Variable.java index 00fcde73a..5999944de 100644 --- a/src/main/java/dk/camelot64/kickc/model/symbols/Variable.java +++ b/src/main/java/dk/camelot64/kickc/model/symbols/Variable.java @@ -214,7 +214,7 @@ public class Variable implements Symbol { constVar.setExport(variable.isExport()); constVar.setComments(variable.getComments()); constVar.setStructUnwind(variable.isStructUnwind()); - constVar.setAsmImportLibrary(variable.getImportAsmLibrary()); + constVar.setAsmImportLibrary(variable.getImportAsmLibraryName()); // constVar.setAsmExportLibrary(variable.getExportAsmLibrary()); return constVar; } @@ -336,14 +336,23 @@ public class Variable implements Symbol { return this.asmImportLibrary != null; } - public String getExportAsmLibrary() { + public String getExportAsmLibraryName() { return asmExportLibrary != null ? asmExportLibrary.toString() : null; } - public String getImportAsmLibrary() { + public String getExportAsmLibraryLabel() { + return asmExportLibrary != null ? asmExportLibrary.getAsm() : null; + } + + public String getImportAsmLibraryName() { return asmImportLibrary != null ? asmImportLibrary.toString() : null; } + public String getImportAsmLibraryLabel() { + return asmImportLibrary != null ? asmImportLibrary.getAsm() : null; + } + + public boolean isKindIntermediate() { return Kind.INTERMEDIATE.equals(getKind()); } diff --git a/src/main/java/dk/camelot64/kickc/passes/Pass4CodeGeneration.java b/src/main/java/dk/camelot64/kickc/passes/Pass4CodeGeneration.java index d44147ba6..e43d40282 100644 --- a/src/main/java/dk/camelot64/kickc/passes/Pass4CodeGeneration.java +++ b/src/main/java/dk/camelot64/kickc/passes/Pass4CodeGeneration.java @@ -395,11 +395,11 @@ public class Pass4CodeGeneration { } } - private boolean hasExportAsmLibrary(Variable constantVar, String exportAsmLibrary) { - String varExportAsmLibrary = constantVar.getExportAsmLibrary(); - if(exportAsmLibrary != null) { - if(varExportAsmLibrary != null) { - return varExportAsmLibrary.equals(exportAsmLibrary); + private boolean hasExportAsmLibrary(Variable constantVar, String exportAsmLibraryName) { + String varExportAsmLibraryName = constantVar.getExportAsmLibraryName(); + if(exportAsmLibraryName != null) { + if(varExportAsmLibraryName != null) { + return varExportAsmLibraryName.equals(exportAsmLibraryName); } else { return true; // Bugfix } @@ -407,7 +407,7 @@ public class Pass4CodeGeneration { boolean isImportAsmLibraryGlobal = constantVar.isAsmImportLibraryGlobal(); boolean isExportAsmLibraryParameter = constantVar.isAsmExportLibraryParameter(); boolean isExportAsmLibraryReturn = constantVar.isAsmExportLibraryReturn(); - return ( varExportAsmLibrary == null || isExportAsmLibraryParameter || isExportAsmLibraryReturn ) + return ( varExportAsmLibraryName == null || isExportAsmLibraryParameter || isExportAsmLibraryReturn ) && !isImportAsmLibraryGlobal; } }