[llvm] [cmake] Add possibility to use ChooseMSVCCRT.cmake when include LLVM library
[llvm-core.git] / tools / lli / ChildTarget / ChildTarget.cpp
blob77b1d47a9466e42af86a0c9887967325c54a8daf
1 #include "llvm/ExecutionEngine/Orc/OrcABISupport.h"
2 #include "llvm/ExecutionEngine/Orc/OrcRemoteTargetServer.h"
3 #include "llvm/Support/Debug.h"
4 #include "llvm/Support/DynamicLibrary.h"
5 #include "llvm/Support/Process.h"
6 #include <sstream>
8 #include "../RemoteJITUtils.h"
10 using namespace llvm;
11 using namespace llvm::orc;
12 using namespace llvm::sys;
14 #ifdef __x86_64__
15 typedef OrcX86_64_SysV HostOrcArch;
16 #else
17 typedef OrcGenericABI HostOrcArch;
18 #endif
20 ExitOnError ExitOnErr;
22 int main(int argc, char *argv[]) {
24 if (argc != 3) {
25 errs() << "Usage: " << argv[0] << " <input fd> <output fd>\n";
26 return 1;
29 ExitOnErr.setBanner(std::string(argv[0]) + ":");
31 int InFD;
32 int OutFD;
34 std::istringstream InFDStream(argv[1]), OutFDStream(argv[2]);
35 InFDStream >> InFD;
36 OutFDStream >> OutFD;
39 if (sys::DynamicLibrary::LoadLibraryPermanently(nullptr)) {
40 errs() << "Error loading program symbols.\n";
41 return 1;
44 auto SymbolLookup = [](const std::string &Name) {
45 return RTDyldMemoryManager::getSymbolAddressInProcess(Name);
48 auto RegisterEHFrames = [](uint8_t *Addr, uint32_t Size) {
49 RTDyldMemoryManager::registerEHFramesInProcess(Addr, Size);
52 auto DeregisterEHFrames = [](uint8_t *Addr, uint32_t Size) {
53 RTDyldMemoryManager::deregisterEHFramesInProcess(Addr, Size);
56 FDRawChannel Channel(InFD, OutFD);
57 typedef remote::OrcRemoteTargetServer<FDRawChannel, HostOrcArch> JITServer;
58 JITServer Server(Channel, SymbolLookup, RegisterEHFrames, DeregisterEHFrames);
60 while (!Server.receivedTerminate())
61 ExitOnErr(Server.handleOne());
63 close(InFD);
64 close(OutFD);
66 return 0;