Skip to content

Commit

Permalink
Refactor LLVM IR generator data members
Browse files Browse the repository at this point in the history
  • Loading branch information
leewei05 committed Jul 5, 2024
1 parent 6e50cce commit 353f4a9
Show file tree
Hide file tree
Showing 2 changed files with 132 additions and 134 deletions.
16 changes: 8 additions & 8 deletions include/llvm_ir_generator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,27 +59,27 @@ class LLVMIRGenerator : public NonModifyingVisitor {

LLVMIRGenerator(std::ostream& output, const std::string& filename)
: output_{output},
context_{std::make_unique<llvm::LLVMContext>()},
builder_{std::make_unique<llvm::IRBuilder<>>(*context_)},
module_{std::make_unique<llvm::Module>(filename, *context_)},
builder_helper_{util::LLVMIRBuilderHelper(*builder_)} {}
context_{},
builder_{llvm::IRBuilder<>(context_)},
module_{llvm::Module(filename, context_)},
builder_helper_{util::LLVMIRBuilderHelper(builder_)} {}

/// @brief Print LLVM IR to output.
void PrintIR() {
module_->print(output_, nullptr);
module_.print(output_, nullptr);
}

private:
/// @brief A LLVM ostream wrapper for writing to output.
llvm::raw_os_ostream output_;
/// @brief A LLVM object that includes core LLVM infrastructure.
std::unique_ptr<llvm::LLVMContext> context_;
llvm::LLVMContext context_;
/// @brief Provides LLVM Builder API for constructing IR. By default, Constant
/// folding is enabled and we have more flexibility for inserting
/// instructions.
std::unique_ptr<llvm::IRBuilder<>> builder_;
llvm::IRBuilder<> builder_;
/// @brief Stores global variables, function lists, and the constructed IR.
std::unique_ptr<llvm::Module> module_;
llvm::Module module_;
/// @brief Wrapping IR builder to provide handy LLVM types and functions for
/// IR generation.
util::LLVMIRBuilderHelper builder_helper_;
Expand Down
Loading

0 comments on commit 353f4a9

Please sign in to comment.