xref: /linux/tools/perf/util/expr.h (revision 4d39c89f0b94bf4a6e1ccf42702e7d80d210a5fd)
1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
207516736SAndi Kleen #ifndef PARSE_CTX_H
307516736SAndi Kleen #define PARSE_CTX_H 1
407516736SAndi Kleen 
5ded80bdaSIan Rogers // There are fixes that need to land upstream before we can use libbpf's headers,
6*4d39c89fSIngo Molnar // for now use our copy unconditionally, since the data structures at this point
7ded80bdaSIan Rogers // are exactly the same, no problem.
8ded80bdaSIan Rogers //#ifdef HAVE_LIBBPF_SUPPORT
9ded80bdaSIan Rogers //#include <bpf/hashmap.h>
10ded80bdaSIan Rogers //#else
11ded80bdaSIan Rogers #include "util/hashmap.h"
12ded80bdaSIan Rogers //#endif
1307516736SAndi Kleen 
14fc393839SJiri Olsa struct metric_ref;
15fc393839SJiri Olsa 
16f6fb0960SJiri Olsa struct expr_id {
17f6fb0960SJiri Olsa 	char		*id;
18f6fb0960SJiri Olsa 	struct expr_id	*parent;
19f6fb0960SJiri Olsa };
20f6fb0960SJiri Olsa 
21aecce63eSJiri Olsa struct expr_parse_ctx {
22ded80bdaSIan Rogers 	struct hashmap	 ids;
23f6fb0960SJiri Olsa 	struct expr_id	*parent;
2407516736SAndi Kleen };
2507516736SAndi Kleen 
2629396cd5SIan Rogers struct expr_id_data;
27070b3b5aSJiri Olsa 
28871f9f59SJiri Olsa struct expr_scanner_ctx {
29871f9f59SJiri Olsa 	int start_token;
301e1a873dSKajol Jain 	int runtime;
31871f9f59SJiri Olsa };
32871f9f59SJiri Olsa 
33aecce63eSJiri Olsa void expr__ctx_init(struct expr_parse_ctx *ctx);
34ded80bdaSIan Rogers void expr__ctx_clear(struct expr_parse_ctx *ctx);
353fd29fa6SJiri Olsa void expr__del_id(struct expr_parse_ctx *ctx, const char *id);
36332603c2SJiri Olsa int expr__add_id(struct expr_parse_ctx *ctx, const char *id);
372c46f542SJiri Olsa int expr__add_id_val(struct expr_parse_ctx *ctx, const char *id, double val);
38fc393839SJiri Olsa int expr__add_ref(struct expr_parse_ctx *ctx, struct metric_ref *ref);
395c5f5e83SJiri Olsa int expr__get_id(struct expr_parse_ctx *ctx, const char *id,
405c5f5e83SJiri Olsa 		 struct expr_id_data **data);
41acf71b05SJiri Olsa int expr__resolve_id(struct expr_parse_ctx *ctx, const char *id,
42acf71b05SJiri Olsa 		     struct expr_id_data **datap);
43ded80bdaSIan Rogers int expr__parse(double *final_val, struct expr_parse_ctx *ctx,
44ded80bdaSIan Rogers 		const char *expr, int runtime);
45ded80bdaSIan Rogers int expr__find_other(const char *expr, const char *one,
46ded80bdaSIan Rogers 		struct expr_parse_ctx *ids, int runtime);
4707516736SAndi Kleen 
4829396cd5SIan Rogers double expr_id_data__value(const struct expr_id_data *data);
4929396cd5SIan Rogers struct expr_id *expr_id_data__parent(struct expr_id_data *data);
5029396cd5SIan Rogers 
5107516736SAndi Kleen #endif
52