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