-static void WriteMDNodeComment(const MDNode *Node,
- formatted_raw_ostream &Out) {
- if (Node->getNumElements() < 1)
- return;
- ConstantInt *CI = dyn_cast_or_null<ConstantInt>(Node->getElement(0));
- if (!CI) return;
- unsigned Val = CI->getZExtValue();
- unsigned Tag = Val & ~LLVMDebugVersionMask;
- if (Val >= LLVMDebugVersion) {
- if (Tag == dwarf::DW_TAG_auto_variable)
- Out << "; [ DW_TAG_auto_variable ]";
- else if (Tag == dwarf::DW_TAG_arg_variable)
- Out << "; [ DW_TAG_arg_variable ]";
- else if (Tag == dwarf::DW_TAG_return_variable)
- Out << "; [ DW_TAG_return_variable ]";
- else if (Tag == dwarf::DW_TAG_vector_type)
- Out << "; [ DW_TAG_vector_type ]";
- else if (Tag == dwarf::DW_TAG_user_base)
- Out << "; [ DW_TAG_user_base ]";
- else
- Out << "; [" << dwarf::TagString(Tag) << " ]";
- }
-}
-
-static void WriteMDNodes(formatted_raw_ostream &Out, TypePrinting &TypePrinter,
- SlotTracker &Machine) {
- SmallVector<const MDNode *, 16> Nodes;
- Nodes.resize(Machine.mdnSize());
- for (SlotTracker::ValueMap::iterator I =
- Machine.mdnBegin(), E = Machine.mdnEnd(); I != E; ++I)
- Nodes[I->second] = cast<MDNode>(I->first);
-
- for (unsigned i = 0, e = Nodes.size(); i != e; ++i) {
- Out << '!' << i << " = metadata ";
- const MDNode *Node = Nodes[i];
- Out << "!{";
- for (unsigned mi = 0, me = Node->getNumElements(); mi != me; ++mi) {
- const Value *V = Node->getElement(mi);
- if (!V)
- Out << "null";
- else if (const MDNode *N = dyn_cast<MDNode>(V)) {
- Out << "metadata ";
- Out << '!' << Machine.getMetadataSlot(N);
- }
- else {
- TypePrinter.print(V->getType(), Out);
- Out << ' ';
- WriteAsOperandInternal(Out, Node->getElement(mi),
- &TypePrinter, &Machine);
- }
- if (mi + 1 != me)
- Out << ", ";
- }
-
- Out << "}";
- WriteMDNodeComment(Node, Out);
- Out << "\n";
- }
-}