diff options
author | Chris Lattner <sabre@nondot.org> | 2007-04-23 17:43:52 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2007-04-23 17:43:52 +0000 |
commit | 6d4135a62e9b6af2417748ab81da8dad5e2059d9 (patch) | |
tree | 2bded19045c930ef1a8e83321e988be58a79fcd6 /include/llvm/Bitcode/BitstreamWriter.h | |
parent | 36d5e7d31be61f631ace0488f0d6cd71b8f31a16 (diff) |
finish implementation of basic abbrev writing.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@36364 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/Bitcode/BitstreamWriter.h')
-rw-r--r-- | include/llvm/Bitcode/BitstreamWriter.h | 73 |
1 files changed, 69 insertions, 4 deletions
diff --git a/include/llvm/Bitcode/BitstreamWriter.h b/include/llvm/Bitcode/BitstreamWriter.h index 104508578d..61208724bf 100644 --- a/include/llvm/Bitcode/BitstreamWriter.h +++ b/include/llvm/Bitcode/BitstreamWriter.h @@ -194,11 +194,40 @@ public: unsigned AbbrevNo = Abbrev-bitc::FIRST_ABBREV; assert(AbbrevNo < CurAbbrevs.size() && "Invalid abbrev #!"); BitCodeAbbrev *Abbv = CurAbbrevs[AbbrevNo]; - assert(0 && "TODO"); - for (unsigned i = 0, e = Abbv->getNumOperandInfos(); i != e; ++i) { - } + EmitCode(Abbrev); + // Insert the code into Vals to treat it uniformly. + Vals.insert(Vals.begin(), Code); + + unsigned RecordIdx = 0; + for (unsigned i = 0, e = Abbv->getNumOperandInfos(); i != e; ++i) { + assert(RecordIdx < Vals.size() && "Invalid abbrev/record"); + const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i); + uint64_t RecordVal = Vals[RecordIdx]; + + if (Op.isLiteral()) { + // If the abbrev specifies the literal value to use, don't emit + // anything. + assert(RecordVal == Op.getLiteralValue() && + "Invalid abbrev for record!"); + ++RecordIdx; + } else { + // Encode the value as we are commanded. + switch (Op.getEncoding()) { + default: assert(0 && "Unknown encoding!"); + case BitCodeAbbrevOp::FixedWidth: + Emit64(RecordVal, Op.getEncodingData()); + ++RecordIdx; + break; + case BitCodeAbbrevOp::VBR: + EmitVBR64(RecordVal, Op.getEncodingData()); + ++RecordIdx; + break; + } + } + } + assert(RecordIdx == Vals.size() && "Not all record operands emitted!"); } else { // If we don't have an abbrev to use, emit this in its fully unabbreviated // form. @@ -215,7 +244,43 @@ public: void EmitRecord(unsigned Code, SmallVectorImpl<unsigned> &Vals, unsigned Abbrev = 0) { if (Abbrev) { - assert(0 && "abbrevs not implemented yet!"); + unsigned AbbrevNo = Abbrev-bitc::FIRST_ABBREV; + assert(AbbrevNo < CurAbbrevs.size() && "Invalid abbrev #!"); + BitCodeAbbrev *Abbv = CurAbbrevs[AbbrevNo]; + + EmitCode(Abbrev); + + // Insert the code into Vals to treat it uniformly. + Vals.insert(Vals.begin(), Code); + + unsigned RecordIdx = 0; + for (unsigned i = 0, e = Abbv->getNumOperandInfos(); i != e; ++i) { + assert(RecordIdx < Vals.size() && "Invalid abbrev/record"); + const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i); + unsigned RecordVal = Vals[RecordIdx]; + + if (Op.isLiteral()) { + // If the abbrev specifies the literal value to use, don't emit + // anything. + assert(RecordVal == Op.getLiteralValue() && + "Invalid abbrev for record!"); + ++RecordIdx; + } else { + // Encode the value as we are commanded. + switch (Op.getEncoding()) { + default: assert(0 && "Unknown encoding!"); + case BitCodeAbbrevOp::FixedWidth: + Emit(RecordVal, Op.getEncodingData()); + ++RecordIdx; + break; + case BitCodeAbbrevOp::VBR: + EmitVBR(RecordVal, Op.getEncodingData()); + ++RecordIdx; + break; + } + } + } + assert(RecordIdx == Vals.size() && "Not all record operands emitted!"); } else { // If we don't have an abbrev to use, emit this in its fully unabbreviated // form. |