llvm.org GIT mirror llvm / 8d42fc3
use a template to eliminate manual code duplication git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@36757 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 12 years ago
1 changed file(s) with 2 addition(s) and 47 deletion(s). Raw diff Collapse all Expand all
216216
217217 /// EmitRecord - Emit the specified record to the stream, using an abbrev if
218218 /// we have one to compress the output.
219 void EmitRecord(unsigned Code, SmallVectorImpl &Vals,
219 template
220 void EmitRecord(unsigned Code, SmallVectorImpl &Vals,
220221 unsigned Abbrev = 0) {
221222 if (Abbrev) {
222223 unsigned AbbrevNo = Abbrev-bitc::FIRST_APPLICATION_ABBREV;
260261 }
261262 }
262263
263 /// EmitRecord - Emit the specified record to the stream, using an abbrev if
264 /// we have one to compress the output.
265 void EmitRecord(unsigned Code, SmallVectorImpl &Vals,
266 unsigned Abbrev = 0) {
267 if (Abbrev) {
268 unsigned AbbrevNo = Abbrev-bitc::FIRST_APPLICATION_ABBREV;
269 assert(AbbrevNo < CurAbbrevs.size() && "Invalid abbrev #!");
270 BitCodeAbbrev *Abbv = CurAbbrevs[AbbrevNo];
271
272 EmitCode(Abbrev);
273
274 // Insert the code into Vals to treat it uniformly.
275 Vals.insert(Vals.begin(), Code);
276
277 unsigned RecordIdx = 0;
278 for (unsigned i = 0, e = Abbv->getNumOperandInfos(); i != e; ++i) {
279 assert(RecordIdx < Vals.size() && "Invalid abbrev/record");
280 const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i);
281
282 if (Op.isLiteral() || Op.getEncoding() != BitCodeAbbrevOp::Array) {
283 EmitAbbreviatedField(Op, Vals[RecordIdx]);
284 ++RecordIdx;
285 } else {
286 assert(i+2 == e && "array op not second to last?");
287 const BitCodeAbbrevOp &EltEnc = Abbv->getOperandInfo(++i);
288
289 // Emit a vbr6 to indicate the number of elements present.
290 EmitVBR(Vals.size()-RecordIdx, 6);
291
292 // Emit each field.
293 for (; RecordIdx != Vals.size(); ++RecordIdx)
294 EmitAbbreviatedField(EltEnc, Vals[RecordIdx]);
295 }
296 }
297 assert(RecordIdx == Vals.size() && "Not all record operands emitted!");
298 } else {
299 // If we don't have an abbrev to use, emit this in its fully unabbreviated
300 // form.
301 EmitCode(bitc::UNABBREV_RECORD);
302 EmitVBR(Code, 6);
303 EmitVBR(Vals.size(), 6);
304 for (unsigned i = 0, e = Vals.size(); i != e; ++i)
305 EmitVBR(Vals[i], 6);
306 }
307 }
308
309264 //===--------------------------------------------------------------------===//
310265 // Abbrev Emission
311266 //===--------------------------------------------------------------------===//