From d0728add45a37aa8fba2095798d4bf72bb306940 Mon Sep 17 00:00:00 2001 From: steve Date: Thu, 13 Feb 2003 18:13:28 +0000 Subject: [PATCH] Make lxt use stringheap to perm-allocate strings. --- vpi/Makefile.in | 4 +-- vpi/stringheap.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++ vpi/stringheap.h | 43 +++++++++++++++++++++++++++++ vpi/sys_lxt.c | 19 +++++++++---- vpi/vcd_priv.c | 10 +++++-- vpi/vcd_priv.h | 6 ++++- 6 files changed, 142 insertions(+), 10 deletions(-) create mode 100644 vpi/stringheap.c create mode 100644 vpi/stringheap.h diff --git a/vpi/Makefile.in b/vpi/Makefile.in index 7af3215a4..c1c01bf4f 100644 --- a/vpi/Makefile.in +++ b/vpi/Makefile.in @@ -18,7 +18,7 @@ # 59 Temple Place - Suite 330 # Boston, MA 02111-1307, USA # -#ident "$Id: Makefile.in,v 1.33 2003/02/11 05:21:33 steve Exp $" +#ident "$Id: Makefile.in,v 1.34 2003/02/13 18:13:28 steve Exp $" # # SHELL = /bin/sh @@ -58,7 +58,7 @@ all: system.vpi O = sys_table.o sys_deposit.o sys_display.o sys_finish.o sys_plusargs.o \ sys_random.o sys_readmem.o sys_readmem_lex.o sys_time.o sys_vcd.o \ sys_lxt.o lxt_write.o vcd_priv.o \ -mt19937int.o +mt19937int.o stringheap.o SYSTEM_VPI_LDFLAGS = -L../vvp -lvpi ifeq (@WIN32@,yes) diff --git a/vpi/stringheap.c b/vpi/stringheap.c new file mode 100644 index 000000000..3ca42fccc --- /dev/null +++ b/vpi/stringheap.c @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2003 Stephen Williams (steve@icarus.com) + * + * This source code is free software; you can redistribute it + * and/or modify it in source code form under the terms of the GNU + * General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ +#ifdef HAVE_CVS_IDENT +#ident "$Id: stringheap.c,v 1.1 2003/02/13 18:13:28 steve Exp $" +#endif + +# include "stringheap.h" +# include +# include +#ifdef HAVE_MALLOC_H +# include +#endif +# include + +struct stringheap_cell { + struct stringheap_cell*next; +}; + +# define PAGE_SIZE 8192 +# define STRINGHEAP_SIZE (PAGE_SIZE - sizeof(struct stringheap_cell)) + +const char*strdup_sh(struct stringheap_s*hp, const char*txt) +{ + char*res; + unsigned len = strlen(txt); + assert(len < STRINGHEAP_SIZE); + + if (hp->cell_lst == 0) { + hp->cell_lst = malloc(PAGE_SIZE); + hp->cell_lst->next = 0; + hp->cell_off = 0; + } + + if ((STRINGHEAP_SIZE - hp->cell_off) <= len) { + struct stringheap_cell*tmp = malloc(PAGE_SIZE); + tmp->next = hp->cell_lst; + hp->cell_off = 0; + } + + res = (char*) (hp->cell_lst + 1); + res += hp->cell_off; + strcpy(res, txt); + hp->cell_off += len + 1; + + return res; +} + +/* + * $Log: stringheap.c,v $ + * Revision 1.1 2003/02/13 18:13:28 steve + * Make lxt use stringheap to perm-allocate strings. + * + */ + diff --git a/vpi/stringheap.h b/vpi/stringheap.h new file mode 100644 index 000000000..9db1e6d06 --- /dev/null +++ b/vpi/stringheap.h @@ -0,0 +1,43 @@ +#ifndef __stringheap_H +#define __stringheap_H +/* + * Copyright (c) 2003 Stephen Williams (steve@icarus.com) + * + * This source code is free software; you can redistribute it + * and/or modify it in source code form under the terms of the GNU + * General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ +#ifdef HAVE_CVS_IDENT +#ident "$Id: stringheap.h,v 1.1 2003/02/13 18:13:28 steve Exp $" +#endif + +struct stringheap_cell; + +struct stringheap_s { + struct stringheap_cell*cell_lst; + unsigned cell_off; +}; + +/* + * Allocate the string from the heap. + */ +const char*strdup_sh(struct stringheap_s*hp, const char*str); + +/* + * $Log: stringheap.h,v $ + * Revision 1.1 2003/02/13 18:13:28 steve + * Make lxt use stringheap to perm-allocate strings. + * + */ +#endif diff --git a/vpi/sys_lxt.c b/vpi/sys_lxt.c index 35d00ecff..1234ae206 100644 --- a/vpi/sys_lxt.c +++ b/vpi/sys_lxt.c @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #ifdef HAVE_CVS_IDENT -#ident "$Id: sys_lxt.c,v 1.15 2003/02/12 05:28:01 steve Exp $" +#ident "$Id: sys_lxt.c,v 1.16 2003/02/13 18:13:28 steve Exp $" #endif # include "config.h" @@ -39,6 +39,8 @@ #ifdef HAVE_MALLOC_H # include #endif +# include "stringheap.h" + /* * The lxt_scope head and current pointers are used to keep a scope @@ -125,7 +127,7 @@ static char *create_full_name(const char *name) n2 += strlen(n2); assert( (n2 - n + 1) == len ); - return(n); + return n; } @@ -475,7 +477,9 @@ static void scan_item(unsigned depth, vpiHandle item, int skip) } if (!ident) { - ident = create_full_name(name); + char*tmp = create_full_name(name); + ident = strdup_sh(&name_heap, tmp); + free(tmp); if (nexus_id) set_nexus_ident(nexus_id, ident); @@ -513,8 +517,10 @@ static void scan_item(unsigned depth, vpiHandle item, int skip) break; name = vpi_get_str(vpiName, item); - ident = create_full_name(name); - + { char*tmp = create_full_name(name); + ident = strdup_sh(&name_heap, tmp); + free(tmp); + } info = malloc(sizeof(*info)); info->time.type = vpiSimTime; @@ -730,6 +736,9 @@ void sys_lxt_register() /* * $Log: sys_lxt.c,v $ + * Revision 1.16 2003/02/13 18:13:28 steve + * Make lxt use stringheap to perm-allocate strings. + * * Revision 1.15 2003/02/12 05:28:01 steve * Set dumpoff of real variables to NaN. * diff --git a/vpi/vcd_priv.c b/vpi/vcd_priv.c index edaa07a43..7d28e2a47 100644 --- a/vpi/vcd_priv.c +++ b/vpi/vcd_priv.c @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #ifdef HAVE_CVS_IDENT -#ident "$Id: vcd_priv.c,v 1.1 2003/02/11 05:21:33 steve Exp $" +#ident "$Id: vcd_priv.c,v 1.2 2003/02/13 18:13:28 steve Exp $" #endif # include "vcd_priv.h" @@ -28,6 +28,9 @@ #ifdef HAVE_MALLOC_H # include #endif +# include "stringheap.h" + +struct stringheap_s name_heap = {0, 0}; struct vcd_names_s { const char *name; @@ -39,7 +42,7 @@ void vcd_names_add(struct vcd_names_list_s*tab, const char *name) struct vcd_names_s *nl = (struct vcd_names_s *) malloc(sizeof(struct vcd_names_s)); assert(nl); - nl->name = strdup(name); + nl->name = strdup_sh(&name_heap, name); nl->next = tab->vcd_names_list; tab->vcd_names_list = nl; tab->listed_names ++; @@ -166,6 +169,9 @@ void set_nexus_ident(int nex, const char *id) /* * $Log: vcd_priv.c,v $ + * Revision 1.2 2003/02/13 18:13:28 steve + * Make lxt use stringheap to perm-allocate strings. + * * Revision 1.1 2003/02/11 05:21:33 steve * Support dump of vpiRealVar objects. * diff --git a/vpi/vcd_priv.h b/vpi/vcd_priv.h index 9321ae9c6..f5f1ed70a 100644 --- a/vpi/vcd_priv.h +++ b/vpi/vcd_priv.h @@ -19,10 +19,11 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #ifdef HAVE_CVS_IDENT -#ident "$Id: vcd_priv.h,v 1.1 2003/02/11 05:21:33 steve Exp $" +#ident "$Id: vcd_priv.h,v 1.2 2003/02/13 18:13:28 steve Exp $" #endif struct vcd_names_s; +extern struct stringheap_s name_heap; struct vcd_names_list_s { struct vcd_names_s *vcd_names_list; @@ -43,6 +44,9 @@ extern void set_nexus_ident(int nex, const char *id); /* * $Log: vcd_priv.h,v $ + * Revision 1.2 2003/02/13 18:13:28 steve + * Make lxt use stringheap to perm-allocate strings. + * * Revision 1.1 2003/02/11 05:21:33 steve * Support dump of vpiRealVar objects. *