main
Odeinjul 11 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()) {
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<Ptr<Constant>> varInit;
@ -523,7 +524,8 @@ void IRBuilder::visit(SyntaxTree::VarDef &node) {
varInit.push_back(dynamic_pointer_cast<Constant>(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" <<std::endl;
//std::cout << "Block1" <<std::endl;
stmt->accept(*this);
//std::cout << "Block2" <<std::endl;
}
scope.exit();
return ;

Loading…
Cancel
Save