]> git.saurik.com Git - bison.git/blame - lib/bitsetv.c
Fix dates in copyright notice.
[bison.git] / lib / bitsetv.c
CommitLineData
7086e707
AD
1/* Bitset vectors.
2 Copyright (C) 2001 Free Software Foundation, Inc.
3
4This file is part of GCC.
5
6GCC is free software; you can redistribute it and/or modify it under
7the terms of the GNU General Public License as published by the Free
8Software Foundation; either version 2, or (at your option) any later
9version.
10
11GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12WARRANTY; without even the implied warranty of MERCHANTABILITY or
13FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14for more details.
15
16You should have received a copy of the GNU General Public License
17along with GCC; see the file COPYING. If not, write to the Free
18Software Foundation, 59 Temple Place - Suite 330, Boston, MA
1902111-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. */
31bitset *
32bitsetv_alloc (n_vecs, n_bits, type)
ef017502
AD
33 unsigned int n_vecs;
34 unsigned int n_bits;
35 enum bitset_type type;
7086e707 36{
ef017502
AD
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 + 1) * sizeof (bitset);
47 bsetv = (bitset *) xcalloc (1, vector_bytes + bytes * n_vecs);
48
49 for (i = 0; i < n_vecs; i++)
7086e707 50 {
ef017502 51 bsetv[i] = (bitset) ((char *) bsetv + vector_bytes + i * bytes);
613f5e1a 52
7086e707
AD
53 bitset_init (bsetv[i], n_bits, type);
54 }
ef017502
AD
55
56 /* Null terminate table. */
57 bsetv[i] = 0;
58 return bsetv;
7086e707
AD
59}
60
61
62/* Create a vector of N_VECS bitsets, each of N_BITS, and with
63 attribute hints specified by ATTR. */
64bitset *
65bitsetv_create (n_vecs, n_bits, attr)
ef017502
AD
66 unsigned int n_vecs;
67 unsigned int n_bits;
68 unsigned int attr;
7086e707 69{
ef017502
AD
70 enum bitset_type type;
71
72 type = bitset_type_choose (n_bits, attr);
73 return bitsetv_alloc (n_vecs, n_bits, type);
7086e707
AD
74}
75
76
77/* Free bitset vector BSETV. */
78void
79bitsetv_free (bsetv)
ef017502 80 bitset *bsetv;
7086e707 81{
ef017502
AD
82 unsigned int i;
83
84 for (i = 0; bsetv[i]; i++)
85 BITSET_FREE_ (bsetv[i]);
86 free (bsetv);
7086e707
AD
87}
88
89
ef017502 90/* Zero a vector of bitsets. */
7086e707 91void
ef017502 92bitsetv_zero (bsetv)
7086e707 93 struct bitset_struct **bsetv;
7086e707
AD
94{
95 unsigned int i;
ef017502
AD
96
97 for (i = 0; bsetv[i]; i++)
98 bitset_zero (bsetv[i]);
7086e707
AD
99}
100
101
ef017502 102/* Set a vector of bitsets to ones. */
7086e707 103void
ef017502 104bitsetv_ones (bsetv)
7086e707 105 bitset *bsetv;
7086e707
AD
106{
107 unsigned int i;
ef017502
AD
108
109 for (i = 0; bsetv[i]; i++)
7086e707
AD
110 bitset_ones (bsetv[i]);
111}
112
113
345cea78
AD
114/* Given a vector BSETV of N bitsets of size N, modify its contents to
115 be the transitive closure of what was given. */
116void
117bitsetv_transitive_closure (bsetv)
118 bitset *bsetv;
119{
120 unsigned int i;
121 unsigned int j;
122
123 for (i = 0; bsetv[i]; i++)
124 for (j = 0; bsetv[j]; j++)
125 if (bitset_test (bsetv[j], i))
126 bitset_or (bsetv[j], bsetv[j], bsetv[i]);
127}
128
129
130/* Given a vector BSETV of N bitsets of size N, modify its contents to
131 be the reflexive transitive closure of what was given. This is
132 the same as transitive closure but with all bits on the diagonal
133 of the bit matrix set. */
134void
135bitsetv_reflexive_transitive_closure (bitsetv bsetv)
136{
137 int i;
138
139 bitsetv_transitive_closure (bsetv);
140 for (i = 0; bsetv[i]; i++)
141 bitset_set (bsetv[i], i);
142}
143
144
7086e707
AD
145/* Dump the contents of a bitset vector BSETV with N_VECS elements to
146 FILE. */
147void
ef017502 148bitsetv_dump (file, title, subtitle, bsetv)
7086e707
AD
149 FILE *file;
150 const char *title, *subtitle;
151 bitset *bsetv;
7086e707
AD
152{
153 unsigned int i;
ef017502 154
7086e707 155 fprintf (file, "%s\n", title);
ef017502 156 for (i = 0; bsetv[i]; i++)
7086e707
AD
157 {
158 fprintf (file, "%s %d\n", subtitle, i);
159 bitset_dump (file, bsetv[i]);
160 }
ef017502 161
7086e707
AD
162 fprintf (file, "\n");
163}
ef017502
AD
164
165
166void
167debug_bitsetv (bsetv)
168 bitset *bsetv;
169{
170 unsigned int i;
171
172 for (i = 0; bsetv[i]; i++)
173 {
174 fprintf (stderr, "%d: ", i);
175 debug_bitset (bsetv[i]);
176 }
177
178 fprintf (stderr, "\n");
179}