Fix: Arguments that don't fit into registeres are passed in the incorrect order
This commit is contained in:
@@ -222,14 +222,15 @@ public class GenASM implements Visitor<Void> {
|
|||||||
this.env = new HashMap<String, Integer>();
|
this.env = new HashMap<String, Integer>();
|
||||||
|
|
||||||
// Merke dir die offsets der parameter, die direkt auf den stack gelegt wurden
|
// Merke dir die offsets der parameter, die direkt auf den stack gelegt wurden
|
||||||
int m = e.parameters.length - this.rs.length;
|
int offset = 16; // Per Stack übergebene Parameter liegen über unserm BSP
|
||||||
|
// Per stack übergebene variablen in env registrieren
|
||||||
for (int i = this.rs.length; i < e.parameters.length; i++) {
|
for (int i = this.rs.length; i < e.parameters.length; i++) {
|
||||||
int j = i - this.rs.length;
|
env.put(e.parameters[i], offset);
|
||||||
this.env.put(e.parameters[i], (((m - j) + 1) * 8)); // positiv, liegt über unserem stack frame
|
offset += 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
// pushe die aufrufparameter aus den Registern wieder auf den Stack
|
// pushe die aufrufparameter aus den Registern wieder auf den Stack
|
||||||
int offset = 0;
|
offset = 0;
|
||||||
for (int i = 0; i < Math.min(this.rs.length, e.parameters.length); i++) {
|
for (int i = 0; i < Math.min(this.rs.length, e.parameters.length); i++) {
|
||||||
this.ex.write(" pushq " + this.rs[i] + "\n");
|
this.ex.write(" pushq " + this.rs[i] + "\n");
|
||||||
offset -= 8;
|
offset -= 8;
|
||||||
@@ -256,7 +257,7 @@ public class GenASM implements Visitor<Void> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Den Rest auf den stack pushen
|
// Den Rest auf den stack pushen
|
||||||
for (int i = this.rs.length; i < e.arguments.length; i++) {
|
for (int i = e.arguments.length -1; i >= this.rs.length; i--) {
|
||||||
e.arguments[i].welcome(this);
|
e.arguments[i].welcome(this);
|
||||||
this.ex.write(" pushq %rax\n");
|
this.ex.write(" pushq %rax\n");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ int argumentTest(char* name, int expected, int result) {
|
|||||||
|
|
||||||
int runFunctionCallTests () {
|
int runFunctionCallTests () {
|
||||||
int failed = 0;
|
int failed = 0;
|
||||||
printf("\nFunctionCallTests Tests \n");
|
printf("\nFunction Call Tests \n");
|
||||||
// Checks that parameters are correctly passed from gcc to functions
|
// Checks that parameters are correctly passed from gcc to functions
|
||||||
failed += argumentTest("arg1", 1, arg1(1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
|
failed += argumentTest("arg1", 1, arg1(1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
|
||||||
failed += argumentTest("arg2", 2, arg2(1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
|
failed += argumentTest("arg2", 2, arg2(1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ int main(){
|
|||||||
failed += testOneArg("id", cId, id, -1);
|
failed += testOneArg("id", cId, id, -1);
|
||||||
failed += testOneArg("id", cId, id, 15);
|
failed += testOneArg("id", cId, id, 15);
|
||||||
|
|
||||||
printf("\nFunction Argument Tests\n");
|
// Test for passing arguments to functions
|
||||||
failed += runFunctionCallTests();
|
failed += runFunctionCallTests();
|
||||||
|
|
||||||
printf("\n=== Failed Tests: %d\n", failed);
|
printf("\n=== Failed Tests: %d\n", failed);
|
||||||
|
|||||||
Reference in New Issue
Block a user