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 Message("Some error occurred"); |
| 85 if (ErrorStream) { | |
|
jvoung (off chromium)
2015/04/17 18:15:09
ErrorStream *should* be non-null at this point, si
Karl
2015/04/17 21:33:52
I agree that it shouldn't be null. I wasn't 100% s
| |
| 86 std::string Error = ErrorStream->getContents(); | |
| 87 if (!Error.empty()) | |
| 88 Message = Error; | |
| 89 } | |
| 90 return strdup(Message); | |
|
jvoung (off chromium)
2015/04/17 18:15:09
strdup is usually given the c_str() -- or am I mis
Karl
2015/04/17 21:33:52
My bad. Fixing.
| |
| 85 } | 91 } |
| 86 return nullptr; | 92 return nullptr; |
| 87 } | 93 } |
| 88 | 94 |
| 89 struct nacl_irt_pnacl_compile_funcs SubzeroCallbacks { | 95 struct nacl_irt_pnacl_compile_funcs SubzeroCallbacks { |
| 90 &onInitCallback, &onDataCallback, &onEndCallback | 96 &onInitCallback, &onDataCallback, &onEndCallback |
| 91 }; | 97 }; |
| 92 | 98 |
| 93 std::unique_ptr<llvm::raw_fd_ostream> getOutputStream(int FD) { | 99 std::unique_ptr<llvm::raw_fd_ostream> getOutputStream(int FD) { |
| 94 if (FD <= 0) | 100 if (FD <= 0) |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 135 } | 141 } |
| 136 | 142 |
| 137 void BrowserCompileServer::endInputStream() { InputStream->SetDone(); } | 143 void BrowserCompileServer::endInputStream() { InputStream->SetDone(); } |
| 138 | 144 |
| 139 void BrowserCompileServer::startCompileThread(int ObjFD) { | 145 void BrowserCompileServer::startCompileThread(int ObjFD) { |
| 140 InputStream = new llvm::QueueStreamer(); | 146 InputStream = new llvm::QueueStreamer(); |
| 141 LogStream = getOutputStream(STDOUT_FILENO); | 147 LogStream = getOutputStream(STDOUT_FILENO); |
| 142 LogStream->SetUnbuffered(); | 148 LogStream->SetUnbuffered(); |
| 143 EmitStream = getOutputStream(ObjFD); | 149 EmitStream = getOutputStream(ObjFD); |
| 144 EmitStream->SetBufferSize(1 << 14); | 150 EmitStream->SetBufferSize(1 << 14); |
| 151 ErrorStream = new StringStream(); | |
| 145 ELFStream.reset(new ELFStreamer(*EmitStream.get())); | 152 ELFStream.reset(new ELFStreamer(*EmitStream.get())); |
| 146 Ctx.reset(new GlobalContext(LogStream.get(), EmitStream.get(), | 153 Ctx.reset(new GlobalContext(LogStream.get(), EmitStream.get(), |
| 147 ELFStream.get(), Flags)); | 154 ELFStream.get(), Flags. ErrorStream.getStream())); |
|
jvoung (off chromium)
2015/04/17 18:15:09
Should that be a comma instead of a period?
Might
Karl
2015/04/17 21:33:52
Fixed, and moved the streams into a group.
| |
| 148 CompileThread = std::thread([this]() { | 155 CompileThread = std::thread([this]() { |
| 149 Ctx->initParserThread(); | 156 Ctx->initParserThread(); |
| 150 this->getCompiler().run(ExtraFlags, *Ctx.get(), | 157 this->getCompiler().run(ExtraFlags, *Ctx.get(), |
| 151 // Retain original reference, but the compiler | 158 // Retain original reference, but the compiler |
| 152 // (LLVM's MemoryObject) wants to handle deletion. | 159 // (LLVM's MemoryObject) wants to handle deletion. |
| 153 std::unique_ptr<llvm::DataStreamer>(InputStream)); | 160 std::unique_ptr<llvm::DataStreamer>(InputStream)); |
| 154 }); | 161 }); |
| 155 } | 162 } |
| 156 | 163 |
| 157 } // end of namespace Ice | 164 } // end of namespace Ice |
| 158 | 165 |
| 159 #endif // PNACL_BROWSER_TRANSLATOR | 166 #endif // PNACL_BROWSER_TRANSLATOR |
| OLD | NEW |