19
19
20
20
using namespace llvm ;
21
21
22
+ // A type encapsulating simple Orc JIT functionality. Loosely based on the
23
+ // KaleidoscopeJIT example in the LLVM tree. Doesn't support cross-module
24
+ // symbol resolution; this JIT is best used with just a single module.
22
25
class SimpleOrcJIT {
23
26
public:
24
27
// This sample doesn't implement on-request or lazy compilation. It therefore
@@ -34,10 +37,11 @@ class SimpleOrcJIT {
34
37
SimpleOrcJIT ()
35
38
: TM(EngineBuilder().selectTarget()), DL(TM->createDataLayout ()),
36
39
CompileLayer(ObjectLayer, orc::SimpleCompiler(*TM)) {
37
- std::string s;
38
- llvm::sys::DynamicLibrary::LoadLibraryPermanently (nullptr , &s);
39
- errs () << " $$ error from loading: " << s << " \n " ;
40
- }
40
+ std::string s;
41
+ bool b = llvm::sys::DynamicLibrary::LoadLibraryPermanently (nullptr , &s);
42
+ errs () << " $$ LoadLibraryPermanently returned " << b
43
+ << " ; error string=" << s << " \n " ;
44
+ }
41
45
42
46
TargetMachine &getTargetMachine () { return *TM; }
43
47
@@ -58,7 +62,7 @@ class SimpleOrcJIT {
58
62
return Sym;
59
63
return JITSymbol (nullptr );
60
64
},
61
- [](const std::string &S) {
65
+ [](const std::string &S) {
62
66
errs () << " $$ external resolving " << S << " \n " ;
63
67
return nullptr ;
64
68
});
@@ -152,8 +156,9 @@ Function *MakeFunction(Module *Mod, std::string name, Function *printdfunc) {
152
156
}
153
157
154
158
// / printd - printf that takes a double prints it as "%f\n", returning 0.
155
- extern " C" void printd (double X) {
159
+ extern " C" double printd (double X) {
156
160
fprintf (stderr, " %f\n " , X);
161
+ return 0 ;
157
162
}
158
163
159
164
// Signature of the function we expect.
@@ -180,6 +185,12 @@ int main(int argc, char **argv) {
180
185
181
186
SimpleOrcJIT JIT;
182
187
Mod->setDataLayout (JIT.getTargetMachine ().createDataLayout ());
188
+ void * s = llvm::sys::DynamicLibrary::SearchForAddressOfSymbol (" printd" );
189
+ if (s != nullptr ) {
190
+ errs () << " $$ " << s << " \n " ;
191
+ } else {
192
+ errs () << " $$ SearchForAddressOfSymbol unable to find printd\n " ;
193
+ }
183
194
184
195
PassManagerBuilder Builder;
185
196
Builder.OptLevel = 3 ;
0 commit comments