32: Require data type for all asm functions

This commit is contained in:
Marvin Kaiser
2020-03-17 16:02:03 +01:00
parent 982fc6417d
commit 49b024b95f
15 changed files with 84 additions and 177 deletions

View File

@@ -12,10 +12,6 @@ public class ASM {
this.mnemonics = new ArrayList<Mnemonic>(); this.mnemonics = new ArrayList<Mnemonic>();
} }
public void push(String operand) {
mnemonics.add(new Push(operand));
}
public void push(String dataType, int immediate) { public void push(String dataType, int immediate) {
mnemonics.add(new Push(dataType, immediate)); mnemonics.add(new Push(dataType, immediate));
} }
@@ -24,22 +20,10 @@ public class ASM {
mnemonics.add(new Push(dataType, operand)); mnemonics.add(new Push(dataType, operand));
} }
public void pop(String operand) {
mnemonics.add(new Pop(operand));
}
public void pop(String dataType, String operand) { public void pop(String dataType, String operand) {
mnemonics.add(new Pop(dataType, operand)); mnemonics.add(new Pop(dataType, operand));
} }
public void mov(int immediate, String dst) {
mnemonics.add(new Mov(immediate, dst));
}
public void mov(String src, String dst) {
mnemonics.add(new Mov(src, dst));
}
public void mov(String dataType, String src, String dst) { public void mov(String dataType, String src, String dst) {
mnemonics.add(new Mov(dataType, src, dst)); mnemonics.add(new Mov(dataType, src, dst));
} }
@@ -60,16 +44,12 @@ public class ASM {
mnemonics.add(new Mov(dataType, immediate, dst)); mnemonics.add(new Mov(dataType, immediate, dst));
} }
public void ucomi(String src, String dst) {
mnemonics.add(new Ucomi(src, dst));
}
public void ucomi(String dataType, String src, String dst) { public void ucomi(String dataType, String src, String dst) {
mnemonics.add(new Ucomi(dataType, src, dst)); mnemonics.add(new Ucomi(dataType, src, dst));
} }
public void cmp(String src, String dst) { public void cmp(String dataType, String src, String dst) {
mnemonics.add(new Cmp(src, dst)); mnemonics.add(new Cmp(dataType, src, dst));
} }
public void cmp(String dataType, int immediate, String dst) { public void cmp(String dataType, int immediate, String dst) {
@@ -156,10 +136,6 @@ public class ASM {
mnemonics.add(new Label(labelPrefix, label)); mnemonics.add(new Label(labelPrefix, label));
} }
public void add(String src, String dst) {
mnemonics.add(new Add(src, dst));
}
public void add(String dataType, String src, String dst) { public void add(String dataType, String src, String dst) {
mnemonics.add(new Add(dataType, src, dst)); mnemonics.add(new Add(dataType, src, dst));
} }
@@ -171,27 +147,15 @@ public class ASM {
public void add(String dataType, int immediate, String dst) { public void add(String dataType, int immediate, String dst) {
mnemonics.add(new Add(dataType, immediate, dst)); mnemonics.add(new Add(dataType, immediate, dst));
} }
public void sub(String src, String dst) {
mnemonics.add(new Sub(src, dst));
}
public void sub(String dataType, String src, String dst) { public void sub(String dataType, String src, String dst) {
mnemonics.add(new Sub(dataType, src, dst)); mnemonics.add(new Sub(dataType, src, dst));
} }
public void mul(String src, String dst) {
mnemonics.add(new Mul(src, dst));
}
public void mul(String dataType, String src, String dst) { public void mul(String dataType, String src, String dst) {
mnemonics.add(new Mul(dataType, src, dst)); mnemonics.add(new Mul(dataType, src, dst));
} }
public void div(String src, String dst) {
mnemonics.add(new Div(src, dst));
}
public void div(String dataType, String src, String dst) { public void div(String dataType, String src, String dst) {
mnemonics.add(new Div(dataType, src, dst)); mnemonics.add(new Div(dataType, src, dst));
} }
@@ -200,12 +164,8 @@ public class ASM {
mnemonics.add(new Idiv(dataType, operand)); mnemonics.add(new Idiv(dataType, operand));
} }
public void idiv(String operand) { public void imul(String dataType, String src, String dst) {
mnemonics.add(new Idiv(operand)); mnemonics.add(new Imul(dataType, src, dst));
}
public void imul(String src, String dst) {
mnemonics.add(new Imul(src, dst));
} }
public void cqto() { public void cqto() {
@@ -219,10 +179,6 @@ public class ASM {
public void xor(String dataType, String src, String dst) { public void xor(String dataType, String src, String dst) {
mnemonics.add(new Xor(dataType, src, dst)); mnemonics.add(new Xor(dataType, src, dst));
} }
public void xor(String src, String dst) {
mnemonics.add(new Xor(src, dst));
}
public void neg(String operand) { public void neg(String operand) {
mnemonics.add(new Neg(operand)); mnemonics.add(new Neg(operand));

View File

@@ -1,13 +1,8 @@
package de.hsrm.compiler.Klang.asm.mnemonics; package de.hsrm.compiler.Klang.asm.mnemonics;
public class Add extends TwoOperandMnemonic { public class Add extends TwoOperandMnemonic {
public String dataType = "q"; public String dataType;
public Add(String src, String dst) {
this.src = src;
this.dst = dst;
}
public Add(String dataType, String src, String dst) { public Add(String dataType, String src, String dst) {
this.dataType = dataType; this.dataType = dataType;
this.src = src; this.src = src;

View File

@@ -1,9 +1,10 @@
package de.hsrm.compiler.Klang.asm.mnemonics; package de.hsrm.compiler.Klang.asm.mnemonics;
public class Cmp extends TwoOperandMnemonic { public class Cmp extends TwoOperandMnemonic {
public String dataType;
public Cmp(String src, String dst) {
this.dataType = ""; public Cmp(String dataType, String src, String dst) {
this.dataType = dataType;
this.src = src; this.src = src;
this.dst = dst; this.dst = dst;
} }

View File

@@ -1,12 +1,7 @@
package de.hsrm.compiler.Klang.asm.mnemonics; package de.hsrm.compiler.Klang.asm.mnemonics;
public class Div extends TwoOperandMnemonic { public class Div extends TwoOperandMnemonic {
public String dataType = "q"; public String dataType;
public Div(String src, String dst) {
this.src = src;
this.dst = dst;
}
public Div(String dataType, String src, String dst) { public Div(String dataType, String src, String dst) {
this.dataType = dataType; this.dataType = dataType;

View File

@@ -1,11 +1,7 @@
package de.hsrm.compiler.Klang.asm.mnemonics; package de.hsrm.compiler.Klang.asm.mnemonics;
public class Idiv extends OneOperandMnemonic{ public class Idiv extends OneOperandMnemonic{
public String dataType = ""; public String dataType;
public Idiv(String operand) {
this.operand = operand;
}
public Idiv(String dataType, String operand) { public Idiv(String dataType, String operand) {
this.dataType = dataType; this.dataType = dataType;

View File

@@ -1,9 +1,10 @@
package de.hsrm.compiler.Klang.asm.mnemonics; package de.hsrm.compiler.Klang.asm.mnemonics;
public class Imul extends TwoOperandMnemonic { public class Imul extends TwoOperandMnemonic {
public String dataType = "q"; public String dataType;
public Imul(String src, String dst) { public Imul(String dataType, String src, String dst) {
this.dataType = dataType;
this.src = src; this.src = src;
this.dst = dst; this.dst = dst;
} }

View File

@@ -1,7 +1,6 @@
package de.hsrm.compiler.Klang.asm.mnemonics; package de.hsrm.compiler.Klang.asm.mnemonics;
public abstract class Mnemonic { public abstract class Mnemonic {
public String dataType = "";
public abstract String toAsm(); public abstract String toAsm();
public int indentation = 2; public int indentation = 2;
} }

View File

@@ -3,16 +3,6 @@ package de.hsrm.compiler.Klang.asm.mnemonics;
public class Mov extends TwoOperandMnemonic{ public class Mov extends TwoOperandMnemonic{
public String dataType = "q"; public String dataType = "q";
public Mov(int immediate, String dst) {
this.src = "$" + immediate;
this.dst = dst;
}
public Mov(String src, String dst) {
this.src = src;
this.dst = dst;
}
public Mov(String dataType, String src, String dst) { public Mov(String dataType, String src, String dst) {
this.dataType = dataType; this.dataType = dataType;
this.src = src; this.src = src;

View File

@@ -1,12 +1,7 @@
package de.hsrm.compiler.Klang.asm.mnemonics; package de.hsrm.compiler.Klang.asm.mnemonics;
public class Mul extends TwoOperandMnemonic { public class Mul extends TwoOperandMnemonic {
public String dataType = "q"; public String dataType;
public Mul(String src, String dst) {
this.src = src;
this.dst = dst;
}
public Mul(String dataType, String src, String dst) { public Mul(String dataType, String src, String dst) {
this.dataType = dataType; this.dataType = dataType;

View File

@@ -1,10 +1,7 @@
package de.hsrm.compiler.Klang.asm.mnemonics; package de.hsrm.compiler.Klang.asm.mnemonics;
public class Pop extends OneOperandMnemonic { public class Pop extends OneOperandMnemonic {
public String dataType = "q"; public String dataType;
public Pop(String operand) {
this.operand = operand;
}
public Pop(String dataType, String operand) { public Pop(String dataType, String operand) {
this.dataType = dataType; this.dataType = dataType;

View File

@@ -1,10 +1,7 @@
package de.hsrm.compiler.Klang.asm.mnemonics; package de.hsrm.compiler.Klang.asm.mnemonics;
public class Push extends OneOperandMnemonic { public class Push extends OneOperandMnemonic {
public Push(String operand){ public String dataType;
this.dataType = "q";
this.operand = operand;
}
public Push(String dataType, int immediate){ public Push(String dataType, int immediate){
this.dataType = dataType; this.dataType = dataType;

View File

@@ -1,12 +1,7 @@
package de.hsrm.compiler.Klang.asm.mnemonics; package de.hsrm.compiler.Klang.asm.mnemonics;
public class Sub extends TwoOperandMnemonic { public class Sub extends TwoOperandMnemonic {
public String dataType = "q"; public String dataType;
public Sub(String src, String dst) {
this.src = src;
this.dst = dst;
}
public Sub(String dataType, String src, String dst) { public Sub(String dataType, String src, String dst) {
this.dataType = dataType; this.dataType = dataType;

View File

@@ -1,12 +1,7 @@
package de.hsrm.compiler.Klang.asm.mnemonics; package de.hsrm.compiler.Klang.asm.mnemonics;
public class Ucomi extends TwoOperandMnemonic { public class Ucomi extends TwoOperandMnemonic {
public String dataType = "q"; public String dataType;
public Ucomi(String src, String dst) {
this.src = src;
this.dst = dst;
}
public Ucomi(String dataType, String src, String dst) { public Ucomi(String dataType, String src, String dst) {
this.dataType = dataType; this.dataType = dataType;

View File

@@ -1,12 +1,7 @@
package de.hsrm.compiler.Klang.asm.mnemonics; package de.hsrm.compiler.Klang.asm.mnemonics;
public class Xor extends TwoOperandMnemonic { public class Xor extends TwoOperandMnemonic {
public String dataType = "q"; public String dataType;
public Xor(String src, String dst) {
this.src = src;
this.dst = dst;
}
public Xor(String dataType, String src, String dst) { public Xor(String dataType, String src, String dst) {
this.dataType = dataType; this.dataType = dataType;

View File

@@ -83,7 +83,7 @@ public class GenASM implements Visitor<Void> {
asm.mov("sd", "%xmm0", "%xmm2"); asm.mov("sd", "%xmm0", "%xmm2");
rhs.welcome(this); rhs.welcome(this);
asm.mov("sd", "%xmm2", "%xmm0"); asm.mov("sd", "%xmm2", "%xmm0");
asm.mov("%xmm2", "%xmm0"); asm.mov("sd", "%xmm2", "%xmm0");
return true; return true;
} else if (lhsIsFloat && !rhsIsFloat) { } else if (lhsIsFloat && !rhsIsFloat) {
lhs.welcome(this); lhs.welcome(this);
@@ -99,10 +99,10 @@ public class GenASM implements Visitor<Void> {
return true; return true;
} else { } else {
lhs.welcome(this); lhs.welcome(this);
asm.push("%rax"); asm.push("q", "%rax");
rhs.welcome(this); rhs.welcome(this);
asm.mov("%rax", "%rbx"); asm.mov("q", "%rax", "%rbx");
asm.pop("%rax"); asm.pop("q", "%rax");
return false; return false;
} }
} }
@@ -123,7 +123,7 @@ public class GenASM implements Visitor<Void> {
@Override @Override
public Void visit(IntegerExpression e) { public Void visit(IntegerExpression e) {
asm.mov(e.value, "%rax"); asm.mov("q", e.value, "%rax");
return null; return null;
} }
@@ -136,7 +136,7 @@ public class GenASM implements Visitor<Void> {
@Override @Override
public Void visit(BooleanExpression e) { public Void visit(BooleanExpression e) {
asm.mov(e.value ? 1 : 0, "%rax"); asm.mov("q", e.value ? 1 : 0, "%rax");
return null; return null;
} }
@@ -159,15 +159,15 @@ public class GenASM implements Visitor<Void> {
if (isFloatOperation) { if (isFloatOperation) {
asm.ucomi("sd", "%xmm1", "xmm0"); asm.ucomi("sd", "%xmm1", "xmm0");
} else { } else {
asm.cmp("%rbx", "%rax"); asm.cmp("q", "%rbx", "%rax");
} }
asm.je(lblTrue); asm.je(lblTrue);
// false // false
asm.mov(0, "%rax"); asm.mov("q", 0, "%rax");
asm.jmp(lblEnd); asm.jmp(lblEnd);
asm.label(lblTrue); asm.label(lblTrue);
// true // true
asm.mov(1, "%rax"); asm.mov("q", 1, "%rax");
asm.label(lblEnd); asm.label(lblEnd);
return null; return null;
} }
@@ -181,15 +181,15 @@ public class GenASM implements Visitor<Void> {
if (isFloatOperation) { if (isFloatOperation) {
asm.ucomi("sd", "%xmm0", "%xmm1"); asm.ucomi("sd", "%xmm0", "%xmm1");
} else { } else {
asm.cmp("%rax", "%rbx"); asm.cmp("q", "%rax", "%rbx");
} }
asm.jne(lblTrue); asm.jne(lblTrue);
// false // false
asm.mov(0, "%rax"); asm.mov("q", 0, "%rax");
asm.jmp(lblEnd); asm.jmp(lblEnd);
asm.label(lblTrue); asm.label(lblTrue);
// true // true
asm.mov(1, "%rax"); asm.mov("q", 1, "%rax");
asm.label(lblEnd); asm.label(lblEnd);
return null; return null;
} }
@@ -203,15 +203,15 @@ public class GenASM implements Visitor<Void> {
if (isFloatOperation) { if (isFloatOperation) {
asm.ucomi("sd", "%xmm1", "%xmm0"); asm.ucomi("sd", "%xmm1", "%xmm0");
} else { } else {
asm.cmp("%rbx", "%rax"); asm.cmp("q", "%rbx", "%rax");
} }
asm.jg(lblTrue); asm.jg(lblTrue);
// false // false
asm.mov(0, "%rax"); asm.mov("q", 0, "%rax");
asm.jmp(lblEnd); asm.jmp(lblEnd);
asm.label(lblTrue); asm.label(lblTrue);
// true // true
asm.mov(1, "%rax"); asm.mov("q", 1, "%rax");
asm.label(lblEnd); asm.label(lblEnd);
return null; return null;
} }
@@ -225,15 +225,15 @@ public class GenASM implements Visitor<Void> {
if (isFloatOperation) { if (isFloatOperation) {
asm.ucomi("sd", "%xmm1", "xmm0"); asm.ucomi("sd", "%xmm1", "xmm0");
} else { } else {
asm.cmp("%rbx", "%rax"); asm.cmp("q", "%rbx", "%rax");
} }
asm.jge(lblTrue); asm.jge(lblTrue);
// false // false
asm.mov(0, "%rax"); asm.mov("q", 0, "%rax");
asm.jmp(lblEnd); asm.jmp(lblEnd);
asm.label(lblTrue); asm.label(lblTrue);
// true // true
asm.mov(1, "%rax"); asm.mov("q", 1, "%rax");
asm.label(lblEnd); asm.label(lblEnd);
return null; return null;
} }
@@ -247,15 +247,15 @@ public class GenASM implements Visitor<Void> {
if (isFloatOperation) { if (isFloatOperation) {
asm.ucomi("sd", "%xmm1", "%xmm0"); asm.ucomi("sd", "%xmm1", "%xmm0");
} else { } else {
asm.cmp("%rbx", "%rax"); asm.cmp("q", "%rbx", "%rax");
} }
asm.jl(lblTrue); asm.jl(lblTrue);
// false // false
asm.mov(0, "%rax"); asm.mov("q", 0, "%rax");
asm.jmp(lblEnd); asm.jmp(lblEnd);
asm.label(lblTrue); asm.label(lblTrue);
// true // true
asm.mov(1, "%rax"); asm.mov("q", 1, "%rax");
asm.label(lblEnd); asm.label(lblEnd);
return null; return null;
} }
@@ -269,15 +269,15 @@ public class GenASM implements Visitor<Void> {
if (isFloatOperation) { if (isFloatOperation) {
asm.ucomi("sd", "%xmm1", "%xmm0"); asm.ucomi("sd", "%xmm1", "%xmm0");
} else { } else {
asm.cmp("%rbx", "%rax"); asm.cmp("q", "%rbx", "%rax");
} }
asm.jle(lblTrue); asm.jle(lblTrue);
// false // false
asm.mov(0, "%rax"); asm.mov("q", 0, "%rax");
asm.jmp(lblEnd); asm.jmp(lblEnd);
asm.label(lblTrue); asm.label(lblTrue);
// true // true
asm.mov(1, "%rax"); asm.mov("q", 1, "%rax");
asm.label(lblEnd); asm.label(lblEnd);
return null; return null;
} }
@@ -288,7 +288,7 @@ public class GenASM implements Visitor<Void> {
if (isFloatOperation) { if (isFloatOperation) {
asm.add("sd", "%xmm1", "%xmm0"); asm.add("sd", "%xmm1", "%xmm0");
} else { } else {
asm.add("%rbx", "%rax"); asm.add("q", "%rbx", "%rax");
} }
return null; return null;
} }
@@ -299,7 +299,7 @@ public class GenASM implements Visitor<Void> {
if (isFloatOperation) { if (isFloatOperation) {
asm.sub("sd", "%xmm1", "%xmm0"); asm.sub("sd", "%xmm1", "%xmm0");
} else { } else {
asm.sub("%rbx", "%rax"); asm.sub("q", "%rbx", "%rax");
} }
return null; return null;
} }
@@ -310,7 +310,7 @@ public class GenASM implements Visitor<Void> {
if (isFloatOperation) { if (isFloatOperation) {
asm.mul("sd", "%xmm1", "%xmm0"); asm.mul("sd", "%xmm1", "%xmm0");
} else { } else {
asm.imul("%rbx", "%rax"); asm.imul("q", "%rbx", "%rax");
} }
return null; return null;
} }
@@ -322,7 +322,7 @@ public class GenASM implements Visitor<Void> {
asm.div("sd", "%xmm1", "%xmm0"); asm.div("sd", "%xmm1", "%xmm0");
} else { } else {
asm.cqto(); asm.cqto();
asm.idiv("%rbx"); asm.idiv("q", "%rbx");
} }
return null; return null;
} }
@@ -330,13 +330,13 @@ public class GenASM implements Visitor<Void> {
@Override @Override
public Void visit(ModuloExpression e) { public Void visit(ModuloExpression e) {
e.lhs.welcome(this); e.lhs.welcome(this);
asm.push("%rax"); asm.push("q", "%rax");
e.rhs.welcome(this); e.rhs.welcome(this);
asm.mov("%rax", "%rbx"); asm.mov("q", "%rax", "%rbx");
asm.pop("%rax"); asm.pop("q", "%rax");
asm.cqto(); asm.cqto();
asm.idiv("%rbx"); asm.idiv("q", "%rbx");
asm.mov("%rdx", "%rax"); asm.mov("q", "%rdx", "%rax");
return null; return null;
} }
@@ -376,12 +376,12 @@ public class GenASM implements Visitor<Void> {
// Die Expression wertet zu true aus // Die Expression wertet zu true aus
// Springe am false Teil vorbei // Springe am false Teil vorbei
asm.label(lblTrue); asm.label(lblTrue);
asm.mov(1, "%rax"); asm.mov("q", 1, "%rax");
asm.jmp(lblEnd); asm.jmp(lblEnd);
// Die Expressoin wertet zu false aus // Die Expressoin wertet zu false aus
asm.label(lblFalse); asm.label(lblFalse);
asm.mov(0, "%rax"); asm.mov("q", 0, "%rax");
// Das hier ist das ende // Das hier ist das ende
asm.label(lblEnd); asm.label(lblEnd);
@@ -411,12 +411,12 @@ public class GenASM implements Visitor<Void> {
// Die Expression wertet zu true aus // Die Expression wertet zu true aus
// Springe am false Teil vorbei // Springe am false Teil vorbei
asm.label(lblTrue); asm.label(lblTrue);
asm.mov(1, "%rax"); asm.mov("q", 1, "%rax");
asm.jmp(lblEnd); asm.jmp(lblEnd);
// Die Expressoin wertet zu false aus // Die Expressoin wertet zu false aus
asm.label(lblFalse); asm.label(lblFalse);
asm.mov(0, "%rax"); asm.mov("q", 0, "%rax");
// Das hier ist das ende // Das hier ist das ende
asm.label(lblEnd); asm.label(lblEnd);
@@ -437,13 +437,13 @@ public class GenASM implements Visitor<Void> {
// Hier ist das Ergebnis true // Hier ist das Ergebnis true
// Springe am false Teil vorbei // Springe am false Teil vorbei
asm.mov(1, "%rax"); asm.mov("q", 1, "%rax");
asm.jmp(lblEnd); asm.jmp(lblEnd);
// Hier ist das Ergebnis false // Hier ist das Ergebnis false
// Falle zum Ende durch // Falle zum Ende durch
asm.label(lblFalse); asm.label(lblFalse);
asm.mov(0, "%rax"); asm.mov("q", 0, "%rax");
// Hier ist das Ende // Hier ist das Ende
asm.label(lblEnd); asm.label(lblEnd);
@@ -555,8 +555,8 @@ public class GenASM implements Visitor<Void> {
@Override @Override
public Void visit(ReturnStatement e) { public Void visit(ReturnStatement e) {
e.expression.welcome(this); e.expression.welcome(this);
asm.mov("%rbp", "%rsp"); asm.mov("q", "%rbp", "%rsp");
asm.pop("%rbp"); asm.pop("q", "%rbp");
asm.ret(); asm.ret();
return null; return null;
} }
@@ -575,8 +575,8 @@ public class GenASM implements Visitor<Void> {
this.currentFunctionStartLabel = lblStart; this.currentFunctionStartLabel = lblStart;
this.currentFunctionParams = e.parameters; this.currentFunctionParams = e.parameters;
asm.functionHead(e.name); asm.functionHead(e.name);
asm.push("%rbp"); asm.push("q", "%rbp");
asm.mov("%rsp", "%rbp"); asm.mov("q", "%rsp", "%rbp");
asm.label(lblStart); asm.label(lblStart);
// hole die anzahl der lokalen variablen // hole die anzahl der lokalen variablen
@@ -623,13 +623,13 @@ public class GenASM implements Visitor<Void> {
fi = 0; fi = 0;
for (var param: registerParameters) { for (var param: registerParameters) {
if (param.type.equals(Type.getFloatType())) { if (param.type.equals(Type.getFloatType())) {
asm.mov(this.floatRegisters[fi], "%rax"); asm.mov("q", this.floatRegisters[fi], "%rax");
asm.push("%rax"); asm.push("q", "%rax");
offset -= 8; offset -= 8;
this.env.put(param.name, offset); // negative, liegt unter aktuellem BP this.env.put(param.name, offset); // negative, liegt unter aktuellem BP
fi++; fi++;
} else { } else {
asm.push(this.registers[ri]); asm.push("q", this.registers[ri]);
offset -= 8; offset -= 8;
this.env.put(param.name, offset); // negative, liegt unter aktuellem BP this.env.put(param.name, offset); // negative, liegt unter aktuellem BP
ri++; ri++;
@@ -656,15 +656,15 @@ public class GenASM implements Visitor<Void> {
e.arguments[i].welcome(this); e.arguments[i].welcome(this);
if (e.arguments[i].type.equals(Type.getFloatType())) { if (e.arguments[i].type.equals(Type.getFloatType())) {
asm.mov("%xmm0", "%rax0"); asm.mov("q", "%xmm0", "%rax0");
} }
asm.push("%rax"); asm.push("q", "%rax");
} }
// push args into local var locations, last arg is ontop of the stack // push args into local var locations, last arg is ontop of the stack
for (int i = e.arguments.length - 1; i >= 0; i--) { for (int i = e.arguments.length - 1; i >= 0; i--) {
asm.pop(this.env.get(this.currentFunctionParams[i].name) + "(%rbp)"); asm.pop("q", this.env.get(this.currentFunctionParams[i].name) + "(%rbp)");
} }
asm.jmp(this.currentFunctionStartLabel); asm.jmp(this.currentFunctionStartLabel);
@@ -713,10 +713,10 @@ public class GenASM implements Visitor<Void> {
for (var arg : e.arguments) { for (var arg : e.arguments) {
arg.welcome(this); arg.welcome(this);
if (arg.type.equals(Type.getFloatType())) { if (arg.type.equals(Type.getFloatType())) {
asm.mov("%xmm0", "%rax"); asm.mov("q", "%xmm0", "%rax");
asm.push("%rax"); asm.push("q", "%rax");
} else { } else {
asm.push("%rax"); asm.push("q", "%rax");
} }
} }
@@ -760,11 +760,11 @@ public class GenASM implements Visitor<Void> {
asm.newline(); asm.newline();
} }
asm.functionHead(mainName); asm.functionHead(mainName);
asm.push("%rbp"); asm.push("q", "%rbp");
asm.mov("%rsp", "%rbp"); asm.mov("q", "%rsp", "%rbp");
e.expression.welcome(this); e.expression.welcome(this);
asm.mov("%rbp", "%rsp"); asm.mov("q", "%rbp", "%rsp");
asm.pop("%rbp"); asm.pop("q", "%rbp");
asm.ret(); asm.ret();
asm.text(fw.getFloatSection()); asm.text(fw.getFloatSection());
@@ -810,7 +810,7 @@ public class GenASM implements Visitor<Void> {
// push rax to xmm0 if the result type is a float // push rax to xmm0 if the result type is a float
if (e.type.equals(Type.getFloatType())) { if (e.type.equals(Type.getFloatType())) {
asm.mov("%rax", "%xmm0"); asm.mov("q", "%rax", "%xmm0");
} }
return null; return null;
@@ -824,10 +824,10 @@ public class GenASM implements Visitor<Void> {
// move float values from xmm0 to rax first // move float values from xmm0 to rax first
if (arg.type.equals(Type.getFloatType())) { if (arg.type.equals(Type.getFloatType())) {
asm.mov("%xmm0", "%rax"); asm.mov("q", "%xmm0", "%rax");
} }
asm.push("%rax"); asm.push("q", "%rax");
} }
// allocate heap memory by calling malloc // allocate heap memory by calling malloc
@@ -837,7 +837,7 @@ public class GenASM implements Visitor<Void> {
// push args into struct memory, last arg is ontop of the stack // push args into struct memory, last arg is ontop of the stack
for (int i = e.args.length - 1; i >= 0; i--) { for (int i = e.args.length - 1; i >= 0; i--) {
asm.pop(Helper.getFieldOffset(structDef, i) + "(%rax)"); asm.pop("q", Helper.getFieldOffset(structDef, i) + "(%rax)");
} }
return null; return null;
@@ -866,11 +866,11 @@ public class GenASM implements Visitor<Void> {
// Move it from xmm0 rax if its a flaot // Move it from xmm0 rax if its a flaot
if (e.expression.type.equals(Type.getFloatType())) { if (e.expression.type.equals(Type.getFloatType())) {
asm.mov("%xmm0", "%rax"); asm.mov("q", "%xmm0", "%rax");
} }
// Push the expression onto the stack // Push the expression onto the stack
asm.push("%rax"); asm.push("q", "%rax");
// move struct address into rax // move struct address into rax
asm.mov("q", offset, "%rbp", "%rax"); asm.mov("q", offset, "%rbp", "%rax");
@@ -883,7 +883,7 @@ public class GenASM implements Visitor<Void> {
} }
// pop the expression that is ontop of the stack into the field of the struct that has to be updated // pop the expression that is ontop of the stack into the field of the struct that has to be updated
asm.pop(Helper.getFieldOffset(structDef, fieldNameToUpdate) + "(%rax)"); asm.pop("q", Helper.getFieldOffset(structDef, fieldNameToUpdate) + "(%rax)");
asm.mov("q", 0 , "%rax"); // clear rax since an assignment has no result asm.mov("q", 0 , "%rax"); // clear rax since an assignment has no result
return null; return null;