6ce3b92681e21b0d1032d926a49343baa1567764
[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/Assembly/Writer 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 GlobalVariable;
24 class Method;
25 class BasicBlock;
26 class Instruction;
27 class SlotCalculator;
28
29 // The only interface defined by this file... convert the internal 
30 // representation of an object into an ascii bytestream that the parser can 
31 // understand later... (the parser only understands whole classes though)
32 //
33 void WriteToAssembly(const Module  *Module, ostream &o);
34 void WriteToAssembly(const GlobalVariable *G, ostream &o);
35 void WriteToAssembly(const Method  *Method, ostream &o);
36 void WriteToAssembly(const BasicBlock  *BB, ostream &o);
37 void WriteToAssembly(const Instruction *In, ostream &o);
38 void WriteToAssembly(const ConstPoolVal *V, ostream &o);
39
40 // WriteAsOperand - Write the name of the specified value out to the specified
41 // ostream.  This can be useful when you just want to print int %reg126, not the
42 // whole instruction that generated it.
43 //
44 ostream &WriteAsOperand(ostream &o, const Value *V, bool PrintType = true,
45                         bool PrintName = true, SlotCalculator *Table = 0);
46
47
48 // WriteToVCG - Dump the specified structure to a VCG file.  If method is
49 // dumped, then the file named is created.  If a module is to be written, a
50 // family of files with a common base name is created, with a method name
51 // suffix.
52 //
53 void WriteToVCG(const Module *Module, const string &Filename);
54 void WriteToVCG(const Method *Method, const string &Filename);
55
56
57
58
59 // Define operator<< to work on the various classes that we can send to an 
60 // ostream...
61 //
62 inline ostream &operator<<(ostream &o, const Module *C) {
63   WriteToAssembly(C, o); return o;
64 }
65
66 inline ostream &operator<<(ostream &o, const GlobalVariable *G) {
67   WriteToAssembly(G, o); return o;
68 }
69
70 inline ostream &operator<<(ostream &o, const Method *M) {
71   WriteToAssembly(M, o); return o;
72 }
73
74 inline ostream &operator<<(ostream &o, const BasicBlock *B) {
75   WriteToAssembly(B, o); return o;
76 }
77
78 inline ostream &operator<<(ostream &o, const Instruction *I) {
79   WriteToAssembly(I, o); return o;
80 }
81
82 inline ostream &operator<<(ostream &o, const ConstPoolVal *I) {
83   WriteToAssembly(I, o); return o;
84 }
85
86
87 inline ostream &operator<<(ostream &o, const Type *T) {
88   if (!T) return o << "<null Type>";
89   return o << T->getDescription();
90 }
91
92 #endif