summaryrefslogtreecommitdiff
path: root/include/llvm/Assembly/CachedWriter.h
blob: f5c947be52d74853dd301f708b5f28d8400a3019 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//===-- llvm/Assembly/CachedWriter.h - Printer Accellerator -----*- C++ -*-===//
// 
//                     The LLVM Compiler Infrastructure
//
// This file was developed by the LLVM research group and is distributed under
// the University of Illinois Open Source License. See LICENSE.TXT for details.
// 
//===----------------------------------------------------------------------===//
//
// This file defines a 'CachedWriter' class that is used to accelerate printing
// chunks of LLVM.  This is used when a module is not being changed, but random
// parts of it need to be printed.  This can greatly speed up printing of LLVM
// output.
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_ASSEMBLY_CACHEDWRITER_H
#define LLVM_ASSEMBLY_CACHEDWRITER_H

#include "llvm/Value.h"
#include <iostream>

namespace llvm {

class Module;
class PointerType;
class AssemblyWriter;  // Internal private class
class SlotMachine;

class CachedWriter {
  AssemblyWriter *AW;
  SlotMachine *SC;
  bool SymbolicTypes;
  std::ostream &Out;

public:
  enum TypeWriter {
    SymTypeOn,
    SymTypeOff
  };

  CachedWriter(std::ostream &O = std::cout)
    : AW(0), SC(0), SymbolicTypes(false), Out(O) { }
  CachedWriter(const Module *M, std::ostream &O = std::cout)
    : AW(0), SC(0), SymbolicTypes(false), Out(O) {
    setModule(M);
  }
  ~CachedWriter();

  // setModule - Invalidate internal state, use the new module instead.
  void setModule(const Module *M);

  CachedWriter &operator<<(const Value &V);

  CachedWriter &operator<<(const Type &X);

  inline CachedWriter &operator<<(std::ostream &(&Manip)(std::ostream &)) {
    Out << Manip; return *this;
  }

  inline CachedWriter& operator<<(const char *X) {
    Out << X;
    return *this;
  }

  inline CachedWriter &operator<<(enum TypeWriter tw) {
    SymbolicTypes = (tw == SymTypeOn);
    return *this;
  }
};

} // End llvm namespace

#endif