Commit 75ea8c19 authored by zygzagZ's avatar zygzagZ

Fix tables

parent e4d71bee
...@@ -312,7 +312,6 @@ void QuadrupleGenerator::visitEOr(EOr *p) { ...@@ -312,7 +312,6 @@ void QuadrupleGenerator::visitEOr(EOr *p) {
void QuadrupleGenerator::visitEIndexAcc(EIndexAcc *p) { void QuadrupleGenerator::visitEIndexAcc(EIndexAcc *p) {
auto lhs = evalExpr(p->expr_1); auto lhs = evalExpr(p->expr_1);
auto index = evalExpr(p->expr_2); auto index = evalExpr(p->expr_2);
lastVar = alloc();
auto type = dynamic_pointer_cast<Array>(lhs->type); auto type = dynamic_pointer_cast<Array>(lhs->type);
if (!type) { if (!type) {
throw ParseError("compiler evalExpr Variable has no Array type", p->expr_1); throw ParseError("compiler evalExpr Variable has no Array type", p->expr_1);
...@@ -320,11 +319,12 @@ void QuadrupleGenerator::visitEIndexAcc(EIndexAcc *p) { ...@@ -320,11 +319,12 @@ void QuadrupleGenerator::visitEIndexAcc(EIndexAcc *p) {
if (!type->type_) { if (!type->type_) {
throw ParseError("compiler evalExpr Variable is Array of no type", p->expr_1); throw ParseError("compiler evalExpr Variable is Array of no type", p->expr_1);
} }
lastVar = alloc(type->type_->clone());
lastVar->memory = true;
if (type->type_->size() > 4) { if (type->type_->size() > 4) {
// calculate quantifier, we multiply index because size is larger than 4 // calculate quantifier, we multiply index because size is larger than 4
auto q = alloc(type->type_->size()); auto q = alloc(type->type_->size());
auto newIndex = alloc(); auto newIndex = alloc();
// calculate var = index * quantifier // calculate var = index * quantifier
addQuad<QAssign>(newIndex, index, Op::Mul, q); addQuad<QAssign>(newIndex, index, Op::Mul, q);
...@@ -423,7 +423,7 @@ void QuadrupleGenerator::visitENewArray(ENewArray *p) { ...@@ -423,7 +423,7 @@ void QuadrupleGenerator::visitENewArray(ENewArray *p) {
virtSymbol = Compiler::getVirtName(info); virtSymbol = Compiler::getVirtName(info);
} }
auto count = evalExpr(p->expr_); auto count = evalExpr(p->expr_);
lastVar = alloc(); lastVar = alloc(new Array(type->clone()));
addQuad<QAlloc>(lastVar, size, virtSymbol, count); addQuad<QAlloc>(lastVar, size, virtSymbol, count);
} }
...@@ -459,7 +459,7 @@ void QuadrupleGenerator::visitNoInit(Init *p) { ...@@ -459,7 +459,7 @@ void QuadrupleGenerator::visitNoInit(Init *p) {
void QuadrupleGenerator::assign(Expr* lval, VariablePtr val) { void QuadrupleGenerator::assign(Expr* lval, VariablePtr val) {
auto dest = evalLVal(lval); auto dest = evalLVal(lval);
if (dest->info && dest->info->isInstanceVariable()) { if (dest->isInstanceVariable()) {
// instance variable, need to write it to memory // instance variable, need to write it to memory
auto quad = dynamic_pointer_cast<QAccess>(lastQuad); auto quad = dynamic_pointer_cast<QAccess>(lastQuad);
assert(quad); assert(quad);
......
...@@ -23,8 +23,9 @@ public: ...@@ -23,8 +23,9 @@ public:
int val{0}; int val{0};
std::string name; std::string name;
int registerColor = 0; int registerColor = 0;
bool memory = false;
bool isInstanceVariable() const { return info && info->isInstanceVariable(); } bool isInstanceVariable() const { return memory || (info && info->isInstanceVariable()); }
vector<QuadruplePtr> uses; vector<QuadruplePtr> uses;
vector<QuadruplePtr> writes; vector<QuadruplePtr> writes;
......
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