1259698Sdim//===-- llvm/IR/AsmWriter.h - Printing LLVM IR as an assembly file - C++ --===//
2259698Sdim//
3259698Sdim//                     The LLVM Compiler Infrastructure
4259698Sdim//
5259698Sdim// This file is distributed under the University of Illinois Open Source
6259698Sdim// License. See LICENSE.TXT for details.
7259698Sdim//
8259698Sdim//===----------------------------------------------------------------------===//
9259698Sdim//
10259698Sdim// This files defines the interface for the AssemblyWriter class used to print
11259698Sdim// LLVM IR and various helper classes that are used in printing.
12259698Sdim//
13259698Sdim//===----------------------------------------------------------------------===//
14259698Sdim
15259698Sdim#ifndef LLVM_IR_ASSEMBLYWRITER_H
16259698Sdim#define LLVM_IR_ASSEMBLYWRITER_H
17259698Sdim
18259698Sdim#include "llvm/ADT/DenseMap.h"
19259698Sdim#include "llvm/ADT/OwningPtr.h"
20259698Sdim#include "llvm/IR/Attributes.h"
21259698Sdim#include "llvm/IR/Instructions.h"
22259698Sdim#include "llvm/IR/TypeFinder.h"
23259698Sdim#include "llvm/Support/FormattedStream.h"
24259698Sdim
25259698Sdimnamespace llvm {
26259698Sdim
27259698Sdimclass BasicBlock;
28259698Sdimclass Function;
29259698Sdimclass GlobalValue;
30259698Sdimclass Module;
31259698Sdimclass NamedMDNode;
32259698Sdimclass Value;
33259698Sdimclass SlotTracker;
34259698Sdim
35259698Sdim/// Create a new SlotTracker for a Module
36259698SdimSlotTracker *createSlotTracker(const Module *M);
37259698Sdim
38259698Sdim//===----------------------------------------------------------------------===//
39259698Sdim// TypePrinting Class: Type printing machinery
40259698Sdim//===----------------------------------------------------------------------===//
41259698Sdim
42259698Sdimclass TypePrinting {
43259698Sdim  TypePrinting(const TypePrinting &) LLVM_DELETED_FUNCTION;
44259698Sdim  void operator=(const TypePrinting&) LLVM_DELETED_FUNCTION;
45259698Sdimpublic:
46259698Sdim
47259698Sdim  /// NamedTypes - The named types that are used by the current module.
48259698Sdim  TypeFinder NamedTypes;
49259698Sdim
50259698Sdim  /// NumberedTypes - The numbered types, along with their value.
51259698Sdim  DenseMap<StructType*, unsigned> NumberedTypes;
52259698Sdim
53259698Sdim
54259698Sdim  TypePrinting() {}
55259698Sdim  ~TypePrinting() {}
56259698Sdim
57259698Sdim  void incorporateTypes(const Module &M);
58259698Sdim
59259698Sdim  void print(Type *Ty, raw_ostream &OS);
60259698Sdim
61259698Sdim  void printStructBody(StructType *Ty, raw_ostream &OS);
62259698Sdim};
63259698Sdim
64259698Sdimclass AssemblyWriter {
65259698Sdimprotected:
66259698Sdim  formatted_raw_ostream &Out;
67259698Sdim  const Module *TheModule;
68259698Sdim
69259698Sdimprivate:
70259698Sdim  OwningPtr<SlotTracker> ModuleSlotTracker;
71259698Sdim  SlotTracker &Machine;
72259698Sdim  TypePrinting TypePrinter;
73259698Sdim  AssemblyAnnotationWriter *AnnotationWriter;
74259698Sdim
75259698Sdimpublic:
76259698Sdim  /// Construct an AssemblyWriter with an external SlotTracker
77259698Sdim  AssemblyWriter(formatted_raw_ostream &o, SlotTracker &Mac,
78259698Sdim                 const Module *M, AssemblyAnnotationWriter *AAW);
79259698Sdim
80259698Sdim  /// Construct an AssemblyWriter with an internally allocated SlotTracker
81259698Sdim  AssemblyWriter(formatted_raw_ostream &o, const Module *M,
82259698Sdim                 AssemblyAnnotationWriter *AAW);
83259698Sdim
84259698Sdim  virtual ~AssemblyWriter();
85259698Sdim
86259698Sdim  void printMDNodeBody(const MDNode *MD);
87259698Sdim  void printNamedMDNode(const NamedMDNode *NMD);
88259698Sdim
89259698Sdim  void printModule(const Module *M);
90259698Sdim
91259698Sdim  void writeOperand(const Value *Op, bool PrintType);
92259698Sdim  void writeParamOperand(const Value *Operand, AttributeSet Attrs,unsigned Idx);
93259698Sdim  void writeAtomic(AtomicOrdering Ordering, SynchronizationScope SynchScope);
94259698Sdim
95259698Sdim  void writeAllMDNodes();
96259698Sdim  void writeMDNode(unsigned Slot, const MDNode *Node);
97259698Sdim  void writeAllAttributeGroups();
98259698Sdim
99259698Sdim  void printTypeIdentities();
100259698Sdim  void printGlobal(const GlobalVariable *GV);
101259698Sdim  void printAlias(const GlobalAlias *GV);
102259698Sdim  void printFunction(const Function *F);
103259698Sdim  void printArgument(const Argument *FA, AttributeSet Attrs, unsigned Idx);
104259698Sdim  void printBasicBlock(const BasicBlock *BB);
105259698Sdim  void printInstructionLine(const Instruction &I);
106259698Sdim  void printInstruction(const Instruction &I);
107259698Sdim
108259698Sdimprivate:
109259698Sdim  void init();
110259698Sdim
111259698Sdim  // printInfoComment - Print a little comment after the instruction indicating
112259698Sdim  // which slot it occupies.
113259698Sdim  void printInfoComment(const Value &V);
114259698Sdim};
115259698Sdim
116259698Sdim} // namespace llvm
117259698Sdim
118259698Sdim#endif //LLVM_IR_ASMWRITER_H
119