LLVM API Documentation

AsmWriter.h
Go to the documentation of this file.
00001 //===-- llvm/IR/AsmWriter.h - Printing LLVM IR as an assembly file - C++ --===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This files defines the interface for the AssemblyWriter class used to print
00011 // LLVM IR and various helper classes that are used in printing.
00012 //
00013 //===----------------------------------------------------------------------===//
00014 
00015 #ifndef LLVM_LIB_IR_ASMWRITER_H
00016 #define LLVM_LIB_IR_ASMWRITER_H
00017 
00018 #include "llvm/ADT/DenseMap.h"
00019 #include "llvm/ADT/SetVector.h"
00020 #include "llvm/IR/Attributes.h"
00021 #include "llvm/IR/Instructions.h"
00022 #include "llvm/IR/TypeFinder.h"
00023 #include "llvm/IR/UseListOrder.h"
00024 #include "llvm/Support/FormattedStream.h"
00025 
00026 namespace llvm {
00027 
00028 class BasicBlock;
00029 class Function;
00030 class GlobalValue;
00031 class Comdat;
00032 class Module;
00033 class NamedMDNode;
00034 class Value;
00035 class SlotTracker;
00036 
00037 /// Create a new SlotTracker for a Module 
00038 SlotTracker *createSlotTracker(const Module *M);
00039 
00040 //===----------------------------------------------------------------------===//
00041 // TypePrinting Class: Type printing machinery
00042 //===----------------------------------------------------------------------===//
00043 
00044 class TypePrinting {
00045   TypePrinting(const TypePrinting &) LLVM_DELETED_FUNCTION;
00046   void operator=(const TypePrinting&) LLVM_DELETED_FUNCTION;
00047 public:
00048 
00049   /// NamedTypes - The named types that are used by the current module.
00050   TypeFinder NamedTypes;
00051 
00052   /// NumberedTypes - The numbered types, along with their value.
00053   DenseMap<StructType*, unsigned> NumberedTypes;
00054 
00055 
00056   TypePrinting() {}
00057   ~TypePrinting() {}
00058 
00059   void incorporateTypes(const Module &M);
00060 
00061   void print(Type *Ty, raw_ostream &OS);
00062 
00063   void printStructBody(StructType *Ty, raw_ostream &OS);
00064 };
00065 
00066 class AssemblyWriter {
00067 protected:
00068   formatted_raw_ostream &Out;
00069   const Module *TheModule;
00070 
00071 private:
00072   std::unique_ptr<SlotTracker> ModuleSlotTracker;
00073   SlotTracker &Machine;
00074   TypePrinting TypePrinter;
00075   AssemblyAnnotationWriter *AnnotationWriter;
00076   SetVector<const Comdat *> Comdats;
00077   UseListOrderStack UseListOrders;
00078 
00079 public:
00080   /// Construct an AssemblyWriter with an external SlotTracker
00081   AssemblyWriter(formatted_raw_ostream &o, SlotTracker &Mac,
00082                  const Module *M, AssemblyAnnotationWriter *AAW);
00083 
00084   /// Construct an AssemblyWriter with an internally allocated SlotTracker
00085   AssemblyWriter(formatted_raw_ostream &o, const Module *M,
00086                  AssemblyAnnotationWriter *AAW);
00087 
00088   virtual ~AssemblyWriter();
00089 
00090   void printMDNodeBody(const MDNode *MD);
00091   void printNamedMDNode(const NamedMDNode *NMD);
00092 
00093   void printModule(const Module *M);
00094 
00095   void writeOperand(const Value *Op, bool PrintType);
00096   void writeParamOperand(const Value *Operand, AttributeSet Attrs,unsigned Idx);
00097   void writeAtomic(AtomicOrdering Ordering, SynchronizationScope SynchScope);
00098   void writeAtomicCmpXchg(AtomicOrdering SuccessOrdering,
00099                           AtomicOrdering FailureOrdering,
00100                           SynchronizationScope SynchScope);
00101 
00102   void writeAllMDNodes();
00103   void writeMDNode(unsigned Slot, const MDNode *Node);
00104   void writeAllAttributeGroups();
00105 
00106   void printTypeIdentities();
00107   void printGlobal(const GlobalVariable *GV);
00108   void printAlias(const GlobalAlias *GV);
00109   void printComdat(const Comdat *C);
00110   void printFunction(const Function *F);
00111   void printArgument(const Argument *FA, AttributeSet Attrs, unsigned Idx);
00112   void printBasicBlock(const BasicBlock *BB);
00113   void printInstructionLine(const Instruction &I);
00114   void printInstruction(const Instruction &I);
00115 
00116   void printUseListOrder(const UseListOrder &Order);
00117   void printUseLists(const Function *F);
00118 
00119 private:
00120   void init();
00121 
00122   // printInfoComment - Print a little comment after the instruction indicating
00123   // which slot it occupies.
00124   void printInfoComment(const Value &V);
00125 };
00126 
00127 } // namespace llvm
00128 
00129 #endif