Jan Voung | 44c3a80 | 2015-03-27 16:29:08 -0700 | [diff] [blame] | 1 | //===- subzero/src/IceCompileServer.h - Compile 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 | //===----------------------------------------------------------------------===// |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 9 | /// |
| 10 | /// \file |
| 11 | /// This file declares the compile server. Given a compiler implementation, |
| 12 | /// it dispatches compile requests to the implementation. |
| 13 | /// |
Jan Voung | 44c3a80 | 2015-03-27 16:29:08 -0700 | [diff] [blame] | 14 | //===----------------------------------------------------------------------===// |
| 15 | |
| 16 | #ifndef SUBZERO_SRC_ICECOMPILESERVER_H |
| 17 | #define SUBZERO_SRC_ICECOMPILESERVER_H |
| 18 | |
| 19 | #include "IceCompiler.h" |
| 20 | #include "IceDefs.h" |
| 21 | #include "IceGlobalContext.h" |
| 22 | |
| 23 | namespace llvm { |
| 24 | class DataStreamer; |
| 25 | class raw_fd_ostream; |
Mircea Trofin | 59c6f5a | 2015-04-06 16:06:47 -0700 | [diff] [blame] | 26 | } |
Jan Voung | 44c3a80 | 2015-03-27 16:29:08 -0700 | [diff] [blame] | 27 | |
| 28 | namespace Ice { |
| 29 | |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 30 | /// A CompileServer awaits compile requests, and dispatches the requests |
| 31 | /// to a given Compiler. Each request is paired with an input stream, |
| 32 | /// a context (which has the output stream), and a set of arguments. |
| 33 | /// The CompileServer takes over the current thread to listen to requests, |
| 34 | /// and compile requests are handled on separate threads. |
| 35 | /// |
| 36 | /// Currently, this only handles a single request. |
| 37 | /// |
| 38 | /// When run on the commandline, it receives and therefore dispatches |
| 39 | /// the request immediately. When run in the browser, it blocks waiting |
| 40 | /// for a request. |
Jan Voung | 44c3a80 | 2015-03-27 16:29:08 -0700 | [diff] [blame] | 41 | class CompileServer { |
| 42 | CompileServer() = delete; |
| 43 | CompileServer(const CompileServer &) = delete; |
| 44 | CompileServer &operator=(const CompileServer &) = delete; |
| 45 | |
| 46 | public: |
| 47 | explicit CompileServer(Compiler &Comp) : Comp(Comp) {} |
| 48 | |
Jim Stichnoth | eafb56c | 2015-06-22 10:35:22 -0700 | [diff] [blame] | 49 | virtual ~CompileServer() = default; |
Jan Voung | 44c3a80 | 2015-03-27 16:29:08 -0700 | [diff] [blame] | 50 | |
| 51 | virtual void run() = 0; |
| 52 | |
Jan Voung | 2f7f2b7 | 2015-06-03 17:50:20 -0700 | [diff] [blame] | 53 | virtual ErrorCode &getErrorCode() { return LastError; } |
Jan Voung | 44c3a80 | 2015-03-27 16:29:08 -0700 | [diff] [blame] | 54 | void transferErrorCode(ErrorCodes Code) { LastError.assign(Code); } |
| 55 | |
| 56 | protected: |
| 57 | Compiler &getCompiler() const { return Comp; } |
| 58 | |
| 59 | Compiler &Comp; |
| 60 | ErrorCode LastError; |
| 61 | }; |
| 62 | |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 63 | /// Commandline variant of the compile server. |
Jan Voung | 44c3a80 | 2015-03-27 16:29:08 -0700 | [diff] [blame] | 64 | class CLCompileServer : public CompileServer { |
| 65 | CLCompileServer() = delete; |
| 66 | CLCompileServer(const CLCompileServer &) = delete; |
| 67 | CLCompileServer &operator=(const CLCompileServer &) = delete; |
| 68 | |
| 69 | public: |
| 70 | CLCompileServer(Compiler &Comp, int argc, char **argv) |
| 71 | : CompileServer(Comp), argc(argc), argv(argv) {} |
| 72 | |
Jim Stichnoth | e587d94 | 2015-06-22 15:49:04 -0700 | [diff] [blame] | 73 | ~CLCompileServer() final = default; |
Jan Voung | 44c3a80 | 2015-03-27 16:29:08 -0700 | [diff] [blame] | 74 | |
| 75 | void run() final; |
| 76 | |
| 77 | private: |
| 78 | int argc; |
| 79 | char **argv; |
| 80 | std::unique_ptr<GlobalContext> Ctx; |
| 81 | }; |
| 82 | |
| 83 | } // end of namespace Ice |
| 84 | |
| 85 | #endif // SUBZERO_SRC_ICECOMPILESERVER_H |