blob: 9b02f92c85259263ff07f89787d811b741f6c80d [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
Jim Stichnoth92a6e5b2015-12-02 16:52:44 -080011/// \brief Declares the compile server.
12///
13/// Given a compiler implementation, it dispatches compile requests to the
14/// implementation.
Andrew Scull9612d322015-07-06 14:53:25 -070015///
Jan Voung44c3a802015-03-27 16:29:08 -070016//===----------------------------------------------------------------------===//
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
25namespace llvm {
26class DataStreamer;
27class raw_fd_ostream;
Mircea Trofin59c6f5a2015-04-06 16:06:47 -070028}
Jan Voung44c3a802015-03-27 16:29:08 -070029
30namespace Ice {
31
Andrew Scull57e12682015-09-16 11:30:19 -070032/// 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 Scull9612d322015-07-06 14:53:25 -070037///
38/// Currently, this only handles a single request.
39///
Andrew Scull57e12682015-09-16 11:30:19 -070040/// 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 Voung44c3a802015-03-27 16:29:08 -070043class CompileServer {
44 CompileServer() = delete;
45 CompileServer(const CompileServer &) = delete;
46 CompileServer &operator=(const CompileServer &) = delete;
47
48public:
49 explicit CompileServer(Compiler &Comp) : Comp(Comp) {}
50
Jim Stichnotheafb56c2015-06-22 10:35:22 -070051 virtual ~CompileServer() = default;
Jan Voung44c3a802015-03-27 16:29:08 -070052
53 virtual void run() = 0;
54
Jan Voung2f7f2b72015-06-03 17:50:20 -070055 virtual ErrorCode &getErrorCode() { return LastError; }
Jan Voung44c3a802015-03-27 16:29:08 -070056 void transferErrorCode(ErrorCodes Code) { LastError.assign(Code); }
57
58protected:
59 Compiler &getCompiler() const { return Comp; }
60
61 Compiler &Comp;
62 ErrorCode LastError;
63};
64
Andrew Scull9612d322015-07-06 14:53:25 -070065/// Commandline variant of the compile server.
Jan Voung44c3a802015-03-27 16:29:08 -070066class CLCompileServer : public CompileServer {
67 CLCompileServer() = delete;
68 CLCompileServer(const CLCompileServer &) = delete;
69 CLCompileServer &operator=(const CLCompileServer &) = delete;
70
71public:
72 CLCompileServer(Compiler &Comp, int argc, char **argv)
73 : CompileServer(Comp), argc(argc), argv(argv) {}
74
Jim Stichnothe587d942015-06-22 15:49:04 -070075 ~CLCompileServer() final = default;
Jan Voung44c3a802015-03-27 16:29:08 -070076
77 void run() final;
78
79private:
80 int argc;
81 char **argv;
82 std::unique_ptr<GlobalContext> Ctx;
83};
84
85} // end of namespace Ice
86
87#endif // SUBZERO_SRC_ICECOMPILESERVER_H