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