llvm.org GIT mirror llvm / d08fb26
Change EmitRecordWithAbbrevImpl to take Optional record code. NFC. This change enables EmitRecord to pass the supplied record Code to EmitRecordWithAbbrevImpl, rather than insert it into the Vals array. It is an enabler for changing EmitRecord to take an ArrayRef<uintty> instead of a SmallVectorImpl<uintty>& Patch suggested by Duncan P. N. Exon Smith, modified by myself a bit to get correct assertion checking. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@247186 91177308-0d34-0410-b5e6-96231b3b80d8 Teresa Johnson 5 years ago
1 changed file(s) with 30 addition(s) and 15 deletion(s). Raw diff Collapse all Expand all
1414 #ifndef LLVM_BITCODE_BITSTREAMWRITER_H
1515 #define LLVM_BITCODE_BITSTREAMWRITER_H
1616
17 #include "llvm/ADT/Optional.h"
1718 #include "llvm/ADT/SmallVector.h"
1819 #include "llvm/ADT/StringRef.h"
1920 #include "llvm/Bitcode/BitCodes.h"
284285 /// EmitRecordWithAbbrevImpl - This is the core implementation of the record
285286 /// emission code. If BlobData is non-null, then it specifies an array of
286287 /// data that should be emitted as part of the Blob or Array operand that is
287 /// known to exist at the end of the record.
288 /// known to exist at the end of the record. If Code is specified, then
289 /// it is the record code to emit before the Vals, which must not contain
290 /// the code.
288291 template
289292 void EmitRecordWithAbbrevImpl(unsigned Abbrev, SmallVectorImpl &Vals,
290 StringRef Blob) {
293 StringRef Blob, Optional Code) {
291294 const char *BlobData = Blob.data();
292295 unsigned BlobLen = (unsigned) Blob.size();
293296 unsigned AbbrevNo = Abbrev-bitc::FIRST_APPLICATION_ABBREV;
296299
297300 EmitCode(Abbrev);
298301
302 unsigned i = 0, e = static_cast(Abbv->getNumOperandInfos());
303 if (Code) {
304 assert(e && "Expected non-empty abbreviation");
305 const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i++);
306
307 if (Op.isLiteral())
308 EmitAbbreviatedLiteral(Op, Code.getValue());
309 else {
310 assert(Op.getEncoding() != BitCodeAbbrevOp::Array &&
311 Op.getEncoding() != BitCodeAbbrevOp::Blob &&
312 "Expected literal or scalar");
313 EmitAbbreviatedField(Op, Code.getValue());
314 }
315 }
316
299317 unsigned RecordIdx = 0;
300 for (unsigned i = 0, e = static_cast(Abbv->getNumOperandInfos());
301 i != e; ++i) {
318 for (; i != e; ++i) {
302319 const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i);
303320 if (Op.isLiteral()) {
304321 assert(RecordIdx < Vals.size() && "Invalid abbrev/record");
306323 ++RecordIdx;
307324 } else if (Op.getEncoding() == BitCodeAbbrevOp::Array) {
308325 // Array case.
309 assert(i+2 == e && "array op not second to last?");
326 assert(i + 2 == e && "array op not second to last?");
310327 const BitCodeAbbrevOp &EltEnc = Abbv->getOperandInfo(++i);
311328
312329 // If this record has blob data, emit it, otherwise we must have record
394411 return;
395412 }
396413
397 // Insert the code into Vals to treat it uniformly.
398 Vals.insert(Vals.begin(), Code);
399
400 EmitRecordWithAbbrev(Abbrev, Vals);
414 EmitRecordWithAbbrevImpl(Abbrev, Vals, StringRef(), Code);
401415 }
402416
403417 /// EmitRecordWithAbbrev - Emit a record with the specified abbreviation.
405419 /// the first entry.
406420 template
407421 void EmitRecordWithAbbrev(unsigned Abbrev, SmallVectorImpl &Vals) {
408 EmitRecordWithAbbrevImpl(Abbrev, Vals, StringRef());
422 EmitRecordWithAbbrevImpl(Abbrev, Vals, StringRef(), None);
409423 }
410424
411425 /// EmitRecordWithBlob - Emit the specified record to the stream, using an
416430 template
417431 void EmitRecordWithBlob(unsigned Abbrev, SmallVectorImpl &Vals,
418432 StringRef Blob) {
419 EmitRecordWithAbbrevImpl(Abbrev, Vals, Blob);
433 EmitRecordWithAbbrevImpl(Abbrev, Vals, Blob, None);
420434 }
421435 template
422436 void EmitRecordWithBlob(unsigned Abbrev, SmallVectorImpl &Vals,
423437 const char *BlobData, unsigned BlobLen) {
424 return EmitRecordWithAbbrevImpl(Abbrev, Vals, StringRef(BlobData, BlobLen));
438 return EmitRecordWithAbbrevImpl(Abbrev, Vals, StringRef(BlobData, BlobLen),
439 None);
425440 }
426441
427442 /// EmitRecordWithArray - Just like EmitRecordWithBlob, works with records
429444 template
430445 void EmitRecordWithArray(unsigned Abbrev, SmallVectorImpl &Vals,
431446 StringRef Array) {
432 EmitRecordWithAbbrevImpl(Abbrev, Vals, Array);
447 EmitRecordWithAbbrevImpl(Abbrev, Vals, Array, None);
433448 }
434449 template
435450 void EmitRecordWithArray(unsigned Abbrev, SmallVectorImpl &Vals,
436451 const char *ArrayData, unsigned ArrayLen) {
437 return EmitRecordWithAbbrevImpl(Abbrev, Vals, StringRef(ArrayData,
438 ArrayLen));
452 return EmitRecordWithAbbrevImpl(Abbrev, Vals,
453 StringRef(ArrayData, ArrayLen), None);
439454 }
440455
441456 //===--------------------------------------------------------------------===//