xref: /openbsd-src/usr.bin/lex/tables_shared.h (revision c35772119fd4c2c9d0eb8db5bd9d1282fdddf264)
1*c3577211Stedu /* $OpenBSD: tables_shared.h,v 1.2 2015/11/19 22:16:43 tedu Exp $ */
2a58c1ecbStedu 
3a58c1ecbStedu #ifdef FLEX_SCANNER
4a58c1ecbStedu /*
5a58c1ecbStedu dnl  tables_shared.h - tables serialization header
6a58c1ecbStedu dnl
7a58c1ecbStedu dnl  Copyright (c) 1990 The Regents of the University of California.
8a58c1ecbStedu dnl  All rights reserved.
9a58c1ecbStedu dnl
10a58c1ecbStedu dnl  This code is derived from software contributed to Berkeley by
11a58c1ecbStedu dnl  Vern Paxson.
12a58c1ecbStedu dnl
13a58c1ecbStedu dnl  The United States Government has rights in this work pursuant
14a58c1ecbStedu dnl  to contract no. DE-AC03-76SF00098 between the United States
15a58c1ecbStedu dnl  Department of Energy and the University of California.
16a58c1ecbStedu dnl
17a58c1ecbStedu dnl  This file is part of flex.
18a58c1ecbStedu dnl
19a58c1ecbStedu dnl  Redistribution and use in source and binary forms, with or without
20a58c1ecbStedu dnl  modification, are permitted provided that the following conditions
21a58c1ecbStedu dnl  are met:
22a58c1ecbStedu dnl
23a58c1ecbStedu dnl  1. Redistributions of source code must retain the above copyright
24a58c1ecbStedu dnl     notice, this list of conditions and the following disclaimer.
25a58c1ecbStedu dnl  2. Redistributions in binary form must reproduce the above copyright
26a58c1ecbStedu dnl     notice, this list of conditions and the following disclaimer in the
27a58c1ecbStedu dnl     documentation and/or other materials provided with the distribution.
28a58c1ecbStedu dnl
29a58c1ecbStedu dnl  Neither the name of the University nor the names of its contributors
30a58c1ecbStedu dnl  may be used to endorse or promote products derived from this software
31a58c1ecbStedu dnl  without specific prior written permission.
32a58c1ecbStedu dnl
33a58c1ecbStedu dnl  THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
34a58c1ecbStedu dnl  IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
35a58c1ecbStedu dnl  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
36a58c1ecbStedu dnl  PURPOSE.
37a58c1ecbStedu 
38a58c1ecbStedu dnl
39a58c1ecbStedu dnl  This file is meant to be included in both the skeleton and the actual
40a58c1ecbStedu dnl  flex code (hence the name "_shared").
41a58c1ecbStedu */
42a58c1ecbStedu #ifndef yyskel_static
43a58c1ecbStedu #define yyskel_static static
44a58c1ecbStedu #endif
45a58c1ecbStedu #else
46a58c1ecbStedu #ifndef yyskel_static
47a58c1ecbStedu #define yyskel_static
48a58c1ecbStedu #endif
49a58c1ecbStedu #endif
50a58c1ecbStedu 
51a58c1ecbStedu /* Structures and prototypes for serializing flex tables.  The
52a58c1ecbStedu  * binary format is documented in the manual.
53a58c1ecbStedu  *
54a58c1ecbStedu  * Design considerations:
55a58c1ecbStedu  *
56a58c1ecbStedu  *  -  The format allows many tables per file.
57a58c1ecbStedu  *  -  The tables can be streamed.
58a58c1ecbStedu  *  -  All data is stored in network byte order.
59a58c1ecbStedu  *  -  We do not hinder future unicode support.
60a58c1ecbStedu  *  -  We can lookup tables by name.
61a58c1ecbStedu  */
62a58c1ecbStedu 
63a58c1ecbStedu /** Magic number for serialized format. */
64a58c1ecbStedu #ifndef YYTBL_MAGIC
65a58c1ecbStedu #define YYTBL_MAGIC 0xF13C57B1
66a58c1ecbStedu #endif
67a58c1ecbStedu 
68a58c1ecbStedu /** Calculate (0-7) = number bytes needed to pad n to next 64-bit boundary. */
69a58c1ecbStedu #ifndef yypad64
70a58c1ecbStedu #define yypad64(n) ((8-((n)%8))%8)
71a58c1ecbStedu #endif
72a58c1ecbStedu 
73a58c1ecbStedu 
74a58c1ecbStedu #ifndef YYTABLES_TYPES
75a58c1ecbStedu #define YYTABLES_TYPES
76a58c1ecbStedu /** Possible values for td_id field. Each one corresponds to a
77a58c1ecbStedu  *  scanner table of the same name.
78a58c1ecbStedu  */
79a58c1ecbStedu enum yytbl_id {
80a58c1ecbStedu 	YYTD_ID_ACCEPT = 0x01,		/**< 1-dim ints */
81a58c1ecbStedu 	YYTD_ID_BASE = 0x02,		/**< 1-dim ints */
82a58c1ecbStedu 	YYTD_ID_CHK = 0x03,		/**< 1-dim ints */
83a58c1ecbStedu 	YYTD_ID_DEF = 0x04,		/**< 1-dim ints */
84a58c1ecbStedu 	YYTD_ID_EC = 0x05,		/**< 1-dim ints */
85a58c1ecbStedu 	YYTD_ID_META = 0x06,		/**< 1-dim ints */
86a58c1ecbStedu 	YYTD_ID_NUL_TRANS = 0x07,	/**< 1-dim ints, maybe indices */
87a58c1ecbStedu 	YYTD_ID_NXT = 0x08,		/**< may be 2 dimensional ints */
88a58c1ecbStedu 	YYTD_ID_RULE_CAN_MATCH_EOL = 0x09, /**< 1-dim ints */
89a58c1ecbStedu 	YYTD_ID_START_STATE_LIST = 0x0A,	/**< 1-dim indices into trans tbl  */
90a58c1ecbStedu 	YYTD_ID_TRANSITION = 0x0B,	/**< structs */
91a58c1ecbStedu 	YYTD_ID_ACCLIST = 0x0C		/**< 1-dim ints */
92a58c1ecbStedu };
93a58c1ecbStedu 
94a58c1ecbStedu /** bit flags for t_flags field of struct yytbl_data */
95a58c1ecbStedu enum yytbl_flags {
96a58c1ecbStedu 	/* These first three are mutually exclusive */
97a58c1ecbStedu 	YYTD_DATA8 = 0x01,   /**< data is an array of type flex_int8_t */
98a58c1ecbStedu 	YYTD_DATA16 = 0x02,  /**< data is an array of type flex_int16_t */
99a58c1ecbStedu 	YYTD_DATA32 = 0x04,  /**< data is an array of type flex_int32_t */
100a58c1ecbStedu 
101a58c1ecbStedu 	/* These two are mutually exclusive. */
102a58c1ecbStedu 	YYTD_PTRANS = 0x08,  /**< data is a list of indexes of entries
103a58c1ecbStedu                                  into the expanded `yy_transition'
104a58c1ecbStedu                                  array. See notes in manual. */
105a58c1ecbStedu 	YYTD_STRUCT = 0x10  /**< data consists of yy_trans_info structs */
106a58c1ecbStedu };
107a58c1ecbStedu 
108a58c1ecbStedu /* The serialized tables header. */
109a58c1ecbStedu struct yytbl_hdr {
110a58c1ecbStedu 	flex_uint32_t th_magic;  /**< Must be 0xF13C57B1 (comes from "Flex Table") */
111a58c1ecbStedu 	flex_uint32_t th_hsize;  /**< Size of this header in bytes. */
112a58c1ecbStedu 	flex_uint32_t th_ssize;  /**< Size of this dataset, in bytes, including header. */
113a58c1ecbStedu 	flex_uint16_t th_flags;  /**< Currently unused, must be 0 */
114a58c1ecbStedu 	char   *th_version; /**< Flex version string. NUL terminated. */
115a58c1ecbStedu 	char   *th_name;    /**< The name of this table set. NUL terminated. */
116a58c1ecbStedu };
117a58c1ecbStedu 
118a58c1ecbStedu /** A single serialized table */
119a58c1ecbStedu struct yytbl_data {
120a58c1ecbStedu 	flex_uint16_t td_id;      /**< enum yytbl_id table identifier */
121a58c1ecbStedu 	flex_uint16_t td_flags;   /**< how to interpret this data */
122a58c1ecbStedu 	flex_uint32_t td_hilen;   /**< num elements in highest dimension array */
123a58c1ecbStedu 	flex_uint32_t td_lolen;   /**< num elements in lowest dimension array */
124a58c1ecbStedu 	void   *td_data;     /**< table data */
125a58c1ecbStedu };
126a58c1ecbStedu #endif
127a58c1ecbStedu 
128a58c1ecbStedu /** Extract corresponding data size_t from td_flags */
129a58c1ecbStedu #ifndef YYTDFLAGS2BYTES
130a58c1ecbStedu #define YYTDFLAGS2BYTES(td_flags)\
131a58c1ecbStedu         (((td_flags) & YYTD_DATA8)\
132a58c1ecbStedu             ? sizeof(flex_int8_t)\
133a58c1ecbStedu             :(((td_flags) & YYTD_DATA16)\
134a58c1ecbStedu                 ? sizeof(flex_int16_t)\
135a58c1ecbStedu                 :sizeof(flex_int32_t)))
136a58c1ecbStedu #endif
137a58c1ecbStedu 
138a58c1ecbStedu #ifdef FLEX_SCANNER
139a58c1ecbStedu %not-for-header
140a58c1ecbStedu #endif
141a58c1ecbStedu yyskel_static flex_int32_t yytbl_calc_total_len (const struct yytbl_data *tbl);
142a58c1ecbStedu #ifdef FLEX_SCANNER
143a58c1ecbStedu %ok-for-header
144a58c1ecbStedu #endif
145