llvm.org GIT mirror llvm / 28e4c4c
add a 6-bit encoding type for strings. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@36770 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 13 years ago
3 changed file(s) with 38 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
8484 unsigned Enc : 3; // The encoding to use.
8585 public:
8686 enum Encoding {
87 Fixed = 1, // A fixed with field, Val specifies number of bits.
87 Fixed = 1, // A fixed width field, Val specifies number of bits.
8888 VBR = 2, // A VBR field where Val specifies the width of each chunk.
89 Array = 3 // A sequence of fields, next field species elt encoding.
89 Array = 3, // A sequence of fields, next field species elt encoding.
90 Char6 = 4 // A 6-bit fixed field which maps to [a-zA-Z0-9._].
9091 };
9192
9293 BitCodeAbbrevOp(uint64_t V) : Val(V), IsLiteral(true) {}
9394 BitCodeAbbrevOp(Encoding E, uint64_t Data = 0)
9495 : Val(Data), IsLiteral(false), Enc(E) {}
95
9696
9797 bool isLiteral() const { return IsLiteral; }
9898 bool isEncoding() const { return !IsLiteral; }
115115 case VBR:
116116 return true;
117117 case Array:
118 case Char6:
118119 return false;
119120 }
120121 }
122
123 /// isChar6 - Return true if this character is legal in the Char6 encoding.
124 static bool isChar6(char C) {
125 if (C >= 'a' && C <= 'z') return true;
126 if (C >= 'A' && C <= 'Z') return true;
127 if (C >= '0' && C <= '9') return true;
128 if (C == '.' || C == '_') return true;
129 return false;
130 }
131 static unsigned EncodeChar6(char C) {
132 if (C >= 'a' && C <= 'z') return C-'a';
133 if (C >= 'A' && C <= 'Z') return C-'A'+26;
134 if (C >= '0' && C <= '9') return C-'0'+26+26;
135 if (C == '.') return 62;
136 if (C == '_') return 63;
137 assert(0 && "Not a value Char6 character!");
138 }
139
140 static char DecodeChar6(unsigned V) {
141 assert((V & ~63) == 0 && "Not a Char6 encoded character!");
142 if (V < 26) return V+'a';
143 if (V < 26+26) return V-26+'A';
144 if (V < 26+26+10) return V-26-26+'0';
145 if (V == 62) return '.';
146 if (V == 63) return '_';
147 assert(0 && "Not a value Char6 character!");
148 }
149
121150 };
122151
123152 /// BitCodeAbbrev - This class represents an abbreviation record. An
331331 case BitCodeAbbrevOp::VBR:
332332 Vals.push_back(ReadVBR64(Op.getEncodingData()));
333333 break;
334 case BitCodeAbbrevOp::Char6:
335 Vals.push_back(BitCodeAbbrevOp::DecodeChar6(Read(6)));
336 break;
334337 }
335338 }
336339 }
258258 break;
259259 case BitCodeAbbrevOp::VBR:
260260 EmitVBR(V, Op.getEncodingData());
261 break;
262 case BitCodeAbbrevOp::Char6:
263 Emit(BitCodeAbbrevOp::EncodeChar6((char)V), 6);
261264 break;
262265 }
263266 }