Commit 43e8ab38 by Reed Kotler Committed by Jim Stichnoth

cleanup main

seems like these two lines are common to both paths and in fact the different classes allocated are derived from the same common base class so this makes sense to me. BUG= R=stichnot@chromium.org Review URL: https://codereview.chromium.org/1494753003 . Patch from Reed Kotler <rkotlerimgtec@gmail.com>.
parent 4ddce702
...@@ -37,14 +37,12 @@ namespace Ice { ...@@ -37,14 +37,12 @@ namespace Ice {
/// defaults that make sense in the browser case. The output file is specified /// defaults that make sense in the browser case. The output file is specified
/// via a posix FD, and input bytes are pushed to the server. /// via a posix FD, and input bytes are pushed to the server.
class BrowserCompileServer : public CompileServer { class BrowserCompileServer : public CompileServer {
BrowserCompileServer() = delete;
BrowserCompileServer(const BrowserCompileServer &) = delete; BrowserCompileServer(const BrowserCompileServer &) = delete;
BrowserCompileServer &operator=(const BrowserCompileServer &) = delete; BrowserCompileServer &operator=(const BrowserCompileServer &) = delete;
class StringStream; class StringStream;
public: public:
explicit BrowserCompileServer(Compiler &Comp) BrowserCompileServer() : HadError(false) {}
: CompileServer(Comp), InputStream(nullptr), HadError(false) {}
~BrowserCompileServer() final; ~BrowserCompileServer() final;
......
...@@ -35,6 +35,16 @@ constexpr bool asserts() { ...@@ -35,6 +35,16 @@ constexpr bool asserts() {
#endif // !NDEBUG #endif // !NDEBUG
} }
// PNACL_BROWSER_TRANSLATOR can be undefined, or defined to something non-zero
// to indicate a browser-based translator.
constexpr bool browser() {
#if PNACL_BROWSER_TRANSLATOR
return true;
#else // !PNACL_BROWSER_TRANSLATOR
return false;
#endif // !PNACL_BROWSER_TRANSLATOR
}
// ALLOW_EXTRA_VALIDATION can be undefined, or defined to something non-zero. // ALLOW_EXTRA_VALIDATION can be undefined, or defined to something non-zero.
constexpr bool extraValidation() { constexpr bool extraValidation() {
#if ALLOW_EXTRA_VALIDATION #if ALLOW_EXTRA_VALIDATION
......
...@@ -41,12 +41,11 @@ namespace Ice { ...@@ -41,12 +41,11 @@ namespace Ice {
/// request immediately. When run in the browser, it blocks waiting for a /// request immediately. When run in the browser, it blocks waiting for a
/// request. /// request.
class CompileServer { class CompileServer {
CompileServer() = delete;
CompileServer(const CompileServer &) = delete; CompileServer(const CompileServer &) = delete;
CompileServer &operator=(const CompileServer &) = delete; CompileServer &operator=(const CompileServer &) = delete;
public: public:
explicit CompileServer(Compiler &Comp) : Comp(Comp) {} CompileServer() = default;
virtual ~CompileServer() = default; virtual ~CompileServer() = default;
...@@ -55,10 +54,15 @@ public: ...@@ -55,10 +54,15 @@ public:
virtual ErrorCode &getErrorCode() { return LastError; } virtual ErrorCode &getErrorCode() { return LastError; }
void transferErrorCode(ErrorCodes Code) { LastError.assign(Code); } void transferErrorCode(ErrorCodes Code) { LastError.assign(Code); }
int runAndReturnErrorCode() {
run();
return getErrorCode().value();
}
protected: protected:
Compiler &getCompiler() const { return Comp; } Compiler &getCompiler() { return Comp; }
Compiler &Comp; Compiler Comp;
ErrorCode LastError; ErrorCode LastError;
}; };
...@@ -69,8 +73,7 @@ class CLCompileServer : public CompileServer { ...@@ -69,8 +73,7 @@ class CLCompileServer : public CompileServer {
CLCompileServer &operator=(const CLCompileServer &) = delete; CLCompileServer &operator=(const CLCompileServer &) = delete;
public: public:
CLCompileServer(Compiler &Comp, int argc, char **argv) CLCompileServer(int argc, char **argv) : argc(argc), argv(argv) {}
: CompileServer(Comp), argc(argc), argv(argv) {}
~CLCompileServer() final = default; ~CLCompileServer() final = default;
......
...@@ -14,25 +14,17 @@ ...@@ -14,25 +14,17 @@
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#include "IceBrowserCompileServer.h" #include "IceBrowserCompileServer.h"
#include "IceCompiler.h" #include "IceBuildDefs.h"
#include "IceCompileServer.h" #include "IceCompileServer.h"
int main(int argc, char **argv) { int main(int argc, char **argv) {
// Start file server and "wait" for compile request. // Start file server and "wait" for compile request.
Ice::Compiler Comp; // Can only compile the BrowserCompileServer w/ the NaCl compiler.
// Can only compile the BrowserCompileServer w/ the NaCl compiler. if (Ice::BuildDefs::browser()) {
#if PNACL_BROWSER_TRANSLATOR // There are no real commandline arguments in the browser case. They are
// There are no real commandline arguments in the browser case. They are // supplied via IPC.
// supplied via IPC. assert(argc == 1);
assert(argc == 1); return Ice::BrowserCompileServer().runAndReturnErrorCode();
(void)argc; }
(void)argv; return Ice::CLCompileServer(argc, argv).runAndReturnErrorCode();
Ice::BrowserCompileServer Server(Comp);
Server.run();
return Server.getErrorCode().value();
#else // !PNACL_BROWSER_TRANSLATOR
Ice::CLCompileServer Server(Comp, argc, argv);
Server.run();
return Server.getErrorCode().value();
#endif // !PNACL_BROWSER_TRANSLATOR
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment