mirror of
https://gitlab.com/camelot/kickc.git
synced 2025-02-04 00:30:43 +00:00
Working on #554 variables used in ASM.
This commit is contained in:
parent
279cc322b7
commit
b1f34e5769
@ -1,4 +1,4 @@
|
||||
//KICKC FRAGMENT CACHE 107d6cfa86 107d6d178e
|
||||
//KICKC FRAGMENT CACHE 10dedb3bb9 10dedb58e1
|
||||
//FRAGMENT vbuz1=vbuc1
|
||||
lda #{c1}
|
||||
sta {z1}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,4 +1,4 @@
|
||||
//KICKC FRAGMENT CACHE 107d6cfa86 107d6d178e
|
||||
//KICKC FRAGMENT CACHE 10dedb3bb9 10dedb58e1
|
||||
//FRAGMENT vbuz1=vbuc1
|
||||
lda #{c1}
|
||||
sta {z1}
|
||||
|
18123
src/main/fragment/cache/fragment-cache-mos6502x.asm
vendored
18123
src/main/fragment/cache/fragment-cache-mos6502x.asm
vendored
File diff suppressed because it is too large
Load Diff
@ -1,4 +1,4 @@
|
||||
//KICKC FRAGMENT CACHE 107d6cfa86 107d6d178e
|
||||
//KICKC FRAGMENT CACHE 10dedb3bb9 10dedb58e1
|
||||
//FRAGMENT vbuz1=_deref_pbuc1
|
||||
lda {c1}
|
||||
sta {z1}
|
||||
|
@ -18,7 +18,6 @@ import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@ -277,6 +276,7 @@ public class Compiler {
|
||||
new PassNAddTypeConversionAssignment(program, true).execute();
|
||||
|
||||
new Pass1EarlyConstantIdentification(program).execute();
|
||||
new Pass1AsmUsesHandling(program).execute();
|
||||
new PassNAssertConstantModification(program).execute();
|
||||
new PassNAssertTypeDeref(program).check();
|
||||
|
||||
|
@ -8,7 +8,10 @@ import dk.camelot64.kickc.model.operators.Operators;
|
||||
import dk.camelot64.kickc.model.symbols.Symbol;
|
||||
import dk.camelot64.kickc.model.symbols.Variable;
|
||||
import dk.camelot64.kickc.model.types.SymbolTypeStruct;
|
||||
import dk.camelot64.kickc.model.values.*;
|
||||
import dk.camelot64.kickc.model.values.ConstantSymbolPointer;
|
||||
import dk.camelot64.kickc.model.values.RValue;
|
||||
import dk.camelot64.kickc.model.values.SymbolVariableRef;
|
||||
import dk.camelot64.kickc.model.values.Value;
|
||||
|
||||
/**
|
||||
* Update variables properly if address-of is used
|
||||
@ -21,6 +24,7 @@ public class Pass1AddressOfHandling extends Pass2SsaOptimization {
|
||||
|
||||
@Override
|
||||
public boolean step() {
|
||||
// Expressions using & operator
|
||||
ProgramExpressionIterator.execute(getProgram(), (programExpression, currentStmt, stmtIt, currentBlock) -> {
|
||||
if(Operators.ADDRESS_OF.equals(programExpression.getOperator())) {
|
||||
RValue rValue = ((ProgramExpressionUnary) programExpression).getOperand();
|
||||
@ -36,13 +40,16 @@ public class Pass1AddressOfHandling extends Pass2SsaOptimization {
|
||||
});
|
||||
ProgramValueIterator.execute(getProgram(), (programValue, currentStmt, stmtIt, currentBlock) -> {
|
||||
if(programValue.get() instanceof ConstantSymbolPointer) {
|
||||
// Values containing constant pointers
|
||||
Value value = ((ConstantSymbolPointer) programValue.get()).getToSymbol();
|
||||
if(value instanceof SymbolVariableRef) {
|
||||
Symbol toSymbol = getScope().getSymbol((SymbolVariableRef) value);
|
||||
if(toSymbol instanceof Variable) {
|
||||
final Variable variable = (Variable) toSymbol;
|
||||
final String stmtStr = currentStmt==null?toSymbol.toString(getProgram()):currentStmt.toString(getProgram(), false);
|
||||
updateAddressOfVariable(variable, stmtStr);
|
||||
if(!variable.isNoModify() && !variable.isVolatile()) {
|
||||
final String stmtStr = currentStmt == null ? toSymbol.toString(getProgram()) : currentStmt.toString(getProgram(), false);
|
||||
updateAddressOfVariable(variable, stmtStr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -54,10 +61,12 @@ public class Pass1AddressOfHandling extends Pass2SsaOptimization {
|
||||
if(variable.getType() instanceof SymbolTypeStruct) {
|
||||
variable.setKind(Variable.Kind.LOAD_STORE);
|
||||
getLog().append("Setting struct to load/store in variable affected by address-of " + stmtStr);
|
||||
//getLog().append("Setting struct to load/store in variable affected by address-of: " + variable.toString() + " in " + stmtStr);
|
||||
} else {
|
||||
variable.setKind(Variable.Kind.LOAD_STORE);
|
||||
variable.setVolatile(true);
|
||||
getLog().append("Setting inferred volatile on symbol affected by address-of " + stmtStr);
|
||||
//getLog().append("Setting inferred volatile on symbol affected by address-of: " + variable.toString() + " in " + stmtStr);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,57 @@
|
||||
package dk.camelot64.kickc.passes;
|
||||
|
||||
import dk.camelot64.kickc.model.Program;
|
||||
import dk.camelot64.kickc.model.iterator.ProgramExpressionIterator;
|
||||
import dk.camelot64.kickc.model.iterator.ProgramExpressionUnary;
|
||||
import dk.camelot64.kickc.model.iterator.ProgramValue;
|
||||
import dk.camelot64.kickc.model.iterator.ProgramValueIterator;
|
||||
import dk.camelot64.kickc.model.operators.Operators;
|
||||
import dk.camelot64.kickc.model.symbols.Symbol;
|
||||
import dk.camelot64.kickc.model.symbols.Variable;
|
||||
import dk.camelot64.kickc.model.types.SymbolTypeStruct;
|
||||
import dk.camelot64.kickc.model.values.ConstantSymbolPointer;
|
||||
import dk.camelot64.kickc.model.values.RValue;
|
||||
import dk.camelot64.kickc.model.values.SymbolVariableRef;
|
||||
import dk.camelot64.kickc.model.values.Value;
|
||||
|
||||
/**
|
||||
* Update variables properly if address-of is used
|
||||
*/
|
||||
public class Pass1AsmUsesHandling extends Pass2SsaOptimization {
|
||||
|
||||
public Pass1AsmUsesHandling(Program program) {
|
||||
super(program);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean step() {
|
||||
|
||||
ProgramValueIterator.execute(getProgram(), (programValue, currentStmt, stmtIt, currentBlock) -> {
|
||||
if(programValue instanceof ProgramValue.ProgramValueAsmReferenced || programValue instanceof ProgramValue.KickAsmUses || programValue instanceof ProgramValue.ProgramValueConstantArrayKickAsmUses) {
|
||||
// Symbol used in inline ASM or KickAsm
|
||||
final Value value = programValue.get();
|
||||
if(value instanceof SymbolVariableRef) {
|
||||
Variable variable = getScope().getVariable((SymbolVariableRef) value);
|
||||
if(!variable.isKindConstant() && !variable.isVolatile()) {
|
||||
final String stmtStr = currentStmt == null ? value.toString(getProgram()) : currentStmt.toString(getProgram(), false);
|
||||
updateAddressOfVariable(variable, stmtStr);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
private void updateAddressOfVariable(Variable variable, String stmtStr) {
|
||||
if(variable.getType() instanceof SymbolTypeStruct) {
|
||||
variable.setKind(Variable.Kind.LOAD_STORE);
|
||||
getLog().append("Setting struct to load/store in variable affected by address-of: " + variable.toString() + " in " + stmtStr);
|
||||
} else {
|
||||
variable.setKind(Variable.Kind.LOAD_STORE);
|
||||
variable.setVolatile(true);
|
||||
getLog().append("Setting inferred volatile on symbol affected by address-of: " + variable.toString() + " in " + stmtStr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -22,7 +22,7 @@ void fn2() {
|
||||
*r = 2;
|
||||
}
|
||||
|
||||
void enableDLI(__ma void *dliptr) {
|
||||
void enableDLI(void *dliptr) {
|
||||
asm {
|
||||
lda #<dliptr
|
||||
sta dlivec
|
||||
|
@ -21,9 +21,9 @@ void main() {
|
||||
// foo(b, a);
|
||||
}
|
||||
|
||||
void foo(__mem uint8_t *x1, uint8_t *x2) {
|
||||
__ma volatile uint8_t * v1;
|
||||
__ma uint8_t * v2;
|
||||
void foo(uint8_t *x1, uint8_t *x2) {
|
||||
uint8_t * v1;
|
||||
uint8_t * v2;
|
||||
uint8_t a1 = 1;
|
||||
uint8_t a2 = 2;
|
||||
v1 = x1;
|
||||
|
Loading…
x
Reference in New Issue
Block a user