]> git.saurik.com Git - bison.git/blob - lib/bitsetv.c
* src/print.c: Convert to use bitset.h, not hand coded iterations
[bison.git] / lib / bitsetv.c
1 /* Bitset vectors.
2 Copyright (C) 2001 Free Software Foundation, Inc.
3
4 This file is part of GCC.
5
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2, or (at your option) any later
9 version.
10
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING. If not, write to the Free
18 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
19 02111-1307, USA. */
20
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
24
25 #include <stdlib.h>
26 #include "bitsetv.h"
27
28
29 /* Create a vector of N_VECS bitsets, each of N_BITS, and of
30 type TYPE. */
31 bitset *
32 bitsetv_alloc (n_vecs, n_bits, type)
33 unsigned int n_vecs;
34 unsigned int n_bits;
35 enum bitset_type type;
36 {
37 unsigned int vector_bytes;
38 unsigned int bytes;
39 bitset *bsetv;
40 unsigned int i;
41
42 /* Determine number of bytes for each set. */
43 bytes = bitset_bytes (type, n_bits);
44
45 /* Allocate vector table at head of bitset array. */
46 vector_bytes = n_vecs * sizeof (bitset);
47 bsetv = (bitset *) xmalloc (vector_bytes + bytes * n_vecs);
48
49 for (i = 0; i < n_vecs; i++)
50 {
51 bsetv[i] = (bitset)((char *)bsetv + vector_bytes + i * bytes);
52
53 bitset_init (bsetv[i], n_bits, type);
54 }
55 return bsetv;
56 }
57
58
59 /* Create a vector of N_VECS bitsets, each of N_BITS, and with
60 attribute hints specified by ATTR. */
61 bitset *
62 bitsetv_create (n_vecs, n_bits, attr)
63 unsigned int n_vecs;
64 unsigned int n_bits;
65 unsigned int attr;
66 {
67 enum bitset_type type;
68
69 type = bitset_type_choose (n_bits, attr);
70 return bitsetv_alloc (n_vecs, n_bits, type);
71 }
72
73
74 /* Free bitset vector BSETV. */
75 void
76 bitsetv_free (bsetv)
77 bitset *bsetv;
78 {
79 free (bsetv);
80 }
81
82
83 /* Zero a vector of N_VECS bitsets. */
84 void
85 bitsetv_zero (bsetv, n_vecs)
86 struct bitset_struct **bsetv;
87 unsigned int n_vecs;
88 {
89 unsigned int i;
90
91 for (i = 0; i < n_vecs; i++)
92 bitset_zero (bsetv[i]);
93 }
94
95
96 /* Set a vector of N_VECS bitsets to ones. */
97 void
98 bitsetv_ones (bsetv, n_vecs)
99 bitset *bsetv;
100 unsigned int n_vecs;
101 {
102 unsigned int i;
103
104 for (i = 0; i < n_vecs; i++)
105 bitset_ones (bsetv[i]);
106 }
107
108
109 /* Dump the contents of a bitset vector BSETV with N_VECS elements to
110 FILE. */
111 void
112 bitsetv_dump (file, title, subtitle, bsetv, n_vecs)
113 FILE *file;
114 const char *title, *subtitle;
115 bitset *bsetv;
116 unsigned int n_vecs;
117 {
118 unsigned int i;
119
120 fprintf (file, "%s\n", title);
121 for (i = 0; i < n_vecs; i++)
122 {
123 fprintf (file, "%s %d\n", subtitle, i);
124 bitset_dump (file, bsetv[i]);
125 }
126
127 fprintf (file, "\n");
128 }