GenASM: Use leave instead of mov and pop for returning from a function.
This commit is contained in:
@@ -172,6 +172,10 @@ public class ASM {
|
||||
mnemonics.add(new Cqto());
|
||||
}
|
||||
|
||||
public void leave() {
|
||||
mnemonics.add(new Leave());
|
||||
}
|
||||
|
||||
public void ret() {
|
||||
mnemonics.add(new Ret());
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package de.hsrm.compiler.Klang.asm.mnemonics;
|
||||
|
||||
public class Leave extends NoOperandMnemonic {
|
||||
@Override
|
||||
public String toAsm() {
|
||||
return "leave";
|
||||
}
|
||||
}
|
||||
@@ -551,8 +551,7 @@ public class GenASM implements Visitor<Void> {
|
||||
@Override
|
||||
public Void visit(ReturnStatement e) {
|
||||
e.expression.welcome(this);
|
||||
asm.mov("q", "%rbp", "%rsp");
|
||||
asm.pop("q", "%rbp");
|
||||
asm.leave();
|
||||
asm.ret();
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user