71e2f4e0543a2c625fd086c0a5ffd1c4a9a37474
[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 library uses the Analysis library to figure out offsets for
9 // variables in the method tables...
10 //
11 //===----------------------------------------------------------------------===//
12
13 #ifndef LLVM_ASSEMBLY_WRITER_H
14 #define LLVM_ASSEMBLY_WRITER_H
15
16 #include <iostream>
17 #include "llvm/Type.h"
18
19 class Module;
20 class Method;
21 class BasicBlock;
22 class Instruction;
23
24 // The only interface defined by this file... convert the internal 
25 // representation of an object into an ascii bytestream that the parser can 
26 // understand later... (the parser only understands whole classes though)
27 //
28 void WriteToAssembly(const Module  *Module, ostream &o);
29 void WriteToAssembly(const Method  *Method, ostream &o);
30 void WriteToAssembly(const BasicBlock  *BB, ostream &o);
31 void WriteToAssembly(const Instruction *In, ostream &o);
32 void WriteToAssembly(const ConstPoolVal *V, ostream &o);
33
34
35
36 // Define operator<< to work on the various classes that we can send to an 
37 // ostream...
38 //
39 inline ostream &operator<<(ostream &o, const Module *C) {
40   WriteToAssembly(C, o); return o;
41 }
42
43 inline ostream &operator<<(ostream &o, const Method *M) {
44   WriteToAssembly(M, o); return o;
45 }
46
47 inline ostream &operator<<(ostream &o, const BasicBlock *B) {
48   WriteToAssembly(B, o); return o;
49 }
50
51 inline ostream &operator<<(ostream &o, const Instruction *I) {
52   WriteToAssembly(I, o); return o;
53 }
54
55 inline ostream &operator<<(ostream &o, const ConstPoolVal *I) {
56   WriteToAssembly(I, o); return o;
57 }
58
59
60 inline ostream &operator<<(ostream &o, const Type *T) {
61   if (!T) return o << "<null Type>";
62   return o << T->getName();
63 }
64
65 inline ostream &operator<<(ostream &o, const Value *I) {
66   switch (I->getValueType()) {
67   case Value::TypeVal:        return o << (const Type*)I;
68   case Value::ConstantVal:    WriteToAssembly((const ConstPoolVal*)I, o); break;
69   case Value::MethodArgumentVal: return o <<I->getType() << " " << I->getName();
70   case Value::InstructionVal: WriteToAssembly((const Instruction *)I, o); break;
71   case Value::BasicBlockVal:  WriteToAssembly((const BasicBlock  *)I, o); break;
72   case Value::MethodVal:      WriteToAssembly((const Method      *)I, o); break;
73   case Value::ModuleVal:      WriteToAssembly((const Module      *)I, o); break;
74   default: return o << "<unknown value type: " << I->getValueType() << ">";
75   }
76   return o;
77 }
78
79 #endif