Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 //===- subzero/src/llvm2ice.cpp - Driver for testing ----------------------===// | 1 //===- subzero/src/llvm2ice.cpp - Driver for testing ----------------------===// |
| 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 that uses LLVM capabilities to parse a | 10 // This file defines a driver that uses LLVM capabilities to parse a |
| 11 // bitcode file and build the LLVM IR, and then convert the LLVM basic | 11 // bitcode file and build the LLVM IR, and then convert the LLVM basic |
| 12 // blocks, instructions, and operands into their Subzero equivalents. | 12 // blocks, instructions, and operands into their Subzero equivalents. |
| 13 // | 13 // |
| 14 //===----------------------------------------------------------------------===// | 14 //===----------------------------------------------------------------------===// |
| 15 | 15 |
| 16 #include <fstream> | 16 #include <fstream> |
| 17 #include <iostream> | 17 #include <iostream> |
| 18 | 18 |
| 19 #include "llvm/ADT/STLExtras.h" | |
| 19 #include "llvm/IR/LLVMContext.h" | 20 #include "llvm/IR/LLVMContext.h" |
| 20 #include "llvm/IRReader/IRReader.h" | 21 #include "llvm/IRReader/IRReader.h" |
| 21 #include "llvm/Support/CommandLine.h" | 22 #include "llvm/Support/CommandLine.h" |
| 22 #include "llvm/Support/raw_os_ostream.h" | 23 #include "llvm/Support/raw_os_ostream.h" |
| 23 #include "llvm/Support/SourceMgr.h" | 24 #include "llvm/Support/SourceMgr.h" |
| 24 | 25 |
| 25 #include "IceCfg.h" | 26 #include "IceCfg.h" |
| 26 #include "IceClFlags.h" | 27 #include "IceClFlags.h" |
| 27 #include "IceConverter.h" | 28 #include "IceConverter.h" |
| 28 #include "PNaClTranslator.h" | 29 #include "PNaClTranslator.h" |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 154 cl::desc("Use integrated assembler (default yes)"), | 155 cl::desc("Use integrated assembler (default yes)"), |
| 155 cl::init(true)); | 156 cl::init(true)); |
| 156 | 157 |
| 157 static cl::alias UseIas("ias", cl::desc("Alias for -integrated-as"), | 158 static cl::alias UseIas("ias", cl::desc("Alias for -integrated-as"), |
| 158 cl::NotHidden, cl::aliasopt(UseIntegratedAssembler)); | 159 cl::NotHidden, cl::aliasopt(UseIntegratedAssembler)); |
| 159 | 160 |
| 160 static cl::opt<bool> AlwaysExitSuccess( | 161 static cl::opt<bool> AlwaysExitSuccess( |
| 161 "exit-success", cl::desc("Exit with success status, even if errors found"), | 162 "exit-success", cl::desc("Exit with success status, even if errors found"), |
| 162 cl::init(false)); | 163 cl::init(false)); |
| 163 | 164 |
| 165 static cl::opt<bool> GenerateBuildAtts( | |
| 166 "build-atts", cl::desc("Generate list of build attributes associated with " | |
| 167 "this executable."), | |
| 168 cl::init(false)); | |
| 169 | |
| 164 static int GetReturnValue(int Val) { | 170 static int GetReturnValue(int Val) { |
| 165 if (AlwaysExitSuccess) | 171 if (AlwaysExitSuccess) |
| 166 return 0; | 172 return 0; |
| 167 return Val; | 173 return Val; |
| 168 } | 174 } |
| 169 | 175 |
| 176 static struct { | |
| 177 const char *FlagName; | |
| 178 int FlagValue; | |
| 179 } ConditionalBuildAttributes[] = { | |
| 180 { "text_asm", ALLOW_TEXT_ASM }, | |
| 181 { "dump", ALLOW_DUMP }, | |
| 182 { "llvm_cl", ALLOW_LLVM_CL }, | |
| 183 { "llvm_ir", ALLOW_LLVM_IR }, | |
| 184 { "llvm_ir_as_input", ALLOW_LLVM_IR_AS_INPUT } | |
| 185 }; | |
| 186 | |
| 187 // Validates values of build attributes. Prints them to Stream if | |
| 188 // Stream is non-null. | |
| 189 static void ValidateAndGenerateBuildAttributes(raw_os_ostream *Stream) { | |
| 190 | |
| 191 // TODO(kschimpf): Conditionalize this once we have multiple targets. | |
|
Jim Stichnoth
2014/10/21 21:58:41
After the GlobalContext object is created, you cou
Karl
2014/10/22 17:03:36
Done.
| |
| 192 if (Stream) | |
| 193 *Stream << "x86-32\n"; | |
| 194 | |
| 195 for (size_t i = 0; i < array_lengthof(ConditionalBuildAttributes); ++i) { | |
| 196 switch (ConditionalBuildAttributes[i].FlagValue) { | |
| 197 case 0: | |
| 198 if (Stream) | |
| 199 *Stream << "no_" << ConditionalBuildAttributes[i].FlagName << "\n"; | |
| 200 break; | |
| 201 case 1: | |
| 202 if (Stream) | |
| 203 *Stream << "allow_" << ConditionalBuildAttributes[i].FlagName << "\n"; | |
| 204 break; | |
| 205 default: { | |
| 206 std::string Buffer; | |
| 207 raw_string_ostream StrBuf(Buffer); | |
| 208 StrBuf << "Flag " << ConditionalBuildAttributes[i].FlagName | |
| 209 << " must be defined as 0/1. Found: " | |
| 210 << ConditionalBuildAttributes[i].FlagValue; | |
| 211 report_fatal_error(StrBuf.str()); | |
| 212 } | |
| 213 } | |
| 214 } | |
| 215 } | |
| 216 | |
| 170 int main(int argc, char **argv) { | 217 int main(int argc, char **argv) { |
| 171 | 218 |
| 172 cl::ParseCommandLineOptions(argc, argv); | 219 cl::ParseCommandLineOptions(argc, argv); |
| 173 | 220 |
| 174 Ice::VerboseMask VMask = Ice::IceV_None; | 221 Ice::VerboseMask VMask = Ice::IceV_None; |
| 175 for (unsigned i = 0; i != VerboseList.size(); ++i) | 222 for (unsigned i = 0; i != VerboseList.size(); ++i) |
| 176 VMask |= VerboseList[i]; | 223 VMask |= VerboseList[i]; |
| 177 | 224 |
| 178 std::ofstream Ofs; | 225 std::ofstream Ofs; |
| 179 if (OutputFilename != "-") { | 226 if (OutputFilename != "-") { |
| 180 Ofs.open(OutputFilename.c_str(), std::ofstream::out); | 227 Ofs.open(OutputFilename.c_str(), std::ofstream::out); |
| 181 } | 228 } |
| 182 raw_os_ostream *Os = | 229 raw_os_ostream *Os = |
| 183 new raw_os_ostream(OutputFilename == "-" ? std::cout : Ofs); | 230 new raw_os_ostream(OutputFilename == "-" ? std::cout : Ofs); |
| 184 Os->SetUnbuffered(); | 231 Os->SetUnbuffered(); |
| 232 | |
| 233 ValidateAndGenerateBuildAttributes(GenerateBuildAtts ? Os : nullptr); | |
| 234 if (GenerateBuildAtts) | |
| 235 return GetReturnValue(0); | |
| 236 | |
| 185 std::ofstream Lfs; | 237 std::ofstream Lfs; |
| 186 if (LogFilename != "-") { | 238 if (LogFilename != "-") { |
| 187 Lfs.open(LogFilename.c_str(), std::ofstream::out); | 239 Lfs.open(LogFilename.c_str(), std::ofstream::out); |
| 188 } | 240 } |
| 189 raw_os_ostream *Ls = new raw_os_ostream(LogFilename == "-" ? std::cout : Lfs); | 241 raw_os_ostream *Ls = new raw_os_ostream(LogFilename == "-" ? std::cout : Lfs); |
| 190 Ls->SetUnbuffered(); | 242 Ls->SetUnbuffered(); |
| 191 | 243 |
| 192 Ice::ClFlags Flags; | 244 Ice::ClFlags Flags; |
| 193 Flags.DisableInternal = DisableInternal; | 245 Flags.DisableInternal = DisableInternal; |
| 194 Flags.SubzeroTimingEnabled = SubzeroTimingEnabled; | 246 Flags.SubzeroTimingEnabled = SubzeroTimingEnabled; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 233 if (TimeEachFunction) { | 285 if (TimeEachFunction) { |
| 234 const bool DumpCumulative = false; | 286 const bool DumpCumulative = false; |
| 235 Ctx.dumpTimers(Ice::GlobalContext::TSK_Funcs, DumpCumulative); | 287 Ctx.dumpTimers(Ice::GlobalContext::TSK_Funcs, DumpCumulative); |
| 236 } | 288 } |
| 237 if (SubzeroTimingEnabled) | 289 if (SubzeroTimingEnabled) |
| 238 Ctx.dumpTimers(); | 290 Ctx.dumpTimers(); |
| 239 const bool FinalStats = true; | 291 const bool FinalStats = true; |
| 240 Ctx.dumpStats("_FINAL_", FinalStats); | 292 Ctx.dumpStats("_FINAL_", FinalStats); |
| 241 return GetReturnValue(ErrorStatus); | 293 return GetReturnValue(ErrorStatus); |
| 242 } | 294 } |
| OLD | NEW |