Enable printing of dominator related information.
[oota-llvm.git] / include / llvm / Assembly / Writer.h
1 //===-- llvm/assembly/Writer.h - Printer for VM assembly files ---*- C++ -*--=//
2 //
3 // This functionality is implemented by the lib/AssemblyWriter library.
4 // This library is used to print VM assembly language files to an iostream. It
5 // can print VM code at a variety of granularities, ranging from a whole class
6 // down to an individual instruction.  This makes it useful for debugging.
7 //
8 // This file also defines functions that allow it to output files that a program
9 // called VCG can read.
10 //
11 // This library uses the Analysis library to figure out offsets for
12 // variables in the method tables...
13 //
14 //===----------------------------------------------------------------------===//
15
16 #ifndef LLVM_ASSEMBLY_WRITER_H
17 #define LLVM_ASSEMBLY_WRITER_H
18
19 #include <iostream>
20 #include "llvm/Type.h"
21
22 class Module;
23 class Method;
24 class BasicBlock;
25 class Instruction;
26
27 // The only interface defined by this file... convert the internal 
28 // representation of an object into an ascii bytestream that the parser can 
29 // understand later... (the parser only understands whole classes though)
30 //
31 void WriteToAssembly(const Module  *Module, ostream &o);
32 void WriteToAssembly(const Method  *Method, ostream &o);
33 void WriteToAssembly(const BasicBlock  *BB, ostream &o);
34 void WriteToAssembly(const Instruction *In, ostream &o);
35 void WriteToAssembly(const ConstPoolVal *V, ostream &o);
36
37 // WriteToVCG - Dump the specified structure to a VCG file.  If method is
38 // dumped, then the file named is created.  If a module is to be written, a
39 // family of files with a common base name is created, with a method name
40 // suffix.
41 //
42 void WriteToVCG(const Module *Module, const string &Filename);
43 void WriteToVCG(const Method *Method, const string &Filename);
44
45
46
47
48 // Define operator<< to work on the various classes that we can send to an 
49 // ostream...
50 //
51 inline ostream &operator<<(ostream &o, const Module *C) {
52   WriteToAssembly(C, o); return o;
53 }
54
55 inline ostream &operator<<(ostream &o, const Method *M) {
56   WriteToAssembly(M, o); return o;
57 }
58
59 inline ostream &operator<<(ostream &o, const BasicBlock *B) {
60   WriteToAssembly(B, o); return o;
61 }
62
63 inline ostream &operator<<(ostream &o, const Instruction *I) {
64   WriteToAssembly(I, o); return o;
65 }
66
67 inline ostream &operator<<(ostream &o, const ConstPoolVal *I) {
68   WriteToAssembly(I, o); return o;
69 }
70
71
72 inline ostream &operator<<(ostream &o, const Type *T) {
73   if (!T) return o << "<null Type>";
74   return o << T->getName();
75 }
76
77 inline ostream &operator<<(ostream &o, const Value *I) {
78   switch (I->getValueType()) {
79   case Value::TypeVal:        return o << (const Type*)I;
80   case Value::ConstantVal:    WriteToAssembly((const ConstPoolVal*)I, o); break;
81   case Value::MethodArgumentVal: return o <<I->getType() << " " << I->getName();
82   case Value::InstructionVal: WriteToAssembly((const Instruction *)I, o); break;
83   case Value::BasicBlockVal:  WriteToAssembly((const BasicBlock  *)I, o); break;
84   case Value::MethodVal:      WriteToAssembly((const Method      *)I, o); break;
85   case Value::ModuleVal:      WriteToAssembly((const Module      *)I, o); break;
86   default: return o << "<unknown value type: " << I->getValueType() << ">";
87   }
88   return o;
89 }
90
91
92 // This library also provides support for printing out Interval's.
93 namespace cfg {
94   class Interval;
95   void WriteToOutput(const Interval *I, ostream &o);
96   inline ostream &operator <<(ostream &o, const Interval *I) {
97     WriteToOutput(I, o); return o;
98   }
99
100   // Stuff for printing out Dominator data structures...
101   class DominatorSet;
102   class ImmediateDominators;
103   class DominatorTree;
104   class DominanceFrontier;
105
106   void WriteToOutput(const DominatorSet &, ostream &o);
107   inline ostream &operator <<(ostream &o, const DominatorSet &DS) {
108     WriteToOutput(DS, o); return o;
109   }
110
111   void WriteToOutput(const ImmediateDominators &, ostream &o);
112   inline ostream &operator <<(ostream &o, const ImmediateDominators &ID) {
113     WriteToOutput(ID, o); return o;
114   }
115
116   void WriteToOutput(const DominatorTree &, ostream &o);
117   inline ostream &operator <<(ostream &o, const DominatorTree &DT) {
118     WriteToOutput(DT, o); return o;
119   }
120
121   void WriteToOutput(const DominanceFrontier &, ostream &o);
122   inline ostream &operator <<(ostream &o, const DominanceFrontier &DF) {
123     WriteToOutput(DF, o); return o;
124   }
125 }
126
127 #endif