[llvm-commits] [llvm] r68461 - /llvm/trunk/include/llvm/Bitcode/BitstreamWriter.h
Chris Lattner
sabre at nondot.org
Mon Apr 6 14:20:02 PDT 2009
Author: lattner
Date: Mon Apr 6 16:20:01 2009
New Revision: 68461
URL: http://llvm.org/viewvc/llvm-project?rev=68461&view=rev
Log:
simplify code a bit.
Modified:
llvm/trunk/include/llvm/Bitcode/BitstreamWriter.h
Modified: llvm/trunk/include/llvm/Bitcode/BitstreamWriter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Bitcode/BitstreamWriter.h?rev=68461&r1=68460&r2=68461&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Bitcode/BitstreamWriter.h (original)
+++ llvm/trunk/include/llvm/Bitcode/BitstreamWriter.h Mon Apr 6 16:20:01 2009
@@ -252,18 +252,23 @@
//===--------------------------------------------------------------------===//
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 @@
break;
}
}
+
public:
/// EmitRecord - Emit the specified record to the stream, using an abbrev if
@@ -309,7 +315,11 @@
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;
More information about the llvm-commits
mailing list