1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-05 09:14:03 +00:00
freebsd/contrib/gcc/varray.h

325 lines
12 KiB
C
Raw Normal View History

1999-08-26 09:30:50 +00:00
/* Virtual array support.
2004-07-28 03:11:36 +00:00
Copyright (C) 1998, 1999, 2000, 2002, 2003, 2004
Free Software Foundation, Inc.
1999-08-26 09:30:50 +00:00
Contributed by Cygnus Solutions.
This file is part of GCC.
1999-08-26 09:30:50 +00:00
GCC is free software; you can redistribute it and/or modify it
1999-08-26 09:30:50 +00:00
under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GCC is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
License for more details.
1999-08-26 09:30:50 +00:00
You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING. If not, write to the Free
2007-05-19 01:19:51 +00:00
the Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA. */
1999-08-26 09:30:50 +00:00
#ifndef GCC_VARRAY_H
#define GCC_VARRAY_H
1999-08-26 09:30:50 +00:00
#ifndef HOST_WIDE_INT
#include "machmode.h"
#endif
#ifndef GCC_SYSTEM_H
1999-08-26 09:30:50 +00:00
#include "system.h"
2004-07-28 03:11:36 +00:00
#include "coretypes.h"
#include "tm.h"
1999-08-26 09:30:50 +00:00
#endif
2004-07-28 03:11:36 +00:00
/* Enum indicating what the varray contains.
If this is changed, `element' in varray.c needs to be updated. */
2003-07-11 03:40:53 +00:00
enum varray_data_enum {
VARRAY_DATA_C,
VARRAY_DATA_UC,
VARRAY_DATA_S,
VARRAY_DATA_US,
VARRAY_DATA_I,
VARRAY_DATA_U,
VARRAY_DATA_L,
VARRAY_DATA_UL,
VARRAY_DATA_HINT,
VARRAY_DATA_UHINT,
VARRAY_DATA_GENERIC,
2007-05-19 01:19:51 +00:00
VARRAY_DATA_GENERIC_NOGC,
2003-07-11 03:40:53 +00:00
VARRAY_DATA_CPTR,
VARRAY_DATA_RTX,
VARRAY_DATA_RTVEC,
VARRAY_DATA_TREE,
VARRAY_DATA_BITMAP,
VARRAY_DATA_REG,
VARRAY_DATA_BB,
VARRAY_DATA_TE,
2007-05-19 01:19:51 +00:00
VARRAY_DATA_EDGE,
VARRAY_DATA_TREE_PTR,
2003-07-11 03:40:53 +00:00
NUM_VARRAY_DATA
};
1999-08-26 09:30:50 +00:00
/* Union of various array types that are used. */
2003-07-11 03:40:53 +00:00
typedef union varray_data_tag GTY (()) {
char GTY ((length ("%0.num_elements"),
2007-05-19 01:19:51 +00:00
tag ("VARRAY_DATA_C"))) vdt_c[1];
2003-07-11 03:40:53 +00:00
unsigned char GTY ((length ("%0.num_elements"),
2007-05-19 01:19:51 +00:00
tag ("VARRAY_DATA_UC"))) vdt_uc[1];
2003-07-11 03:40:53 +00:00
short GTY ((length ("%0.num_elements"),
2007-05-19 01:19:51 +00:00
tag ("VARRAY_DATA_S"))) vdt_s[1];
2003-07-11 03:40:53 +00:00
unsigned short GTY ((length ("%0.num_elements"),
2007-05-19 01:19:51 +00:00
tag ("VARRAY_DATA_US"))) vdt_us[1];
2003-07-11 03:40:53 +00:00
int GTY ((length ("%0.num_elements"),
2007-05-19 01:19:51 +00:00
tag ("VARRAY_DATA_I"))) vdt_i[1];
2003-07-11 03:40:53 +00:00
unsigned int GTY ((length ("%0.num_elements"),
2007-05-19 01:19:51 +00:00
tag ("VARRAY_DATA_U"))) vdt_u[1];
2003-07-11 03:40:53 +00:00
long GTY ((length ("%0.num_elements"),
2007-05-19 01:19:51 +00:00
tag ("VARRAY_DATA_L"))) vdt_l[1];
2003-07-11 03:40:53 +00:00
unsigned long GTY ((length ("%0.num_elements"),
2007-05-19 01:19:51 +00:00
tag ("VARRAY_DATA_UL"))) vdt_ul[1];
2003-07-11 03:40:53 +00:00
HOST_WIDE_INT GTY ((length ("%0.num_elements"),
2007-05-19 01:19:51 +00:00
tag ("VARRAY_DATA_HINT"))) vdt_hint[1];
2003-07-11 03:40:53 +00:00
unsigned HOST_WIDE_INT GTY ((length ("%0.num_elements"),
2007-05-19 01:19:51 +00:00
tag ("VARRAY_DATA_UHINT"))) vdt_uhint[1];
PTR GTY ((length ("%0.num_elements"), use_param,
tag ("VARRAY_DATA_GENERIC"))) vdt_generic[1];
PTR GTY ((length ("%0.num_elements"), skip (""),
tag ("VARRAY_DATA_GENERIC_NOGC"))) vdt_generic_nogc[1];
2003-07-11 03:40:53 +00:00
char *GTY ((length ("%0.num_elements"),
2007-05-19 01:19:51 +00:00
tag ("VARRAY_DATA_CPTR"))) vdt_cptr[1];
2004-07-28 03:11:36 +00:00
rtx GTY ((length ("%0.num_elements"),
2007-05-19 01:19:51 +00:00
tag ("VARRAY_DATA_RTX"))) vdt_rtx[1];
2004-07-28 03:11:36 +00:00
rtvec GTY ((length ("%0.num_elements"),
2007-05-19 01:19:51 +00:00
tag ("VARRAY_DATA_RTVEC"))) vdt_rtvec[1];
2004-07-28 03:11:36 +00:00
tree GTY ((length ("%0.num_elements"),
2007-05-19 01:19:51 +00:00
tag ("VARRAY_DATA_TREE"))) vdt_tree[1];
2003-07-11 03:40:53 +00:00
struct bitmap_head_def *GTY ((length ("%0.num_elements"),
2007-05-19 01:19:51 +00:00
tag ("VARRAY_DATA_BITMAP"))) vdt_bitmap[1];
struct reg_info_def *GTY ((length ("%0.num_elements"), skip,
tag ("VARRAY_DATA_REG"))) vdt_reg[1];
struct basic_block_def *GTY ((length ("%0.num_elements"), skip,
tag ("VARRAY_DATA_BB"))) vdt_bb[1];
2003-07-11 03:40:53 +00:00
struct elt_list *GTY ((length ("%0.num_elements"),
2007-05-19 01:19:51 +00:00
tag ("VARRAY_DATA_TE"))) vdt_te[1];
struct edge_def *GTY ((length ("%0.num_elements"),
tag ("VARRAY_DATA_EDGE"))) vdt_e[1];
tree *GTY ((length ("%0.num_elements"), skip (""),
tag ("VARRAY_DATA_TREE_PTR"))) vdt_tp[1];
1999-08-26 09:30:50 +00:00
} varray_data;
/* Virtual array of pointers header. */
2003-07-11 03:40:53 +00:00
struct varray_head_tag GTY(()) {
size_t num_elements; /* Maximum element number allocated. */
size_t elements_used; /* The number of elements used, if
using VARRAY_PUSH/VARRAY_POP. */
2003-07-11 03:40:53 +00:00
enum varray_data_enum type; /* The kind of elements in the varray. */
1999-08-26 09:30:50 +00:00
const char *name; /* name of the varray for reporting errors */
2004-07-28 03:11:36 +00:00
varray_data GTY ((desc ("%0.type"))) data; /* The data elements follow,
2003-07-11 03:40:53 +00:00
must be last. */
};
typedef struct varray_head_tag *varray_type;
1999-08-26 09:30:50 +00:00
/* Allocate a virtual array with NUM elements, each of which is SIZE bytes
long, named NAME. Array elements are zeroed. */
2004-07-28 03:11:36 +00:00
extern varray_type varray_init (size_t, enum varray_data_enum, const char *);
1999-08-26 09:30:50 +00:00
#define VARRAY_CHAR_INIT(va, num, name) \
2003-07-11 03:40:53 +00:00
va = varray_init (num, VARRAY_DATA_C, name)
1999-08-26 09:30:50 +00:00
#define VARRAY_UCHAR_INIT(va, num, name) \
2003-07-11 03:40:53 +00:00
va = varray_init (num, VARRAY_DATA_UC, name)
1999-08-26 09:30:50 +00:00
#define VARRAY_SHORT_INIT(va, num, name) \
2003-07-11 03:40:53 +00:00
va = varray_init (num, VARRAY_DATA_S, name)
1999-08-26 09:30:50 +00:00
#define VARRAY_USHORT_INIT(va, num, name) \
2003-07-11 03:40:53 +00:00
va = varray_init (num, VARRAY_DATA_US, name)
1999-08-26 09:30:50 +00:00
#define VARRAY_INT_INIT(va, num, name) \
2003-07-11 03:40:53 +00:00
va = varray_init (num, VARRAY_DATA_I, name)
1999-08-26 09:30:50 +00:00
#define VARRAY_UINT_INIT(va, num, name) \
2003-07-11 03:40:53 +00:00
va = varray_init (num, VARRAY_DATA_U, name)
1999-08-26 09:30:50 +00:00
#define VARRAY_LONG_INIT(va, num, name) \
2003-07-11 03:40:53 +00:00
va = varray_init (num, VARRAY_DATA_L, name)
1999-08-26 09:30:50 +00:00
#define VARRAY_ULONG_INIT(va, num, name) \
2003-07-11 03:40:53 +00:00
va = varray_init (num, VARRAY_DATA_UL, name)
1999-08-26 09:30:50 +00:00
#define VARRAY_WIDE_INT_INIT(va, num, name) \
2003-07-11 03:40:53 +00:00
va = varray_init (num, VARRAY_DATA_HINT, name)
1999-08-26 09:30:50 +00:00
#define VARRAY_UWIDE_INT_INIT(va, num, name) \
2003-07-11 03:40:53 +00:00
va = varray_init (num, VARRAY_DATA_UHINT, name)
1999-08-26 09:30:50 +00:00
#define VARRAY_GENERIC_PTR_INIT(va, num, name) \
2003-07-11 03:40:53 +00:00
va = varray_init (num, VARRAY_DATA_GENERIC, name)
1999-08-26 09:30:50 +00:00
2007-05-19 01:19:51 +00:00
#define VARRAY_GENERIC_PTR_NOGC_INIT(va, num, name) \
va = varray_init (num, VARRAY_DATA_GENERIC_NOGC, name)
1999-08-26 09:30:50 +00:00
#define VARRAY_CHAR_PTR_INIT(va, num, name) \
2003-07-11 03:40:53 +00:00
va = varray_init (num, VARRAY_DATA_CPTR, name)
1999-08-26 09:30:50 +00:00
#define VARRAY_RTX_INIT(va, num, name) \
2003-07-11 03:40:53 +00:00
va = varray_init (num, VARRAY_DATA_RTX, name)
1999-08-26 09:30:50 +00:00
#define VARRAY_RTVEC_INIT(va, num, name) \
2003-07-11 03:40:53 +00:00
va = varray_init (num, VARRAY_DATA_RTVEC, name)
1999-08-26 09:30:50 +00:00
#define VARRAY_TREE_INIT(va, num, name) \
2003-07-11 03:40:53 +00:00
va = varray_init (num, VARRAY_DATA_TREE, name)
1999-08-26 09:30:50 +00:00
#define VARRAY_BITMAP_INIT(va, num, name) \
2003-07-11 03:40:53 +00:00
va = varray_init (num, VARRAY_DATA_BITMAP, name)
1999-08-26 09:30:50 +00:00
#define VARRAY_REG_INIT(va, num, name) \
2003-07-11 03:40:53 +00:00
va = varray_init (num, VARRAY_DATA_REG, name)
1999-08-26 09:30:50 +00:00
#define VARRAY_BB_INIT(va, num, name) \
2003-07-11 03:40:53 +00:00
va = varray_init (num, VARRAY_DATA_BB, name)
#define VARRAY_ELT_LIST_INIT(va, num, name) \
2003-07-11 03:40:53 +00:00
va = varray_init (num, VARRAY_DATA_TE, name)
2007-05-19 01:19:51 +00:00
#define VARRAY_EDGE_INIT(va, num, name) \
va = varray_init (num, VARRAY_DATA_EDGE, name)
#define VARRAY_TREE_PTR_INIT(va, num, name) \
va = varray_init (num, VARRAY_DATA_TREE_PTR, name)
1999-08-26 09:30:50 +00:00
/* Free up memory allocated by the virtual array, but do not free any of the
elements involved. */
#define VARRAY_FREE(vp) \
do { if (vp) { free (vp); vp = (varray_type) 0; } } while (0)
1999-08-26 09:30:50 +00:00
/* Grow/shrink the virtual array VA to N elements. */
2004-07-28 03:11:36 +00:00
extern varray_type varray_grow (varray_type, size_t);
1999-08-26 09:30:50 +00:00
#define VARRAY_GROW(VA, N) ((VA) = varray_grow (VA, N))
#define VARRAY_SIZE(VA) ((VA)->num_elements)
#define VARRAY_ACTIVE_SIZE(VA) ((VA)->elements_used)
#define VARRAY_POP_ALL(VA) ((VA)->elements_used = 0)
2003-07-11 03:40:53 +00:00
#define VARRAY_CLEAR(VA) varray_clear(VA)
2004-07-28 03:11:36 +00:00
extern void varray_clear (varray_type);
extern void dump_varray_statistics (void);
2003-07-11 03:40:53 +00:00
/* Check for VARRAY_xxx macros being in bound. */
#if defined ENABLE_CHECKING && (GCC_VERSION >= 2007)
2004-07-28 03:11:36 +00:00
extern void varray_check_failed (varray_type, size_t, const char *, int,
const char *) ATTRIBUTE_NORETURN;
extern void varray_underflow (varray_type, const char *, int, const char *)
ATTRIBUTE_NORETURN;
#define VARRAY_CHECK(VA, N, T) __extension__ \
2003-07-11 03:40:53 +00:00
(*({ varray_type const _va = (VA); \
2004-07-28 03:11:36 +00:00
const size_t _n = (N); \
if (_n >= _va->num_elements) \
varray_check_failed (_va, _n, __FILE__, __LINE__, __FUNCTION__); \
&_va->data.T[_n]; }))
2004-07-28 03:11:36 +00:00
#define VARRAY_POP(VA) do { \
varray_type const _va = (VA); \
if (_va->elements_used == 0) \
varray_underflow (_va, __FILE__, __LINE__, __FUNCTION__); \
else \
_va->elements_used--; \
} while (0)
1999-08-26 09:30:50 +00:00
#else
#define VARRAY_CHECK(VA, N, T) ((VA)->data.T[N])
2004-07-28 03:11:36 +00:00
/* Pop the top element of VA. */
#define VARRAY_POP(VA) do { ((VA)->elements_used--); } while (0)
1999-08-26 09:30:50 +00:00
#endif
/* Push X onto VA. T is the name of the field in varray_data
corresponding to the type of X. */
2003-07-11 03:40:53 +00:00
#define VARRAY_PUSH(VA, T, X) \
do \
{ \
if ((VA)->elements_used >= (VA)->num_elements) \
VARRAY_GROW ((VA), 2 * (VA)->num_elements); \
(VA)->data.T[(VA)->elements_used++] = (X); \
} \
while (0)
2007-05-19 01:19:51 +00:00
#define VARRAY_CHAR(VA, N) VARRAY_CHECK (VA, N, vdt_c)
#define VARRAY_UCHAR(VA, N) VARRAY_CHECK (VA, N, vdt_uc)
#define VARRAY_SHORT(VA, N) VARRAY_CHECK (VA, N, vdt_s)
#define VARRAY_USHORT(VA, N) VARRAY_CHECK (VA, N, vdt_us)
#define VARRAY_INT(VA, N) VARRAY_CHECK (VA, N, vdt_i)
#define VARRAY_UINT(VA, N) VARRAY_CHECK (VA, N, vdt_u)
#define VARRAY_LONG(VA, N) VARRAY_CHECK (VA, N, vdt_l)
#define VARRAY_ULONG(VA, N) VARRAY_CHECK (VA, N, vdt_ul)
#define VARRAY_WIDE_INT(VA, N) VARRAY_CHECK (VA, N, vdt_hint)
#define VARRAY_UWIDE_INT(VA, N) VARRAY_CHECK (VA, N, vdt_uhint)
#define VARRAY_GENERIC_PTR(VA,N) VARRAY_CHECK (VA, N, vdt_generic)
#define VARRAY_GENERIC_PTR_NOGC(VA,N) VARRAY_CHECK (VA, N, vdt_generic_nogc)
#define VARRAY_CHAR_PTR(VA,N) VARRAY_CHECK (VA, N, vdt_cptr)
#define VARRAY_RTX(VA, N) VARRAY_CHECK (VA, N, vdt_rtx)
#define VARRAY_RTVEC(VA, N) VARRAY_CHECK (VA, N, vdt_rtvec)
#define VARRAY_TREE(VA, N) VARRAY_CHECK (VA, N, vdt_tree)
#define VARRAY_BITMAP(VA, N) VARRAY_CHECK (VA, N, vdt_bitmap)
#define VARRAY_REG(VA, N) VARRAY_CHECK (VA, N, vdt_reg)
#define VARRAY_BB(VA, N) VARRAY_CHECK (VA, N, vdt_bb)
#define VARRAY_ELT_LIST(VA, N) VARRAY_CHECK (VA, N, vdt_te)
#define VARRAY_EDGE(VA, N) VARRAY_CHECK (VA, N, vdt_e)
#define VARRAY_TREE_PTR(VA, N) VARRAY_CHECK (VA, N, vdt_tp)
/* Push a new element on the end of VA, extending it if necessary. */
2007-05-19 01:19:51 +00:00
#define VARRAY_PUSH_CHAR(VA, X) VARRAY_PUSH (VA, vdt_c, X)
#define VARRAY_PUSH_UCHAR(VA, X) VARRAY_PUSH (VA, vdt_uc, X)
#define VARRAY_PUSH_SHORT(VA, X) VARRAY_PUSH (VA, vdt_s, X)
#define VARRAY_PUSH_USHORT(VA, X) VARRAY_PUSH (VA, vdt_us, X)
#define VARRAY_PUSH_INT(VA, X) VARRAY_PUSH (VA, vdt_i, X)
#define VARRAY_PUSH_UINT(VA, X) VARRAY_PUSH (VA, vdt_u, X)
#define VARRAY_PUSH_LONG(VA, X) VARRAY_PUSH (VA, vdt_l, X)
#define VARRAY_PUSH_ULONG(VA, X) VARRAY_PUSH (VA, vdt_ul, X)
#define VARRAY_PUSH_WIDE_INT(VA, X) VARRAY_PUSH (VA, vdt_hint, X)
#define VARRAY_PUSH_UWIDE_INT(VA, X) VARRAY_PUSH (VA, vdt_uhint, X)
#define VARRAY_PUSH_GENERIC_PTR(VA, X) VARRAY_PUSH (VA, vdt_generic, X)
#define VARRAY_PUSH_GENERIC_PTR_NOGC(VA, X) VARRAY_PUSH (VA, vdt_generic_nogc, X)
#define VARRAY_PUSH_CHAR_PTR(VA, X) VARRAY_PUSH (VA, vdt_cptr, X)
#define VARRAY_PUSH_RTX(VA, X) VARRAY_PUSH (VA, vdt_rtx, X)
#define VARRAY_PUSH_RTVEC(VA, X) VARRAY_PUSH (VA, vdt_rtvec, X)
#define VARRAY_PUSH_TREE(VA, X) VARRAY_PUSH (VA, vdt_tree, X)
#define VARRAY_PUSH_BITMAP(VA, X) VARRAY_PUSH (VA, vdt_bitmap, X)
#define VARRAY_PUSH_REG(VA, X) VARRAY_PUSH (VA, vdt_reg, X)
#define VARRAY_PUSH_BB(VA, X) VARRAY_PUSH (VA, vdt_bb, X)
#define VARRAY_PUSH_EDGE(VA, X) VARRAY_PUSH (VA, vdt_e, X)
#define VARRAY_PUSH_TREE_PTR(VA, X) VARRAY_PUSH (VA, vdt_tp, X)
/* Return the last element of VA. */
2004-07-28 03:11:36 +00:00
#define VARRAY_TOP(VA, T) VARRAY_CHECK(VA, (VA)->elements_used - 1, T)
2007-05-19 01:19:51 +00:00
#define VARRAY_TOP_CHAR(VA) VARRAY_TOP (VA, vdt_c)
#define VARRAY_TOP_UCHAR(VA) VARRAY_TOP (VA, vdt_uc)
#define VARRAY_TOP_SHORT(VA) VARRAY_TOP (VA, vdt_s)
#define VARRAY_TOP_USHORT(VA) VARRAY_TOP (VA, vdt_us)
#define VARRAY_TOP_INT(VA) VARRAY_TOP (VA, vdt_i)
#define VARRAY_TOP_UINT(VA) VARRAY_TOP (VA, vdt_u)
#define VARRAY_TOP_LONG(VA) VARRAY_TOP (VA, vdt_l)
#define VARRAY_TOP_ULONG(VA) VARRAY_TOP (VA, vdt_ul)
#define VARRAY_TOP_WIDE_INT(VA) VARRAY_TOP (VA, vdt_hint)
#define VARRAY_TOP_UWIDE_INT(VA) VARRAY_TOP (VA, vdt_uhint)
#define VARRAY_TOP_GENERIC_PTR(VA) VARRAY_TOP (VA, vdt_generic)
#define VARRAY_TOP_GENERIC_PTR_NOGC(VA) VARRAY_TOP (VA, vdt_generic_nogc)
#define VARRAY_TOP_CHAR_PTR(VA) VARRAY_TOP (VA, vdt_cptr)
#define VARRAY_TOP_RTX(VA) VARRAY_TOP (VA, vdt_rtx)
#define VARRAY_TOP_RTVEC(VA) VARRAY_TOP (VA, vdt_rtvec)
#define VARRAY_TOP_TREE(VA) VARRAY_TOP (VA, vdt_tree)
#define VARRAY_TOP_BITMAP(VA) VARRAY_TOP (VA, vdt_bitmap)
#define VARRAY_TOP_REG(VA) VARRAY_TOP (VA, vdt_reg)
#define VARRAY_TOP_BB(VA) VARRAY_TOP (VA, vdt_bb)
#define VARRAY_TOP_EDGE(VA) VARRAY_TOP (VA, vdt_e)
#define VARRAY_TOP_TREE_PTR(VA) VARRAY_TOP (VA, vdt_tp)
#endif /* ! GCC_VARRAY_H */