From e1e17f61522316841e9251c442a6778b14b7ea45 Mon Sep 17 00:00:00 2001 From: jespergravgaard Date: Wed, 26 Feb 2020 11:44:15 +0100 Subject: [PATCH] Fixed type inference for StackIdxValue. Added a few missing stack fragments for __stackcall with pointers. --- src/main/fragment/mos6502-common/_stackpushptr_=vwuc1.asm | 4 ++++ src/main/fragment/mos6502-common/_stackpushptr_=vwum1.asm | 4 ++++ .../fragment/mos6502-common/pbum1=_stackidxptr_vbuc1.asm | 5 +++++ src/main/java/dk/camelot64/kickc/model/ControlFlowGraph.java | 2 +- .../dk/camelot64/kickc/model/types/SymbolTypeInference.java | 2 +- .../dk/camelot64/kickc/passes/Pass1AssertNoRecursion.java | 2 +- 6 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 src/main/fragment/mos6502-common/_stackpushptr_=vwuc1.asm create mode 100644 src/main/fragment/mos6502-common/_stackpushptr_=vwum1.asm create mode 100644 src/main/fragment/mos6502-common/pbum1=_stackidxptr_vbuc1.asm diff --git a/src/main/fragment/mos6502-common/_stackpushptr_=vwuc1.asm b/src/main/fragment/mos6502-common/_stackpushptr_=vwuc1.asm new file mode 100644 index 000000000..aea37787e --- /dev/null +++ b/src/main/fragment/mos6502-common/_stackpushptr_=vwuc1.asm @@ -0,0 +1,4 @@ +lda #>{c1} +pha +lda #<{c1} +pha diff --git a/src/main/fragment/mos6502-common/_stackpushptr_=vwum1.asm b/src/main/fragment/mos6502-common/_stackpushptr_=vwum1.asm new file mode 100644 index 000000000..63b51bce2 --- /dev/null +++ b/src/main/fragment/mos6502-common/_stackpushptr_=vwum1.asm @@ -0,0 +1,4 @@ +lda {m1}+1 +pha +lda {m1} +pha diff --git a/src/main/fragment/mos6502-common/pbum1=_stackidxptr_vbuc1.asm b/src/main/fragment/mos6502-common/pbum1=_stackidxptr_vbuc1.asm new file mode 100644 index 000000000..fb56042f3 --- /dev/null +++ b/src/main/fragment/mos6502-common/pbum1=_stackidxptr_vbuc1.asm @@ -0,0 +1,5 @@ +tsx +lda STACK_BASE+{c1},x +sta {m1} +lda STACK_BASE+{c1}+1,x +sta {m1}+1 diff --git a/src/main/java/dk/camelot64/kickc/model/ControlFlowGraph.java b/src/main/java/dk/camelot64/kickc/model/ControlFlowGraph.java index f9d642720..886371380 100644 --- a/src/main/java/dk/camelot64/kickc/model/ControlFlowGraph.java +++ b/src/main/java/dk/camelot64/kickc/model/ControlFlowGraph.java @@ -141,7 +141,7 @@ public class ControlFlowGraph implements Serializable { public List getEntryPointBlocks(Program program) { List entryPointBlocks = new ArrayList<>(); for(Procedure procedure : program.getScope().getAllProcedures(true)) { - if(Pass2ConstantIdentification.isAddressOfUsed(procedure.getRef(), program) || procedure.getCallingConvension().equals(Procedure.CallingConvension.STACK_CALL)) { + if(Pass2ConstantIdentification.isAddressOfUsed(procedure.getRef(), program) || Procedure.CallingConvension.STACK_CALL.equals(procedure.getCallingConvension())) { // Address-of is used on the procedure Label procedureLabel = procedure.getLabel(); ControlFlowBlock procedureBlock = getBlock(procedureLabel.getRef()); diff --git a/src/main/java/dk/camelot64/kickc/model/types/SymbolTypeInference.java b/src/main/java/dk/camelot64/kickc/model/types/SymbolTypeInference.java index bb416c71e..5887408d8 100644 --- a/src/main/java/dk/camelot64/kickc/model/types/SymbolTypeInference.java +++ b/src/main/java/dk/camelot64/kickc/model/types/SymbolTypeInference.java @@ -114,7 +114,7 @@ public class SymbolTypeInference { } else if(rValue instanceof ParamValue) { return inferType(symbols, ((ParamValue) rValue).getParameter()); } else if(rValue instanceof StackIdxValue) { - return SymbolType.BYTE; + return ((StackIdxValue) rValue).getValueType(); } else if(rValue instanceof MemsetValue) { return ((MemsetValue) rValue).getType(); } else if(rValue instanceof MemcpyValue) { diff --git a/src/main/java/dk/camelot64/kickc/passes/Pass1AssertNoRecursion.java b/src/main/java/dk/camelot64/kickc/passes/Pass1AssertNoRecursion.java index 85dc3da2e..b75229f90 100644 --- a/src/main/java/dk/camelot64/kickc/passes/Pass1AssertNoRecursion.java +++ b/src/main/java/dk/camelot64/kickc/passes/Pass1AssertNoRecursion.java @@ -21,7 +21,7 @@ public class Pass1AssertNoRecursion extends Pass1Base { Collection procedures = getScope().getAllProcedures(true); for(Procedure procedure : procedures) { Collection recursiveCalls = callGraph.getRecursiveCalls(procedure.getRef()); - if(recursiveCalls.contains(procedure.getRef()) && !procedure.getCallingConvension().equals(Procedure.CallingConvension.STACK_CALL)) { + if(recursiveCalls.contains(procedure.getRef()) && !Procedure.CallingConvension.STACK_CALL.equals(procedure.getCallingConvension())) { throw new CompileError("ERROR! Recursion not allowed! Occurs in " + procedure.getRef()); } }