003 File Manager
Current Path:
/usr/src/contrib/llvm-project/llvm/lib/MC
usr
/
src
/
contrib
/
llvm-project
/
llvm
/
lib
/
MC
/
📁
..
📄
ConstantPools.cpp
(3.72 KB)
📄
ELFObjectWriter.cpp
(51.58 KB)
📄
MCAsmBackend.cpp
(4.01 KB)
📄
MCAsmInfo.cpp
(4.44 KB)
📄
MCAsmInfoCOFF.cpp
(2.17 KB)
📄
MCAsmInfoDarwin.cpp
(3.01 KB)
📄
MCAsmInfoELF.cpp
(1.05 KB)
📄
MCAsmInfoWasm.cpp
(853 B)
📄
MCAsmInfoXCOFF.cpp
(1.63 KB)
📄
MCAsmMacro.cpp
(1.12 KB)
📄
MCAsmStreamer.cpp
(68.69 KB)
📄
MCAssembler.cpp
(42.61 KB)
📄
MCCodeEmitter.cpp
(515 B)
📄
MCCodeView.cpp
(25.49 KB)
📄
MCContext.cpp
(31.94 KB)
📁
MCDisassembler
📄
MCDwarf.cpp
(71.58 KB)
📄
MCELFObjectTargetWriter.cpp
(1.29 KB)
📄
MCELFStreamer.cpp
(24.89 KB)
📄
MCExpr.cpp
(34.06 KB)
📄
MCFragment.cpp
(15.28 KB)
📄
MCInst.cpp
(2.6 KB)
📄
MCInstPrinter.cpp
(7.87 KB)
📄
MCInstrAnalysis.cpp
(1.2 KB)
📄
MCInstrDesc.cpp
(1.96 KB)
📄
MCInstrInfo.cpp
(1.03 KB)
📄
MCLabel.cpp
(772 B)
📄
MCLinkerOptimizationHint.cpp
(2.03 KB)
📄
MCMachOStreamer.cpp
(18.55 KB)
📄
MCMachObjectTargetWriter.cpp
(780 B)
📄
MCNullStreamer.cpp
(1.61 KB)
📄
MCObjectFileInfo.cpp
(39.55 KB)
📄
MCObjectStreamer.cpp
(28.26 KB)
📄
MCObjectWriter.cpp
(1.82 KB)
📁
MCParser
📄
MCRegisterInfo.cpp
(4.76 KB)
📄
MCSchedule.cpp
(6.15 KB)
📄
MCSection.cpp
(4.41 KB)
📄
MCSectionCOFF.cpp
(3.52 KB)
📄
MCSectionELF.cpp
(5.29 KB)
📄
MCSectionMachO.cpp
(10.84 KB)
📄
MCSectionWasm.cpp
(2.45 KB)
📄
MCSectionXCOFF.cpp
(2.46 KB)
📄
MCStreamer.cpp
(42.97 KB)
📄
MCSubtargetInfo.cpp
(11.35 KB)
📄
MCSymbol.cpp
(2.98 KB)
📄
MCSymbolELF.cpp
(4.69 KB)
📄
MCSymbolXCOFF.cpp
(1.73 KB)
📄
MCTargetOptions.cpp
(990 B)
📄
MCTargetOptionsCommandFlags.cpp
(4.42 KB)
📄
MCValue.cpp
(1.42 KB)
📄
MCWasmObjectTargetWriter.cpp
(727 B)
📄
MCWasmStreamer.cpp
(7.59 KB)
📄
MCWin64EH.cpp
(22.87 KB)
📄
MCWinCOFFStreamer.cpp
(11.94 KB)
📄
MCWinEH.cpp
(711 B)
📄
MCXCOFFObjectTargetWriter.cpp
(596 B)
📄
MCXCOFFStreamer.cpp
(4.87 KB)
📄
MachObjectWriter.cpp
(37.79 KB)
📄
StringTableBuilder.cpp
(5.26 KB)
📄
SubtargetFeature.cpp
(2.6 KB)
📄
WasmObjectWriter.cpp
(60.42 KB)
📄
WinCOFFObjectWriter.cpp
(39.32 KB)
📄
XCOFFObjectWriter.cpp
(31.62 KB)
Editing: StringTableBuilder.cpp
//===- StringTableBuilder.cpp - String table building utility -------------===// // // 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 // //===----------------------------------------------------------------------===// #include "llvm/MC/StringTableBuilder.h" #include "llvm/ADT/CachedHashString.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/StringRef.h" #include "llvm/BinaryFormat/COFF.h" #include "llvm/Support/Endian.h" #include "llvm/Support/MathExtras.h" #include "llvm/Support/raw_ostream.h" #include <cassert> #include <cstddef> #include <cstdint> #include <cstring> #include <utility> #include <vector> using namespace llvm; StringTableBuilder::~StringTableBuilder() = default; void StringTableBuilder::initSize() { // Account for leading bytes in table so that offsets returned from add are // correct. switch (K) { case RAW: case DWARF: Size = 0; break; case MachO: case ELF: // Start the table with a NUL byte. Size = 1; break; case XCOFF: case WinCOFF: // Make room to write the table size later. Size = 4; break; } } StringTableBuilder::StringTableBuilder(Kind K, unsigned Alignment) : K(K), Alignment(Alignment) { initSize(); } void StringTableBuilder::write(raw_ostream &OS) const { assert(isFinalized()); SmallString<0> Data; Data.resize(getSize()); write((uint8_t *)Data.data()); OS << Data; } using StringPair = std::pair<CachedHashStringRef, size_t>; void StringTableBuilder::write(uint8_t *Buf) const { assert(isFinalized()); for (const StringPair &P : StringIndexMap) { StringRef Data = P.first.val(); if (!Data.empty()) memcpy(Buf + P.second, Data.data(), Data.size()); } // The COFF formats store the size of the string table in the first 4 bytes. // For Windows, the format is little-endian; for AIX, it is big-endian. if (K == WinCOFF) support::endian::write32le(Buf, Size); else if (K == XCOFF) support::endian::write32be(Buf, Size); } // Returns the character at Pos from end of a string. static int charTailAt(StringPair *P, size_t Pos) { StringRef S = P->first.val(); if (Pos >= S.size()) return -1; return (unsigned char)S[S.size() - Pos - 1]; } // Three-way radix quicksort. This is much faster than std::sort with strcmp // because it does not compare characters that we already know the same. static void multikeySort(MutableArrayRef<StringPair *> Vec, int Pos) { tailcall: if (Vec.size() <= 1) return; // Partition items so that items in [0, I) are greater than the pivot, // [I, J) are the same as the pivot, and [J, Vec.size()) are less than // the pivot. int Pivot = charTailAt(Vec[0], Pos); size_t I = 0; size_t J = Vec.size(); for (size_t K = 1; K < J;) { int C = charTailAt(Vec[K], Pos); if (C > Pivot) std::swap(Vec[I++], Vec[K++]); else if (C < Pivot) std::swap(Vec[--J], Vec[K]); else K++; } multikeySort(Vec.slice(0, I), Pos); multikeySort(Vec.slice(J), Pos); // multikeySort(Vec.slice(I, J - I), Pos + 1), but with // tail call optimization. if (Pivot != -1) { Vec = Vec.slice(I, J - I); ++Pos; goto tailcall; } } void StringTableBuilder::finalize() { assert(K != DWARF); finalizeStringTable(/*Optimize=*/true); } void StringTableBuilder::finalizeInOrder() { finalizeStringTable(/*Optimize=*/false); } void StringTableBuilder::finalizeStringTable(bool Optimize) { Finalized = true; if (Optimize) { std::vector<StringPair *> Strings; Strings.reserve(StringIndexMap.size()); for (StringPair &P : StringIndexMap) Strings.push_back(&P); multikeySort(Strings, 0); initSize(); StringRef Previous; for (StringPair *P : Strings) { StringRef S = P->first.val(); if (Previous.endswith(S)) { size_t Pos = Size - S.size() - (K != RAW); if (!(Pos & (Alignment - 1))) { P->second = Pos; continue; } } Size = alignTo(Size, Alignment); P->second = Size; Size += S.size(); if (K != RAW) ++Size; Previous = S; } } if (K == MachO) Size = alignTo(Size, 4); // Pad to multiple of 4. // The first byte in an ELF string table must be null, according to the ELF // specification. In 'initSize()' we reserved the first byte to hold null for // this purpose and here we actually add the string to allow 'getOffset()' to // be called on an empty string. if (K == ELF) StringIndexMap[CachedHashStringRef("")] = 0; } void StringTableBuilder::clear() { Finalized = false; StringIndexMap.clear(); } size_t StringTableBuilder::getOffset(CachedHashStringRef S) const { assert(isFinalized()); auto I = StringIndexMap.find(S); assert(I != StringIndexMap.end() && "String is not in table!"); return I->second; } size_t StringTableBuilder::add(CachedHashStringRef S) { if (K == WinCOFF) assert(S.size() > COFF::NameSize && "Short string in COFF string table!"); assert(!isFinalized()); auto P = StringIndexMap.insert(std::make_pair(S, 0)); if (P.second) { size_t Start = alignTo(Size, Alignment); P.first->second = Start; Size = Start + S.size() + (K != RAW); } return P.first->second; }
Upload File
Create Folder