aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Bitcode/Reader
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/Reader
parent2cd1b777d7ba88dc4c4c072ec58dca9f96a8b4c2 (diff)
downloadexternal_llvm-21cc4460efa104e8591b05a90f20130291614344.zip
external_llvm-21cc4460efa104e8591b05a90f20130291614344.tar.gz
external_llvm-21cc4460efa104e8591b05a90f20130291614344.tar.bz2
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/Reader')
-rw-r--r--lib/Bitcode/Reader/BitcodeReader.cpp29
1 files changed, 27 insertions, 2 deletions
diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp
index dd9db8f..66ccdc2 100644
--- a/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -286,10 +286,12 @@ void BitcodeReaderValueList::ResolveConstantForwardRefs() {
UserCS->getType()->isPacked());
} else if (isa<ConstantVector>(UserC)) {
NewC = ConstantVector::get(&NewOps[0], NewOps.size());
- } else {
- // Must be a constant expression.
+ } else if (isa<ConstantExpr>(UserC)) {
NewC = cast<ConstantExpr>(UserC)->getWithOperands(&NewOps[0],
NewOps.size());
+ } else {
+ assert(isa<MDNode>(UserC) && "Must be a metadata node.");
+ NewC = MDNode::get(&NewOps[0], NewOps.size());
}
UserC->replaceAllUsesWith(NewC);
@@ -999,6 +1001,29 @@ bool BitcodeReader::ParseConstants() {
AsmStr, ConstrStr, HasSideEffects);
break;
}
+ case bitc::CST_CODE_MDSTRING: {
+ if (Record.size() < 2) return Error("Invalid MDSTRING record");
+ unsigned MDStringLength = Record.size();
+ SmallString<8> String;
+ String.resize(MDStringLength);
+ for (unsigned i = 0; i != MDStringLength; ++i)
+ String[i] = Record[i];
+ V = MDString::get(String.c_str(), String.c_str() + MDStringLength);
+ break;
+ }
+ case bitc::CST_CODE_MDNODE: {
+ if (Record.empty() || Record.size() % 2 == 1)
+ return Error("Invalid CST_MDNODE record");
+
+ unsigned Size = Record.size();
+ SmallVector<Constant*, 8> Elts;
+ for (unsigned i = 0; i != Size; i += 2) {
+ const Type *Ty = getTypeByID(Record[i], false);
+ Elts.push_back(ValueList.getConstantFwdRef(Record[i+1], Ty));
+ }
+ V = MDNode::get(&Elts[0], Elts.size());
+ break;
+ }
}
ValueList.AssignValue(V, NextCstNo);