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. MinByteWidth is the | |
jvoung (off chromium)
2015/03/06 22:30:27
There's no MinByteWidth argument for this function
Karl
2015/03/06 22:54:20
Good catch. Removing the sentence.
| |
33 /// minimum number of characters to print out the Byte value (blank | |
34 /// fills). | |
35 std::string getBitAddress(uint64_t Bit); | |
36 | |
37 /// Severity levels for reporting errors. | |
38 enum ErrorLevel { | |
39 Warning, | |
40 Error, | |
41 Fatal | |
42 }; | |
43 | |
44 // Basic printing routine to generate the beginning of an error | |
45 // message. BitPosition is the bit position the error was found. | |
46 // Level is the severity of the error. | |
47 raw_ostream &ErrorAt(raw_ostream &Out, ErrorLevel Level, | |
48 uint64_t BitPosition); | |
49 | |
50 } // End namespace naclbitc. | |
51 | |
30 /// This class is used to read from a NaCl bitcode wire format stream, | 52 /// This class is used to read from a NaCl bitcode wire format stream, |
31 /// maintaining information that is global to decoding the entire file. | 53 /// maintaining information that is global to decoding the entire file. |
32 /// While a file is being read, multiple cursors can be independently | 54 /// While a file is being read, multiple cursors can be independently |
33 /// advanced or skipped around within the file. These are represented by | 55 /// advanced or skipped around within the file. These are represented by |
34 /// the NaClBitstreamCursor class. | 56 /// the NaClBitstreamCursor class. |
35 class NaClBitstreamReader { | 57 class NaClBitstreamReader { |
36 public: | 58 public: |
37 /// This contains information emitted to BLOCKINFO_BLOCK blocks. These | 59 /// This contains information emitted to BLOCKINFO_BLOCK blocks. These |
38 /// describe abbreviations that all blocks of the specified ID inherit. | 60 /// describe abbreviations that all blocks of the specified ID inherit. |
39 struct BlockInfo { | 61 struct BlockInfo { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
81 Info.Abbrevs[i]->dropRef(); | 103 Info.Abbrevs[i]->dropRef(); |
82 BlockInfoRecords.pop_back(); | 104 BlockInfoRecords.pop_back(); |
83 } | 105 } |
84 } | 106 } |
85 | 107 |
86 /// \brief Returns the initial address (after the header) of the input stream. | 108 /// \brief Returns the initial address (after the header) of the input stream. |
87 size_t getInitialAddress() const { | 109 size_t getInitialAddress() const { |
88 return InitialAddress; | 110 return InitialAddress; |
89 } | 111 } |
90 | 112 |
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 //===--------------------------------------------------------------------===// | 113 //===--------------------------------------------------------------------===// |
97 // Block Manipulation | 114 // Block Manipulation |
98 //===--------------------------------------------------------------------===// | 115 //===--------------------------------------------------------------------===// |
99 | 116 |
100 /// Return true if we've already read and processed the block info block for | 117 /// 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 | 118 /// this Bitstream. We only process it for the first cursor that walks over |
102 /// it. | 119 /// it. |
103 bool hasBlockInfoRecords() const { return !BlockInfoRecords.empty(); } | 120 bool hasBlockInfoRecords() const { return !BlockInfoRecords.empty(); } |
104 | 121 |
105 /// If there is block info for the specified ID, return it, otherwise return | 122 /// 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 } | 337 } |
321 | 338 |
322 NaClBitstreamReader *getBitStreamReader() { | 339 NaClBitstreamReader *getBitStreamReader() { |
323 return BitStream; | 340 return BitStream; |
324 } | 341 } |
325 const NaClBitstreamReader *getBitStreamReader() const { | 342 const NaClBitstreamReader *getBitStreamReader() const { |
326 return BitStream; | 343 return BitStream; |
327 } | 344 } |
328 | 345 |
329 /// Returns the current bit address (string) of the bit cursor. | 346 /// Returns the current bit address (string) of the bit cursor. |
330 /// MinByteWidth is the minimum number of characters to print out | 347 /// MinByteWidth is the minimum number of characters to print out |
jvoung (off chromium)
2015/03/06 22:30:27
There's no MinByteWidth parameter here anymore.
Karl
2015/03/06 22:54:20
Removed the sentence.
| |
331 /// the Byte value (blank fills). | 348 /// the Byte value (blank fills). |
332 std::string getCurrentBitAddress(unsigned MinByteWidth=1) const { | 349 std::string getCurrentBitAddress() const { |
333 return BitStream->getBitAddress(GetCurrentBitNo(), MinByteWidth); | 350 return naclbitc::getBitAddress(GetCurrentBitNo()); |
334 } | 351 } |
335 | 352 |
336 /// Flags that modify the behavior of advance(). | 353 /// Flags that modify the behavior of advance(). |
337 enum { | 354 enum { |
338 /// If this flag is used, the advance() method does not automatically pop | 355 /// If this flag is used, the advance() method does not automatically pop |
339 /// the block scope when the end of a block is reached. | 356 /// the block scope when the end of a block is reached. |
340 AF_DontPopBlockAtEnd = 1, | 357 AF_DontPopBlockAtEnd = 1, |
341 | 358 |
342 /// If this flag is used, abbrev entries are returned just like normal | 359 /// If this flag is used, abbrev entries are returned just like normal |
343 /// records. | 360 /// records. |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
638 // Skips over an abbreviation record. Duplicates code of ReadAbbrevRecord, | 655 // Skips over an abbreviation record. Duplicates code of ReadAbbrevRecord, |
639 // except that no abbreviation is built. | 656 // except that no abbreviation is built. |
640 void SkipAbbrevRecord(); | 657 void SkipAbbrevRecord(); |
641 | 658 |
642 bool ReadBlockInfoBlock(NaClAbbrevListener *Listener); | 659 bool ReadBlockInfoBlock(NaClAbbrevListener *Listener); |
643 }; | 660 }; |
644 | 661 |
645 } // End llvm namespace | 662 } // End llvm namespace |
646 | 663 |
647 #endif | 664 #endif |
OLD | NEW |