diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp index 4a18ead5e762..4d6d264ee0a2 100644 --- a/lld/COFF/Driver.cpp +++ b/lld/COFF/Driver.cpp @@ -426,7 +426,7 @@ static std::string createResponseFile(const opt::InputArgList &Args, case OPT_manifestuac: break; default: - OS << toString(Arg) << "\n"; + OS << toString(*Arg) << "\n"; } } @@ -674,7 +674,7 @@ void LinkerDriver::invokeMSVC(opt::InputArgList &Args) { break; case OPT_opt: if (!StringRef(Arg->getValue()).startswith("lld")) - Rsp += toString(Arg) + " "; + Rsp += toString(*Arg) + " "; break; case OPT_INPUT: { if (Optional Path = doFindFile(Arg->getValue())) { @@ -686,7 +686,7 @@ void LinkerDriver::invokeMSVC(opt::InputArgList &Args) { break; } default: - Rsp += toString(Arg) + "\n"; + Rsp += toString(*Arg) + "\n"; } } diff --git a/lld/COFF/InputFiles.cpp b/lld/COFF/InputFiles.cpp index aa444ec44cb0..df72aa50aef6 100644 --- a/lld/COFF/InputFiles.cpp +++ b/lld/COFF/InputFiles.cpp @@ -493,7 +493,7 @@ static StringRef getBasename(StringRef Path) { } // Returns a string in the format of "foo.obj" or "foo.obj(bar.lib)". -std::string lld::toString(coff::InputFile *File) { +std::string lld::toString(const coff::InputFile *File) { if (!File) return ""; if (File->ParentName.empty()) diff --git a/lld/COFF/InputFiles.h b/lld/COFF/InputFiles.h index 10b0502e80b8..645fa38badc3 100644 --- a/lld/COFF/InputFiles.h +++ b/lld/COFF/InputFiles.h @@ -58,7 +58,7 @@ public: virtual ~InputFile() {} // Returns the filename. - StringRef getName() { return MB.getBufferIdentifier(); } + StringRef getName() const { return MB.getBufferIdentifier(); } // Reads a file (the constructor doesn't do that). virtual void parse() = 0; @@ -229,7 +229,7 @@ private: }; } // namespace coff -std::string toString(coff::InputFile *File); +std::string toString(const coff::InputFile *File); } // namespace lld #endif diff --git a/lld/Common/Reproduce.cpp b/lld/Common/Reproduce.cpp index 1e3dabaea0c5..7be4ea6bb98b 100644 --- a/lld/Common/Reproduce.cpp +++ b/lld/Common/Reproduce.cpp @@ -55,12 +55,12 @@ std::string lld::rewritePath(StringRef S) { return S; } -std::string lld::toString(opt::Arg *Arg) { - std::string K = Arg->getSpelling(); - if (Arg->getNumValues() == 0) +std::string lld::toString(const opt::Arg &Arg) { + std::string K = Arg.getSpelling(); + if (Arg.getNumValues() == 0) return K; - std::string V = quote(Arg->getValue()); - if (Arg->getOption().getRenderStyle() == opt::Option::RenderJoinedStyle) + std::string V = quote(Arg.getValue()); + if (Arg.getOption().getRenderStyle() == opt::Option::RenderJoinedStyle) return K + V; return K + " " + V; } diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp index a3ab42d93b44..ff1dd2251de2 100644 --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -493,7 +493,7 @@ static StripPolicy getStrip(opt::InputArgList &Args) { return StripPolicy::Debug; } -static uint64_t parseSectionAddress(StringRef S, opt::Arg *Arg) { +static uint64_t parseSectionAddress(StringRef S, const opt::Arg &Arg) { uint64_t VA = 0; if (S.startswith("0x")) S = S.drop_front(2); @@ -508,15 +508,15 @@ static StringMap getSectionStartMap(opt::InputArgList &Args) { StringRef Name; StringRef Addr; std::tie(Name, Addr) = StringRef(Arg->getValue()).split('='); - Ret[Name] = parseSectionAddress(Addr, Arg); + Ret[Name] = parseSectionAddress(Addr, *Arg); } if (auto *Arg = Args.getLastArg(OPT_Ttext)) - Ret[".text"] = parseSectionAddress(Arg->getValue(), Arg); + Ret[".text"] = parseSectionAddress(Arg->getValue(), *Arg); if (auto *Arg = Args.getLastArg(OPT_Tdata)) - Ret[".data"] = parseSectionAddress(Arg->getValue(), Arg); + Ret[".data"] = parseSectionAddress(Arg->getValue(), *Arg); if (auto *Arg = Args.getLastArg(OPT_Tbss)) - Ret[".bss"] = parseSectionAddress(Arg->getValue(), Arg); + Ret[".bss"] = parseSectionAddress(Arg->getValue(), *Arg); return Ret; } diff --git a/lld/ELF/DriverUtils.cpp b/lld/ELF/DriverUtils.cpp index 56f9c0ffc3d2..9fa6f620abcb 100644 --- a/lld/ELF/DriverUtils.cpp +++ b/lld/ELF/DriverUtils.cpp @@ -166,7 +166,7 @@ std::string elf::createResponseFile(const opt::InputArgList &Args) { << "\n"; break; default: - OS << toString(Arg) << "\n"; + OS << toString(*Arg) << "\n"; } } return Data.str(); diff --git a/lld/include/lld/Common/Reproduce.h b/lld/include/lld/Common/Reproduce.h index 9cc430e51859..0f425de269c7 100644 --- a/lld/include/lld/Common/Reproduce.h +++ b/lld/include/lld/Common/Reproduce.h @@ -33,7 +33,7 @@ std::string quote(StringRef S); std::string rewritePath(StringRef S); // Returns the string form of the given argument. -std::string toString(llvm::opt::Arg *Arg); +std::string toString(const llvm::opt::Arg &Arg); } #endif diff --git a/lld/wasm/InputFiles.cpp b/lld/wasm/InputFiles.cpp index 9cb4e08619c3..bb93620a9311 100644 --- a/lld/wasm/InputFiles.cpp +++ b/lld/wasm/InputFiles.cpp @@ -264,7 +264,7 @@ void ArchiveFile::addMember(const Archive::Symbol *Sym) { } // Returns a string in the format of "foo.o" or "foo.a(bar.o)". -std::string lld::toString(wasm::InputFile *File) { +std::string lld::toString(const wasm::InputFile *File) { if (!File) return ""; diff --git a/lld/wasm/InputFiles.h b/lld/wasm/InputFiles.h index 3467fb6c8e88..65b606a150ba 100644 --- a/lld/wasm/InputFiles.h +++ b/lld/wasm/InputFiles.h @@ -143,7 +143,7 @@ llvm::Optional readFile(StringRef Path); } // namespace wasm -std::string toString(wasm::InputFile *File); +std::string toString(const wasm::InputFile *File); } // namespace lld diff --git a/lld/wasm/Symbols.cpp b/lld/wasm/Symbols.cpp index ba23e395dd19..94851dd8e807 100644 --- a/lld/wasm/Symbols.cpp +++ b/lld/wasm/Symbols.cpp @@ -76,11 +76,11 @@ bool Symbol::isWeak() const { return Sym && Sym->isWeak(); } bool Symbol::isHidden() const { return Sym && Sym->isHidden(); } -std::string lld::toString(wasm::Symbol &Sym) { +std::string lld::toString(const wasm::Symbol &Sym) { return wasm::displayName(Sym.getName()); } -std::string lld::toString(wasm::Symbol::Kind &Kind) { +std::string lld::toString(wasm::Symbol::Kind Kind) { switch (Kind) { case wasm::Symbol::DefinedFunctionKind: return "DefinedFunction"; diff --git a/lld/wasm/Symbols.h b/lld/wasm/Symbols.h index 8e0e6d503b00..0817e4df835e 100644 --- a/lld/wasm/Symbols.h +++ b/lld/wasm/Symbols.h @@ -111,8 +111,8 @@ protected: } // namespace wasm // Returns a symbol name for an error message. -std::string toString(wasm::Symbol &Sym); -std::string toString(wasm::Symbol::Kind &Kind); +std::string toString(const wasm::Symbol &Sym); +std::string toString(wasm::Symbol::Kind Kind); } // namespace lld