| OLD | NEW |
| 1 //===- subzero/src/IceBrowserCompileServer.h - Browser server ---*- C++ -*-===// | 1 //===- subzero/src/IceBrowserCompileServer.h - Browser server ---*- C++ -*-===// |
| 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 declares the browser-specific compile server. | 10 // This file declares the browser-specific compile server. |
| 11 // | 11 // |
| 12 //===----------------------------------------------------------------------===// | 12 //===----------------------------------------------------------------------===// |
| 13 | 13 |
| 14 #ifndef SUBZERO_SRC_ICEBROWSERCOMPILESERVER_H | 14 #ifndef SUBZERO_SRC_ICEBROWSERCOMPILESERVER_H |
| 15 #define SUBZERO_SRC_ICEBROWSERCOMPILESERVER_H | 15 #define SUBZERO_SRC_ICEBROWSERCOMPILESERVER_H |
| 16 | 16 |
| 17 #include <atomic> |
| 17 #include <thread> | 18 #include <thread> |
| 18 | 19 |
| 19 #include "IceClFlags.h" | 20 #include "IceClFlags.h" |
| 20 #include "IceClFlagsExtra.h" | 21 #include "IceClFlagsExtra.h" |
| 21 #include "IceCompileServer.h" | 22 #include "IceCompileServer.h" |
| 22 #include "IceDefs.h" | 23 #include "IceDefs.h" |
| 23 #include "IceELFStreamer.h" | 24 #include "IceELFStreamer.h" |
| 24 | 25 |
| 25 namespace llvm { | 26 namespace llvm { |
| 26 class QueueStreamer; | 27 class QueueStreamer; |
| 27 class raw_fd_ostream; | 28 class raw_fd_ostream; |
| 28 } | 29 } |
| 29 | 30 |
| 30 namespace Ice { | 31 namespace Ice { |
| 31 | 32 |
| 32 // The browser variant of the compile server. | 33 // The browser variant of the compile server. |
| 33 // Compared to the commandline version, this version gets compile | 34 // Compared to the commandline version, this version gets compile |
| 34 // requests over IPC. Each compile request will have a slimmed down | 35 // requests over IPC. Each compile request will have a slimmed down |
| 35 // version of argc, argv while other flags are set to defaults that | 36 // version of argc, argv while other flags are set to defaults that |
| 36 // make sense in the browser case. The output file is specified via | 37 // make sense in the browser case. The output file is specified via |
| 37 // a posix FD, and input bytes are pushed to the server. | 38 // a posix FD, and input bytes are pushed to the server. |
| 38 class BrowserCompileServer : public CompileServer { | 39 class BrowserCompileServer : public CompileServer { |
| 39 BrowserCompileServer() = delete; | 40 BrowserCompileServer() = delete; |
| 40 BrowserCompileServer(const BrowserCompileServer &) = delete; | 41 BrowserCompileServer(const BrowserCompileServer &) = delete; |
| 41 BrowserCompileServer &operator=(const BrowserCompileServer &) = delete; | 42 BrowserCompileServer &operator=(const BrowserCompileServer &) = delete; |
| 42 class StringStream; | 43 class StringStream; |
| 43 | 44 |
| 44 public: | 45 public: |
| 45 explicit BrowserCompileServer(Compiler &Comp) | 46 explicit BrowserCompileServer(Compiler &Comp) |
| 46 : CompileServer(Comp), InputStream(nullptr) {} | 47 : CompileServer(Comp), InputStream(nullptr), HadError(false) {} |
| 47 | 48 |
| 48 ~BrowserCompileServer() final; | 49 ~BrowserCompileServer() final; |
| 49 | 50 |
| 50 void run() final; | 51 void run() final; |
| 51 | 52 |
| 53 ErrorCode &getErrorCode() final; |
| 54 |
| 52 // Parse and set up the flags for compile jobs. | 55 // Parse and set up the flags for compile jobs. |
| 53 void getParsedFlags(uint32_t NumThreads, int argc, char **argv); | 56 void getParsedFlags(uint32_t NumThreads, int argc, char **argv); |
| 54 | 57 |
| 55 // Creates the streams + context and starts the compile thread, | 58 // Creates the streams + context and starts the compile thread, |
| 56 // handing off the streams + context. | 59 // handing off the streams + context. |
| 57 void startCompileThread(int OutFD); | 60 void startCompileThread(int OutFD); |
| 58 | 61 |
| 59 // Call to push more bytes to the current input stream. | 62 // Call to push more bytes to the current input stream. |
| 60 // Returns false on success and true on error. | 63 // Returns false on success and true on error. |
| 61 bool pushInputBytes(const void *Data, size_t NumBytes); | 64 bool pushInputBytes(const void *Data, size_t NumBytes); |
| 62 | 65 |
| 63 // Notify the input stream of EOF. | 66 // Notify the input stream of EOF. |
| 64 void endInputStream(); | 67 void endInputStream(); |
| 65 | 68 |
| 66 // Wait for the compile thread to complete then reset the state. | 69 // Wait for the compile thread to complete then reset the state. |
| 67 void waitForCompileThread() { | 70 void waitForCompileThread() { |
| 68 CompileThread.join(); | 71 CompileThread.join(); |
| 69 LastError.assign(Ctx->getErrorStatus()->value()); | 72 if (Ctx->getErrorStatus()->value()) |
| 73 LastError.assign(Ctx->getErrorStatus()->value()); |
| 70 // Reset some state. The InputStream is deleted by the compiler | 74 // Reset some state. The InputStream is deleted by the compiler |
| 71 // so only reset this to nullptr. Free and flush the rest | 75 // so only reset this to nullptr. Free and flush the rest |
| 72 // of the streams. | 76 // of the streams. |
| 73 InputStream = nullptr; | 77 InputStream = nullptr; |
| 74 EmitStream.reset(nullptr); | 78 EmitStream.reset(nullptr); |
| 75 ELFStream.reset(nullptr); | 79 ELFStream.reset(nullptr); |
| 76 } | 80 } |
| 77 | 81 |
| 78 StringStream &getErrorStream() { return *ErrorStream; } | 82 StringStream &getErrorStream() { return *ErrorStream; } |
| 79 | 83 |
| 84 void setFatalError(const IceString &Reason); |
| 85 |
| 80 private: | 86 private: |
| 81 class StringStream { | 87 class StringStream { |
| 82 public: | 88 public: |
| 83 StringStream() : StrBuf(Buffer) {} | 89 StringStream() : StrBuf(Buffer) {} |
| 84 const IceString &getContents() { return StrBuf.str(); } | 90 const IceString &getContents() { return StrBuf.str(); } |
| 85 Ostream &getStream() { return StrBuf; } | 91 Ostream &getStream() { return StrBuf; } |
| 86 | 92 |
| 87 private: | 93 private: |
| 88 std::string Buffer; | 94 std::string Buffer; |
| 89 llvm::raw_string_ostream StrBuf; | 95 llvm::raw_string_ostream StrBuf; |
| 90 }; | 96 }; |
| 91 // This currently only handles a single compile request, hence one copy | 97 // This currently only handles a single compile request, hence one copy |
| 92 // of the state. | 98 // of the state. |
| 93 std::unique_ptr<GlobalContext> Ctx; | 99 std::unique_ptr<GlobalContext> Ctx; |
| 94 // A borrowed reference to the current InputStream. The compiler owns | 100 // A borrowed reference to the current InputStream. The compiler owns |
| 95 // the actual reference so the server must be careful not to access | 101 // the actual reference so the server must be careful not to access |
| 96 // after the compiler is done. | 102 // after the compiler is done. |
| 97 llvm::QueueStreamer *InputStream; | 103 llvm::QueueStreamer *InputStream; |
| 98 std::unique_ptr<Ostream> LogStream; | 104 std::unique_ptr<Ostream> LogStream; |
| 99 std::unique_ptr<llvm::raw_fd_ostream> EmitStream; | 105 std::unique_ptr<llvm::raw_fd_ostream> EmitStream; |
| 100 std::unique_ptr<StringStream> ErrorStream; | 106 std::unique_ptr<StringStream> ErrorStream; |
| 101 std::unique_ptr<ELFStreamer> ELFStream; | 107 std::unique_ptr<ELFStreamer> ELFStream; |
| 102 ClFlags Flags; | 108 ClFlags Flags; |
| 103 ClFlagsExtra ExtraFlags; | 109 ClFlagsExtra ExtraFlags; |
| 104 std::thread CompileThread; | 110 std::thread CompileThread; |
| 111 std::atomic<bool> HadError; |
| 105 }; | 112 }; |
| 106 | 113 |
| 107 } // end of namespace Ice | 114 } // end of namespace Ice |
| 108 | 115 |
| 109 #endif // SUBZERO_SRC_ICEBROWSERCOMPILESERVER_H | 116 #endif // SUBZERO_SRC_ICEBROWSERCOMPILESERVER_H |
| OLD | NEW |