Chromium Code Reviews| Index: src/IceBrowserCompileServer.h |
| diff --git a/src/IceBrowserCompileServer.h b/src/IceBrowserCompileServer.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..177440f7ef96d7041a1c6656f936b4b55985bf57 |
| --- /dev/null |
| +++ b/src/IceBrowserCompileServer.h |
| @@ -0,0 +1,95 @@ |
| +//===- subzero/src/IceBrowserCompileServer.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_ICEBROWSERCOMPILESERVER_H |
| +#define SUBZERO_SRC_ICEBROWSERCOMPILESERVER_H |
| + |
| +#include <thread> |
| + |
| +#include "IceCompileServer.h" |
| +#include "IceDefs.h" |
| + |
| +namespace llvm { |
| +class DataStreamer; |
| +class QueueStreamer; |
| +class raw_fd_ostream; |
| +}; |
| + |
| +namespace Ice { |
| + |
| +// Browser variant of the compile server. |
| +class BrowserCompileServer : public CompileServer { |
| + BrowserCompileServer() = delete; |
| + BrowserCompileServer(const BrowserCompileServer &) = delete; |
| + BrowserCompileServer &operator=(const BrowserCompileServer &) = delete; |
| + |
| +public: |
| + BrowserCompileServer(Compiler &Comp) |
|
Jim Stichnoth
2015/03/13 04:55:00
explicit
jvoung (off chromium)
2015/03/18 15:39:09
Done.
|
| + : CompileServer(Comp), OutputFD(-1), InputStream(nullptr), argc(-1), |
| + argv(nullptr) {} |
| + |
| + ~BrowserCompileServer() 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; |
| + |
| + void takeArgs(int argc_, char **argv_) { |
| + argc = argc_; |
| + argv = argv_; |
| + } |
| + |
| + // Call to push more bytes to the current input stream. |
| + // Returns false on success and true on error. |
| + bool pushInputBytes(unsigned char *Data, size_t NumBytes); |
| + |
| + // Notify the input stream of EOF. |
| + void endInputStream(); |
| + |
| + // Set the output file descriptor to use for the current compile |
| + // request. Must be called before getOutputStream(). |
| + void setOutputFD(int fd) { OutputFD = fd; } |
| + |
| + // Start the compile thread. |
| + void startCompileThread(); |
| + |
| + // Wait for the compile thread to complete. |
| + void waitForCompileThread() { |
| + CompileThread.join(); |
| + InputStream = nullptr; |
| + } |
| + |
| +private: |
| + // This currently only handles a single compile request, hence one copy |
| + // of the state. |
| + int OutputFD; |
| + // A borrowed reference to the current InputStream. The compiler owns |
| + // the actual reference so the server must be careful not to access |
| + // after the compiler is done. |
| + llvm::QueueStreamer *InputStream; |
| + std::thread CompileThread; |
| + int argc; |
| + char **argv; |
| +}; |
| + |
| +} // end of namespace Ice |
| + |
| +#endif // SUBZERO_SRC_ICEBROWSERCOMPILESERVER_H |