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