Skip to content
Snippets Groups Projects
Commit 5d693497 authored by Lukáš Korenčik's avatar Lukáš Korenčik
Browse files

bricks: Add function that loads bitcode from file.

parent ed76761f
No related branches found
No related tags found
No related merge requests found
...@@ -33,11 +33,15 @@ ...@@ -33,11 +33,15 @@
DIVINE_RELAX_WARNINGS DIVINE_RELAX_WARNINGS
#endif #endif
#include <llvm/IR/LLVMContext.h>
#include <llvm/IR/Module.h> #include <llvm/IR/Module.h>
#include <llvm/IR/Verifier.h> #include <llvm/IR/Verifier.h>
#include <llvm/IR/Constants.h> #include <llvm/IR/Constants.h>
#include <llvm/IR/Intrinsics.h> #include <llvm/IR/Intrinsics.h>
#include <llvm/Bitcode/BitcodeWriter.h> #include <llvm/Bitcode/BitcodeWriter.h>
#include <llvm/Bitcode/BitcodeReader.h>
#include <llvm/Object/IRObjectFile.h>
#include <llvm/Support/MemoryBuffer.h>
#include <llvm/Support/raw_ostream.h> #include <llvm/Support/raw_ostream.h>
#include <llvm/Support/raw_os_ostream.h> #include <llvm/Support/raw_os_ostream.h>
#include <llvm/Support/Error.h> #include <llvm/Support/Error.h>
...@@ -48,6 +52,8 @@ DIVINE_RELAX_WARNINGS ...@@ -48,6 +52,8 @@ DIVINE_RELAX_WARNINGS
DIVINE_UNRELAX_WARNINGS DIVINE_UNRELAX_WARNINGS
#endif #endif
#include <memory>
#include <brick-assert> #include <brick-assert>
#include <brick-string> #include <brick-string>
#include <brick-types> #include <brick-types>
...@@ -244,6 +250,25 @@ inline void writeModule( ::llvm::Module *m, std::string out ) { ...@@ -244,6 +250,25 @@ inline void writeModule( ::llvm::Module *m, std::string out ) {
WriteBitcodeToFile( *m, fs ); WriteBitcodeToFile( *m, fs );
} }
inline std::unique_ptr< ::llvm::Module > load_bc( const std::string &str,
::llvm::LLVMContext *ctx )
{
std::unique_ptr< ::llvm::MemoryBuffer > input =
std::move( ::llvm::MemoryBuffer::getFile( str ).get() );
auto bc_input =
::llvm::object::IRObjectFile::findBitcodeInMemBuffer( input->getMemBufferRef() );
if ( !bc_input )
UNREACHABLE( "Could not load bitcode file" );
auto module = ::llvm::parseBitcodeFile( bc_input.get(), *ctx );
if ( !module )
UNREACHABLE( "Error parsing input model; probably not a valid bc file." );
return std::move( module.get() );
}
inline std::string getModuleBytes( ::llvm::Module *m ) { inline std::string getModuleBytes( ::llvm::Module *m ) {
std::string s; std::string s;
verifyModule( *m ); verifyModule( *m );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment