main
Odeinjul 12 months ago
parent 024aad74f2
commit 52ae9de107
No known key found for this signature in database
GPG Key ID: E384228B2B38FFBB

@ -498,16 +498,17 @@ void IRBuilder::visit(SyntaxTree::VarDef &node) {
if (node.is_constant && node.array_length.empty()) { if (node.is_constant && node.array_length.empty()) {
node.initializers->expr->accept(*this); node.initializers->expr->accept(*this);
TypeConvert(tmpInst, varType); TypeConvert(tmpInst, varType);
identAlloca = tmpInst; scope.push(node.name, tmpInst);
scope.push(node.name, identAlloca); //builder->create_store(tmpInst, identAlloca);
return ;
} else { } else {
identAlloca = builder->create_alloca(varType);
scope.push(node.name, identAlloca);
if (node.array_length.empty()) { if (node.array_length.empty()) {
node.initializers->expr->accept(*this); identAlloca = builder->create_alloca(varType);
TypeConvert(tmpInst, varType); scope.push(node.name, identAlloca);
builder->create_store(tmpInst, identAlloca); if (node.is_inited) {
node.initializers->expr->accept(*this);
TypeConvert(tmpInst, varType);
builder->create_store(tmpInst, identAlloca);
}
return ; return ;
} else { } else {
std::vector<Ptr<Constant>> varInit; std::vector<Ptr<Constant>> varInit;
@ -523,7 +524,8 @@ void IRBuilder::visit(SyntaxTree::VarDef &node) {
varInit.push_back(dynamic_pointer_cast<Constant>(tmpInst)); varInit.push_back(dynamic_pointer_cast<Constant>(tmpInst));
} }
auto zeroInit = ConstantZero::create(varType, module); 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++) { for (int i = 0; i < varInit.size(); i++) {
auto index = CONST_INT(i); auto index = CONST_INT(i);
auto ptr = builder->create_gep(identAlloca, {CONST_INT(0), index}); 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) { void IRBuilder::visit(SyntaxTree::BlockStmt &node) {
scope.enter(); scope.enter();
for (const auto &stmt : node.body) { for (const auto &stmt : node.body) {
//std::cout << "Block" <<std::endl; //std::cout << "Block1" <<std::endl;
stmt->accept(*this); stmt->accept(*this);
//std::cout << "Block2" <<std::endl;
} }
scope.exit(); scope.exit();
return ; return ;

Loading…
Cancel
Save