150476Speter/* $OpenBSD: tables_shared.h,v 1.2 2015/11/19 22:16:43 tedu Exp $ */
215903Swosch
315903Swosch#ifdef FLEX_SCANNER
415903Swosch/*
515903Swoschdnl  tables_shared.h - tables serialization header
615903Swoschdnl
715903Swoschdnl  Copyright (c) 1990 The Regents of the University of California.
815903Swoschdnl  All rights reserved.
915903Swoschdnl
1015903Swoschdnl  This code is derived from software contributed to Berkeley by
1115903Swoschdnl  Vern Paxson.
1215903Swoschdnl
1315903Swoschdnl  The United States Government has rights in this work pursuant
14139761Skriondnl  to contract no. DE-AC03-76SF00098 between the United States
1534678Sbdednl  Department of Energy and the University of California.
1623546Swoschdnl
1723546Swoschdnl  This file is part of flex.
1823546Swoschdnl
1939161Sobriendnl  Redistribution and use in source and binary forms, with or without
2015903Swoschdnl  modification, are permitted provided that the following conditions
2139161Sobriendnl  are met:
2215903Swoschdnl
2315903Swoschdnl  1. Redistributions of source code must retain the above copyright
2415903Swoschdnl     notice, this list of conditions and the following disclaimer.
2515903Swoschdnl  2. Redistributions in binary form must reproduce the above copyright
2615903Swoschdnl     notice, this list of conditions and the following disclaimer in the
2715903Swoschdnl     documentation and/or other materials provided with the distribution.
2815903Swoschdnl
2932216Swoschdnl  Neither the name of the University nor the names of its contributors
3032216Swoschdnl  may be used to endorse or promote products derived from this software
3132216Swoschdnl  without specific prior written permission.
3232216Swoschdnl
33218525Skeramidadnl  THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
34218525Skeramidadnl  IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
3515903Swoschdnl  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
3615903Swoschdnl  PURPOSE.
3715903Swosch
3815903Swoschdnl
39119057Sobriendnl  This file is meant to be included in both the skeleton and the actual
4015903Swoschdnl  flex code (hence the name "_shared").
4115903Swosch*/
4215903Swosch#ifndef yyskel_static
4315903Swosch#define yyskel_static static
4415903Swosch#endif
4515903Swosch#else
4615903Swosch#ifndef yyskel_static
4765501Sobrien#define yyskel_static
4815903Swosch#endif
49186894Sbz#endif
5015903Swosch
51186894Sbz/* Structures and prototypes for serializing flex tables.  The
5215903Swosch * binary format is documented in the manual.
5353033Sphantom *
5415903Swosch * Design considerations:
5515903Swosch *
5615903Swosch *  -  The format allows many tables per file.
5715903Swosch *  -  The tables can be streamed.
5815903Swosch *  -  All data is stored in network byte order.
5939161Sobrien *  -  We do not hinder future unicode support.
6015903Swosch *  -  We can lookup tables by name.
6139161Sobrien */
6215903Swosch
6315903Swosch/** Magic number for serialized format. */
6415903Swosch#ifndef YYTBL_MAGIC
6515903Swosch#define YYTBL_MAGIC 0xF13C57B1
66223596Sse#endif
67223596Sse
68223596Sse/** Calculate (0-7) = number bytes needed to pad n to next 64-bit boundary. */
69223596Sse#ifndef yypad64
70223596Sse#define yypad64(n) ((8-((n)%8))%8)
71223596Sse#endif
72223596Sse
73223596Sse
74223596Sse#ifndef YYTABLES_TYPES
7515903Swosch#define YYTABLES_TYPES
7615903Swosch/** Possible values for td_id field. Each one corresponds to a
7715903Swosch *  scanner table of the same name.
7815903Swosch */
7915903Swoschenum yytbl_id {
8015903Swosch	YYTD_ID_ACCEPT = 0x01,		/**< 1-dim ints */
8115903Swosch	YYTD_ID_BASE = 0x02,		/**< 1-dim ints */
8215903Swosch	YYTD_ID_CHK = 0x03,		/**< 1-dim ints */
8315903Swosch	YYTD_ID_DEF = 0x04,		/**< 1-dim ints */
8415903Swosch	YYTD_ID_EC = 0x05,		/**< 1-dim ints */
8515903Swosch	YYTD_ID_META = 0x06,		/**< 1-dim ints */
8615903Swosch	YYTD_ID_NUL_TRANS = 0x07,	/**< 1-dim ints, maybe indices */
8715903Swosch	YYTD_ID_NXT = 0x08,		/**< may be 2 dimensional ints */
8815903Swosch	YYTD_ID_RULE_CAN_MATCH_EOL = 0x09, /**< 1-dim ints */
8915903Swosch	YYTD_ID_START_STATE_LIST = 0x0A,	/**< 1-dim indices into trans tbl  */
9015903Swosch	YYTD_ID_TRANSITION = 0x0B,	/**< structs */
9115903Swosch	YYTD_ID_ACCLIST = 0x0C		/**< 1-dim ints */
9215903Swosch};
9315903Swosch
9415903Swosch/** bit flags for t_flags field of struct yytbl_data */
9515903Swoschenum yytbl_flags {
9615903Swosch	/* These first three are mutually exclusive */
9715903Swosch	YYTD_DATA8 = 0x01,   /**< data is an array of type flex_int8_t */
9815903Swosch	YYTD_DATA16 = 0x02,  /**< data is an array of type flex_int16_t */
9915903Swosch	YYTD_DATA32 = 0x04,  /**< data is an array of type flex_int32_t */
10015903Swosch
10115903Swosch	/* These two are mutually exclusive. */
10215903Swosch	YYTD_PTRANS = 0x08,  /**< data is a list of indexes of entries
10315903Swosch                                 into the expanded `yy_transition'
10415903Swosch                                 array. See notes in manual. */
10590627Sphantom	YYTD_STRUCT = 0x10  /**< data consists of yy_trans_info structs */
10615903Swosch};
10790626Sphantom
10815903Swosch/* The serialized tables header. */
10990626Sphantomstruct yytbl_hdr {
11015903Swosch	flex_uint32_t th_magic;  /**< Must be 0xF13C57B1 (comes from "Flex Table") */
11161462Sghelmer	flex_uint32_t th_hsize;  /**< Size of this header in bytes. */
11215903Swosch	flex_uint32_t th_ssize;  /**< Size of this dataset, in bytes, including header. */
11332216Swosch	flex_uint16_t th_flags;  /**< Currently unused, must be 0 */
11415903Swosch	char   *th_version; /**< Flex version string. NUL terminated. */
11594982Sru	char   *th_name;    /**< The name of this table set. NUL terminated. */
11694982Sru};
11794982Sru
118164411Sru/** A single serialized table */
119156813Srustruct yytbl_data {
120156836Sru	flex_uint16_t td_id;      /**< enum yytbl_id table identifier */
121156836Sru	flex_uint16_t td_flags;   /**< how to interpret this data */
122156836Sru	flex_uint32_t td_hilen;   /**< num elements in highest dimension array */
123164411Sru	flex_uint32_t td_lolen;   /**< num elements in lowest dimension array */
124156813Sru	void   *td_data;     /**< table data */
12514968Swosch};
12639161Sobrien#endif
12739161Sobrien
12814573Swosch/** Extract corresponding data size_t from td_flags */
12914968Swosch#ifndef YYTDFLAGS2BYTES
13014573Swosch#define YYTDFLAGS2BYTES(td_flags)\
131111853Sru        (((td_flags) & YYTD_DATA8)\
132111853Sru            ? sizeof(flex_int8_t)\
133111853Sru            :(((td_flags) & YYTD_DATA16)\
13465501Sobrien                ? sizeof(flex_int16_t)\
135111853Sru                :sizeof(flex_int32_t)))
13648204Sjmg#endif
13748204Sjmg
13848204Sjmg#ifdef FLEX_SCANNER
13948204Sjmg%not-for-header
14014573Swosch#endif
14132226Ssteveyyskel_static flex_int32_t yytbl_calc_total_len (const struct yytbl_data *tbl);
14232226Ssteve#ifdef FLEX_SCANNER
143218525Skeramida%ok-for-header
14414573Swosch#endif
14514573Swosch