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