blob: 60da5ad33502865001c2b2462491dfb8e0bb1ca6 [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
Benjamin Kramera7c40ef2014-08-13 16:26:38 +000015#ifndef LLVM_LIB_IR_ASMWRITER_H
16#define LLVM_LIB_IR_ASMWRITER_H
Daniel Maleaded9f932013-05-08 20:38:31 +000017
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"
Duncan P. N. Exon Smith0a448fb2014-08-19 21:30:15 +000023#include "llvm/IR/UseListOrder.h"
Daniel Maleaded9f932013-05-08 20:38:31 +000024#include "llvm/Support/FormattedStream.h"
25
26namespace llvm {
27
28class BasicBlock;
29class Function;
30class GlobalValue;
David Majnemerdad0a642014-06-27 18:19:56 +000031class Comdat;
Daniel Maleaded9f932013-05-08 20:38:31 +000032class Module;
33class NamedMDNode;
34class Value;
35class SlotTracker;
36
37/// Create a new SlotTracker for a Module
38SlotTracker *createSlotTracker(const Module *M);
39
40//===----------------------------------------------------------------------===//
41// TypePrinting Class: Type printing machinery
42//===----------------------------------------------------------------------===//
43
Benjamin Kramer079b96e2013-09-11 18:05:11 +000044class TypePrinting {
Daniel Maleaded9f932013-05-08 20:38:31 +000045 TypePrinting(const TypePrinting &) LLVM_DELETED_FUNCTION;
46 void operator=(const TypePrinting&) LLVM_DELETED_FUNCTION;
47public:
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
56 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
Benjamin Kramer079b96e2013-09-11 18:05:11 +000066class AssemblyWriter {
Daniel Maleaded9f932013-05-08 20:38:31 +000067protected:
68 formatted_raw_ostream &Out;
69 const Module *TheModule;
70
71private:
Ahmed Charles56440fd2014-03-06 05:51:42 +000072 std::unique_ptr<SlotTracker> ModuleSlotTracker;
Daniel Maleaded9f932013-05-08 20:38:31 +000073 SlotTracker &Machine;
74 TypePrinting TypePrinter;
75 AssemblyAnnotationWriter *AnnotationWriter;
David Majnemerdad0a642014-06-27 18:19:56 +000076 SetVector<const Comdat *> Comdats;
Duncan P. N. Exon Smith0a448fb2014-08-19 21:30:15 +000077 UseListOrderStack UseListOrders;
Daniel Maleaded9f932013-05-08 20:38:31 +000078
79public:
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
Daniel Maleafddddbe2013-05-23 22:34:33 +000090 void printMDNodeBody(const MDNode *MD);
91 void printNamedMDNode(const NamedMDNode *NMD);
Daniel Maleaded9f932013-05-08 20:38:31 +000092
Daniel Maleafddddbe2013-05-23 22:34:33 +000093 void printModule(const Module *M);
Daniel Maleaded9f932013-05-08 20:38:31 +000094
Daniel Maleafddddbe2013-05-23 22:34:33 +000095 void writeOperand(const Value *Op, bool PrintType);
96 void writeParamOperand(const Value *Operand, AttributeSet Attrs,unsigned Idx);
97 void writeAtomic(AtomicOrdering Ordering, SynchronizationScope SynchScope);
Tim Northovere94a5182014-03-11 10:48:52 +000098 void writeAtomicCmpXchg(AtomicOrdering SuccessOrdering,
99 AtomicOrdering FailureOrdering,
100 SynchronizationScope SynchScope);
Daniel Maleaded9f932013-05-08 20:38:31 +0000101
Daniel Maleafddddbe2013-05-23 22:34:33 +0000102 void writeAllMDNodes();
103 void writeMDNode(unsigned Slot, const MDNode *Node);
104 void writeAllAttributeGroups();
Daniel Maleaded9f932013-05-08 20:38:31 +0000105
Daniel Maleafddddbe2013-05-23 22:34:33 +0000106 void printTypeIdentities();
107 void printGlobal(const GlobalVariable *GV);
108 void printAlias(const GlobalAlias *GV);
David Majnemerdad0a642014-06-27 18:19:56 +0000109 void printComdat(const Comdat *C);
Daniel Maleafddddbe2013-05-23 22:34:33 +0000110 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);
Daniel Maleaded9f932013-05-08 20:38:31 +0000115
Duncan P. N. Exon Smith0a448fb2014-08-19 21:30:15 +0000116 void printUseListOrder(const UseListOrder &Order);
117 void printUseLists(const Function *F);
118
Daniel Maleaded9f932013-05-08 20:38:31 +0000119private:
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
Benjamin Kramera7c40ef2014-08-13 16:26:38 +0000129#endif