From dab3153471de35d1af0e333516aca2303b171a90 Mon Sep 17 00:00:00 2001 From: Odeinjul Date: Sat, 16 Dec 2023 20:54:41 +0800 Subject: [PATCH] Finish high dim array --- src/SysYFIRBuilder/IRBuilder.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/SysYFIRBuilder/IRBuilder.cpp b/src/SysYFIRBuilder/IRBuilder.cpp index 38f23d2..106570b 100644 --- a/src/SysYFIRBuilder/IRBuilder.cpp +++ b/src/SysYFIRBuilder/IRBuilder.cpp @@ -595,10 +595,21 @@ void IRBuilder::visit(SyntaxTree::VarDef &node) { identAlloca = dynamic_pointer_cast(tmpIdent); scope.push(node.name, identAlloca); auto varInit = constArrayInit.get(); + std::cout << arraySize << std::endl; + Ptr tmpZero; + if (varType->is_integer_type()) { + tmpZero = CONST_INT(0); + } else { + tmpZero = CONST_FLOAT(0.0); + } for (int i = 0u; i < arraySize; i++) { auto index = CONST_INT(i); auto ptr = builder->create_gep(identAlloca, {CONST_INT(0), index}); - builder->create_store((*varInit)[i], ptr); + if ((*varInit)[i] == nullptr) { + builder->create_store(tmpZero, ptr); + } else { + builder->create_store((*varInit)[i], ptr); + } } } }