OLD | NEW |
1 //===- BitstreamWriter.h - Low-level bitstream writer interface -*- C++ -*-===// | 1 //===- NaClBitstreamWriter.h - NaCl bitstream writer ------------*- C++ -*-===// |
2 // | 2 // |
3 // The LLVM Compiler Infrastructure | 3 // The LLVM Compiler Infrastructure |
4 // | 4 // |
5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
7 // | 7 // |
8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
9 // | 9 // |
10 // This header defines the BitstreamWriter class. This class can be used to | 10 // This header defines the BitstreamWriter class. This class can be used to |
11 // write an arbitrary bitstream, regardless of its contents. | 11 // write an arbitrary bitstream, regardless of its contents. |
12 // | 12 // |
13 //===----------------------------------------------------------------------===// | 13 //===----------------------------------------------------------------------===// |
14 | 14 |
15 #ifndef LLVM_BITCODE_BITSTREAMWRITER_H | 15 #ifndef LLVM_BITCODE_NACL_NACLBITSTREAMWRITER_H |
16 #define LLVM_BITCODE_BITSTREAMWRITER_H | 16 #define LLVM_BITCODE_NACL_NACLBITSTREAMWRITER_H |
17 | 17 |
18 #include "llvm/ADT/SmallVector.h" | 18 #include "llvm/ADT/SmallVector.h" |
19 #include "llvm/ADT/StringRef.h" | 19 #include "llvm/ADT/StringRef.h" |
20 #include "llvm/Bitcode/BitCodes.h" | 20 #include "llvm/Bitcode/BitCodes.h" |
21 #include <vector> | 21 #include <vector> |
22 | 22 |
23 namespace llvm { | 23 namespace llvm { |
24 | 24 |
25 class BitstreamWriter { | 25 class NaClBitstreamWriter { |
26 SmallVectorImpl<char> &Out; | 26 SmallVectorImpl<char> &Out; |
27 | 27 |
28 /// CurBit - Always between 0 and 31 inclusive, specifies the next bit to use. | 28 /// CurBit - Always between 0 and 31 inclusive, specifies the next bit to use. |
29 unsigned CurBit; | 29 unsigned CurBit; |
30 | 30 |
31 /// CurValue - The current value. Only bits < CurBit are valid. | 31 /// CurValue - The current value. Only bits < CurBit are valid. |
32 uint32_t CurValue; | 32 uint32_t CurValue; |
33 | 33 |
34 /// CurCodeSize - This is the declared size of code values used for the | 34 /// CurCodeSize - This is the declared size of code values used for the |
35 /// current block, in bits. | 35 /// current block, in bits. |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 return Out.size(); | 86 return Out.size(); |
87 } | 87 } |
88 | 88 |
89 unsigned GetWordIndex() const { | 89 unsigned GetWordIndex() const { |
90 unsigned Offset = GetBufferOffset(); | 90 unsigned Offset = GetBufferOffset(); |
91 assert((Offset & 3) == 0 && "Not 32-bit aligned"); | 91 assert((Offset & 3) == 0 && "Not 32-bit aligned"); |
92 return Offset / 4; | 92 return Offset / 4; |
93 } | 93 } |
94 | 94 |
95 public: | 95 public: |
96 explicit BitstreamWriter(SmallVectorImpl<char> &O) | 96 explicit NaClBitstreamWriter(SmallVectorImpl<char> &O) |
97 : Out(O), CurBit(0), CurValue(0), CurCodeSize(2) {} | 97 : Out(O), CurBit(0), CurValue(0), CurCodeSize(2) {} |
98 | 98 |
99 ~BitstreamWriter() { | 99 ~NaClBitstreamWriter() { |
100 assert(CurBit == 0 && "Unflused data remaining"); | 100 assert(CurBit == 0 && "Unflused data remaining"); |
101 assert(BlockScope.empty() && CurAbbrevs.empty() && "Block imbalance"); | 101 assert(BlockScope.empty() && CurAbbrevs.empty() && "Block imbalance"); |
102 | 102 |
103 // Free the BlockInfoRecords. | 103 // Free the BlockInfoRecords. |
104 while (!BlockInfoRecords.empty()) { | 104 while (!BlockInfoRecords.empty()) { |
105 BlockInfo &Info = BlockInfoRecords.back(); | 105 BlockInfo &Info = BlockInfoRecords.back(); |
106 // Free blockinfo abbrev info. | 106 // Free blockinfo abbrev info. |
107 for (unsigned i = 0, e = static_cast<unsigned>(Info.Abbrevs.size()); | 107 for (unsigned i = 0, e = static_cast<unsigned>(Info.Abbrevs.size()); |
108 i != e; ++i) | 108 i != e; ++i) |
109 Info.Abbrevs[i]->dropRef(); | 109 Info.Abbrevs[i]->dropRef(); |
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
539 Info.Abbrevs.push_back(Abbv); | 539 Info.Abbrevs.push_back(Abbv); |
540 | 540 |
541 return Info.Abbrevs.size()-1+bitc::FIRST_APPLICATION_ABBREV; | 541 return Info.Abbrevs.size()-1+bitc::FIRST_APPLICATION_ABBREV; |
542 } | 542 } |
543 }; | 543 }; |
544 | 544 |
545 | 545 |
546 } // End llvm namespace | 546 } // End llvm namespace |
547 | 547 |
548 #endif | 548 #endif |
OLD | NEW |