From d9ce28b743012dd29c4bd195d6cbef0b370e531d Mon Sep 17 00:00:00 2001 From: Odeinjul Date: Thu, 14 Dec 2023 17:27:25 +0800 Subject: [PATCH] Modified something --- src/SysYFIRBuilder/IRBuilder.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/SysYFIRBuilder/IRBuilder.cpp b/src/SysYFIRBuilder/IRBuilder.cpp index 537c735..b4a3ab2 100644 --- a/src/SysYFIRBuilder/IRBuilder.cpp +++ b/src/SysYFIRBuilder/IRBuilder.cpp @@ -141,7 +141,7 @@ void IRBuilder::visit(SyntaxTree::Assembly &node) { // You need to fill them -// TODO +// FINISH void IRBuilder::visit(SyntaxTree::InitVal &node) { node.expr->accept(*this); } @@ -219,7 +219,6 @@ void IRBuilder::visit(SyntaxTree::FuncParam &node) { // TODO void IRBuilder::visit(SyntaxTree::VarDef &node) { - // TODOļ¼š high dim array (not now) int arrayLength; Ptr initVal; if (node.is_constant) { @@ -350,12 +349,20 @@ void IRBuilder::visit(SyntaxTree::VarDef &node) { } -// TODO +// FINISH void IRBuilder::visit(SyntaxTree::LVal &node) { auto ident = scope.find(node.name, false); if (!node.array_index.empty()) { - //TODO + node.array_index[0]->accept(*this); + auto constIndex = dynamic_pointer_cast(tmpInst); + auto globalIdent = dynamic_pointer_cast(ident); + if(globalIdent != nullptr && globalIdent->is_const() && constIndex == nullptr) { + auto arrayInit = dynamic_pointer_cast(globalIdent->get_init()); + tmpInst = arrayInit->get_element_value(constIndex->get_value()); + } else { + tmpInst = builder->create_gep(ident, {CONST_INT(0), tmpInst}); + } } else { if (ident->get_type()->is_pointer_type() && ident->get_type()->get_pointer_element_type()->is_array_type()) { @@ -364,7 +371,7 @@ void IRBuilder::visit(SyntaxTree::LVal &node) { tmpInst = ident; } } - isAddr = true; + return ; } // FINISH @@ -413,8 +420,6 @@ void IRBuilder::visit(SyntaxTree::BlockStmt &node) { scope.enter(); for (const auto &stmt : node.body) { stmt->accept(*this); - if (builder->get_insert_block()->get_terminator() != nullptr) - break; } scope.exit(); return ;