Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:44:33

0001 //===--- Printable.h - Print function helpers -------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 //  This file defines the Printable struct.
0010 //
0011 //===----------------------------------------------------------------------===//
0012 
0013 #ifndef LLVM_SUPPORT_PRINTABLE_H
0014 #define LLVM_SUPPORT_PRINTABLE_H
0015 
0016 #include <functional>
0017 #include <utility>
0018 
0019 namespace llvm {
0020 
0021 class raw_ostream;
0022 
0023 /// Simple wrapper around std::function<void(raw_ostream&)>.
0024 /// This class is useful to construct print helpers for raw_ostream.
0025 ///
0026 /// Example:
0027 ///     Printable printRegister(unsigned Register) {
0028 ///       return Printable([Register](raw_ostream &OS) {
0029 ///         OS << getRegisterName(Register);
0030 ///       });
0031 ///     }
0032 ///     ... OS << printRegister(Register); ...
0033 ///
0034 /// Implementation note: Ideally this would just be a typedef, but doing so
0035 /// leads to operator << being ambiguous as function has matching constructors
0036 /// in some STL versions. I have seen the problem on gcc 4.6 libstdc++ and
0037 /// microsoft STL.
0038 class Printable {
0039 public:
0040   std::function<void(raw_ostream &OS)> Print;
0041   Printable(std::function<void(raw_ostream &OS)> Print)
0042       : Print(std::move(Print)) {}
0043 };
0044 
0045 inline raw_ostream &operator<<(raw_ostream &OS, const Printable &P) {
0046   P.Print(OS);
0047   return OS;
0048 }
0049 
0050 } // namespace llvm
0051 
0052 #endif