[OCaml] Commit missing parts of r210395
[oota-llvm.git] / lib / IR / AsmWriter.h
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_IR_ASSEMBLYWRITER_H
16 #define LLVM_IR_ASSEMBLYWRITER_H
17
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"
23
24 namespace llvm {
25
26 class BasicBlock;
27 class Function;
28 class GlobalValue;
29 class Module;
30 class NamedMDNode;
31 class Value;
32 class SlotTracker;
33
34 /// Create a new SlotTracker for a Module 
35 SlotTracker *createSlotTracker(const Module *M);
36
37 //===----------------------------------------------------------------------===//
38 // TypePrinting Class: Type printing machinery
39 //===----------------------------------------------------------------------===//
40
41 class TypePrinting {
42   TypePrinting(const TypePrinting &) LLVM_DELETED_FUNCTION;
43   void operator=(const TypePrinting&) LLVM_DELETED_FUNCTION;
44 public:
45
46   /// NamedTypes - The named types that are used by the current module.
47   TypeFinder NamedTypes;
48
49   /// NumberedTypes - The numbered types, along with their value.
50   DenseMap<StructType*, unsigned> NumberedTypes;
51
52
53   TypePrinting() {}
54   ~TypePrinting() {}
55
56   void incorporateTypes(const Module &M);
57
58   void print(Type *Ty, raw_ostream &OS);
59
60   void printStructBody(StructType *Ty, raw_ostream &OS);
61 };
62
63 class AssemblyWriter {
64 protected:
65   formatted_raw_ostream &Out;
66   const Module *TheModule;
67
68 private:
69   std::unique_ptr<SlotTracker> ModuleSlotTracker;
70   SlotTracker &Machine;
71   TypePrinting TypePrinter;
72   AssemblyAnnotationWriter *AnnotationWriter;
73
74 public:
75   /// Construct an AssemblyWriter with an external SlotTracker
76   AssemblyWriter(formatted_raw_ostream &o, SlotTracker &Mac,
77                  const Module *M, AssemblyAnnotationWriter *AAW);
78
79   /// Construct an AssemblyWriter with an internally allocated SlotTracker
80   AssemblyWriter(formatted_raw_ostream &o, const Module *M,
81                  AssemblyAnnotationWriter *AAW);
82
83   virtual ~AssemblyWriter();
84
85   void printMDNodeBody(const MDNode *MD);
86   void printNamedMDNode(const NamedMDNode *NMD);
87
88   void printModule(const Module *M);
89
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);
96
97   void writeAllMDNodes();
98   void writeMDNode(unsigned Slot, const MDNode *Node);
99   void writeAllAttributeGroups();
100
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);
109
110 private:
111   void init();
112
113   // printInfoComment - Print a little comment after the instruction indicating
114   // which slot it occupies.
115   void printInfoComment(const Value &V);
116 };
117
118 } // namespace llvm
119
120 #endif //LLVM_IR_ASMWRITER_H