003 File Manager
Current Path:
/usr/src/contrib/llvm-project/llvm/include/llvm/Support
usr
/
src
/
contrib
/
llvm-project
/
llvm
/
include
/
llvm
/
Support
/
📁
..
📄
AArch64TargetParser.def
(12.01 KB)
📄
AArch64TargetParser.h
(4.89 KB)
📄
AMDGPUMetadata.h
(17.98 KB)
📄
AMDHSAKernelDescriptor.h
(7.63 KB)
📄
ARMAttributeParser.h
(3.2 KB)
📄
ARMBuildAttributes.h
(8.6 KB)
📄
ARMEHABI.h
(3.72 KB)
📄
ARMTargetParser.def
(18.94 KB)
📄
ARMTargetParser.h
(8.76 KB)
📄
ARMWinEH.h
(18.27 KB)
📄
AlignOf.h
(1.56 KB)
📄
Alignment.h
(12.95 KB)
📄
Allocator.h
(16.54 KB)
📄
AllocatorBase.h
(3.87 KB)
📄
ArrayRecycler.h
(4.78 KB)
📄
Atomic.h
(1.09 KB)
📄
AtomicOrdering.h
(6.01 KB)
📄
Automaton.h
(9.64 KB)
📄
Base64.h
(1.84 KB)
📄
BinaryByteStream.h
(9.14 KB)
📄
BinaryItemStream.h
(3.63 KB)
📄
BinaryStream.h
(3.75 KB)
📄
BinaryStreamArray.h
(12.46 KB)
📄
BinaryStreamError.h
(1.29 KB)
📄
BinaryStreamReader.h
(11.01 KB)
📄
BinaryStreamRef.h
(10.09 KB)
📄
BinaryStreamWriter.h
(7.79 KB)
📄
BlockFrequency.h
(2.41 KB)
📄
BranchProbability.h
(7.92 KB)
📄
BuryPointer.h
(1.03 KB)
📄
CBindingWrapping.h
(1.86 KB)
📄
CFGDiff.h
(9.95 KB)
📄
CFGUpdate.h
(4.12 KB)
📄
COM.h
(1004 B)
📄
CRC.h
(1.63 KB)
📄
CachePruning.h
(3.5 KB)
📄
Capacity.h
(972 B)
📄
Casting.h
(13.92 KB)
📄
CheckedArithmetic.h
(3.71 KB)
📄
Chrono.h
(5.78 KB)
📄
CodeGen.h
(1.96 KB)
📄
CodeGenCoverage.h
(1.18 KB)
📄
CommandLine.h
(71.22 KB)
📄
Compiler.h
(19.5 KB)
📄
Compression.h
(1.39 KB)
📄
ConvertUTF.h
(11.4 KB)
📄
CrashRecoveryContext.h
(9.26 KB)
📄
DJB.h
(1.05 KB)
📄
DOTGraphTraits.h
(5.58 KB)
📄
DataExtractor.h
(30.28 KB)
📄
DataTypes.h
(775 B)
📄
Debug.h
(4.7 KB)
📄
DebugCounter.h
(7.01 KB)
📄
DynamicLibrary.h
(5.77 KB)
📄
ELFAttributeParser.h
(2.22 KB)
📄
ELFAttributes.h
(1.02 KB)
📄
Endian.h
(14.28 KB)
📄
EndianStream.h
(1.93 KB)
📄
Errc.h
(3.8 KB)
📄
Errno.h
(1.45 KB)
📄
Error.h
(43.82 KB)
📄
ErrorHandling.h
(6.39 KB)
📄
ErrorOr.h
(7.48 KB)
📄
ExtensibleRTTI.h
(4.02 KB)
📄
FileCheck.h
(6.69 KB)
📄
FileCollector.h
(3.74 KB)
📄
FileOutputBuffer.h
(3.36 KB)
📄
FileSystem.h
(53.03 KB)
📄
FileUtilities.h
(3.83 KB)
📄
Format.h
(9.45 KB)
📄
FormatAdapters.h
(3.38 KB)
📄
FormatCommon.h
(2.05 KB)
📄
FormatProviders.h
(15.27 KB)
📄
FormatVariadic.h
(9.88 KB)
📄
FormatVariadicDetails.h
(5.3 KB)
📄
FormattedStream.h
(6.42 KB)
📄
GenericDomTree.h
(30.89 KB)
📄
GenericDomTreeConstruction.h
(63.42 KB)
📄
GenericIteratedDominanceFrontier.h
(7.31 KB)
📄
GlobPattern.h
(1.35 KB)
📄
GraphWriter.h
(11.79 KB)
📄
Host.h
(2.68 KB)
📄
InitLLVM.h
(1.79 KB)
📄
ItaniumManglingCanonicalizer.h
(3.17 KB)
📄
JSON.h
(28.25 KB)
📄
KnownBits.h
(8.35 KB)
📄
LEB128.h
(5.74 KB)
📄
LineIterator.h
(2.62 KB)
📄
Locale.h
(223 B)
📄
LockFileManager.h
(3.13 KB)
📄
LowLevelTypeImpl.h
(11.94 KB)
📄
MD5.h
(3.39 KB)
📄
MSVCErrorWorkarounds.h
(2.62 KB)
📄
MachineValueType.h
(42.37 KB)
📄
ManagedStatic.h
(4.21 KB)
📄
MathExtras.h
(32.81 KB)
📄
MemAlloc.h
(3.21 KB)
📄
Memory.h
(6.94 KB)
📄
MemoryBuffer.h
(10.98 KB)
📄
MipsABIFlags.h
(3.92 KB)
📄
Mutex.h
(2.14 KB)
📄
NativeFormatting.h
(1.64 KB)
📄
OnDiskHashTable.h
(21.97 KB)
📄
OptimizedStructLayout.h
(5.89 KB)
📄
Parallel.h
(5.99 KB)
📄
Path.h
(15.6 KB)
📄
PluginLoader.h
(1.29 KB)
📄
PointerLikeTypeTraits.h
(5.69 KB)
📄
PrettyStackTrace.h
(4.45 KB)
📄
Printable.h
(1.5 KB)
📄
Process.h
(9.31 KB)
📄
Program.h
(10.35 KB)
📄
RISCVAttributeParser.h
(1.15 KB)
📄
RISCVAttributes.h
(1.2 KB)
📄
RISCVTargetParser.def
(446 B)
📄
RWMutex.h
(5.65 KB)
📄
RandomNumberGenerator.h
(2.29 KB)
📄
Recycler.h
(3.47 KB)
📄
RecyclingAllocator.h
(2.38 KB)
📄
Regex.h
(4.37 KB)
📄
Registry.h
(5.14 KB)
📄
ReverseIteration.h
(360 B)
📄
SHA1.h
(2.37 KB)
📄
SMLoc.h
(1.78 KB)
📄
SMTAPI.h
(16.33 KB)
📄
SaveAndRestore.h
(1.02 KB)
📄
ScaledNumber.h
(30.65 KB)
📄
ScopedPrinter.h
(11.39 KB)
📄
Signals.h
(5.22 KB)
📄
Signposts.h
(1.29 KB)
📄
SmallVectorMemoryBuffer.h
(2.28 KB)
📁
Solaris
📄
SourceMgr.h
(10.37 KB)
📄
SpecialCaseList.h
(6.01 KB)
📄
StringSaver.h
(1.94 KB)
📄
SuffixTree.h
(13.15 KB)
📄
SwapByteOrder.h
(4.8 KB)
📄
SymbolRemappingReader.h
(4.36 KB)
📄
SystemUtils.h
(1.02 KB)
📄
TarWriter.h
(941 B)
📄
TargetOpcodes.def
(22.01 KB)
📄
TargetParser.h
(4.08 KB)
📄
TargetRegistry.h
(46.87 KB)
📄
TargetSelect.h
(6.2 KB)
📄
TaskQueue.h
(4.24 KB)
📄
ThreadLocal.h
(2.08 KB)
📄
ThreadPool.h
(3.44 KB)
📄
Threading.h
(10.62 KB)
📄
TimeProfiler.h
(3.46 KB)
📄
Timer.h
(8.93 KB)
📄
ToolOutputFile.h
(2.24 KB)
📄
TrailingObjects.h
(15.19 KB)
📄
TrigramIndex.h
(2.84 KB)
📄
TypeName.h
(2.13 KB)
📄
TypeSize.h
(8.53 KB)
📄
Unicode.h
(2.5 KB)
📄
UnicodeCharRanges.h
(3.27 KB)
📄
Valgrind.h
(1.16 KB)
📄
VersionTuple.h
(5.22 KB)
📄
VirtualFileSystem.h
(28.28 KB)
📄
Watchdog.h
(1.15 KB)
📄
Win64EH.h
(4.82 KB)
📁
Windows
📄
WindowsError.h
(541 B)
📄
WithColor.h
(4.64 KB)
📄
X86DisassemblerDecoderCommon.h
(29.39 KB)
📄
X86TargetParser.def
(8.21 KB)
📄
X86TargetParser.h
(3.57 KB)
📄
YAMLParser.h
(16.29 KB)
📄
YAMLTraits.h
(67.62 KB)
📄
circular_raw_ostream.h
(4.97 KB)
📄
raw_os_ostream.h
(1.29 KB)
📄
raw_ostream.h
(20.82 KB)
📄
raw_sha1_ostream.h
(1.29 KB)
📄
thread.h
(1.33 KB)
📄
type_traits.h
(6.75 KB)
📄
xxhash.h
(1.92 KB)
Editing: BinaryStreamArray.h
//===- BinaryStreamArray.h - Array backed by an arbitrary stream *- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// #ifndef LLVM_SUPPORT_BINARYSTREAMARRAY_H #define LLVM_SUPPORT_BINARYSTREAMARRAY_H #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/iterator.h" #include "llvm/Support/Alignment.h" #include "llvm/Support/BinaryStreamRef.h" #include "llvm/Support/Error.h" #include <cassert> #include <cstdint> /// Lightweight arrays that are backed by an arbitrary BinaryStream. This file /// provides two different array implementations. /// /// VarStreamArray - Arrays of variable length records. The user specifies /// an Extractor type that can extract a record from a given offset and /// return the number of bytes consumed by the record. /// /// FixedStreamArray - Arrays of fixed length records. This is similar in /// spirit to ArrayRef<T>, but since it is backed by a BinaryStream, the /// elements of the array need not be laid out in contiguous memory. namespace llvm { /// VarStreamArrayExtractor is intended to be specialized to provide customized /// extraction logic. On input it receives a BinaryStreamRef pointing to the /// beginning of the next record, but where the length of the record is not yet /// known. Upon completion, it should return an appropriate Error instance if /// a record could not be extracted, or if one could be extracted it should /// return success and set Len to the number of bytes this record occupied in /// the underlying stream, and it should fill out the fields of the value type /// Item appropriately to represent the current record. /// /// You can specialize this template for your own custom value types to avoid /// having to specify a second template argument to VarStreamArray (documented /// below). template <typename T> struct VarStreamArrayExtractor { // Method intentionally deleted. You must provide an explicit specialization // with the following method implemented. Error operator()(BinaryStreamRef Stream, uint32_t &Len, T &Item) const = delete; }; /// VarStreamArray represents an array of variable length records backed by a /// stream. This could be a contiguous sequence of bytes in memory, it could /// be a file on disk, or it could be a PDB stream where bytes are stored as /// discontiguous blocks in a file. Usually it is desirable to treat arrays /// as contiguous blocks of memory, but doing so with large PDB files, for /// example, could mean allocating huge amounts of memory just to allow /// re-ordering of stream data to be contiguous before iterating over it. By /// abstracting this out, we need not duplicate this memory, and we can /// iterate over arrays in arbitrarily formatted streams. Elements are parsed /// lazily on iteration, so there is no upfront cost associated with building /// or copying a VarStreamArray, no matter how large it may be. /// /// You create a VarStreamArray by specifying a ValueType and an Extractor type. /// If you do not specify an Extractor type, you are expected to specialize /// VarStreamArrayExtractor<T> for your ValueType. /// /// By default an Extractor is default constructed in the class, but in some /// cases you might find it useful for an Extractor to maintain state across /// extractions. In this case you can provide your own Extractor through a /// secondary constructor. The following examples show various ways of /// creating a VarStreamArray. /// /// // Will use VarStreamArrayExtractor<MyType> as the extractor. /// VarStreamArray<MyType> MyTypeArray; /// /// // Will use a default-constructed MyExtractor as the extractor. /// VarStreamArray<MyType, MyExtractor> MyTypeArray2; /// /// // Will use the specific instance of MyExtractor provided. /// // MyExtractor need not be default-constructible in this case. /// MyExtractor E(SomeContext); /// VarStreamArray<MyType, MyExtractor> MyTypeArray3(E); /// template <typename ValueType, typename Extractor> class VarStreamArrayIterator; template <typename ValueType, typename Extractor = VarStreamArrayExtractor<ValueType>> class VarStreamArray { friend class VarStreamArrayIterator<ValueType, Extractor>; public: typedef VarStreamArrayIterator<ValueType, Extractor> Iterator; VarStreamArray() = default; explicit VarStreamArray(const Extractor &E) : E(E) {} explicit VarStreamArray(BinaryStreamRef Stream, uint32_t Skew = 0) : Stream(Stream), Skew(Skew) {} VarStreamArray(BinaryStreamRef Stream, const Extractor &E, uint32_t Skew = 0) : Stream(Stream), E(E), Skew(Skew) {} Iterator begin(bool *HadError = nullptr) const { return Iterator(*this, E, Skew, nullptr); } bool valid() const { return Stream.valid(); } uint32_t skew() const { return Skew; } Iterator end() const { return Iterator(E); } bool empty() const { return Stream.getLength() == 0; } VarStreamArray<ValueType, Extractor> substream(uint32_t Begin, uint32_t End) const { assert(Begin >= Skew); // We should never cut off the beginning of the stream since it might be // skewed, meaning the initial bytes are important. BinaryStreamRef NewStream = Stream.slice(0, End); return {NewStream, E, Begin}; } /// given an offset into the array's underlying stream, return an /// iterator to the record at that offset. This is considered unsafe /// since the behavior is undefined if \p Offset does not refer to the /// beginning of a valid record. Iterator at(uint32_t Offset) const { return Iterator(*this, E, Offset, nullptr); } const Extractor &getExtractor() const { return E; } Extractor &getExtractor() { return E; } BinaryStreamRef getUnderlyingStream() const { return Stream; } void setUnderlyingStream(BinaryStreamRef NewStream, uint32_t NewSkew = 0) { Stream = NewStream; Skew = NewSkew; } void drop_front() { Skew += begin()->length(); } private: BinaryStreamRef Stream; Extractor E; uint32_t Skew = 0; }; template <typename ValueType, typename Extractor> class VarStreamArrayIterator : public iterator_facade_base<VarStreamArrayIterator<ValueType, Extractor>, std::forward_iterator_tag, ValueType> { typedef VarStreamArrayIterator<ValueType, Extractor> IterType; typedef VarStreamArray<ValueType, Extractor> ArrayType; public: VarStreamArrayIterator(const ArrayType &Array, const Extractor &E, uint32_t Offset, bool *HadError) : IterRef(Array.Stream.drop_front(Offset)), Extract(E), Array(&Array), AbsOffset(Offset), HadError(HadError) { if (IterRef.getLength() == 0) moveToEnd(); else { auto EC = Extract(IterRef, ThisLen, ThisValue); if (EC) { consumeError(std::move(EC)); markError(); } } } VarStreamArrayIterator() = default; explicit VarStreamArrayIterator(const Extractor &E) : Extract(E) {} ~VarStreamArrayIterator() = default; bool operator==(const IterType &R) const { if (Array && R.Array) { // Both have a valid array, make sure they're same. assert(Array == R.Array); return IterRef == R.IterRef; } // Both iterators are at the end. if (!Array && !R.Array) return true; // One is not at the end and one is. return false; } const ValueType &operator*() const { assert(Array && !HasError); return ThisValue; } ValueType &operator*() { assert(Array && !HasError); return ThisValue; } IterType &operator+=(unsigned N) { for (unsigned I = 0; I < N; ++I) { // We are done with the current record, discard it so that we are // positioned at the next record. AbsOffset += ThisLen; IterRef = IterRef.drop_front(ThisLen); if (IterRef.getLength() == 0) { // There is nothing after the current record, we must make this an end // iterator. moveToEnd(); } else { // There is some data after the current record. auto EC = Extract(IterRef, ThisLen, ThisValue); if (EC) { consumeError(std::move(EC)); markError(); } else if (ThisLen == 0) { // An empty record? Make this an end iterator. moveToEnd(); } } } return *this; } uint32_t offset() const { return AbsOffset; } uint32_t getRecordLength() const { return ThisLen; } private: void moveToEnd() { Array = nullptr; ThisLen = 0; } void markError() { moveToEnd(); HasError = true; if (HadError != nullptr) *HadError = true; } ValueType ThisValue; BinaryStreamRef IterRef; Extractor Extract; const ArrayType *Array{nullptr}; uint32_t ThisLen{0}; uint32_t AbsOffset{0}; bool HasError{false}; bool *HadError{nullptr}; }; template <typename T> class FixedStreamArrayIterator; /// FixedStreamArray is similar to VarStreamArray, except with each record /// having a fixed-length. As with VarStreamArray, there is no upfront /// cost associated with building or copying a FixedStreamArray, as the /// memory for each element is not read from the backing stream until that /// element is iterated. template <typename T> class FixedStreamArray { friend class FixedStreamArrayIterator<T>; public: typedef FixedStreamArrayIterator<T> Iterator; FixedStreamArray() = default; explicit FixedStreamArray(BinaryStreamRef Stream) : Stream(Stream) { assert(Stream.getLength() % sizeof(T) == 0); } bool operator==(const FixedStreamArray<T> &Other) const { return Stream == Other.Stream; } bool operator!=(const FixedStreamArray<T> &Other) const { return !(*this == Other); } FixedStreamArray(const FixedStreamArray &) = default; FixedStreamArray &operator=(const FixedStreamArray &) = default; const T &operator[](uint32_t Index) const { assert(Index < size()); uint32_t Off = Index * sizeof(T); ArrayRef<uint8_t> Data; if (auto EC = Stream.readBytes(Off, sizeof(T), Data)) { assert(false && "Unexpected failure reading from stream"); // This should never happen since we asserted that the stream length was // an exact multiple of the element size. consumeError(std::move(EC)); } assert(isAddrAligned(Align::Of<T>(), Data.data())); return *reinterpret_cast<const T *>(Data.data()); } uint32_t size() const { return Stream.getLength() / sizeof(T); } bool empty() const { return size() == 0; } FixedStreamArrayIterator<T> begin() const { return FixedStreamArrayIterator<T>(*this, 0); } FixedStreamArrayIterator<T> end() const { return FixedStreamArrayIterator<T>(*this, size()); } const T &front() const { return *begin(); } const T &back() const { FixedStreamArrayIterator<T> I = end(); return *(--I); } BinaryStreamRef getUnderlyingStream() const { return Stream; } private: BinaryStreamRef Stream; }; template <typename T> class FixedStreamArrayIterator : public iterator_facade_base<FixedStreamArrayIterator<T>, std::random_access_iterator_tag, const T> { public: FixedStreamArrayIterator(const FixedStreamArray<T> &Array, uint32_t Index) : Array(Array), Index(Index) {} FixedStreamArrayIterator<T>(const FixedStreamArrayIterator<T> &Other) : Array(Other.Array), Index(Other.Index) {} FixedStreamArrayIterator<T> & operator=(const FixedStreamArrayIterator<T> &Other) { Array = Other.Array; Index = Other.Index; return *this; } const T &operator*() const { return Array[Index]; } const T &operator*() { return Array[Index]; } bool operator==(const FixedStreamArrayIterator<T> &R) const { assert(Array == R.Array); return (Index == R.Index) && (Array == R.Array); } FixedStreamArrayIterator<T> &operator+=(std::ptrdiff_t N) { Index += N; return *this; } FixedStreamArrayIterator<T> &operator-=(std::ptrdiff_t N) { assert(std::ptrdiff_t(Index) >= N); Index -= N; return *this; } std::ptrdiff_t operator-(const FixedStreamArrayIterator<T> &R) const { assert(Array == R.Array); assert(Index >= R.Index); return Index - R.Index; } bool operator<(const FixedStreamArrayIterator<T> &RHS) const { assert(Array == RHS.Array); return Index < RHS.Index; } private: FixedStreamArray<T> Array; uint32_t Index; }; } // namespace llvm #endif // LLVM_SUPPORT_BINARYSTREAMARRAY_H
Upload File
Create Folder