OLD | NEW |
1 //===- NaClBitstreamReader.h -----------------------------------*- C++ -*-===// | 1 //===- NaClBitstreamReader.h -----------------------------------*- C++ -*-===// |
2 // Low-level bitstream reader interface | 2 // Low-level bitstream reader interface |
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 // |
11 // This header defines the BitstreamReader class. This class can be used to | 11 // This header defines the BitstreamReader class. This class can be used to |
12 // read an arbitrary bitstream, regardless of its contents. | 12 // read an arbitrary bitstream, regardless of its contents. |
13 // | 13 // |
14 //===----------------------------------------------------------------------===// | 14 //===----------------------------------------------------------------------===// |
15 | 15 |
16 #ifndef LLVM_BITCODE_NACL_NACLBITSTREAMREADER_H | 16 #ifndef LLVM_BITCODE_NACL_NACLBITSTREAMREADER_H |
17 #define LLVM_BITCODE_NACL_NACLBITSTREAMREADER_H | 17 #define LLVM_BITCODE_NACL_NACLBITSTREAMREADER_H |
18 | 18 |
19 #include "llvm/ADT/SmallVector.h" | 19 #include "llvm/ADT/SmallVector.h" |
20 #include "llvm/Bitcode/NaCl/NaClLLVMBitCodes.h" | 20 #include "llvm/Bitcode/NaCl/NaClLLVMBitCodes.h" |
21 #include "llvm/Support/Endian.h" | 21 #include "llvm/Support/Endian.h" |
22 #include "llvm/Support/StreamingMemoryObject.h" | 22 #include "llvm/Support/StreamingMemoryObject.h" |
23 #include <climits> | 23 #include <climits> |
24 #include <vector> | 24 #include <vector> |
25 | 25 |
26 namespace llvm { | 26 namespace llvm { |
27 | 27 |
28 class Deserializer; | 28 class Deserializer; |
29 | 29 |
| 30 namespace naclbitc { |
| 31 |
| 32 /// Returns the Bit as a Byte:BitInByte string. |
| 33 std::string getBitAddress(uint64_t Bit); |
| 34 |
| 35 /// Severity levels for reporting errors. |
| 36 enum ErrorLevel { |
| 37 Warning, |
| 38 Error, |
| 39 Fatal |
| 40 }; |
| 41 |
| 42 // Basic printing routine to generate the beginning of an error |
| 43 // message. BitPosition is the bit position the error was found. |
| 44 // Level is the severity of the error. |
| 45 raw_ostream &ErrorAt(raw_ostream &Out, ErrorLevel Level, |
| 46 uint64_t BitPosition); |
| 47 |
| 48 } // End namespace naclbitc. |
| 49 |
30 /// This class is used to read from a NaCl bitcode wire format stream, | 50 /// This class is used to read from a NaCl bitcode wire format stream, |
31 /// maintaining information that is global to decoding the entire file. | 51 /// maintaining information that is global to decoding the entire file. |
32 /// While a file is being read, multiple cursors can be independently | 52 /// While a file is being read, multiple cursors can be independently |
33 /// advanced or skipped around within the file. These are represented by | 53 /// advanced or skipped around within the file. These are represented by |
34 /// the NaClBitstreamCursor class. | 54 /// the NaClBitstreamCursor class. |
35 class NaClBitstreamReader { | 55 class NaClBitstreamReader { |
36 public: | 56 public: |
37 /// This contains information emitted to BLOCKINFO_BLOCK blocks. These | 57 /// This contains information emitted to BLOCKINFO_BLOCK blocks. These |
38 /// describe abbreviations that all blocks of the specified ID inherit. | 58 /// describe abbreviations that all blocks of the specified ID inherit. |
39 struct BlockInfo { | 59 struct BlockInfo { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 Info.Abbrevs[i]->dropRef(); | 101 Info.Abbrevs[i]->dropRef(); |
82 BlockInfoRecords.pop_back(); | 102 BlockInfoRecords.pop_back(); |
83 } | 103 } |
84 } | 104 } |
85 | 105 |
86 /// \brief Returns the initial address (after the header) of the input stream. | 106 /// \brief Returns the initial address (after the header) of the input stream. |
87 size_t getInitialAddress() const { | 107 size_t getInitialAddress() const { |
88 return InitialAddress; | 108 return InitialAddress; |
89 } | 109 } |
90 | 110 |
91 /// Returns the Bit as a Byte:BitInByte string. MinByteWidth is the | |
92 /// minimum number of characters to print out the Byte value (blank | |
93 /// fills). | |
94 static std::string getBitAddress(uint64_t Bit, unsigned MinByteWidth=1); | |
95 | |
96 //===--------------------------------------------------------------------===// | 111 //===--------------------------------------------------------------------===// |
97 // Block Manipulation | 112 // Block Manipulation |
98 //===--------------------------------------------------------------------===// | 113 //===--------------------------------------------------------------------===// |
99 | 114 |
100 /// Return true if we've already read and processed the block info block for | 115 /// Return true if we've already read and processed the block info block for |
101 /// this Bitstream. We only process it for the first cursor that walks over | 116 /// this Bitstream. We only process it for the first cursor that walks over |
102 /// it. | 117 /// it. |
103 bool hasBlockInfoRecords() const { return !BlockInfoRecords.empty(); } | 118 bool hasBlockInfoRecords() const { return !BlockInfoRecords.empty(); } |
104 | 119 |
105 /// If there is block info for the specified ID, return it, otherwise return | 120 /// If there is block info for the specified ID, return it, otherwise return |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 } | 335 } |
321 | 336 |
322 NaClBitstreamReader *getBitStreamReader() { | 337 NaClBitstreamReader *getBitStreamReader() { |
323 return BitStream; | 338 return BitStream; |
324 } | 339 } |
325 const NaClBitstreamReader *getBitStreamReader() const { | 340 const NaClBitstreamReader *getBitStreamReader() const { |
326 return BitStream; | 341 return BitStream; |
327 } | 342 } |
328 | 343 |
329 /// Returns the current bit address (string) of the bit cursor. | 344 /// Returns the current bit address (string) of the bit cursor. |
330 /// MinByteWidth is the minimum number of characters to print out | 345 std::string getCurrentBitAddress() const { |
331 /// the Byte value (blank fills). | 346 return naclbitc::getBitAddress(GetCurrentBitNo()); |
332 std::string getCurrentBitAddress(unsigned MinByteWidth=1) const { | |
333 return BitStream->getBitAddress(GetCurrentBitNo(), MinByteWidth); | |
334 } | 347 } |
335 | 348 |
336 /// Flags that modify the behavior of advance(). | 349 /// Flags that modify the behavior of advance(). |
337 enum { | 350 enum { |
338 /// If this flag is used, the advance() method does not automatically pop | 351 /// If this flag is used, the advance() method does not automatically pop |
339 /// the block scope when the end of a block is reached. | 352 /// the block scope when the end of a block is reached. |
340 AF_DontPopBlockAtEnd = 1, | 353 AF_DontPopBlockAtEnd = 1, |
341 | 354 |
342 /// If this flag is used, abbrev entries are returned just like normal | 355 /// If this flag is used, abbrev entries are returned just like normal |
343 /// records. | 356 /// records. |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
638 // Skips over an abbreviation record. Duplicates code of ReadAbbrevRecord, | 651 // Skips over an abbreviation record. Duplicates code of ReadAbbrevRecord, |
639 // except that no abbreviation is built. | 652 // except that no abbreviation is built. |
640 void SkipAbbrevRecord(); | 653 void SkipAbbrevRecord(); |
641 | 654 |
642 bool ReadBlockInfoBlock(NaClAbbrevListener *Listener); | 655 bool ReadBlockInfoBlock(NaClAbbrevListener *Listener); |
643 }; | 656 }; |
644 | 657 |
645 } // End llvm namespace | 658 } // End llvm namespace |
646 | 659 |
647 #endif | 660 #endif |
OLD | NEW |