aboutsummaryrefslogtreecommitdiff
path: root/compiler-rt/lib/orc/jit_dispatch.h
blob: 9b2329fa1e4fc760e209d44bdf6b30176b5e10ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//===------ jit_dispatch.h - Call back to an ORC controller -----*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file is a part of the ORC runtime support library.
//
//===----------------------------------------------------------------------===//

#ifndef ORC_RT_JIT_DISPATCH_H
#define ORC_RT_JIT_DISPATCH_H

#include "common.h"
#include "wrapper_function_utils.h"

namespace orc_rt {

class JITDispatch {
public:
  JITDispatch(const void *FnTag) : FnTag(FnTag) {}

  WrapperFunctionResult operator()(const char *ArgData, size_t ArgSize) {
    // Since the functions cannot be zero/unresolved on Windows, the following
    // reference taking would always be non-zero, thus generating a compiler
    // warning otherwise.
#if !defined(_WIN32)
    if (ORC_RT_UNLIKELY(!&__orc_rt_jit_dispatch_ctx))
      return WrapperFunctionResult::createOutOfBandError(
                 "__orc_rt_jit_dispatch_ctx not set")
          .release();
    if (ORC_RT_UNLIKELY(!&__orc_rt_jit_dispatch))
      return WrapperFunctionResult::createOutOfBandError(
                 "__orc_rt_jit_dispatch not set")
          .release();
#endif

    return __orc_rt_jit_dispatch(&__orc_rt_jit_dispatch_ctx, FnTag, ArgData,
                                 ArgSize);
  }

private:
  const void *FnTag;
};

} // namespace orc_rt

#endif // ORC_RT_JIT_DISPATCH_H