mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-16 07:43:03 +00:00
* lib/libiberty.h: New.
* lib: Update the bitset implementation from upstream. * src/closure.c, src/lalr.c, src/output.c, src/print_graph.c, * src/state.c: Use BITSET_FOR_EACH, not BITSET_EXECUTE. * src/main.c: Adjust bitset stats calls.
This commit is contained in:
125
lib/bbitset.h
125
lib/bbitset.h
@@ -19,43 +19,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
#ifndef _BBITSET_H
|
||||
#define _BBITSET_H
|
||||
|
||||
/* Bison modifications: BEGIN. */
|
||||
#define IN_BISON 1
|
||||
#if IN_BISON
|
||||
# if HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
# endif
|
||||
# include <stdlib.h>
|
||||
|
||||
# define BITSET_STATS 1
|
||||
/* This file is the public interface to the bitset abstract data type.
|
||||
Only use the functions and macros defined in this file. */
|
||||
|
||||
# ifndef PARAMS
|
||||
# if defined PROTOTYPES || (defined __STDC__ && __STDC__)
|
||||
# define PARAMS(Args) Args
|
||||
# else
|
||||
# define PARAMS(Args) ()
|
||||
# endif
|
||||
# endif
|
||||
|
||||
# ifndef __attribute__
|
||||
# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8) || __STRICT_ANSI__
|
||||
# define __attribute__(x)
|
||||
# endif
|
||||
# endif
|
||||
|
||||
# ifndef ATTRIBUTE_NORETURN
|
||||
# define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
|
||||
# endif
|
||||
|
||||
# ifndef ATTRIBUTE_UNUSED
|
||||
# define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
|
||||
# endif
|
||||
# include "xalloc.h"
|
||||
#else /* ! IN_BISON */
|
||||
# include "libiberty.h"
|
||||
#endif
|
||||
#include "libiberty.h"
|
||||
|
||||
#ifdef HAVE_LIMITS_H
|
||||
#include <limits.h>
|
||||
@@ -64,25 +28,21 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
/* Currently we support three flavours of bitsets:
|
||||
BITSET_ARRAY: Array of bits (fixed size, faster).
|
||||
BITSET_LIST: Linked list of array of bits (variable size, least storage
|
||||
for large very sparse sets).
|
||||
BITSET_TABLE: Expandable table of pointers to array of bits
|
||||
(variable size, less storage for large sparse sets).
|
||||
*/
|
||||
enum bitset_type {BITSET_ARRAY, BITSET_LIST, BITSET_TABLE, BITSET_TYPE_NUM};
|
||||
#define BITSET_TYPE_NAMES {"sbitset", "lbitset", "ebitset"}
|
||||
for large very sparse sets).
|
||||
BITSET_TABLE: Expandable table of pointers to array of bits
|
||||
(variable size, less storage for large sparse sets).
|
||||
|
||||
/* Non-zero to enable bitset caching. */
|
||||
#define BITSET_CACHE 1
|
||||
BITSET_STATS: Wrapper bitset for internal use only.
|
||||
*/
|
||||
enum bitset_type {BITSET_ARRAY, BITSET_LIST, BITSET_TABLE, BITSET_TYPE_NUM,
|
||||
BITSET_STATS};
|
||||
#define BITSET_TYPE_NAMES {"abitset", "lbitset", "ebitset"}
|
||||
|
||||
enum bitset_alloc_type {BITSET_MALLOC, BITSET_OBALLOC};
|
||||
|
||||
/* Non-zero to use inline functions instead of macros. */
|
||||
#define BITSET_INLINE 0
|
||||
|
||||
/* Non-zero to enable bitset statistics gathering. */
|
||||
#define BITSET_STATS 1
|
||||
|
||||
/* Non-zero to enable bitset type checking. */
|
||||
#define BITSET_CHECK 1
|
||||
|
||||
/* Data type used to store a word of bits. */
|
||||
typedef unsigned long bitset_word;
|
||||
#define BITSET_WORD_BITS ((unsigned) CHAR_BIT * sizeof (bitset_word))
|
||||
@@ -99,45 +59,45 @@ typedef unsigned long bitset_windex;
|
||||
|
||||
#define BITSET_LIST_SIZE 1024
|
||||
|
||||
enum bitset_ops {BITSET_OP_ZERO, BITSET_OP_ONES,
|
||||
BITSET_OP_COPY, BITSET_OP_NOT,
|
||||
enum bitset_ops {BITSET_OP_ZERO, BITSET_OP_ONES,
|
||||
BITSET_OP_COPY, BITSET_OP_NOT,
|
||||
BITSET_OP_EMPTY_P, BITSET_OP_EQUAL_P,
|
||||
BITSET_OP_SUBSET_P, BITSET_OP_DISJOINT_P,
|
||||
BITSET_OP_AND, BITSET_OP_OR, BITSET_OP_XOR, BITSET_OP_ANDN,
|
||||
BITSET_OP_AND, BITSET_OP_OR, BITSET_OP_XOR, BITSET_OP_ANDN,
|
||||
BITSET_OP_OR_AND, BITSET_OP_AND_OR, BITSET_OP_ANDN_OR};
|
||||
|
||||
/* Return size in bits of bitset SRC. */
|
||||
#define BITSET_SIZE_(SRC) (SRC)->b.ops->size (SRC)
|
||||
#define BITSET_SIZE_(SRC) (SRC)->b.ops->size (SRC)
|
||||
|
||||
/* Return type of bitset SRC. */
|
||||
#define BITSET_TYPE_(DST) (DST)->b.ops->type
|
||||
#define BITSET_TYPE_(DST) (DST)->b.ops->type
|
||||
|
||||
/* Set bit BITNO in bitset DST. */
|
||||
#define BITSET_SET_(DST, BITNO) (DST)->b.ops->set (DST, BITNO)
|
||||
#define BITSET_SET_(DST, BITNO) (DST)->b.ops->set (DST, BITNO)
|
||||
|
||||
/* Reset bit BITNO in bitset DST. */
|
||||
#define BITSET_RESET_(DST, BITNO) (DST)->b.ops->reset (DST, BITNO)
|
||||
#define BITSET_RESET_(DST, BITNO) (DST)->b.ops->reset (DST, BITNO)
|
||||
|
||||
/* Return non-zero if bit BITNO in bitset SRC is set. */
|
||||
#define BITSET_TEST_(SRC, BITNO) (SRC)->b.ops->test (SRC, BITNO)
|
||||
#define BITSET_TEST_(SRC, BITNO) (SRC)->b.ops->test (SRC, BITNO)
|
||||
|
||||
/* Free bitset SRC. */
|
||||
#define BITSET_FREE_(SRC)\
|
||||
((SRC)->b.ops->free ? (SRC)->b.ops->free (SRC) :(void)0)
|
||||
|
||||
/* Perform operation OP on DST. */
|
||||
#define BITSET_OP1_(DST, OP) (DST)->b.ops->op1 (DST, OP)
|
||||
#define BITSET_OP1_(DST, OP) (DST)->b.ops->op1 (DST, OP)
|
||||
|
||||
/* Perform operation OP on SRC and store in DST. */
|
||||
#define BITSET_OP2_(DST, SRC, OP) (DST)->b.ops->op2 (DST, SRC, OP)
|
||||
#define BITSET_OP2_(DST, SRC, OP) (DST)->b.ops->op2 (DST, SRC, OP)
|
||||
|
||||
/* DST = SRC1 OP SRC2. */
|
||||
#define BITSET_OP3_(DST, SRC1, SRC2, OP) \
|
||||
(DST)->b.ops->op3 (DST, SRC1, SRC2, OP)
|
||||
(DST)->b.ops->op3 (DST, SRC1, SRC2, OP)
|
||||
|
||||
/* DST = (SRC1 OP1 SRC2) OP2 SRC3. */
|
||||
#define BITSET_OP4_(DST, SRC1, SRC2, SRC3, OP) \
|
||||
(DST)->b.ops->op4 (DST, SRC1, SRC2, SRC3, OP)
|
||||
(DST)->b.ops->op4 (DST, SRC1, SRC2, SRC3, OP)
|
||||
|
||||
/* DST = 0. */
|
||||
#define BITSET_ZERO_(DST) BITSET_OP1_ (DST, BITSET_OP_ZERO);
|
||||
@@ -149,63 +109,63 @@ enum bitset_ops {BITSET_OP_ZERO, BITSET_OP_ONES,
|
||||
#define BITSET_EMPTY_P_(SRC) BITSET_OP1_ (SRC, BITSET_OP_EMPTY_P);
|
||||
|
||||
/* Return DST == SRC. */
|
||||
#define BITSET_EQUAL_P_(DST, SRC) BITSET_OP2_ (DST, SRC, BITSET_OP_EQUAL_P)
|
||||
#define BITSET_EQUAL_P_(DST, SRC) BITSET_OP2_ (DST, SRC, BITSET_OP_EQUAL_P)
|
||||
|
||||
/* Return DST == DST | SRC. */
|
||||
#define BITSET_SUBSET_P_(DST, SRC) BITSET_OP2_ (DST, SRC, BITSET_OP_SUBSET_P)
|
||||
#define BITSET_SUBSET_P_(DST, SRC) BITSET_OP2_ (DST, SRC, BITSET_OP_SUBSET_P)
|
||||
|
||||
/* Return DST & SRC == 0. */
|
||||
#define BITSET_DISJOINT_P_(DST, SRC)\
|
||||
BITSET_OP2_ (DST, SRC, BITSET_OP_DISJOINT_P)
|
||||
BITSET_OP2_ (DST, SRC, BITSET_OP_DISJOINT_P)
|
||||
|
||||
/* DST = SRC. */
|
||||
#define BITSET_COPY_(DST, SRC) BITSET_OP2_ (DST, SRC, BITSET_OP_COPY)
|
||||
#define BITSET_COPY_(DST, SRC) BITSET_OP2_ (DST, SRC, BITSET_OP_COPY)
|
||||
|
||||
/* DST = ~SRC. */
|
||||
#define BITSET_NOT_(DST, SRC) BITSET_OP2_ (DST, SRC, BITSET_OP_NOT)
|
||||
#define BITSET_NOT_(DST, SRC) BITSET_OP2_ (DST, SRC, BITSET_OP_NOT)
|
||||
|
||||
/* DST = SRC1 | SRC2. */
|
||||
#define BITSET_OR_(DST, SRC1, SRC2) BITSET_OP3_ (DST, SRC1, SRC2,\
|
||||
BITSET_OP_OR)
|
||||
BITSET_OP_OR)
|
||||
|
||||
/* DST = SRC1 ^ SRC2. */
|
||||
#define BITSET_XOR_(DST, SRC1, SRC2) BITSET_OP3_ (DST, SRC1, SRC2,\
|
||||
BITSET_OP_XOR)
|
||||
BITSET_OP_XOR)
|
||||
|
||||
/* DST = SRC1 & SRC2. */
|
||||
#define BITSET_AND_(DST, SRC1, SRC2) BITSET_OP3_ (DST, SRC1, SRC2, \
|
||||
BITSET_OP_AND)
|
||||
BITSET_OP_AND)
|
||||
|
||||
/* DST = SRC1 & ~SRC2. */
|
||||
#define BITSET_ANDN_(DST, SRC1, SRC2) BITSET_OP3_ (DST, SRC1, SRC2, \
|
||||
BITSET_OP_ANDN)
|
||||
BITSET_OP_ANDN)
|
||||
|
||||
/* DST = (SRC1 & SRC2) | SRC3. Return non-zero if
|
||||
DST != (SRC1 & SRC2) | SRC3. */
|
||||
#define BITSET_AND_OR_(DST, SRC1, SRC2, SRC3)\
|
||||
BITSET_OP4_ (DST, SRC1, SRC2, SRC3, BITSET_OP_AND_OR)
|
||||
BITSET_OP4_ (DST, SRC1, SRC2, SRC3, BITSET_OP_AND_OR)
|
||||
|
||||
/* DST = (SRC1 | SRC2) & SRC3. Return non-zero if
|
||||
DST != (SRC1 | SRC2) & SRC3. */
|
||||
#define BITSET_OR_AND_(DST, SRC1, SRC2, SRC3)\
|
||||
BITSET_OP4_ (DST, SRC1, SRC2, SRC3, BITSET_OP_OR_AND)
|
||||
BITSET_OP4_ (DST, SRC1, SRC2, SRC3, BITSET_OP_OR_AND)
|
||||
|
||||
/* DST = (SRC1 & ~SRC2) | SRC3. Return non-zero if
|
||||
DST != (SRC1 & ~SRC2) | SRC3. */
|
||||
#define BITSET_ANDN_OR_(DST, SRC1, SRC2, SRC3)\
|
||||
BITSET_OP4_ (DST, SRC1, SRC2, SRC3, BITSET_OP_ANDN_OR)
|
||||
BITSET_OP4_ (DST, SRC1, SRC2, SRC3, BITSET_OP_ANDN_OR)
|
||||
|
||||
/* Find list of up to NUM bits set in BSET starting from and including
|
||||
/* Find list of up to NUM bits set in BSET starting from and including
|
||||
*NEXT. Return with actual number of bits found and with *NEXT
|
||||
indicating where search stopped. */
|
||||
#define BITSET_LIST_(BSET, LIST, NUM, NEXT) \
|
||||
(BSET)->b.ops->list (BSET, LIST, NUM, NEXT)
|
||||
(BSET)->b.ops->list (BSET, LIST, NUM, NEXT)
|
||||
|
||||
/* Find reverse list of up to NUM bits set in BSET starting from and
|
||||
including NEXT. Return with actual number of bits found and with
|
||||
*NEXT indicating where search stopped. */
|
||||
#define BITSET_REVERSE_LIST_(BSET, LIST, NUM, NEXT) \
|
||||
(BSET)->b.ops->reverse_list (BSET, LIST, NUM, NEXT)
|
||||
(BSET)->b.ops->reverse_list (BSET, LIST, NUM, NEXT)
|
||||
|
||||
|
||||
struct bbitset_struct
|
||||
@@ -250,7 +210,6 @@ struct bitset_ops_struct
|
||||
|
||||
#define BITSET_COMPATIBLE_(BSET1, BSET2) ((BSET1)->b.ops == (BSET2)->b.ops)
|
||||
|
||||
#if BITSET_CHECK
|
||||
#define BITSET_CHECK2_(DST, SRC) \
|
||||
if (!BITSET_COMPATIBLE_ (DST, SRC)) abort ();
|
||||
|
||||
@@ -261,15 +220,9 @@ if (!BITSET_COMPATIBLE_ (DST, SRC1) \
|
||||
#define BITSET_CHECK4_(DST, SRC1, SRC2, SRC3) \
|
||||
if (!BITSET_COMPATIBLE_ (DST, SRC1) || !BITSET_COMPATIBLE_ (DST, SRC2) \
|
||||
|| !BITSET_COMPATIBLE_ (DST, SRC3)) abort ();
|
||||
#else
|
||||
#define BITSET_CHECK2_(DST, SRC)
|
||||
|
||||
#define BITSET_CHECK3_(DST, SRC1, SRC2)
|
||||
|
||||
#define BITSET_CHECK4_(DST, SRC1, SRC2, SRC3)
|
||||
#endif
|
||||
|
||||
extern int bitset_op4 PARAMS ((bitset, bitset, bitset, bitset,
|
||||
extern int bitset_op4 PARAMS ((bitset, bitset, bitset, bitset,
|
||||
enum bitset_ops op));
|
||||
|
||||
#endif /* _BBITSET_H */
|
||||
|
||||
Reference in New Issue
Block a user