]>
Commit | Line | Data |
---|---|---|
848205e6 MM |
1 | /* Virtual array support. |
2 | Copyright (C) 1998 Free Software Foundation, Inc. | |
3 | Contributed by Cygnus Solutions. | |
4 | ||
5 | This file is part of GNU CC. | |
6 | ||
7 | GNU CC is free software; you can redistribute it and/or modify it | |
8 | under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2, or (at your option) | |
10 | any later version. | |
11 | ||
12 | GNU CC is distributed in the hope that it will be useful, but | |
13 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with GNU CC; see the file COPYING. If not, write to the Free | |
19 | the Free Software Foundation, 59 Temple Place - Suite 330, | |
20 | Boston, MA 02111-1307, USA. */ | |
21 | ||
22 | #ifndef _VARRAY_H_ | |
23 | #define _VARRAY_H_ | |
24 | ||
25 | #ifndef PROTO | |
26 | #include "gansidecl.h" | |
27 | #endif | |
28 | ||
29 | #ifndef HOST_WIDE_INT | |
30 | #include "machmode.h" | |
31 | #endif | |
32 | ||
33 | /* Union of various array types that are used. */ | |
34 | typedef union varray_data_tag { | |
35 | char c[1]; | |
36 | unsigned char uc[1]; | |
37 | short s[1]; | |
38 | unsigned short us[1]; | |
39 | int i[1]; | |
40 | unsigned int u[1]; | |
41 | long l[1]; | |
42 | unsigned long ul[1]; | |
43 | HOST_WIDE_INT hint[1]; | |
44 | unsigned HOST_WIDE_INT uhint[1]; | |
45 | GENERIC_PTR generic[1]; | |
46 | char *cptr[1]; | |
47 | struct rtx_def *rtx[1]; | |
48 | struct rtvec_def *rtvec[1]; | |
49 | union tree_node *tree[1]; | |
50 | struct bitmap_head_def *bitmap[1]; | |
51 | struct sched_info_tag *sched[1]; | |
52 | struct reg_info_def *reg[1]; | |
53 | } varray_data; | |
54 | ||
55 | /* Virtual array of pointers header. */ | |
56 | typedef struct varray_head_tag { | |
57 | size_t num_elements; /* maximum element number allocated */ | |
58 | size_t element_size; /* size of each data element */ | |
59 | const char *name; /* name of the varray for reporting errors */ | |
60 | varray_data data; /* data elements follow, must be last */ | |
61 | } *varray_type; | |
62 | ||
63 | /* Allocate a virtual array with NUM elements, each of which is SIZE bytes | |
64 | long, named NAME. Array elements are zeroed. */ | |
65 | extern varray_type varray_init PROTO ((size_t, size_t, const char *)); | |
66 | ||
67 | #define VARRAY_CHAR_INIT(va, num, name) \ | |
68 | va = varray_init (num, sizeof (char), name) | |
69 | ||
70 | #define VARRAY_UCHAR_INIT(va, num, name) \ | |
71 | va = varray_init (num, sizeof (unsigned char), name) | |
72 | ||
73 | #define VARRAY_SHORT_INIT(va, num, name) \ | |
74 | va = varray_init (num, sizeof (short), name) | |
75 | ||
76 | #define VARRAY_USHORT_INIT(va, num, name) \ | |
77 | va = varray_init (num, sizeof (unsigned short), name) | |
78 | ||
79 | #define VARRAY_INT_INIT(va, num, name) \ | |
80 | va = varray_init (num, sizeof (int), name) | |
81 | ||
82 | #define VARRAY_UINT_INIT(va, num, name) \ | |
83 | va = varray_init (num, sizeof (unsigned int), name) | |
84 | ||
85 | #define VARRAY_LONG_INIT(va, num, name) \ | |
86 | va = varray_init (num, sizeof (long), name) | |
87 | ||
88 | #define VARRAY_ULONG_INIT(va, num, name) \ | |
89 | va = varray_init (num, sizeof (unsigned long), name) | |
90 | ||
91 | #define VARRAY_WIDE_INT_INIT(va, num, name) \ | |
92 | va = varray_init (num, sizeof (HOST_WIDE_INT), name) | |
93 | ||
94 | #define VARRAY_UWIDE_INT_INIT(va, num, name) \ | |
95 | va = varray_init (num, sizeof (unsigned HOST_WIDE_INT), name) | |
96 | ||
97 | #define VARRAY_GENERIC_PTR_INIT(va, num, name) \ | |
98 | va = varray_init (num, sizeof (GENERIC_PTR), name) | |
99 | ||
100 | #define VARRAY_CHAR_PTR_INIT(va, num, name) \ | |
101 | va = varray_init (num, sizeof (char *), name) | |
102 | ||
103 | #define VARRAY_RTX_INIT(va, num, name) \ | |
104 | va = varray_init (num, sizeof (struct rtx_def *), name) | |
105 | ||
106 | #define VARRAY_RTVEC_INIT(va, num, name) \ | |
107 | va = varray_init (num, sizeof (struct rtvec_def), name) | |
108 | ||
109 | #define VARRAY_TREE_INIT(va, num, name) \ | |
110 | va = varray_init (num, sizeof (union tree_node *), name) | |
111 | ||
112 | #define VARRAY_BITMAP_INIT(va, num, name) \ | |
113 | va = varray_init (num, sizeof (struct bitmap_head_def *), name) | |
114 | ||
115 | #define VARRAY_SCHED_INIT(va, num, name) \ | |
116 | va = varray_init (num, sizeof (struct sched_info_tag *), name) | |
117 | ||
118 | #define VARRAY_REG_INIT(va, num, name) \ | |
119 | va = varray_init (num, sizeof (struct reg_info_def *), name) | |
120 | ||
121 | /* Free up memory allocated by the virtual array, but do not free any of the | |
122 | elements involved. */ | |
123 | #define VARRAY_FREE(vp) ((vp) && (free (vp), (vp = (varray_type)0))) | |
124 | ||
125 | /* Grow/shrink the virtual array VA to N elements. */ | |
126 | extern varray_type varray_grow PROTO((varray_type, size_t)); | |
127 | ||
128 | #define VARRAY_GROW(VA, N) ((VA) = varray_grow (VA, N)) | |
129 | ||
130 | /* Check for VARRAY_xxx macros being in bound, return N for use as an | |
131 | index. */ | |
132 | #ifdef ENABLE_CHECKING | |
133 | #define VARRAY_CHECK(VA, N) \ | |
134 | ((((size_t)(N) < (VA)->num_elements) \ | |
135 | ? 0 \ | |
136 | : (fatal ("Virtual array %s element %ld out of bounds, at %s:%d", \ | |
137 | (VA)->name, (long)(N), __FILE__, __LINE__), 0)), \ | |
138 | (N)) | |
139 | #else | |
140 | #define VARRAY_CHECK(VA, N) (N) | |
141 | #endif | |
142 | ||
143 | #define VARRAY_CHAR(VA, N) ((VA)->data.c[ VARRAY_CHECK (VA, N) ]) | |
144 | #define VARRAY_UCHAR(VA, N) ((VA)->data.uc[ VARRAY_CHECK (VA, N) ]) | |
145 | #define VARRAY_SHORT(VA, N) ((VA)->data.s[ VARRAY_CHECK (VA, N) ]) | |
146 | #define VARRAY_USHORT(VA, N) ((VA)->data.us[ VARRAY_CHECK (VA, N) ]) | |
147 | #define VARRAY_INT(VA, N) ((VA)->data.i[ VARRAY_CHECK (VA, N) ]) | |
148 | #define VARRAY_UINT(VA, N) ((VA)->data.u[ VARRAY_CHECK (VA, N) ]) | |
149 | #define VARRAY_LONG(VA, N) ((VA)->data.l[ VARRAY_CHECK (VA, N) ]) | |
150 | #define VARRAY_ULONG(VA, N) ((VA)->data.ul[ VARRAY_CHECK (VA, N) ]) | |
151 | #define VARRAY_WIDE_INT(VA, N) ((VA)->data.hint[ VARRAY_CHECK (VA, N) ]) | |
152 | #define VARRAY_UWIDE_INT(VA, N) ((VA)->data.uhint[ VARRAY_CHECK (VA, N) ]) | |
153 | #define VARRAY_GENERIC_PTR(VA,N) ((VA)->data.generic[ VARRAY_CHECK (VA, N) ]) | |
154 | #define VARRAY_CHAR_PTR(VA,N) ((VA)->data.cptr[ VARRAY_CHECK (VA, N) ]) | |
155 | #define VARRAY_RTX(VA, N) ((VA)->data.rtx[ VARRAY_CHECK (VA, N) ]) | |
156 | #define VARRAY_RTVEC(VA, N) ((VA)->data.rtvec[ VARRAY_CHECK (VA, N) ]) | |
157 | #define VARRAY_TREE(VA, N) ((VA)->data.tree[ VARRAY_CHECK (VA, N) ]) | |
158 | #define VARRAY_BITMAP(VA, N) ((VA)->data.bitmap[ VARRAY_CHECK (VA, N) ]) | |
159 | #define VARRAY_SCHED(VA, N) ((VA)->data.sched[ VARRAY_CHECK (VA, N) ]) | |
160 | #define VARRAY_REG(VA, N) ((VA)->data.reg[ VARRAY_CHECK (VA, N) ]) | |
161 | ||
162 | #endif /* _VARRAY_H_ */ |