• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===- 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 //===----------------------------------------------------------------------===//
9 ///
10 /// \file
11 /// \brief Declares the compile server.
12 ///
13 /// Given a compiler implementation, it dispatches compile requests to the
14 /// implementation.
15 ///
16 //===----------------------------------------------------------------------===//
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 
25 namespace llvm {
26 class DataStreamer;
27 class raw_fd_ostream;
28 }
29 
30 namespace Ice {
31 
32 /// 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.
37 ///
38 /// Currently, this only handles a single request.
39 ///
40 /// 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.
43 class CompileServer {
44   CompileServer(const CompileServer &) = delete;
45   CompileServer &operator=(const CompileServer &) = delete;
46 
47 public:
48   CompileServer() = default;
49 
50   virtual ~CompileServer() = default;
51 
52   virtual void run() = 0;
53 
getErrorCode()54   virtual ErrorCode &getErrorCode() { return LastError; }
transferErrorCode(ErrorCodes Code)55   void transferErrorCode(ErrorCodes Code) { LastError.assign(Code); }
56 
runAndReturnErrorCode()57   int runAndReturnErrorCode() {
58     run();
59     return getErrorCode().value();
60   }
61 
62 protected:
getCompiler()63   Compiler &getCompiler() { return Comp; }
64 
65   Compiler Comp;
66   ErrorCode LastError;
67 };
68 
69 /// Commandline variant of the compile server.
70 class CLCompileServer : public CompileServer {
71   CLCompileServer() = delete;
72   CLCompileServer(const CLCompileServer &) = delete;
73   CLCompileServer &operator=(const CLCompileServer &) = delete;
74 
75 public:
CLCompileServer(int argc,char ** argv)76   CLCompileServer(int argc, char **argv) : argc(argc), argv(argv) {}
77 
78   ~CLCompileServer() final = default;
79 
80   void run() final;
81 
82 private:
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
91