diff options
author | Chris Lattner <sabre@nondot.org> | 2009-04-06 21:20:01 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-04-06 21:20:01 +0000 |
commit | 96153a45fd706db8731ba17bdf848912c8033e1d (patch) | |
tree | 31d2275577b220e1984b84600a10929e94593517 /include/llvm/Bitcode/BitstreamWriter.h | |
parent | 40728791f5c8c77d3460a30fcdce6d1fac72aa0d (diff) |
simplify code a bit.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@68461 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/Bitcode/BitstreamWriter.h')
-rw-r--r-- | include/llvm/Bitcode/BitstreamWriter.h | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/include/llvm/Bitcode/BitstreamWriter.h b/include/llvm/Bitcode/BitstreamWriter.h index acb61d88bd..49fe4076c2 100644 --- a/include/llvm/Bitcode/BitstreamWriter.h +++ b/include/llvm/Bitcode/BitstreamWriter.h @@ -252,18 +252,23 @@ public: //===--------------------------------------------------------------------===// private: + /// EmitAbbreviatedLiteral - Emit a literal value according to its abbrev + /// record. This is a no-op, since the abbrev specifies the literal to use. + template<typename uintty> + void EmitAbbreviatedLiteral(const BitCodeAbbrevOp &Op, uintty V) { + assert(Op.isLiteral() && "Not a literal"); + // If the abbrev specifies the literal value to use, don't emit + // anything. + assert(V == Op.getLiteralValue() && + "Invalid abbrev for record!"); + } + /// EmitAbbreviatedField - Emit a single scalar field value with the specified /// encoding. template<typename uintty> void EmitAbbreviatedField(const BitCodeAbbrevOp &Op, uintty V) { - if (Op.isLiteral()) { - // If the abbrev specifies the literal value to use, don't emit - // anything. - assert(V == Op.getLiteralValue() && - "Invalid abbrev for record!"); - return; - } - + assert(!Op.isLiteral() && "Literals should use EmitAbbreviatedLiteral!"); + // Encode the value as we are commanded. switch (Op.getEncoding()) { default: assert(0 && "Unknown encoding!"); @@ -278,6 +283,7 @@ private: break; } } + public: /// EmitRecord - Emit the specified record to the stream, using an abbrev if @@ -309,7 +315,11 @@ public: for (unsigned i = 0, e = static_cast<unsigned>(Abbv->getNumOperandInfos()); i != e; ++i) { const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i); - if (Op.isLiteral() || Op.getEncoding() != BitCodeAbbrevOp::Array) { + if (Op.isLiteral()) { + assert(RecordIdx < Vals.size() && "Invalid abbrev/record"); + EmitAbbreviatedLiteral(Op, Vals[RecordIdx]); + ++RecordIdx; + } else if (Op.getEncoding() != BitCodeAbbrevOp::Array) { assert(RecordIdx < Vals.size() && "Invalid abbrev/record"); EmitAbbreviatedField(Op, Vals[RecordIdx]); ++RecordIdx; |