1 //===-- llvm/IR/AsmWriter.h - Printing LLVM IR as an assembly file - C++ --===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This files defines the interface for the AssemblyWriter class used to print
11 // LLVM IR and various helper classes that are used in printing.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_LIB_IR_ASMWRITER_H
16 #define LLVM_LIB_IR_ASMWRITER_H
18 #include "llvm/ADT/DenseMap.h"
19 #include "llvm/ADT/SetVector.h"
20 #include "llvm/IR/Attributes.h"
21 #include "llvm/IR/Instructions.h"
22 #include "llvm/IR/TypeFinder.h"
23 #include "llvm/Support/FormattedStream.h"
36 /// Create a new SlotTracker for a Module
37 SlotTracker *createSlotTracker(const Module *M);
39 //===----------------------------------------------------------------------===//
40 // TypePrinting Class: Type printing machinery
41 //===----------------------------------------------------------------------===//
44 TypePrinting(const TypePrinting &) LLVM_DELETED_FUNCTION;
45 void operator=(const TypePrinting&) LLVM_DELETED_FUNCTION;
48 /// NamedTypes - The named types that are used by the current module.
49 TypeFinder NamedTypes;
51 /// NumberedTypes - The numbered types, along with their value.
52 DenseMap<StructType*, unsigned> NumberedTypes;
58 void incorporateTypes(const Module &M);
60 void print(Type *Ty, raw_ostream &OS);
62 void printStructBody(StructType *Ty, raw_ostream &OS);
65 class AssemblyWriter {
67 formatted_raw_ostream &Out;
68 const Module *TheModule;
71 std::unique_ptr<SlotTracker> ModuleSlotTracker;
73 TypePrinting TypePrinter;
74 AssemblyAnnotationWriter *AnnotationWriter;
75 SetVector<const Comdat *> Comdats;
78 /// Construct an AssemblyWriter with an external SlotTracker
79 AssemblyWriter(formatted_raw_ostream &o, SlotTracker &Mac,
80 const Module *M, AssemblyAnnotationWriter *AAW);
82 /// Construct an AssemblyWriter with an internally allocated SlotTracker
83 AssemblyWriter(formatted_raw_ostream &o, const Module *M,
84 AssemblyAnnotationWriter *AAW);
86 virtual ~AssemblyWriter();
88 void printMDNodeBody(const MDNode *MD);
89 void printNamedMDNode(const NamedMDNode *NMD);
91 void printModule(const Module *M);
93 void writeOperand(const Value *Op, bool PrintType);
94 void writeParamOperand(const Value *Operand, AttributeSet Attrs,unsigned Idx);
95 void writeAtomic(AtomicOrdering Ordering, SynchronizationScope SynchScope);
96 void writeAtomicCmpXchg(AtomicOrdering SuccessOrdering,
97 AtomicOrdering FailureOrdering,
98 SynchronizationScope SynchScope);
100 void writeAllMDNodes();
101 void writeMDNode(unsigned Slot, const MDNode *Node);
102 void writeAllAttributeGroups();
104 void printTypeIdentities();
105 void printGlobal(const GlobalVariable *GV);
106 void printAlias(const GlobalAlias *GV);
107 void printComdat(const Comdat *C);
108 void printFunction(const Function *F);
109 void printArgument(const Argument *FA, AttributeSet Attrs, unsigned Idx);
110 void printBasicBlock(const BasicBlock *BB);
111 void printInstructionLine(const Instruction &I);
112 void printInstruction(const Instruction &I);
117 // printInfoComment - Print a little comment after the instruction indicating
118 // which slot it occupies.
119 void printInfoComment(const Value &V);