int main() { InitializeNativeTarget(); InitializeNativeTargetAsmPrinter(); InitializeNativeTargetAsmParser(); ExitOnErr.setBanner("Kaleidoscope: "); // Install standard binary operators. // 1 is lowest precedence. BinopPrecedence['='] = 2; BinopPrecedence['<'] = 10; BinopPrecedence['+'] = 20; BinopPrecedence['-'] = 20; BinopPrecedence['*'] = 40; // highest. // Prime the first token. fprintf(stderr, "ready> "); getNextToken(); TheJIT = llvm::make_unique<KaleidoscopeJIT>(); InitializeModule(); // Run the main "interpreter loop" now. MainLoop(); return 0; }
int main(int argc, char *argv[]) { if (argc != 3) { errs() << "Usage: " << argv[0] << " <input fd> <output fd>\n"; return 1; } ExitOnErr.setBanner(std::string(argv[0]) + ":"); int InFD; int OutFD; { std::istringstream InFDStream(argv[1]), OutFDStream(argv[2]); InFDStream >> InFD; OutFDStream >> OutFD; } if (sys::DynamicLibrary::LoadLibraryPermanently(nullptr)) { errs() << "Error loading program symbols.\n"; return 1; } auto SymbolLookup = [](const std::string &Name) { return RTDyldMemoryManager::getSymbolAddressInProcess(Name); }; auto RegisterEHFrames = [](uint8_t *Addr, uint32_t Size) { RTDyldMemoryManager::registerEHFramesInProcess(Addr, Size); }; auto DeregisterEHFrames = [](uint8_t *Addr, uint32_t Size) { RTDyldMemoryManager::deregisterEHFramesInProcess(Addr, Size); }; FDRPCChannel Channel(InFD, OutFD); typedef remote::OrcRemoteTargetServer<FDRPCChannel, HostOrcArch> JITServer; JITServer Server(Channel, SymbolLookup, RegisterEHFrames, DeregisterEHFrames); while (1) { uint32_t RawId; ExitOnErr(Server.startReceivingFunction(Channel, RawId)); auto Id = static_cast<JITServer::JITFuncId>(RawId); switch (Id) { case JITServer::TerminateSessionId: ExitOnErr(Server.handleTerminateSession()); return 0; default: ExitOnErr(Server.handleKnownFunction(Id)); break; } } close(InFD); close(OutFD); return 0; }
int main(int argc, char *argv[]) { // Parse the command line options. cl::ParseCommandLineOptions(argc, argv, "Building A JIT - Client.\n"); InitializeNativeTarget(); InitializeNativeTargetAsmPrinter(); InitializeNativeTargetAsmParser(); ExitOnErr.setBanner("Kaleidoscope: "); // Install standard binary operators. // 1 is lowest precedence. BinopPrecedence['='] = 2; BinopPrecedence['<'] = 10; BinopPrecedence['+'] = 20; BinopPrecedence['-'] = 20; BinopPrecedence['*'] = 40; // highest. auto TCPChannel = connect(); auto Remote = ExitOnErr(MyRemote::Create(*TCPChannel)); TheJIT = llvm::make_unique<KaleidoscopeJIT>(*Remote); // Automatically inject a definition for 'printExprResult'. FunctionProtos["printExprResult"] = llvm::make_unique<PrototypeAST>("printExprResult", std::vector<std::string>({"Val"})); // Prime the first token. fprintf(stderr, "ready> "); getNextToken(); InitializeModule(); // Run the main "interpreter loop" now. MainLoop(); // Delete the JIT before the Remote and Channel go out of scope, otherwise // we'll crash in the JIT destructor when it tries to release remote // resources over a channel that no longer exists. TheJIT = nullptr; // Send a terminate message to the remote to tell it to exit cleanly. ExitOnErr(Remote->terminateSession()); return 0; }
int main(int argc, char **argv) { // Print a stack trace if we signal out. sys::PrintStackTraceOnErrorSignal(argv[0]); PrettyStackTraceProgram X(argc, argv); ExitOnErr.setBanner(std::string(argv[0]) + ": "); LLVMContext Context; Context.setDiagnosticHandler(diagnosticHandler, nullptr, true); llvm_shutdown_obj Y; // Call llvm_shutdown() on exit. cl::ParseCommandLineOptions(argc, argv, "llvm linker\n"); if (!DisableDITypeMap) Context.enableDebugTypeODRUniquing(); auto Composite = make_unique<Module>("llvm-link", Context); Linker L(*Composite); unsigned Flags = Linker::Flags::None; if (Internalize) Flags |= Linker::Flags::InternalizeLinkedSymbols; if (OnlyNeeded) Flags |= Linker::Flags::LinkOnlyNeeded; // First add all the regular input files if (!linkFiles(argv[0], Context, L, InputFilenames, Flags)) return 1; // Next the -override ones. if (!linkFiles(argv[0], Context, L, OverridingInputs, Flags | Linker::Flags::OverrideFromSrc)) return 1; // Import any functions requested via -import if (!importFunctions(argv[0], Context, L)) return 1; if (DumpAsm) errs() << "Here's the assembly:\n" << *Composite; std::error_code EC; tool_output_file Out(OutputFilename, EC, sys::fs::F_None); if (EC) { errs() << EC.message() << '\n'; return 1; } if (verifyModule(*Composite, &errs())) { errs() << argv[0] << ": error: linked module is broken!\n"; return 1; } if (Verbose) errs() << "Writing bitcode...\n"; if (OutputAssembly) { Composite->print(Out.os(), nullptr, PreserveAssemblyUseListOrder); } else if (Force || !CheckBitcodeOutputToConsole(Out.os(), true)) WriteBitcodeToFile(Composite.get(), Out.os(), PreserveBitcodeUseListOrder); // Declare success. Out.keep(); return 0; }
// --- LAZY COMPILE TEST --- int main(int argc, char* argv[]) { if (argc == 0) ExitOnErr.setBanner("jit_server: "); else ExitOnErr.setBanner(std::string(argv[0]) + ": "); // --- Initialize LLVM --- cl::ParseCommandLineOptions(argc, argv, "LLVM lazy JIT example.\n"); InitializeNativeTarget(); InitializeNativeTargetAsmPrinter(); InitializeNativeTargetAsmParser(); if (sys::DynamicLibrary::LoadLibraryPermanently(nullptr)) { errs() << "Error loading program symbols.\n"; return 1; } // --- Initialize remote connection --- int sockfd = socket(PF_INET, SOCK_STREAM, 0); sockaddr_in servAddr, clientAddr; socklen_t clientAddrLen = sizeof(clientAddr); bzero(&servAddr, sizeof(servAddr)); servAddr.sin_family = PF_INET; servAddr.sin_family = INADDR_ANY; servAddr.sin_port = htons(Port); { // avoid "Address already in use" error. int yes=1; if (setsockopt(sockfd,SOL_SOCKET,SO_REUSEADDR,&yes,sizeof(int)) == -1) { errs() << "Error calling setsockopt.\n"; return 1; } } if (bind(sockfd, reinterpret_cast<sockaddr*>(&servAddr), sizeof(servAddr)) < 0) { errs() << "Error on binding.\n"; return 1; } listen(sockfd, 1); int newsockfd = accept(sockfd, reinterpret_cast<sockaddr*>(&clientAddr), &clientAddrLen); auto SymbolLookup = [](const std::string &Name) { return RTDyldMemoryManager::getSymbolAddressInProcess(Name); }; auto RegisterEHFrames = [](uint8_t *Addr, uint32_t Size) { RTDyldMemoryManager::registerEHFramesInProcess(Addr, Size); }; auto DeregisterEHFrames = [](uint8_t *Addr, uint32_t Size) { RTDyldMemoryManager::deregisterEHFramesInProcess(Addr, Size); }; FDRPCChannel TCPChannel(newsockfd, newsockfd); typedef remote::OrcRemoteTargetServer<FDRPCChannel, OrcX86_64_SysV> MyServerT; MyServerT Server(TCPChannel, SymbolLookup, RegisterEHFrames, DeregisterEHFrames); while (!Server.receivedTerminate()) ExitOnErr(Server.handleOne()); return 0; }
int main(int argc_, const char *argv_[]) { // Print a stack trace if we signal out. sys::PrintStackTraceOnErrorSignal(argv_[0]); PrettyStackTraceProgram X(argc_, argv_); ExitOnErr.setBanner("llvm-pdbdump: "); SmallVector<const char *, 256> argv; SpecificBumpPtrAllocator<char> ArgAllocator; ExitOnErr(errorCodeToError(sys::Process::GetArgumentVector( argv, makeArrayRef(argv_, argc_), ArgAllocator))); llvm_shutdown_obj Y; // Call llvm_shutdown() on exit. cl::ParseCommandLineOptions(argv.size(), argv.data(), "LLVM PDB Dumper\n"); if (opts::Lines) opts::Compilands = true; if (opts::All) { opts::Compilands = true; opts::Symbols = true; opts::Globals = true; opts::Types = true; opts::Externals = true; opts::Lines = true; } if (opts::RawAll) { opts::DumpHeaders = true; opts::DumpModules = true; opts::DumpModuleFiles = true; opts::DumpModuleSyms = true; opts::DumpPublics = true; opts::DumpSectionHeaders = true; opts::DumpStreamSummary = true; opts::DumpStreamBlocks = true; opts::DumpTpiRecords = true; opts::DumpTpiHash = true; opts::DumpIpiRecords = true; opts::DumpSectionMap = true; opts::DumpSectionContribs = true; opts::DumpLineInfo = true; opts::DumpFpo = true; } // When adding filters for excluded compilands and types, we need to remember // that these are regexes. So special characters such as * and \ need to be // escaped in the regex. In the case of a literal \, this means it needs to // be escaped again in the C++. So matching a single \ in the input requires // 4 \es in the C++. if (opts::ExcludeCompilerGenerated) { opts::ExcludeTypes.push_back("__vc_attributes"); opts::ExcludeCompilands.push_back("\\* Linker \\*"); } if (opts::ExcludeSystemLibraries) { opts::ExcludeCompilands.push_back( "f:\\\\binaries\\\\Intermediate\\\\vctools\\\\crt_bld"); opts::ExcludeCompilands.push_back("f:\\\\dd\\\\vctools\\\\crt"); opts::ExcludeCompilands.push_back("d:\\\\th.obj.x86fre\\\\minkernel"); } llvm::sys::InitializeCOMRAII COM(llvm::sys::COMThreadingMode::MultiThreaded); std::for_each(opts::InputFilenames.begin(), opts::InputFilenames.end(), dumpInput); outs().flush(); return 0; }