diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/Kaleidoscope/BuildingAJIT/Chapter1/KaleidoscopeJIT.h | 4 | ||||
-rw-r--r-- | examples/Kaleidoscope/BuildingAJIT/Chapter1/toy.cpp | 12 |
2 files changed, 9 insertions, 7 deletions
diff --git a/examples/Kaleidoscope/BuildingAJIT/Chapter1/KaleidoscopeJIT.h b/examples/Kaleidoscope/BuildingAJIT/Chapter1/KaleidoscopeJIT.h index 5a2148a14a1..ab675e3f742 100644 --- a/examples/Kaleidoscope/BuildingAJIT/Chapter1/KaleidoscopeJIT.h +++ b/examples/Kaleidoscope/BuildingAJIT/Chapter1/KaleidoscopeJIT.h @@ -86,6 +86,10 @@ public: return CompileLayer.findSymbol(MangledNameStream.str(), true); } + JITTargetAddress getSymbolAddress(const std::string Name) { + return cantFail(findSymbol(Name).getAddress()); + } + void removeModule(ModuleHandle H) { cantFail(CompileLayer.removeModule(H)); } diff --git a/examples/Kaleidoscope/BuildingAJIT/Chapter1/toy.cpp b/examples/Kaleidoscope/BuildingAJIT/Chapter1/toy.cpp index 2471344c6d6..7652e80c69a 100644 --- a/examples/Kaleidoscope/BuildingAJIT/Chapter1/toy.cpp +++ b/examples/Kaleidoscope/BuildingAJIT/Chapter1/toy.cpp @@ -1144,13 +1144,11 @@ static void HandleTopLevelExpression() { auto H = TheJIT->addModule(std::move(TheModule)); InitializeModule(); - // Search the JIT for the __anon_expr symbol. - auto ExprSymbol = TheJIT->findSymbol("__anon_expr"); - assert(ExprSymbol && "Function not found"); - - // Get the symbol's address and cast it to the right type (takes no - // arguments, returns a double) so we can call it as a native function. - double (*FP)() = (double (*)())(intptr_t)cantFail(ExprSymbol.getAddress()); + // Get the anonymous expression's address and cast it to the right type, + // double(*)(), so we can call it as a native function. + double (*FP)() = + (double (*)())(intptr_t)TheJIT->getSymbolAddress("__anon_expr"); + assert(FP && "Failed to codegen function"); fprintf(stderr, "Evaluated to %f\n", FP()); // Delete the anonymous expression module from the JIT. |