1#ifndef CPPAD_CG_LLVM_MODEL_LIBRARY_PROCESSOR_INCLUDED
2#define CPPAD_CG_LLVM_MODEL_LIBRARY_PROCESSOR_INCLUDED
19#include <cppad/cg/model/llvm/llvm_base_model_library_processor.hpp>
30class LlvmModelLibraryProcessor :
public LlvmBaseModelLibraryProcessor<Base> {
32 const std::string _version;
33 std::vector<std::string> _includePaths;
34 std::unique_ptr<llvm::Linker> _linker;
35 std::unique_ptr<llvm::LLVMContext> _context;
56 inline void setIncludePaths(
const std::vector<std::string>&
includePaths) {
60 inline const std::vector<std::string>& getIncludePaths()
const {
64 std::unique_ptr<LlvmModelLibrary<Base>> create() {
77 std::unique_ptr<LlvmModelLibrary<Base>>
lib;
79 this->modelLibraryHelper_->startingJob(
"", JobTimer::JIT_MODEL_LIBRARY);
90 llvm::InitializeAllTargets();
91 llvm::InitializeAllAsmPrinters();
93 _context.reset(
new llvm::LLVMContext());
100 if (
buffer.get() ==
nullptr)
105 Module*
module = llvm::ParseBitcodeFile(buffer.get(), *_context.get(), &errMsg);
110 if (_linker.get() ==
nullptr) {
111 _linker.reset(
new llvm::Linker(
module));
119 llvm::InitializeNativeTarget();
130 this->modelLibraryHelper_->finishedJob();
147 using namespace llvm;
148 using namespace clang;
156 static const char*
argv [] = {
"program",
"-Wall",
"-x",
"c",
"string-input"};
157 static const int argc =
sizeof (
argv) /
sizeof (
argv[0]);
168 throw CGException(
"Failed to create compiler invocation");
169 CompilerInvocation::setLangDefaults(*
invocation->getLangOpts(),
IK_C,
170 LangStandard::lang_unspecified);
171 invocation->getFrontendOpts().DisableFree =
false;
180 throw CGException(
"No diagnostics");
183 llvm::MemoryBuffer *
buffer = llvm::MemoryBuffer::getMemBufferCopy(
source,
"SIMPLE_BUFFER");
185 throw CGException(
"Failed to create memory buffer");
189 po.addRemappedFile(
"string-input",
buffer);
192 for (
size_t s = 0; s < _includePaths.size(); s++)
193 hso.AddPath(llvm::StringRef(_includePaths[s]), clang::frontend::Angled,
true,
false);
199 throw CGException(
"Failed to emit LLVM bitcode");
201 llvm::Module*
module = action->takeModule();
203 throw CGException(
"No module");
const std::set< std::string > & createBitCode(ClangCompiler< Base > &clang, const std::string &version)
std::unique_ptr< LlvmModelLibrary< Base > > create(ClangCompiler< Base > &clang)
LlvmModelLibraryProcessor(ModelLibraryCSourceGen< Base > &modelLibraryHelper)
const std::string & getVersion() const
bool GreaterThanZero(const cg::CG< Base > &x)