summaryrefslogtreecommitdiffstats
path: root/clang/examples/clang-interpreter/Invoke.cpp
blob: 90afa0146b1b3869f2883f32ead22dc0f6ee98a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//==-- examples/clang-interpreter/Invoke.cpp - Clang C Interpreter Example -==//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#include "Invoke.h"

#include <iostream>
#include <stdexcept>

namespace interpreter {

int TryIt(llvm::ExecutionEngine *EE, llvm::Function *EntryFn,
          const std::vector<std::string> &Args, char *const *EnvP,
          Invoker Invoke) {
  int Res = -1;
  try {
    Res = Invoke(EE, EntryFn, Args, EnvP);
  } catch (const std::exception &E) {
    std::cout << "Caught '" << E.what() << "'\n";
  } catch (...) {
    std::cout << "Unknown exception\n";
  }
  return Res;
}

}
OpenPOWER on IntegriCloud