LLVM  10.0.0svn
Printable.h
Go to the documentation of this file.
1 //===--- Printable.h - Print function helpers -------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines the Printable struct.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_SUPPORT_PRINTABLE_H
14 #define LLVM_SUPPORT_PRINTABLE_H
15 
16 #include <functional>
17 
18 namespace llvm {
19 
20 class raw_ostream;
21 
22 /// Simple wrapper around std::function<void(raw_ostream&)>.
23 /// This class is useful to construct print helpers for raw_ostream.
24 ///
25 /// Example:
26 /// Printable PrintRegister(unsigned Register) {
27 /// return Printable([Register](raw_ostream &OS) {
28 /// OS << getRegisterName(Register);
29 /// }
30 /// }
31 /// ... OS << PrintRegister(Register); ...
32 ///
33 /// Implementation note: Ideally this would just be a typedef, but doing so
34 /// leads to operator << being ambiguous as function has matching constructors
35 /// in some STL versions. I have seen the problem on gcc 4.6 libstdc++ and
36 /// microsoft STL.
37 class Printable {
38 public:
39  std::function<void(raw_ostream &OS)> Print;
41  : Print(std::move(Print)) {}
42 };
43 
45  P.Print(OS);
46  return OS;
47 }
48 
49 }
50 
51 #endif
Printable(std::function< void(raw_ostream &OS)> Print)
Definition: Printable.h:40
This class represents lattice values for constants.
Definition: AllocatorList.h:23
Definition: BitVector.h:937
#define P(N)
raw_ostream & operator<<(raw_ostream &OS, const APInt &I)
Definition: APInt.h:2038
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:45
std::function< void(raw_ostream &OS)> Print
Definition: Printable.h:39
print Print MemDeps of function
Simple wrapper around std::function<void(raw_ostream&)>.
Definition: Printable.h:37