blob: b4ce6de10ddea512a93fd1328c5bee35580ac205 [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"
Daniel Maleaded9f932013-05-08 20:38:31 +000019#include "llvm/IR/Attributes.h"
20#include "llvm/IR/Instructions.h"
21#include "llvm/IR/TypeFinder.h"
22#include "llvm/Support/FormattedStream.h"
23
24namespace llvm {
25
26class BasicBlock;
27class Function;
28class GlobalValue;
29class Module;
30class NamedMDNode;
31class Value;
32class SlotTracker;
33
34/// Create a new SlotTracker for a Module
35SlotTracker *createSlotTracker(const Module *M);
36
37//===----------------------------------------------------------------------===//
38// TypePrinting Class: Type printing machinery
39//===----------------------------------------------------------------------===//
40
Benjamin Kramer079b96e2013-09-11 18:05:11 +000041class TypePrinting {
Daniel Maleaded9f932013-05-08 20:38:31 +000042 TypePrinting(const TypePrinting &) LLVM_DELETED_FUNCTION;
43 void operator=(const TypePrinting&) LLVM_DELETED_FUNCTION;
44public:
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
Benjamin Kramer079b96e2013-09-11 18:05:11 +000063class AssemblyWriter {
Daniel Maleaded9f932013-05-08 20:38:31 +000064protected:
65 formatted_raw_ostream &Out;
66 const Module *TheModule;
67
68private:
Ahmed Charles56440fd2014-03-06 05:51:42 +000069 std::unique_ptr<SlotTracker> ModuleSlotTracker;
Daniel Maleaded9f932013-05-08 20:38:31 +000070 SlotTracker &Machine;
71 TypePrinting TypePrinter;
72 AssemblyAnnotationWriter *AnnotationWriter;
73
74public:
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
Daniel Maleafddddbe2013-05-23 22:34:33 +000085 void printMDNodeBody(const MDNode *MD);
86 void printNamedMDNode(const NamedMDNode *NMD);
Daniel Maleaded9f932013-05-08 20:38:31 +000087
Daniel Maleafddddbe2013-05-23 22:34:33 +000088 void printModule(const Module *M);
Daniel Maleaded9f932013-05-08 20:38:31 +000089
Daniel Maleafddddbe2013-05-23 22:34:33 +000090 void writeOperand(const Value *Op, bool PrintType);
91 void writeParamOperand(const Value *Operand, AttributeSet Attrs,unsigned Idx);
92 void writeAtomic(AtomicOrdering Ordering, SynchronizationScope SynchScope);
Tim Northovere94a5182014-03-11 10:48:52 +000093 void writeAtomicCmpXchg(AtomicOrdering SuccessOrdering,
94 AtomicOrdering FailureOrdering,
95 SynchronizationScope SynchScope);
Daniel Maleaded9f932013-05-08 20:38:31 +000096
Daniel Maleafddddbe2013-05-23 22:34:33 +000097 void writeAllMDNodes();
98 void writeMDNode(unsigned Slot, const MDNode *Node);
99 void writeAllAttributeGroups();
Daniel Maleaded9f932013-05-08 20:38:31 +0000100
Daniel Maleafddddbe2013-05-23 22:34:33 +0000101 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);
Daniel Maleaded9f932013-05-08 20:38:31 +0000109
110private:
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