Chromium Code Reviews| 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 // This file defines the browser-based compile server. | 10 // This file defines the browser-based compile server. |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 74 int onDataCallback(const void *Data, size_t NumBytes) { | 74 int onDataCallback(const void *Data, size_t NumBytes) { |
| 75 return gCompileServer->pushInputBytes(Data, NumBytes) ? 1 : 0; | 75 return gCompileServer->pushInputBytes(Data, NumBytes) ? 1 : 0; |
| 76 } | 76 } |
| 77 | 77 |
| 78 char *onEndCallback() { | 78 char *onEndCallback() { |
| 79 gCompileServer->endInputStream(); | 79 gCompileServer->endInputStream(); |
| 80 gCompileServer->waitForCompileThread(); | 80 gCompileServer->waitForCompileThread(); |
| 81 // TODO(jvoung): Also return an error string, and UMA data. | 81 // TODO(jvoung): Also return an error string, and UMA data. |
| 82 // Set up a report_fatal_error handler to grab that string. | 82 // Set up a report_fatal_error handler to grab that string. |
| 83 if (gCompileServer->getErrorCode().value()) { | 83 if (gCompileServer->getErrorCode().value()) { |
| 84 return strdup("Some error occurred"); | 84 std::string Error = ErrorStream->getContents(); |
| 85 return strdup(Error.empty() ? "Some error occurred" : Error.c_str()); | |
| 86 return strdup(Message); | |
|
jvoung (off chromium)
2015/04/20 21:41:57
remove the dup'ed strdup: "return strdup(Message);
Karl
2015/04/22 22:23:50
Done.
| |
| 85 } | 87 } |
| 86 return nullptr; | 88 return nullptr; |
| 87 } | 89 } |
| 88 | 90 |
| 89 struct nacl_irt_pnacl_compile_funcs SubzeroCallbacks { | 91 struct nacl_irt_pnacl_compile_funcs SubzeroCallbacks { |
| 90 &onInitCallback, &onDataCallback, &onEndCallback | 92 &onInitCallback, &onDataCallback, &onEndCallback |
| 91 }; | 93 }; |
| 92 | 94 |
| 93 std::unique_ptr<llvm::raw_fd_ostream> getOutputStream(int FD) { | 95 std::unique_ptr<llvm::raw_fd_ostream> getOutputStream(int FD) { |
| 94 if (FD <= 0) | 96 if (FD <= 0) |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 135 } | 137 } |
| 136 | 138 |
| 137 void BrowserCompileServer::endInputStream() { InputStream->SetDone(); } | 139 void BrowserCompileServer::endInputStream() { InputStream->SetDone(); } |
| 138 | 140 |
| 139 void BrowserCompileServer::startCompileThread(int ObjFD) { | 141 void BrowserCompileServer::startCompileThread(int ObjFD) { |
| 140 InputStream = new llvm::QueueStreamer(); | 142 InputStream = new llvm::QueueStreamer(); |
| 141 LogStream = getOutputStream(STDOUT_FILENO); | 143 LogStream = getOutputStream(STDOUT_FILENO); |
| 142 LogStream->SetUnbuffered(); | 144 LogStream->SetUnbuffered(); |
| 143 EmitStream = getOutputStream(ObjFD); | 145 EmitStream = getOutputStream(ObjFD); |
| 144 EmitStream->SetBufferSize(1 << 14); | 146 EmitStream->SetBufferSize(1 << 14); |
| 147 ErrorStream = new StringStream(); | |
| 145 ELFStream.reset(new ELFStreamer(*EmitStream.get())); | 148 ELFStream.reset(new ELFStreamer(*EmitStream.get())); |
| 146 Ctx.reset(new GlobalContext(LogStream.get(), EmitStream.get(), | 149 Ctx.reset(new GlobalContext(LogStream.get(), EmitStream.get(), |
| 147 ELFStream.get(), Flags)); | 150 ErrorStream.getStream(), ELFStream.get(), Flags); |
| 148 CompileThread = std::thread([this]() { | 151 CompileThread = std::thread([this]() { |
| 149 Ctx->initParserThread(); | 152 Ctx->initParserThread(); |
| 150 this->getCompiler().run(ExtraFlags, *Ctx.get(), | 153 this->getCompiler().run(ExtraFlags, *Ctx.get(), |
| 151 // Retain original reference, but the compiler | 154 // Retain original reference, but the compiler |
| 152 // (LLVM's MemoryObject) wants to handle deletion. | 155 // (LLVM's MemoryObject) wants to handle deletion. |
| 153 std::unique_ptr<llvm::DataStreamer>(InputStream)); | 156 std::unique_ptr<llvm::DataStreamer>(InputStream)); |
| 154 }); | 157 }); |
| 155 } | 158 } |
| 156 | 159 |
| 157 } // end of namespace Ice | 160 } // end of namespace Ice |
| 158 | 161 |
| 159 #endif // PNACL_BROWSER_TRANSLATOR | 162 #endif // PNACL_BROWSER_TRANSLATOR |
| OLD | NEW |