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

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: FlagValue is always a bool 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..5cf9220353924666efeead17a123d6c211a5da48 100644
--- a/src/IceCompiler.cpp
+++ b/src/IceCompiler.cpp
@@ -42,9 +42,9 @@ namespace Ice {
namespace {
-struct {
+struct CBA {
const char *FlagName;
- int FlagValue;
+ bool FlagValue;
} ConditionalBuildAttributes[] = {
{"dump", BuildDefs::dump()},
{"llvm_cl", BuildDefs::llvmCl()},
@@ -53,35 +53,19 @@ 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
Jim Stichnoth 2015/12/19 16:12:54 Reflow comment to 80-col
rkotlerimgtec 2015/12/21 02:51:31 Done.
+/// non-null.
+void dumpBuildAttributes(Ostream *Stream) {
+ if (!Stream)
Jim Stichnoth 2015/12/19 16:12:54 Stream == nullptr I think the code base is incons
rkotlerimgtec 2015/12/21 02:51:30 Done.
+ 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 CBA &A = ConditionalBuildAttributes[i];
Jim Stichnoth 2015/12/19 16:12:54 I think you can use "const auto &A" here, and ther
rkotlerimgtec 2015/12/21 02:51:31 Done.
+ *Stream << Prefix[A.FlagValue] << "_" << A.FlagName << "\n";
}
}
@@ -89,8 +73,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