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