mirror of
https://gitlab.com/camelot/kickc.git
synced 2024-12-30 15:31:17 +00:00
Added STACK parameter push. #316
This commit is contained in:
parent
dfcc4beab2
commit
4ed3621d9e
1
src/main/fragment/mos6502-common/_pushbyte_=vbuaa.asm
Normal file
1
src/main/fragment/mos6502-common/_pushbyte_=vbuaa.asm
Normal file
@ -0,0 +1 @@
|
||||
pha
|
@ -359,6 +359,8 @@ public class AsmFragmentInstanceSpecFactory {
|
||||
} else if(value instanceof ParamStackValue) {
|
||||
// TODO: Handle different parameter types!
|
||||
return "_stackbyte_"+bind(((ParamStackValue) value).getStackOffset());
|
||||
} else if(value instanceof ParamStackPush) {
|
||||
return "_push"+((ParamStackPush) value).getType().getTypeName()+"_";
|
||||
}
|
||||
throw new RuntimeException("Binding of value type not supported " + value.toString(program));
|
||||
}
|
||||
|
@ -0,0 +1,24 @@
|
||||
package dk.camelot64.kickc.model.values;
|
||||
|
||||
import dk.camelot64.kickc.model.Program;
|
||||
import dk.camelot64.kickc.model.types.SymbolType;
|
||||
|
||||
/** A value pushed to the stack. */
|
||||
public class ParamStackPush implements LValue {
|
||||
|
||||
/** The type of value being pushed. */
|
||||
private SymbolType type;
|
||||
|
||||
public ParamStackPush(SymbolType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public SymbolType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(Program program) {
|
||||
return "paramstackpush(" + type.getTypeName()+ ")";
|
||||
}
|
||||
}
|
@ -734,16 +734,30 @@ public class Pass4CodeGeneration {
|
||||
generateAsm(asm, asmFragmentInstanceSpecFactory);
|
||||
} else if(statement instanceof StatementCall) {
|
||||
StatementCall call = (StatementCall) statement;
|
||||
if(genCallPhiEntry) {
|
||||
ControlFlowBlock callSuccessor = getGraph().getCallSuccessor(block);
|
||||
if(callSuccessor != null && callSuccessor.hasPhiBlock()) {
|
||||
PhiTransitions.PhiTransition transition = getTransitions(callSuccessor).getTransition(block);
|
||||
if(transitionIsGenerated(transition)) {
|
||||
throw new InternalError("Error! JSR transition already generated. Must modify PhiTransitions code to ensure this does not happen.");
|
||||
|
||||
Procedure procedure = getScope().getProcedure(call.getProcedure());
|
||||
if(Procedure.CallingConvension.PHI_CALL.equals(procedure.getCallingConvension())) {
|
||||
// Generate PHI transition
|
||||
if(genCallPhiEntry) {
|
||||
ControlFlowBlock callSuccessor = getGraph().getCallSuccessor(block);
|
||||
if(callSuccessor != null && callSuccessor.hasPhiBlock()) {
|
||||
PhiTransitions.PhiTransition transition = getTransitions(callSuccessor).getTransition(block);
|
||||
if(transitionIsGenerated(transition)) {
|
||||
throw new InternalError("Error! JSR transition already generated. Must modify PhiTransitions code to ensure this does not happen.");
|
||||
}
|
||||
genBlockPhiTransition(asm, block, callSuccessor, block.getScope());
|
||||
}
|
||||
genBlockPhiTransition(asm, block, callSuccessor, block.getScope());
|
||||
}
|
||||
} else if(Procedure.CallingConvension.STACK_CALL.equals(procedure.getCallingConvension())) {
|
||||
// Push parameters to the stack
|
||||
for(RValue parameter : call.getParameters()) {
|
||||
SymbolType parameterType = SymbolTypeInference.inferType(program.getScope(), parameter);
|
||||
AsmFragmentInstanceSpecFactory asmFragmentInstanceSpecFactory = new AsmFragmentInstanceSpecFactory(new ParamStackPush(parameterType), parameter, program, block.getScope());
|
||||
ensureEncoding(asm, asmFragmentInstanceSpecFactory);
|
||||
generateAsm(asm, asmFragmentInstanceSpecFactory);
|
||||
}
|
||||
}
|
||||
|
||||
asm.addInstruction("jsr", AsmAddressingMode.ABS, call.getProcedure().getFullName(), false);
|
||||
} else if(statement instanceof StatementReturn) {
|
||||
Procedure.InterruptType interruptType = null;
|
||||
|
@ -31,9 +31,11 @@ public class PassNCallingConventionStack extends Pass2SsaOptimization {
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: Add global STACK_BASE constant
|
||||
|
||||
if(offsetConstants.size() > 0) {
|
||||
// Add global STACK_BASE constant
|
||||
long STACK_BASE = 0x103L;
|
||||
getScope().add(new ConstantVar("STACK_BASE", getScope(), SymbolType.WORD, new ConstantInteger(STACK_BASE, SymbolType.WORD), Scope.SEGMENT_DATA_DEFAULT));
|
||||
|
||||
// Convert ParamValue to ParamStackValue
|
||||
ProgramValueIterator.execute(getGraph(), (programValue, currentStmt, stmtIt, currentBlock) -> {
|
||||
if(programValue.get() instanceof ParamValue) {
|
||||
|
@ -40,12 +40,12 @@ public class TestPrograms {
|
||||
public void testProcedureCallingConventionStack1() throws IOException, URISyntaxException {
|
||||
compileAndCompare("procedure-callingconvention-stack-1", log());
|
||||
}
|
||||
*/
|
||||
|
||||
@Test
|
||||
public void testProcedureCallingConventionStack0() throws IOException, URISyntaxException {
|
||||
compileAndCompare("procedure-callingconvention-stack-0", log().verboseCreateSsa().verboseParse().verboseStatementSequence());
|
||||
}
|
||||
*/
|
||||
|
||||
@Test
|
||||
public void testSignedCharComparison() throws IOException, URISyntaxException {
|
||||
|
Loading…
Reference in New Issue
Block a user