LLVM API Documentation
00001 //===- BitCodes.h - Enum values for the bitcode format ----------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This header Bitcode enum values. 00011 // 00012 // The enum values defined in this file should be considered permanent. If 00013 // new features are added, they should have values added at the end of the 00014 // respective lists. 00015 // 00016 //===----------------------------------------------------------------------===// 00017 00018 #ifndef LLVM_BITCODE_BITCODES_H 00019 #define LLVM_BITCODE_BITCODES_H 00020 00021 #include "llvm/ADT/IntrusiveRefCntPtr.h" 00022 #include "llvm/ADT/SmallVector.h" 00023 #include "llvm/Support/DataTypes.h" 00024 #include "llvm/Support/ErrorHandling.h" 00025 #include <cassert> 00026 00027 namespace llvm { 00028 namespace bitc { 00029 enum StandardWidths { 00030 BlockIDWidth = 8, // We use VBR-8 for block IDs. 00031 CodeLenWidth = 4, // Codelen are VBR-4. 00032 BlockSizeWidth = 32 // BlockSize up to 2^32 32-bit words = 16GB per block. 00033 }; 00034 00035 // The standard abbrev namespace always has a way to exit a block, enter a 00036 // nested block, define abbrevs, and define an unabbreviated record. 00037 enum FixedAbbrevIDs { 00038 END_BLOCK = 0, // Must be zero to guarantee termination for broken bitcode. 00039 ENTER_SUBBLOCK = 1, 00040 00041 /// DEFINE_ABBREV - Defines an abbrev for the current block. It consists 00042 /// of a vbr5 for # operand infos. Each operand info is emitted with a 00043 /// single bit to indicate if it is a literal encoding. If so, the value is 00044 /// emitted with a vbr8. If not, the encoding is emitted as 3 bits followed 00045 /// by the info value as a vbr5 if needed. 00046 DEFINE_ABBREV = 2, 00047 00048 // UNABBREV_RECORDs are emitted with a vbr6 for the record code, followed by 00049 // a vbr6 for the # operands, followed by vbr6's for each operand. 00050 UNABBREV_RECORD = 3, 00051 00052 // This is not a code, this is a marker for the first abbrev assignment. 00053 FIRST_APPLICATION_ABBREV = 4 00054 }; 00055 00056 /// StandardBlockIDs - All bitcode files can optionally include a BLOCKINFO 00057 /// block, which contains metadata about other blocks in the file. 00058 enum StandardBlockIDs { 00059 /// BLOCKINFO_BLOCK is used to define metadata about blocks, for example, 00060 /// standard abbrevs that should be available to all blocks of a specified 00061 /// ID. 00062 BLOCKINFO_BLOCK_ID = 0, 00063 00064 // Block IDs 1-7 are reserved for future expansion. 00065 FIRST_APPLICATION_BLOCKID = 8 00066 }; 00067 00068 /// BlockInfoCodes - The blockinfo block contains metadata about user-defined 00069 /// blocks. 00070 enum BlockInfoCodes { 00071 // DEFINE_ABBREV has magic semantics here, applying to the current SETBID'd 00072 // block, instead of the BlockInfo block. 00073 00074 BLOCKINFO_CODE_SETBID = 1, // SETBID: [blockid#] 00075 BLOCKINFO_CODE_BLOCKNAME = 2, // BLOCKNAME: [name] 00076 BLOCKINFO_CODE_SETRECORDNAME = 3 // BLOCKINFO_CODE_SETRECORDNAME: 00077 // [id, name] 00078 }; 00079 00080 } // End bitc namespace 00081 00082 /// BitCodeAbbrevOp - This describes one or more operands in an abbreviation. 00083 /// This is actually a union of two different things: 00084 /// 1. It could be a literal integer value ("the operand is always 17"). 00085 /// 2. It could be an encoding specification ("this operand encoded like so"). 00086 /// 00087 class BitCodeAbbrevOp { 00088 uint64_t Val; // A literal value or data for an encoding. 00089 bool IsLiteral : 1; // Indicate whether this is a literal value or not. 00090 unsigned Enc : 3; // The encoding to use. 00091 public: 00092 enum Encoding { 00093 Fixed = 1, // A fixed width field, Val specifies number of bits. 00094 VBR = 2, // A VBR field where Val specifies the width of each chunk. 00095 Array = 3, // A sequence of fields, next field species elt encoding. 00096 Char6 = 4, // A 6-bit fixed field which maps to [a-zA-Z0-9._]. 00097 Blob = 5 // 32-bit aligned array of 8-bit characters. 00098 }; 00099 00100 explicit BitCodeAbbrevOp(uint64_t V) : Val(V), IsLiteral(true) {} 00101 explicit BitCodeAbbrevOp(Encoding E, uint64_t Data = 0) 00102 : Val(Data), IsLiteral(false), Enc(E) {} 00103 00104 bool isLiteral() const { return IsLiteral; } 00105 bool isEncoding() const { return !IsLiteral; } 00106 00107 // Accessors for literals. 00108 uint64_t getLiteralValue() const { assert(isLiteral()); return Val; } 00109 00110 // Accessors for encoding info. 00111 Encoding getEncoding() const { assert(isEncoding()); return (Encoding)Enc; } 00112 uint64_t getEncodingData() const { 00113 assert(isEncoding() && hasEncodingData()); 00114 return Val; 00115 } 00116 00117 bool hasEncodingData() const { return hasEncodingData(getEncoding()); } 00118 static bool hasEncodingData(Encoding E) { 00119 switch (E) { 00120 case Fixed: 00121 case VBR: 00122 return true; 00123 case Array: 00124 case Char6: 00125 case Blob: 00126 return false; 00127 } 00128 llvm_unreachable("Invalid encoding"); 00129 } 00130 00131 /// isChar6 - Return true if this character is legal in the Char6 encoding. 00132 static bool isChar6(char C) { 00133 if (C >= 'a' && C <= 'z') return true; 00134 if (C >= 'A' && C <= 'Z') return true; 00135 if (C >= '0' && C <= '9') return true; 00136 if (C == '.' || C == '_') return true; 00137 return false; 00138 } 00139 static unsigned EncodeChar6(char C) { 00140 if (C >= 'a' && C <= 'z') return C-'a'; 00141 if (C >= 'A' && C <= 'Z') return C-'A'+26; 00142 if (C >= '0' && C <= '9') return C-'0'+26+26; 00143 if (C == '.') return 62; 00144 if (C == '_') return 63; 00145 llvm_unreachable("Not a value Char6 character!"); 00146 } 00147 00148 static char DecodeChar6(unsigned V) { 00149 assert((V & ~63) == 0 && "Not a Char6 encoded character!"); 00150 if (V < 26) return V+'a'; 00151 if (V < 26+26) return V-26+'A'; 00152 if (V < 26+26+10) return V-26-26+'0'; 00153 if (V == 62) return '.'; 00154 if (V == 63) return '_'; 00155 llvm_unreachable("Not a value Char6 character!"); 00156 } 00157 00158 }; 00159 00160 template <> struct isPodLike<BitCodeAbbrevOp> { static const bool value=true; }; 00161 00162 /// BitCodeAbbrev - This class represents an abbreviation record. An 00163 /// abbreviation allows a complex record that has redundancy to be stored in a 00164 /// specialized format instead of the fully-general, fully-vbr, format. 00165 class BitCodeAbbrev : public RefCountedBase<BitCodeAbbrev> { 00166 SmallVector<BitCodeAbbrevOp, 32> OperandList; 00167 ~BitCodeAbbrev() {} 00168 // Only RefCountedBase is allowed to delete. 00169 friend class RefCountedBase<BitCodeAbbrev>; 00170 00171 public: 00172 unsigned getNumOperandInfos() const { 00173 return static_cast<unsigned>(OperandList.size()); 00174 } 00175 const BitCodeAbbrevOp &getOperandInfo(unsigned N) const { 00176 return OperandList[N]; 00177 } 00178 00179 void Add(const BitCodeAbbrevOp &OpInfo) { 00180 OperandList.push_back(OpInfo); 00181 } 00182 }; 00183 } // End llvm namespace 00184 00185 #endif