diff options
author | Daniel Malea <daniel.malea@intel.com> | 2013-05-08 20:38:31 +0000 |
---|---|---|
committer | Daniel Malea <daniel.malea@intel.com> | 2013-05-08 20:38:31 +0000 |
commit | d0fef32e5f3700c7de6dfc50a1a3815659b7d19e (patch) | |
tree | e57a6c9be1dc8d14dca060527a258cdc301a3e39 /include | |
parent | f28e3c501e033f103405c03a4bbf848cb6e67a2a (diff) | |
download | llvm-d0fef32e5f3700c7de6dfc50a1a3815659b7d19e.tar.gz llvm-d0fef32e5f3700c7de6dfc50a1a3815659b7d19e.tar.bz2 llvm-d0fef32e5f3700c7de6dfc50a1a3815659b7d19e.tar.xz |
Pull up AssemblyWriter interface into header to allow subclassing
- made all functions virtual so that subclasses can specialize them
- add printInstructionLine so that subclasses can choose whether or not to
print the newline character (without having to implement printBasicBlock()
- added a second constructor to AssemblyWriter that does not require a
SlotTracker, as required in order to keep the SlotTracker helper class outside
AsmWriter.h and buried in the implementation.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@181466 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r-- | include/llvm/IR/AsmWriter.h | 118 |
1 files changed, 118 insertions, 0 deletions
diff --git a/include/llvm/IR/AsmWriter.h b/include/llvm/IR/AsmWriter.h new file mode 100644 index 0000000000..aac7975ee6 --- /dev/null +++ b/include/llvm/IR/AsmWriter.h @@ -0,0 +1,118 @@ +//===-- llvm/IR/AsmWriter.h - Printing LLVM IR as an assembly file - C++ --===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This files defines the interface for the AssemblyWriter class used to print +// LLVM IR and various helper classes that are used in printing. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_IR_ASSEMBLYWRITER_H +#define LLVM_IR_ASSEMBLYWRITER_H + +#include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/OwningPtr.h" +#include "llvm/IR/Attributes.h" +#include "llvm/IR/Instructions.h" +#include "llvm/IR/TypeFinder.h" +#include "llvm/Support/FormattedStream.h" + +namespace llvm { + +class BasicBlock; +class Function; +class GlobalValue; +class Module; +class NamedMDNode; +class Value; +class SlotTracker; + +/// Create a new SlotTracker for a Module +SlotTracker *createSlotTracker(const Module *M); + +//===----------------------------------------------------------------------===// +// TypePrinting Class: Type printing machinery +//===----------------------------------------------------------------------===// + +class TypePrinting { + TypePrinting(const TypePrinting &) LLVM_DELETED_FUNCTION; + void operator=(const TypePrinting&) LLVM_DELETED_FUNCTION; +public: + + /// NamedTypes - The named types that are used by the current module. + TypeFinder NamedTypes; + + /// NumberedTypes - The numbered types, along with their value. + DenseMap<StructType*, unsigned> NumberedTypes; + + + TypePrinting() {} + ~TypePrinting() {} + + void incorporateTypes(const Module &M); + + void print(Type *Ty, raw_ostream &OS); + + void printStructBody(StructType *Ty, raw_ostream &OS); +}; + +class AssemblyWriter { +protected: + formatted_raw_ostream &Out; + const Module *TheModule; + +private: + OwningPtr<SlotTracker> ModuleSlotTracker; + SlotTracker &Machine; + TypePrinting TypePrinter; + AssemblyAnnotationWriter *AnnotationWriter; + +public: + /// Construct an AssemblyWriter with an external SlotTracker + AssemblyWriter(formatted_raw_ostream &o, SlotTracker &Mac, + const Module *M, AssemblyAnnotationWriter *AAW); + + /// Construct an AssemblyWriter with an internally allocated SlotTracker + AssemblyWriter(formatted_raw_ostream &o, const Module *M, + AssemblyAnnotationWriter *AAW); + + virtual ~AssemblyWriter(); + + virtual void printMDNodeBody(const MDNode *MD); + virtual void printNamedMDNode(const NamedMDNode *NMD); + + virtual void printModule(const Module *M); + + virtual void writeOperand(const Value *Op, bool PrintType); + virtual void writeParamOperand(const Value *Operand, AttributeSet Attrs,unsigned Idx); + virtual void writeAtomic(AtomicOrdering Ordering, SynchronizationScope SynchScope); + + virtual void writeAllMDNodes(); + virtual void writeMDNode(unsigned Slot, const MDNode *Node); + virtual void writeAllAttributeGroups(); + + virtual void printTypeIdentities(); + virtual void printGlobal(const GlobalVariable *GV); + virtual void printAlias(const GlobalAlias *GV); + virtual void printFunction(const Function *F); + virtual void printArgument(const Argument *FA, AttributeSet Attrs, unsigned Idx); + virtual void printBasicBlock(const BasicBlock *BB); + virtual void printInstructionLine(const Instruction &I); + virtual void printInstruction(const Instruction &I); + +private: + void init(); + + // printInfoComment - Print a little comment after the instruction indicating + // which slot it occupies. + void printInfoComment(const Value &V); +}; + +} // namespace llvm + +#endif //LLVM_IR_ASMWRITER_H |