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