1*bb5f97e3SLang Hames //===- run_program_wrapper.cpp --------------------------------------------===//
2*bb5f97e3SLang Hames //
3*bb5f97e3SLang Hames // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*bb5f97e3SLang Hames // See https://llvm.org/LICENSE.txt for license information.
5*bb5f97e3SLang Hames // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*bb5f97e3SLang Hames //
7*bb5f97e3SLang Hames //===----------------------------------------------------------------------===//
8*bb5f97e3SLang Hames //
9*bb5f97e3SLang Hames // This file is a part of the ORC runtime support library.
10*bb5f97e3SLang Hames //
11*bb5f97e3SLang Hames //===----------------------------------------------------------------------===//
12*bb5f97e3SLang Hames
13*bb5f97e3SLang Hames #include "adt.h"
14*bb5f97e3SLang Hames #include "common.h"
15*bb5f97e3SLang Hames #include "wrapper_function_utils.h"
16*bb5f97e3SLang Hames
17*bb5f97e3SLang Hames #include <vector>
18*bb5f97e3SLang Hames
19*bb5f97e3SLang Hames using namespace __orc_rt;
20*bb5f97e3SLang Hames
21*bb5f97e3SLang Hames extern "C" int64_t __orc_rt_run_program(const char *JITDylibName,
22*bb5f97e3SLang Hames const char *EntrySymbolName, int argc,
23*bb5f97e3SLang Hames char *argv[]);
24*bb5f97e3SLang Hames
25*bb5f97e3SLang Hames ORC_RT_INTERFACE __orc_rt_CWrapperFunctionResult
__orc_rt_run_program_wrapper(const char * ArgData,size_t ArgSize)26*bb5f97e3SLang Hames __orc_rt_run_program_wrapper(const char *ArgData, size_t ArgSize) {
27*bb5f97e3SLang Hames return WrapperFunction<int64_t(SPSString, SPSString,
28*bb5f97e3SLang Hames SPSSequence<SPSString>)>::
29*bb5f97e3SLang Hames handle(ArgData, ArgSize,
30*bb5f97e3SLang Hames [](const std::string &JITDylibName,
31*bb5f97e3SLang Hames const std::string &EntrySymbolName,
32*bb5f97e3SLang Hames const std::vector<string_view> &Args) {
33*bb5f97e3SLang Hames std::vector<std::unique_ptr<char[]>> ArgVStorage;
34*bb5f97e3SLang Hames ArgVStorage.reserve(Args.size());
35*bb5f97e3SLang Hames for (auto &Arg : Args) {
36*bb5f97e3SLang Hames ArgVStorage.push_back(
37*bb5f97e3SLang Hames std::make_unique<char[]>(Arg.size() + 1));
38*bb5f97e3SLang Hames memcpy(ArgVStorage.back().get(), Arg.data(), Arg.size());
39*bb5f97e3SLang Hames ArgVStorage.back()[Arg.size()] = '\0';
40*bb5f97e3SLang Hames }
41*bb5f97e3SLang Hames std::vector<char *> ArgV;
42*bb5f97e3SLang Hames ArgV.reserve(ArgVStorage.size() + 1);
43*bb5f97e3SLang Hames for (auto &ArgStorage : ArgVStorage)
44*bb5f97e3SLang Hames ArgV.push_back(ArgStorage.get());
45*bb5f97e3SLang Hames ArgV.push_back(nullptr);
46*bb5f97e3SLang Hames return __orc_rt_run_program(JITDylibName.c_str(),
47*bb5f97e3SLang Hames EntrySymbolName.c_str(),
48*bb5f97e3SLang Hames ArgV.size() - 1, ArgV.data());
49*bb5f97e3SLang Hames })
50*bb5f97e3SLang Hames .release();
51*bb5f97e3SLang Hames }
52