OLD | NEW |
(Empty) | |
| 1 //===- subzero/src/IceBrowserCompileServer.h - Browser server ---*- C++ -*-===// |
| 2 // |
| 3 // The Subzero Code Generator |
| 4 // |
| 5 // This file is distributed under the University of Illinois Open Source |
| 6 // License. See LICENSE.TXT for details. |
| 7 // |
| 8 //===----------------------------------------------------------------------===// |
| 9 // |
| 10 // This file declares the browser-specific compile server. |
| 11 // |
| 12 //===----------------------------------------------------------------------===// |
| 13 |
| 14 #ifndef SUBZERO_SRC_ICEBROWSERCOMPILESERVER_H |
| 15 #define SUBZERO_SRC_ICEBROWSERCOMPILESERVER_H |
| 16 |
| 17 #include <thread> |
| 18 |
| 19 #include "IceClFlags.h" |
| 20 #include "IceClFlagsExtra.h" |
| 21 #include "IceCompileServer.h" |
| 22 #include "IceDefs.h" |
| 23 #include "IceELFStreamer.h" |
| 24 |
| 25 namespace llvm { |
| 26 class QueueStreamer; |
| 27 class raw_fd_ostream; |
| 28 }; |
| 29 |
| 30 namespace Ice { |
| 31 |
| 32 // The browser variant of the compile server. |
| 33 // Compared to the commandline version, this version gets compile |
| 34 // 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 // 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 class BrowserCompileServer : public CompileServer { |
| 39 BrowserCompileServer() = delete; |
| 40 BrowserCompileServer(const BrowserCompileServer &) = delete; |
| 41 BrowserCompileServer &operator=(const BrowserCompileServer &) = delete; |
| 42 |
| 43 public: |
| 44 explicit BrowserCompileServer(Compiler &Comp) |
| 45 : CompileServer(Comp), InputStream(nullptr) {} |
| 46 |
| 47 ~BrowserCompileServer() final; |
| 48 |
| 49 void run() final; |
| 50 |
| 51 // Parse and set up the flags for compile jobs. |
| 52 void getParsedFlags(uint32_t NumThreads, int argc, char **argv); |
| 53 |
| 54 // Creates the streams + context and starts the compile thread, |
| 55 // handing off the streams + context. |
| 56 void startCompileThread(int OutFD); |
| 57 |
| 58 // Call to push more bytes to the current input stream. |
| 59 // Returns false on success and true on error. |
| 60 bool pushInputBytes(const void *Data, size_t NumBytes); |
| 61 |
| 62 // Notify the input stream of EOF. |
| 63 void endInputStream(); |
| 64 |
| 65 // Wait for the compile thread to complete then reset the state. |
| 66 void waitForCompileThread() { |
| 67 CompileThread.join(); |
| 68 LastError.assign(Ctx->getErrorStatus()->value()); |
| 69 // Reset some state. The InputStream is deleted by the compiler |
| 70 // so only reset this to nullptr. Free and flush the rest |
| 71 // of the streams. |
| 72 InputStream = nullptr; |
| 73 EmitStream.reset(nullptr); |
| 74 ELFStream.reset(nullptr); |
| 75 } |
| 76 |
| 77 private: |
| 78 // This currently only handles a single compile request, hence one copy |
| 79 // of the state. |
| 80 std::unique_ptr<GlobalContext> Ctx; |
| 81 // A borrowed reference to the current InputStream. The compiler owns |
| 82 // the actual reference so the server must be careful not to access |
| 83 // after the compiler is done. |
| 84 llvm::QueueStreamer *InputStream; |
| 85 std::unique_ptr<Ostream> LogStream; |
| 86 std::unique_ptr<llvm::raw_fd_ostream> EmitStream; |
| 87 std::unique_ptr<ELFStreamer> ELFStream; |
| 88 ClFlags Flags; |
| 89 ClFlagsExtra ExtraFlags; |
| 90 std::thread CompileThread; |
| 91 }; |
| 92 |
| 93 } // end of namespace Ice |
| 94 |
| 95 #endif // SUBZERO_SRC_ICEBROWSERCOMPILESERVER_H |
OLD | NEW |