1 //===- run_program_wrapper.cpp --------------------------------------------===//
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-exception
7 //===----------------------------------------------------------------------===//
9 // This file is a part of the ORC runtime support library.
11 //===----------------------------------------------------------------------===//
15 #include "wrapper_function_utils.h"
19 using namespace __orc_rt
;
21 extern "C" int64_t __orc_rt_run_program(const char *JITDylibName
,
22 const char *EntrySymbolName
, int argc
,
25 ORC_RT_INTERFACE __orc_rt_CWrapperFunctionResult
26 __orc_rt_run_program_wrapper(const char *ArgData
, size_t ArgSize
) {
27 return WrapperFunction
<int64_t(SPSString
, SPSString
,
28 SPSSequence
<SPSString
>)>::
29 handle(ArgData
, ArgSize
,
30 [](const std::string
&JITDylibName
,
31 const std::string
&EntrySymbolName
,
32 const std::vector
<std::string_view
> &Args
) {
33 std::vector
<std::unique_ptr
<char[]>> ArgVStorage
;
34 ArgVStorage
.reserve(Args
.size());
35 for (auto &Arg
: Args
) {
36 ArgVStorage
.push_back(
37 std::make_unique
<char[]>(Arg
.size() + 1));
38 memcpy(ArgVStorage
.back().get(), Arg
.data(), Arg
.size());
39 ArgVStorage
.back()[Arg
.size()] = '\0';
41 std::vector
<char *> ArgV
;
42 ArgV
.reserve(ArgVStorage
.size() + 1);
43 for (auto &ArgStorage
: ArgVStorage
)
44 ArgV
.push_back(ArgStorage
.get());
45 ArgV
.push_back(nullptr);
46 return __orc_rt_run_program(JITDylibName
.c_str(),
47 EntrySymbolName
.c_str(),
48 ArgV
.size() - 1, ArgV
.data());