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/Manager.h b/clang/examples/clang-interpreter/Manager.h
new file mode 100644
index 0000000..d1b1461
--- /dev/null
+++ b/clang/examples/clang-interpreter/Manager.h
@@ -0,0 +1,59 @@
+//===-- examples/clang-interpreter/Manager.h - 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.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef CLANG_EXAMPLE_INTERPRETER_MANAGER_H
+#define CLANG_EXAMPLE_INTERPRETER_MANAGER_H
+
+#include "llvm/ExecutionEngine/SectionMemoryManager.h"
+
+#if defined(LLVM_ON_WIN32) && defined(_WIN64)
+#define CLANG_INTERPRETER_COFF_FORMAT
+#define CLANG_INTERPRETER_WIN_EXCEPTIONS
+#endif
+
+namespace interpreter {
+
+class SingleSectionMemoryManager : public llvm::SectionMemoryManager {
+  struct Block {
+    uint8_t *Addr = nullptr, *End = nullptr;
+    void Reset(uint8_t *Ptr, uintptr_t Size);
+    uint8_t *Next(uintptr_t Size, unsigned Alignment);
+  };
+  Block Code, ROData, RWData;
+
+public:
+  uint8_t *allocateCodeSection(uintptr_t Size, unsigned Align, unsigned ID,
+                               llvm::StringRef Name) final;
+
+  uint8_t *allocateDataSection(uintptr_t Size, unsigned Align, unsigned ID,
+                               llvm::StringRef Name, bool RO) final;
+
+  void reserveAllocationSpace(uintptr_t CodeSize, uint32_t CodeAlign,
+                              uintptr_t ROSize, uint32_t ROAlign,
+                              uintptr_t RWSize, uint32_t RWAlign) final;
+
+  bool needsToReserveAllocationSpace() override { return true; }
+
+#ifdef CLANG_INTERPRETER_WIN_EXCEPTIONS
+  using llvm::SectionMemoryManager::EHFrameInfos;
+
+  SingleSectionMemoryManager();
+
+  void deregisterEHFrames() override;
+
+  bool finalizeMemory(std::string *ErrMsg) override;
+
+private:
+  uintptr_t ImageBase = 0;
+#endif
+};
+
+}
+
+#endif // CLANG_EXAMPLE_INTERPRETER_MANAGER_H