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

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: changes suggested by stichnot Created 4 years, 12 months 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 26 matching lines...) Expand all
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 {
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 non-null.
57 // non-null. 57 void dumpBuildAttributes(Ostream *Stream) {
58 void validateAndGenerateBuildAttributes(Ostream *Stream) { 58 if (Stream == nullptr)
59 // List the supported targets. 59 return;
60 if (Stream) { 60 // List the supported targets.
61 #define SUBZERO_TARGET(TARGET) *Stream << "target_" #TARGET << "\n"; 61 #define SUBZERO_TARGET(TARGET) *Stream << "target_" #TARGET << "\n";
62 #include "llvm/Config/SZTargets.def" 62 #include "llvm/Config/SZTargets.def"
63 } 63 const char *Prefix[2] = {"no", "allow"};
64
65 for (size_t i = 0; i < llvm::array_lengthof(ConditionalBuildAttributes); 64 for (size_t i = 0; i < llvm::array_lengthof(ConditionalBuildAttributes);
66 ++i) { 65 ++i) {
67 switch (ConditionalBuildAttributes[i].FlagValue) { 66 const auto &A = ConditionalBuildAttributes[i];
68 case 0: 67 *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 } 68 }
86 } 69 }
87 70
88 } // end of anonymous namespace 71 } // end of anonymous namespace
89 72
90 void Compiler::run(const Ice::ClFlagsExtra &ExtraFlags, GlobalContext &Ctx, 73 void Compiler::run(const Ice::ClFlagsExtra &ExtraFlags, GlobalContext &Ctx,
91 std::unique_ptr<llvm::DataStreamer> &&InputStream) { 74 std::unique_ptr<llvm::DataStreamer> &&InputStream) {
92 validateAndGenerateBuildAttributes( 75 dumpBuildAttributes(ExtraFlags.getGenerateBuildAtts() ? &Ctx.getStrDump()
93 ExtraFlags.getGenerateBuildAtts() ? &Ctx.getStrDump() : nullptr); 76 : nullptr);
94 if (ExtraFlags.getGenerateBuildAtts()) 77 if (ExtraFlags.getGenerateBuildAtts())
95 return Ctx.getErrorStatus()->assign(EC_None); 78 return Ctx.getErrorStatus()->assign(EC_None);
96 79
97 // The Minimal build (specifically, when dump()/emit() are not implemented) 80 // The Minimal build (specifically, when dump()/emit() are not implemented)
98 // allows only --filetype=obj. Check here to avoid cryptic error messages 81 // allows only --filetype=obj. Check here to avoid cryptic error messages
99 // downstream. 82 // downstream.
100 if (!BuildDefs::dump() && Ctx.getFlags().getOutFileType() != FT_Elf) { 83 if (!BuildDefs::dump() && Ctx.getFlags().getOutFileType() != FT_Elf) {
101 // TODO(stichnot): Access the actual command-line argument via 84 // TODO(stichnot): Access the actual command-line argument via
102 // llvm::Option.ArgStr and .ValueStr . 85 // llvm::Option.ArgStr and .ValueStr .
103 Ctx.getStrError() 86 Ctx.getStrError()
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 160
178 if (Ctx.getFlags().getTimeEachFunction()) { 161 if (Ctx.getFlags().getTimeEachFunction()) {
179 constexpr bool DumpCumulative = false; 162 constexpr bool DumpCumulative = false;
180 Ctx.dumpTimers(GlobalContext::TSK_Funcs, DumpCumulative); 163 Ctx.dumpTimers(GlobalContext::TSK_Funcs, DumpCumulative);
181 } 164 }
182 constexpr bool FinalStats = true; 165 constexpr bool FinalStats = true;
183 Ctx.dumpStats("_FINAL_", FinalStats); 166 Ctx.dumpStats("_FINAL_", FinalStats);
184 } 167 }
185 168
186 } // end of namespace Ice 169 } // 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