| OLD | NEW |
| 1 //===- subzero/src/IceBrowserCompileServer.cpp - Browser compile server ---===// | 1 //===- subzero/src/IceBrowserCompileServer.cpp - Browser compile server ---===// |
| 2 // | 2 // |
| 3 // The Subzero Code Generator | 3 // The Subzero Code Generator |
| 4 // | 4 // |
| 5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
| 6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
| 7 // | 7 // |
| 8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
| 9 /// | 9 /// |
| 10 /// \file | 10 /// \file |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 return std::unique_ptr<llvm::raw_fd_ostream>( | 99 return std::unique_ptr<llvm::raw_fd_ostream>( |
| 100 new llvm::raw_fd_ostream(FD, CloseOnDtor, Unbuffered)); | 100 new llvm::raw_fd_ostream(FD, CloseOnDtor, Unbuffered)); |
| 101 } | 101 } |
| 102 | 102 |
| 103 void fatalErrorHandler(void *UserData, const std::string &Reason, | 103 void fatalErrorHandler(void *UserData, const std::string &Reason, |
| 104 bool GenCrashDialog) { | 104 bool GenCrashDialog) { |
| 105 (void)GenCrashDialog; | 105 (void)GenCrashDialog; |
| 106 BrowserCompileServer *Server = | 106 BrowserCompileServer *Server = |
| 107 reinterpret_cast<BrowserCompileServer *>(UserData); | 107 reinterpret_cast<BrowserCompileServer *>(UserData); |
| 108 Server->setFatalError(Reason); | 108 Server->setFatalError(Reason); |
| 109 // Only kill the current thread instead of the whole process. | 109 // Only kill the current thread instead of the whole process. We need the |
| 110 // We need the server thread to remain alive in order to respond with the | 110 // server thread to remain alive in order to respond with the error message. |
| 111 // error message. | |
| 112 // We could also try to pthread_kill all other worker threads, but | 111 // We could also try to pthread_kill all other worker threads, but |
| 113 // pthread_kill / raising signals is not supported by NaCl. | 112 // pthread_kill / raising signals is not supported by NaCl. We'll have to |
| 114 // We'll have to assume that the worker/emitter threads will be well behaved | 113 // assume that the worker/emitter threads will be well behaved after a fatal |
| 115 // after a fatal error in other threads, and either get stuck waiting | 114 // error in other threads, and either get stuck waiting on input from a |
| 116 // on input from a previous stage, or also call report_fatal_error. | 115 // previous stage, or also call report_fatal_error. |
| 117 pthread_exit(0); | 116 pthread_exit(0); |
| 118 } | 117 } |
| 119 | 118 |
| 120 } // end of anonymous namespace | 119 } // end of anonymous namespace |
| 121 | 120 |
| 122 BrowserCompileServer::~BrowserCompileServer() = default; | 121 BrowserCompileServer::~BrowserCompileServer() = default; |
| 123 | 122 |
| 124 void BrowserCompileServer::run() { | 123 void BrowserCompileServer::run() { |
| 125 gCompileServer = this; | 124 gCompileServer = this; |
| 126 getIRTInterfaces(); | 125 getIRTInterfaces(); |
| 127 gIRTFuncs.serve_translate_request(&SubzeroCallbacks); | 126 gIRTFuncs.serve_translate_request(&SubzeroCallbacks); |
| 128 } | 127 } |
| 129 | 128 |
| 130 void BrowserCompileServer::getParsedFlags(uint32_t NumThreads, int argc, | 129 void BrowserCompileServer::getParsedFlags(uint32_t NumThreads, int argc, |
| 131 char **argv) { | 130 char **argv) { |
| 132 ClFlags::parseFlags(argc, argv); | 131 ClFlags::parseFlags(argc, argv); |
| 133 ClFlags::getParsedClFlags(Flags); | 132 ClFlags::getParsedClFlags(Flags); |
| 134 ClFlags::getParsedClFlagsExtra(ExtraFlags); | 133 ClFlags::getParsedClFlagsExtra(ExtraFlags); |
| 135 // Set some defaults which aren't specified via the argv string. | 134 // Set some defaults which aren't specified via the argv string. |
| 136 Flags.setNumTranslationThreads(NumThreads); | 135 Flags.setNumTranslationThreads(NumThreads); |
| 137 Flags.setUseSandboxing(true); | 136 Flags.setUseSandboxing(true); |
| 138 Flags.setOutFileType(FT_Elf); | 137 Flags.setOutFileType(FT_Elf); |
| 139 // TODO(jvoung): allow setting different target arches. | 138 // TODO(jvoung): allow setting different target arches. |
| 140 Flags.setTargetArch(Target_X8632); | 139 Flags.setTargetArch(Target_X8632); |
| 141 ExtraFlags.setBuildOnRead(true); | 140 ExtraFlags.setBuildOnRead(true); |
| 142 ExtraFlags.setInputFileFormat(llvm::PNaClFormat); | 141 ExtraFlags.setInputFileFormat(llvm::PNaClFormat); |
| 143 } | 142 } |
| 144 | 143 |
| 145 bool BrowserCompileServer::pushInputBytes(const void *Data, size_t NumBytes) { | 144 bool BrowserCompileServer::pushInputBytes(const void *Data, size_t NumBytes) { |
| 146 // If there was an earlier error, do not attempt to push bytes to | 145 // If there was an earlier error, do not attempt to push bytes to the |
| 147 // the QueueStreamer. Otherwise the thread could become blocked. | 146 // QueueStreamer. Otherwise the thread could become blocked. |
| 148 if (HadError.load()) | 147 if (HadError.load()) |
| 149 return true; | 148 return true; |
| 150 return InputStream->PutBytes( | 149 return InputStream->PutBytes( |
| 151 const_cast<unsigned char *>( | 150 const_cast<unsigned char *>( |
| 152 reinterpret_cast<const unsigned char *>(Data)), | 151 reinterpret_cast<const unsigned char *>(Data)), |
| 153 NumBytes) != NumBytes; | 152 NumBytes) != NumBytes; |
| 154 } | 153 } |
| 155 | 154 |
| 156 void BrowserCompileServer::setFatalError(const IceString &Reason) { | 155 void BrowserCompileServer::setFatalError(const IceString &Reason) { |
| 157 HadError.store(true); | 156 HadError.store(true); |
| 158 Ctx->getStrError() << Reason; | 157 Ctx->getStrError() << Reason; |
| 159 // Make sure that the QueueStreamer is not stuck by signaling an early end. | 158 // Make sure that the QueueStreamer is not stuck by signaling an early end. |
| 160 InputStream->SetDone(); | 159 InputStream->SetDone(); |
| 161 } | 160 } |
| 162 | 161 |
| 163 ErrorCode &BrowserCompileServer::getErrorCode() { | 162 ErrorCode &BrowserCompileServer::getErrorCode() { |
| 164 if (HadError.load()) { | 163 if (HadError.load()) { |
| 165 // HadError means report_fatal_error is called. Make sure that the | 164 // HadError means report_fatal_error is called. Make sure that the |
| 166 // LastError is not EC_None. We don't know the type of error so | 165 // LastError is not EC_None. We don't know the type of error so just pick |
| 167 // just pick some error category. | 166 // some error category. |
| 168 LastError.assign(EC_Translation); | 167 LastError.assign(EC_Translation); |
| 169 } | 168 } |
| 170 return LastError; | 169 return LastError; |
| 171 } | 170 } |
| 172 | 171 |
| 173 void BrowserCompileServer::endInputStream() { InputStream->SetDone(); } | 172 void BrowserCompileServer::endInputStream() { InputStream->SetDone(); } |
| 174 | 173 |
| 175 void BrowserCompileServer::startCompileThread(int ObjFD) { | 174 void BrowserCompileServer::startCompileThread(int ObjFD) { |
| 176 InputStream = new llvm::QueueStreamer(); | 175 InputStream = new llvm::QueueStreamer(); |
| 177 LogStream = getOutputStream(STDOUT_FILENO); | 176 LogStream = getOutputStream(STDOUT_FILENO); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 190 this->getCompiler().run(ExtraFlags, *Ctx.get(), | 189 this->getCompiler().run(ExtraFlags, *Ctx.get(), |
| 191 // Retain original reference, but the compiler | 190 // Retain original reference, but the compiler |
| 192 // (LLVM's MemoryObject) wants to handle deletion. | 191 // (LLVM's MemoryObject) wants to handle deletion. |
| 193 std::unique_ptr<llvm::DataStreamer>(InputStream)); | 192 std::unique_ptr<llvm::DataStreamer>(InputStream)); |
| 194 }); | 193 }); |
| 195 } | 194 } |
| 196 | 195 |
| 197 } // end of namespace Ice | 196 } // end of namespace Ice |
| 198 | 197 |
| 199 #endif // PNACL_BROWSER_TRANSLATOR | 198 #endif // PNACL_BROWSER_TRANSLATOR |
| OLD | NEW |