diff options
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/AsmParser/LLParser.cpp | 15 | ||||
-rw-r--r-- | llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 12 | ||||
-rw-r--r-- | llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 17 | ||||
-rw-r--r-- | llvm/lib/IR/AsmWriter.cpp | 20 |
4 files changed, 56 insertions, 8 deletions
diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp index 90a680818f9..be1db2233d2 100644 --- a/llvm/lib/AsmParser/LLParser.cpp +++ b/llvm/lib/AsmParser/LLParser.cpp @@ -3497,9 +3497,22 @@ bool LLParser::ParseMDLexicalBlockFile(MDNode *&Result, bool IsDistinct) { return false; } +/// ParseMDNamespace: +/// ::= !MDNamespace(scope: !0, file: !2, name: "SomeNamespace", line: 9) bool LLParser::ParseMDNamespace(MDNode *&Result, bool IsDistinct) { - return TokError("unimplemented parser"); +#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \ + REQUIRED(scope, MDField, ); \ + OPTIONAL(file, MDField, ); \ + OPTIONAL(name, MDStringField, ); \ + OPTIONAL(line, LineField, ); + PARSE_MD_FIELDS(); +#undef VISIT_MD_FIELDS + + Result = GET_OR_DISTINCT(MDNamespace, + (Context, scope.Val, file.Val, name.Val, line.Val)); + return false; } + bool LLParser::ParseMDTemplateTypeParameter(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 fa139d74fba..d0606788d44 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -1490,6 +1490,18 @@ std::error_code BitcodeReader::ParseMetadata() { NextMDValueNo++); break; } + case bitc::METADATA_NAMESPACE: { + if (Record.size() != 5) + return Error("Invalid record"); + + MDValueList.AssignValue( + GET_OR_DISTINCT(MDNamespace, Record[0], + (Context, getMDOrNull(Record[1]), + getMDOrNull(Record[2]), getMDString(Record[3]), + Record[4])), + 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 4643a7236a4..aa774ba38e0 100644 --- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -1007,11 +1007,20 @@ static void WriteMDLexicalBlockFile(const MDLexicalBlockFile *N, Record.clear(); } -static void WriteMDNamespace(const MDNamespace *, const ValueEnumerator &, - BitstreamWriter &, SmallVectorImpl<uint64_t> &, - unsigned) { - llvm_unreachable("write not implemented"); +static void WriteMDNamespace(const MDNamespace *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->getFile())); + Record.push_back(VE.getMetadataOrNullID(N->getRawName())); + Record.push_back(N->getLine()); + + Stream.EmitRecord(bitc::METADATA_NAMESPACE, Record, Abbrev); + Record.clear(); } + static void WriteMDTemplateTypeParameter(const MDTemplateTypeParameter *, const ValueEnumerator &, BitstreamWriter &, diff --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp index 560f71f7338..29de2f291d2 100644 --- a/llvm/lib/IR/AsmWriter.cpp +++ b/llvm/lib/IR/AsmWriter.cpp @@ -1660,10 +1660,24 @@ static void writeMDLexicalBlockFile(raw_ostream &Out, Out << ")"; } -static void writeMDNamespace(raw_ostream &, const MDNamespace *, TypePrinting *, - SlotTracker *, const Module *) { - llvm_unreachable("write not implemented"); +static void writeMDNamespace(raw_ostream &Out, const MDNamespace *N, + TypePrinting *TypePrinter, SlotTracker *Machine, + const Module *Context) { + Out << "!MDNamespace("; + FieldSeparator FS; + Out << FS << "scope: "; + writeMetadataAsOperand(Out, N->getScope(), TypePrinter, Machine, Context); + if (N->getFile()) { + Out << FS << "file: "; + writeMetadataAsOperand(Out, N->getFile(), TypePrinter, Machine, Context); + } + if (!N->getName().empty()) + Out << FS << "name: \"" << N->getName() << "\""; + if (N->getLine()) + Out << FS << "line: " << N->getLine(); + Out << ")"; } + static void writeMDTemplateTypeParameter(raw_ostream &, const MDTemplateTypeParameter *, TypePrinting *, SlotTracker *, |