From 397b10957c7a9187cc2baf00ddb1c90c1a7fcf0a Mon Sep 17 00:00:00 2001 From: Yu-hsin Wang Date: Tue, 16 Mar 2021 13:05:39 +0800 Subject: [PATCH] base: Add a rename helper to SymbolTable In some cases, we want to move and copy the symbol table to another address. However, the name of symbol table should be unique. This rename helper provides a way to modify the name of symbol. Developers can use it to solve the conflict with this helper. Change-Id: I4627e06da3a03da57009d613188be117c75750a0 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/43105 Reviewed-by: Daniel Carvalho Maintainer: Bobby R. Bruce Tested-by: kokoro --- src/base/loader/symtab.hh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/base/loader/symtab.hh b/src/base/loader/symtab.hh index 561054492b..c148289bdd 100644 --- a/src/base/loader/symtab.hh +++ b/src/base/loader/symtab.hh @@ -153,6 +153,21 @@ class SymbolTable return operate(op); } + /// Modify symbol name with a given transform function. + /// @param func The transform function accepting the reference of + /// symbol name. + /// @retval SymbolTablePtr A pointer to the modified SymbolTable copy. + SymbolTablePtr + rename(std::function func) const + { + SymTabOp op = [func](SymbolTable &symtab, const Symbol &symbol) { + Symbol sym = symbol; + func(sym.name); + symtab.insert(sym); + }; + return operate(op); + } + SymbolTablePtr globals() const {