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