blob: 3b4726d9945619336f2ff96d24bc071740bc508a [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;
Antonio Maioranodebdfa22020-11-10 16:28:34 -050028} // namespace llvm
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 {
Jan Voung44c3a802015-03-27 16:29:08 -070044 CompileServer(const CompileServer &) = delete;
45 CompileServer &operator=(const CompileServer &) = delete;
46
47public:
Reed Kotler43e8ab32015-12-07 14:31:01 -080048 CompileServer() = default;
Jan Voung44c3a802015-03-27 16:29:08 -070049
Jim Stichnotheafb56c2015-06-22 10:35:22 -070050 virtual ~CompileServer() = default;
Jan Voung44c3a802015-03-27 16:29:08 -070051
52 virtual void run() = 0;
53
Jan Voung2f7f2b72015-06-03 17:50:20 -070054 virtual ErrorCode &getErrorCode() { return LastError; }
Jan Voung44c3a802015-03-27 16:29:08 -070055 void transferErrorCode(ErrorCodes Code) { LastError.assign(Code); }
56
Reed Kotler43e8ab32015-12-07 14:31:01 -080057 int runAndReturnErrorCode() {
58 run();
59 return getErrorCode().value();
60 }
Jan Voung44c3a802015-03-27 16:29:08 -070061
Reed Kotler43e8ab32015-12-07 14:31:01 -080062protected:
63 Compiler &getCompiler() { return Comp; }
64
65 Compiler Comp;
Jan Voung44c3a802015-03-27 16:29:08 -070066 ErrorCode LastError;
67};
68
Andrew Scull9612d322015-07-06 14:53:25 -070069/// Commandline variant of the compile server.
Jan Voung44c3a802015-03-27 16:29:08 -070070class CLCompileServer : public CompileServer {
71 CLCompileServer() = delete;
72 CLCompileServer(const CLCompileServer &) = delete;
73 CLCompileServer &operator=(const CLCompileServer &) = delete;
74
75public:
Reed Kotler43e8ab32015-12-07 14:31:01 -080076 CLCompileServer(int argc, char **argv) : argc(argc), argv(argv) {}
Jan Voung44c3a802015-03-27 16:29:08 -070077
Jim Stichnothe587d942015-06-22 15:49:04 -070078 ~CLCompileServer() final = default;
Jan Voung44c3a802015-03-27 16:29:08 -070079
80 void run() final;
81
82private:
83 int argc;
84 char **argv;
85 std::unique_ptr<GlobalContext> Ctx;
86};
87
88} // end of namespace Ice
89
90#endif // SUBZERO_SRC_ICECOMPILESERVER_H