diff options
Diffstat (limited to 'include/llvm/MC/MCDwarf.h')
-rw-r--r-- | include/llvm/MC/MCDwarf.h | 91 |
1 files changed, 55 insertions, 36 deletions
diff --git a/include/llvm/MC/MCDwarf.h b/include/llvm/MC/MCDwarf.h index 7b96e9aaca89..1a37aafd0654 100644 --- a/include/llvm/MC/MCDwarf.h +++ b/include/llvm/MC/MCDwarf.h @@ -1,9 +1,8 @@ //===- MCDwarf.h - Machine Code Dwarf support -------------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// // @@ -42,11 +41,14 @@ class raw_ostream; class SMLoc; class SourceMgr; -/// Instances of this class represent the name of the dwarf -/// .file directive and its associated dwarf file number in the MC file, -/// and MCDwarfFile's are created and uniqued by the MCContext class where -/// the file number for each is its index into the vector of DwarfFiles (note -/// index 0 is not used and not a valid dwarf file number). +/// Instances of this class represent the name of the dwarf .file directive and +/// its associated dwarf file number in the MC file. MCDwarfFile's are created +/// and uniqued by the MCContext class. In Dwarf 4 file numbers start from 1; +/// i.e. the entry with file number 1 is the first element in the vector of +/// DwarfFiles and there is no MCDwarfFile with file number 0. In Dwarf 5 file +/// numbers start from 0, with the MCDwarfFile with file number 0 being the +/// primary source file, and file numbers correspond to their index in the +/// vector. struct MCDwarfFile { // The base name of the file without its directory path. std::string Name; @@ -56,7 +58,7 @@ struct MCDwarfFile { /// The MD5 checksum, if there is one. Non-owning pointer to data allocated /// in MCContext. - MD5::MD5Result *Checksum = nullptr; + Optional<MD5::MD5Result> Checksum; /// The source code of the file. Non-owning reference to data allocated in /// MCContext. @@ -224,8 +226,9 @@ public: MCDwarfLineTableHeader() = default; Expected<unsigned> tryGetFile(StringRef &Directory, StringRef &FileName, - MD5::MD5Result *Checksum, - Optional<StringRef> &Source, + Optional<MD5::MD5Result> Checksum, + Optional<StringRef> Source, + uint16_t DwarfVersion, unsigned FileNumber = 0); std::pair<MCSymbol *, MCSymbol *> Emit(MCStreamer *MCOS, MCDwarfLineTableParams Params, @@ -246,32 +249,50 @@ public: return MCDwarfFiles.empty() || (HasAllMD5 == HasAnyMD5); } + void setRootFile(StringRef Directory, StringRef FileName, + Optional<MD5::MD5Result> Checksum, + Optional<StringRef> Source) { + CompilationDir = Directory; + RootFile.Name = FileName; + RootFile.DirIndex = 0; + RootFile.Checksum = Checksum; + RootFile.Source = Source; + trackMD5Usage(Checksum.hasValue()); + HasSource = Source.hasValue(); + } + + void resetFileTable() { + MCDwarfDirs.clear(); + MCDwarfFiles.clear(); + RootFile.Name.clear(); + resetMD5Usage(); + HasSource = false; + } + private: void emitV2FileDirTables(MCStreamer *MCOS) const; - void emitV5FileDirTables(MCStreamer *MCOS, Optional<MCDwarfLineStr> &LineStr, - StringRef CtxCompilationDir) const; + void emitV5FileDirTables(MCStreamer *MCOS, Optional<MCDwarfLineStr> &LineStr) const; }; class MCDwarfDwoLineTable { MCDwarfLineTableHeader Header; + bool HasSplitLineTable = false; public: void maybeSetRootFile(StringRef Directory, StringRef FileName, - MD5::MD5Result *Checksum, Optional<StringRef> Source) { + Optional<MD5::MD5Result> Checksum, + Optional<StringRef> Source) { if (!Header.RootFile.Name.empty()) return; - Header.CompilationDir = Directory; - Header.RootFile.Name = FileName; - Header.RootFile.DirIndex = 0; - Header.RootFile.Checksum = Checksum; - Header.RootFile.Source = Source; - Header.trackMD5Usage(Checksum); - Header.HasSource = Source.hasValue(); + Header.setRootFile(Directory, FileName, Checksum, Source); } unsigned getFile(StringRef Directory, StringRef FileName, - MD5::MD5Result *Checksum, Optional<StringRef> Source) { - return cantFail(Header.tryGetFile(Directory, FileName, Checksum, Source)); + Optional<MD5::MD5Result> Checksum, uint16_t DwarfVersion, + Optional<StringRef> Source) { + HasSplitLineTable = true; + return cantFail(Header.tryGetFile(Directory, FileName, Checksum, Source, + DwarfVersion)); } void Emit(MCStreamer &MCOS, MCDwarfLineTableParams Params, @@ -291,36 +312,34 @@ public: Optional<MCDwarfLineStr> &LineStr) const; Expected<unsigned> tryGetFile(StringRef &Directory, StringRef &FileName, - MD5::MD5Result *Checksum, + Optional<MD5::MD5Result> Checksum, Optional<StringRef> Source, + uint16_t DwarfVersion, unsigned FileNumber = 0); unsigned getFile(StringRef &Directory, StringRef &FileName, - MD5::MD5Result *Checksum, Optional<StringRef> &Source, - unsigned FileNumber = 0) { + Optional<MD5::MD5Result> Checksum, Optional<StringRef> Source, + uint16_t DwarfVersion, unsigned FileNumber = 0) { return cantFail(tryGetFile(Directory, FileName, Checksum, Source, - FileNumber)); + DwarfVersion, FileNumber)); } void setRootFile(StringRef Directory, StringRef FileName, - MD5::MD5Result *Checksum, Optional<StringRef> Source) { + Optional<MD5::MD5Result> Checksum, Optional<StringRef> Source) { Header.CompilationDir = Directory; Header.RootFile.Name = FileName; Header.RootFile.DirIndex = 0; Header.RootFile.Checksum = Checksum; Header.RootFile.Source = Source; - Header.trackMD5Usage(Checksum); + Header.trackMD5Usage(Checksum.hasValue()); Header.HasSource = Source.hasValue(); } - void resetRootFile() { - assert(Header.MCDwarfFiles.empty()); - Header.RootFile.Name.clear(); - Header.resetMD5Usage(); - Header.HasSource = false; - } + void resetFileTable() { Header.resetFileTable(); } bool hasRootFile() const { return !Header.RootFile.Name.empty(); } + const MCDwarfFile &getRootFile() const { return Header.RootFile; } + // Report whether MD5 usage has been consistent (all-or-none). bool isMD5UsageConsistent() const { return Header.isMD5UsageConsistent(); } |