mirror of
https://gitlab.com/camelot/kickc.git
synced 2025-02-12 07:31:36 +00:00
Fixed parameter offsets on stack by reversing order.
This commit is contained in:
parent
c3c2999381
commit
c44cb02b96
@ -5,6 +5,9 @@ import dk.camelot64.kickc.model.types.SymbolType;
|
||||
import dk.camelot64.kickc.model.values.ConstantInteger;
|
||||
import dk.camelot64.kickc.model.values.ConstantRef;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
* Utility methods for {@link Procedure.CallingConvention#STACK_CALL}
|
||||
*/
|
||||
@ -94,7 +97,10 @@ public class CallingConventionStack {
|
||||
*/
|
||||
public static long getParameterByteOffset(Procedure procedure, Variable parameter) {
|
||||
long byteOffset = 0;
|
||||
for(Variable procedureParameter : procedure.getParameters()) {
|
||||
ArrayList<Variable> parameters = new ArrayList<>(procedure.getParameters());
|
||||
// Reverse because pushing is done in parameter order
|
||||
Collections.reverse(parameters);
|
||||
for(Variable procedureParameter : parameters) {
|
||||
if(parameter.equals(procedureParameter)) {
|
||||
break;
|
||||
} else {
|
||||
|
@ -37,7 +37,7 @@ public class PassNCallingConventionStack extends Pass2SsaOptimization {
|
||||
createStackBase = true;
|
||||
}
|
||||
// Introduce the return value offset
|
||||
if(procedure.getReturnType() != null) {
|
||||
if(procedure.getReturnType() != null && !SymbolType.VOID.equals(procedure.getReturnType())) {
|
||||
CallingConventionStack.getReturnOffsetConstant(procedure);
|
||||
createStackBase = true;
|
||||
}
|
||||
|
@ -20,8 +20,8 @@ main: {
|
||||
}
|
||||
// plus(byte zp(2) a, byte register(A) b)
|
||||
plus: {
|
||||
.const OFFSET_STACK_A = 0
|
||||
.const OFFSET_STACK_B = 1
|
||||
.const OFFSET_STACK_A = 1
|
||||
.const OFFSET_STACK_B = 0
|
||||
.const OFFSET_STACK_RETURN = 1
|
||||
.label a = 2
|
||||
tsx
|
||||
|
@ -205,8 +205,8 @@ main: {
|
||||
// plus
|
||||
// plus(byte zp(3) a, byte zp(4) b)
|
||||
plus: {
|
||||
.const OFFSET_STACK_A = 0
|
||||
.const OFFSET_STACK_B = 1
|
||||
.const OFFSET_STACK_A = 1
|
||||
.const OFFSET_STACK_B = 0
|
||||
.const OFFSET_STACK_RETURN = 1
|
||||
.label a = 3
|
||||
.label b = 4
|
||||
@ -322,8 +322,8 @@ main: {
|
||||
// plus
|
||||
// plus(byte zp(2) a, byte register(A) b)
|
||||
plus: {
|
||||
.const OFFSET_STACK_A = 0
|
||||
.const OFFSET_STACK_B = 1
|
||||
.const OFFSET_STACK_A = 1
|
||||
.const OFFSET_STACK_B = 0
|
||||
.const OFFSET_STACK_RETURN = 1
|
||||
.label a = 2
|
||||
// [10] (byte) plus::a#0 ← stackidx(byte,(const byte) plus::OFFSET_STACK_A) -- vbuz1=_stackidxbyte_vbuc1
|
||||
@ -380,8 +380,8 @@ FINAL SYMBOL TABLE
|
||||
(label) main::@return
|
||||
__stackcall (byte()) plus((byte) plus::a , (byte) plus::b)
|
||||
(label) plus::@return
|
||||
(const byte) plus::OFFSET_STACK_A = (byte) 0
|
||||
(const byte) plus::OFFSET_STACK_B = (byte) 1
|
||||
(const byte) plus::OFFSET_STACK_A = (byte) 1
|
||||
(const byte) plus::OFFSET_STACK_B = (byte) 0
|
||||
(const byte) plus::OFFSET_STACK_RETURN = (byte) 1
|
||||
(byte) plus::a
|
||||
(byte) plus::a#0 a zp[1]:2 2.0
|
||||
@ -444,8 +444,8 @@ main: {
|
||||
// plus
|
||||
// plus(byte zp(2) a, byte register(A) b)
|
||||
plus: {
|
||||
.const OFFSET_STACK_A = 0
|
||||
.const OFFSET_STACK_B = 1
|
||||
.const OFFSET_STACK_A = 1
|
||||
.const OFFSET_STACK_B = 0
|
||||
.const OFFSET_STACK_RETURN = 1
|
||||
.label a = 2
|
||||
// [10] (byte) plus::a#0 ← stackidx(byte,(const byte) plus::OFFSET_STACK_A) -- vbuz1=_stackidxbyte_vbuc1
|
||||
|
@ -8,8 +8,8 @@
|
||||
(label) main::@return
|
||||
__stackcall (byte()) plus((byte) plus::a , (byte) plus::b)
|
||||
(label) plus::@return
|
||||
(const byte) plus::OFFSET_STACK_A = (byte) 0
|
||||
(const byte) plus::OFFSET_STACK_B = (byte) 1
|
||||
(const byte) plus::OFFSET_STACK_A = (byte) 1
|
||||
(const byte) plus::OFFSET_STACK_B = (byte) 0
|
||||
(const byte) plus::OFFSET_STACK_RETURN = (byte) 1
|
||||
(byte) plus::a
|
||||
(byte) plus::a#0 a zp[1]:2 2.0
|
||||
|
@ -20,8 +20,8 @@ main: {
|
||||
}
|
||||
// plus(byte zp(2) a, byte register(A) b)
|
||||
plus: {
|
||||
.const OFFSET_STACK_A = 0
|
||||
.const OFFSET_STACK_B = 1
|
||||
.const OFFSET_STACK_A = 1
|
||||
.const OFFSET_STACK_B = 0
|
||||
.const OFFSET_STACK_RETURN = 1
|
||||
.label a = 2
|
||||
tsx
|
||||
|
@ -205,8 +205,8 @@ main: {
|
||||
// plus
|
||||
// plus(byte zp(3) a, byte zp(4) b)
|
||||
plus: {
|
||||
.const OFFSET_STACK_A = 0
|
||||
.const OFFSET_STACK_B = 1
|
||||
.const OFFSET_STACK_A = 1
|
||||
.const OFFSET_STACK_B = 0
|
||||
.const OFFSET_STACK_RETURN = 1
|
||||
.label a = 3
|
||||
.label b = 4
|
||||
@ -322,8 +322,8 @@ main: {
|
||||
// plus
|
||||
// plus(byte zp(2) a, byte register(A) b)
|
||||
plus: {
|
||||
.const OFFSET_STACK_A = 0
|
||||
.const OFFSET_STACK_B = 1
|
||||
.const OFFSET_STACK_A = 1
|
||||
.const OFFSET_STACK_B = 0
|
||||
.const OFFSET_STACK_RETURN = 1
|
||||
.label a = 2
|
||||
// [10] (byte) plus::a#0 ← stackidx(byte,(const byte) plus::OFFSET_STACK_A) -- vbuz1=_stackidxbyte_vbuc1
|
||||
@ -380,8 +380,8 @@ FINAL SYMBOL TABLE
|
||||
(label) main::@return
|
||||
__stackcall (byte()) plus((byte) plus::a , (byte) plus::b)
|
||||
(label) plus::@return
|
||||
(const byte) plus::OFFSET_STACK_A = (byte) 0
|
||||
(const byte) plus::OFFSET_STACK_B = (byte) 1
|
||||
(const byte) plus::OFFSET_STACK_A = (byte) 1
|
||||
(const byte) plus::OFFSET_STACK_B = (byte) 0
|
||||
(const byte) plus::OFFSET_STACK_RETURN = (byte) 1
|
||||
(byte) plus::a
|
||||
(byte) plus::a#0 a zp[1]:2 2.0
|
||||
@ -444,8 +444,8 @@ main: {
|
||||
// plus
|
||||
// plus(byte zp(2) a, byte register(A) b)
|
||||
plus: {
|
||||
.const OFFSET_STACK_A = 0
|
||||
.const OFFSET_STACK_B = 1
|
||||
.const OFFSET_STACK_A = 1
|
||||
.const OFFSET_STACK_B = 0
|
||||
.const OFFSET_STACK_RETURN = 1
|
||||
.label a = 2
|
||||
// [10] (byte) plus::a#0 ← stackidx(byte,(const byte) plus::OFFSET_STACK_A) -- vbuz1=_stackidxbyte_vbuc1
|
||||
|
@ -8,8 +8,8 @@
|
||||
(label) main::@return
|
||||
__stackcall (byte()) plus((byte) plus::a , (byte) plus::b)
|
||||
(label) plus::@return
|
||||
(const byte) plus::OFFSET_STACK_A = (byte) 0
|
||||
(const byte) plus::OFFSET_STACK_B = (byte) 1
|
||||
(const byte) plus::OFFSET_STACK_A = (byte) 1
|
||||
(const byte) plus::OFFSET_STACK_B = (byte) 0
|
||||
(const byte) plus::OFFSET_STACK_RETURN = (byte) 1
|
||||
(byte) plus::a
|
||||
(byte) plus::a#0 a zp[1]:2 2.0
|
||||
|
@ -32,8 +32,8 @@ main: {
|
||||
}
|
||||
// plus(word zp(2) a, word zp(4) b)
|
||||
plus: {
|
||||
.const OFFSET_STACK_A = 0
|
||||
.const OFFSET_STACK_B = 2
|
||||
.const OFFSET_STACK_A = 2
|
||||
.const OFFSET_STACK_B = 0
|
||||
.const OFFSET_STACK_RETURN = 2
|
||||
.label a = 2
|
||||
.label b = 4
|
||||
|
@ -232,8 +232,8 @@ main: {
|
||||
// plus
|
||||
// plus(word zp(4) a, word zp(6) b)
|
||||
plus: {
|
||||
.const OFFSET_STACK_A = 0
|
||||
.const OFFSET_STACK_B = 2
|
||||
.const OFFSET_STACK_A = 2
|
||||
.const OFFSET_STACK_B = 0
|
||||
.const OFFSET_STACK_RETURN = 2
|
||||
.label a = 4
|
||||
.label b = 6
|
||||
@ -364,8 +364,8 @@ main: {
|
||||
// plus
|
||||
// plus(word zp(2) a, word zp(4) b)
|
||||
plus: {
|
||||
.const OFFSET_STACK_A = 0
|
||||
.const OFFSET_STACK_B = 2
|
||||
.const OFFSET_STACK_A = 2
|
||||
.const OFFSET_STACK_B = 0
|
||||
.const OFFSET_STACK_RETURN = 2
|
||||
.label a = 2
|
||||
.label b = 4
|
||||
@ -437,8 +437,8 @@ FINAL SYMBOL TABLE
|
||||
(label) main::@return
|
||||
__stackcall (word()) plus((word) plus::a , (word) plus::b)
|
||||
(label) plus::@return
|
||||
(const byte) plus::OFFSET_STACK_A = (byte) 0
|
||||
(const byte) plus::OFFSET_STACK_B = (byte) 2
|
||||
(const byte) plus::OFFSET_STACK_A = (byte) 2
|
||||
(const byte) plus::OFFSET_STACK_B = (byte) 0
|
||||
(const byte) plus::OFFSET_STACK_RETURN = (byte) 2
|
||||
(word) plus::a
|
||||
(word) plus::a#0 a zp[2]:2 2.0
|
||||
@ -511,8 +511,8 @@ main: {
|
||||
// plus
|
||||
// plus(word zp(2) a, word zp(4) b)
|
||||
plus: {
|
||||
.const OFFSET_STACK_A = 0
|
||||
.const OFFSET_STACK_B = 2
|
||||
.const OFFSET_STACK_A = 2
|
||||
.const OFFSET_STACK_B = 0
|
||||
.const OFFSET_STACK_RETURN = 2
|
||||
.label a = 2
|
||||
.label b = 4
|
||||
|
@ -8,8 +8,8 @@
|
||||
(label) main::@return
|
||||
__stackcall (word()) plus((word) plus::a , (word) plus::b)
|
||||
(label) plus::@return
|
||||
(const byte) plus::OFFSET_STACK_A = (byte) 0
|
||||
(const byte) plus::OFFSET_STACK_B = (byte) 2
|
||||
(const byte) plus::OFFSET_STACK_A = (byte) 2
|
||||
(const byte) plus::OFFSET_STACK_B = (byte) 0
|
||||
(const byte) plus::OFFSET_STACK_RETURN = (byte) 2
|
||||
(word) plus::a
|
||||
(word) plus::a#0 a zp[2]:2 2.0
|
||||
|
@ -35,8 +35,8 @@ main: {
|
||||
}
|
||||
// plus(word zp(2) a, word zp(4) b)
|
||||
plus: {
|
||||
.const OFFSET_STACK_A = 0
|
||||
.const OFFSET_STACK_B = 2
|
||||
.const OFFSET_STACK_A = 2
|
||||
.const OFFSET_STACK_B = 0
|
||||
.const OFFSET_STACK_RETURN = 2
|
||||
.label a = 2
|
||||
.label b = 4
|
||||
|
@ -232,8 +232,8 @@ main: {
|
||||
// plus
|
||||
// plus(word zp(4) a, word zp(6) b)
|
||||
plus: {
|
||||
.const OFFSET_STACK_A = 0
|
||||
.const OFFSET_STACK_B = 2
|
||||
.const OFFSET_STACK_A = 2
|
||||
.const OFFSET_STACK_B = 0
|
||||
.const OFFSET_STACK_RETURN = 2
|
||||
.label a = 4
|
||||
.label b = 6
|
||||
@ -367,8 +367,8 @@ main: {
|
||||
// plus
|
||||
// plus(word zp(2) a, word zp(4) b)
|
||||
plus: {
|
||||
.const OFFSET_STACK_A = 0
|
||||
.const OFFSET_STACK_B = 2
|
||||
.const OFFSET_STACK_A = 2
|
||||
.const OFFSET_STACK_B = 0
|
||||
.const OFFSET_STACK_RETURN = 2
|
||||
.label a = 2
|
||||
.label b = 4
|
||||
@ -440,8 +440,8 @@ FINAL SYMBOL TABLE
|
||||
(label) main::@return
|
||||
__stackcall (word()) plus((word) plus::a , (word) plus::b)
|
||||
(label) plus::@return
|
||||
(const byte) plus::OFFSET_STACK_A = (byte) 0
|
||||
(const byte) plus::OFFSET_STACK_B = (byte) 2
|
||||
(const byte) plus::OFFSET_STACK_A = (byte) 2
|
||||
(const byte) plus::OFFSET_STACK_B = (byte) 0
|
||||
(const byte) plus::OFFSET_STACK_RETURN = (byte) 2
|
||||
(word) plus::a
|
||||
(word) plus::a#0 a zp[2]:2 2.0
|
||||
@ -517,8 +517,8 @@ main: {
|
||||
// plus
|
||||
// plus(word zp(2) a, word zp(4) b)
|
||||
plus: {
|
||||
.const OFFSET_STACK_A = 0
|
||||
.const OFFSET_STACK_B = 2
|
||||
.const OFFSET_STACK_A = 2
|
||||
.const OFFSET_STACK_B = 0
|
||||
.const OFFSET_STACK_RETURN = 2
|
||||
.label a = 2
|
||||
.label b = 4
|
||||
|
@ -8,8 +8,8 @@
|
||||
(label) main::@return
|
||||
__stackcall (word()) plus((word) plus::a , (word) plus::b)
|
||||
(label) plus::@return
|
||||
(const byte) plus::OFFSET_STACK_A = (byte) 0
|
||||
(const byte) plus::OFFSET_STACK_B = (byte) 2
|
||||
(const byte) plus::OFFSET_STACK_A = (byte) 2
|
||||
(const byte) plus::OFFSET_STACK_B = (byte) 0
|
||||
(const byte) plus::OFFSET_STACK_RETURN = (byte) 2
|
||||
(word) plus::a
|
||||
(word) plus::a#0 a zp[2]:2 2.0
|
||||
|
@ -35,8 +35,8 @@ main: {
|
||||
}
|
||||
// plus(byte zp(2) a, byte register(A) b)
|
||||
plus: {
|
||||
.const OFFSET_STACK_A = 0
|
||||
.const OFFSET_STACK_B = 1
|
||||
.const OFFSET_STACK_A = 1
|
||||
.const OFFSET_STACK_B = 0
|
||||
.const OFFSET_STACK_RETURN = 1
|
||||
.label a = 2
|
||||
tsx
|
||||
|
@ -337,8 +337,8 @@ main: {
|
||||
// plus
|
||||
// plus(byte zp(6) a, byte zp(7) b)
|
||||
plus: {
|
||||
.const OFFSET_STACK_A = 0
|
||||
.const OFFSET_STACK_B = 1
|
||||
.const OFFSET_STACK_A = 1
|
||||
.const OFFSET_STACK_B = 0
|
||||
.const OFFSET_STACK_RETURN = 1
|
||||
.label a = 6
|
||||
.label b = 7
|
||||
@ -487,8 +487,8 @@ main: {
|
||||
// plus
|
||||
// plus(byte zp(2) a, byte register(A) b)
|
||||
plus: {
|
||||
.const OFFSET_STACK_A = 0
|
||||
.const OFFSET_STACK_B = 1
|
||||
.const OFFSET_STACK_A = 1
|
||||
.const OFFSET_STACK_B = 0
|
||||
.const OFFSET_STACK_RETURN = 1
|
||||
.label a = 2
|
||||
// [15] (byte) plus::a#0 ← stackidx(byte,(const byte) plus::OFFSET_STACK_A) -- vbuz1=_stackidxbyte_vbuc1
|
||||
@ -560,8 +560,8 @@ FINAL SYMBOL TABLE
|
||||
(byte) main::w#0 reg byte a 11.0
|
||||
__stackcall (byte()) plus((byte) plus::a , (byte) plus::b)
|
||||
(label) plus::@return
|
||||
(const byte) plus::OFFSET_STACK_A = (byte) 0
|
||||
(const byte) plus::OFFSET_STACK_B = (byte) 1
|
||||
(const byte) plus::OFFSET_STACK_A = (byte) 1
|
||||
(const byte) plus::OFFSET_STACK_B = (byte) 0
|
||||
(const byte) plus::OFFSET_STACK_RETURN = (byte) 1
|
||||
(byte) plus::a
|
||||
(byte) plus::a#0 a zp[1]:2 2.0
|
||||
@ -651,8 +651,8 @@ main: {
|
||||
// plus
|
||||
// plus(byte zp(2) a, byte register(A) b)
|
||||
plus: {
|
||||
.const OFFSET_STACK_A = 0
|
||||
.const OFFSET_STACK_B = 1
|
||||
.const OFFSET_STACK_A = 1
|
||||
.const OFFSET_STACK_B = 0
|
||||
.const OFFSET_STACK_RETURN = 1
|
||||
.label a = 2
|
||||
// [15] (byte) plus::a#0 ← stackidx(byte,(const byte) plus::OFFSET_STACK_A) -- vbuz1=_stackidxbyte_vbuc1
|
||||
|
@ -17,8 +17,8 @@
|
||||
(byte) main::w#0 reg byte a 11.0
|
||||
__stackcall (byte()) plus((byte) plus::a , (byte) plus::b)
|
||||
(label) plus::@return
|
||||
(const byte) plus::OFFSET_STACK_A = (byte) 0
|
||||
(const byte) plus::OFFSET_STACK_B = (byte) 1
|
||||
(const byte) plus::OFFSET_STACK_A = (byte) 1
|
||||
(const byte) plus::OFFSET_STACK_B = (byte) 0
|
||||
(const byte) plus::OFFSET_STACK_RETURN = (byte) 1
|
||||
(byte) plus::a
|
||||
(byte) plus::a#0 a zp[1]:2 2.0
|
||||
|
Loading…
x
Reference in New Issue
Block a user