Skip to content

Commit

Permalink
Update for llvm api change.
Browse files Browse the repository at this point in the history
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@215968 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
espindola committed Aug 19, 2014
1 parent 9adb1ed commit 82abc10
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
28 changes: 15 additions & 13 deletions examples/clang-interpreter/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,35 +42,37 @@ std::string GetExecutablePath(const char *Argv0) {
return llvm::sys::fs::getMainExecutable(Argv0, MainAddr);
}

static llvm::ExecutionEngine *createExecutionEngine(llvm::Module *M,
std::string *ErrorStr) {
llvm::EngineBuilder EB = llvm::EngineBuilder(M)
.setUseMCJIT(true)
.setEngineKind(llvm::EngineKind::Either)
.setErrorStr(ErrorStr);
return EB.create();
static llvm::ExecutionEngine *
createExecutionEngine(std::unique_ptr<llvm::Module> M, std::string *ErrorStr) {
return llvm::EngineBuilder(std::move(M))
.setUseMCJIT(true)
.setEngineKind(llvm::EngineKind::Either)
.setErrorStr(ErrorStr)
.create();
}

static int Execute(llvm::Module *Mod, char * const *envp) {
static int Execute(std::unique_ptr<llvm::Module> Mod, char *const *envp) {
llvm::InitializeNativeTarget();
llvm::InitializeNativeTargetAsmPrinter();

llvm::Module &M = *Mod;
std::string Error;
std::unique_ptr<llvm::ExecutionEngine> EE(createExecutionEngine(Mod, &Error));
std::unique_ptr<llvm::ExecutionEngine> EE(
createExecutionEngine(std::move(Mod), &Error));
if (!EE) {
llvm::errs() << "unable to make execution engine: " << Error << "\n";
return 255;
}

llvm::Function *EntryFn = Mod->getFunction("main");
llvm::Function *EntryFn = M.getFunction("main");
if (!EntryFn) {
llvm::errs() << "'main' function not found in module.\n";
return 255;
}

// FIXME: Support passing arguments.
std::vector<std::string> Args;
Args.push_back(Mod->getModuleIdentifier());
Args.push_back(M.getModuleIdentifier());

EE->finalizeObject();
return EE->runFunctionAsMain(EntryFn, Args, envp);
Expand Down Expand Up @@ -163,8 +165,8 @@ int main(int argc, const char **argv, char * const *envp) {
return 1;

int Res = 255;
if (llvm::Module *Module = Act->takeModule())
Res = Execute(Module, envp);
if (std::unique_ptr<llvm::Module> &Module = Act->getModule())
Res = Execute(std::move(Module), envp);

// Shutdown.

Expand Down
6 changes: 3 additions & 3 deletions include/clang/CodeGen/CodeGenAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ class CodeGenAction : public ASTFrontendAction {
/// the action will load it from the specified file.
void setLinkModule(llvm::Module *Mod) { LinkModule = Mod; }

/// takeModule - Take the generated LLVM module, for use after the action has
/// been run. The result may be null on failure.
llvm::Module *takeModule();
/// Take the generated LLVM module, for use after the action has been run.
/// The result may be null on failure.
std::unique_ptr<llvm::Module> &getModule() { return TheModule; }

/// Take the LLVM context used by this action.
llvm::LLVMContext *takeLLVMContext();
Expand Down
2 changes: 0 additions & 2 deletions lib/CodeGen/CodeGenAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -579,8 +579,6 @@ void CodeGenAction::EndSourceFileAction() {
TheModule.reset(BEConsumer->takeModule());
}

llvm::Module *CodeGenAction::takeModule() { return TheModule.release(); }

llvm::LLVMContext *CodeGenAction::takeLLVMContext() {
OwnsVMContext = false;
return VMContext;
Expand Down

0 comments on commit 82abc10

Please sign in to comment.