Skip to content

Commit

Permalink
Add constructor for llvm::Module + entrypoint name
Browse files Browse the repository at this point in the history
This is useful when a user generates an llvm::Module that may have
multiple entry points, as the Qwerty compiler/runtime does.
  • Loading branch information
ausbin committed Oct 8, 2024
1 parent aef6406 commit 8e55e78
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/qiree/Module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,22 @@ Module::Module(UPModule&& module) : module_{std::move(module)}
<< module_->getSourceFileName() << "'");
}

//---------------------------------------------------------------------------//
/*!
* Construct with an LLVM module and an entry point.
*/
Module::Module(UPModule&& module, std::string const& entrypoint)
: module_{std::move(module)}
{
QIREE_EXPECT(module_);

// Search for explicitly named entry point
entrypoint_ = module_->getFunction(entrypoint);
QIREE_VALIDATE(entrypoint_,
<< "no entrypoint function '" << entrypoint << "' exists");
}


//---------------------------------------------------------------------------//
/*!
* Construct with an LLVM IR file (bitcode or disassembled).
Expand Down
3 changes: 3 additions & 0 deletions src/qiree/Module.hh
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ class Module
// Construct from an externally created LLVM module
explicit Module(UPModule&& module);

// Construct from an externally created LLVM module and an entry point
explicit Module(UPModule&& module, std::string const& entrypoint);

// Construct with an LLVM IR file (bitcode or disassembled)
explicit Module(std::string const& filename);

Expand Down

0 comments on commit 8e55e78

Please sign in to comment.