33
35
#include "llvm/IR/TypeFinder.h"
34
36
#include "llvm/IR/ValueSymbolTable.h"
35
37
#include "llvm/Support/CFG.h"
36
#include "llvm/Support/CommandLine.h"
37
38
#include "llvm/Support/Debug.h"
38
39
#include "llvm/Support/Dwarf.h"
39
40
#include "llvm/Support/ErrorHandling.h"
40
41
#include "llvm/Support/FormattedStream.h"
41
42
#include "llvm/Support/MathExtras.h"
42
44
#include <algorithm>
44
46
using namespace llvm;
47
OldStyleAttrSyntax("enable-old-style-attr-syntax",
48
cl::desc("Output attributes on functions rather than in attribute groups"),
52
48
// Make virtual table appear in this compilation unit.
53
49
AssemblyAnnotationWriter::~AssemblyAnnotationWriter() {}
160
156
isa<GlobalValue>(V) ? GlobalPrefix : LocalPrefix);
163
//===----------------------------------------------------------------------===//
164
// TypePrinting Class: Type printing machinery
165
//===----------------------------------------------------------------------===//
167
/// TypePrinting - Type printing machinery.
170
TypePrinting(const TypePrinting &) LLVM_DELETED_FUNCTION;
171
void operator=(const TypePrinting&) LLVM_DELETED_FUNCTION;
174
/// NamedTypes - The named types that are used by the current module.
175
TypeFinder NamedTypes;
177
/// NumberedTypes - The numbered types, along with their value.
178
DenseMap<StructType*, unsigned> NumberedTypes;
184
void incorporateTypes(const Module &M);
186
void print(Type *Ty, raw_ostream &OS);
188
void printStructBody(StructType *Ty, raw_ostream &OS);
190
} // end anonymous namespace.
193
162
void TypePrinting::incorporateTypes(const Module &M) {
194
163
NamedTypes.run(M, false);
1207
1172
Out << "<badref>";
1210
void llvm::WriteAsOperand(raw_ostream &Out, const Value *V,
1211
bool PrintType, const Module *Context) {
1175
void WriteAsOperand(raw_ostream &Out, const Value *V,
1176
bool PrintType, const Module *Context) {
1213
1178
// Fast path: Don't construct and populate a TypePrinting object if we
1214
1179
// won't be needing any types printed.
1232
1197
WriteAsOperandInternal(Out, V, &TypePrinter, 0, Context);
1237
class AssemblyWriter {
1238
formatted_raw_ostream &Out;
1239
SlotTracker &Machine;
1240
const Module *TheModule;
1241
TypePrinting TypePrinter;
1242
AssemblyAnnotationWriter *AnnotationWriter;
1245
inline AssemblyWriter(formatted_raw_ostream &o, SlotTracker &Mac,
1247
AssemblyAnnotationWriter *AAW)
1248
: Out(o), Machine(Mac), TheModule(M), AnnotationWriter(AAW) {
1250
TypePrinter.incorporateTypes(*M);
1253
void printMDNodeBody(const MDNode *MD);
1254
void printNamedMDNode(const NamedMDNode *NMD);
1256
void printModule(const Module *M);
1258
void writeOperand(const Value *Op, bool PrintType);
1259
void writeParamOperand(const Value *Operand, AttributeSet Attrs,unsigned Idx);
1260
void writeAtomic(AtomicOrdering Ordering, SynchronizationScope SynchScope);
1262
void writeAllMDNodes();
1263
void writeAllAttributeGroups();
1265
void printTypeIdentities();
1266
void printGlobal(const GlobalVariable *GV);
1267
void printAlias(const GlobalAlias *GV);
1268
void printFunction(const Function *F);
1269
void printArgument(const Argument *FA, AttributeSet Attrs, unsigned Idx);
1270
void printBasicBlock(const BasicBlock *BB);
1271
void printInstruction(const Instruction &I);
1274
// printInfoComment - Print a little comment after the instruction indicating
1275
// which slot it occupies.
1276
void printInfoComment(const Value &V);
1278
} // end of anonymous namespace
1200
void AssemblyWriter::init() {
1202
TypePrinter.incorporateTypes(*TheModule);
1206
AssemblyWriter::AssemblyWriter(formatted_raw_ostream &o, SlotTracker &Mac,
1208
AssemblyAnnotationWriter *AAW)
1209
: Out(o), TheModule(M), Machine(Mac), AnnotationWriter(AAW) {
1213
AssemblyWriter::AssemblyWriter(formatted_raw_ostream &o, const Module *M,
1214
AssemblyAnnotationWriter *AAW)
1215
: Out(o), TheModule(M), ModuleSlotTracker(createSlotTracker(M)),
1216
Machine(*ModuleSlotTracker), AnnotationWriter(AAW) {
1220
AssemblyWriter::~AssemblyWriter() { }
1280
1222
void AssemblyWriter::writeOperand(const Value *Operand, bool PrintType) {
1281
1223
if (Operand == 0) {
1613
1555
Out << "; Materializable\n";
1615
1557
const AttributeSet &Attrs = F->getAttributes();
1616
if (!OldStyleAttrSyntax && Attrs.hasAttributes(AttributeSet::FunctionIndex)) {
1558
if (Attrs.hasAttributes(AttributeSet::FunctionIndex)) {
1617
1559
AttributeSet AS = Attrs.getFnAttributes();
1618
std::string AttrStr = AS.getAsString(AttributeSet::FunctionIndex, false);
1560
std::string AttrStr;
1563
for (unsigned E = AS.getNumSlots(); Idx != E; ++Idx)
1564
if (AS.getSlotIndex(Idx) == AttributeSet::FunctionIndex)
1567
for (AttributeSet::iterator I = AS.begin(Idx), E = AS.end(Idx);
1569
Attribute Attr = *I;
1570
if (!Attr.isStringAttribute()) {
1571
if (!AttrStr.empty()) AttrStr += ' ';
1572
AttrStr += Attr.getAsString();
1619
1576
if (!AttrStr.empty())
1620
1577
Out << "; Function Attrs: " << AttrStr << '\n';
1678
1635
if (F->hasUnnamedAddr())
1679
1636
Out << " unnamed_addr";
1680
if (!OldStyleAttrSyntax) {
1681
if (Attrs.hasAttributes(AttributeSet::FunctionIndex))
1682
Out << " #" << Machine.getAttributeGroupSlot(Attrs.getFnAttributes());
1684
AttributeSet AS = Attrs.getFnAttributes();
1685
std::string AttrStr = AS.getAsString(AttributeSet::FunctionIndex, false);
1686
if (!AttrStr.empty())
1687
Out << ' ' << AttrStr;
1637
if (Attrs.hasAttributes(AttributeSet::FunctionIndex))
1638
Out << " #" << Machine.getAttributeGroupSlot(Attrs.getFnAttributes());
1689
1639
if (F->hasSection()) {
1690
1640
Out << " section \"";
1691
1641
PrintEscapedString(F->getSection(), Out);
1772
1722
// Output all of the instructions in the basic block...
1773
1723
for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I != E; ++I) {
1774
printInstruction(*I);
1724
printInstructionLine(*I);
1778
1727
if (AnnotationWriter) AnnotationWriter->emitBasicBlockEndAnnot(BB, Out);
1730
/// printInstructionLine - Print an instruction and a newline character.
1731
void AssemblyWriter::printInstructionLine(const Instruction &I) {
1732
printInstruction(I);
1781
1736
/// printInfoComment - Print a little comment after the instruction indicating
1782
1737
/// which slot it occupies.
2092
2047
unsigned Kind = InstMD[i].first;
2093
2048
if (Kind < MDNames.size()) {
2094
2049
Out << ", !" << MDNames[Kind];
2096
Out << ", !<unknown kind #" << Kind << ">";
2051
Out << ", !<unknown kind #" << Kind << ">";
2099
2054
WriteAsOperandInternal(Out, InstMD[i].second, &TypePrinter, &Machine,
2156
2115
for (std::vector<std::pair<AttributeSet, unsigned> >::iterator
2157
2116
I = asVec.begin(), E = asVec.end(); I != E; ++I)
2158
2117
Out << "attributes #" << I->second << " = { "
2159
<< I->first.getAsString(AttributeSet::FunctionIndex, true, true)
2118
<< I->first.getAsString(AttributeSet::FunctionIndex, true) << " }\n";
2163
2123
//===----------------------------------------------------------------------===//
2164
2124
// External Interface declarations
2165
2125
//===----------------------------------------------------------------------===//