diff options
author | Bill Wendling <isanbard@gmail.com> | 2013-04-17 23:35:59 +0000 |
---|---|---|
committer | Bill Wendling <isanbard@gmail.com> | 2013-04-17 23:35:59 +0000 |
commit | b1ac6e617291e2a628bc460933bde97c73466cb0 (patch) | |
tree | c4207d2f1e88610f79ccf1bd5e815607d34ee7eb /lib/IR/AsmWriter.cpp | |
parent | f92bf40cedf2204211b96d27e89e0e2f0170b78d (diff) |
Add an option `-enable-old-style-attr-syntax' to print out function attributes in the "old" style.
It's sometimes beneficial to emit a testcase with the old style attribute
syntax. Allow someone to do this.
<rdar://problem/13563209>
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@179735 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/IR/AsmWriter.cpp')
-rw-r--r-- | lib/IR/AsmWriter.cpp | 42 |
1 files changed, 21 insertions, 21 deletions
diff --git a/lib/IR/AsmWriter.cpp b/lib/IR/AsmWriter.cpp index 7761127d55..6b0bfd5918 100644 --- a/lib/IR/AsmWriter.cpp +++ b/lib/IR/AsmWriter.cpp @@ -33,6 +33,7 @@ #include "llvm/IR/TypeFinder.h" #include "llvm/IR/ValueSymbolTable.h" #include "llvm/Support/CFG.h" +#include "llvm/Support/CommandLine.h" #include "llvm/Support/Debug.h" #include "llvm/Support/Dwarf.h" #include "llvm/Support/ErrorHandling.h" @@ -42,6 +43,12 @@ #include <cctype> using namespace llvm; +static cl::opt<bool> +OldStyleAttrSyntax("enable-old-style-attr-syntax", + cl::desc("Output attributes on functions rather than in attribute groups"), + cl::Hidden, + cl::init(false)); + // Make virtual table appear in this compilation unit. AssemblyAnnotationWriter::~AssemblyAnnotationWriter() {} @@ -1378,7 +1385,7 @@ void AssemblyWriter::printModule(const Module *M) { printFunction(I); // Output all attribute groups. - if (!Machine.as_empty()) { + if (!OldStyleAttrSyntax && !Machine.as_empty()) { Out << '\n'; writeAllAttributeGroups(); } @@ -1606,24 +1613,9 @@ void AssemblyWriter::printFunction(const Function *F) { Out << "; Materializable\n"; const AttributeSet &Attrs = F->getAttributes(); - if (Attrs.hasAttributes(AttributeSet::FunctionIndex)) { + if (!OldStyleAttrSyntax && Attrs.hasAttributes(AttributeSet::FunctionIndex)) { AttributeSet AS = Attrs.getFnAttributes(); - std::string AttrStr; - - unsigned Idx = 0; - for (unsigned E = AS.getNumSlots(); Idx != E; ++Idx) - if (AS.getSlotIndex(Idx) == AttributeSet::FunctionIndex) - break; - - for (AttributeSet::iterator I = AS.begin(Idx), E = AS.end(Idx); - I != E; ++I) { - Attribute Attr = *I; - if (!Attr.isStringAttribute()) { - if (!AttrStr.empty()) AttrStr += ' '; - AttrStr += Attr.getAsString(); - } - } - + std::string AttrStr = AS.getAsString(AttributeSet::FunctionIndex, true); if (!AttrStr.empty()) Out << "; Function Attrs: " << AttrStr << '\n'; } @@ -1685,8 +1677,15 @@ void AssemblyWriter::printFunction(const Function *F) { Out << ')'; if (F->hasUnnamedAddr()) Out << " unnamed_addr"; - if (Attrs.hasAttributes(AttributeSet::FunctionIndex)) - Out << " #" << Machine.getAttributeGroupSlot(Attrs.getFnAttributes()); + if (!OldStyleAttrSyntax) { + if (Attrs.hasAttributes(AttributeSet::FunctionIndex)) + Out << " #" << Machine.getAttributeGroupSlot(Attrs.getFnAttributes()); + } else { + AttributeSet AS = Attrs.getFnAttributes(); + std::string AttrStr = AS.getAsString(AttributeSet::FunctionIndex, true); + if (!AttrStr.empty()) + Out << ' ' << AttrStr; + } if (F->hasSection()) { Out << " section \""; PrintEscapedString(F->getSection(), Out); @@ -2157,7 +2156,8 @@ void AssemblyWriter::writeAllAttributeGroups() { for (std::vector<std::pair<AttributeSet, unsigned> >::iterator I = asVec.begin(), E = asVec.end(); I != E; ++I) Out << "attributes #" << I->second << " = { " - << I->first.getAsString(AttributeSet::FunctionIndex, true) << " }\n"; + << I->first.getAsString(AttributeSet::FunctionIndex, false, true) + << " }\n"; } //===----------------------------------------------------------------------===// |