1 //===-- llvm/IR/AsmWriter.h - Printing LLVM IR as an assembly file - C++ --===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 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. 12 // 13 //===----------------------------------------------------------------------===// 14 15 #ifndef LLVM_LIB_IR_ASMWRITER_H 16 #define LLVM_LIB_IR_ASMWRITER_H 17 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/IR/UseListOrder.h" 24 #include "llvm/Support/FormattedStream.h" 25 26 namespace llvm { 27 28 class BasicBlock; 29 class Function; 30 class GlobalValue; 31 class Comdat; 32 class Module; 33 class NamedMDNode; 34 class Value; 35 class SlotTracker; 36 37 /// Create a new SlotTracker for a Module 38 SlotTracker *createSlotTracker(const Module *M); 39 40 //===----------------------------------------------------------------------===// 41 // TypePrinting Class: Type printing machinery 42 //===----------------------------------------------------------------------===// 43 44 class TypePrinting { 45 TypePrinting(const TypePrinting &) LLVM_DELETED_FUNCTION; 46 void operator=(const TypePrinting&) LLVM_DELETED_FUNCTION; 47 public: 48 49 /// NamedTypes - The named types that are used by the current module. 50 TypeFinder NamedTypes; 51 52 /// NumberedTypes - The numbered types, along with their value. 53 DenseMap<StructType*, unsigned> NumberedTypes; 54 55 TypePrinting()56 TypePrinting() {} ~TypePrinting()57 ~TypePrinting() {} 58 59 void incorporateTypes(const Module &M); 60 61 void print(Type *Ty, raw_ostream &OS); 62 63 void printStructBody(StructType *Ty, raw_ostream &OS); 64 }; 65 66 class AssemblyWriter { 67 protected: 68 formatted_raw_ostream &Out; 69 const Module *TheModule; 70 71 private: 72 std::unique_ptr<SlotTracker> ModuleSlotTracker; 73 SlotTracker &Machine; 74 TypePrinting TypePrinter; 75 AssemblyAnnotationWriter *AnnotationWriter; 76 SetVector<const Comdat *> Comdats; 77 UseListOrderStack UseListOrders; 78 79 public: 80 /// Construct an AssemblyWriter with an external SlotTracker 81 AssemblyWriter(formatted_raw_ostream &o, SlotTracker &Mac, 82 const Module *M, AssemblyAnnotationWriter *AAW); 83 84 /// Construct an AssemblyWriter with an internally allocated SlotTracker 85 AssemblyWriter(formatted_raw_ostream &o, const Module *M, 86 AssemblyAnnotationWriter *AAW); 87 88 virtual ~AssemblyWriter(); 89 90 void printMDNodeBody(const MDNode *MD); 91 void printNamedMDNode(const NamedMDNode *NMD); 92 93 void printModule(const Module *M); 94 95 void writeOperand(const Value *Op, bool PrintType); 96 void writeParamOperand(const Value *Operand, AttributeSet Attrs,unsigned Idx); 97 void writeAtomic(AtomicOrdering Ordering, SynchronizationScope SynchScope); 98 void writeAtomicCmpXchg(AtomicOrdering SuccessOrdering, 99 AtomicOrdering FailureOrdering, 100 SynchronizationScope SynchScope); 101 102 void writeAllMDNodes(); 103 void writeMDNode(unsigned Slot, const MDNode *Node); 104 void writeAllAttributeGroups(); 105 106 void printTypeIdentities(); 107 void printGlobal(const GlobalVariable *GV); 108 void printAlias(const GlobalAlias *GV); 109 void printComdat(const Comdat *C); 110 void printFunction(const Function *F); 111 void printArgument(const Argument *FA, AttributeSet Attrs, unsigned Idx); 112 void printBasicBlock(const BasicBlock *BB); 113 void printInstructionLine(const Instruction &I); 114 void printInstruction(const Instruction &I); 115 116 void printUseListOrder(const UseListOrder &Order); 117 void printUseLists(const Function *F); 118 119 private: 120 void init(); 121 122 // printInfoComment - Print a little comment after the instruction indicating 123 // which slot it occupies. 124 void printInfoComment(const Value &V); 125 }; 126 127 } // namespace llvm 128 129 #endif 130