Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

187 lines
6.6 KiB

  1. //===- BitCodes.h - Enum values for the bitcode format ----------*- C++ -*-===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This header Bitcode enum values.
  11. //
  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
  14. // respective lists.
  15. //
  16. //===----------------------------------------------------------------------===//
  17. #ifndef LLVM_BITCODE_BITCODES_H
  18. #define LLVM_BITCODE_BITCODES_H
  19. #include "llvm/ADT/SmallVector.h"
  20. #include "llvm/Support/DataTypes.h"
  21. #include "llvm/Support/ErrorHandling.h"
  22. #include <cassert>
  23. namespace llvm {
  24. namespace bitc {
  25. enum StandardWidths {
  26. BlockIDWidth = 8, // We use VBR-8 for block IDs.
  27. CodeLenWidth = 4, // Codelen are VBR-4.
  28. BlockSizeWidth = 32 // BlockSize up to 2^32 32-bit words = 16GB per block.
  29. };
  30. // The standard abbrev namespace always has a way to exit a block, enter a
  31. // nested block, define abbrevs, and define an unabbreviated record.
  32. enum FixedAbbrevIDs {
  33. END_BLOCK = 0, // Must be zero to guarantee termination for broken bitcode.
  34. ENTER_SUBBLOCK = 1,
  35. /// DEFINE_ABBREV - Defines an abbrev for the current block. It consists
  36. /// of a vbr5 for # operand infos. Each operand info is emitted with a
  37. /// single bit to indicate if it is a literal encoding. If so, the value is
  38. /// emitted with a vbr8. If not, the encoding is emitted as 3 bits followed
  39. /// by the info value as a vbr5 if needed.
  40. DEFINE_ABBREV = 2,
  41. // UNABBREV_RECORDs are emitted with a vbr6 for the record code, followed by
  42. // a vbr6 for the # operands, followed by vbr6's for each operand.
  43. UNABBREV_RECORD = 3,
  44. // This is not a code, this is a marker for the first abbrev assignment.
  45. FIRST_APPLICATION_ABBREV = 4
  46. };
  47. /// StandardBlockIDs - All bitcode files can optionally include a BLOCKINFO
  48. /// block, which contains metadata about other blocks in the file.
  49. enum StandardBlockIDs {
  50. /// BLOCKINFO_BLOCK is used to define metadata about blocks, for example,
  51. /// standard abbrevs that should be available to all blocks of a specified
  52. /// ID.
  53. BLOCKINFO_BLOCK_ID = 0,
  54. // Block IDs 1-7 are reserved for future expansion.
  55. FIRST_APPLICATION_BLOCKID = 8
  56. };
  57. /// BlockInfoCodes - The blockinfo block contains metadata about user-defined
  58. /// blocks.
  59. enum BlockInfoCodes {
  60. // DEFINE_ABBREV has magic semantics here, applying to the current SETBID'd
  61. // block, instead of the BlockInfo block.
  62. BLOCKINFO_CODE_SETBID = 1, // SETBID: [blockid#]
  63. BLOCKINFO_CODE_BLOCKNAME = 2, // BLOCKNAME: [name]
  64. BLOCKINFO_CODE_SETRECORDNAME = 3 // BLOCKINFO_CODE_SETRECORDNAME:
  65. // [id, name]
  66. };
  67. } // End bitc namespace
  68. /// BitCodeAbbrevOp - This describes one or more operands in an abbreviation.
  69. /// This is actually a union of two different things:
  70. /// 1. It could be a literal integer value ("the operand is always 17").
  71. /// 2. It could be an encoding specification ("this operand encoded like so").
  72. ///
  73. class BitCodeAbbrevOp {
  74. uint64_t Val; // A literal value or data for an encoding.
  75. bool IsLiteral : 1; // Indicate whether this is a literal value or not.
  76. unsigned Enc : 3; // The encoding to use.
  77. public:
  78. enum Encoding {
  79. Fixed = 1, // A fixed width field, Val specifies number of bits.
  80. VBR = 2, // A VBR field where Val specifies the width of each chunk.
  81. Array = 3, // A sequence of fields, next field species elt encoding.
  82. Char6 = 4, // A 6-bit fixed field which maps to [a-zA-Z0-9._].
  83. Blob = 5 // 32-bit aligned array of 8-bit characters.
  84. };
  85. explicit BitCodeAbbrevOp(uint64_t V) : Val(V), IsLiteral(true) {}
  86. explicit BitCodeAbbrevOp(Encoding E, uint64_t Data = 0)
  87. : Val(Data), IsLiteral(false), Enc(E) {}
  88. bool isLiteral() const { return IsLiteral; }
  89. bool isEncoding() const { return !IsLiteral; }
  90. // Accessors for literals.
  91. uint64_t getLiteralValue() const { assert(isLiteral()); return Val; }
  92. // Accessors for encoding info.
  93. Encoding getEncoding() const { assert(isEncoding()); return (Encoding)Enc; }
  94. uint64_t getEncodingData() const {
  95. assert(isEncoding() && hasEncodingData());
  96. return Val;
  97. }
  98. bool hasEncodingData() const { return hasEncodingData(getEncoding()); }
  99. static bool hasEncodingData(Encoding E) {
  100. switch (E) {
  101. case Fixed:
  102. case VBR:
  103. return true;
  104. case Array:
  105. case Char6:
  106. case Blob:
  107. return false;
  108. }
  109. llvm_unreachable("Invalid encoding");
  110. }
  111. /// isChar6 - Return true if this character is legal in the Char6 encoding.
  112. static bool isChar6(char C) {
  113. if (C >= 'a' && C <= 'z') return true;
  114. if (C >= 'A' && C <= 'Z') return true;
  115. if (C >= '0' && C <= '9') return true;
  116. if (C == '.' || C == '_') return true;
  117. return false;
  118. }
  119. static unsigned EncodeChar6(char C) {
  120. if (C >= 'a' && C <= 'z') return C-'a';
  121. if (C >= 'A' && C <= 'Z') return C-'A'+26;
  122. if (C >= '0' && C <= '9') return C-'0'+26+26;
  123. if (C == '.') return 62;
  124. if (C == '_') return 63;
  125. llvm_unreachable("Not a value Char6 character!");
  126. }
  127. static char DecodeChar6(unsigned V) {
  128. assert((V & ~63) == 0 && "Not a Char6 encoded character!");
  129. if (V < 26) return V+'a';
  130. if (V < 26+26) return V-26+'A';
  131. if (V < 26+26+10) return V-26-26+'0';
  132. if (V == 62) return '.';
  133. if (V == 63) return '_';
  134. llvm_unreachable("Not a value Char6 character!");
  135. }
  136. };
  137. template <> struct isPodLike<BitCodeAbbrevOp> { static const bool value=true; };
  138. /// BitCodeAbbrev - This class represents an abbreviation record. An
  139. /// abbreviation allows a complex record that has redundancy to be stored in a
  140. /// specialized format instead of the fully-general, fully-vbr, format.
  141. class BitCodeAbbrev {
  142. SmallVector<BitCodeAbbrevOp, 32> OperandList;
  143. unsigned char RefCount; // Number of things using this.
  144. ~BitCodeAbbrev() {}
  145. public:
  146. BitCodeAbbrev() : RefCount(1) {}
  147. void addRef() { ++RefCount; }
  148. void dropRef() { if (--RefCount == 0) delete this; }
  149. unsigned getNumOperandInfos() const {
  150. return static_cast<unsigned>(OperandList.size());
  151. }
  152. const BitCodeAbbrevOp &getOperandInfo(unsigned N) const {
  153. return OperandList[N];
  154. }
  155. void Add(const BitCodeAbbrevOp &OpInfo) {
  156. OperandList.push_back(OpInfo);
  157. }
  158. };
  159. } // End llvm namespace
  160. #endif