* Minor cleanups
[oota-llvm.git] / include / llvm / Assembly / CachedWriter.h
1 //===-- llvm/Assembly/CachedWriter.h - Printer Accellerator ------*- C++ -*--=//
2 //
3 // This file defines a 'CacheWriter' class that is used to accelerate printing
4 // chunks of LLVM.  This is used when a module is not being changed, but random
5 // parts of it need to be printed.  This can greatly speed up printing of LLVM
6 // output.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef LLVM_ASSEMBLY_CACHED_WRITER_H
11 #define LLVM_ASSEMBLY_CACHED_WRITER_H
12
13 #include "llvm/Assembly/Writer.h"
14 #include <iostream>
15
16 class AssemblyWriter;  // Internal private class
17 class SlotCalculator;
18
19 class CachedWriter {
20   AssemblyWriter *AW;
21   SlotCalculator *SC;
22 public:
23   std::ostream &Out;
24 public:
25   CachedWriter(std::ostream &O = std::cout) : AW(0), SC(0), Out(O) { }
26   CachedWriter(const Module *M, std::ostream &O = std::cout)
27     : AW(0), SC(0), Out(O) {
28     setModule(M);
29   }
30   ~CachedWriter();
31
32   // setModule - Invalidate internal state, use the new module instead.
33   void setModule(const Module *M);
34
35   CachedWriter &operator<<(const Value *V);
36
37   inline CachedWriter &operator<<(Value *X) {
38     return *this << (const Value*)X;
39   }
40   inline CachedWriter &operator<<(const Module *X) {
41     return *this << (const Value*)X;
42   }
43   inline CachedWriter &operator<<(const GlobalVariable *X) {
44     return *this << (const Value*)X;
45   }
46   inline CachedWriter &operator<<(const Method *X) {
47     return *this << (const Value*)X;
48   }
49   inline CachedWriter &operator<<(const MethodArgument *X) {
50     return *this << (const Value*)X;
51   }
52   inline CachedWriter &operator<<(const BasicBlock *X) {
53     return *this << (const Value*)X;
54   }
55   inline CachedWriter &operator<<(const Instruction *X) {
56     return *this << (const Value*)X; 
57   }
58   inline CachedWriter &operator<<(const Constant *X) {
59     return *this << (const Value*)X; 
60   }
61   inline CachedWriter &operator<<(const Type *X) {
62     return *this << (const Value*)X;
63   }
64   inline CachedWriter &operator<<(const PointerType *X) {
65     return *this << (const Value*)X; 
66   }
67
68   inline CachedWriter &operator<<(std::ostream &(&Manip)(std::ostream &)) {
69     Out << Manip; return *this;
70   }
71
72   template<class X>
73   inline CachedWriter &operator<<(const X &v) {
74     Out << v;
75     return *this;
76   }
77 };
78
79 #endif