brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.7 KiB · 3d9b37d Raw
50 lines · cpp
1//===- resolve.cpp --------------------------------------------------------===//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-exception6//7//===----------------------------------------------------------------------===//8//9// This file contains a generic "resolver" function compatible with the10// __orc_rt_reenter function.11//12//===----------------------------------------------------------------------===//13 14#include "executor_symbol_def.h"15#include "jit_dispatch.h"16#include "wrapper_function_utils.h"17 18#include <stdio.h>19 20#define DEBUG_TYPE "resolve"21 22using namespace orc_rt;23 24// Declare function tags for functions in the JIT process.25ORC_RT_JIT_DISPATCH_TAG(__orc_rt_resolve_tag)26 27// FIXME: Make this configurable via an alias.28static void __orc_rt_resolve_fail(void *Caller, const char *ErrMsg) {29  fprintf(stderr, "error resolving implementation for stub %p: %s\n", Caller,30          ErrMsg);31  abort();32}33 34extern "C" ORC_RT_HIDDEN void *__orc_rt_resolve(void *Caller) {35  Expected<ExecutorSymbolDef> Result((ExecutorSymbolDef()));36  if (auto Err = WrapperFunction<SPSExpected<SPSExecutorSymbolDef>(37          SPSExecutorAddr)>::call(JITDispatch(&__orc_rt_resolve_tag), Result,38                                  ExecutorAddr::fromPtr(Caller))) {39    __orc_rt_resolve_fail(Caller, toString(std::move(Err)).c_str());40    return nullptr; // Unreachable.41  }42 43  if (!Result) {44    __orc_rt_resolve_fail(Caller, toString(Result.takeError()).c_str());45    return nullptr; // Unreachable.46  }47 48  return Result->getAddress().toPtr<void *>();49}50