From 610cd8acdd18dd590c452a6846388d210371fdc8 Mon Sep 17 00:00:00 2001 From: Austin Adams Date: Sun, 30 Jun 2024 13:17:59 -0400 Subject: [PATCH] Add constructor for llvm::Module + entrypoint name This is useful when a user generates an llvm::Module that may have multiple entry points, as the Qwerty compiler/runtime does. --- src/qiree/Module.cc | 16 ++++++++++++++++ src/qiree/Module.hh | 3 +++ 2 files changed, 19 insertions(+) diff --git a/src/qiree/Module.cc b/src/qiree/Module.cc index 346e311..83d9703 100644 --- a/src/qiree/Module.cc +++ b/src/qiree/Module.cc @@ -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). diff --git a/src/qiree/Module.hh b/src/qiree/Module.hh index c6ceaed..fc7247c 100644 --- a/src/qiree/Module.hh +++ b/src/qiree/Module.hh @@ -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);