1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 11:02:59 +02:00

[WebAssembly][MC] Use StringRef over std::string pointer

This is followup based on feedback on 5be42f36f56.
See: https://reviews.llvm.org/D77627.

Differential Revision: https://reviews.llvm.org/D77674
This commit is contained in:
Sam Clegg 2020-04-07 14:02:20 -07:00
parent e60044ece6
commit 49ea87ec89
3 changed files with 19 additions and 24 deletions

View File

@ -19,15 +19,13 @@ class MCSymbolWasm : public MCSymbol {
bool IsHidden = false;
bool IsComdat = false;
mutable bool IsUsedInGOT = false;
Optional<StringRef> ImportModule;
Optional<StringRef> ImportName;
Optional<StringRef> ExportName;
wasm::WasmSignature *Signature = nullptr;
Optional<wasm::WasmGlobalType> GlobalType;
Optional<wasm::WasmEventType> EventType;
// Non-owning pointers since MCSymbol must be trivially destructible.
std::string *ImportModule = nullptr;
std::string *ImportName = nullptr;
std::string *ExportName = nullptr;
wasm::WasmSignature *Signature = nullptr;
/// An expression describing how to calculate the size of a symbol. If a
/// symbol has no size this field will be NULL.
const MCExpr *SymbolSize = nullptr;
@ -71,32 +69,29 @@ public:
bool isComdat() const { return IsComdat; }
void setComdat(bool isComdat) { IsComdat = isComdat; }
bool hasImportModule() const { return ImportModule != nullptr; }
bool hasImportModule() const { return ImportModule.hasValue(); }
StringRef getImportModule() const {
if (ImportModule)
return StringRef(*ImportModule);
if (ImportModule.hasValue())
return ImportModule.getValue();
// Use a default module name of "env" for now, for compatibility with
// existing tools.
// TODO(sbc): Find a way to specify a default value in the object format
// without picking a hardcoded value like this.
return "env";
}
void setImportModule(std::string *Name) { ImportModule = Name; }
void setImportModule(StringRef Name) { ImportModule = Name; }
bool hasImportName() const { return ImportName != nullptr; }
bool hasImportName() const { return ImportName.hasValue(); }
StringRef getImportName() const {
if (ImportName)
return StringRef(*ImportName);
if (ImportName.hasValue())
return ImportName.getValue();
return getName();
}
void setImportName(std::string *Name) { ImportName = Name; }
void setImportName(StringRef Name) { ImportName = Name; }
bool hasExportName() const { return ExportName != nullptr; }
StringRef getExportName() const {
assert(ExportName);
return StringRef(*ExportName);
}
void setExportName(std::string *Name) { ExportName = Name; }
bool hasExportName() const { return ExportName.hasValue(); }
StringRef getExportName() const { return ExportName.getValue(); }
void setExportName(StringRef Name) { ExportName = Name; }
void setUsedInGOT() const { IsUsedInGOT = true; }
bool isUsedInGOT() const { return IsUsedInGOT; }

View File

@ -233,10 +233,10 @@ public:
Signatures.push_back(std::move(Sig));
}
std::string *storeName(StringRef Name) {
StringRef storeName(StringRef Name) {
std::unique_ptr<std::string> N = std::make_unique<std::string>(Name);
Names.push_back(std::move(N));
return Names.back().get();
return *Names.back();
}
std::pair<StringRef, StringRef> nestingString(NestingType NT) {

View File

@ -28,10 +28,10 @@ class LLVM_LIBRARY_VISIBILITY WebAssemblyAsmPrinter final : public AsmPrinter {
std::vector<std::unique_ptr<wasm::WasmSignature>> Signatures;
std::vector<std::unique_ptr<std::string>> Names;
std::string *storeName(StringRef Name) {
StringRef storeName(StringRef Name) {
std::unique_ptr<std::string> N = std::make_unique<std::string>(Name);
Names.push_back(std::move(N));
return Names.back().get();
return *Names.back();
}
public: