Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Unified Diff: src/IceCompiler.cpp

Issue 1541063002: misc cleanup of Compiler::run (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: changes suggested by stichnot Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/IceCompiler.cpp
diff --git a/src/IceCompiler.cpp b/src/IceCompiler.cpp
index c510e284a3c20ec2705ee8b47f7cb3828bf9059a..8736a665db173e211cc65fb173ab2e10fd5cbbdf 100644
--- a/src/IceCompiler.cpp
+++ b/src/IceCompiler.cpp
@@ -17,6 +17,8 @@
///
//===----------------------------------------------------------------------===//
+#include <regex>
+
#include "IceCompiler.h"
#include "IceBuildDefs.h"
@@ -67,16 +69,20 @@ void dumpBuildAttributes(Ostream *Stream) {
*Stream << Prefix[A.FlagValue] << "_" << A.FlagName << "\n";
}
}
+bool llvmIRInput(const IceString &Filename) {
+ return BuildDefs::llvmIrAsInput() &&
+ std::regex_match(Filename, std::regex(".*\\.ll"));
+}
} // end of anonymous namespace
void Compiler::run(const Ice::ClFlagsExtra &ExtraFlags, GlobalContext &Ctx,
std::unique_ptr<llvm::DataStreamer> &&InputStream) {
- dumpBuildAttributes(ExtraFlags.getGenerateBuildAtts() ? &Ctx.getStrDump()
- : nullptr);
- if (ExtraFlags.getGenerateBuildAtts())
- return Ctx.getErrorStatus()->assign(EC_None);
-
+ if (ExtraFlags.getGenerateBuildAtts()) {
+ dumpBuildAttributes(&Ctx.getStrDump());
+ Ctx.getErrorStatus()->assign(EC_None);
+ return;
+ }
// The Minimal build (specifically, when dump()/emit() are not implemented)
// allows only --filetype=obj. Check here to avoid cryptic error messages
// downstream.
@@ -85,24 +91,18 @@ void Compiler::run(const Ice::ClFlagsExtra &ExtraFlags, GlobalContext &Ctx,
// llvm::Option.ArgStr and .ValueStr .
Ctx.getStrError()
<< "Error: only --filetype=obj is supported in this build.\n";
- return Ctx.getErrorStatus()->assign(EC_Args);
+ Ctx.getErrorStatus()->assign(EC_Args);
+ return;
}
- // Force -build-on-read=0 for .ll files.
- const std::string LLSuffix = ".ll";
- const IceString &IRFilename = ExtraFlags.getIRFilename();
- bool BuildOnRead = ExtraFlags.getBuildOnRead();
- if (BuildDefs::llvmIrAsInput() && IRFilename.length() >= LLSuffix.length() &&
- IRFilename.compare(IRFilename.length() - LLSuffix.length(),
- LLSuffix.length(), LLSuffix) == 0)
- BuildOnRead = false;
-
TimerMarker T(Ice::TimerStack::TT_szmain, &Ctx);
Ctx.emitFileHeader();
Ctx.startWorkerThreads();
std::unique_ptr<Translator> Translator;
+ const IceString &IRFilename = ExtraFlags.getIRFilename();
+ bool BuildOnRead = ExtraFlags.getBuildOnRead() && !llvmIRInput(IRFilename);
if (BuildOnRead) {
std::unique_ptr<PNaClTranslator> PTranslator(new PNaClTranslator(&Ctx));
std::unique_ptr<llvm::StreamingMemoryObject> MemObj(
@@ -113,7 +113,8 @@ void Compiler::run(const Ice::ClFlagsExtra &ExtraFlags, GlobalContext &Ctx,
if (BuildDefs::browser()) {
Ctx.getStrError()
<< "non BuildOnRead is not supported w/ PNACL_BROWSER_TRANSLATOR\n";
- return Ctx.getErrorStatus()->assign(EC_Args);
+ Ctx.getErrorStatus()->assign(EC_Args);
+ return;
}
// Parse the input LLVM IR file into a module.
llvm::SMDiagnostic Err;
@@ -127,7 +128,8 @@ void Compiler::run(const Ice::ClFlagsExtra &ExtraFlags, GlobalContext &Ctx,
llvm::getGlobalContext(), DiagnosticHandler);
if (!Mod) {
Err.print(ExtraFlags.getAppName().c_str(), llvm::errs());
- return Ctx.getErrorStatus()->assign(EC_Bitcode);
+ Ctx.getErrorStatus()->assign(EC_Bitcode);
+ return;
}
std::unique_ptr<Converter> Converter(new class Converter(Mod.get(), &Ctx));
@@ -136,7 +138,8 @@ void Compiler::run(const Ice::ClFlagsExtra &ExtraFlags, GlobalContext &Ctx,
} else {
Ctx.getStrError() << "Error: Build doesn't allow LLVM IR, "
<< "--build-on-read=0 not allowed\n";
- return Ctx.getErrorStatus()->assign(EC_Args);
+ Ctx.getErrorStatus()->assign(EC_Args);
+ return;
}
Ctx.waitForWorkerThreads();
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698