blob: 8f4a37777eb147e0aecc6c2d1aee02c21433715b [file] [log] [blame]
Daniel Maleaded9f932013-05-08 20:38:31 +00001//===-- 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/ADT/OwningPtr.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"
24
25namespace llvm {
26
27class BasicBlock;
28class Function;
29class GlobalValue;
30class Module;
31class NamedMDNode;
32class Value;
33class SlotTracker;
34
35/// Create a new SlotTracker for a Module
36SlotTracker *createSlotTracker(const Module *M);
37
38//===----------------------------------------------------------------------===//
39// TypePrinting Class: Type printing machinery
40//===----------------------------------------------------------------------===//
41
Benjamin Kramer079b96e2013-09-11 18:05:11 +000042class TypePrinting {
Daniel Maleaded9f932013-05-08 20:38:31 +000043 TypePrinting(const TypePrinting &) LLVM_DELETED_FUNCTION;
44 void operator=(const TypePrinting&) LLVM_DELETED_FUNCTION;
45public:
46
47 /// NamedTypes - The named types that are used by the current module.
48 TypeFinder NamedTypes;
49
50 /// NumberedTypes - The numbered types, along with their value.
51 DenseMap<StructType*, unsigned> NumberedTypes;
52
53
54 TypePrinting() {}
55 ~TypePrinting() {}
56
57 void incorporateTypes(const Module &M);
58
59 void print(Type *Ty, raw_ostream &OS);
60
61 void printStructBody(StructType *Ty, raw_ostream &OS);
62};
63
Benjamin Kramer079b96e2013-09-11 18:05:11 +000064class AssemblyWriter {
Daniel Maleaded9f932013-05-08 20:38:31 +000065protected:
66 formatted_raw_ostream &Out;
67 const Module *TheModule;
68
69private:
70 OwningPtr<SlotTracker> ModuleSlotTracker;
71 SlotTracker &Machine;
72 TypePrinting TypePrinter;
73 AssemblyAnnotationWriter *AnnotationWriter;
74
75public:
76 /// Construct an AssemblyWriter with an external SlotTracker
77 AssemblyWriter(formatted_raw_ostream &o, SlotTracker &Mac,
78 const Module *M, AssemblyAnnotationWriter *AAW);
79
80 /// Construct an AssemblyWriter with an internally allocated SlotTracker
81 AssemblyWriter(formatted_raw_ostream &o, const Module *M,
82 AssemblyAnnotationWriter *AAW);
83
84 virtual ~AssemblyWriter();
85
Daniel Maleafddddbe2013-05-23 22:34:33 +000086 void printMDNodeBody(const MDNode *MD);
87 void printNamedMDNode(const NamedMDNode *NMD);
Daniel Maleaded9f932013-05-08 20:38:31 +000088
Daniel Maleafddddbe2013-05-23 22:34:33 +000089 void printModule(const Module *M);
Daniel Maleaded9f932013-05-08 20:38:31 +000090
Daniel Maleafddddbe2013-05-23 22:34:33 +000091 void writeOperand(const Value *Op, bool PrintType);
92 void writeParamOperand(const Value *Operand, AttributeSet Attrs,unsigned Idx);
93 void writeAtomic(AtomicOrdering Ordering, SynchronizationScope SynchScope);
Daniel Maleaded9f932013-05-08 20:38:31 +000094
Daniel Maleafddddbe2013-05-23 22:34:33 +000095 void writeAllMDNodes();
96 void writeMDNode(unsigned Slot, const MDNode *Node);
97 void writeAllAttributeGroups();
Daniel Maleaded9f932013-05-08 20:38:31 +000098
Daniel Maleafddddbe2013-05-23 22:34:33 +000099 void printTypeIdentities();
100 void printGlobal(const GlobalVariable *GV);
101 void printAlias(const GlobalAlias *GV);
102 void printFunction(const Function *F);
103 void printArgument(const Argument *FA, AttributeSet Attrs, unsigned Idx);
104 void printBasicBlock(const BasicBlock *BB);
105 void printInstructionLine(const Instruction &I);
106 void printInstruction(const Instruction &I);
Daniel Maleaded9f932013-05-08 20:38:31 +0000107
108private:
109 void init();
110
111 // printInfoComment - Print a little comment after the instruction indicating
112 // which slot it occupies.
113 void printInfoComment(const Value &V);
114};
115
116} // namespace llvm
117
118#endif //LLVM_IR_ASMWRITER_H