Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:42

0001 //===- DwarfTransformer.h ---------------------------------------*- 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 #ifndef LLVM_DEBUGINFO_GSYM_OUTPUTAGGREGATOR_H
0010 #define LLVM_DEBUGINFO_GSYM_OUTPUTAGGREGATOR_H
0011 
0012 #include "llvm/ADT/StringRef.h"
0013 #include "llvm/DebugInfo/GSYM/ExtractRanges.h"
0014 
0015 #include <map>
0016 #include <string>
0017 
0018 namespace llvm {
0019 
0020 class raw_ostream;
0021 
0022 namespace gsym {
0023 
0024 class OutputAggregator {
0025 protected:
0026   // A std::map is preferable over an llvm::StringMap for presenting results
0027   // in a predictable order.
0028   std::map<std::string, unsigned> Aggregation;
0029   raw_ostream *Out;
0030 
0031 public:
0032   OutputAggregator(raw_ostream *out) : Out(out) {}
0033 
0034   size_t GetNumCategories() const { return Aggregation.size(); }
0035 
0036   void Report(StringRef s, std::function<void(raw_ostream &o)> detailCallback) {
0037     Aggregation[std::string(s)]++;
0038     if (GetOS())
0039       detailCallback(*Out);
0040   }
0041 
0042   void EnumerateResults(
0043       std::function<void(StringRef, unsigned)> handleCounts) const {
0044     for (auto &&[name, count] : Aggregation)
0045       handleCounts(name, count);
0046   }
0047 
0048   raw_ostream *GetOS() const { return Out; }
0049 
0050   // You can just use the stream, and if it's null, nothing happens.
0051   // Don't do a lot of stuff like this, but it's convenient for silly stuff.
0052   // It doesn't work with things that have custom insertion operators, though.
0053   template <typename T> OutputAggregator &operator<<(T &&value) {
0054     if (Out != nullptr)
0055       *Out << value;
0056     return *this;
0057   }
0058 
0059   // For multi-threaded usage, we can collect stuff in another aggregator,
0060   // then merge it in here. Note that this is *not* thread safe. It is up to
0061   // the caller to ensure that this is only called from one thread at a time.
0062   void Merge(const OutputAggregator &other) {
0063     for (auto &&[name, count] : other.Aggregation)
0064       Aggregation[name] += count;
0065   }
0066 };
0067 
0068 } // namespace gsym
0069 } // namespace llvm
0070 
0071 #endif // LLVM_DEBUGINFO_GSYM_OUTPUTAGGREGATOR_H