Make test more lenient for custom clang version strings
[llvm-project.git] / llvm / examples / OrcV2Examples / LLJITDumpObjects / LLJITDumpObjects.cpp
blobc3752cc36c060c4591619febe92f7ae9c3144b63
1 //===----- LLJITDumpObjects.cpp - How to dump JIT'd objects with LLJIT ----===//
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 //===----------------------------------------------------------------------===//
9 #include "llvm/ADT/StringMap.h"
10 #include "llvm/ExecutionEngine/Orc/DebugUtils.h"
11 #include "llvm/ExecutionEngine/Orc/LLJIT.h"
12 #include "llvm/ExecutionEngine/Orc/ObjectTransformLayer.h"
13 #include "llvm/Support/InitLLVM.h"
14 #include "llvm/Support/TargetSelect.h"
15 #include "llvm/Support/raw_ostream.h"
17 #include "../ExampleModules.h"
19 using namespace llvm;
20 using namespace llvm::orc;
22 ExitOnError ExitOnErr;
24 cl::opt<bool> DumpJITdObjects("dump-jitted-objects",
25 cl::desc("dump jitted objects"), cl::Optional,
26 cl::init(true));
28 cl::opt<std::string> DumpDir("dump-dir",
29 cl::desc("directory to dump objects to"),
30 cl::Optional, cl::init(""));
32 cl::opt<std::string> DumpFileStem("dump-file-stem",
33 cl::desc("Override default dump names"),
34 cl::Optional, cl::init(""));
36 int main(int argc, char *argv[]) {
37 // Initialize LLVM.
38 InitLLVM X(argc, argv);
40 InitializeNativeTarget();
41 InitializeNativeTargetAsmPrinter();
43 cl::ParseCommandLineOptions(argc, argv, "LLJITDumpObjects");
44 ExitOnErr.setBanner(std::string(argv[0]) + ": ");
46 outs()
47 << "Usage notes:\n"
48 " Use -debug-only=orc on debug builds to see log messages of objects "
49 "being dumped\n"
50 " Specify -dump-dir to specify a dump directory\n"
51 " Specify -dump-file-stem to override the dump file stem\n"
52 " Specify -dump-jitted-objects=false to disable dumping\n";
54 auto J = ExitOnErr(LLJITBuilder().create());
56 if (DumpJITdObjects)
57 J->getObjTransformLayer().setTransform(DumpObjects(DumpDir, DumpFileStem));
59 auto M = ExitOnErr(parseExampleModule(Add1Example, "add1"));
61 ExitOnErr(J->addIRModule(std::move(M)));
63 // Look up the JIT'd function, cast it to a function pointer, then call it.
64 auto Add1Addr = ExitOnErr(J->lookup("add1"));
65 int (*Add1)(int) = Add1Addr.toPtr<int(int)>();
67 int Result = Add1(42);
68 outs() << "add1(42) = " << Result << "\n";
70 return 0;