Commit 391da1d4 authored by zygzagZ's avatar zygzagZ

Fix var names, alloc from VariablePtr doesn't maintain VarInfoPtr, fix

set* operand sizes
parent c34a692b
......@@ -351,9 +351,12 @@ void Compiler::generateQJumpCond(QJumpCond &q) {
auto tgBlock = q.target->block;
const auto &map = tgBlock->getPhiMapping(thisBlock);
for (const auto &phiVars : map) {
// if (Register(phiVars.first) != Register(phiVars.second)) {
if ((phiVars.first->info && phiVars.second->info && phiVars.first->info != phiVars.second->info) ||
(phiVars.first->localOffset && phiVars.second->localOffset && phiVars.first->localOffset != phiVars.second->localOffset) ||
(phiVars.first->registerColor && phiVars.second->registerColor && phiVars.first->registerColor != phiVars.second->registerColor)
) {
buf << ("// Unimplemented phi CondJump register XCHG\n");
// }
}
}
auto op = q.op;
if (q.left) { // 2 args
......@@ -374,20 +377,16 @@ void Compiler::generateQJumpCond(QJumpCond &q) {
string operand = getOpName(op);
// getOpName returns SETZ, SETNE, SET*, replace it to JMP
operand.replace(0,3, "J");
// if (operand == "SETZ" || operand == "SETNZ") {
//
// } else {
// operand.replace(0,3, "JMP");
// }
append(operand, getBlockLabelText(q.target));
}
void Compiler::generateQAssign(QAssign &q) {
if (!q.aliveAfter.count(q.loc) || q.loc->constExpr) return;
Register tg(q.loc);
auto op = q.op;
if (q.args.size() == 1) {
auto &arg = q.args[0];
switch (q.op.op) {
switch (op.op) {
case Op::Not: {
auto reg = Register(arg);
if (reg == 0) {
......@@ -395,8 +394,8 @@ void Compiler::generateQAssign(QAssign &q) {
moveTo(arg, tg);
reg = tg;
}
// append("CMP", "$1", reg); // dziala
append("TEST", reg, reg);
append("SETZ", tg);
break;
}
case Op::Copy: {
......@@ -417,7 +416,7 @@ void Compiler::generateQAssign(QAssign &q) {
}
} else {
auto &i = q.args[0], &j = q.args[1];
if (q.op == Op::Div || q.op == Op::Mod) {
if (op == Op::Div || op == Op::Mod) {
auto edx = Register("edx");
auto alives = to_set(aliveAfter(q, Register::assignable));
......@@ -441,38 +440,40 @@ void Compiler::generateQAssign(QAssign &q) {
moveTo(i, 0);
append("CLTD"); // edx lost
append("IDIVL", jLoc);
append("MOVL", q.op == Op::Mod ? edx : 0, getRef(q.loc));
append("MOVL", op == Op::Mod ? edx : 0, getRef(q.loc));
// restore unnecessary if j was in edx and becomes dead and was NOT coalesced
// not easy to check if not coalesced, so move anyway
if (backupEdx && edxAlive) append("MOVL", "-4(%esp)", edx);
return;
} else if (q.op.kind() == Op::CMP) {
auto op = generateCmp(i, q.op, j);
if ((int) tg < 4) { // eax - edx
append("MOVL", "$0", tg);
string s = "%AL";
s[1] = ((string)tg)[2];
append(op, s);
} else {
append("MOVL", "$0", "%EAX");
append(op, "%AL");
append("MOVL", "%EAX", tg);
}
} else if (op.kind() == Op::CMP) {
op = generateCmp(i, op, j);
} else {
assert(q.op.kind() == Op::BINARY);
assert(op.kind() == Op::BINARY);
bool swapped = false;
if (Register(j) == tg && tg != 0) {
swapped = true;
swap(i, j);
}
moveTo(i, tg);
append(q.op, getRef(j), tg);
append(op, getRef(j), tg);
if (swapped) {
if (q.op == Op::Minus)
if (op == Op::Minus)
append("NEG", tg);
}
}
}
if (op.boolean()) {
if ((int) tg < 4) { // EAX - EDX
append("MOVL", "$0", tg);
string s = "%?l";
s[1] = ((string)tg)[2];
append(op, s);
} else { // EDI/ESI
append("MOVL", "$0", "%eax");
append(op, "%al");
append("MOVL", "%eax", tg);
}
}
if (tg == 0) {
append("MOVL", tg, getRef(q.loc));
}
......
......@@ -49,6 +49,10 @@ public:
return op;
}
bool boolean() const {
return kind() == CMP || op == Op::Not;
}
static OpType kind(OpType op) {
if (op <= UNARY_END) return UNARY;
if (op <= BINARY_END) return BINARY;
......
......@@ -10,7 +10,7 @@
class Variable : std::enable_shared_from_this<Variable> {
public:
Variable() = default;
explicit Variable(const VariablePtr &v) : info(v->info), type(v->type), constExpr(v->constExpr), val(v->val) {};
explicit Variable(const VariablePtr &v) : type(v->type), constExpr(v->constExpr), val(v->val) {};
explicit Variable(TypePtr t) : type(std::move(t)) {};
explicit Variable(Type *t) : type(t) {};
explicit Variable(VarInfoPtr i) : info(std::move(i)), type(info->type) {};
......
......@@ -20,7 +20,7 @@ make -j8 && for i in lat/lattests/good/*.lat; do
exit 1;
fi
if ! diff <( ${i%.*} ) "${i%.*}.output"; then
if ! diff <( timeout 2 ${i%.*} ) "${i%.*}.output"; then
red "ERROR $i"
exit 1
fi
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment