mirror of
https://gitlab.com/camelot/kickc.git
synced 2025-04-14 10:37:36 +00:00
- processed some of the comments.
- documentation fixes.
This commit is contained in:
parent
9cf5f4cd05
commit
8bb0ae904f
@ -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;
|
||||
|
@ -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" );
|
||||
|
@ -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<String, KickCParser.PragmaContext> 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<String, KickCParser.PragmaContext> getPragmaCodeSegs() {
|
||||
return pragmaCodeSegs;
|
||||
}
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ public class Procedure extends Scope {
|
||||
private List<Comment> comments;
|
||||
/** Reserved zeropage addresses. */
|
||||
private List<Integer> 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<ProcedureRef> 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<String> 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(" ");
|
||||
|
@ -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;
|
||||
|
@ -289,11 +289,10 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
|
||||
}
|
||||
break;
|
||||
case CParser.PRAGMA_CODE_SEG:
|
||||
this.currentCodeSegment = pragmaParamName(pragmaParamSingle(ctx));
|
||||
this.program.getPragmaCodeSegs().put(this.currentCodeSegment, ctx);
|
||||
this.currentSegmentCode = pragmaParamName(pragmaParamSingle(ctx));
|
||||
break;
|
||||
case CParser.PRAGMA_DATA_SEG:
|
||||
this.currentDataSegment = pragmaParamName(pragmaParamSingle(ctx));
|
||||
this.currentSegmentData = pragmaParamName(pragmaParamSingle(ctx));
|
||||
break;
|
||||
case CParser.PRAGMA_BANK:
|
||||
try {
|
||||
@ -468,12 +467,12 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
|
||||
private Procedure.CallingConvention currentCallingConvention;
|
||||
|
||||
/** The current code segment. */
|
||||
private String currentCodeSegment = Scope.SEGMENT_CODE_DEFAULT;
|
||||
private String currentSegmentCode = Scope.SEGMENT_CODE_DEFAULT;
|
||||
|
||||
/** The current data segment. */
|
||||
private String currentDataSegment = Scope.SEGMENT_DATA_DEFAULT;
|
||||
private String currentSegmentData = Scope.SEGMENT_DATA_DEFAULT;
|
||||
|
||||
/** The current far segment. */
|
||||
/** The current far segment. If null, the sequent procedures won't be banked. */
|
||||
private Bank currentBank;
|
||||
|
||||
/** The current default interrupt type. */
|
||||
@ -531,7 +530,7 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
|
||||
*/
|
||||
private Procedure declareProcedure(boolean defineProcedure, ParserRuleContext ctx, StatementSource statementSource) {
|
||||
|
||||
Procedure procedure = new Procedure(varDecl.getVarName(), (SymbolTypeProcedure) varDecl.getEffectiveType(), program.getScope(), currentCodeSegment, currentDataSegment, currentCallingConvention, currentBank);
|
||||
Procedure procedure = new Procedure(varDecl.getVarName(), (SymbolTypeProcedure) varDecl.getEffectiveType(), program.getScope(), currentSegmentCode, currentSegmentData, currentCallingConvention, currentBank);
|
||||
addDirectives(procedure, varDecl.getDeclDirectives(), statementSource);
|
||||
// Check if the declaration matches any existing declaration!
|
||||
final Symbol existingSymbol = program.getScope().getSymbol(procedure.getRef());
|
||||
@ -583,19 +582,19 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
|
||||
if(parameter.name == null)
|
||||
throw new CompileError("Illegal unnamed parameter.", statementSource);
|
||||
|
||||
VariableBuilder varBuilder = new VariableBuilder(parameter.name, getCurrentScope(), true, false, parameter.type, null, currentDataSegment, program.getTargetPlatform().getVariableBuilderConfig());
|
||||
VariableBuilder varBuilder = new VariableBuilder(parameter.name, getCurrentScope(), true, false, parameter.type, null, currentSegmentData, program.getTargetPlatform().getVariableBuilderConfig());
|
||||
final Variable paramVar = varBuilder.build();
|
||||
parameterList.add(paramVar);
|
||||
}
|
||||
procedure.setParameters(parameterList);
|
||||
procedure.setSegmentData(currentDataSegment); // When a procedure is defined, the currentDataSegment is to be set.
|
||||
procedure.setSegmentCode(currentCodeSegment); // When a procedure is defined, the currentCodeSegment is to be set.
|
||||
procedure.setSegmentData(currentSegmentData); // When a procedure is defined, the currentDataSegment is to be set.
|
||||
procedure.setSegmentCode(currentSegmentCode); // When a procedure is defined, the currentSegmentCode is to be set.
|
||||
if(procedure.getBankLocation() == null && currentBank != null) {
|
||||
procedure.setBankLocation(currentBank); // When a procedure is defined, the currentBank is to be set, or far calls won't work.
|
||||
}
|
||||
// Add return variable
|
||||
if(!SymbolType.VOID.equals(procedure.getReturnType())) {
|
||||
final VariableBuilder builder = new VariableBuilder("return", procedure, false, false, procedure.getReturnType(), varDecl.getDeclDirectives(), currentDataSegment, program.getTargetPlatform().getVariableBuilderConfig());
|
||||
final VariableBuilder builder = new VariableBuilder("return", procedure, false, false, procedure.getReturnType(), varDecl.getDeclDirectives(), currentSegmentData, program.getTargetPlatform().getVariableBuilderConfig());
|
||||
builder.build();
|
||||
}
|
||||
// exit the procedure
|
||||
@ -1070,7 +1069,7 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
|
||||
final List<Directive> effectiveDirectives = varDecl.getDeclDirectives();
|
||||
final List<Comment> 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<Objec
|
||||
ConstantArrayKickAsm constantArrayKickAsm = new ConstantArrayKickAsm(((SymbolTypePointer) varDecl.getEffectiveType()).getElementType(), kasm.kickAsmCode, kasm.uses, ((SymbolTypePointer) effectiveType).getArraySpec().getArraySize());
|
||||
// Add a constant variable
|
||||
Scope scope = getCurrentScope();
|
||||
VariableBuilder varBuilder = new VariableBuilder(varName, scope, false, false, varDecl.getEffectiveType(), varDecl.getDeclDirectives(), currentDataSegment, program.getTargetPlatform().getVariableBuilderConfig());
|
||||
VariableBuilder varBuilder = new VariableBuilder(varName, scope, false, false, varDecl.getEffectiveType(), varDecl.getDeclDirectives(), currentSegmentData, program.getTargetPlatform().getVariableBuilderConfig());
|
||||
Variable variable = varBuilder.build();
|
||||
// Set constant value
|
||||
variable.setInitValue(getConstInitValue(constantArrayKickAsm, null, statementSource));
|
||||
@ -1739,7 +1738,7 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
|
||||
String varName = varDecl.getVarName();
|
||||
Variable lValue;
|
||||
if(varType != null) {
|
||||
VariableBuilder varBuilder = new VariableBuilder(varName, blockScope, false, false, varType, varDecl.getDeclDirectives(), currentDataSegment, program.getTargetPlatform().getVariableBuilderConfig());
|
||||
VariableBuilder varBuilder = new VariableBuilder(varName, blockScope, false, false, varType, varDecl.getDeclDirectives(), currentSegmentData, program.getTargetPlatform().getVariableBuilderConfig());
|
||||
lValue = varBuilder.build();
|
||||
} else {
|
||||
lValue = getCurrentScope().findVariable(varName);
|
||||
@ -2067,7 +2066,7 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
|
||||
while(parentScope instanceof StructDefinition || parentScope instanceof TypeDefsScope)
|
||||
parentScope = parentScope.getScope();
|
||||
for(Variable member : enumDefinition.getAllConstants(false)) {
|
||||
parentScope.add(Variable.createConstant(member.getLocalName(), SymbolType.BYTE, parentScope, member.getInitValue(), currentDataSegment));
|
||||
parentScope.add(Variable.createConstant(member.getLocalName(), SymbolType.BYTE, parentScope, member.getInitValue(), currentSegmentData));
|
||||
}
|
||||
varDecl.setDeclType(SymbolType.BYTE);
|
||||
return null;
|
||||
@ -2102,7 +2101,7 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
|
||||
}
|
||||
}
|
||||
}
|
||||
currentEnum.add(Variable.createConstant(memberName, SymbolType.BYTE, getCurrentScope(), enumValue, currentDataSegment));
|
||||
currentEnum.add(Variable.createConstant(memberName, SymbolType.BYTE, getCurrentScope(), enumValue, currentSegmentData));
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -2284,7 +2283,7 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
|
||||
this.visit(ctx.declType());
|
||||
this.visit(ctx.declarator());
|
||||
String typedefName = varDecl.getVarName();
|
||||
VariableBuilder varBuilder = new VariableBuilder(typedefName, getCurrentScope(), false, false, varDecl.getEffectiveType(), varDecl.getDeclDirectives(), currentDataSegment, program.getTargetPlatform().getVariableBuilderConfig());
|
||||
VariableBuilder varBuilder = new VariableBuilder(typedefName, getCurrentScope(), false, false, varDecl.getEffectiveType(), varDecl.getDeclDirectives(), currentSegmentData, program.getTargetPlatform().getVariableBuilderConfig());
|
||||
varBuilder.build();
|
||||
scopeStack.pop();
|
||||
varDecl.exitType();
|
||||
|
@ -582,7 +582,7 @@ public class Pass4CodeGeneration {
|
||||
// Set segment
|
||||
// We check first the bank of the variable. Only local variables can be stored in the bank.
|
||||
// Parameters must be stored in main memory.
|
||||
if(!variable.getDataSegment().equals("Data")) {
|
||||
if(!variable.getDataSegment().equals(Scope.SEGMENT_DATA_DEFAULT)) {
|
||||
if(scope instanceof Procedure) {
|
||||
Procedure procedure = (Procedure) scope;
|
||||
List<Variable> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user