aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gcc/ChangeLog10
-rw-r--r--gcc/rtl.h2
-rw-r--r--gcc/toplev.c40
-rw-r--r--gcc/tree.h2
-rw-r--r--gcc/varray.c70
-rw-r--r--gcc/varray.h162
6 files changed, 281 insertions, 5 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 2724be4..9f0bfba 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,13 @@
+Thu Jul 2 14:16:11 1998 Michael Meissner <meissner@cygnus.com>
+
+ * varray.{c,h}: New files to provide virtual array support.
+ * Makefile.in (OBJS): Add varray.o.
+ (varray.o): Add new file.
+
+ * toplev.c (x{m,re}alloc): If size is 0, allocate 1 byte.
+ (xcalloc): Provide frontend for calloc.
+ * {tree,rtl}.h (xcalloc): Add declaration.
+
Thu Jul 2 10:11:47 1998 Robert Lipe <robertl@dgii.com>
* install.texi (sco3.2v5): Document new --with-gnu-as flag.
diff --git a/gcc/rtl.h b/gcc/rtl.h
index 5f50839..7515dcf 100644
--- a/gcc/rtl.h
+++ b/gcc/rtl.h
@@ -830,9 +830,11 @@ extern rtx read_rtx PROTO((FILE *));
cast their pointers to char *, and all of the xrealloc's don't use
void * yet. */
extern char *xmalloc PROTO((size_t));
+extern char *xcalloc PROTO((size_t, size_t));
extern char *xrealloc PROTO((void *, size_t));
#else
extern char *xmalloc ();
+extern char *xcalloc ();
extern char *xrealloc ();
#endif
diff --git a/gcc/toplev.c b/gcc/toplev.c
index 353d418..6bc7663 100644
--- a/gcc/toplev.c
+++ b/gcc/toplev.c
@@ -1968,12 +1968,35 @@ char *
xmalloc (size)
unsigned size;
{
- register char *value = (char *) malloc (size);
- if (value == 0 && size != 0)
+ register char *value;
+
+ if (size == 0)
+ size = 1;
+
+ value = (char *) malloc (size);
+ if (value == 0)
+ fatal ("virtual memory exhausted");
+ return value;
+}
+
+/* Same as `calloc' but report error if no memory available. */
+
+char *
+xcalloc (size1, size2)
+ unsigned size1, size2;
+{
+ register char *value;
+
+ if (size1 == 0 || size2 == 0)
+ size1 = size2 = 1;
+
+ value = (char *) calloc (size1, size2);
+ if (value == 0)
fatal ("virtual memory exhausted");
return value;
}
+
/* Same as `realloc' but report error if no memory available.
Also handle null PTR even if the vendor realloc gets it wrong. */
@@ -1982,11 +2005,18 @@ xrealloc (ptr, size)
char *ptr;
int size;
{
- char *result = (ptr
- ? (char *) realloc (ptr, size)
- : (char *) malloc (size));
+ char *result;
+
+ if (size == 0)
+ size = 1;
+
+ result = (ptr
+ ? (char *) realloc (ptr, size)
+ : (char *) malloc (size));
+
if (!result)
fatal ("virtual memory exhausted");
+
return result;
}
diff --git a/gcc/tree.h b/gcc/tree.h
index 6a88bee..b98f555 100644
--- a/gcc/tree.h
+++ b/gcc/tree.h
@@ -1314,9 +1314,11 @@ extern int floor_log2_wide PROTO((unsigned HOST_WIDE_INT));
cast their pointers to char *, and all of the xrealloc's don't use
void * yet. */
extern char *xmalloc PROTO((size_t));
+extern char *xcalloc PROTO((size_t, size_t));
extern char *xrealloc PROTO((void *, size_t));
#else
extern char *xmalloc ();
+extern char *xcalloc ();
extern char *xrealloc ();
#endif
diff --git a/gcc/varray.c b/gcc/varray.c
new file mode 100644
index 0000000..80f15b2
--- /dev/null
+++ b/gcc/varray.c
@@ -0,0 +1,70 @@
+/* Virtual array support.
+ Copyright (C) 1998 Free Software Foundation, Inc.
+ Contributed by Cygnus Solutions.
+
+ This file is part of GNU CC.
+
+ GNU CC is free software; you can redistribute it and/or modify it
+ 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.
+
+ GNU CC 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.
+
+ You should have received a copy of the GNU General Public License
+ along with GNU CC; see the file COPYING. If not, write to the Free
+ the Free Software Foundation, 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include "config.h"
+#include "system.h"
+#include "rtl.h"
+#include "tree.h"
+#include "bitmap.h"
+#include "varray.h"
+
+#define VARRAY_HDR_SIZE (sizeof (struct varray_head_tag) - sizeof (varray_data))
+
+/* Allocate a virtual array with NUM_ELEMENT elements, each of which is
+ ELEMENT_SIZE bytes long, named NAME. Array elements are zeroed. */
+varray_type
+varray_init (num_elements, element_size, name)
+ size_t num_elements;
+ size_t element_size;
+ const char *name;
+{
+ size_t data_size = num_elements * element_size;
+ varray_type ptr = (varray_type) xcalloc (VARRAY_HDR_SIZE + data_size, 1);
+
+ ptr->num_elements = num_elements;
+ ptr->element_size = element_size;
+ ptr->name = name;
+ return ptr;
+}
+
+/* Grow/shrink the virtual array VA to N elements. Zero any new elements
+ allocated. */
+varray_type
+varray_grow (va, n)
+ varray_type va;
+ size_t n;
+{
+ size_t old_elements = va->num_elements;
+
+ if (n != old_elements)
+ {
+ size_t element_size = va->element_size;
+ size_t old_data_size = old_elements * element_size;
+ size_t data_size = n * element_size;
+
+ va = (varray_type) xrealloc ((char *)va, VARRAY_HDR_SIZE + data_size);
+ va->num_elements = n;
+ if (n > old_elements)
+ bzero (&va->data.c[old_data_size], data_size - old_data_size);
+ }
+
+ return va;
+}
diff --git a/gcc/varray.h b/gcc/varray.h
new file mode 100644
index 0000000..373bb5c
--- /dev/null
+++ b/gcc/varray.h
@@ -0,0 +1,162 @@
+/* Virtual array support.
+ Copyright (C) 1998 Free Software Foundation, Inc.
+ Contributed by Cygnus Solutions.
+
+ This file is part of GNU CC.
+
+ GNU CC is free software; you can redistribute it and/or modify it
+ 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.
+
+ GNU CC 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.
+
+ You should have received a copy of the GNU General Public License
+ along with GNU CC; see the file COPYING. If not, write to the Free
+ the Free Software Foundation, 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#ifndef _VARRAY_H_
+#define _VARRAY_H_
+
+#ifndef PROTO
+#include "gansidecl.h"
+#endif
+
+#ifndef HOST_WIDE_INT
+#include "machmode.h"
+#endif
+
+/* Union of various array types that are used. */
+typedef union varray_data_tag {
+ char c[1];
+ unsigned char uc[1];
+ short s[1];
+ unsigned short us[1];
+ int i[1];
+ unsigned int u[1];
+ long l[1];
+ unsigned long ul[1];
+ HOST_WIDE_INT hint[1];
+ unsigned HOST_WIDE_INT uhint[1];
+ GENERIC_PTR generic[1];
+ char *cptr[1];
+ struct rtx_def *rtx[1];
+ struct rtvec_def *rtvec[1];
+ union tree_node *tree[1];
+ struct bitmap_head_def *bitmap[1];
+ struct sched_info_tag *sched[1];
+ struct reg_info_def *reg[1];
+} varray_data;
+
+/* Virtual array of pointers header. */
+typedef struct varray_head_tag {
+ size_t num_elements; /* maximum element number allocated */
+ size_t element_size; /* size of each data element */
+ const char *name; /* name of the varray for reporting errors */
+ varray_data data; /* data elements follow, must be last */
+} *varray_type;
+
+/* Allocate a virtual array with NUM elements, each of which is SIZE bytes
+ long, named NAME. Array elements are zeroed. */
+extern varray_type varray_init PROTO ((size_t, size_t, const char *));
+
+#define VARRAY_CHAR_INIT(va, num, name) \
+ va = varray_init (num, sizeof (char), name)
+
+#define VARRAY_UCHAR_INIT(va, num, name) \
+ va = varray_init (num, sizeof (unsigned char), name)
+
+#define VARRAY_SHORT_INIT(va, num, name) \
+ va = varray_init (num, sizeof (short), name)
+
+#define VARRAY_USHORT_INIT(va, num, name) \
+ va = varray_init (num, sizeof (unsigned short), name)
+
+#define VARRAY_INT_INIT(va, num, name) \
+ va = varray_init (num, sizeof (int), name)
+
+#define VARRAY_UINT_INIT(va, num, name) \
+ va = varray_init (num, sizeof (unsigned int), name)
+
+#define VARRAY_LONG_INIT(va, num, name) \
+ va = varray_init (num, sizeof (long), name)
+
+#define VARRAY_ULONG_INIT(va, num, name) \
+ va = varray_init (num, sizeof (unsigned long), name)
+
+#define VARRAY_WIDE_INT_INIT(va, num, name) \
+ va = varray_init (num, sizeof (HOST_WIDE_INT), name)
+
+#define VARRAY_UWIDE_INT_INIT(va, num, name) \
+ va = varray_init (num, sizeof (unsigned HOST_WIDE_INT), name)
+
+#define VARRAY_GENERIC_PTR_INIT(va, num, name) \
+ va = varray_init (num, sizeof (GENERIC_PTR), name)
+
+#define VARRAY_CHAR_PTR_INIT(va, num, name) \
+ va = varray_init (num, sizeof (char *), name)
+
+#define VARRAY_RTX_INIT(va, num, name) \
+ va = varray_init (num, sizeof (struct rtx_def *), name)
+
+#define VARRAY_RTVEC_INIT(va, num, name) \
+ va = varray_init (num, sizeof (struct rtvec_def), name)
+
+#define VARRAY_TREE_INIT(va, num, name) \
+ va = varray_init (num, sizeof (union tree_node *), name)
+
+#define VARRAY_BITMAP_INIT(va, num, name) \
+ va = varray_init (num, sizeof (struct bitmap_head_def *), name)
+
+#define VARRAY_SCHED_INIT(va, num, name) \
+ va = varray_init (num, sizeof (struct sched_info_tag *), name)
+
+#define VARRAY_REG_INIT(va, num, name) \
+ va = varray_init (num, sizeof (struct reg_info_def *), name)
+
+/* Free up memory allocated by the virtual array, but do not free any of the
+ elements involved. */
+#define VARRAY_FREE(vp) ((vp) && (free (vp), (vp = (varray_type)0)))
+
+/* Grow/shrink the virtual array VA to N elements. */
+extern varray_type varray_grow PROTO((varray_type, size_t));
+
+#define VARRAY_GROW(VA, N) ((VA) = varray_grow (VA, N))
+
+/* Check for VARRAY_xxx macros being in bound, return N for use as an
+ index. */
+#ifdef ENABLE_CHECKING
+#define VARRAY_CHECK(VA, N) \
+((((size_t)(N) < (VA)->num_elements) \
+ ? 0 \
+ : (fatal ("Virtual array %s element %ld out of bounds, at %s:%d", \
+ (VA)->name, (long)(N), __FILE__, __LINE__), 0)), \
+ (N))
+#else
+#define VARRAY_CHECK(VA, N) (N)
+#endif
+
+#define VARRAY_CHAR(VA, N) ((VA)->data.c[ VARRAY_CHECK (VA, N) ])
+#define VARRAY_UCHAR(VA, N) ((VA)->data.uc[ VARRAY_CHECK (VA, N) ])
+#define VARRAY_SHORT(VA, N) ((VA)->data.s[ VARRAY_CHECK (VA, N) ])
+#define VARRAY_USHORT(VA, N) ((VA)->data.us[ VARRAY_CHECK (VA, N) ])
+#define VARRAY_INT(VA, N) ((VA)->data.i[ VARRAY_CHECK (VA, N) ])
+#define VARRAY_UINT(VA, N) ((VA)->data.u[ VARRAY_CHECK (VA, N) ])
+#define VARRAY_LONG(VA, N) ((VA)->data.l[ VARRAY_CHECK (VA, N) ])
+#define VARRAY_ULONG(VA, N) ((VA)->data.ul[ VARRAY_CHECK (VA, N) ])
+#define VARRAY_WIDE_INT(VA, N) ((VA)->data.hint[ VARRAY_CHECK (VA, N) ])
+#define VARRAY_UWIDE_INT(VA, N) ((VA)->data.uhint[ VARRAY_CHECK (VA, N) ])
+#define VARRAY_GENERIC_PTR(VA,N) ((VA)->data.generic[ VARRAY_CHECK (VA, N) ])
+#define VARRAY_CHAR_PTR(VA,N) ((VA)->data.cptr[ VARRAY_CHECK (VA, N) ])
+#define VARRAY_RTX(VA, N) ((VA)->data.rtx[ VARRAY_CHECK (VA, N) ])
+#define VARRAY_RTVEC(VA, N) ((VA)->data.rtvec[ VARRAY_CHECK (VA, N) ])
+#define VARRAY_TREE(VA, N) ((VA)->data.tree[ VARRAY_CHECK (VA, N) ])
+#define VARRAY_BITMAP(VA, N) ((VA)->data.bitmap[ VARRAY_CHECK (VA, N) ])
+#define VARRAY_SCHED(VA, N) ((VA)->data.sched[ VARRAY_CHECK (VA, N) ])
+#define VARRAY_REG(VA, N) ((VA)->data.reg[ VARRAY_CHECK (VA, N) ])
+
+#endif /* _VARRAY_H_ */