mirror of
https://gitlab.com/apparmor/apparmor
synced 2025-08-31 06:16:03 +00:00
parser: cleanup and rework optimization and dump flag handling
In preparation for more flags (not all of the backend dfa based), rework the optimization and dump flag handling which has been exclusively around the dfa up to this point. - split dfa control and dump flags into separate fields. This gives more room for new flags in the existing DFA set - rename DFA_DUMP, and DFA_CONTROL to CONTROL_DFA and DUMP_DFA as this will provide more uniform naming for none dfa flags - group dump and control flags into a structure so they can be passed together. Signed-off-by: John Johansen <john.johansen@canonical.com>
This commit is contained in:
@@ -27,82 +27,90 @@
|
||||
#include "common_optarg.h"
|
||||
#include "parser.h"
|
||||
|
||||
optflag_table_t dumpflag_table[] = {
|
||||
optflag_table_t dfadumpflag_table[] = {
|
||||
{ 1, "rule-exprs", "Dump rule to expr tree conversions",
|
||||
DFA_DUMP_RULE_EXPR },
|
||||
{ 1, "expr-stats", "Dump stats on expr tree", DFA_DUMP_TREE_STATS },
|
||||
{ 1, "expr-tree", "Dump expression tree", DFA_DUMP_TREE },
|
||||
DUMP_DFA_RULE_EXPR },
|
||||
{ 1, "expr-stats", "Dump stats on expr tree", DUMP_DFA_TREE_STATS },
|
||||
{ 1, "expr-tree", "Dump expression tree", DUMP_DFA_TREE },
|
||||
{ 1, "expr-simplified", "Dump simplified expression tree",
|
||||
DFA_DUMP_SIMPLE_TREE },
|
||||
DUMP_DFA_SIMPLE_TREE },
|
||||
{ 1, "stats", "Dump all compile stats",
|
||||
DFA_DUMP_TREE_STATS | DFA_DUMP_STATS | DFA_DUMP_TRANS_STATS |
|
||||
DFA_DUMP_EQUIV_STATS | DFA_DUMP_DIFF_STATS },
|
||||
DUMP_DFA_TREE_STATS | DUMP_DFA_STATS | DUMP_DFA_TRANS_STATS |
|
||||
DUMP_DFA_EQUIV_STATS | DUMP_DFA_DIFF_STATS },
|
||||
{ 1, "progress", "Dump progress for all compile phases",
|
||||
DFA_DUMP_PROGRESS | DFA_DUMP_STATS | DFA_DUMP_TRANS_PROGRESS |
|
||||
DFA_DUMP_TRANS_STATS | DFA_DUMP_DIFF_PROGRESS | DFA_DUMP_DIFF_STATS },
|
||||
DUMP_DFA_PROGRESS | DUMP_DFA_STATS | DUMP_DFA_TRANS_PROGRESS |
|
||||
DUMP_DFA_TRANS_STATS | DUMP_DFA_DIFF_PROGRESS | DUMP_DFA_DIFF_STATS },
|
||||
{ 1, "dfa-progress", "Dump dfa creation as in progress",
|
||||
DFA_DUMP_PROGRESS | DFA_DUMP_STATS },
|
||||
{ 1, "dfa-stats", "Dump dfa creation stats", DFA_DUMP_STATS },
|
||||
{ 1, "dfa-states", "Dump dfa state diagram", DFA_DUMP_STATES },
|
||||
{ 1, "dfa-graph", "Dump dfa dot (graphviz) graph", DFA_DUMP_GRAPH },
|
||||
{ 1, "dfa-minimize", "Dump dfa minimization", DFA_DUMP_MINIMIZE },
|
||||
DUMP_DFA_PROGRESS | DUMP_DFA_STATS },
|
||||
{ 1, "dfa-stats", "Dump dfa creation stats", DUMP_DFA_STATS },
|
||||
{ 1, "dfa-states", "Dump dfa state diagram", DUMP_DFA_STATES },
|
||||
{ 1, "dfa-graph", "Dump dfa dot (graphviz) graph", DUMP_DFA_GRAPH },
|
||||
{ 1, "dfa-minimize", "Dump dfa minimization", DUMP_DFA_MINIMIZE },
|
||||
{ 1, "dfa-unreachable", "Dump dfa unreachable states",
|
||||
DFA_DUMP_UNREACHABLE },
|
||||
DUMP_DFA_UNREACHABLE },
|
||||
{ 1, "dfa-node-map", "Dump expr node set to state mapping",
|
||||
DFA_DUMP_NODE_TO_DFA },
|
||||
DUMP_DFA_NODE_TO_DFA },
|
||||
{ 1, "dfa-uniq-perms", "Dump unique perms",
|
||||
DFA_DUMP_UNIQ_PERMS },
|
||||
DUMP_DFA_UNIQ_PERMS },
|
||||
{ 1, "dfa-minimize-uniq-perms", "Dump unique perms post minimization",
|
||||
DFA_DUMP_MIN_UNIQ_PERMS },
|
||||
DUMP_DFA_MIN_UNIQ_PERMS },
|
||||
{ 1, "dfa-minimize-partitions", "Dump dfa minimization partitions",
|
||||
DFA_DUMP_MIN_PARTS },
|
||||
DUMP_DFA_MIN_PARTS },
|
||||
{ 1, "compress-progress", "Dump progress of compression",
|
||||
DFA_DUMP_TRANS_PROGRESS | DFA_DUMP_TRANS_STATS },
|
||||
DUMP_DFA_TRANS_PROGRESS | DUMP_DFA_TRANS_STATS },
|
||||
{ 1, "compress-stats", "Dump stats on compression",
|
||||
DFA_DUMP_TRANS_STATS },
|
||||
{ 1, "compressed-dfa", "Dump compressed dfa", DFA_DUMP_TRANS_TABLE },
|
||||
DUMP_DFA_TRANS_STATS },
|
||||
{ 1, "compressed-dfa", "Dump compressed dfa", DUMP_DFA_TRANS_TABLE },
|
||||
{ 1, "equiv-stats", "Dump equivalence class stats",
|
||||
DFA_DUMP_EQUIV_STATS },
|
||||
{ 1, "equiv", "Dump equivalence class", DFA_DUMP_EQUIV },
|
||||
DUMP_DFA_EQUIV_STATS },
|
||||
{ 1, "equiv", "Dump equivalence class", DUMP_DFA_EQUIV },
|
||||
{ 1, "diff-encode", "Dump differential encoding",
|
||||
DFA_DUMP_DIFF_ENCODE },
|
||||
DUMP_DFA_DIFF_ENCODE },
|
||||
{ 1, "diff-stats", "Dump differential encoding stats",
|
||||
DFA_DUMP_DIFF_STATS },
|
||||
DUMP_DFA_DIFF_STATS },
|
||||
{ 1, "diff-progress", "Dump progress of differential encoding",
|
||||
DFA_DUMP_DIFF_PROGRESS | DFA_DUMP_DIFF_STATS },
|
||||
DUMP_DFA_DIFF_PROGRESS | DUMP_DFA_DIFF_STATS },
|
||||
{ 0, NULL, NULL, 0 },
|
||||
};
|
||||
|
||||
optflag_table_t optflag_table[] = {
|
||||
optflag_table_t dfaoptflag_table[] = {
|
||||
{ 2, "0", "no optimizations",
|
||||
DFA_CONTROL_TREE_NORMAL | DFA_CONTROL_TREE_SIMPLE |
|
||||
DFA_CONTROL_MINIMIZE | DFA_CONTROL_REMOVE_UNREACHABLE |
|
||||
DFA_CONTROL_DIFF_ENCODE
|
||||
CONTROL_DFA_TREE_NORMAL | CONTROL_DFA_TREE_SIMPLE |
|
||||
CONTROL_DFA_MINIMIZE | CONTROL_DFA_REMOVE_UNREACHABLE |
|
||||
CONTROL_DFA_DIFF_ENCODE
|
||||
},
|
||||
{ 1, "equiv", "use equivalent classes", DFA_CONTROL_EQUIV },
|
||||
{ 1, "equiv", "use equivalent classes", CONTROL_DFA_EQUIV },
|
||||
{ 1, "expr-normalize", "expression tree normalization",
|
||||
DFA_CONTROL_TREE_NORMAL },
|
||||
CONTROL_DFA_TREE_NORMAL },
|
||||
{ 1, "expr-simplify", "expression tree simplification",
|
||||
DFA_CONTROL_TREE_SIMPLE },
|
||||
CONTROL_DFA_TREE_SIMPLE },
|
||||
{ 0, "expr-left-simplify", "left simplification first",
|
||||
DFA_CONTROL_TREE_LEFT },
|
||||
CONTROL_DFA_TREE_LEFT },
|
||||
{ 2, "expr-right-simplify", "right simplification first",
|
||||
DFA_CONTROL_TREE_LEFT },
|
||||
{ 1, "minimize", "dfa state minimization", DFA_CONTROL_MINIMIZE },
|
||||
CONTROL_DFA_TREE_LEFT },
|
||||
{ 1, "minimize", "dfa state minimization", CONTROL_DFA_MINIMIZE },
|
||||
{ 1, "filter-deny", "filter out deny information from final dfa",
|
||||
DFA_CONTROL_FILTER_DENY },
|
||||
CONTROL_DFA_FILTER_DENY },
|
||||
{ 1, "remove-unreachable", "dfa unreachable state removal",
|
||||
DFA_CONTROL_REMOVE_UNREACHABLE },
|
||||
CONTROL_DFA_REMOVE_UNREACHABLE },
|
||||
{ 0, "compress-small",
|
||||
"do slower dfa transition table compression",
|
||||
DFA_CONTROL_TRANS_HIGH },
|
||||
CONTROL_DFA_TRANS_HIGH },
|
||||
{ 2, "compress-fast", "do faster dfa transition table compression",
|
||||
DFA_CONTROL_TRANS_HIGH },
|
||||
CONTROL_DFA_TRANS_HIGH },
|
||||
{ 1, "diff-encode", "Differentially encode transitions",
|
||||
DFA_CONTROL_DIFF_ENCODE },
|
||||
CONTROL_DFA_DIFF_ENCODE },
|
||||
{ 0, NULL, NULL, 0 },
|
||||
};
|
||||
|
||||
optflags parseopts = {
|
||||
.dfaflags = (optflags_t)(CONTROL_DFA_TREE_NORMAL | CONTROL_DFA_TREE_SIMPLE | CONTROL_DFA_MINIMIZE | CONTROL_DFA_DIFF_ENCODE),
|
||||
.dfadump = 0,
|
||||
.warn = DEFAULT_WARNINGS,
|
||||
.Werror = 0
|
||||
};
|
||||
|
||||
|
||||
void print_flag_table(optflag_table_t *table)
|
||||
{
|
||||
int i;
|
||||
@@ -114,12 +122,14 @@ void print_flag_table(optflag_table_t *table)
|
||||
|
||||
printf("%-*s \t%s\n", longest, " show", "show flags that have been set and exit");
|
||||
for (i = 0; table[i].option; i++) {
|
||||
printf("%5s%-*s \t%s\n", (table[i].control & 1) ? "[no-]" : "",
|
||||
printf("%5s%-*s \t%s\n",
|
||||
(table[i].control & OPT_FLAG_CONTROL_PREFIX_NO) ? "[no-]" : "",
|
||||
longest, table[i].option, table[i].desc);
|
||||
}
|
||||
}
|
||||
|
||||
void print_flags(const char *prefix, optflag_table_t *table, dfaflags_t flags)
|
||||
void print_flags(const char *prefix, optflag_table_t *table,
|
||||
optflags_t flags)
|
||||
{
|
||||
int i, count = 0;
|
||||
|
||||
@@ -137,7 +147,7 @@ void print_flags(const char *prefix, optflag_table_t *table, dfaflags_t flags)
|
||||
}
|
||||
|
||||
int handle_flag_table(optflag_table_t *table, const char *optarg,
|
||||
dfaflags_t *flags)
|
||||
optflags_t *flags)
|
||||
{
|
||||
const char *arg = optarg;
|
||||
int i, invert = 0;
|
||||
|
Reference in New Issue
Block a user