File indexing completed on 2026-05-10 08:43:22
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 #ifndef LLVM_BITSTREAM_BITCODES_H
0018 #define LLVM_BITSTREAM_BITCODES_H
0019
0020 #include "llvm/ADT/SmallVector.h"
0021 #include "llvm/ADT/StringExtras.h"
0022 #include "llvm/Bitstream/BitCodeEnums.h"
0023 #include "llvm/Support/DataTypes.h"
0024 #include "llvm/Support/ErrorHandling.h"
0025 #include <cassert>
0026
0027 namespace llvm {
0028
0029
0030
0031
0032
0033 class BitCodeAbbrevOp {
0034 uint64_t Val;
0035 bool IsLiteral : 1;
0036 unsigned Enc : 3;
0037 public:
0038 enum Encoding {
0039 Fixed = 1,
0040 VBR = 2,
0041 Array = 3,
0042 Char6 = 4,
0043 Blob = 5
0044 };
0045
0046 static bool isValidEncoding(uint64_t E) {
0047 return E >= 1 && E <= 5;
0048 }
0049
0050 explicit BitCodeAbbrevOp(uint64_t V) : Val(V), IsLiteral(true) {}
0051 explicit BitCodeAbbrevOp(Encoding E, uint64_t Data = 0)
0052 : Val(Data), IsLiteral(false), Enc(E) {}
0053
0054 bool isLiteral() const { return IsLiteral; }
0055 bool isEncoding() const { return !IsLiteral; }
0056
0057
0058 uint64_t getLiteralValue() const { assert(isLiteral()); return Val; }
0059
0060
0061 Encoding getEncoding() const { assert(isEncoding()); return (Encoding)Enc; }
0062 uint64_t getEncodingData() const {
0063 assert(isEncoding() && hasEncodingData());
0064 return Val;
0065 }
0066
0067 bool hasEncodingData() const { return hasEncodingData(getEncoding()); }
0068 static bool hasEncodingData(Encoding E) {
0069 switch (E) {
0070 case Fixed:
0071 case VBR:
0072 return true;
0073 case Array:
0074 case Char6:
0075 case Blob:
0076 return false;
0077 }
0078 report_fatal_error("Invalid encoding");
0079 }
0080
0081
0082 static bool isChar6(char C) { return isAlnum(C) || C == '.' || C == '_'; }
0083 static unsigned EncodeChar6(char C) {
0084 if (C >= 'a' && C <= 'z') return C-'a';
0085 if (C >= 'A' && C <= 'Z') return C-'A'+26;
0086 if (C >= '0' && C <= '9') return C-'0'+26+26;
0087 if (C == '.') return 62;
0088 if (C == '_') return 63;
0089 llvm_unreachable("Not a value Char6 character!");
0090 }
0091
0092 static char DecodeChar6(unsigned V) {
0093 assert((V & ~63) == 0 && "Not a Char6 encoded character!");
0094 return "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789._"
0095 [V];
0096 }
0097
0098 };
0099
0100
0101
0102
0103 class BitCodeAbbrev {
0104 SmallVector<BitCodeAbbrevOp, 32> OperandList;
0105
0106 public:
0107 BitCodeAbbrev() = default;
0108
0109 explicit BitCodeAbbrev(std::initializer_list<BitCodeAbbrevOp> OperandList)
0110 : OperandList(OperandList) {}
0111
0112 unsigned getNumOperandInfos() const {
0113 return static_cast<unsigned>(OperandList.size());
0114 }
0115 const BitCodeAbbrevOp &getOperandInfo(unsigned N) const {
0116 return OperandList[N];
0117 }
0118
0119 void Add(const BitCodeAbbrevOp &OpInfo) {
0120 OperandList.push_back(OpInfo);
0121 }
0122 };
0123 }
0124
0125 #endif