xref: /openbsd/usr.bin/ctfconv/dw.h (revision 0687c322)
1 /*	$OpenBSD: dw.h,v 1.2 2017/08/11 14:58:56 jasper Exp $ */
2 
3 /*
4  * Copyright (c) 2016 Martin Pieuchot
5  *
6  * Permission to use, copy, modify, and distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 #ifndef _DW_H_
20 #define _DW_H_
21 
22 struct dwbuf {
23 	const char		*buf;
24 	size_t			 len;
25 };
26 
27 struct dwattr {
28 	SIMPLEQ_ENTRY(dwattr)	 dat_next;
29 	uint64_t		 dat_attr;
30 	uint64_t		 dat_form;
31 };
32 
33 struct dwaval {
34 	SIMPLEQ_ENTRY(dwaval)	 dav_next;
35 	struct dwattr		*dav_dat;	/* corresponding attribute */
36 	union {
37 		struct dwbuf	 _buf;
38 		struct {
39 			const char	*_str;
40 			union {
41 				uint64_t	 _u64;
42 				int64_t		 _s64;
43 				uint32_t	 _u32;
44 				uint16_t	 _u16;
45 				uint8_t		 _u8;
46 			} _T;
47 		} _V;
48 	} AV;
49 #define dav_buf	AV._buf
50 #define dav_str	AV._V._str
51 #define dav_u64	AV._V._T._u64
52 #define dav_s64	AV._V._T._s64
53 #define dav_u32	AV._V._T._u32
54 #define dav_u16	AV._V._T._u16
55 #define dav_u8	AV._V._T._u8
56 };
57 
58 SIMPLEQ_HEAD(dwaval_queue, dwaval);
59 
60 struct dwdie {
61 	SIMPLEQ_ENTRY(dwdie)	 die_next;
62 	struct dwabbrev		*die_dab;
63 	size_t			 die_offset;
64 	uint8_t			 die_lvl;
65 	struct dwaval_queue	 die_avals;
66 };
67 
68 SIMPLEQ_HEAD(dwdie_queue, dwdie);
69 
70 struct dwabbrev {
71 	SIMPLEQ_ENTRY(dwabbrev)	 dab_next;
72 	uint64_t		 dab_code;
73 	uint64_t		 dab_tag;
74 	uint8_t			 dab_children;
75 	SIMPLEQ_HEAD(, dwattr)	 dab_attrs;
76 };
77 
78 SIMPLEQ_HEAD(dwabbrev_queue, dwabbrev);
79 
80 struct dwcu {
81 	uint64_t		 dcu_length;
82 	uint64_t		 dcu_abbroff;
83 	uint16_t		 dcu_version;
84 	uint8_t			 dcu_psize;
85 	size_t			 dcu_offset;	/* offset in the segment */
86 	struct dwabbrev_queue	 dcu_abbrevs;
87 	struct dwdie_queue	 dcu_dies;
88 };
89 
90 const char	*dw_tag2name(uint64_t);
91 const char	*dw_at2name(uint64_t);
92 const char	*dw_form2name(uint64_t);
93 const char	*dw_op2name(uint8_t);
94 
95 int	 dw_loc_parse(struct dwbuf *, uint8_t *, uint64_t *, uint64_t *);
96 
97 int	 dw_ab_parse(struct dwbuf *, struct dwabbrev_queue *);
98 int	 dw_cu_parse(struct dwbuf *, struct dwbuf *, size_t, struct dwcu **);
99 
100 void	 dw_dabq_purge(struct dwabbrev_queue *);
101 void	 dw_dcu_free(struct dwcu *);
102 
103 
104 #endif /* _DW_H_ */
105