From 9e2af6ed0b0e0df32ef5b1bf23df8eccd8c8abe9 Mon Sep 17 00:00:00 2001 From: Devang Patel Date: Mon, 28 Sep 2009 20:56:00 +0000 Subject: [PATCH] Do not hardcode metadata names. llvm-svn: 83010 --- lib/VMCore/AsmWriter.cpp | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/lib/VMCore/AsmWriter.cpp b/lib/VMCore/AsmWriter.cpp index 62856b3aca9..b8e5ec02657 100644 --- a/lib/VMCore/AsmWriter.cpp +++ b/lib/VMCore/AsmWriter.cpp @@ -1266,6 +1266,7 @@ class AssemblyWriter { TypePrinting TypePrinter; AssemblyAnnotationWriter *AnnotationWriter; std::vector NumberedTypes; + DenseMap MDNames; public: inline AssemblyWriter(formatted_raw_ostream &o, SlotTracker &Mac, @@ -1273,6 +1274,14 @@ public: AssemblyAnnotationWriter *AAW) : Out(o), Machine(Mac), TheModule(M), AnnotationWriter(AAW) { AddModuleTypesToPrinter(TypePrinter, NumberedTypes, M); + // FIXME: Provide MDPrinter + Metadata &TheMetadata = M->getContext().getMetadata(); + const StringMap *Names = TheMetadata.getHandlerNames(); + for (StringMapConstIterator I = Names->begin(), + E = Names->end(); I != E; ++I) { + const StringMapEntry &Entry = *I; + MDNames[I->second] = Entry.getKeyData(); + } } void write(const Module *M) { printModule(M); } @@ -1991,11 +2000,16 @@ void AssemblyWriter::printInstruction(const Instruction &I) { Out << ", align " << cast(I).getAlignment(); } - // Print DebugInfo + // Print Metadata info Metadata &TheMetadata = I.getContext().getMetadata(); - unsigned MDDbgKind = TheMetadata.getMDKind("dbg"); - if (const MDNode *Dbg = TheMetadata.getMD(MDDbgKind, &I)) - Out << ", dbg !" << Machine.getMetadataSlot(Dbg); + const Metadata::MDMapTy *MDMap = TheMetadata.getMDs(&I); + if (MDMap) + for (Metadata::MDMapTy::const_iterator MI = MDMap->begin(), + ME = MDMap->end(); MI != ME; ++MI) + if (const MDNode *MD = dyn_cast_or_null(MI->second)) + Out << ", " << MDNames[MI->first] + << " !" << Machine.getMetadataSlot(MD); + printInfoComment(I); }