blob: aef9c8a3e9f7b7912b9efd1d15e03f963c7be115 [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"
David Majnemerdad0a642014-06-27 18:19:56 +000019#include "llvm/ADT/SetVector.h"
Daniel Maleaded9f932013-05-08 20:38:31 +000020#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;
David Majnemerdad0a642014-06-27 18:19:56 +000030class Comdat;
Daniel Maleaded9f932013-05-08 20:38:31 +000031class Module;
32class NamedMDNode;
33class Value;
34class SlotTracker;
35
36/// Create a new SlotTracker for a Module
37SlotTracker *createSlotTracker(const Module *M);
38
39//===----------------------------------------------------------------------===//
40// TypePrinting Class: Type printing machinery
41//===----------------------------------------------------------------------===//
42
Benjamin Kramer079b96e2013-09-11 18:05:11 +000043class TypePrinting {
Daniel Maleaded9f932013-05-08 20:38:31 +000044 TypePrinting(const TypePrinting &) LLVM_DELETED_FUNCTION;
45 void operator=(const TypePrinting&) LLVM_DELETED_FUNCTION;
46public:
47
48 /// NamedTypes - The named types that are used by the current module.
49 TypeFinder NamedTypes;
50
51 /// NumberedTypes - The numbered types, along with their value.
52 DenseMap<StructType*, unsigned> NumberedTypes;
53
54
55 TypePrinting() {}
56 ~TypePrinting() {}
57
58 void incorporateTypes(const Module &M);
59
60 void print(Type *Ty, raw_ostream &OS);
61
62 void printStructBody(StructType *Ty, raw_ostream &OS);
63};
64
Benjamin Kramer079b96e2013-09-11 18:05:11 +000065class AssemblyWriter {
Daniel Maleaded9f932013-05-08 20:38:31 +000066protected:
67 formatted_raw_ostream &Out;
68 const Module *TheModule;
69
70private:
Ahmed Charles56440fd2014-03-06 05:51:42 +000071 std::unique_ptr<SlotTracker> ModuleSlotTracker;
Daniel Maleaded9f932013-05-08 20:38:31 +000072 SlotTracker &Machine;
73 TypePrinting TypePrinter;
74 AssemblyAnnotationWriter *AnnotationWriter;
David Majnemerdad0a642014-06-27 18:19:56 +000075 SetVector<const Comdat *> Comdats;
Daniel Maleaded9f932013-05-08 20:38:31 +000076
77public:
78 /// Construct an AssemblyWriter with an external SlotTracker
79 AssemblyWriter(formatted_raw_ostream &o, SlotTracker &Mac,
80 const Module *M, AssemblyAnnotationWriter *AAW);
81
82 /// Construct an AssemblyWriter with an internally allocated SlotTracker
83 AssemblyWriter(formatted_raw_ostream &o, const Module *M,
84 AssemblyAnnotationWriter *AAW);
85
86 virtual ~AssemblyWriter();
87
Daniel Maleafddddbe2013-05-23 22:34:33 +000088 void printMDNodeBody(const MDNode *MD);
89 void printNamedMDNode(const NamedMDNode *NMD);
Daniel Maleaded9f932013-05-08 20:38:31 +000090
Daniel Maleafddddbe2013-05-23 22:34:33 +000091 void printModule(const Module *M);
Daniel Maleaded9f932013-05-08 20:38:31 +000092
Daniel Maleafddddbe2013-05-23 22:34:33 +000093 void writeOperand(const Value *Op, bool PrintType);
94 void writeParamOperand(const Value *Operand, AttributeSet Attrs,unsigned Idx);
95 void writeAtomic(AtomicOrdering Ordering, SynchronizationScope SynchScope);
Tim Northovere94a5182014-03-11 10:48:52 +000096 void writeAtomicCmpXchg(AtomicOrdering SuccessOrdering,
97 AtomicOrdering FailureOrdering,
98 SynchronizationScope SynchScope);
Daniel Maleaded9f932013-05-08 20:38:31 +000099
Daniel Maleafddddbe2013-05-23 22:34:33 +0000100 void writeAllMDNodes();
101 void writeMDNode(unsigned Slot, const MDNode *Node);
102 void writeAllAttributeGroups();
Daniel Maleaded9f932013-05-08 20:38:31 +0000103
Daniel Maleafddddbe2013-05-23 22:34:33 +0000104 void printTypeIdentities();
105 void printGlobal(const GlobalVariable *GV);
106 void printAlias(const GlobalAlias *GV);
David Majnemerdad0a642014-06-27 18:19:56 +0000107 void printComdat(const Comdat *C);
Daniel Maleafddddbe2013-05-23 22:34:33 +0000108 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);
Daniel Maleaded9f932013-05-08 20:38:31 +0000113
114private:
115 void init();
116
117 // printInfoComment - Print a little comment after the instruction indicating
118 // which slot it occupies.
119 void printInfoComment(const Value &V);
120};
121
122} // namespace llvm
123
124#endif //LLVM_IR_ASMWRITER_H