From 6eca83d0fb85897b9575a5c53beae8d0b22dd676 Mon Sep 17 00:00:00 2001 From: Hoa Nguyen Date: Sun, 29 Oct 2023 03:29:30 +0000 Subject: [PATCH] base: Add ability to generate SymbolTable by filtering SymbolType This allows filtering out non function symbols. Change-Id: I518c2842a6f04c4475240126ad64070a6de09df9 Signed-off-by: Hoa Nguyen --- src/base/loader/symtab.hh | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/base/loader/symtab.hh b/src/base/loader/symtab.hh index 45e55fcee7..654064c9db 100644 --- a/src/base/loader/symtab.hh +++ b/src/base/loader/symtab.hh @@ -176,6 +176,22 @@ class SymbolTable return filter(filt); } + /** + * Generate a new table by applying a filter that only accepts the symbols + * whose type matches the given symbol type. + * + * @param The type that must be matched. + * @return A new table, filtered by type. + */ + SymbolTablePtr + filterBySymbolType(const Symbol::SymbolType& symbol_type) const + { + auto filt = [symbol_type](const Symbol &symbol) { + return symbol.type == symbol_type; + }; + return filter(filt); + } + public: typedef SymbolVector::iterator iterator; typedef SymbolVector::const_iterator const_iterator; @@ -302,6 +318,17 @@ class SymbolTable return filterByBinding(Symbol::Binding::Weak); } + /** + * Generates a new symbol table containing only function symbols. + * + * @return The new table. + */ + SymbolTablePtr + functionSymbols() const + { + return filterBySymbolType(Symbol::SymbolType::Function); + } + /** * Serialize the table's contents. *