OLD | NEW |
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 Loading... |
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 Loading... |
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 Loading... |
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) { |
833 | 837 return ErrorAt(naclbitc::Error, Bit); |
834 /// Write a fatal error message to the dump stream, and then | |
835 /// stop the executable. If any assembly, comments, or errors have | |
836 /// been buffered, they will be printed first. | |
837 LLVM_ATTRIBUTE_NORETURN | |
838 void Fatal(const std::string &Message) { | |
839 Fatal(LastKnownBit, Message); | |
840 } | 838 } |
841 | 839 |
842 /// Write a fatal error message to the dump stream, and then | 840 /// Prints "Level(Bit/8:Bit%8): " onto the comments stream at the |
843 /// stop the executable. If any assembly, comments, or errors have | 841 /// given bit position and severity Level. Then, it records that an |
844 /// been buffered, they will be printed first. Associates fatal error | 842 /// error has occurred and then returns the comments stream. In |
845 /// Message with the given Bit. | 843 /// general errors will be printed after the next record, unless a |
846 LLVM_ATTRIBUTE_NORETURN | 844 /// call to Flush is made. |
847 void Fatal(uint64_t Bit, const std::string &Message); | 845 raw_ostream &ErrorAt(naclbitc::ErrorLevel Level, uint64_t Bit); |
848 | |
849 /// Write a fatal error message to the dump stream, and then | |
850 /// stop the executable. If any assembly, comments, or errors have | |
851 /// been buffered, they will be printed first, along with the given record. | |
852 LLVM_ATTRIBUTE_NORETURN | |
853 void Fatal(uint64_t Bit, | |
854 const llvm::NaClBitcodeRecordData &Record, | |
855 const std::string &Message); | |
856 | 846 |
857 /// Dumps a record (at the given bit), along with all buffered assembly, | 847 /// Dumps a record (at the given bit), along with all buffered assembly, |
858 /// comments, and errors, into the objdump stream. | 848 /// comments, and errors, into the objdump stream. |
859 void Write(uint64_t Bit, | 849 void Write(uint64_t Bit, |
860 const llvm::NaClBitcodeRecordData &Record, | 850 const llvm::NaClBitcodeRecordData &Record, |
861 int32_t AbbrevIndex = ABBREV_INDEX_NOT_SPECIFIED) { | 851 int32_t AbbrevIndex = ABBREV_INDEX_NOT_SPECIFIED) { |
862 LastKnownBit = Bit; | 852 LastKnownBit = Bit; |
863 NaClBitcodeValues Values(Record); | 853 NaClBitcodeValues Values(Record); |
864 RecordFormatter.WriteValues(Bit, Values, AbbrevIndex); | 854 RecordFormatter.WriteValues(Bit, Values, AbbrevIndex); |
865 Flush(); | 855 Flush(); |
866 } | 856 } |
867 | 857 |
868 /// Dumps the buffered assembly, comments, and errors, without any | 858 /// Dumps the buffered assembly, comments, and errors, without any |
869 /// corresponding record, into the objdump stream. | 859 /// corresponding record, into the objdump stream. |
870 void Flush(); | 860 void Flush(); |
871 | 861 |
| 862 /// Flushes out the last record and/or error, and then stops |
| 863 /// the executable. Should be called immediately after generating |
| 864 /// the error message using ErrorAt(naclbitc::Fatal,...). |
| 865 void FlushThenQuit(); |
| 866 |
872 /// Increments the record indent by one. | 867 /// Increments the record indent by one. |
873 void IncRecordIndent() { | 868 void IncRecordIndent() { |
874 RecordFormatter.Inc(); | 869 RecordFormatter.Inc(); |
875 } | 870 } |
876 | 871 |
877 /// Decrements the record indent by one. | 872 /// Decrements the record indent by one. |
878 void DecRecordIndent() { | 873 void DecRecordIndent() { |
879 RecordFormatter.Dec(); | 874 RecordFormatter.Dec(); |
880 } | 875 } |
881 | 876 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
913 unsigned GetRecordWidth() const { | 908 unsigned GetRecordWidth() const { |
914 return RecordWidth; | 909 return RecordWidth; |
915 } | 910 } |
916 | 911 |
917 /// Changes the column separator character to the given value. | 912 /// Changes the column separator character to the given value. |
918 void SetColumnSeparator(char Separator) { | 913 void SetColumnSeparator(char Separator) { |
919 ColumnSeparator = Separator; | 914 ColumnSeparator = Separator; |
920 } | 915 } |
921 | 916 |
922 /// Changes the internal state, to assume one is processing a record | 917 /// 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 | 918 /// at the given bit. |
924 /// the corresponding bit to associate with the error message. | |
925 void SetRecordBitAddress(uint64_t Bit) { | 919 void SetRecordBitAddress(uint64_t Bit) { |
926 LastKnownBit = Bit; | 920 LastKnownBit = Bit; |
927 } | 921 } |
928 | 922 |
929 private: | 923 private: |
930 // The stream to dump to. | 924 // The stream to dump to. |
931 raw_ostream &Stream; | 925 raw_ostream &Stream; |
932 // True if records should be dumped to the dump stream. | 926 // True if records should be dumped to the dump stream. |
933 bool DumpRecords; | 927 bool DumpRecords; |
934 // True if assembly text should be dumped to the dump stream. | 928 // True if assembly text should be dumped to the dump stream. |
(...skipping 23 matching lines...) Expand all Loading... |
958 raw_string_ostream RecordStream; | 952 raw_string_ostream RecordStream; |
959 /// The text formatter for generating records. | 953 /// The text formatter for generating records. |
960 RecordTextFormatter RecordFormatter; | 954 RecordTextFormatter RecordFormatter; |
961 | 955 |
962 // Resets assembly and buffers. | 956 // Resets assembly and buffers. |
963 void ResetBuffers() { | 957 void ResetBuffers() { |
964 RecordBuffer.clear(); | 958 RecordBuffer.clear(); |
965 AssemblyBuffer.clear(); | 959 AssemblyBuffer.clear(); |
966 MessageBuffer.clear(); | 960 MessageBuffer.clear(); |
967 } | 961 } |
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 }; | 962 }; |
975 | 963 |
976 } | 964 } |
977 } | 965 } |
978 | 966 |
979 #endif | 967 #endif |
OLD | NEW |