blob: 8d9992798370625705bc4d1a1a0b632c9f700d09 [file] [log] [blame]
Jan Voung44c3a802015-03-27 16:29:08 -07001//===- 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 Scull9612d322015-07-06 14:53:25 -07009///
10/// \file
Andrew Scull57e12682015-09-16 11:30:19 -070011/// This file declares the compile server. Given a compiler implementation, it
12/// dispatches compile requests to the implementation.
Andrew Scull9612d322015-07-06 14:53:25 -070013///
Jan Voung44c3a802015-03-27 16:29:08 -070014//===----------------------------------------------------------------------===//
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
23namespace llvm {
24class DataStreamer;
25class raw_fd_ostream;
Mircea Trofin59c6f5a2015-04-06 16:06:47 -070026}
Jan Voung44c3a802015-03-27 16:29:08 -070027
28namespace Ice {
29
Andrew Scull57e12682015-09-16 11:30:19 -070030/// A CompileServer awaits compile requests, and dispatches the requests to a
31/// given Compiler. Each request is paired with an input stream, a context
32/// (which has the output stream), and a set of arguments. The CompileServer
33/// takes over the current thread to listen to requests, and compile requests
34/// are handled on separate threads.
Andrew Scull9612d322015-07-06 14:53:25 -070035///
36/// Currently, this only handles a single request.
37///
Andrew Scull57e12682015-09-16 11:30:19 -070038/// When run on the commandline, it receives and therefore dispatches the
39/// request immediately. When run in the browser, it blocks waiting for a
40/// request.
Jan Voung44c3a802015-03-27 16:29:08 -070041class CompileServer {
42 CompileServer() = delete;
43 CompileServer(const CompileServer &) = delete;
44 CompileServer &operator=(const CompileServer &) = delete;
45
46public:
47 explicit CompileServer(Compiler &Comp) : Comp(Comp) {}
48
Jim Stichnotheafb56c2015-06-22 10:35:22 -070049 virtual ~CompileServer() = default;
Jan Voung44c3a802015-03-27 16:29:08 -070050
51 virtual void run() = 0;
52
Jan Voung2f7f2b72015-06-03 17:50:20 -070053 virtual ErrorCode &getErrorCode() { return LastError; }
Jan Voung44c3a802015-03-27 16:29:08 -070054 void transferErrorCode(ErrorCodes Code) { LastError.assign(Code); }
55
56protected:
57 Compiler &getCompiler() const { return Comp; }
58
59 Compiler &Comp;
60 ErrorCode LastError;
61};
62
Andrew Scull9612d322015-07-06 14:53:25 -070063/// Commandline variant of the compile server.
Jan Voung44c3a802015-03-27 16:29:08 -070064class CLCompileServer : public CompileServer {
65 CLCompileServer() = delete;
66 CLCompileServer(const CLCompileServer &) = delete;
67 CLCompileServer &operator=(const CLCompileServer &) = delete;
68
69public:
70 CLCompileServer(Compiler &Comp, int argc, char **argv)
71 : CompileServer(Comp), argc(argc), argv(argv) {}
72
Jim Stichnothe587d942015-06-22 15:49:04 -070073 ~CLCompileServer() final = default;
Jan Voung44c3a802015-03-27 16:29:08 -070074
75 void run() final;
76
77private:
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