OLD | NEW |
(Empty) | |
| 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 //===----------------------------------------------------------------------===// |
| 9 // |
| 10 // This file declares the compile server. Given a compiler implementation, |
| 11 // it dispatches compile requests to the implementation. Each request is paired |
| 12 // with an abstraction of the input and output streams, which the compiler |
| 13 // will acquire. |
| 14 // |
| 15 //===----------------------------------------------------------------------===// |
| 16 |
| 17 #ifndef SUBZERO_SRC_ICECOMPILESERVER_H |
| 18 #define SUBZERO_SRC_ICECOMPILESERVER_H |
| 19 |
| 20 #include "IceCompiler.h" |
| 21 #include "IceDefs.h" |
| 22 |
| 23 namespace llvm { |
| 24 class DataStreamer; |
| 25 class raw_fd_ostream; |
| 26 }; |
| 27 |
| 28 namespace Ice { |
| 29 |
| 30 // A CompileServer awaits compile requests, and dispatches the requests |
| 31 // to a given Compiler. Each request is paired with an input stream, |
| 32 // an output stream, and a set of arguments. The CompileServer takes |
| 33 // over the current thread to listen to requests, and creates separate |
| 34 // threads to handle each compile request. |
| 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. |
| 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 |
| 49 virtual ~CompileServer() {} |
| 50 |
| 51 virtual void run() = 0; |
| 52 |
| 53 // Return an input stream. This may be shared between the caller and |
| 54 // the server, but the caller owns it. The server must be careful |
| 55 // not to use the data stream once the caller is done. |
| 56 virtual std::unique_ptr<llvm::DataStreamer> |
| 57 getInputStream(const IceString &InputFilename, std::string &ErrorString) = 0; |
| 58 |
| 59 // Return an output stream. The server does not need access to the |
| 60 // output stream, so this is owned by the caller. |
| 61 virtual std::unique_ptr<llvm::raw_fd_ostream> |
| 62 getOutputStream(const IceString &OutputFilename, std::error_code &EC) = 0; |
| 63 |
| 64 Compiler &getCompiler() const { return Comp; } |
| 65 |
| 66 int getReturnValue() const { return Comp.getReturnValue(); } |
| 67 |
| 68 protected: |
| 69 Compiler &Comp; |
| 70 }; |
| 71 |
| 72 // Commandline variant of the compile server. |
| 73 class CLCompileServer : public CompileServer { |
| 74 CLCompileServer() = delete; |
| 75 CLCompileServer(const CLCompileServer &) = delete; |
| 76 CLCompileServer &operator=(const CLCompileServer &) = delete; |
| 77 |
| 78 public: |
| 79 CLCompileServer(Compiler &Comp, int argc, char **argv) |
| 80 : CompileServer(Comp), argc(argc), argv(argv) {} |
| 81 |
| 82 ~CLCompileServer() final {} |
| 83 |
| 84 void run() final; |
| 85 |
| 86 std::unique_ptr<llvm::DataStreamer> |
| 87 getInputStream(const IceString &InputFilename, |
| 88 std::string &ErrorString) final; |
| 89 |
| 90 std::unique_ptr<llvm::raw_fd_ostream> |
| 91 getOutputStream(const IceString &OutputFilename, std::error_code &EC) final; |
| 92 |
| 93 private: |
| 94 int argc; |
| 95 char **argv; |
| 96 }; |
| 97 |
| 98 } // end of namespace Ice |
| 99 |
| 100 #endif // SUBZERO_SRC_ICECOMPILESERVER_H |
OLD | NEW |