forked from OSchip/llvm-project
unify two copies of the NamedMDNode printing code.
llvm-svn: 92327
This commit is contained in:
parent
b9196679f9
commit
2c48c64821
|
@ -634,8 +634,8 @@ void SlotTracker::processModule() {
|
||||||
E = TheModule->named_metadata_end(); I != E; ++I) {
|
E = TheModule->named_metadata_end(); I != E; ++I) {
|
||||||
const NamedMDNode *NMD = I;
|
const NamedMDNode *NMD = I;
|
||||||
for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) {
|
for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) {
|
||||||
MDNode *MD = dyn_cast_or_null<MDNode>(NMD->getOperand(i));
|
// FIXME: Change accessor to be type safe.
|
||||||
if (MD)
|
if (MDNode *MD = cast_or_null<MDNode>(NMD->getOperand(i)))
|
||||||
CreateMetadataSlot(MD);
|
CreateMetadataSlot(MD);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1312,6 +1312,8 @@ public:
|
||||||
M->getMDKindNames(MDNames);
|
M->getMDKindNames(MDNames);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void printNamedMDNode(const NamedMDNode *NMD);
|
||||||
|
|
||||||
void write(const Module *M) { printModule(M); }
|
void write(const Module *M) { printModule(M); }
|
||||||
|
|
||||||
void write(const GlobalValue *G) {
|
void write(const GlobalValue *G) {
|
||||||
|
@ -1446,23 +1448,29 @@ void AssemblyWriter::printModule(const Module *M) {
|
||||||
|
|
||||||
// Output named metadata.
|
// Output named metadata.
|
||||||
if (!M->named_metadata_empty()) Out << '\n';
|
if (!M->named_metadata_empty()) Out << '\n';
|
||||||
|
|
||||||
for (Module::const_named_metadata_iterator I = M->named_metadata_begin(),
|
for (Module::const_named_metadata_iterator I = M->named_metadata_begin(),
|
||||||
E = M->named_metadata_end(); I != E; ++I) {
|
E = M->named_metadata_end(); I != E; ++I)
|
||||||
const NamedMDNode *NMD = I;
|
printNamedMDNode(I);
|
||||||
Out << "!" << NMD->getName() << " = !{";
|
|
||||||
for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) {
|
|
||||||
if (i) Out << ", ";
|
|
||||||
MDNode *MD = dyn_cast_or_null<MDNode>(NMD->getOperand(i));
|
|
||||||
Out << '!' << Machine.getMetadataSlot(MD);
|
|
||||||
}
|
|
||||||
Out << "}\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
// Output metadata.
|
// Output metadata.
|
||||||
if (!Machine.mdnEmpty()) Out << '\n';
|
if (!Machine.mdnEmpty()) Out << '\n';
|
||||||
WriteMDNodes(Out, TypePrinter, Machine);
|
WriteMDNodes(Out, TypePrinter, Machine);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AssemblyWriter::printNamedMDNode(const NamedMDNode *NMD) {
|
||||||
|
Out << "!" << NMD->getName() << " = !{";
|
||||||
|
for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) {
|
||||||
|
if (i) Out << ", ";
|
||||||
|
// FIXME: Change accessor to be typesafe.
|
||||||
|
// FIXME: This doesn't handle null??
|
||||||
|
MDNode *MD = cast_or_null<MDNode>(NMD->getOperand(i));
|
||||||
|
Out << '!' << Machine.getMetadataSlot(MD);
|
||||||
|
}
|
||||||
|
Out << "}\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void PrintLinkage(GlobalValue::LinkageTypes LT,
|
static void PrintLinkage(GlobalValue::LinkageTypes LT,
|
||||||
formatted_raw_ostream &Out) {
|
formatted_raw_ostream &Out) {
|
||||||
switch (LT) {
|
switch (LT) {
|
||||||
|
@ -2100,19 +2108,8 @@ void Value::print(raw_ostream &ROS, AssemblyAnnotationWriter *AAW) const {
|
||||||
WriteMDNodes(OS, TypePrinter, SlotTable);
|
WriteMDNodes(OS, TypePrinter, SlotTable);
|
||||||
} else if (const NamedMDNode *N = dyn_cast<NamedMDNode>(this)) {
|
} else if (const NamedMDNode *N = dyn_cast<NamedMDNode>(this)) {
|
||||||
SlotTracker SlotTable(N->getParent());
|
SlotTracker SlotTable(N->getParent());
|
||||||
TypePrinting TypePrinter;
|
AssemblyWriter W(OS, SlotTable, N->getParent(), AAW);
|
||||||
SlotTable.initialize();
|
W.printNamedMDNode(N);
|
||||||
OS << "!" << N->getName() << " = !{";
|
|
||||||
for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) {
|
|
||||||
if (i) OS << ", ";
|
|
||||||
MDNode *MD = dyn_cast_or_null<MDNode>(N->getOperand(i));
|
|
||||||
if (MD)
|
|
||||||
OS << '!' << SlotTable.getMetadataSlot(MD);
|
|
||||||
else
|
|
||||||
OS << "null";
|
|
||||||
}
|
|
||||||
OS << "}\n";
|
|
||||||
WriteMDNodes(OS, TypePrinter, SlotTable);
|
|
||||||
} else if (const Constant *C = dyn_cast<Constant>(this)) {
|
} else if (const Constant *C = dyn_cast<Constant>(this)) {
|
||||||
TypePrinting TypePrinter;
|
TypePrinting TypePrinter;
|
||||||
TypePrinter.print(C->getType(), OS);
|
TypePrinter.print(C->getType(), OS);
|
||||||
|
|
Loading…
Reference in New Issue