summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>2015-02-13 01:34:32 +0000
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>2015-02-13 01:34:32 +0000
commit2847f3805ebeeb7787323b2b3a6aafa44022a908 (patch)
treeebbb2a3a9e008403adabc236def2f23a9b1b7d4b /llvm/lib
parente146000565c86e7cd70d746a64084f1ea3a7528e (diff)
downloadbcm5719-llvm-2847f3805ebeeb7787323b2b3a6aafa44022a908.tar.gz
bcm5719-llvm-2847f3805ebeeb7787323b2b3a6aafa44022a908.zip
AsmWriter/Bitcode: MDTemplate{Type,Value}Parameter
llvm-svn: 229019
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/AsmParser/LLParser.cpp33
-rw-r--r--llvm/lib/Bitcode/Reader/BitcodeReader.cpp23
-rw-r--r--llvm/lib/Bitcode/Writer/BitcodeWriter.cpp40
-rw-r--r--llvm/lib/IR/AsmWriter.cpp41
4 files changed, 113 insertions, 24 deletions
diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp
index be1db2233d2..59e3c0ec8cf 100644
--- a/llvm/lib/AsmParser/LLParser.cpp
+++ b/llvm/lib/AsmParser/LLParser.cpp
@@ -3513,12 +3513,41 @@ bool LLParser::ParseMDNamespace(MDNode *&Result, bool IsDistinct) {
return false;
}
+/// ParseMDTemplateTypeParameter:
+/// ::= !MDTemplateTypeParameter(scope: !0, name: "Ty", type: !1)
bool LLParser::ParseMDTemplateTypeParameter(MDNode *&Result, bool IsDistinct) {
- return TokError("unimplemented parser");
+#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
+ REQUIRED(scope, MDField, ); \
+ OPTIONAL(name, MDStringField, ); \
+ REQUIRED(type, MDField, );
+ PARSE_MD_FIELDS();
+#undef VISIT_MD_FIELDS
+
+ Result = GET_OR_DISTINCT(MDTemplateTypeParameter,
+ (Context, scope.Val, name.Val, type.Val));
+ return false;
}
+
+/// ParseMDTemplateValueParameter:
+/// ::= !MDTemplateValueParameter(tag: DW_TAG_template_value_parameter,
+/// scope: !0, name: "V", type: !1,
+/// value: i32 7)
bool LLParser::ParseMDTemplateValueParameter(MDNode *&Result, bool IsDistinct) {
- return TokError("unimplemented parser");
+#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
+ REQUIRED(tag, DwarfTagField, ); \
+ REQUIRED(scope, MDField, ); \
+ OPTIONAL(name, MDStringField, ); \
+ REQUIRED(type, MDField, ); \
+ REQUIRED(value, MDField, );
+ PARSE_MD_FIELDS();
+#undef VISIT_MD_FIELDS
+
+ Result = GET_OR_DISTINCT(
+ MDTemplateValueParameter,
+ (Context, tag.Val, scope.Val, name.Val, type.Val, value.Val));
+ return false;
}
+
bool LLParser::ParseMDGlobalVariable(MDNode *&Result, bool IsDistinct) {
return TokError("unimplemented parser");
}
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index d0606788d44..9731e8c0e03 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -1502,6 +1502,29 @@ std::error_code BitcodeReader::ParseMetadata() {
NextMDValueNo++);
break;
}
+ case bitc::METADATA_TEMPLATE_TYPE: {
+ if (Record.size() != 4)
+ return Error("Invalid record");
+
+ MDValueList.AssignValue(
+ GET_OR_DISTINCT(MDTemplateTypeParameter, Record[0],
+ (Context, getMDOrNull(Record[1]),
+ getMDString(Record[2]), getMDOrNull(Record[3]))),
+ NextMDValueNo++);
+ break;
+ }
+ case bitc::METADATA_TEMPLATE_VALUE: {
+ if (Record.size() != 6)
+ return Error("Invalid record");
+
+ MDValueList.AssignValue(
+ GET_OR_DISTINCT(MDTemplateValueParameter, Record[0],
+ (Context, Record[1], getMDOrNull(Record[2]),
+ getMDString(Record[3]), getMDOrNull(Record[4]),
+ getMDOrNull(Record[5]))),
+ NextMDValueNo++);
+ break;
+ }
case bitc::METADATA_STRING: {
std::string String(Record.begin(), Record.end());
llvm::UpgradeMDStringConstant(String);
diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
index aa774ba38e0..b1b61e717e6 100644
--- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -1021,20 +1021,36 @@ static void WriteMDNamespace(const MDNamespace *N, const ValueEnumerator &VE,
Record.clear();
}
-static void WriteMDTemplateTypeParameter(const MDTemplateTypeParameter *,
- const ValueEnumerator &,
- BitstreamWriter &,
- SmallVectorImpl<uint64_t> &,
- unsigned) {
- llvm_unreachable("write not implemented");
+static void WriteMDTemplateTypeParameter(const MDTemplateTypeParameter *N,
+ const ValueEnumerator &VE,
+ BitstreamWriter &Stream,
+ SmallVectorImpl<uint64_t> &Record,
+ unsigned Abbrev) {
+ Record.push_back(N->isDistinct());
+ Record.push_back(VE.getMetadataOrNullID(N->getScope()));
+ Record.push_back(VE.getMetadataOrNullID(N->getRawName()));
+ Record.push_back(VE.getMetadataOrNullID(N->getType()));
+
+ Stream.EmitRecord(bitc::METADATA_TEMPLATE_TYPE, Record, Abbrev);
+ Record.clear();
}
-static void WriteMDTemplateValueParameter(const MDTemplateValueParameter *,
- const ValueEnumerator &,
- BitstreamWriter &,
- SmallVectorImpl<uint64_t> &,
- unsigned) {
- llvm_unreachable("write not implemented");
+
+static void WriteMDTemplateValueParameter(const MDTemplateValueParameter *N,
+ const ValueEnumerator &VE,
+ BitstreamWriter &Stream,
+ SmallVectorImpl<uint64_t> &Record,
+ unsigned Abbrev) {
+ Record.push_back(N->isDistinct());
+ Record.push_back(N->getTag());
+ Record.push_back(VE.getMetadataOrNullID(N->getScope()));
+ Record.push_back(VE.getMetadataOrNullID(N->getRawName()));
+ Record.push_back(VE.getMetadataOrNullID(N->getType()));
+ Record.push_back(VE.getMetadataOrNullID(N->getValue()));
+
+ Stream.EmitRecord(bitc::METADATA_TEMPLATE_VALUE, Record, Abbrev);
+ Record.clear();
}
+
static void WriteMDGlobalVariable(const MDGlobalVariable *,
const ValueEnumerator &, BitstreamWriter &,
SmallVectorImpl<uint64_t> &, unsigned) {
diff --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp
index 29de2f291d2..4e7bc8ded0c 100644
--- a/llvm/lib/IR/AsmWriter.cpp
+++ b/llvm/lib/IR/AsmWriter.cpp
@@ -1678,18 +1678,39 @@ static void writeMDNamespace(raw_ostream &Out, const MDNamespace *N,
Out << ")";
}
-static void writeMDTemplateTypeParameter(raw_ostream &,
- const MDTemplateTypeParameter *,
- TypePrinting *, SlotTracker *,
- const Module *) {
- llvm_unreachable("write not implemented");
+static void writeMDTemplateTypeParameter(raw_ostream &Out,
+ const MDTemplateTypeParameter *N,
+ TypePrinting *TypePrinter,
+ SlotTracker *Machine,
+ const Module *Context) {
+ Out << "!MDTemplateTypeParameter(";
+ FieldSeparator FS;
+ Out << FS << "scope: ";
+ writeMetadataAsOperand(Out, N->getScope(), TypePrinter, Machine, Context);
+ Out << FS << "name: \"" << N->getName() << "\"";
+ Out << FS << "type: ";
+ writeMetadataAsOperand(Out, N->getType(), TypePrinter, Machine, Context);
+ Out << ")";
}
-static void writeMDTemplateValueParameter(raw_ostream &,
- const MDTemplateValueParameter *,
- TypePrinting *, SlotTracker *,
- const Module *) {
- llvm_unreachable("write not implemented");
+
+static void writeMDTemplateValueParameter(raw_ostream &Out,
+ const MDTemplateValueParameter *N,
+ TypePrinting *TypePrinter,
+ SlotTracker *Machine,
+ const Module *Context) {
+ Out << "!MDTemplateValueParameter(";
+ FieldSeparator FS;
+ writeTag(Out, FS, N);
+ Out << FS << "scope: ";
+ writeMetadataAsOperand(Out, N->getScope(), TypePrinter, Machine, Context);
+ Out << FS << "name: \"" << N->getName() << "\"";
+ Out << FS << "type: ";
+ writeMetadataAsOperand(Out, N->getType(), TypePrinter, Machine, Context);
+ Out << FS << "value: ";
+ writeMetadataAsOperand(Out, N->getValue(), TypePrinter, Machine, Context);
+ Out << ")";
}
+
static void writeMDGlobalVariable(raw_ostream &, const MDGlobalVariable *,
TypePrinting *, SlotTracker *,
const Module *) {
OpenPOWER on IntegriCloud