diff --git a/src/Options.cc b/src/Options.cc index 6fac075223..9d6e195af6 100644 --- a/src/Options.cc +++ b/src/Options.cc @@ -151,6 +151,7 @@ static void set_analysis_option(const char* opt, Options& opts) { opts.analysis_options.inliner = true; opts.analysis_options.activate = true; + opts.analysis_options.optimize_AST = true; return; } @@ -161,6 +162,7 @@ static void set_analysis_option(const char* opt, Options& opts) fprintf(stderr, " dump-xform dump transformed scripts to stdout; implies xform\n"); fprintf(stderr, " help print this list\n"); fprintf(stderr, " inline inline function calls\n"); + fprintf(stderr, " optimize-AST optimize the (transformed) AST; implies xform\n"); fprintf(stderr, " recursive report on recursive functions and exit\n"); fprintf(stderr, " xform tranform scripts to \"reduced\" form\n"); exit(0); @@ -178,6 +180,8 @@ static void set_analysis_option(const char* opt, Options& opts) a_o.inliner = a_o.report_recursive = true; else if ( util::streq(opt, "xform") ) a_o.activate = true; + else if ( util::streq(opt, "optimize-AST") ) + a_o.activate = a_o.optimize_AST = true; else { diff --git a/src/script_opt/ScriptOpt.cc b/src/script_opt/ScriptOpt.cc index 5937578d15..e635ff79e6 100644 --- a/src/script_opt/ScriptOpt.cc +++ b/src/script_opt/ScriptOpt.cc @@ -133,6 +133,7 @@ void analyze_scripts() check_env_opt("ZEEK_DUMP_XFORM", analysis_options.dump_xform); check_env_opt("ZEEK_DUMP_UDS", analysis_options.dump_uds); check_env_opt("ZEEK_INLINE", analysis_options.inliner); + check_env_opt("ZEEK_OPT", analysis_options.optimize_AST); check_env_opt("ZEEK_XFORM", analysis_options.activate); auto usage = getenv("ZEEK_USAGE_ISSUES"); @@ -148,6 +149,7 @@ void analyze_scripts() } if ( analysis_options.only_func || + analysis_options.optimize_AST || analysis_options.usage_issues > 0 ) analysis_options.activate = true; @@ -157,6 +159,12 @@ void analyze_scripts() if ( ! analysis_options.activate && ! analysis_options.inliner ) return; + if ( analysis_options.usage_issues > 0 && analysis_options.optimize_AST ) + { + fprintf(stderr, "warning: \"-O optimize-AST\" option is incompatible with -u option, deactivating optimization\n"); + analysis_options.optimize_AST = false; + } + // Now that everything's parsed and BiF's have been initialized, // profile the functions. std::unordered_map> diff --git a/src/script_opt/ScriptOpt.h b/src/script_opt/ScriptOpt.h index 3ea6564c9e..bf6a3e813a 100644 --- a/src/script_opt/ScriptOpt.h +++ b/src/script_opt/ScriptOpt.h @@ -22,6 +22,9 @@ struct AnalyOpt { // Whether to analyze scripts. bool activate = false; + // Whether to optimize the AST. + bool optimize_AST = false; + // If true, dump out transformed code: the results of reducing // interpreted scripts, and, if optimize is set, of then optimizing // them. Always done if only_func is set.