Fix incorrect call
operand generation & register "fp" is actually s0
This commit is contained in:
parent
505166d1d6
commit
87fcbd1aa9
3 changed files with 18 additions and 18 deletions
|
@ -16,7 +16,7 @@ public class CodegenImpl implements Codegen {
|
|||
}
|
||||
|
||||
return builder.toString()
|
||||
+ "call " + String.format("%s_%d:\n", main.id, main.numOfArgs);
|
||||
+ "call " + String.format("%s_%d\n", main.id, main.numOfArgs);
|
||||
}
|
||||
|
||||
private String generateLabel() {
|
||||
|
@ -58,7 +58,7 @@ public class CodegenImpl implements Codegen {
|
|||
} else if (e instanceof Variable) {
|
||||
int offset = ((Variable) e).x;
|
||||
|
||||
return String.format("lw a0,%d(fp)\n", offset * 4);
|
||||
return String.format("lw a0,%d(s0)\n", offset * 4);
|
||||
} else if (e instanceof Invoke) {
|
||||
return compileCall((Invoke) e, false);
|
||||
} else if (e instanceof Seq) {
|
||||
|
@ -131,7 +131,7 @@ public class CodegenImpl implements Codegen {
|
|||
Assign assign = (Assign) e;
|
||||
|
||||
return compileExp(assign.e)
|
||||
+ String.format("sw a0,%d(fp)", assign.x * 4);
|
||||
+ String.format("sw a0,%d(s0)", assign.x * 4);
|
||||
} else if (e instanceof Continue) {
|
||||
return "jr s2\n";
|
||||
} else if (e instanceof Break) {
|
||||
|
@ -165,15 +165,15 @@ public class CodegenImpl implements Codegen {
|
|||
}
|
||||
|
||||
// push old frame pointer
|
||||
builder.append("sw fp,-4(sp)\n");
|
||||
builder.append("sw s0,-4(sp)\n");
|
||||
builder.append("addi sp,sp,-8\n");
|
||||
|
||||
builder.append(
|
||||
// set frame pointer to start of arguments
|
||||
"addi fp,sp,8\n"
|
||||
"addi s0,sp,8\n"
|
||||
+ "call " + methodLabel + "\n"
|
||||
// restore old frame pointer & stack pointer
|
||||
+ "lw fp,4(sp)\n"
|
||||
+ "lw s0,4(sp)\n"
|
||||
+ "lw sp,(sp)\n"
|
||||
// restore return address of caller
|
||||
+ "lw ra,-4(sp)\n"
|
||||
|
|
|
@ -16,7 +16,7 @@ public class CodegenImpl implements Codegen {
|
|||
}
|
||||
|
||||
return builder.toString()
|
||||
+ "call " + String.format("%s_%d:\n", main.id, main.numOfArgs);
|
||||
+ "call " + String.format("%s_%d\n", main.id, main.numOfArgs);
|
||||
}
|
||||
|
||||
private String generateLabel() {
|
||||
|
@ -58,7 +58,7 @@ public class CodegenImpl implements Codegen {
|
|||
} else if (e instanceof Variable) {
|
||||
int offset = ((Variable) e).x;
|
||||
|
||||
return String.format("lw a0,%d(fp)\n", offset * 4);
|
||||
return String.format("lw a0,%d(s0)\n", offset * 4);
|
||||
} else if (e instanceof Invoke) {
|
||||
return compileCall((Invoke) e, false);
|
||||
} else if (e instanceof Seq) {
|
||||
|
@ -131,7 +131,7 @@ public class CodegenImpl implements Codegen {
|
|||
Assign assign = (Assign) e;
|
||||
|
||||
return compileExp(assign.e)
|
||||
+ String.format("sw a0,%d(fp)", assign.x * 4);
|
||||
+ String.format("sw a0,%d(s0)", assign.x * 4);
|
||||
} else if (e instanceof Continue) {
|
||||
return "jr s2\n";
|
||||
} else if (e instanceof Break) {
|
||||
|
@ -165,15 +165,15 @@ public class CodegenImpl implements Codegen {
|
|||
}
|
||||
|
||||
// push old frame pointer
|
||||
builder.append("sw fp,-4(sp)\n");
|
||||
builder.append("sw s0,-4(sp)\n");
|
||||
builder.append("addi sp,sp,-8\n");
|
||||
|
||||
builder.append(
|
||||
// set frame pointer to start of arguments
|
||||
"addi fp,sp,8\n"
|
||||
"addi s0,sp,8\n"
|
||||
+ "call " + methodLabel + "\n"
|
||||
// restore old frame pointer & stack pointer
|
||||
+ "lw fp,4(sp)\n"
|
||||
+ "lw s0,4(sp)\n"
|
||||
+ "lw sp,(sp)\n"
|
||||
// restore return address of caller
|
||||
+ "lw ra,-4(sp)\n"
|
||||
|
|
|
@ -16,7 +16,7 @@ public class CodegenImpl implements Codegen {
|
|||
}
|
||||
|
||||
return builder.toString()
|
||||
+ "call " + String.format("%s_%d:\n", main.id, main.numOfArgs);
|
||||
+ "call " + String.format("%s_%d\n", main.id, main.numOfArgs);
|
||||
}
|
||||
|
||||
private String generateLabel() {
|
||||
|
@ -58,7 +58,7 @@ public class CodegenImpl implements Codegen {
|
|||
} else if (e instanceof Variable) {
|
||||
int offset = ((Variable) e).x;
|
||||
|
||||
return String.format("lw a0,%d(fp)\n", offset * 4);
|
||||
return String.format("lw a0,%d(s0)\n", offset * 4);
|
||||
} else if (e instanceof Invoke) {
|
||||
return compileCall((Invoke) e, false);
|
||||
} else if (e instanceof Seq) {
|
||||
|
@ -131,7 +131,7 @@ public class CodegenImpl implements Codegen {
|
|||
Assign assign = (Assign) e;
|
||||
|
||||
return compileExp(assign.e)
|
||||
+ String.format("sw a0,%d(fp)", assign.x * 4);
|
||||
+ String.format("sw a0,%d(s0)", assign.x * 4);
|
||||
} else if (e instanceof Continue) {
|
||||
return "jr s2\n";
|
||||
} else if (e instanceof Break) {
|
||||
|
@ -165,15 +165,15 @@ public class CodegenImpl implements Codegen {
|
|||
}
|
||||
|
||||
// push old frame pointer
|
||||
builder.append("sw fp,-4(sp)\n");
|
||||
builder.append("sw s0,-4(sp)\n");
|
||||
builder.append("addi sp,sp,-8\n");
|
||||
|
||||
builder.append(
|
||||
// set frame pointer to start of arguments
|
||||
"addi fp,sp,8\n"
|
||||
"addi s0,sp,8\n"
|
||||
+ "call " + methodLabel + "\n"
|
||||
// restore old frame pointer & stack pointer
|
||||
+ "lw fp,4(sp)\n"
|
||||
+ "lw s0,4(sp)\n"
|
||||
+ "lw sp,(sp)\n"
|
||||
// restore return address of caller
|
||||
+ "lw ra,-4(sp)\n"
|
||||
|
|
Loading…
Reference in a new issue