LCOV - code coverage report
Current view: top level - include/llvm/MC - StringTableBuilder.h (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 4 4 100.0 %
Date: 2017-09-14 15:23:50 Functions: 3 3 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- StringTableBuilder.h - String table building utility -----*- C++ -*-===//
       2             : //
       3             : //                     The LLVM Compiler Infrastructure
       4             : //
       5             : // This file is distributed under the University of Illinois Open Source
       6             : // License. See LICENSE.TXT for details.
       7             : //
       8             : //===----------------------------------------------------------------------===//
       9             : 
      10             : #ifndef LLVM_MC_STRINGTABLEBUILDER_H
      11             : #define LLVM_MC_STRINGTABLEBUILDER_H
      12             : 
      13             : #include "llvm/ADT/CachedHashString.h"
      14             : #include "llvm/ADT/DenseMap.h"
      15             : #include "llvm/ADT/StringRef.h"
      16             : #include <cstddef>
      17             : #include <cstdint>
      18             : 
      19             : namespace llvm {
      20             : 
      21             : class raw_ostream;
      22             : 
      23             : /// \brief Utility for building string tables with deduplicated suffixes.
      24       19392 : class StringTableBuilder {
      25             : public:
      26             :   enum Kind { ELF, WinCOFF, MachO, RAW };
      27             : 
      28             : private:
      29             :   DenseMap<CachedHashStringRef, size_t> StringIndexMap;
      30             :   size_t Size = 0;
      31             :   Kind K;
      32             :   unsigned Alignment;
      33             :   bool Finalized = false;
      34             : 
      35             :   void finalizeStringTable(bool Optimize);
      36             :   void initSize();
      37             : 
      38             : public:
      39             :   StringTableBuilder(Kind K, unsigned Alignment = 1);
      40             :   ~StringTableBuilder();
      41             : 
      42             :   /// \brief Add a string to the builder. Returns the position of S in the
      43             :   /// table. The position will be changed if finalize is used.
      44             :   /// Can only be used before the table is finalized.
      45             :   size_t add(CachedHashStringRef S);
      46     1057825 :   size_t add(StringRef S) { return add(CachedHashStringRef(S)); }
      47             : 
      48             :   /// \brief Analyze the strings and build the final table. No more strings can
      49             :   /// be added after this point.
      50             :   void finalize();
      51             : 
      52             :   /// Finalize the string table without reording it. In this mode, offsets
      53             :   /// returned by add will still be valid.
      54             :   void finalizeInOrder();
      55             : 
      56             :   /// \brief Get the offest of a string in the string table. Can only be used
      57             :   /// after the table is finalized.
      58             :   size_t getOffset(CachedHashStringRef S) const;
      59      482007 :   size_t getOffset(StringRef S) const {
      60      482008 :     return getOffset(CachedHashStringRef(S));
      61             :   }
      62             : 
      63             :   size_t getSize() const { return Size; }
      64             :   void clear();
      65             : 
      66             :   void write(raw_ostream &OS) const;
      67             :   void write(uint8_t *Buf) const;
      68             : 
      69             : private:
      70             :   bool isFinalized() const { return Finalized; }
      71             : };
      72             : 
      73             : } // end namespace llvm
      74             : 
      75             : #endif // LLVM_MC_STRINGTABLEBUILDER_H

Generated by: LCOV version 1.13