Use raw pointers for BBs

This commit is contained in:
Sofia 2026-04-09 16:05:04 +03:00
parent 89db646873
commit 9969ad12f6
2 changed files with 6 additions and 7 deletions

View File

@ -26,7 +26,7 @@ namespace AST {
if (!builder.block) if (!builder.block)
return; return;
builder.builder->SetInsertPoint(builder.block.get()); builder.builder->SetInsertPoint(builder.block);
auto value = this->m_expr->codegen(builder, scope); auto value = this->m_expr->codegen(builder, scope);
builder.builder->CreateRet(value); builder.builder->CreateRet(value);
@ -36,7 +36,7 @@ namespace AST {
if (!builder.block) if (!builder.block)
return; return;
builder.builder->SetInsertPoint(builder.block.get()); builder.builder->SetInsertPoint(builder.block);
auto ty = this->m_type->codegen(builder, scope); auto ty = this->m_type->codegen(builder, scope);
auto ptr = builder.builder->CreateAlloca(ty); auto ptr = builder.builder->CreateAlloca(ty);
@ -62,8 +62,8 @@ namespace AST {
this->m_name, this->m_name,
builder.mod.get() builder.mod.get()
); );
auto BB = std::unique_ptr<llvm::BasicBlock>{ llvm::BasicBlock::Create(*builder.context, "entry", function, nullptr) }; auto BB = llvm::BasicBlock::Create(*builder.context, "entry", function, nullptr);
builder.block = std::move(BB); builder.block = BB;
for (auto& statement : this->m_statements) { for (auto& statement : this->m_statements) {
statement->codegen(builder, inner_scope); statement->codegen(builder, inner_scope);
@ -71,8 +71,7 @@ namespace AST {
llvm::verifyFunction(*function); llvm::verifyFunction(*function);
// unique_ptr is not really supposed to free the block builder.block = nullptr;
builder.block.release();
} }
llvm::Type* FundamentalType::codegen(codegen::Builder& builder, codegen::Scope& scope) { llvm::Type* FundamentalType::codegen(codegen::Builder& builder, codegen::Scope& scope) {

View File

@ -11,7 +11,7 @@ namespace codegen {
std::unique_ptr<llvm::LLVMContext> context; std::unique_ptr<llvm::LLVMContext> context;
std::unique_ptr<llvm::Module> mod; std::unique_ptr<llvm::Module> mod;
std::unique_ptr<llvm::IRBuilder<>> builder; std::unique_ptr<llvm::IRBuilder<>> builder;
std::unique_ptr<llvm::BasicBlock> block; llvm::BasicBlock* block;
}; };
struct StackValue { struct StackValue {