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

Side by Side Diff: include/llvm/Bitcode/NaCl/NaClObjDumpStream.h

Issue 986453002: Additional clean ups on errors in bitcode parsing. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-llvm.git@master
Patch Set: Fix nits. Created 5 years, 9 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
OLDNEW
1 //===- NaClObjDumpStream.h --------------------------------------*- C++ -*-===// 1 //===- NaClObjDumpStream.h --------------------------------------*- C++ -*-===//
2 // Models an objdump stream (bitcode records/assembly code). 2 // Models an objdump stream (bitcode records/assembly code).
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 654 matching lines...) Expand 10 before | Expand all | Expand 10 after
665 665
666 /// Models that an abbreviation index is not specified when dumping a 666 /// Models that an abbreviation index is not specified when dumping a
667 /// bitcode record. 667 /// bitcode record.
668 static int32_t ABBREV_INDEX_NOT_SPECIFIED = -1; 668 static int32_t ABBREV_INDEX_NOT_SPECIFIED = -1;
669 669
670 /// The formatter used for dumping records in ObjDumpStream. 670 /// The formatter used for dumping records in ObjDumpStream.
671 class RecordTextFormatter : public TextFormatter { 671 class RecordTextFormatter : public TextFormatter {
672 RecordTextFormatter(const RecordTextFormatter&) = delete; 672 RecordTextFormatter(const RecordTextFormatter&) = delete;
673 RecordTextFormatter &operator=(const RecordTextFormatter&) = delete; 673 RecordTextFormatter &operator=(const RecordTextFormatter&) = delete;
674 public: 674 public:
675 /// The address write width used to print the number of 675 /// The address write width used to print a bit address, when
676 /// bytes in the record bit address, when printing records. 676 /// printing records.
677 static const unsigned AddressWriteWidth = 8; 677 static const unsigned AddressWriteWidth = 10;
678 678
679 explicit RecordTextFormatter(ObjDumpStream *ObjDump); 679 explicit RecordTextFormatter(ObjDumpStream *ObjDump);
680 680
681 ~RecordTextFormatter() override {} 681 ~RecordTextFormatter() override {}
682 682
683 /// Writes out the given record of values as an instruction. 683 /// Writes out the given record of values as an instruction.
684 void WriteValues(uint64_t Bit, 684 void WriteValues(uint64_t Bit,
685 const llvm::NaClBitcodeValues &Values, 685 const llvm::NaClBitcodeValues &Values,
686 int32_t AbbrevIndex = ABBREV_INDEX_NOT_SPECIFIED); 686 int32_t AbbrevIndex = ABBREV_INDEX_NOT_SPECIFIED);
687 687
(...skipping 13 matching lines...) Expand all
701 // A comma between elements in a record. 701 // A comma between elements in a record.
702 TokenTextDirective Comma; 702 TokenTextDirective Comma;
703 // A space inside a record. 703 // A space inside a record.
704 SpaceTextDirective Space; 704 SpaceTextDirective Space;
705 // End the line. 705 // End the line.
706 EndlineTextDirective Endline; 706 EndlineTextDirective Endline;
707 // Start clustering tokens. 707 // Start clustering tokens.
708 StartClusteringDirective StartCluster; 708 StartClusteringDirective StartCluster;
709 // End clustering tokens. 709 // End clustering tokens.
710 FinishClusteringDirective FinishCluster; 710 FinishClusteringDirective FinishCluster;
711
712 // Generates an address label with padding to match AddressWriteWidth;
713 std::string getBitAddress(uint64_t Bit);
711 }; 714 };
712 715
713 /// Implements a stream to print out bitcode records, assembly code, 716 /// Implements a stream to print out bitcode records, assembly code,
714 /// comments, and errors. The general format is to print records and 717 /// comments, and errors. The general format is to print records and
715 /// assembly side by side. Comments and errors (associated with the 718 /// assembly side by side. Comments and errors (associated with the
716 /// record and/or assembly code) follow each printed record. 719 /// record and/or assembly code) follow each printed record.
717 /// 720 ///
718 /// Alignment of records, assembly, comments, and errors is done by 721 /// Alignment of records, assembly, comments, and errors is done by
719 /// buffering assembly, comments, and errors until a write or flush 722 /// buffering assembly, comments, and errors until a write or flush
720 /// occurs. Then, the various streams are stitched together to 723 /// occurs. Then, the various streams are stitched together to
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
799 /// Returns stream to buffer messages that will be printed during the 802 /// Returns stream to buffer messages that will be printed during the
800 // next write call. 803 // next write call.
801 raw_ostream &Comments() { 804 raw_ostream &Comments() {
802 return MessageStream; 805 return MessageStream;
803 } 806 }
804 807
805 /// Prints "Warning(Bit/8:Bit%8): " onto the comments stream, and 808 /// Prints "Warning(Bit/8:Bit%8): " onto the comments stream, and
806 /// then returns the comments stream. In general, warnings will be 809 /// then returns the comments stream. In general, warnings will be
807 /// printed after the next record, unless a call to Flush is made. 810 /// printed after the next record, unless a call to Flush is made.
808 raw_ostream &Warning() { 811 raw_ostream &Warning() {
809 return Warning(LastKnownBit); 812 return WarningAt(LastKnownBit);
810 } 813 }
811 814
812 /// Prints "Warning(Bit/8:Bit%8): " onto the comments stream, and 815 /// Prints "Warning(Bit/8:Bit%8): " onto the comments stream, and
813 /// then returns the comments stream. In general, warnings will be 816 /// then returns the comments stream. In general, warnings will be
814 /// printed after the next record, unless a call to Flush is made. 817 /// printed after the next record, unless a call to Flush is made.
815 raw_ostream &Warning(uint64_t Bit) { 818 raw_ostream &WarningAt(uint64_t Bit) {
816 LastKnownBit = Bit; 819 LastKnownBit = Bit;
817 return PrintMessagePrefix("Warning", Bit); 820 return naclbitc::ErrorAt(Comments(), naclbitc::Warning, Bit);
818 } 821 }
819 822
820 /// Prints "Error(Bit/8:Bit%8): " onto the comments stream, records 823 /// Prints "Error(Bit/8:Bit%8): " onto the comments stream using the
821 /// that an error has occurred, and then returns the comments 824 /// last know bit position of the input. Then, it records that an
822 /// stream. In general errors will be printed after the next record, 825 /// error has occurred and returns the comments stream. In general
823 /// unless a call to Flush is made. 826 /// errors will be printed after the next record, unless a call to
827 /// Flush is made.
824 raw_ostream &Error() { 828 raw_ostream &Error() {
825 return Error(LastKnownBit); 829 return ErrorAt(LastKnownBit);
826 } 830 }
827 831
828 /// Prints "Error(Bit/8:Bit%8): " onto the comments stream, records 832 /// Prints "Error(Bit/8:Bit%8): " onto the comments stream at the
829 /// that an error has occurred, and then returns the comments 833 /// given Bit position. Then, it records that an error has occurred
830 /// stream. In general errors will be printed after the next record, 834 /// and returns the comments stream. In general errors will be
831 /// unless a call to Flush is made. 835 /// printed after the next record, unless a call to Flush is made.
832 raw_ostream &Error(uint64_t Bit); 836 raw_ostream &ErrorAt(uint64_t Bit) {
837 return ErrorAt(naclbitc::Error, Bit);
838 }
839
840 /// Prints "Level(Bit/8:Bit%8): " onto the comments stream at the
841 /// given bit position and severity Level. Then, it records that an
842 /// error has occurred and then returns the comments stream. In
843 /// general errors will be printed after the next record, unless a
844 /// call to Flush is made.
845 raw_ostream &ErrorAt(naclbitc::ErrorLevel Level, uint64_t Bit);
833 846
834 /// Write a fatal error message to the dump stream, and then 847 /// Write a fatal error message to the dump stream, and then
835 /// stop the executable. If any assembly, comments, or errors have 848 /// stop the executable. If any assembly, comments, or errors have
836 /// been buffered, they will be printed first. 849 /// been buffered, they will be printed first.
837 LLVM_ATTRIBUTE_NORETURN 850 LLVM_ATTRIBUTE_NORETURN
838 void Fatal(const std::string &Message) { 851 void Fatal(const std::string &Message) {
jvoung (off chromium) 2015/03/07 00:04:35 Is this method still used?
Karl 2015/03/09 18:10:54 Removed.
839 Fatal(LastKnownBit, Message); 852 FatalAt(LastKnownBit, Message);
840 } 853 }
841 854
842 /// Write a fatal error message to the dump stream, and then 855 /// Write a fatal error message to the dump stream, and then
843 /// stop the executable. If any assembly, comments, or errors have 856 /// stop the executable. If any assembly, comments, or errors have
844 /// been buffered, they will be printed first. Associates fatal error 857 /// been buffered, they will be printed first. Associates fatal error
845 /// Message with the given Bit. 858 /// Message with the given Bit.
846 LLVM_ATTRIBUTE_NORETURN 859 LLVM_ATTRIBUTE_NORETURN
847 void Fatal(uint64_t Bit, const std::string &Message); 860 void FatalAt(uint64_t Bit, const std::string &Message);
848 861
849 /// Write a fatal error message to the dump stream, and then 862 /// Write a fatal error message to the dump stream, and then
850 /// stop the executable. If any assembly, comments, or errors have 863 /// stop the executable. If any assembly, comments, or errors have
851 /// been buffered, they will be printed first, along with the given record. 864 /// been buffered, they will be printed first, along with the given record.
852 LLVM_ATTRIBUTE_NORETURN 865 LLVM_ATTRIBUTE_NORETURN
853 void Fatal(uint64_t Bit, 866 void FatalAt(uint64_t Bit,
854 const llvm::NaClBitcodeRecordData &Record, 867 const llvm::NaClBitcodeRecordData &Record,
855 const std::string &Message); 868 const std::string &Message);
856 869
857 /// Dumps a record (at the given bit), along with all buffered assembly, 870 /// Dumps a record (at the given bit), along with all buffered assembly,
858 /// comments, and errors, into the objdump stream. 871 /// comments, and errors, into the objdump stream.
859 void Write(uint64_t Bit, 872 void Write(uint64_t Bit,
860 const llvm::NaClBitcodeRecordData &Record, 873 const llvm::NaClBitcodeRecordData &Record,
861 int32_t AbbrevIndex = ABBREV_INDEX_NOT_SPECIFIED) { 874 int32_t AbbrevIndex = ABBREV_INDEX_NOT_SPECIFIED) {
862 LastKnownBit = Bit; 875 LastKnownBit = Bit;
863 NaClBitcodeValues Values(Record); 876 NaClBitcodeValues Values(Record);
864 RecordFormatter.WriteValues(Bit, Values, AbbrevIndex); 877 RecordFormatter.WriteValues(Bit, Values, AbbrevIndex);
865 Flush(); 878 Flush();
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
913 unsigned GetRecordWidth() const { 926 unsigned GetRecordWidth() const {
914 return RecordWidth; 927 return RecordWidth;
915 } 928 }
916 929
917 /// Changes the column separator character to the given value. 930 /// Changes the column separator character to the given value.
918 void SetColumnSeparator(char Separator) { 931 void SetColumnSeparator(char Separator) {
919 ColumnSeparator = Separator; 932 ColumnSeparator = Separator;
920 } 933 }
921 934
922 /// Changes the internal state, to assume one is processing a record 935 /// Changes the internal state, to assume one is processing a record
923 /// at the given bit. Used by Error() and Fatal(Message) to fill in 936 /// at the given bit. Used by Warning(), Error(), and Fatal(Message)
924 /// the corresponding bit to associate with the error message. 937 /// to fill in the corresponding bit to associate with the error
jvoung (off chromium) 2015/03/06 22:30:27 On second read, I'm not sure you need to call out
Karl 2015/03/06 22:54:20 Sounds good. Removing sentence.
938 /// message.
925 void SetRecordBitAddress(uint64_t Bit) { 939 void SetRecordBitAddress(uint64_t Bit) {
926 LastKnownBit = Bit; 940 LastKnownBit = Bit;
927 } 941 }
928 942
929 private: 943 private:
930 // The stream to dump to. 944 // The stream to dump to.
931 raw_ostream &Stream; 945 raw_ostream &Stream;
932 // True if records should be dumped to the dump stream. 946 // True if records should be dumped to the dump stream.
933 bool DumpRecords; 947 bool DumpRecords;
934 // True if assembly text should be dumped to the dump stream. 948 // True if assembly text should be dumped to the dump stream.
(...skipping 23 matching lines...) Expand all
958 raw_string_ostream RecordStream; 972 raw_string_ostream RecordStream;
959 /// The text formatter for generating records. 973 /// The text formatter for generating records.
960 RecordTextFormatter RecordFormatter; 974 RecordTextFormatter RecordFormatter;
961 975
962 // Resets assembly and buffers. 976 // Resets assembly and buffers.
963 void ResetBuffers() { 977 void ResetBuffers() {
964 RecordBuffer.clear(); 978 RecordBuffer.clear();
965 AssemblyBuffer.clear(); 979 AssemblyBuffer.clear();
966 MessageBuffer.clear(); 980 MessageBuffer.clear();
967 } 981 }
968
969 // Returns the message stream with 'Label(Bit/8:Bit%8): '.
970 raw_ostream &PrintMessagePrefix(const char *Label, uint64_t Bit) {
971 return Comments() << Label << "(" << NaClBitstreamReader::getBitAddress(Bit)
972 << "): ";
973 }
974 }; 982 };
975 983
976 } 984 }
977 } 985 }
978 986
979 #endif 987 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698