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_IR_ASSEMBLYWRITER_H
16 #define LLVM_IR_ASSEMBLYWRITER_H
18 #include "llvm/ADT/DenseMap.h"
19 #include "llvm/IR/Attributes.h"
20 #include "llvm/IR/Instructions.h"
21 #include "llvm/IR/TypeFinder.h"
22 #include "llvm/Support/FormattedStream.h"
34 /// Create a new SlotTracker for a Module
35 SlotTracker *createSlotTracker(const Module *M);
37 //===----------------------------------------------------------------------===//
38 // TypePrinting Class: Type printing machinery
39 //===----------------------------------------------------------------------===//
42 TypePrinting(const TypePrinting &) LLVM_DELETED_FUNCTION;
43 void operator=(const TypePrinting&) LLVM_DELETED_FUNCTION;
46 /// NamedTypes - The named types that are used by the current module.
47 TypeFinder NamedTypes;
49 /// NumberedTypes - The numbered types, along with their value.
50 DenseMap<StructType*, unsigned> NumberedTypes;
56 void incorporateTypes(const Module &M);
58 void print(Type *Ty, raw_ostream &OS);
60 void printStructBody(StructType *Ty, raw_ostream &OS);
63 class AssemblyWriter {
65 formatted_raw_ostream &Out;
66 const Module *TheModule;
69 std::unique_ptr<SlotTracker> ModuleSlotTracker;
71 TypePrinting TypePrinter;
72 AssemblyAnnotationWriter *AnnotationWriter;
75 /// Construct an AssemblyWriter with an external SlotTracker
76 AssemblyWriter(formatted_raw_ostream &o, SlotTracker &Mac,
77 const Module *M, AssemblyAnnotationWriter *AAW);
79 /// Construct an AssemblyWriter with an internally allocated SlotTracker
80 AssemblyWriter(formatted_raw_ostream &o, const Module *M,
81 AssemblyAnnotationWriter *AAW);
83 virtual ~AssemblyWriter();
85 void printMDNodeBody(const MDNode *MD);
86 void printNamedMDNode(const NamedMDNode *NMD);
88 void printModule(const Module *M);
90 void writeOperand(const Value *Op, bool PrintType);
91 void writeParamOperand(const Value *Operand, AttributeSet Attrs,unsigned Idx);
92 void writeAtomic(AtomicOrdering Ordering, SynchronizationScope SynchScope);
93 void writeAtomicCmpXchg(AtomicOrdering SuccessOrdering,
94 AtomicOrdering FailureOrdering,
95 SynchronizationScope SynchScope);
97 void writeAllMDNodes();
98 void writeMDNode(unsigned Slot, const MDNode *Node);
99 void writeAllAttributeGroups();
101 void printTypeIdentities();
102 void printGlobal(const GlobalVariable *GV);
103 void printAlias(const GlobalAlias *GV);
104 void printFunction(const Function *F);
105 void printArgument(const Argument *FA, AttributeSet Attrs, unsigned Idx);
106 void printBasicBlock(const BasicBlock *BB);
107 void printInstructionLine(const Instruction &I);
108 void printInstruction(const Instruction &I);
113 // printInfoComment - Print a little comment after the instruction indicating
114 // which slot it occupies.
115 void printInfoComment(const Value &V);
120 #endif //LLVM_IR_ASMWRITER_H