1 //===-- llvm/Assembly/Writer.h - Printer for VM assembly files ---*- C++ -*--=//
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.
8 // This file also defines functions that allow it to output files that a program
9 // called VCG can read.
11 // This library uses the Analysis library to figure out offsets for
12 // variables in the method tables...
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_ASSEMBLY_WRITER_H
17 #define LLVM_ASSEMBLY_WRITER_H
20 #include "llvm/Type.h"
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)
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);
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.
44 ostream &WriteAsOperand(ostream &o, const Value *V, bool PrintType = true,
45 bool PrintName = true, SlotCalculator *Table = 0);
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
53 void WriteToVCG(const Module *Module, const string &Filename);
54 void WriteToVCG(const Method *Method, const string &Filename);
59 // Define operator<< to work on the various classes that we can send to an
62 inline ostream &operator<<(ostream &o, const Module *C) {
63 WriteToAssembly(C, o); return o;
66 inline ostream &operator<<(ostream &o, const GlobalVariable *G) {
67 WriteToAssembly(G, o); return o;
70 inline ostream &operator<<(ostream &o, const Method *M) {
71 WriteToAssembly(M, o); return o;
74 inline ostream &operator<<(ostream &o, const BasicBlock *B) {
75 WriteToAssembly(B, o); return o;
78 inline ostream &operator<<(ostream &o, const Instruction *I) {
79 WriteToAssembly(I, o); return o;
82 inline ostream &operator<<(ostream &o, const ConstPoolVal *I) {
83 WriteToAssembly(I, o); return o;
87 inline ostream &operator<<(ostream &o, const Type *T) {
88 if (!T) return o << "<null Type>";
89 return o << T->getDescription();
92 inline ostream &operator<<(ostream &o, const Value *I) {
93 switch (I->getValueType()) {
94 case Value::TypeVal: return o << cast<const Type>(I);
95 case Value::ConstantVal: WriteToAssembly(cast<ConstPoolVal>(I) , o); break;
96 case Value::MethodArgumentVal: return o << I->getType() << " "<< I->getName();
97 case Value::InstructionVal:WriteToAssembly(cast<Instruction>(I) , o); break;
98 case Value::BasicBlockVal: WriteToAssembly(cast<BasicBlock>(I) , o); break;
99 case Value::MethodVal: WriteToAssembly(cast<Method>(I) , o); break;
100 case Value::GlobalVal: WriteToAssembly(cast<GlobalVariable>(I), o); break;
101 case Value::ModuleVal: WriteToAssembly(cast<Module>(I) , o); break;
102 default: return o << "<unknown value type: " << I->getValueType() << ">";