xref: /OK3568_Linux_fs/kernel/tools/perf/util/expr.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */
2*4882a593Smuzhiyun #ifndef PARSE_CTX_H
3*4882a593Smuzhiyun #define PARSE_CTX_H 1
4*4882a593Smuzhiyun 
5*4882a593Smuzhiyun // There are fixes that need to land upstream before we can use libbpf's headers,
6*4882a593Smuzhiyun // for now use our copy uncoditionally, since the data structures at this point
7*4882a593Smuzhiyun // are exactly the same, no problem.
8*4882a593Smuzhiyun //#ifdef HAVE_LIBBPF_SUPPORT
9*4882a593Smuzhiyun //#include <bpf/hashmap.h>
10*4882a593Smuzhiyun //#else
11*4882a593Smuzhiyun #include "util/hashmap.h"
12*4882a593Smuzhiyun //#endif
13*4882a593Smuzhiyun 
14*4882a593Smuzhiyun struct metric_ref;
15*4882a593Smuzhiyun 
16*4882a593Smuzhiyun struct expr_id {
17*4882a593Smuzhiyun 	char		*id;
18*4882a593Smuzhiyun 	struct expr_id	*parent;
19*4882a593Smuzhiyun };
20*4882a593Smuzhiyun 
21*4882a593Smuzhiyun struct expr_parse_ctx {
22*4882a593Smuzhiyun 	struct hashmap	 ids;
23*4882a593Smuzhiyun 	struct expr_id	*parent;
24*4882a593Smuzhiyun };
25*4882a593Smuzhiyun 
26*4882a593Smuzhiyun struct expr_id_data {
27*4882a593Smuzhiyun 	union {
28*4882a593Smuzhiyun 		double val;
29*4882a593Smuzhiyun 		struct {
30*4882a593Smuzhiyun 			const char *metric_name;
31*4882a593Smuzhiyun 			const char *metric_expr;
32*4882a593Smuzhiyun 			bool counted;
33*4882a593Smuzhiyun 		} ref;
34*4882a593Smuzhiyun 		struct expr_id	*parent;
35*4882a593Smuzhiyun 	};
36*4882a593Smuzhiyun 
37*4882a593Smuzhiyun 	bool is_ref;
38*4882a593Smuzhiyun };
39*4882a593Smuzhiyun 
40*4882a593Smuzhiyun struct expr_scanner_ctx {
41*4882a593Smuzhiyun 	int start_token;
42*4882a593Smuzhiyun 	int runtime;
43*4882a593Smuzhiyun };
44*4882a593Smuzhiyun 
45*4882a593Smuzhiyun void expr__ctx_init(struct expr_parse_ctx *ctx);
46*4882a593Smuzhiyun void expr__ctx_clear(struct expr_parse_ctx *ctx);
47*4882a593Smuzhiyun void expr__del_id(struct expr_parse_ctx *ctx, const char *id);
48*4882a593Smuzhiyun int expr__add_id(struct expr_parse_ctx *ctx, const char *id);
49*4882a593Smuzhiyun int expr__add_id_val(struct expr_parse_ctx *ctx, const char *id, double val);
50*4882a593Smuzhiyun int expr__add_ref(struct expr_parse_ctx *ctx, struct metric_ref *ref);
51*4882a593Smuzhiyun int expr__get_id(struct expr_parse_ctx *ctx, const char *id,
52*4882a593Smuzhiyun 		 struct expr_id_data **data);
53*4882a593Smuzhiyun int expr__resolve_id(struct expr_parse_ctx *ctx, const char *id,
54*4882a593Smuzhiyun 		     struct expr_id_data **datap);
55*4882a593Smuzhiyun int expr__parse(double *final_val, struct expr_parse_ctx *ctx,
56*4882a593Smuzhiyun 		const char *expr, int runtime);
57*4882a593Smuzhiyun int expr__find_other(const char *expr, const char *one,
58*4882a593Smuzhiyun 		struct expr_parse_ctx *ids, int runtime);
59*4882a593Smuzhiyun 
60*4882a593Smuzhiyun #endif
61