| 576 | } |
| 577 | |
| 578 | Result<void*> Engine::CompiledFunction(const std::string& function) { |
| 579 | DCHECK(module_finalized_) |
| 580 | << "module must be finalized before getting compiled function"; |
| 581 | auto sym = lljit_->lookup(function); |
| 582 | if (!sym) { |
| 583 | return Status::CodeGenError("Failed to look up function: " + function + |
| 584 | " error: " + llvm::toString(sym.takeError())); |
| 585 | } |
| 586 | // Since LLVM 15, `LLJIT::lookup` returns ExecutorAddrs rather than |
| 587 | // JITEvaluatedSymbols |
| 588 | #if LLVM_VERSION_MAJOR >= 15 |
| 589 | auto fn_addr = sym->getValue(); |
| 590 | #else |
| 591 | auto fn_addr = sym->getAddress(); |
| 592 | #endif |
| 593 | auto fn_ptr = reinterpret_cast<void*>(fn_addr); |
| 594 | if (fn_ptr == nullptr) { |
| 595 | return Status::CodeGenError("Failed to get address for function: " + function); |
| 596 | } |
| 597 | return fn_ptr; |
| 598 | } |
| 599 | |
| 600 | void Engine::AddGlobalMappingForFunc(const std::string& name, llvm::Type* ret_type, |
| 601 | const std::vector<llvm::Type*>& args, void* func) { |
nothing calls this directly
no test coverage detected