diff options
author | Ian Rogers <irogers@google.com> | 2021-09-23 00:46:08 -0700 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2021-09-29 13:41:41 -0300 |
commit | e87576c5ac14e038ac96145d289bf0134eb08506 (patch) | |
tree | 3c19d47c3920db4ac53988e0fbe54e8eece9e54d /tools/perf/util/expr.y | |
parent | aed0d6f8c6edab48be649a071e18d28efb1a203a (diff) |
perf expr: Use macros for operators
No functional change, switch the operators to use macros so that
additional complexity for constants can be added in a later change.
Signed-off-by: Ian Rogers <irogers@google.com>
Tested-by: John Garry <john.garry@huawei.com>
Acked-by: Jiri Olsa <jolsa@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Sandeep Dasgupta <sdasgup@google.com>
Cc: Stephane Eranian <eranian@google.com>
Link: https://lore.kernel.org/r/20210923074616.674826-6-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/expr.y')
-rw-r--r-- | tools/perf/util/expr.y | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/tools/perf/util/expr.y b/tools/perf/util/expr.y index 68b122e59b3f..5535badeef0a 100644 --- a/tools/perf/util/expr.y +++ b/tools/perf/util/expr.y @@ -43,6 +43,12 @@ static void expr_error(double *final_val __maybe_unused, pr_debug("%s\n", s); } +#define BINARY_LONG_OP(RESULT, OP, LHS, RHS) \ + RESULT = (long)LHS OP (long)RHS; + +#define BINARY_OP(RESULT, OP, LHS, RHS) \ + RESULT = LHS OP RHS; + %} %% @@ -81,14 +87,14 @@ expr: NUMBER free($1); } - | expr '|' expr { $$ = (long)$1 | (long)$3; } - | expr '&' expr { $$ = (long)$1 & (long)$3; } - | expr '^' expr { $$ = (long)$1 ^ (long)$3; } - | expr '<' expr { $$ = $1 < $3; } - | expr '>' expr { $$ = $1 > $3; } - | expr '+' expr { $$ = $1 + $3; } - | expr '-' expr { $$ = $1 - $3; } - | expr '*' expr { $$ = $1 * $3; } + | expr '|' expr { BINARY_LONG_OP($$, |, $1, $3); } + | expr '&' expr { BINARY_LONG_OP($$, &, $1, $3); } + | expr '^' expr { BINARY_LONG_OP($$, ^, $1, $3); } + | expr '<' expr { BINARY_OP($$, <, $1, $3); } + | expr '>' expr { BINARY_OP($$, >, $1, $3); } + | expr '+' expr { BINARY_OP($$, +, $1, $3); } + | expr '-' expr { BINARY_OP($$, -, $1, $3); } + | expr '*' expr { BINARY_OP($$, *, $1, $3); } | expr '/' expr { if ($3 == 0) { pr_debug("division by zero\n"); YYABORT; |