From 52ae9de10774b6f45cfa54c551922b1bb5c5dd53 Mon Sep 17 00:00:00 2001 From: Odeinjul Date: Fri, 15 Dec 2023 15:40:28 +0800 Subject: [PATCH] Pass 1-17 --- src/SysYFIRBuilder/IRBuilder.cpp | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/SysYFIRBuilder/IRBuilder.cpp b/src/SysYFIRBuilder/IRBuilder.cpp index 149a1e8..63117eb 100644 --- a/src/SysYFIRBuilder/IRBuilder.cpp +++ b/src/SysYFIRBuilder/IRBuilder.cpp @@ -498,16 +498,17 @@ void IRBuilder::visit(SyntaxTree::VarDef &node) { if (node.is_constant && node.array_length.empty()) { node.initializers->expr->accept(*this); TypeConvert(tmpInst, varType); - identAlloca = tmpInst; - scope.push(node.name, identAlloca); - return ; + scope.push(node.name, tmpInst); + //builder->create_store(tmpInst, identAlloca); } else { - identAlloca = builder->create_alloca(varType); - scope.push(node.name, identAlloca); if (node.array_length.empty()) { - node.initializers->expr->accept(*this); - TypeConvert(tmpInst, varType); - builder->create_store(tmpInst, identAlloca); + identAlloca = builder->create_alloca(varType); + scope.push(node.name, identAlloca); + if (node.is_inited) { + node.initializers->expr->accept(*this); + TypeConvert(tmpInst, varType); + builder->create_store(tmpInst, identAlloca); + } return ; } else { std::vector> varInit; @@ -523,7 +524,8 @@ void IRBuilder::visit(SyntaxTree::VarDef &node) { varInit.push_back(dynamic_pointer_cast(tmpInst)); } auto zeroInit = ConstantZero::create(varType, module); - identAlloca = GlobalVariable::create(node.name, module, arrayType, false, zeroInit); + identAlloca = builder->create_alloca(arrayType); + scope.push(node.name, identAlloca); for (int i = 0; i < varInit.size(); i++) { auto index = CONST_INT(i); auto ptr = builder->create_gep(identAlloca, {CONST_INT(0), index}); @@ -602,8 +604,9 @@ void IRBuilder::visit(SyntaxTree::ReturnStmt &node) { void IRBuilder::visit(SyntaxTree::BlockStmt &node) { scope.enter(); for (const auto &stmt : node.body) { - //std::cout << "Block" <accept(*this); + //std::cout << "Block2" <