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

Unified Diff: src/IceCompiler.cpp

Issue 1534883005: cleanup and rename validateAndGenerateBuildAttributes (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 2d70b6641800227e2f50b47b5543e2973d4f5dfa..c510e284a3c20ec2705ee8b47f7cb3828bf9059a 100644
--- a/src/IceCompiler.cpp
+++ b/src/IceCompiler.cpp
@@ -44,7 +44,7 @@ namespace {
struct {
const char *FlagName;
- int FlagValue;
+ bool FlagValue;
} ConditionalBuildAttributes[] = {
{"dump", BuildDefs::dump()},
{"llvm_cl", BuildDefs::llvmCl()},
@@ -53,35 +53,18 @@ struct {
{"minimal_build", BuildDefs::minimal()},
{"browser_mode", BuildDefs::browser()}};
-// Validates values of build attributes. Prints them to Stream if Stream is
-// non-null.
-void validateAndGenerateBuildAttributes(Ostream *Stream) {
- // List the supported targets.
- if (Stream) {
+/// Dumps values of build attributes to Stream if Stream is non-null.
+void dumpBuildAttributes(Ostream *Stream) {
+ if (Stream == nullptr)
+ return;
+// List the supported targets.
#define SUBZERO_TARGET(TARGET) *Stream << "target_" #TARGET << "\n";
#include "llvm/Config/SZTargets.def"
- }
-
+ const char *Prefix[2] = {"no", "allow"};
for (size_t i = 0; i < llvm::array_lengthof(ConditionalBuildAttributes);
++i) {
- switch (ConditionalBuildAttributes[i].FlagValue) {
- case 0:
- if (Stream)
- *Stream << "no_" << ConditionalBuildAttributes[i].FlagName << "\n";
- break;
- case 1:
- if (Stream)
- *Stream << "allow_" << ConditionalBuildAttributes[i].FlagName << "\n";
- break;
- default: {
- std::string Buffer;
- llvm::raw_string_ostream StrBuf(Buffer);
- StrBuf << "Flag " << ConditionalBuildAttributes[i].FlagName
- << " must be defined as 0/1. Found: "
- << ConditionalBuildAttributes[i].FlagValue;
- llvm::report_fatal_error(StrBuf.str());
- }
- }
+ const auto &A = ConditionalBuildAttributes[i];
+ *Stream << Prefix[A.FlagValue] << "_" << A.FlagName << "\n";
}
}
@@ -89,8 +72,8 @@ void validateAndGenerateBuildAttributes(Ostream *Stream) {
void Compiler::run(const Ice::ClFlagsExtra &ExtraFlags, GlobalContext &Ctx,
std::unique_ptr<llvm::DataStreamer> &&InputStream) {
- validateAndGenerateBuildAttributes(
- ExtraFlags.getGenerateBuildAtts() ? &Ctx.getStrDump() : nullptr);
+ dumpBuildAttributes(ExtraFlags.getGenerateBuildAtts() ? &Ctx.getStrDump()
+ : nullptr);
if (ExtraFlags.getGenerateBuildAtts())
return Ctx.getErrorStatus()->assign(EC_None);
« 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