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