GenASM: Remove a few warnings
This commit is contained in:
@@ -13,16 +13,16 @@ import de.hsrm.compiler.Klang.types.Type;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class GenASM implements Visitor<Void> {
|
public class GenASM implements Visitor<Void> {
|
||||||
private class FloatWriter {
|
private static class FloatWriter {
|
||||||
private StringBuilder sb = new StringBuilder();
|
private final StringBuilder sb = new StringBuilder();
|
||||||
private int id = -1;
|
private int id = -1;
|
||||||
|
|
||||||
public String getFloat(double d) {
|
public String getFloat(double d) {
|
||||||
Long longBits = Double.doubleToRawLongBits(d);
|
long longBits = Double.doubleToRawLongBits(d);
|
||||||
String binary = Long.toBinaryString(longBits);
|
StringBuilder binary = new StringBuilder(Long.toBinaryString(longBits));
|
||||||
int padCount = 64 - binary.length();
|
int padCount = 64 - binary.length();
|
||||||
while (padCount > 0) {
|
while (padCount > 0) {
|
||||||
binary = "0" + binary;
|
binary.insert(0, "0");
|
||||||
padCount--;
|
padCount--;
|
||||||
}
|
}
|
||||||
String upper = binary.substring(0, 32);
|
String upper = binary.substring(0, 32);
|
||||||
@@ -59,14 +59,16 @@ public class GenASM implements Visitor<Void> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private ASM asm;
|
private final ASM asm;
|
||||||
private FloatWriter fw = new FloatWriter();
|
private final FloatWriter fw = new FloatWriter();
|
||||||
private String mainName;
|
private final String mainName;
|
||||||
|
|
||||||
Map<String, Integer> env = new HashMap<>();
|
Map<String, Integer> env = new HashMap<>();
|
||||||
Map<String, StructDefinition> structs;
|
Map<String, StructDefinition> structs;
|
||||||
String[] registers = { "%rdi", "%rsi", "%rdx", "%rcx", "%r8", "%r9" };
|
String[] registers = { "%rdi", "%rsi", "%rdx", "%rcx", "%r8", "%r9" };
|
||||||
String[] floatRegisters = { "%xmm0", "%xmm1", "%xmm2", "%xmm3", "%xmm4", "%xmm5", "%xmm6", "%xmm7" };
|
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 int currentFunctionStartLabel = 0;
|
||||||
private Parameter[] currentFunctionParams;
|
private Parameter[] currentFunctionParams;
|
||||||
|
|
||||||
@@ -320,7 +322,7 @@ public class GenASM implements Visitor<Void> {
|
|||||||
|
|
||||||
// Werte LHS aus
|
// Werte LHS aus
|
||||||
// Wenn LHS != 0 bedeutet das true
|
// 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);
|
e.lhs.welcome(this);
|
||||||
asm.cmp("q", 0, "%rax");
|
asm.cmp("q", 0, "%rax");
|
||||||
asm.jne(lblTrue);
|
asm.jne(lblTrue);
|
||||||
@@ -338,11 +340,11 @@ public class GenASM implements Visitor<Void> {
|
|||||||
asm.mov("q", 1, "%rax");
|
asm.mov("q", 1, "%rax");
|
||||||
asm.jmp(lblEnd);
|
asm.jmp(lblEnd);
|
||||||
|
|
||||||
// Die Expressoin wertet zu false aus
|
// Die Expression wertet zu false aus
|
||||||
asm.label(lblFalse);
|
asm.label(lblFalse);
|
||||||
asm.mov("q", 0, "%rax");
|
asm.mov("q", 0, "%rax");
|
||||||
|
|
||||||
// Das hier ist das ende
|
// Das hier ist das Ende
|
||||||
asm.label(lblEnd);
|
asm.label(lblEnd);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -355,7 +357,7 @@ public class GenASM implements Visitor<Void> {
|
|||||||
|
|
||||||
// Werte LHS aus
|
// Werte LHS aus
|
||||||
// Wenn LHS == 0, bedeutet das false
|
// 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);
|
e.lhs.welcome(this);
|
||||||
asm.cmp("q", 0, "%rax");
|
asm.cmp("q", 0, "%rax");
|
||||||
asm.je(lblFalse);
|
asm.je(lblFalse);
|
||||||
@@ -373,11 +375,11 @@ public class GenASM implements Visitor<Void> {
|
|||||||
asm.mov("q", 1, "%rax");
|
asm.mov("q", 1, "%rax");
|
||||||
asm.jmp(lblEnd);
|
asm.jmp(lblEnd);
|
||||||
|
|
||||||
// Die Expressoin wertet zu false aus
|
// Die Expression wertet zu false aus
|
||||||
asm.label(lblFalse);
|
asm.label(lblFalse);
|
||||||
asm.mov("q", 0, "%rax");
|
asm.mov("q", 0, "%rax");
|
||||||
|
|
||||||
// Das hier ist das ende
|
// Das hier ist das Ende
|
||||||
asm.label(lblEnd);
|
asm.label(lblEnd);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -387,9 +389,9 @@ public class GenASM implements Visitor<Void> {
|
|||||||
int lblFalse = ++lCount;
|
int lblFalse = ++lCount;
|
||||||
int lblEnd = ++lCount;
|
int lblEnd = ++lCount;
|
||||||
|
|
||||||
// Werte LHS aus
|
// Werte LHS aus.
|
||||||
// Wenn LHS != 0 bedeutet das true, also jumpe zum false Teil
|
// Wenn LHS != 0 bedeutet das true, also springe zum false Teil.
|
||||||
// Wenn nicht, falle durch zum true Teil
|
// Wenn nicht, falle durch zum true Teil.
|
||||||
e.lhs.welcome(this);
|
e.lhs.welcome(this);
|
||||||
asm.cmp("q", 0, "%rax");
|
asm.cmp("q", 0, "%rax");
|
||||||
asm.jne(lblFalse);
|
asm.jne(lblFalse);
|
||||||
@@ -872,7 +874,7 @@ public class GenASM implements Visitor<Void> {
|
|||||||
|
|
||||||
e.expression.welcome(this);
|
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())) {
|
if (e.expression.type.equals(Type.getFloatType())) {
|
||||||
asm.mov("q", "%xmm0", "%rax");
|
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");
|
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.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
|
||||||
|
|
||||||
@@ -907,12 +909,12 @@ public class GenASM implements Visitor<Void> {
|
|||||||
asm.mov("sd", "%xmm2", "%xmm0");
|
asm.mov("sd", "%xmm2", "%xmm0");
|
||||||
asm.mov("sd", "%xmm2", "%xmm0");
|
asm.mov("sd", "%xmm2", "%xmm0");
|
||||||
return true;
|
return true;
|
||||||
} else if (lhsIsFloat && !rhsIsFloat) {
|
} else if (lhsIsFloat) {
|
||||||
lhs.welcome(this);
|
lhs.welcome(this);
|
||||||
rhs.welcome(this);
|
rhs.welcome(this);
|
||||||
asm.cvtsi2sd("%rax", "%xmm1");
|
asm.cvtsi2sd("%rax", "%xmm1");
|
||||||
return true;
|
return true;
|
||||||
} else if (!lhsIsFloat && rhsIsFloat) {
|
} else if (rhsIsFloat) {
|
||||||
lhs.welcome(this);
|
lhs.welcome(this);
|
||||||
asm.cvtsi2sd("%rax", "%xmm2");
|
asm.cvtsi2sd("%rax", "%xmm2");
|
||||||
rhs.welcome(this);
|
rhs.welcome(this);
|
||||||
|
|||||||
Reference in New Issue
Block a user