Commit c2ff1508 authored by Jaikrishnan Menon's avatar Jaikrishnan Menon

Codegen: Minor cleanup

parent 4ecdb791
...@@ -12,8 +12,6 @@ ...@@ -12,8 +12,6 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
#include <iostream>
#include <clang/CodeGen/ObjectFilePCHContainerOperations.h> #include <clang/CodeGen/ObjectFilePCHContainerOperations.h>
#include <clang/Driver/DriverDiagnostic.h> #include <clang/Driver/DriverDiagnostic.h>
#include <clang/Driver/Options.h> #include <clang/Driver/Options.h>
...@@ -150,40 +148,31 @@ std::unique_ptr<llvm::Module> execution_state::compile(const string& source, con ...@@ -150,40 +148,31 @@ std::unique_ptr<llvm::Module> execution_state::compile(const string& source, con
bool execution_state::add_module(std::unique_ptr<llvm::Module>& module) bool execution_state::add_module(std::unique_ptr<llvm::Module>& module)
{ {
bool rc = false;
if (module) if (module)
{ {
rc = true;
if (!m_execution_engine) if (!m_execution_engine)
{ {
std::string jit_error_string;
// auto mm = unique_ptr<RTDyldMemoryManager>(new method_resolver(this)); // auto mm = unique_ptr<RTDyldMemoryManager>(new method_resolver(this));
m_execution_engine = llvm::EngineBuilder(move(module)) m_execution_engine = llvm::EngineBuilder(move(module))
.setEngineKind(llvm::EngineKind::JIT) .setEngineKind(llvm::EngineKind::JIT)
.setOptLevel(llvm::CodeGenOpt::Aggressive) .setOptLevel(llvm::CodeGenOpt::Aggressive)
.setErrorStr(&jit_error_string) .setErrorStr(&jit_error)
// .setUseMCJIT(true) // .setUseMCJIT(true)
// .setMCJITMemoryManager(std::move(mm)) // .setMCJITMemoryManager(std::move(mm))
.create(); .create();
if (m_execution_engine) if (!m_execution_engine)
{
}
else
{ {
cout << "nullptr engine\n"; return false;
cout << jit_error_string << endl;
rc = false;
} }
} }
} }
else else
{ {
cout << "nullptr module\n"; return false;
rc = false;
} }
return rc; return true;
} }
void execution_state::finalize() void execution_state::finalize()
...@@ -195,6 +184,8 @@ void execution_state::finalize() ...@@ -195,6 +184,8 @@ void execution_state::finalize()
} }
else else
{ {
throw std::runtime_error("must add_module before finalize"); throw std::runtime_error(
"Error in finalize: " +
(jit_error.empty() ? "Could not create an execution engine" : jit_error));
} }
} }
...@@ -14,6 +14,10 @@ ...@@ -14,6 +14,10 @@
#pragma once #pragma once
#include <functional>
#include <memory>
#include <string>
#include <llvm/ExecutionEngine/MCJIT.h> // forces JIT to link in #include <llvm/ExecutionEngine/MCJIT.h> // forces JIT to link in
#include <llvm/ExecutionEngine/SectionMemoryManager.h> #include <llvm/ExecutionEngine/SectionMemoryManager.h>
#include <llvm/Option/Arg.h> #include <llvm/Option/Arg.h>
...@@ -56,6 +60,7 @@ public: ...@@ -56,6 +60,7 @@ public:
private: private:
llvm::ExecutionEngine* m_execution_engine; llvm::ExecutionEngine* m_execution_engine;
std::string jit_error;
template <typename signature> template <typename signature>
std::function<signature> f_cast(void* f) std::function<signature> f_cast(void* f)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment