[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230901233949.2930562-4-irogers@google.com>
Date: Fri, 1 Sep 2023 16:39:47 -0700
From: Ian Rogers <irogers@...gle.com>
To: Peter Zijlstra <peterz@...radead.org>,
Ingo Molnar <mingo@...hat.com>,
Arnaldo Carvalho de Melo <acme@...nel.org>,
Mark Rutland <mark.rutland@....com>,
Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
Jiri Olsa <jolsa@...nel.org>,
Namhyung Kim <namhyung@...nel.org>,
Ian Rogers <irogers@...gle.com>,
Adrian Hunter <adrian.hunter@...el.com>,
James Clark <james.clark@....com>,
Kan Liang <kan.liang@...ux.intel.com>,
Rob Herring <robh@...nel.org>,
linux-perf-users@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: [PATCH v1 4/6] perf parse-events: Avoid enum casts
Add term_type to union of values returned by the lexer to avoid casts
to and from an integer.
Signed-off-by: Ian Rogers <irogers@...gle.com>
---
tools/perf/util/parse-events.l | 2 +-
tools/perf/util/parse-events.y | 25 +++++++++++--------------
2 files changed, 12 insertions(+), 15 deletions(-)
diff --git a/tools/perf/util/parse-events.l b/tools/perf/util/parse-events.l
index 4ef4b6f171a0..7bdf0565a92c 100644
--- a/tools/perf/util/parse-events.l
+++ b/tools/perf/util/parse-events.l
@@ -120,7 +120,7 @@ static int term(yyscan_t scanner, enum parse_events__term_type type)
{
YYSTYPE *yylval = parse_events_get_lval(scanner);
- yylval->num = type;
+ yylval->term_type = type;
return PE_TERM;
}
diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y
index 4a305df61f74..4fae7847d13b 100644
--- a/tools/perf/util/parse-events.y
+++ b/tools/perf/util/parse-events.y
@@ -70,7 +70,7 @@ static void free_list_evsel(struct list_head* list_evsel)
%type <num> PE_VALUE_SYM_HW
%type <num> PE_VALUE_SYM_SW
%type <num> PE_VALUE_SYM_TOOL
-%type <num> PE_TERM
+%type <term_type> PE_TERM
%type <num> value_sym
%type <str> PE_RAW
%type <str> PE_NAME
@@ -111,6 +111,7 @@ static void free_list_evsel(struct list_head* list_evsel)
{
char *str;
u64 num;
+ enum parse_events__term_type term_type;
struct list_head *list_evsel;
struct list_head *list_terms;
struct parse_events_term *term;
@@ -778,8 +779,7 @@ PE_TERM_HW
PE_TERM '=' name_or_legacy
{
struct parse_events_term *term;
- int err = parse_events_term__str(&term, (enum parse_events__term_type)$1,
- /*config=*/NULL, $3, &@1, &@3);
+ int err = parse_events_term__str(&term, $1, /*config=*/NULL, $3, &@1, &@3);
if (err) {
free($3);
@@ -791,8 +791,7 @@ PE_TERM '=' name_or_legacy
PE_TERM '=' PE_TERM_HW
{
struct parse_events_term *term;
- int err = parse_events_term__str(&term, (enum parse_events__term_type)$1,
- /*config=*/NULL, $3.str, &@1, &@3);
+ int err = parse_events_term__str(&term, $1, /*config=*/NULL, $3.str, &@1, &@3);
if (err) {
free($3.str);
@@ -804,10 +803,7 @@ PE_TERM '=' PE_TERM_HW
PE_TERM '=' PE_TERM
{
struct parse_events_term *term;
- int err = parse_events_term__term(&term,
- (enum parse_events__term_type)$1,
- (enum parse_events__term_type)$3,
- &@1, &@3);
+ int err = parse_events_term__term(&term, $1, $3, &@1, &@3);
if (err)
PE_ABORT(err);
@@ -818,8 +814,9 @@ PE_TERM '=' PE_TERM
PE_TERM '=' PE_VALUE
{
struct parse_events_term *term;
- int err = parse_events_term__num(&term, (enum parse_events__term_type)$1,
- /*config=*/NULL, $3, /*novalue=*/false, &@1, &@3);
+ int err = parse_events_term__num(&term, $1,
+ /*config=*/NULL, $3, /*novalue=*/false,
+ &@1, &@3);
if (err)
PE_ABORT(err);
@@ -830,9 +827,9 @@ PE_TERM '=' PE_VALUE
PE_TERM
{
struct parse_events_term *term;
- int err = parse_events_term__num(&term, (enum parse_events__term_type)$1,
- /*config=*/NULL, /*num=*/1, /*novalue=*/true,
- &@1, /*loc_val=*/NULL);
+ int err = parse_events_term__num(&term, $1,
+ /*config=*/NULL, /*num=*/1, /*novalue=*/true,
+ &@1, /*loc_val=*/NULL);
if (err)
PE_ABORT(err);
--
2.42.0.283.g2d96d420d3-goog
Powered by blists - more mailing lists