a0f05cf6779ad2c8a028c5b780aa1bfc600b7081
[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/Value.h"
14 #include <iostream>
15
16 class Module;
17 class PointerType;
18 class SlotCalculator;
19 class AssemblyWriter;  // Internal private class
20
21 class CachedWriter {
22   AssemblyWriter *AW;
23   SlotCalculator *SC;
24 public:
25   std::ostream &Out;
26 public:
27   CachedWriter(std::ostream &O = std::cout) : AW(0), SC(0), Out(O) { }
28   CachedWriter(const Module *M, std::ostream &O = std::cout)
29     : AW(0), SC(0), Out(O) {
30     setModule(M);
31   }
32   ~CachedWriter();
33
34   // setModule - Invalidate internal state, use the new module instead.
35   void setModule(const Module *M);
36
37   CachedWriter &operator<<(const Value *V);
38
39   inline CachedWriter &operator<<(Value *X) {
40     return *this << (const Value*)X;
41   }
42   inline CachedWriter &operator<<(const GlobalVariable *X) {
43     return *this << (const Value*)X;
44   }
45   inline CachedWriter &operator<<(const Function *X) {
46     return *this << (const Value*)X;
47   }
48   inline CachedWriter &operator<<(const Argument *X) {
49     return *this << (const Value*)X;
50   }
51   inline CachedWriter &operator<<(const BasicBlock *X) {
52     return *this << (const Value*)X;
53   }
54   inline CachedWriter &operator<<(const Instruction *X) {
55     return *this << (const Value*)X; 
56   }
57   inline CachedWriter &operator<<(const Constant *X) {
58     return *this << (const Value*)X; 
59   }
60   inline CachedWriter &operator<<(const Type *X) {
61     return *this << (const Value*)X;
62   }
63   inline CachedWriter &operator<<(const PointerType *X) {
64     return *this << (const Value*)X; 
65   }
66
67   inline CachedWriter &operator<<(std::ostream &(&Manip)(std::ostream &)) {
68     Out << Manip; return *this;
69   }
70
71   template<class X>
72   inline CachedWriter &operator<<(const X &v) {
73     Out << v;
74     return *this;
75   }
76 };
77
78 #endif