| OLD | NEW |
| 1 //===- NaClBitCodes.h - Enum values for the bitcode format ------*- C++ -*-===// | 1 //===- NaClBitCodes.h - Enum values for the bitcode format ------*- 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 Bitcode enum values. | 10 // This header Bitcode enum values. |
| 11 // | 11 // |
| 12 // The enum values defined in this file should be considered permanent. If | 12 // The enum values defined in this file should be considered permanent. If |
| 13 // new features are added, they should have values added at the end of the | 13 // new features are added, they should have values added at the end of the |
| 14 // respective lists. | 14 // respective lists. |
| 15 // | 15 // |
| 16 //===----------------------------------------------------------------------===// | 16 //===----------------------------------------------------------------------===// |
| 17 | 17 |
| 18 #ifndef LLVM_BITCODE_NACL_NACLBITCODES_H | 18 #ifndef LLVM_BITCODE_NACL_NACLBITCODES_H |
| 19 #define LLVM_BITCODE_NACL_NACLBITCODES_H | 19 #define LLVM_BITCODE_NACL_NACLBITCODES_H |
| 20 | 20 |
| 21 #include "llvm/ADT/SmallVector.h" | 21 #include "llvm/ADT/SmallVector.h" |
| 22 #include "llvm/Support/DataTypes.h" | 22 #include "llvm/Support/DataTypes.h" |
| 23 #include "llvm/Support/ErrorHandling.h" | 23 #include "llvm/Support/ErrorHandling.h" |
| 24 #include "llvm/Support/MathExtras.h" | 24 #include "llvm/Support/MathExtras.h" |
| 25 #include <cassert> | 25 #include <cassert> |
| 26 | 26 |
| 27 namespace llvm { | 27 namespace llvm { |
| 28 class raw_ostream; |
| 29 |
| 28 namespace naclbitc { | 30 namespace naclbitc { |
| 29 enum StandardWidths { | 31 enum StandardWidths { |
| 30 BlockIDWidth = 8, // We use VBR-8 for block IDs. | 32 BlockIDWidth = 8, // We use VBR-8 for block IDs. |
| 31 CodeLenWidth = 4, // Codelen are VBR-4. | 33 CodeLenWidth = 4, // Codelen are VBR-4. |
| 32 BlockSizeWidth = 32 // BlockSize up to 2^32 32-bit words = 16GB per block. | 34 BlockSizeWidth = 32 // BlockSize up to 2^32 32-bit words = 16GB per block. |
| 33 }; | 35 }; |
| 34 | 36 |
| 35 // The standard abbrev namespace always has a way to exit a block, enter a | 37 // The standard abbrev namespace always has a way to exit a block, enter a |
| 36 // nested block, define abbrevs, and define an unabbreviated record. | 38 // nested block, define abbrevs, and define an unabbreviated record. |
| 37 enum FixedAbbrevIDs { | 39 enum FixedAbbrevIDs { |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 return true; | 142 return true; |
| 141 case Array: | 143 case Array: |
| 142 case Char6: | 144 case Char6: |
| 143 return false; | 145 return false; |
| 144 default: | 146 default: |
| 145 break; | 147 break; |
| 146 } | 148 } |
| 147 report_fatal_error("Invalid encoding"); | 149 report_fatal_error("Invalid encoding"); |
| 148 } | 150 } |
| 149 | 151 |
| 152 bool isArrayOp() const { |
| 153 return isEncoding() && Enc == Array; |
| 154 } |
| 155 |
| 156 /// Returns the number of arguments expected by this abbrevation operator. |
| 157 unsigned NumArguments() const { |
| 158 if (isArrayOp()) |
| 159 return 1; |
| 160 else |
| 161 return 0; |
| 162 } |
| 163 |
| 164 /// Prints out the abbreviation operator to the given stream. |
| 165 void Print(raw_ostream &Stream) const; |
| 166 |
| 150 /// isChar6 - Return true if this character is legal in the Char6 encoding. | 167 /// isChar6 - Return true if this character is legal in the Char6 encoding. |
| 151 static bool isChar6(char C) { | 168 static bool isChar6(char C) { |
| 152 if (C >= 'a' && C <= 'z') return true; | 169 if (C >= 'a' && C <= 'z') return true; |
| 153 if (C >= 'A' && C <= 'Z') return true; | 170 if (C >= 'A' && C <= 'Z') return true; |
| 154 if (C >= '0' && C <= '9') return true; | 171 if (C >= '0' && C <= '9') return true; |
| 155 if (C == '.' || C == '_') return true; | 172 if (C == '.' || C == '_') return true; |
| 156 return false; | 173 return false; |
| 157 } | 174 } |
| 158 static unsigned EncodeChar6(char C) { | 175 static unsigned EncodeChar6(char C) { |
| 159 if (C >= 'a' && C <= 'z') return C-'a'; | 176 if (C >= 'a' && C <= 'z') return C-'a'; |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 return static_cast<unsigned>(OperandList.size()); | 273 return static_cast<unsigned>(OperandList.size()); |
| 257 } | 274 } |
| 258 const NaClBitCodeAbbrevOp &getOperandInfo(unsigned N) const { | 275 const NaClBitCodeAbbrevOp &getOperandInfo(unsigned N) const { |
| 259 return OperandList[N]; | 276 return OperandList[N]; |
| 260 } | 277 } |
| 261 | 278 |
| 262 void Add(const NaClBitCodeAbbrevOp &OpInfo) { | 279 void Add(const NaClBitCodeAbbrevOp &OpInfo) { |
| 263 OperandList.push_back(OpInfo); | 280 OperandList.push_back(OpInfo); |
| 264 } | 281 } |
| 265 | 282 |
| 283 // Returns a simplified version of the abbreviation. Used |
| 284 // to recognize equivalent abbrevations. |
| 285 NaClBitCodeAbbrev *Simplify() const; |
| 286 |
| 266 int Compare(const NaClBitCodeAbbrev &Abbrev) const { | 287 int Compare(const NaClBitCodeAbbrev &Abbrev) const { |
| 267 // First order based on number of operands. | 288 // First order based on number of operands. |
| 268 size_t OperandListSize = OperandList.size(); | 289 size_t OperandListSize = OperandList.size(); |
| 269 size_t AbbrevOperandListSize = Abbrev.OperandList.size(); | 290 size_t AbbrevOperandListSize = Abbrev.OperandList.size(); |
| 270 if (OperandListSize < AbbrevOperandListSize) | 291 if (OperandListSize < AbbrevOperandListSize) |
| 271 return -1; | 292 return -1; |
| 272 else if (OperandListSize > AbbrevOperandListSize) | 293 else if (OperandListSize > AbbrevOperandListSize) |
| 273 return 1; | 294 return 1; |
| 274 | 295 |
| 275 // Same number of operands, so compare element by element. | 296 // Same number of operands, so compare element by element. |
| 276 for (size_t I = 0; I < OperandListSize; ++I) { | 297 for (size_t I = 0; I < OperandListSize; ++I) { |
| 277 if (int Diff = OperandList[I].Compare(Abbrev.OperandList[I])) | 298 if (int Diff = OperandList[I].Compare(Abbrev.OperandList[I])) |
| 278 return Diff; | 299 return Diff; |
| 279 } | 300 } |
| 280 return 0; | 301 return 0; |
| 281 } | 302 } |
| 282 | 303 |
| 304 void Print(raw_ostream &Stream) const; |
| 305 |
| 283 NaClBitCodeAbbrev *Copy() const { | 306 NaClBitCodeAbbrev *Copy() const { |
| 284 NaClBitCodeAbbrev *AbbrevCopy = new NaClBitCodeAbbrev(); | 307 NaClBitCodeAbbrev *AbbrevCopy = new NaClBitCodeAbbrev(); |
| 285 for (unsigned I = 0, IEnd = getNumOperandInfos(); | 308 for (unsigned I = 0, IEnd = getNumOperandInfos(); |
| 286 I != IEnd; ++I) { | 309 I != IEnd; ++I) { |
| 287 AbbrevCopy->Add(NaClBitCodeAbbrevOp(getOperandInfo(I))); | 310 AbbrevCopy->Add(NaClBitCodeAbbrevOp(getOperandInfo(I))); |
| 288 } | 311 } |
| 289 return AbbrevCopy; | 312 return AbbrevCopy; |
| 290 } | 313 } |
| 291 }; | 314 }; |
| 292 | 315 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 | 389 |
| 367 // Creates a selector range to handle fixed abbrevations up to | 390 // Creates a selector range to handle fixed abbrevations up to |
| 368 // the specified value. | 391 // the specified value. |
| 369 explicit NaClBitcodeSelectorAbbrev(unsigned MaxAbbrev) | 392 explicit NaClBitcodeSelectorAbbrev(unsigned MaxAbbrev) |
| 370 : IsFixed(true), | 393 : IsFixed(true), |
| 371 NumBits(NaClBitsNeededForValue(MaxAbbrev)) {} | 394 NumBits(NaClBitsNeededForValue(MaxAbbrev)) {} |
| 372 }; | 395 }; |
| 373 } // End llvm namespace | 396 } // End llvm namespace |
| 374 | 397 |
| 375 #endif | 398 #endif |
| OLD | NEW |