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"
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)
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);
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
42 void WriteToVCG(const Module *Module, const string &Filename);
43 void WriteToVCG(const Method *Method, const string &Filename);
48 // Define operator<< to work on the various classes that we can send to an
51 inline ostream &operator<<(ostream &o, const Module *C) {
52 WriteToAssembly(C, o); return o;
55 inline ostream &operator<<(ostream &o, const Method *M) {
56 WriteToAssembly(M, o); return o;
59 inline ostream &operator<<(ostream &o, const BasicBlock *B) {
60 WriteToAssembly(B, o); return o;
63 inline ostream &operator<<(ostream &o, const Instruction *I) {
64 WriteToAssembly(I, o); return o;
67 inline ostream &operator<<(ostream &o, const ConstPoolVal *I) {
68 WriteToAssembly(I, o); return o;
72 inline ostream &operator<<(ostream &o, const Type *T) {
73 if (!T) return o << "<null Type>";
74 return o << T->getName();
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() << ">";
91 void DebugValue(const Value *V);