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

Side by Side Diff: tools/pnacl-llc/pnacl-llc.cpp

Issue 770853002: Fix error reporting in the PNaCl bitcode reader. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-llvm.git@master
Patch Set: Fix issues and add test case. Created 6 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
OLDNEW
1 //===-- pnacl-llc.cpp - PNaCl-specific llc: pexe ---> nexe ---------------===// 1 //===-- pnacl-llc.cpp - PNaCl-specific llc: pexe ---> nexe ---------------===//
2 // 2 //
3 // The LLVM Compiler Infrastructure 3 // The LLVM Compiler Infrastructure
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 // pnacl-llc: the core of the PNaCl translator, compiling a pexe into a nexe. 10 // pnacl-llc: the core of the PNaCl translator, compiling a pexe into a nexe.
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 // General options for llc. Other pass-specific options are specified 83 // General options for llc. Other pass-specific options are specified
84 // within the corresponding llc passes, and target-specific options 84 // within the corresponding llc passes, and target-specific options
85 // and back-end code generation options are specified with the target machine. 85 // and back-end code generation options are specified with the target machine.
86 // 86 //
87 static cl::opt<std::string> 87 static cl::opt<std::string>
88 InputFilename(cl::Positional, cl::desc("<input bitcode>"), cl::init("-")); 88 InputFilename(cl::Positional, cl::desc("<input bitcode>"), cl::init("-"));
89 89
90 static cl::opt<std::string> 90 static cl::opt<std::string>
91 OutputFilename("o", cl::desc("Output filename"), cl::value_desc("filename")); 91 OutputFilename("o", cl::desc("Output filename"), cl::value_desc("filename"));
92 92
93 static cl::opt<bool>
94 VerboseErrors(
95 "verbose-parse-errors",
96 cl::desc("Print out more descriptive PNaCl bitcode parse errors"),
97 cl::init(false));
98
93 // Using bitcode streaming allows compilation of one function at a time. This 99 // Using bitcode streaming allows compilation of one function at a time. This
94 // allows earlier functions to be compiled before later functions are read from 100 // allows earlier functions to be compiled before later functions are read from
95 // the bitcode but of course means no whole-module optimizations. This means 101 // the bitcode but of course means no whole-module optimizations. This means
96 // that Module passes that run should only touch globals/function declarations 102 // that Module passes that run should only touch globals/function declarations
97 // and not function bodies, otherwise the streaming and non-streaming code 103 // and not function bodies, otherwise the streaming and non-streaming code
98 // pathes wouldn't emit the same code for each function. For now, streaming is 104 // pathes wouldn't emit the same code for each function. For now, streaming is
99 // only supported for files and stdin. 105 // only supported for files and stdin.
100 static cl::opt<bool> 106 static cl::opt<bool>
101 LazyBitcode("streaming-bitcode", 107 LazyBitcode("streaming-bitcode",
102 cl::desc("Use lazy bitcode streaming for file inputs"), 108 cl::desc("Use lazy bitcode streaming for file inputs"),
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 Reporter.reset(); 325 Reporter.reset();
320 } 326 }
321 327
322 static Module* getModule(StringRef ProgramName, LLVMContext &Context, 328 static Module* getModule(StringRef ProgramName, LLVMContext &Context,
323 StreamingMemoryObject *StreamingObject) { 329 StreamingMemoryObject *StreamingObject) {
324 Module *M = nullptr; 330 Module *M = nullptr;
325 SMDiagnostic Err; 331 SMDiagnostic Err;
326 if (LazyBitcode) { 332 if (LazyBitcode) {
327 std::string StrError; 333 std::string StrError;
328 if (InputFileFormat == PNaClFormat) { 334 if (InputFileFormat == PNaClFormat) {
335 raw_ostream *Verbose = VerboseErrors ? &errs() : nullptr;
jvoung (off chromium) 2014/12/03 19:43:46 Now that this is a stream, __native_client__/pnacl
Karl 2014/12/03 20:53:44 Went ahead and added verbose errors if command lin
jvoung (off chromium) 2014/12/03 22:11:13 What I meant was why not pass in the VerboseStrm a
Karl 2014/12/03 22:28:51 Ok. I'll make it be always when in __native_client
329 M = getNaClStreamedBitcodeModule( 336 M = getNaClStreamedBitcodeModule(
330 InputFilename, 337 InputFilename,
331 new ThreadedStreamingCache(StreamingObject), Context, &StrError); 338 new ThreadedStreamingCache(StreamingObject), Context, Verbose,
339 &StrError);
332 } else if (InputFileFormat == LLVMFormat) { 340 } else if (InputFileFormat == LLVMFormat) {
333 M = getStreamedBitcodeModule( 341 M = getStreamedBitcodeModule(
334 InputFilename, 342 InputFilename,
335 new ThreadedStreamingCache(StreamingObject), Context, &StrError); 343 new ThreadedStreamingCache(StreamingObject), Context, &StrError);
336 } else { 344 } else {
337 llvm_unreachable("Unknown bitcode format"); 345 llvm_unreachable("Unknown bitcode format");
338 } 346 }
339 if (!StrError.empty()) 347 if (!StrError.empty())
340 Err = SMDiagnostic(InputFilename, SourceMgr::DK_Error, StrError); 348 Err = SMDiagnostic(InputFilename, SourceMgr::DK_Error, StrError);
341 } else { 349 } else {
342 #if defined(__native_client__) 350 #if defined(__native_client__)
343 llvm_unreachable("native client SRPC only supports streaming"); 351 llvm_unreachable("native client SRPC only supports streaming");
344 #else 352 #else
345 // Parses binary bitcode as well as textual assembly 353 // Parses binary bitcode as well as textual assembly
346 // (so pulls in more code into pnacl-llc). 354 // (so pulls in more code into pnacl-llc).
347 M = NaClParseIRFile(InputFilename, InputFileFormat, Err, Context); 355 raw_ostream *Verbose = VerboseErrors ? &errs() : nullptr;
356 M = NaClParseIRFile(InputFilename, InputFileFormat, Err, Verbose,
357 Context);
348 #endif 358 #endif
349 } 359 }
350 if (!M) { 360 if (!M) {
351 #if defined(__native_client__) 361 #if defined(__native_client__)
352 report_fatal_error(Err.getMessage()); 362 report_fatal_error(Err.getMessage());
353 #else 363 #else
354 // Err.print is prettier, so use it for the non-sandboxed translator. 364 // Err.print is prettier, so use it for the non-sandboxed translator.
355 Err.print(ProgramName.data(), errs()); 365 Err.print(ProgramName.data(), errs());
356 return nullptr; 366 return nullptr;
357 #endif 367 #endif
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
767 return 0; 777 return 0;
768 } 778 }
769 779
770 int main(int argc, char **argv) { 780 int main(int argc, char **argv) {
771 #if defined(__native_client__) 781 #if defined(__native_client__)
772 return srpc_main(argc, argv); 782 return srpc_main(argc, argv);
773 #else 783 #else
774 return llc_main(argc, argv); 784 return llc_main(argc, argv);
775 #endif // __native_client__ 785 #endif // __native_client__
776 } 786 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698