GenASM: Remove a few warnings

This commit is contained in:
2023-03-23 02:57:17 +01:00
parent f55f2661de
commit 76419d86bb

View File

@@ -13,16 +13,16 @@ import de.hsrm.compiler.Klang.types.Type;
import java.util.*;
public class GenASM implements Visitor<Void> {
private class FloatWriter {
private StringBuilder sb = new StringBuilder();
private static class FloatWriter {
private final StringBuilder sb = new StringBuilder();
private int id = -1;
public String getFloat(double d) {
Long longBits = Double.doubleToRawLongBits(d);
String binary = Long.toBinaryString(longBits);
long longBits = Double.doubleToRawLongBits(d);
StringBuilder binary = new StringBuilder(Long.toBinaryString(longBits));
int padCount = 64 - binary.length();
while (padCount > 0) {
binary = "0" + binary;
binary.insert(0, "0");
padCount--;
}
String upper = binary.substring(0, 32);
@@ -59,14 +59,16 @@ public class GenASM implements Visitor<Void> {
}
}
private ASM asm;
private FloatWriter fw = new FloatWriter();
private String mainName;
private final ASM asm;
private final FloatWriter fw = new FloatWriter();
private final String mainName;
Map<String, Integer> env = new HashMap<>();
Map<String, StructDefinition> structs;
String[] registers = { "%rdi", "%rsi", "%rdx", "%rcx", "%r8", "%r9" };
String[] floatRegisters = { "%xmm0", "%xmm1", "%xmm2", "%xmm3", "%xmm4", "%xmm5", "%xmm6", "%xmm7" };
private int lCount = 0; // Invariant: lCount is used
private int lCount = 0;
private int currentFunctionStartLabel = 0;
private Parameter[] currentFunctionParams;
@@ -320,7 +322,7 @@ public class GenASM implements Visitor<Void> {
// Werte LHS aus
// Wenn LHS != 0 bedeutet das true
// also können wir direkt sagen dass das Ergebnis true ist
// also können wir direkt sagen, dass das Ergebnis true ist
e.lhs.welcome(this);
asm.cmp("q", 0, "%rax");
asm.jne(lblTrue);
@@ -338,11 +340,11 @@ public class GenASM implements Visitor<Void> {
asm.mov("q", 1, "%rax");
asm.jmp(lblEnd);
// Die Expressoin wertet zu false aus
// Die Expression wertet zu false aus
asm.label(lblFalse);
asm.mov("q", 0, "%rax");
// Das hier ist das ende
// Das hier ist das Ende
asm.label(lblEnd);
return null;
}
@@ -355,7 +357,7 @@ public class GenASM implements Visitor<Void> {
// Werte LHS aus
// Wenn LHS == 0, bedeutet das false
// also können wir direkt sagen dass das Ergebnis false ist
// also können wir direkt sagen, dass das Ergebnis false ist
e.lhs.welcome(this);
asm.cmp("q", 0, "%rax");
asm.je(lblFalse);
@@ -373,11 +375,11 @@ public class GenASM implements Visitor<Void> {
asm.mov("q", 1, "%rax");
asm.jmp(lblEnd);
// Die Expressoin wertet zu false aus
// Die Expression wertet zu false aus
asm.label(lblFalse);
asm.mov("q", 0, "%rax");
// Das hier ist das ende
// Das hier ist das Ende
asm.label(lblEnd);
return null;
}
@@ -387,9 +389,9 @@ public class GenASM implements Visitor<Void> {
int lblFalse = ++lCount;
int lblEnd = ++lCount;
// Werte LHS aus
// Wenn LHS != 0 bedeutet das true, also jumpe zum false Teil
// Wenn nicht, falle durch zum true Teil
// Werte LHS aus.
// Wenn LHS != 0 bedeutet das true, also springe zum false Teil.
// Wenn nicht, falle durch zum true Teil.
e.lhs.welcome(this);
asm.cmp("q", 0, "%rax");
asm.jne(lblFalse);
@@ -872,7 +874,7 @@ public class GenASM implements Visitor<Void> {
e.expression.welcome(this);
// Move it from xmm0 rax if its a flaot
// Move it from xmm0 rax if it's a float
if (e.expression.type.equals(Type.getFloatType())) {
asm.mov("q", "%xmm0", "%rax");
}
@@ -890,7 +892,7 @@ public class GenASM implements Visitor<Void> {
asm.mov("q", Helper.getFieldOffset(structDef, e.path[i]), "%rax", "%rax");
}
// 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 on top of the stack into the field of the struct that has to be updated
asm.pop("q", Helper.getFieldOffset(structDef, fieldNameToUpdate) + "(%rax)");
asm.mov("q", 0 , "%rax"); // clear rax since an assignment has no result
@@ -907,12 +909,12 @@ public class GenASM implements Visitor<Void> {
asm.mov("sd", "%xmm2", "%xmm0");
asm.mov("sd", "%xmm2", "%xmm0");
return true;
} else if (lhsIsFloat && !rhsIsFloat) {
} else if (lhsIsFloat) {
lhs.welcome(this);
rhs.welcome(this);
asm.cvtsi2sd("%rax", "%xmm1");
return true;
} else if (!lhsIsFloat && rhsIsFloat) {
} else if (rhsIsFloat) {
lhs.welcome(this);
asm.cvtsi2sd("%rax", "%xmm2");
rhs.welcome(this);