Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 //===- NaClBitcodeParser.h -----------------------------------*- C++ -*-===// | 1 //===- NaClBitcodeParser.h -----------------------------------*- C++ -*-===// |
| 2 // Low-level bitcode driver to parse PNaCl bitcode files. | 2 // Low-level bitcode driver to parse PNaCl bitcode files. |
| 3 // | 3 // |
| 4 // The LLVM Compiler Infrastructure | 4 // The LLVM Compiler Infrastructure |
| 5 // | 5 // |
| 6 // This file is distributed under the University of Illinois Open Source | 6 // This file is distributed under the University of Illinois Open Source |
| 7 // License. See LICENSE.TXT for details. | 7 // License. See LICENSE.TXT for details. |
| 8 // | 8 // |
| 9 //===----------------------------------------------------------------------===// | 9 //===----------------------------------------------------------------------===// |
| 10 // | 10 // |
| (...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 406 /// The block ID to use if a global abbreviation. Note: This field is | 406 /// The block ID to use if a global abbreviation. Note: This field is |
| 407 /// updated by calls to method SetBID. | 407 /// updated by calls to method SetBID. |
| 408 unsigned GlobalBlockID; | 408 unsigned GlobalBlockID; |
| 409 }; | 409 }; |
| 410 | 410 |
| 411 /// Parses a block in the PNaCl bitcode stream. | 411 /// Parses a block in the PNaCl bitcode stream. |
| 412 class NaClBitcodeParser { | 412 class NaClBitcodeParser { |
| 413 // Allow listener privledges, so that it can update/call the parser | 413 // Allow listener privledges, so that it can update/call the parser |
| 414 // using a clean API. | 414 // using a clean API. |
| 415 friend class NaClBitcodeParserListener; | 415 friend class NaClBitcodeParserListener; |
| 416 | |
| 417 // Implements an error handler for errors in the bitstream reader. | |
| 418 // Redirects bitstream reader errors to corresponding parrser error | |
| 419 // reporting function. | |
| 420 class ErrorHandler : public NaClBitstreamCursor::ErrorHandler { | |
| 421 NaClBitcodeParser *Parser; | |
| 422 public: | |
| 423 ErrorHandler(NaClBitcodeParser *Parser, | |
| 424 NaClBitstreamCursor &Cursor): | |
| 425 NaClBitstreamCursor::ErrorHandler(Cursor), Parser(Parser) {} | |
| 426 LLVM_ATTRIBUTE_NORETURN | |
| 427 void Fatal(const std::string &ErrorMessage) const final { | |
| 428 Parser->FatalAt(getCurrentBitNo(), ErrorMessage); | |
| 429 } | |
| 430 ~ErrorHandler() override {} | |
| 431 }; | |
| 432 | |
| 416 public: | 433 public: |
| 417 | |
| 418 // Creates a parser to parse the the block at the given cursor in | 434 // Creates a parser to parse the the block at the given cursor in |
| 419 // the PNaCl bitcode stream. This instance is a "dummy" instance | 435 // the PNaCl bitcode stream. This instance is a "dummy" instance |
| 420 // that starts the parser. | 436 // that starts the parser. |
| 421 explicit NaClBitcodeParser(NaClBitstreamCursor &Cursor) | 437 explicit NaClBitcodeParser(NaClBitstreamCursor &Cursor) |
| 422 : EnclosingParser(0), | 438 : EnclosingParser(0), |
| 423 Block(ILLEGAL_BLOCK_ID, Cursor), | 439 Block(ILLEGAL_BLOCK_ID, Cursor), |
| 424 Record(Block), | 440 Record(Block), |
| 425 Listener(0), | 441 Listener(0), |
| 426 ErrStream(&errs()) | 442 ErrStream(&errs()) { |
| 427 {} | 443 std::unique_ptr<NaClBitstreamCursor::ErrorHandler> |
| 444 ErrHandler(new ErrorHandler(this, Cursor)); | |
| 445 Cursor.setErrorHandler(ErrHandler); | |
|
jvoung (off chromium)
2015/02/23 18:58:56
Does "Cursor.setErrorHandler(make_unique<ErrorHand
Karl
2015/02/23 20:46:22
The problem is that there is two different types,
| |
| 446 } | |
| 428 | 447 |
| 429 virtual ~NaClBitcodeParser(); | 448 virtual ~NaClBitcodeParser(); |
| 430 | 449 |
| 431 /// Reads the (top-level) block associated with the given block | 450 /// Reads the (top-level) block associated with the given block |
| 432 /// record at the stream cursor. Returns true if unable to parse. | 451 /// record at the stream cursor. Returns true if unable to parse. |
| 433 /// Can be called multiple times to parse multiple blocks. | 452 /// Can be called multiple times to parse multiple blocks. |
| 434 bool Parse(); | 453 bool Parse(); |
| 435 | 454 |
| 436 // Called once the bitstream reader has entered the corresponding | 455 // Called once the bitstream reader has entered the corresponding |
| 437 // subblock. Argument NumWords is set to the number of words in the | 456 // subblock. Argument NumWords is set to the number of words in the |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 476 // 2) Temporarily modify it for a single error message. In this context, | 495 // 2) Temporarily modify it for a single error message. In this context, |
| 477 // the method Error() is overridden in the derived class, and | 496 // the method Error() is overridden in the derived class, and |
| 478 // calls this method twice. Once before calling base method Error(), | 497 // calls this method twice. Once before calling base method Error(), |
| 479 // and followed by a second call to restore the default error stream. | 498 // and followed by a second call to restore the default error stream. |
| 480 raw_ostream &setErrStream(raw_ostream &Stream) { | 499 raw_ostream &setErrStream(raw_ostream &Stream) { |
| 481 raw_ostream &OldErrStream = *ErrStream; | 500 raw_ostream &OldErrStream = *ErrStream; |
| 482 ErrStream = &Stream; | 501 ErrStream = &Stream; |
| 483 return OldErrStream; | 502 return OldErrStream; |
| 484 } | 503 } |
| 485 | 504 |
| 486 // Called when error occurs. Message is the error to report. Always | 505 // Called when an error occurs. BitPosition is the bit position the |
| 506 // error was found, and Message is the error to report. Always | |
| 487 // returns true (the error return value of Parse). | 507 // returns true (the error return value of Parse). |
| 488 virtual bool Error(const std::string &Message) { | 508 virtual bool ErrorAt(uint64_t BitPosition, const std::string &Message); |
| 489 *ErrStream << "Error: " << Message << "\n"; | 509 |
| 490 return true; | 510 // Called when an error occurs. Message is the error to |
| 511 // report. Always returns true (the error return value of Parse). | |
| 512 bool Error(const std::string &Message) { | |
| 513 // Overrides NaClBitcodeParser::Error and defines the reporting | |
|
jvoung (off chromium)
2015/02/23 18:58:55
Similar question to below Fatal() about "Overrides
Karl
2015/02/23 20:46:22
Not sure why this comment is here anymore. Removin
| |
| 514 // point to be the beginning of the current record being parsed, | |
| 515 // instead of at the end of the record. | |
| 516 return ErrorAt(Record.GetStartBit(), Message); | |
| 517 } | |
| 518 | |
| 519 // Called when a fatal error occurs. BitPosition is the bit position | |
| 520 // the error was found, and Message is the error to report. Does not | |
| 521 // return. | |
| 522 LLVM_ATTRIBUTE_NORETURN | |
| 523 virtual void FatalAt(uint64_t BitPosition, const std::string &Message); | |
| 524 | |
| 525 // Called when a fatal error occurs. Message is the error to | |
| 526 // report. Does not return. | |
| 527 LLVM_ATTRIBUTE_NORETURN | |
| 528 void Fatal(const std::string &Message) { | |
| 529 // Overrides NaClBitcodeParser::Fatal and defines the reporting | |
|
jvoung (off chromium)
2015/02/23 18:58:55
I don't quite understand the "Overrides NaClBitcod
Karl
2015/02/23 20:46:22
Also removed comment here.
| |
| 530 // point to be the beginning of the current record being parsed, | |
| 531 // instead of at the end of the record. | |
| 532 FatalAt(Record.GetStartBit(), Message); | |
| 533 } | |
| 534 | |
| 535 // Generates fatal generic error message. | |
| 536 LLVM_ATTRIBUTE_NORETURN | |
| 537 void Fatal() { | |
| 538 Fatal("Fatal error occurred!"); | |
| 491 } | 539 } |
| 492 | 540 |
| 493 // Returns the number of bits in this block, including nested blocks. | 541 // Returns the number of bits in this block, including nested blocks. |
| 494 unsigned GetBlockNumBits() const { | 542 unsigned GetBlockNumBits() const { |
| 495 return Block.GetNumBits(); | 543 return Block.GetNumBits(); |
| 496 } | 544 } |
| 497 | 545 |
| 498 // Returns the number of bits in this block, excluding nested blocks. | 546 // Returns the number of bits in this block, excluding nested blocks. |
| 499 unsigned GetBlockLocalNumBits() const { | 547 unsigned GetBlockLocalNumBits() const { |
| 500 return Block.GetLocalNumBits(); | 548 return Block.GetLocalNumBits(); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 593 } | 641 } |
| 594 | 642 |
| 595 // Parses a BlockInfo block, where processing is handled through | 643 // Parses a BlockInfo block, where processing is handled through |
| 596 // a listener in the bitstream reader. | 644 // a listener in the bitstream reader. |
| 597 bool ParseBlockInfoInternal(); | 645 bool ParseBlockInfoInternal(); |
| 598 | 646 |
| 599 // Parses the non-BlockInfo block. Returns true if unable to parse the | 647 // Parses the non-BlockInfo block. Returns true if unable to parse the |
| 600 // block. | 648 // block. |
| 601 bool ParseBlockInternal(); | 649 bool ParseBlockInternal(); |
| 602 | 650 |
| 603 | |
| 604 void operator=(const NaClBitcodeParser &Parser) LLVM_DELETED_FUNCTION; | 651 void operator=(const NaClBitcodeParser &Parser) LLVM_DELETED_FUNCTION; |
| 605 NaClBitcodeParser(const NaClBitcodeParser &Parser) LLVM_DELETED_FUNCTION; | 652 NaClBitcodeParser(const NaClBitcodeParser &Parser) LLVM_DELETED_FUNCTION; |
| 606 | 653 |
| 607 }; | 654 }; |
| 608 | 655 |
| 609 } // namespace llvm | 656 } // namespace llvm |
| 610 | 657 |
| 611 #endif | 658 #endif |
| OLD | NEW |