Skip to content

Commit

Permalink
allocate new LLVMContext per Lua global state
Browse files Browse the repository at this point in the history
  • Loading branch information
Dibyendu Majumdar committed Sep 6, 2015
1 parent 2da4a33 commit d2fbb17
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions include/ravi_llvmcodegen.h
Expand Up @@ -374,7 +374,7 @@ class RAVI_API RaviJITStateImpl : public RaviJITState {
// map of names to functions
std::map<std::string, RaviJITFunction *> functions_;

llvm::LLVMContext &context_;
llvm::LLVMContext *context_;

// The triple represents the host target
std::string triple_;
Expand Down Expand Up @@ -420,7 +420,7 @@ class RAVI_API RaviJITStateImpl : public RaviJITState {
void addGlobalSymbol(const std::string &name, void *address);

virtual void dump();
virtual llvm::LLVMContext &context() { return context_; }
virtual llvm::LLVMContext &context() { return *context_; }
LuaLLVMTypes *types() const { return types_; }
const std::string &triple() const { return triple_; }
bool is_auto() const { return auto_; }
Expand Down
6 changes: 4 additions & 2 deletions src/ravi_llvmjit.cpp
Expand Up @@ -42,7 +42,7 @@ RaviJITState *RaviJITFunctionImpl::owner() const { return owner_; }
// lua_State - all compilation activity happens
// in the context of the JIT State
RaviJITStateImpl::RaviJITStateImpl()
: context_(llvm::getGlobalContext()), auto_(false), enabled_(true),
: auto_(false), enabled_(true),
opt_level_(2), size_level_(0), min_code_size_(150), min_exec_count_(50),
gc_step_(200) {
// LLVM needs to be initialized else
Expand All @@ -64,7 +64,8 @@ RaviJITStateImpl::RaviJITStateImpl()
// format; LLVM 3.7 onwards COEFF is supported
triple_ += "-elf";
#endif
types_ = new LuaLLVMTypes(context_);
context_ = new llvm::LLVMContext();
types_ = new LuaLLVMTypes(*context_);
}

// Destroy the JIT state freeing up any
Expand All @@ -79,6 +80,7 @@ RaviJITStateImpl::~RaviJITStateImpl() {
delete todelete[i];
}
delete types_;
delete context_;
}

void RaviJITStateImpl::addGlobalSymbol(const std::string &name, void *address) {
Expand Down

0 comments on commit d2fbb17

Please sign in to comment.