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