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 |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 StubConstantCalls("stub-const-calls", | 177 StubConstantCalls("stub-const-calls", |
178 cl::desc("Stub indirect calls to constants."), | 178 cl::desc("Stub indirect calls to constants."), |
179 cl::init(false)); | 179 cl::init(false)); |
180 | 180 |
181 static cl::opt<bool> LLVMVerboseErrors( | 181 static cl::opt<bool> LLVMVerboseErrors( |
182 "verbose-llvm-parse-errors", | 182 "verbose-llvm-parse-errors", |
183 cl::desc("Print out more descriptive PNaCl bitcode parse errors when " | 183 cl::desc("Print out more descriptive PNaCl bitcode parse errors when " |
184 "building LLVM IR first"), | 184 "building LLVM IR first"), |
185 cl::init(false)); | 185 cl::init(false)); |
186 | 186 |
187 static cl::opt<bool> | 187 static cl::opt<Ice::FileType> OutFileType( |
188 UseIntegratedAssembler("integrated-as", | 188 "filetype", cl::desc("Output file type"), cl::init(Ice::FT_Iasm), |
189 cl::desc("Use integrated assembler (default yes)"), | 189 cl::values(clEnumValN(Ice::FT_Elf, "obj", "Native ELF object ('.o') file"), |
190 cl::init(true)); | 190 clEnumValN(Ice::FT_Asm, "asm", "Assembly ('.s') file"), |
191 | 191 clEnumValN(Ice::FT_Iasm, "iasm", |
192 static cl::alias UseIas("ias", cl::desc("Alias for -integrated-as"), | 192 "Low-level integrated assembly ('.s') file"), |
193 cl::NotHidden, cl::aliasopt(UseIntegratedAssembler)); | 193 clEnumValEnd)); |
194 | |
195 static cl::opt<bool> | |
196 UseELFWriter("elf-writer", | |
197 cl::desc("Use ELF writer with the integrated assembler"), | |
198 cl::init(false)); | |
199 | 194 |
200 static cl::opt<bool> AlwaysExitSuccess( | 195 static cl::opt<bool> AlwaysExitSuccess( |
201 "exit-success", cl::desc("Exit with success status, even if errors found"), | 196 "exit-success", cl::desc("Exit with success status, even if errors found"), |
202 cl::init(false)); | 197 cl::init(false)); |
203 | 198 |
204 static cl::opt<bool> GenerateBuildAtts( | 199 static cl::opt<bool> GenerateBuildAtts( |
205 "build-atts", cl::desc("Generate list of build attributes associated with " | 200 "build-atts", cl::desc("Generate list of build attributes associated with " |
206 "this executable."), | 201 "this executable."), |
207 cl::init(false)); | 202 cl::init(false)); |
208 | 203 |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 Flags.setDisableTranslation(DisableTranslation); | 305 Flags.setDisableTranslation(DisableTranslation); |
311 Flags.setDumpStats(DumpStats); | 306 Flags.setDumpStats(DumpStats); |
312 Flags.setFunctionSections(FunctionSections); | 307 Flags.setFunctionSections(FunctionSections); |
313 Flags.setNumTranslationThreads(NumThreads); | 308 Flags.setNumTranslationThreads(NumThreads); |
314 Flags.setPhiEdgeSplit(EnablePhiEdgeSplit); | 309 Flags.setPhiEdgeSplit(EnablePhiEdgeSplit); |
315 Flags.setStubConstantCalls(StubConstantCalls); | 310 Flags.setStubConstantCalls(StubConstantCalls); |
316 Flags.setSubzeroTimingEnabled(SubzeroTimingEnabled); | 311 Flags.setSubzeroTimingEnabled(SubzeroTimingEnabled); |
317 Flags.setTimeEachFunction(TimeEachFunction); | 312 Flags.setTimeEachFunction(TimeEachFunction); |
318 Flags.setTimingFocusOn(TimingFocusOn); | 313 Flags.setTimingFocusOn(TimingFocusOn); |
319 Flags.setTranslateOnly(TranslateOnly); | 314 Flags.setTranslateOnly(TranslateOnly); |
320 Flags.setUseELFWriter(UseELFWriter); | |
321 Flags.setUseIntegratedAssembler(UseIntegratedAssembler); | |
322 Flags.setUseSandboxing(UseSandboxing); | 315 Flags.setUseSandboxing(UseSandboxing); |
323 Flags.setVerboseFocusOn(VerboseFocusOn); | 316 Flags.setVerboseFocusOn(VerboseFocusOn); |
| 317 Flags.setOutFileType(OutFileType); |
324 | 318 |
325 // Force -build-on-read=0 for .ll files. | 319 // Force -build-on-read=0 for .ll files. |
326 const std::string LLSuffix = ".ll"; | 320 const std::string LLSuffix = ".ll"; |
327 if (IRFilename.length() >= LLSuffix.length() && | 321 if (IRFilename.length() >= LLSuffix.length() && |
328 IRFilename.compare(IRFilename.length() - LLSuffix.length(), | 322 IRFilename.compare(IRFilename.length() - LLSuffix.length(), |
329 LLSuffix.length(), LLSuffix) == 0) | 323 LLSuffix.length(), LLSuffix) == 0) |
330 BuildOnRead = false; | 324 BuildOnRead = false; |
331 | 325 |
332 // With the ELF writer, use a raw_fd_ostream to allow seeking. | 326 // With the ELF writer, use a raw_fd_ostream to allow seeking. |
333 // Also don't buffer, otherwise it gets pretty slow. | 327 // Also don't buffer, otherwise it gets pretty slow. |
334 std::unique_ptr<Ice::Ostream> Os; | 328 std::unique_ptr<Ice::Ostream> Os; |
335 std::unique_ptr<Ice::ELFStreamer> ELFStr; | 329 std::unique_ptr<Ice::ELFStreamer> ELFStr; |
336 std::ofstream Ofs; | 330 std::ofstream Ofs; |
337 if (UseELFWriter) { | 331 switch (OutFileType) { |
| 332 case Ice::FT_Elf: { |
338 if (OutputFilename == "-") { | 333 if (OutputFilename == "-") { |
339 *Ls << "Error: writing binary ELF to stdout is unsupported\n"; | 334 *Ls << "Error: writing binary ELF to stdout is unsupported\n"; |
340 return GetReturnValue(Ice::EC_Args); | 335 return GetReturnValue(Ice::EC_Args); |
341 } | 336 } |
342 std::string ErrorInfo; | 337 std::string ErrorInfo; |
343 raw_fd_ostream *FdOs = | 338 raw_fd_ostream *FdOs = |
344 new raw_fd_ostream(OutputFilename.c_str(), ErrorInfo, sys::fs::F_None); | 339 new raw_fd_ostream(OutputFilename.c_str(), ErrorInfo, sys::fs::F_None); |
345 Os.reset(FdOs); | 340 Os.reset(FdOs); |
346 if (!ErrorInfo.empty()) { | 341 if (!ErrorInfo.empty()) { |
347 *Ls << "Failed to open output file: " << OutputFilename << ":\n" | 342 *Ls << "Failed to open output file: " << OutputFilename << ":\n" |
348 << ErrorInfo << "\n"; | 343 << ErrorInfo << "\n"; |
349 return GetReturnValue(Ice::EC_Args); | 344 return GetReturnValue(Ice::EC_Args); |
350 } | 345 } |
351 ELFStr.reset(new Ice::ELFStreamer(*FdOs)); | 346 ELFStr.reset(new Ice::ELFStreamer(*FdOs)); |
352 } else { | 347 } break; |
| 348 case Ice::FT_Asm: |
| 349 case Ice::FT_Iasm: { |
353 if (OutputFilename != "-") { | 350 if (OutputFilename != "-") { |
354 Ofs.open(OutputFilename.c_str(), std::ofstream::out); | 351 Ofs.open(OutputFilename.c_str(), std::ofstream::out); |
355 Os.reset(new raw_os_ostream(Ofs)); | 352 Os.reset(new raw_os_ostream(Ofs)); |
356 } else { | 353 } else { |
357 Os.reset(new raw_os_ostream(std::cout)); | 354 Os.reset(new raw_os_ostream(std::cout)); |
358 } | 355 } |
359 Os->SetUnbuffered(); | 356 Os->SetUnbuffered(); |
| 357 } break; |
360 } | 358 } |
361 | 359 |
362 Ice::GlobalContext Ctx(Ls.get(), Os.get(), ELFStr.get(), VMask, TargetArch, | 360 Ice::GlobalContext Ctx(Ls.get(), Os.get(), ELFStr.get(), VMask, TargetArch, |
363 OptLevel, TestPrefix, Flags); | 361 OptLevel, TestPrefix, Flags); |
364 | 362 |
365 Ice::TimerMarker T(Ice::TimerStack::TT_szmain, &Ctx); | 363 Ice::TimerMarker T(Ice::TimerStack::TT_szmain, &Ctx); |
366 | 364 |
367 if (UseELFWriter) { | 365 if (OutFileType == Ice::FT_Elf) { |
368 Ice::TimerMarker T1(Ice::TimerStack::TT_emit, &Ctx); | 366 Ice::TimerMarker T1(Ice::TimerStack::TT_emit, &Ctx); |
369 Ctx.getObjectWriter()->writeInitialELFHeader(); | 367 Ctx.getObjectWriter()->writeInitialELFHeader(); |
370 } | 368 } |
371 | 369 |
372 Ctx.startWorkerThreads(); | 370 Ctx.startWorkerThreads(); |
373 | 371 |
374 std::unique_ptr<Ice::Translator> Translator; | 372 std::unique_ptr<Ice::Translator> Translator; |
375 if (BuildOnRead) { | 373 if (BuildOnRead) { |
376 std::unique_ptr<Ice::PNaClTranslator> PTranslator( | 374 std::unique_ptr<Ice::PNaClTranslator> PTranslator( |
377 new Ice::PNaClTranslator(&Ctx)); | 375 new Ice::PNaClTranslator(&Ctx)); |
(...skipping 18 matching lines...) Expand all Loading... |
396 } else { | 394 } else { |
397 *Ls << "Error: Build doesn't allow LLVM IR, " | 395 *Ls << "Error: Build doesn't allow LLVM IR, " |
398 << "--build-on-read=0 not allowed\n"; | 396 << "--build-on-read=0 not allowed\n"; |
399 return GetReturnValue(Ice::EC_Args); | 397 return GetReturnValue(Ice::EC_Args); |
400 } | 398 } |
401 | 399 |
402 Ctx.waitForWorkerThreads(); | 400 Ctx.waitForWorkerThreads(); |
403 Translator->transferErrorCode(); | 401 Translator->transferErrorCode(); |
404 Translator->emitConstants(); | 402 Translator->emitConstants(); |
405 | 403 |
406 if (UseELFWriter) { | 404 if (OutFileType == Ice::FT_Elf) { |
407 Ice::TimerMarker T1(Ice::TimerStack::TT_emit, &Ctx); | 405 Ice::TimerMarker T1(Ice::TimerStack::TT_emit, &Ctx); |
408 Ctx.getObjectWriter()->setUndefinedSyms(Ctx.getConstantExternSyms()); | 406 Ctx.getObjectWriter()->setUndefinedSyms(Ctx.getConstantExternSyms()); |
409 Ctx.getObjectWriter()->writeNonUserSections(); | 407 Ctx.getObjectWriter()->writeNonUserSections(); |
410 } | 408 } |
411 if (SubzeroTimingEnabled) | 409 if (SubzeroTimingEnabled) |
412 Ctx.dumpTimers(); | 410 Ctx.dumpTimers(); |
413 if (TimeEachFunction) { | 411 if (TimeEachFunction) { |
414 const bool DumpCumulative = false; | 412 const bool DumpCumulative = false; |
415 Ctx.dumpTimers(Ice::GlobalContext::TSK_Funcs, DumpCumulative); | 413 Ctx.dumpTimers(Ice::GlobalContext::TSK_Funcs, DumpCumulative); |
416 } | 414 } |
417 const bool FinalStats = true; | 415 const bool FinalStats = true; |
418 Ctx.dumpStats("_FINAL_", FinalStats); | 416 Ctx.dumpStats("_FINAL_", FinalStats); |
419 return GetReturnValue(Ctx.getErrorStatus()->value()); | 417 return GetReturnValue(Ctx.getErrorStatus()->value()); |
420 } | 418 } |
OLD | NEW |