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 {
/// 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.
class BrowserCompileServer : public CompileServer {
BrowserCompileServer() = delete;
BrowserCompileServer(const BrowserCompileServer &) = delete;
BrowserCompileServer &operator=(const BrowserCompileServer &) = delete;
class StringStream;
public:
explicit BrowserCompileServer(Compiler &Comp)
: CompileServer(Comp), InputStream(nullptr), HadError(false) {}
BrowserCompileServer() : HadError(false) {}
~BrowserCompileServer() final;
......
......@@ -35,6 +35,16 @@ constexpr bool asserts() {
#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.
constexpr bool extraValidation() {
#if ALLOW_EXTRA_VALIDATION
......
......@@ -41,12 +41,11 @@ namespace Ice {
/// request immediately. When run in the browser, it blocks waiting for a
/// request.
class CompileServer {
CompileServer() = delete;
CompileServer(const CompileServer &) = delete;
CompileServer &operator=(const CompileServer &) = delete;
public:
explicit CompileServer(Compiler &Comp) : Comp(Comp) {}
CompileServer() = default;
virtual ~CompileServer() = default;
......@@ -55,10 +54,15 @@ public:
virtual ErrorCode &getErrorCode() { return LastError; }
void transferErrorCode(ErrorCodes Code) { LastError.assign(Code); }
int runAndReturnErrorCode() {
run();
return getErrorCode().value();
}
protected:
Compiler &getCompiler() const { return Comp; }
Compiler &getCompiler() { return Comp; }
Compiler &Comp;
Compiler Comp;
ErrorCode LastError;
};
......@@ -69,8 +73,7 @@ class CLCompileServer : public CompileServer {
CLCompileServer &operator=(const CLCompileServer &) = delete;
public:
CLCompileServer(Compiler &Comp, int argc, char **argv)
: CompileServer(Comp), argc(argc), argv(argv) {}
CLCompileServer(int argc, char **argv) : argc(argc), argv(argv) {}
~CLCompileServer() final = default;
......
......@@ -14,25 +14,17 @@
//===----------------------------------------------------------------------===//
#include "IceBrowserCompileServer.h"
#include "IceCompiler.h"
#include "IceBuildDefs.h"
#include "IceCompileServer.h"
int main(int argc, char **argv) {
// Start file server and "wait" for compile request.
Ice::Compiler Comp;
// Can only compile the BrowserCompileServer w/ the NaCl compiler.
#if PNACL_BROWSER_TRANSLATOR
// There are no real commandline arguments in the browser case. They are
// supplied via IPC.
assert(argc == 1);
(void)argc;
(void)argv;
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
// Can only compile the BrowserCompileServer w/ the NaCl compiler.
if (Ice::BuildDefs::browser()) {
// There are no real commandline arguments in the browser case. They are
// supplied via IPC.
assert(argc == 1);
return Ice::BrowserCompileServer().runAndReturnErrorCode();
}
return Ice::CLCompileServer(argc, argv).runAndReturnErrorCode();
}
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