xref: /illumos-gate/usr/src/lib/libdemangle/common/rust.h (revision 1cd083931cfd3fb8617c1178f62bce417cfa6af2)
1 /*
2  * This file and its contents are supplied under the terms of the
3  * Common Development and Distribution License ("CDDL"), version 1.0.
4  * You may only use this file in accordance with the terms of version
5  * 1.0 of the CDDL.
6  *
7  * A full copy of the text of the CDDL should have accompanied this
8  * source.  A copy of the CDDL is also available via the Internet at
9  * http://www.illumos.org/license/CDDL.
10  */
11 
12 /*
13  * Copyright 2019 Joyent, Inc.
14  * Copyright 2021 Jason King
15  */
16 
17 #ifndef _RUST_H
18 #define	_RUST_H
19 
20 #include <errno.h>
21 #include <sys/types.h>
22 #include "demangle-sys.h"
23 #include "demangle_int.h"
24 #include "strview.h"
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
30 typedef enum rustenc_version {
31 	RUSTENC_LEGACY = -1,
32 	RUSTENC_V0 = 0
33 } rustenc_version_t;
34 
35 typedef struct rust_state {
36 	const char	*rs_str; /* The original string */
37 	custr_t		*rs_demangled;
38 	sysdem_ops_t	*rs_ops;
39 	custr_alloc_t	rs_cualloc;
40 	strview_t	rs_orig; /* strview of original string, sans prefix */
41 	int		rs_error;
42 	rustenc_version_t rs_encver;
43 	uint64_t	rs_lt_depth;
44 	boolean_t	rs_skip;
45 	boolean_t	rs_args_stay_open;
46 	boolean_t	rs_args_is_open;
47 	boolean_t	rs_verbose;
48 	boolean_t	rs_show_const_type;
49 	boolean_t	rs_isutf8;
50 } rust_state_t;
51 #define	HAS_ERROR(_st) ((_st)->rs_error != 0)
52 #define	SET_ERROR(_st) ((_st)->rs_error = errno)
53 
54 /*
55  * In certain circumstances, we need to parse an item, but not emit any
56  * output. These macros assist in that. To use:
57  *
58  * rust_state_t *st;
59  * boolean_t saved_state;
60  * ...
61  * SKIP_BEGIN(st, saved_state);
62  * ... stuff to no emit
63  * SKIP_END(st, saved_state);
64  */
65 #define	SKIP_BEGIN(_st, _save)		\
66 	(_save) = (_st)->rs_skip,	\
67 	(_st)->rs_skip = B_TRUE
68 #define	SKIP_END(_st, _n) (_st)->rs_skip = (_n)
69 
70 boolean_t rust_appendc(rust_state_t *, char);
71 boolean_t rust_append(rust_state_t *, const char *);
72 boolean_t rust_append_printf(rust_state_t *, const char *, ...) __PRINTFLIKE(2);
73 boolean_t rust_append_sv(rust_state_t *restrict, uint64_t, strview_t *restrict);
74 boolean_t rust_append_utf8_c(rust_state_t *, uint32_t);
75 boolean_t rust_parse_base10(rust_state_t *restrict, strview_t *restrict,
76     uint64_t *restrict);
77 boolean_t rust_demangle_legacy(rust_state_t *restrict, strview_t *restrict);
78 boolean_t rust_demangle_v0(rust_state_t *restrict, strview_t *restrict);
79 
80 boolean_t rustv0_puny_decode(rust_state_t *restrict, strview_t *restrict,
81     boolean_t);
82 
83 #ifdef __cplusplus
84 }
85 #endif
86 
87 #endif /* _RUST_H */
88