Gabe Black has submitted this change. (
https://gem5-review.googlesource.com/c/public/gem5/+/24786 )
Change subject: sim: Add some methods to create derived symbol tables.
......................................................................
sim: Add some methods to create derived symbol tables.
These tables are based on passing the symbols in the current table
through some sort of operator function which can chose to add those
symbols, modified versions of those symbols, or nothing at all into a
new symbol table.
The new table is returned as a shared_ptr so its memory will be
managed automatically.
Change-Id: I8809336e2fc2fda63b16a0400536116ca852ca13
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/24786
Reviewed-by: Gabe Black <gabebl...@google.com>
Maintainer: Gabe Black <gabebl...@google.com>
Tested-by: kokoro <noreply+kok...@google.com>
---
M src/base/loader/symtab.hh
1 file changed, 78 insertions(+), 0 deletions(-)
Approvals:
Gabe Black: Looks good to me, approved; Looks good to me, approved
kokoro: Regressions pass
diff --git a/src/base/loader/symtab.hh b/src/base/loader/symtab.hh
index 30f0a4f..1e99fec 100644
--- a/src/base/loader/symtab.hh
+++ b/src/base/loader/symtab.hh
@@ -29,8 +29,10 @@
#ifndef __SYMTAB_HH__
#define __SYMTAB_HH__
+#include <functional>
#include <iosfwd>
#include <map>
+#include <memory>
#include <string>
#include <vector>
@@ -56,6 +58,9 @@
class SymbolTable
{
+ public:
+ typedef std::shared_ptr<SymbolTable> SymbolTablePtr;
+
private:
typedef std::vector<Symbol> SymbolVector;
// Map addresses to an index into the symbol vector.
@@ -80,6 +85,39 @@
return true;
}
+ typedef std::function<void(SymbolTable &symtab,
+ const Symbol &symbol)> SymTabOp;
+ SymbolTablePtr
+ operate(SymTabOp op) const
+ {
+ SymbolTablePtr symtab(new SymbolTable);
+ for (const auto &symbol: symbols)
+ op(*symtab, symbol);
+ return symtab;
+ }
+
+ typedef std::function<bool(const Symbol &symbol)> SymTabFilter;
+ SymbolTablePtr
+ filter(SymTabFilter filter) const
+ {
+ SymTabOp apply_filter =
+ [filter](SymbolTable &symtab, const Symbol &symbol) {
+ if (filter(symbol)) {
+ symtab.insert(symbol);
+ }
+ };
+ return operate(apply_filter);
+ }
+
+ SymbolTablePtr
+ filterByBinding(Symbol::Binding binding) const
+ {
+ auto filt = [binding](const Symbol &symbol) {
+ return symbol.binding == binding;
+ };
+ return filter(filt);
+ }
+
public:
typedef SymbolVector::iterator iterator;
typedef SymbolVector::const_iterator const_iterator;
@@ -95,6 +133,46 @@
bool load(const std::string &file);
bool empty() const { return symbols.empty(); }
+ SymbolTablePtr
+ offset(Addr by) const
+ {
+ SymTabOp op = [by](SymbolTable &symtab, const Symbol &symbol) {
+ Symbol sym = symbol;
+ sym.address += by;
+ symtab.insert(sym);
+ };
+ return operate(op);
+ }
+
+ SymbolTablePtr
+ mask(Addr m) const
+ {
+ SymTabOp op = [m](SymbolTable &symtab, const Symbol &symbol) {
+ Symbol sym = symbol;
+ sym.address &= m;
+ symtab.insert(sym);
+ };
+ return operate(op);
+ }
+
+ SymbolTablePtr
+ globals() const
+ {
+ return filterByBinding(Symbol::Binding::Global);
+ }
+
+ SymbolTablePtr
+ locals() const
+ {
+ return filterByBinding(Symbol::Binding::Local);
+ }
+
+ SymbolTablePtr
+ weaks() const
+ {
+ return filterByBinding(Symbol::Binding::Weak);
+ }
+
void serialize(const std::string &base, CheckpointOut &cp) const;
void unserialize(const std::string &base, CheckpointIn &cp,
Symbol::Binding
default_binding=Symbol::Binding::Global);
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/24786
To unsubscribe, or for help writing mail filters, visit
https://gem5-review.googlesource.com/settings
Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: I8809336e2fc2fda63b16a0400536116ca852ca13
Gerrit-Change-Number: 24786
Gerrit-PatchSet: 33
Gerrit-Owner: Gabe Black <gabebl...@google.com>
Gerrit-Reviewer: Bobby R. Bruce <bbr...@ucdavis.edu>
Gerrit-Reviewer: Bradford Beckmann <brad.beckm...@amd.com>
Gerrit-Reviewer: Gabe Black <gabebl...@google.com>
Gerrit-Reviewer: Giacomo Travaglini <giacomo.travagl...@arm.com>
Gerrit-Reviewer: Jason Lowe-Power <power...@gmail.com>
Gerrit-Reviewer: kokoro <noreply+kok...@google.com>
Gerrit-MessageType: merged
_______________________________________________
gem5-dev mailing list -- gem5-dev@gem5.org
To unsubscribe send an email to gem5-dev-le...@gem5.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s