Index: src/IceCompileServer.h |
diff --git a/src/IceCompileServer.h b/src/IceCompileServer.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..55b20599f59647c8ab05ece6c61ef287db541392 |
--- /dev/null |
+++ b/src/IceCompileServer.h |
@@ -0,0 +1,100 @@ |
+//===- subzero/src/IceCompileServer.h - Compile server ----------*- C++ -*-===// |
+// |
+// The Subzero Code Generator |
+// |
+// This file is distributed under the University of Illinois Open Source |
+// License. See LICENSE.TXT for details. |
+// |
+//===----------------------------------------------------------------------===// |
+// |
+// This file declares the compile server. Given a compiler implementation, |
+// it dispatches compile requests to the implementation. Each request is paired |
+// with an abstraction of the input and output streams, which the compiler |
+// will acquire. |
+// |
+//===----------------------------------------------------------------------===// |
+ |
+#ifndef SUBZERO_SRC_ICECOMPILESERVER_H |
+#define SUBZERO_SRC_ICECOMPILESERVER_H |
+ |
+#include "IceCompiler.h" |
+#include "IceDefs.h" |
+ |
+namespace llvm { |
+class DataStreamer; |
+class raw_fd_ostream; |
+}; |
+ |
+namespace Ice { |
+ |
+// A CompileServer awaits compile requests, and dispatches the requests |
+// to a given Compiler. Each request is paired with an input stream, |
+// an output stream, and a set of arguments. The CompileServer takes |
+// over the current thread to listen to requests, and creates separate |
+// threads to handle each compile request. |
+// |
+// Currently, this only handles a single request. |
+// |
+// When run on the commandline, it receives and therefore dispatches |
+// the request immediately. When run in the browser, it blocks waiting |
+// for a request. |
+class CompileServer { |
+ CompileServer() = delete; |
+ CompileServer(const CompileServer &) = delete; |
+ CompileServer &operator=(const CompileServer &) = delete; |
+ |
+public: |
+ explicit CompileServer(Compiler &Comp) : Comp(Comp) {} |
+ |
+ virtual ~CompileServer() {} |
+ |
+ virtual void run() = 0; |
+ |
+ // Return an input stream. This may be shared between the caller and |
+ // the server, but the caller owns it. The server must be careful |
+ // not to use the data stream once the caller is done. |
+ virtual std::unique_ptr<llvm::DataStreamer> |
+ getInputStream(const IceString &InputFilename, std::string &ErrorString) = 0; |
+ |
+ // Return an output stream. The server does not need access to the |
+ // output stream, so this is owned by the caller. |
+ virtual std::unique_ptr<llvm::raw_fd_ostream> |
+ getOutputStream(const IceString &OutputFilename, std::error_code &EC) = 0; |
+ |
+ Compiler &getCompiler() const { return Comp; } |
+ |
+ int getReturnValue() const { return Comp.getReturnValue(); } |
+ |
+protected: |
+ Compiler &Comp; |
+}; |
+ |
+// Commandline variant of the compile server. |
+class CLCompileServer : public CompileServer { |
+ CLCompileServer() = delete; |
+ CLCompileServer(const CLCompileServer &) = delete; |
+ CLCompileServer &operator=(const CLCompileServer &) = delete; |
+ |
+public: |
+ CLCompileServer(Compiler &Comp, int argc, char **argv) |
+ : CompileServer(Comp), argc(argc), argv(argv) {} |
+ |
+ ~CLCompileServer() final {} |
+ |
+ void run() final; |
+ |
+ std::unique_ptr<llvm::DataStreamer> |
+ getInputStream(const IceString &InputFilename, |
+ std::string &ErrorString) final; |
+ |
+ std::unique_ptr<llvm::raw_fd_ostream> |
+ getOutputStream(const IceString &OutputFilename, std::error_code &EC) final; |
+ |
+private: |
+ int argc; |
+ char **argv; |
+}; |
+ |
+} // end of namespace Ice |
+ |
+#endif // SUBZERO_SRC_ICECOMPILESERVER_H |