| OLD | NEW |
| 1 //===- NaClBitcodeMungeUtils.h - Munge bitcode records --------*- C++ -*-===// | 1 //===- NaClBitcodeMungeUtils.h - Munge bitcode records --------*- 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 file defines utility class NaClMungedBitcode to edit a base | 10 // This file defines utility class NaClMungedBitcode to edit a base |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 #ifndef LLVM_BITCODE_NACL_NACLBITCODEMUNGEUTILS_H | 74 #ifndef LLVM_BITCODE_NACL_NACLBITCODEMUNGEUTILS_H |
| 75 #define LLVM_BITCODE_NACL_NACLBITCODEMUNGEUTILS_H | 75 #define LLVM_BITCODE_NACL_NACLBITCODEMUNGEUTILS_H |
| 76 | 76 |
| 77 #include "llvm/Bitcode/NaCl/NaClBitcodeParser.h" | 77 #include "llvm/Bitcode/NaCl/NaClBitcodeParser.h" |
| 78 | 78 |
| 79 #include <list> | 79 #include <list> |
| 80 #include <map> | 80 #include <map> |
| 81 | 81 |
| 82 namespace llvm { | 82 namespace llvm { |
| 83 | 83 |
| 84 class MemoryBuffer; // Buffer to read bitcode from |
| 84 class NaClBitcodeAbbrevRecord; // bitcode record. | 85 class NaClBitcodeAbbrevRecord; // bitcode record. |
| 85 class NaClMungedBitcodeIter; // iterator over edited bitcode records. | 86 class NaClMungedBitcodeIter; // iterator over edited bitcode records. |
| 86 | 87 |
| 87 /// \brief Defines a list of bitcode records. | 88 /// \brief Defines a list of bitcode records. |
| 88 typedef std::vector<std::unique_ptr<NaClBitcodeAbbrevRecord>> | 89 typedef std::vector<std::unique_ptr<NaClBitcodeAbbrevRecord>> |
| 89 NaClBitcodeRecordList; | 90 NaClBitcodeRecordList; |
| 90 | 91 |
| 91 /// \brief Extracts out the records in Records, and puts them into RecordList. | 92 /// \brief Extracts out the records in Records, and puts them into RecordList. |
| 92 /// | 93 /// |
| 93 /// \brief RecordList[in/out] Record list to read into. | 94 /// \brief RecordList[in/out] Record list to read into. |
| 94 /// \brief Records Array containing data defining records. | 95 /// \brief Records Array containing data defining records. |
| 95 /// \brief RecordsSize The size of array Records. | 96 /// \brief RecordsSize The size of array Records. |
| 96 /// \brief RecordTerminator The value used to terminate records. | 97 /// \brief RecordTerminator The value used to terminate records. |
| 97 void readNaClBitcodeRecordList(NaClBitcodeRecordList &RecordList, | 98 void readNaClBitcodeRecordList(NaClBitcodeRecordList &RecordList, |
| 98 const uint64_t Records[], | 99 const uint64_t Records[], |
| 99 size_t RecordsSize, | 100 size_t RecordsSize, |
| 100 uint64_t RecordTerminator); | 101 uint64_t RecordTerminator); |
| 101 | 102 |
| 103 /// \brief Read in the list of records from bitcode in a memory buffer. |
| 104 void readNaClBitcodeRecordList(NaClBitcodeRecordList &RecordList, |
| 105 std::unique_ptr<MemoryBuffer> InputBuffer); |
| 106 |
| 102 /// \brief An edited (i.e. munged) list of bitcode records. Edits are | 107 /// \brief An edited (i.e. munged) list of bitcode records. Edits are |
| 103 /// always relative to the initial list of records. | 108 /// always relative to the initial list of records. |
| 104 class NaClMungedBitcode { | 109 class NaClMungedBitcode { |
| 105 friend class NaClMungedBitcodeIter; | 110 friend class NaClMungedBitcodeIter; |
| 106 NaClMungedBitcode() = delete; | 111 NaClMungedBitcode() = delete; |
| 107 NaClMungedBitcode(const NaClMungedBitcode &) = delete; | 112 NaClMungedBitcode(const NaClMungedBitcode &) = delete; |
| 108 NaClMungedBitcode &operator=(const NaClMungedBitcode &) = delete; | 113 NaClMungedBitcode &operator=(const NaClMungedBitcode &) = delete; |
| 109 | 114 |
| 110 public: | 115 public: |
| 111 /// \brief Iterator over edited records. | 116 /// \brief Iterator over edited records. |
| 112 typedef NaClMungedBitcodeIter iterator; | 117 typedef NaClMungedBitcodeIter iterator; |
| 113 | 118 |
| 119 /// \brief Read in initial list of records from bitcode in a memory buffer. |
| 120 explicit NaClMungedBitcode(std::unique_ptr<MemoryBuffer> InputBuffer); |
| 121 |
| 114 /// \brief Initialize the list of records to be edited. | 122 /// \brief Initialize the list of records to be edited. |
| 115 explicit NaClMungedBitcode(std::unique_ptr<NaClBitcodeRecordList> BaseRecords) | 123 explicit NaClMungedBitcode(std::unique_ptr<NaClBitcodeRecordList> BaseRecords) |
| 116 : BaseRecords(std::move(BaseRecords)) {} | 124 : BaseRecords(std::move(BaseRecords)) {} |
| 117 | 125 |
| 118 /// \brief Initialize the list of records to be edited using | 126 /// \brief Initialize the list of records to be edited using |
| 119 /// array specification. | 127 /// array specification. |
| 120 /// | 128 /// |
| 121 /// \brief Records Array containing data defining records. | 129 /// \brief Records Array containing data defining records. |
| 122 /// \brief RecordsSize The size of array Records. | 130 /// \brief RecordsSize The size of array Records. |
| 123 /// \brief RecordTerminator The value used to terminate records. | 131 /// \brief RecordTerminator The value used to terminate records. |
| (...skipping 29 matching lines...) Expand all Loading... |
| 153 | 161 |
| 154 /// \brief Replace the record at RecordIndex with Record. Note that | 162 /// \brief Replace the record at RecordIndex with Record. Note that |
| 155 /// because the record index is based on the base records, and those | 163 /// because the record index is based on the base records, and those |
| 156 /// records are not modified, this editing action effectively undoes | 164 /// records are not modified, this editing action effectively undoes |
| 157 /// all previous remove/replace editing actions for this index. | 165 /// all previous remove/replace editing actions for this index. |
| 158 void replace(size_t RecordIndex, NaClBitcodeAbbrevRecord &Record); | 166 void replace(size_t RecordIndex, NaClBitcodeAbbrevRecord &Record); |
| 159 | 167 |
| 160 /// \brief Print out the resulting edited list of records. | 168 /// \brief Print out the resulting edited list of records. |
| 161 void print(raw_ostream &Out) const; | 169 void print(raw_ostream &Out) const; |
| 162 | 170 |
| 171 /// \brief Write out the edited list of bitcode records using |
| 172 /// the given buffer. |
| 173 /// |
| 174 /// \param Buffer The buffer to write into. |
| 175 /// \param AddHeader Add header block when true. |
| 176 /// \param RecoverOnBadAbbrevId When true, try to recover and when |
| 177 /// given a bad abbreviation index. |
| 178 void write(SmallVectorImpl<char> &Buffer, bool AddHeader, |
| 179 bool RecoverOnBadAbbrevId) const; |
| 180 |
| 163 /// \brief The types of editing actions that can be applied. | 181 /// \brief The types of editing actions that can be applied. |
| 164 enum EditAction { | 182 enum EditAction { |
| 165 AddBefore, // Insert new record before base record at index. | 183 AddBefore, // Insert new record before base record at index. |
| 166 AddAfter, // Insert new record after base record at index. | 184 AddAfter, // Insert new record after base record at index. |
| 167 Remove, // Remove record at index. | 185 Remove, // Remove record at index. |
| 168 Replace // Replace base record at index with new record. | 186 Replace // Replace base record at index with new record. |
| 169 }; | 187 }; |
| 170 | 188 |
| 171 /// \brief Apply a set of edits defined in the given array. | 189 /// \brief Apply a set of edits defined in the given array. |
| 172 /// | 190 /// |
| (...skipping 10 matching lines...) Expand all Loading... |
| 183 /// | 201 /// |
| 184 /// \param Munges The array containing the edits to apply. | 202 /// \param Munges The array containing the edits to apply. |
| 185 /// \param MungesSize The size of Munges. | 203 /// \param MungesSize The size of Munges. |
| 186 /// \param Terminator The value used to terminate records in editing actions. | 204 /// \param Terminator The value used to terminate records in editing actions. |
| 187 void munge(const uint64_t Munges[], size_t MungesSize, uint64_t Terminator); | 205 void munge(const uint64_t Munges[], size_t MungesSize, uint64_t Terminator); |
| 188 | 206 |
| 189 /// \brief Removes all editing actions and resets back to the original | 207 /// \brief Removes all editing actions and resets back to the original |
| 190 /// set of base records. | 208 /// set of base records. |
| 191 void removeEdits(); | 209 void removeEdits(); |
| 192 | 210 |
| 211 /// Returns the unedited list of bitcode records. |
| 212 const NaClBitcodeRecordList &getBaseRecords() const { |
| 213 return *BaseRecords; |
| 214 } |
| 215 |
| 193 private: | 216 private: |
| 194 typedef std::list<NaClBitcodeAbbrevRecord *> RecordListType; | 217 typedef std::list<NaClBitcodeAbbrevRecord *> RecordListType; |
| 195 typedef std::map<size_t, RecordListType *> InsertionsMapType; | 218 typedef std::map<size_t, RecordListType *> InsertionsMapType; |
| 196 typedef std::map<size_t, NaClBitcodeAbbrevRecord *> ReplaceMapType; | 219 typedef std::map<size_t, NaClBitcodeAbbrevRecord *> ReplaceMapType; |
| 197 | 220 |
| 198 /// \brief The list of base records that will be edited. | 221 /// \brief The list of base records that will be edited. |
| 199 std::unique_ptr<NaClBitcodeRecordList> BaseRecords; | 222 std::unique_ptr<NaClBitcodeRecordList> BaseRecords; |
| 200 // Holds map from record index to list of records added before | 223 // Holds map from record index to list of records added before |
| 201 // the corresponding record in the list of base records. | 224 // the corresponding record in the list of base records. |
| 202 InsertionsMapType BeforeInsertionsMap; | 225 InsertionsMapType BeforeInsertionsMap; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 public: | 257 public: |
| 235 /// \brief The abbreviation associated with the bitcode record. | 258 /// \brief The abbreviation associated with the bitcode record. |
| 236 unsigned Abbrev; | 259 unsigned Abbrev; |
| 237 | 260 |
| 238 /// \brief Creates a bitcode record. | 261 /// \brief Creates a bitcode record. |
| 239 /// | 262 /// |
| 240 /// \param Abbrev Abbreviation index associated with record. | 263 /// \param Abbrev Abbreviation index associated with record. |
| 241 /// \param Code The selector code of the record. | 264 /// \param Code The selector code of the record. |
| 242 /// \param Values The values associated with the selector code. | 265 /// \param Values The values associated with the selector code. |
| 243 NaClBitcodeAbbrevRecord(unsigned Abbrev, unsigned Code, | 266 NaClBitcodeAbbrevRecord(unsigned Abbrev, unsigned Code, |
| 244 NaClRecordVector &Values) | 267 const NaClRecordVector &Values) |
| 245 : NaClBitcodeRecordData(Code, Values), Abbrev(Abbrev) {} | 268 : NaClBitcodeRecordData(Code, Values), Abbrev(Abbrev) {} |
| 246 | 269 |
| 247 /// \brief Creates a copy of the given abbreviated bitcode record. | 270 /// \brief Creates a copy of the given abbreviated bitcode record. |
| 248 explicit NaClBitcodeAbbrevRecord(const NaClBitcodeAbbrevRecord &Rcd) | 271 explicit NaClBitcodeAbbrevRecord(const NaClBitcodeAbbrevRecord &Rcd) |
| 249 : NaClBitcodeRecordData(Rcd), Abbrev(Rcd.Abbrev) {} | 272 : NaClBitcodeRecordData(Rcd), Abbrev(Rcd.Abbrev) {} |
| 250 | 273 |
| 251 /// \brief Creates a default abbreviated bitcode record. | 274 /// \brief Creates a default abbreviated bitcode record. |
| 252 NaClBitcodeAbbrevRecord() : Abbrev(naclbitc::UNABBREV_RECORD) {} | 275 NaClBitcodeAbbrevRecord() : Abbrev(naclbitc::UNABBREV_RECORD) {} |
| 253 | 276 |
| 254 ~NaClBitcodeAbbrevRecord() {} | 277 ~NaClBitcodeAbbrevRecord() {} |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 } | 384 } |
| 362 | 385 |
| 363 // \brief Moves the iterator to the position of the next edited | 386 // \brief Moves the iterator to the position of the next edited |
| 364 // record. | 387 // record. |
| 365 void updatePosition(); | 388 void updatePosition(); |
| 366 }; | 389 }; |
| 367 | 390 |
| 368 } // end namespace llvm. | 391 } // end namespace llvm. |
| 369 | 392 |
| 370 #endif // LLVM_BITCODE_NACL_NACLBITCODEMUNGE_H | 393 #endif // LLVM_BITCODE_NACL_NACLBITCODEMUNGE_H |
| OLD | NEW |