1 | //===- run_program_wrapper.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-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | // |
9 | // This file is a part of the ORC runtime support library. |
10 | // |
11 | //===----------------------------------------------------------------------===// |
12 | |
13 | #include "adt.h" |
14 | #include "common.h" |
15 | #include "wrapper_function_utils.h" |
16 | |
17 | #include <vector> |
18 | |
19 | using namespace __orc_rt; |
20 | |
21 | extern "C" int64_t __orc_rt_run_program(const char *JITDylibName, |
22 | const char *EntrySymbolName, int argc, |
23 | char *argv[]); |
24 | |
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 | Handler: [](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(n: Args.size()); |
35 | for (auto &Arg : Args) { |
36 | ArgVStorage.push_back( |
37 | x: std::make_unique<char[]>(num: Arg.size() + 1)); |
38 | memcpy(dest: ArgVStorage.back().get(), src: Arg.data(), n: Arg.size()); |
39 | ArgVStorage.back()[Arg.size()] = '\0'; |
40 | } |
41 | std::vector<char *> ArgV; |
42 | ArgV.reserve(n: ArgVStorage.size() + 1); |
43 | for (auto &ArgStorage : ArgVStorage) |
44 | ArgV.push_back(x: ArgStorage.get()); |
45 | ArgV.push_back(x: nullptr); |
46 | return __orc_rt_run_program(JITDylibName: JITDylibName.c_str(), |
47 | EntrySymbolName: EntrySymbolName.c_str(), |
48 | argc: ArgV.size() - 1, argv: ArgV.data()); |
49 | }) |
50 | .release(); |
51 | } |
52 | |