aboutsummaryrefslogtreecommitdiff
path: root/lib/Bitcode/Writer/BitcodeWriter.cpp
diff options
context:
space:
mode:
authorNick Lewycky <nicholas@mxc.ca>2009-04-04 07:22:01 +0000
committerNick Lewycky <nicholas@mxc.ca>2009-04-04 07:22:01 +0000
commit21cc4460efa104e8591b05a90f20130291614344 (patch)
tree6f5a7d6d7f4693fe0b16635fc34ac7c99174331d /lib/Bitcode/Writer/BitcodeWriter.cpp
parent2cd1b777d7ba88dc4c4c072ec58dca9f96a8b4c2 (diff)
Add support for embedded metadata to LLVM. This introduces two new types of
Constant, MDString and MDNode which can only be used by globals with a name that starts with "llvm." or as arguments to a function with the same naming restriction. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@68420 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Bitcode/Writer/BitcodeWriter.cpp')
-rw-r--r--lib/Bitcode/Writer/BitcodeWriter.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/Bitcode/Writer/BitcodeWriter.cpp b/lib/Bitcode/Writer/BitcodeWriter.cpp
index d4d3443ee0..c836d39d25 100644
--- a/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ b/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -458,6 +458,8 @@ static void WriteConstants(unsigned FirstVal, unsigned LastVal,
unsigned String8Abbrev = 0;
unsigned CString7Abbrev = 0;
unsigned CString6Abbrev = 0;
+ unsigned MDString8Abbrev = 0;
+ unsigned MDString6Abbrev = 0;
// If this is a constant pool for the module, emit module-specific abbrevs.
if (isGlobal) {
// Abbrev for CST_CODE_AGGREGATE.
@@ -485,6 +487,19 @@ static void WriteConstants(unsigned FirstVal, unsigned LastVal,
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Char6));
CString6Abbrev = Stream.EmitAbbrev(Abbv);
+
+ // Abbrev for CST_CODE_MDSTRING.
+ Abbv = new BitCodeAbbrev();
+ Abbv->Add(BitCodeAbbrevOp(bitc::CST_CODE_MDSTRING));
+ Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
+ Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 8));
+ MDString8Abbrev = Stream.EmitAbbrev(Abbv);
+ // Abbrev for CST_CODE_MDSTRING.
+ Abbv = new BitCodeAbbrev();
+ Abbv->Add(BitCodeAbbrevOp(bitc::CST_CODE_MDSTRING));
+ Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
+ Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Char6));
+ MDString6Abbrev = Stream.EmitAbbrev(Abbv);
}
SmallVector<uint64_t, 64> Record;
@@ -678,6 +693,22 @@ static void WriteConstants(unsigned FirstVal, unsigned LastVal,
Record.push_back(CE->getPredicate());
break;
}
+ } else if (const MDString *S = dyn_cast<MDString>(C)) {
+ Code = bitc::CST_CODE_MDSTRING;
+ AbbrevToUse = MDString6Abbrev;
+ for (unsigned i = 0, e = S->size(); i != e; ++i) {
+ char V = S->begin()[i];
+ Record.push_back(V);
+
+ if (!BitCodeAbbrevOp::isChar6(V))
+ AbbrevToUse = MDString8Abbrev;
+ }
+ } else if (const MDNode *N = dyn_cast<MDNode>(C)) {
+ Code = bitc::CST_CODE_MDNODE;
+ for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) {
+ Record.push_back(VE.getTypeID(N->getOperand(i)->getType()));
+ Record.push_back(VE.getValueID(N->getOperand(i)));
+ }
} else {
assert(0 && "Unknown constant!");
}