[MIParser] Set RegClassOrRegBank during instruction parsing
[llvm-complete.git] / examples / LLJITExamples / ExampleModules.h
blobae0089fd9dd545533fb69687d9078b84149be63a
1 //===----- ExampleModules.h - IR modules for LLJIT examples -----*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Example modules for LLJIT examples
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_EXAMPLES_HOWTOUSELLJIT_EXAMPLEMODULES_H
14 #define LLVM_EXAMPLES_HOWTOUSELLJIT_EXAMPLEMODULES_H
16 #include "llvm/ADT/StringRef.h"
17 #include "llvm/ExecutionEngine/Orc/ThreadSafeModule.h"
18 #include "llvm/IR/LLVMContext.h"
19 #include "llvm/IR/Module.h"
20 #include "llvm/IRReader/IRReader.h"
21 #include "llvm/Support/Error.h"
22 #include "llvm/Support/SourceMgr.h"
24 const llvm::StringRef Add1Example =
25 R"(
26 define i32 @add1(i32 %x) {
27 entry:
28 %r = add nsw i32 %x, 1
29 ret i32 %r
31 )";
33 inline llvm::Expected<llvm::orc::ThreadSafeModule>
34 parseExampleModule(llvm::StringRef Source, llvm::StringRef Name) {
35 using namespace llvm;
36 using namespace llvm::orc;
38 auto Ctx = std::make_unique<LLVMContext>();
39 SMDiagnostic Err;
40 auto M = parseIR(MemoryBufferRef(Source, Name), Err, *Ctx);
42 if (!M) {
43 std::string ErrMsg;
45 raw_string_ostream ErrStream(ErrMsg);
46 Err.print("", ErrStream);
48 return make_error<StringError>(std::move(ErrMsg), inconvertibleErrorCode());
51 return ThreadSafeModule(std::move(M), std::move(Ctx));
54 #endif // LLVM_EXAMPLES_HOWTOUSELLJIT_EXAMPLEMODULES_H