Added cli argument to either generate main method or not

This commit is contained in:
Marvin Kaiser
2020-01-14 18:37:34 +01:00
parent 5275b63940
commit 34d0e1bb0e
2 changed files with 16 additions and 4 deletions

View File

@@ -56,13 +56,20 @@ public class GenASM implements Visitor<Void> {
}
public ExWriter ex;
private String mainName;
Map<String, Integer> env = new HashMap<>();
Set<String> vars;
String[] rs = { "%rdi", "%rsi", "%rdx", "%rcx", "%r8", "%r9" };
private int lCount = 0; // Invariante: lCount ist benutzt
public GenASM(ExWriter ex, String mainName) {
this.ex = ex;
this.mainName = mainName;
}
public GenASM(ExWriter ex) {
this.ex = ex;
this.mainName = "main";
}
@Override
@@ -445,9 +452,9 @@ public class GenASM implements Visitor<Void> {
func.welcome(this);
this.ex.write("\n");
}
this.ex.write(".globl start\n");
this.ex.write(".type start, @function\n");
this.ex.write("start:\n");
this.ex.write(".globl " + mainName + "\n");
this.ex.write(".type " +mainName + ", @function\n");
this.ex.write(mainName + ":\n");
this.ex.write(" pushq %rbp\n");
this.ex.write(" movq %rsp, %rbp\n");
e.expression.welcome(this);