forked from osmocom/wireshark
dfilter: Add optimization flag
When we are just testing code to see if it compiles performing optimizations is wasteful. Add an option to disable them.
This commit is contained in:
parent
4b0bf62791
commit
84e75be5c6
2
dftest.c
2
dftest.c
|
@ -165,7 +165,7 @@ main(int argc, char **argv)
|
|||
|
||||
/* Compile it */
|
||||
if (!dfilter_compile_real(expanded_text, &df, &df_err,
|
||||
"dftest", TRUE, FALSE)) {
|
||||
"dftest", TRUE, FALSE, FALSE)) {
|
||||
fprintf(stderr, "dftest: %s\n", df_err->msg);
|
||||
if (df_err->loc.col_start >= 0) {
|
||||
fprintf(stderr, "\t%s\n", expanded_text);
|
||||
|
|
|
@ -55,6 +55,7 @@ typedef struct {
|
|||
GHashTable *references; /* hfinfo -> pointer to array of references */
|
||||
GHashTable *raw_references; /* hfinfo -> pointer to array of references */
|
||||
char *expanded_text;
|
||||
gboolean apply_optimization;
|
||||
} dfwork_t;
|
||||
|
||||
/*
|
||||
|
|
|
@ -357,7 +357,7 @@ gboolean
|
|||
dfilter_compile_real(const gchar *text, dfilter_t **dfp,
|
||||
df_error_t **errpp,
|
||||
const char *caller, gboolean save_tree,
|
||||
gboolean apply_macros)
|
||||
gboolean apply_macros, gboolean apply_optimization)
|
||||
{
|
||||
int token;
|
||||
dfilter_t *dfilter;
|
||||
|
@ -393,6 +393,7 @@ dfilter_compile_real(const gchar *text, dfilter_t **dfp,
|
|||
}
|
||||
|
||||
dfw = dfwork_new();
|
||||
dfw->apply_optimization = apply_optimization;
|
||||
|
||||
if (apply_macros) {
|
||||
dfw->expanded_text = dfilter_macro_apply(text, &dfw->error.msg);
|
||||
|
|
|
@ -69,15 +69,16 @@ WS_DLL_PUBLIC
|
|||
void
|
||||
dfilter_error_free(df_error_t *);
|
||||
|
||||
// TODO: Replace booleans with a bit flag.
|
||||
WS_DLL_PUBLIC
|
||||
gboolean
|
||||
dfilter_compile_real(const gchar *text, dfilter_t **dfp,
|
||||
df_error_t **errpp,
|
||||
const char *caller, gboolean save_tree,
|
||||
gboolean apply_macros);
|
||||
gboolean apply_macros, gboolean apply_optimization);
|
||||
|
||||
#define dfilter_compile(text, dfp, errp) \
|
||||
dfilter_compile_real(text, dfp, errp, __func__, FALSE, TRUE)
|
||||
dfilter_compile_real(text, dfp, errp, __func__, FALSE, TRUE, TRUE)
|
||||
|
||||
/* Frees all memory used by dfilter, and frees
|
||||
* the dfilter itself. */
|
||||
|
|
|
@ -846,7 +846,9 @@ dfw_gencode(dfwork_t *dfw)
|
|||
dfw->interesting_fields = g_hash_table_new(g_int_hash, g_int_equal);
|
||||
gencode(dfw, dfw->st_root);
|
||||
dfw_append_insn(dfw, dfvm_insn_new(DFVM_RETURN));
|
||||
optimize(dfw);
|
||||
if (dfw->apply_optimization) {
|
||||
optimize(dfw);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
2
tshark.c
2
tshark.c
|
@ -626,7 +626,7 @@ _compile_dfilter(const char *text, dfilter_t **dfp, const char *caller)
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
ok = dfilter_compile_real(expanded, dfp, &df_err, caller, FALSE, FALSE);
|
||||
ok = dfilter_compile_real(expanded, dfp, &df_err, caller, FALSE, FALSE, TRUE);
|
||||
if (!ok ) {
|
||||
cmdarg_err("%s", df_err->msg);
|
||||
|
||||
|
|
Loading…
Reference in New Issue