1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-06-03 07:29:37 +00:00

- Added comments and restructured the code in the compiler for constant references in asm fragments placed in inline function scopes.

This commit is contained in:
Flight_Control 2023-03-21 06:53:20 +01:00
parent 152832fd4e
commit 64d30faf9c

View File

@ -909,11 +909,45 @@ public class Pass4CodeGeneration {
}
}
}
/* author: sven.van.de.velde@telenet.be - 2023-03-21
The following logic ensures that inlined asm{} blocks placed in inline functions()
are replacing the used C constants or variables with the inlined version
of these C constants or variables.
During pass1, in the functions inlineStatement() and execute() in the Pass1ProcedureInline.c,
the asm fragment gets scanned for referenced constants or variables and the
referenced constant names get updated with the modified inlined referenced constant names.
These modified reference names are then used here in the asm generation, to scan the asm fragment,
of which the source is the bare, parsed antlr source, and really directly in the cut/pasted source
search for any constant or variable in operand1 and replace with the inlined reference
constant or variable name using the Operand1 structure.
This is the only pragmatic way I saw possible.
However, this section gets called during coalescing many, many times and
slows the compiler. However, such solution requires a complete redesign and cannot
just be put in scope to add this fix. So I hope that this change is acceptable.
*/
for (AsmLine asmLine : currentChunk.getLines()) {
if (asmLine instanceof AsmInstruction) {
AsmInstruction asmInstruction = (AsmInstruction) asmLine;
Map<String, SymbolRef> referenced = statementAsm.getReferenced();
for(String reference : referenced.keySet()) {
String operand = asmInstruction.getOperand1();
if(operand != null) {
String replace = referenced.get(reference).getLocalName();
if(operand.startsWith(replace)) {
} else {
operand = operand.replaceAll(reference, replace);
asmInstruction.setOperand1(operand);
}
}
}
}
}
} else if (statement instanceof StatementKickAsm) {
StatementKickAsm statementKasm = (StatementKickAsm) statement;
addKickAsm(asm, statementKasm);
AsmChunk currentChunk = asm.getCurrentChunk();
if (statementKasm.getDeclaredClobber() != null) {
asm.getCurrentChunk().setClobberOverwrite(statementKasm.getDeclaredClobber());
currentChunk.setClobberOverwrite(statementKasm.getDeclaredClobber());
}
} else if (statement instanceof StatementCallPointer) {
throw new InternalError("Statement not supported " + statement);