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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 //===- subzero/src/IceCompiler.cpp - Driver for bitcode translation -------===// 1 //===- subzero/src/IceCompiler.cpp - Driver for bitcode translation -------===//
2 // 2 //
3 // The Subzero Code Generator 3 // The Subzero Code Generator
4 // 4 //
5 // This file is distributed under the University of Illinois Open Source 5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details. 6 // License. See LICENSE.TXT for details.
7 // 7 //
8 //===----------------------------------------------------------------------===// 8 //===----------------------------------------------------------------------===//
9 /// 9 ///
10 /// \file 10 /// \file
(...skipping 24 matching lines...) Expand all
35 #include "llvm/IR/Module.h" 35 #include "llvm/IR/Module.h"
36 #include "llvm/IRReader/IRReader.h" 36 #include "llvm/IRReader/IRReader.h"
37 #include "llvm/Support/SourceMgr.h" 37 #include "llvm/Support/SourceMgr.h"
38 #include "llvm/Support/StreamingMemoryObject.h" 38 #include "llvm/Support/StreamingMemoryObject.h"
39 #pragma clang diagnostic pop 39 #pragma clang diagnostic pop
40 40
41 namespace Ice { 41 namespace Ice {
42 42
43 namespace { 43 namespace {
44 44
45 struct { 45 struct CBA {
46 const char *FlagName; 46 const char *FlagName;
47 int FlagValue; 47 bool FlagValue;
48 } ConditionalBuildAttributes[] = { 48 } ConditionalBuildAttributes[] = {
49 {"dump", BuildDefs::dump()}, 49 {"dump", BuildDefs::dump()},
50 {"llvm_cl", BuildDefs::llvmCl()}, 50 {"llvm_cl", BuildDefs::llvmCl()},
51 {"llvm_ir", BuildDefs::llvmIr()}, 51 {"llvm_ir", BuildDefs::llvmIr()},
52 {"llvm_ir_as_input", BuildDefs::llvmIrAsInput()}, 52 {"llvm_ir_as_input", BuildDefs::llvmIrAsInput()},
53 {"minimal_build", BuildDefs::minimal()}, 53 {"minimal_build", BuildDefs::minimal()},
54 {"browser_mode", BuildDefs::browser()}}; 54 {"browser_mode", BuildDefs::browser()}};
55 55
56 // Validates values of build attributes. Prints them to Stream if Stream is 56 /// 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.
57 // non-null. 57 /// non-null.
58 void validateAndGenerateBuildAttributes(Ostream *Stream) { 58 void dumpBuildAttributes(Ostream *Stream) {
59 // List the supported targets. 59 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.
60 if (Stream) { 60 return;
61 // List the supported targets.
61 #define SUBZERO_TARGET(TARGET) *Stream << "target_" #TARGET << "\n"; 62 #define SUBZERO_TARGET(TARGET) *Stream << "target_" #TARGET << "\n";
62 #include "llvm/Config/SZTargets.def" 63 #include "llvm/Config/SZTargets.def"
63 } 64 const char *Prefix[2] = {"no", "allow"};
64
65 for (size_t i = 0; i < llvm::array_lengthof(ConditionalBuildAttributes); 65 for (size_t i = 0; i < llvm::array_lengthof(ConditionalBuildAttributes);
66 ++i) { 66 ++i) {
67 switch (ConditionalBuildAttributes[i].FlagValue) { 67 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.
68 case 0: 68 *Stream << Prefix[A.FlagValue] << "_" << A.FlagName << "\n";
69 if (Stream)
70 *Stream << "no_" << ConditionalBuildAttributes[i].FlagName << "\n";
71 break;
72 case 1:
73 if (Stream)
74 *Stream << "allow_" << ConditionalBuildAttributes[i].FlagName << "\n";
75 break;
76 default: {
77 std::string Buffer;
78 llvm::raw_string_ostream StrBuf(Buffer);
79 StrBuf << "Flag " << ConditionalBuildAttributes[i].FlagName
80 << " must be defined as 0/1. Found: "
81 << ConditionalBuildAttributes[i].FlagValue;
82 llvm::report_fatal_error(StrBuf.str());
83 }
84 }
85 } 69 }
86 } 70 }
87 71
88 } // end of anonymous namespace 72 } // end of anonymous namespace
89 73
90 void Compiler::run(const Ice::ClFlagsExtra &ExtraFlags, GlobalContext &Ctx, 74 void Compiler::run(const Ice::ClFlagsExtra &ExtraFlags, GlobalContext &Ctx,
91 std::unique_ptr<llvm::DataStreamer> &&InputStream) { 75 std::unique_ptr<llvm::DataStreamer> &&InputStream) {
92 validateAndGenerateBuildAttributes( 76 dumpBuildAttributes(ExtraFlags.getGenerateBuildAtts() ? &Ctx.getStrDump()
93 ExtraFlags.getGenerateBuildAtts() ? &Ctx.getStrDump() : nullptr); 77 : nullptr);
94 if (ExtraFlags.getGenerateBuildAtts()) 78 if (ExtraFlags.getGenerateBuildAtts())
95 return Ctx.getErrorStatus()->assign(EC_None); 79 return Ctx.getErrorStatus()->assign(EC_None);
96 80
97 // The Minimal build (specifically, when dump()/emit() are not implemented) 81 // The Minimal build (specifically, when dump()/emit() are not implemented)
98 // allows only --filetype=obj. Check here to avoid cryptic error messages 82 // allows only --filetype=obj. Check here to avoid cryptic error messages
99 // downstream. 83 // downstream.
100 if (!BuildDefs::dump() && Ctx.getFlags().getOutFileType() != FT_Elf) { 84 if (!BuildDefs::dump() && Ctx.getFlags().getOutFileType() != FT_Elf) {
101 // TODO(stichnot): Access the actual command-line argument via 85 // TODO(stichnot): Access the actual command-line argument via
102 // llvm::Option.ArgStr and .ValueStr . 86 // llvm::Option.ArgStr and .ValueStr .
103 Ctx.getStrError() 87 Ctx.getStrError()
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 161
178 if (Ctx.getFlags().getTimeEachFunction()) { 162 if (Ctx.getFlags().getTimeEachFunction()) {
179 constexpr bool DumpCumulative = false; 163 constexpr bool DumpCumulative = false;
180 Ctx.dumpTimers(GlobalContext::TSK_Funcs, DumpCumulative); 164 Ctx.dumpTimers(GlobalContext::TSK_Funcs, DumpCumulative);
181 } 165 }
182 constexpr bool FinalStats = true; 166 constexpr bool FinalStats = true;
183 Ctx.dumpStats("_FINAL_", FinalStats); 167 Ctx.dumpStats("_FINAL_", FinalStats);
184 } 168 }
185 169
186 } // end of namespace Ice 170 } // end of namespace Ice
OLDNEW
« 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