Expand clang-interpreter with example of throwing in and from the JIT for Windows64.
Summary:
Getting this to work is not particularly obvious, and having it as an example should be helpful.
Portions of this could be placed into LLVM, but as a whole it seems necessary to do this a higher level.
Reviewers: lhames, mehdi_amini
Reviewed By: lhames
Subscribers: mgrang, martell, cfe-commits, mgorny
Differential Revision: https://reviews.llvm.org/D35103
llvm-svn: 327528
diff --git a/clang/examples/clang-interpreter/Invoke.cpp b/clang/examples/clang-interpreter/Invoke.cpp
new file mode 100644
index 0000000..90afa01
--- /dev/null
+++ b/clang/examples/clang-interpreter/Invoke.cpp
@@ -0,0 +1,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;
+}
+
+}