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 <odanrc@yahoo.com.br>
Maintainer: Bobby R. Bruce <bbruce@ucdavis.edu>
Tested-by: kokoro <noreply+kokoro@google.com>
This commit is contained in:
Yu-hsin Wang
2021-03-16 13:05:39 +08:00
parent 07505a30af
commit 397b10957c

View File

@@ -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<void(std::string&)> 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
{