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

Side by Side Diff: src/IceCompiler.cpp

Issue 1197863003: Subzero: Reduce the amount of #ifdef'd code. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Cleanup Created 5 years, 5 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 | « src/IceCompileServer.cpp ('k') | src/IceConverter.cpp » ('j') | 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 // This file defines a driver for translating PNaCl bitcode into native code. 10 // This file defines a driver for translating PNaCl bitcode into native code.
(...skipping 18 matching lines...) Expand all
29 #include "IceConverter.h" 29 #include "IceConverter.h"
30 #include "IceELFObjectWriter.h" 30 #include "IceELFObjectWriter.h"
31 #include "PNaClTranslator.h" 31 #include "PNaClTranslator.h"
32 namespace Ice { 32 namespace Ice {
33 33
34 namespace { 34 namespace {
35 35
36 struct { 36 struct {
37 const char *FlagName; 37 const char *FlagName;
38 int FlagValue; 38 int FlagValue;
39 } ConditionalBuildAttributes[] = {{"dump", ALLOW_DUMP}, 39 } ConditionalBuildAttributes[] = {
40 {"disable_ir_gen", ALLOW_DISABLE_IR_GEN}, 40 {"dump", BuildDefs::dump()},
41 {"llvm_cl", ALLOW_LLVM_CL}, 41 {"disable_ir_gen", BuildDefs::disableIrGen()},
42 {"llvm_ir", ALLOW_LLVM_IR}, 42 {"llvm_cl", BuildDefs::llvmCl()},
43 {"llvm_ir_as_input", ALLOW_LLVM_IR_AS_INPUT}, 43 {"llvm_ir", BuildDefs::llvmIr()},
44 {"minimal_build", ALLOW_MINIMAL_BUILD}, 44 {"llvm_ir_as_input", BuildDefs::llvmIrAsInput()},
45 {"browser_mode", PNACL_BROWSER_TRANSLATOR}}; 45 {"minimal_build", BuildDefs::minimal()},
46 {"browser_mode", PNACL_BROWSER_TRANSLATOR}};
46 47
47 // Validates values of build attributes. Prints them to Stream if 48 // Validates values of build attributes. Prints them to Stream if
48 // Stream is non-null. 49 // Stream is non-null.
49 void validateAndGenerateBuildAttributes(Ostream *Stream) { 50 void validateAndGenerateBuildAttributes(Ostream *Stream) {
50 // List the supported targets. 51 // List the supported targets.
51 if (Stream) { 52 if (Stream) {
52 #define SUBZERO_TARGET(TARGET) *Stream << "target_" #TARGET << "\n"; 53 #define SUBZERO_TARGET(TARGET) *Stream << "target_" #TARGET << "\n";
53 #include "llvm/Config/SZTargets.def" 54 #include "llvm/Config/SZTargets.def"
54 } 55 }
55 56
(...skipping 22 matching lines...) Expand all
78 79
79 } // end of anonymous namespace 80 } // end of anonymous namespace
80 81
81 void Compiler::run(const Ice::ClFlagsExtra &ExtraFlags, GlobalContext &Ctx, 82 void Compiler::run(const Ice::ClFlagsExtra &ExtraFlags, GlobalContext &Ctx,
82 std::unique_ptr<llvm::DataStreamer> &&InputStream) { 83 std::unique_ptr<llvm::DataStreamer> &&InputStream) {
83 validateAndGenerateBuildAttributes( 84 validateAndGenerateBuildAttributes(
84 ExtraFlags.getGenerateBuildAtts() ? &Ctx.getStrDump() : nullptr); 85 ExtraFlags.getGenerateBuildAtts() ? &Ctx.getStrDump() : nullptr);
85 if (ExtraFlags.getGenerateBuildAtts()) 86 if (ExtraFlags.getGenerateBuildAtts())
86 return Ctx.getErrorStatus()->assign(EC_None); 87 return Ctx.getErrorStatus()->assign(EC_None);
87 88
88 if (!ALLOW_DISABLE_IR_GEN && Ctx.getFlags().getDisableIRGeneration()) { 89 if (!BuildDefs::disableIrGen() && Ctx.getFlags().getDisableIRGeneration()) {
89 Ctx.getStrDump() << "Error: Build doesn't allow --no-ir-gen when not " 90 Ctx.getStrDump() << "Error: Build doesn't allow --no-ir-gen when not "
90 << "ALLOW_DISABLE_IR_GEN!\n"; 91 << "ALLOW_DISABLE_IR_GEN!\n";
91 return Ctx.getErrorStatus()->assign(EC_Args); 92 return Ctx.getErrorStatus()->assign(EC_Args);
92 } 93 }
93 94
94 // Force -build-on-read=0 for .ll files. 95 // Force -build-on-read=0 for .ll files.
95 const std::string LLSuffix = ".ll"; 96 const std::string LLSuffix = ".ll";
96 const IceString &IRFilename = ExtraFlags.getIRFilename(); 97 const IceString &IRFilename = ExtraFlags.getIRFilename();
97 bool BuildOnRead = ExtraFlags.getBuildOnRead(); 98 bool BuildOnRead = ExtraFlags.getBuildOnRead();
98 if (ALLOW_LLVM_IR_AS_INPUT && IRFilename.length() >= LLSuffix.length() && 99 if (BuildDefs::llvmIrAsInput() && IRFilename.length() >= LLSuffix.length() &&
99 IRFilename.compare(IRFilename.length() - LLSuffix.length(), 100 IRFilename.compare(IRFilename.length() - LLSuffix.length(),
100 LLSuffix.length(), LLSuffix) == 0) 101 LLSuffix.length(), LLSuffix) == 0)
101 BuildOnRead = false; 102 BuildOnRead = false;
102 103
103 TimerMarker T(Ice::TimerStack::TT_szmain, &Ctx); 104 TimerMarker T(Ice::TimerStack::TT_szmain, &Ctx);
104 105
105 Ctx.emitFileHeader(); 106 Ctx.emitFileHeader();
106 Ctx.startWorkerThreads(); 107 Ctx.startWorkerThreads();
107 108
108 std::unique_ptr<Translator> Translator; 109 std::unique_ptr<Translator> Translator;
109 if (BuildOnRead) { 110 if (BuildOnRead) {
110 std::unique_ptr<PNaClTranslator> PTranslator(new PNaClTranslator(&Ctx)); 111 std::unique_ptr<PNaClTranslator> PTranslator(new PNaClTranslator(&Ctx));
111 std::unique_ptr<llvm::StreamingMemoryObject> MemObj( 112 std::unique_ptr<llvm::StreamingMemoryObject> MemObj(
112 new llvm::StreamingMemoryObjectImpl(InputStream.release())); 113 new llvm::StreamingMemoryObjectImpl(InputStream.release()));
113 PTranslator->translate(IRFilename, std::move(MemObj)); 114 PTranslator->translate(IRFilename, std::move(MemObj));
114 Translator.reset(PTranslator.release()); 115 Translator.reset(PTranslator.release());
115 } else if (ALLOW_LLVM_IR) { 116 } else if (BuildDefs::llvmIr()) {
116 if (PNACL_BROWSER_TRANSLATOR) { 117 if (PNACL_BROWSER_TRANSLATOR) {
117 Ctx.getStrDump() 118 Ctx.getStrDump()
118 << "non BuildOnRead is not supported w/ PNACL_BROWSER_TRANSLATOR\n"; 119 << "non BuildOnRead is not supported w/ PNACL_BROWSER_TRANSLATOR\n";
119 return Ctx.getErrorStatus()->assign(EC_Args); 120 return Ctx.getErrorStatus()->assign(EC_Args);
120 } 121 }
121 // Parse the input LLVM IR file into a module. 122 // Parse the input LLVM IR file into a module.
122 llvm::SMDiagnostic Err; 123 llvm::SMDiagnostic Err;
123 TimerMarker T1(Ice::TimerStack::TT_parse, &Ctx); 124 TimerMarker T1(Ice::TimerStack::TT_parse, &Ctx);
124 llvm::raw_ostream *Verbose = 125 llvm::raw_ostream *Verbose =
125 ExtraFlags.getLLVMVerboseErrors() ? &llvm::errs() : nullptr; 126 ExtraFlags.getLLVMVerboseErrors() ? &llvm::errs() : nullptr;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 161
161 if (Ctx.getFlags().getTimeEachFunction()) { 162 if (Ctx.getFlags().getTimeEachFunction()) {
162 const bool DumpCumulative = false; 163 const bool DumpCumulative = false;
163 Ctx.dumpTimers(GlobalContext::TSK_Funcs, DumpCumulative); 164 Ctx.dumpTimers(GlobalContext::TSK_Funcs, DumpCumulative);
164 } 165 }
165 constexpr bool FinalStats = true; 166 constexpr bool FinalStats = true;
166 Ctx.dumpStats("_FINAL_", FinalStats); 167 Ctx.dumpStats("_FINAL_", FinalStats);
167 } 168 }
168 169
169 } // end of namespace Ice 170 } // end of namespace Ice
OLDNEW
« no previous file with comments | « src/IceCompileServer.cpp ('k') | src/IceConverter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698