1 //===-- llvm/assembly/Writer.h - Printer for VM assembly files ---*- C++ -*--=//
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.
8 // This library uses the Analysis library to figure out offsets for
9 // variables in the method tables...
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_ASSEMBLY_WRITER_H
14 #define LLVM_ASSEMBLY_WRITER_H
17 #include "llvm/Type.h"
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)
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);
36 // Define operator<< to work on the various classes that we can send to an
39 inline ostream &operator<<(ostream &o, const Module *C) {
40 WriteToAssembly(C, o); return o;
43 inline ostream &operator<<(ostream &o, const Method *M) {
44 WriteToAssembly(M, o); return o;
47 inline ostream &operator<<(ostream &o, const BasicBlock *B) {
48 WriteToAssembly(B, o); return o;
51 inline ostream &operator<<(ostream &o, const Instruction *I) {
52 WriteToAssembly(I, o); return o;
55 inline ostream &operator<<(ostream &o, const ConstPoolVal *I) {
56 WriteToAssembly(I, o); return o;
60 inline ostream &operator<<(ostream &o, const Type *T) {
61 if (!T) return o << "<null Type>";
62 return o << T->getName();
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() << ">";