2222#include " filter/Filter.h"
2323#include " filter/Matcher.h"
2424#include " filter/StdForwardFilter.h"
25+ #include " support/ConfigurationBase.h"
2526#include " support/Logger.h"
2627#include " support/Table.h"
2728#include " support/TypeUtil.h"
4344#include < algorithm>
4445#include < cstdlib>
4546#include < sstream>
47+ #include < string>
4648#include < utility>
4749
4850using namespace llvm ;
@@ -61,7 +63,7 @@ ALWAYS_ENABLED_STATISTIC(NumCallFilteredGlobals, "Number of filtered globals");
6163
6264namespace typeart ::analysis {
6365
64- using MemInstFinderConfig = config::TypeARTConfigOptions ;
66+ using MemInstFinderConfig = config::Configuration ;
6567
6668namespace filter {
6769class CallFilter {
@@ -85,25 +87,27 @@ namespace filter {
8587namespace detail {
8688static std::unique_ptr<typeart::filter::Filter> make_filter (const MemInstFinderConfig& config) {
8789 using namespace typeart ::filter;
88- const auto filter_id = config.filter_config .implementation ;
89- const std::string glob = config.filter_config .glob ;
90+ const bool filter = config[config::ConfigStdArgs::filter];
91+ const FilterImplementation filter_id = config[config::ConfigStdArgs::filter_impl];
92+ const std::string glob = config[config::ConfigStdArgs::filter_glob];
9093
91- if (filter_id == FilterImplementation::none || !config. filter ) {
94+ if (filter_id == FilterImplementation::none || !filter) {
9295 LOG_DEBUG (" Return no-op filter" )
9396 return std::make_unique<NoOpFilter>();
9497 } else if (filter_id == FilterImplementation::cg) {
95- if (config.filter_config .cg_file .empty ()) {
98+ const std::string cg_file = config[config::ConfigStdArgs::filter_cg_file];
99+ if (cg_file.empty ()) {
96100 LOG_FATAL (" CG File not set!" );
97101 std::exit (1 );
98102 }
99- LOG_DEBUG (" Return CG filter with CG file @ " << config. filter_config . cg_file )
100- auto json_cg = JSONCG::getJSON (config. filter_config . cg_file );
103+ LOG_DEBUG (" Return CG filter with CG file @ " << cg_file)
104+ auto json_cg = JSONCG::getJSON (cg_file);
101105 auto matcher = std::make_unique<DefaultStringMatcher>(util::glob2regex (glob));
102106 return std::make_unique<CGForwardFilter>(glob, std::move (json_cg), std::move (matcher));
103107 } else {
104108 LOG_DEBUG (" Return default filter" )
105109 auto matcher = std::make_unique<DefaultStringMatcher>(util::glob2regex (glob));
106- const auto deep_glob = config. filter_config . glob_deep ;
110+ const auto deep_glob = config[config::ConfigStdArgs::filter_glob_deep] ;
107111 auto deep_matcher = std::make_unique<DefaultStringMatcher>(util::glob2regex (deep_glob));
108112 return std::make_unique<StandardForwardFilter>(std::move (matcher), std::move (deep_matcher));
109113 }
@@ -150,7 +154,7 @@ class MemInstFinderPass : public MemInstFinder {
150154 MemOpVisitor mOpsCollector ;
151155 filter::CallFilter filter;
152156 llvm::DenseMap<const llvm::Function*, FunctionData> functionMap;
153- MemInstFinderConfig config;
157+ const MemInstFinderConfig& config;
154158
155159 public:
156160 explicit MemInstFinderPass (const MemInstFinderConfig&);
@@ -167,14 +171,14 @@ class MemInstFinderPass : public MemInstFinder {
167171};
168172
169173MemInstFinderPass::MemInstFinderPass (const MemInstFinderConfig& conf_)
170- : mOpsCollector (conf_.stack, conf_.heap ), filter(conf_), config(conf_) {
174+ : mOpsCollector (conf_), filter(conf_), config(conf_) {
171175}
172176
173177bool MemInstFinderPass::runOnModule (Module& module ) {
174178 mOpsCollector .collectGlobals (module );
175179 auto & globals = mOpsCollector .globals ;
176180 NumDetectedGlobals += globals.size ();
177- if (config. analysis_config . filter_global ) {
181+ if (config[config::ConfigStdArgs::analysis_filter_global] ) {
178182 globals.erase (llvm::remove_if (
179183 globals,
180184 [&](const auto gdata) { // NOLINT
@@ -295,7 +299,7 @@ bool MemInstFinderPass::runOnFunction(llvm::Function& function) {
295299
296300 NumDetectedAllocs += mOpsCollector .allocas .size ();
297301
298- if (config. analysis_config . filter_alloca_non_array ) {
302+ if (config[config::ConfigStdArgs::analysis_filter_alloca_non_array] ) {
299303 auto & allocs = mOpsCollector .allocas ;
300304 allocs.erase (llvm::remove_if (allocs,
301305 [&](const auto & data) {
@@ -308,7 +312,7 @@ bool MemInstFinderPass::runOnFunction(llvm::Function& function) {
308312 allocs.end ());
309313 }
310314
311- if (config. analysis_config . filter_heap_alloc ) {
315+ if (config[config::ConfigStdArgs::analysis_filter_heap_alloc] ) {
312316 auto & allocs = mOpsCollector .allocas ;
313317 auto & mallocs = mOpsCollector .mallocs ;
314318
@@ -344,7 +348,7 @@ bool MemInstFinderPass::runOnFunction(llvm::Function& function) {
344348 allocs.end ());
345349 }
346350
347- if (config. analysis_config . filter_pointer_alloc ) {
351+ if (config[config::ConfigStdArgs::analysis_filter_pointer_alloc] ) {
348352 auto & allocs = mOpsCollector .allocas ;
349353 allocs.erase (llvm::remove_if (allocs,
350354 [&](const auto & data) {
@@ -359,7 +363,7 @@ bool MemInstFinderPass::runOnFunction(llvm::Function& function) {
359363 }
360364
361365 // if (config.filter.useCallFilter) {
362- if (config. filter ) {
366+ if (config[config::ConfigStdArgs:: filter] ) {
363367 auto & allocs = mOpsCollector .allocas ;
364368 allocs.erase (llvm::remove_if (allocs,
365369 [&](const auto & data) {
@@ -414,7 +418,8 @@ void MemInstFinderPass::printStats(llvm::raw_ostream& out) const {
414418 Table stats (" MemInstFinderPass" );
415419 stats.wrap_header = true ;
416420 stats.wrap_length = true ;
417- stats.put (Row::make (" Filter string" , config.filter_config .glob ));
421+ std::string glob = config[config::ConfigStdArgs::filter_glob];
422+ stats.put (Row::make (" Filter string" , glob));
418423 stats.put (Row::make_row (" > Heap Memory" ));
419424 stats.put (Row::make (" Heap alloc" , NumDetectedHeap.getValue ()));
420425 stats.put (Row::make (" Heap call filtered %" , call_filter_heap_p));
@@ -449,8 +454,8 @@ const GlobalDataList& MemInstFinderPass::getModuleGlobals() const {
449454
450455std::unique_ptr<MemInstFinder> create_finder (const config::Configuration& config) {
451456 LOG_DEBUG (" Constructing MemInstFinder" )
452- const auto meminst_conf = config::helper::config_to_options (config);
453- return std::make_unique<MemInstFinderPass>(meminst_conf );
457+ // const auto meminst_conf = config::helper::config_to_options(config);
458+ return std::make_unique<MemInstFinderPass>(config );
454459}
455460
456461} // namespace typeart::analysis
0 commit comments