Make lxt use stringheap to perm-allocate strings.

This commit is contained in:
steve 2003-02-13 18:13:28 +00:00
parent 25d47ec6df
commit d0728add45
6 changed files with 142 additions and 10 deletions

View File

@ -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)

70
vpi/stringheap.c Normal file
View File

@ -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 <string.h>
# include <stdlib.h>
#ifdef HAVE_MALLOC_H
# include <malloc.h>
#endif
# include <assert.h>
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.
*
*/

43
vpi/stringheap.h Normal file
View File

@ -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

View File

@ -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 <malloc.h>
#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.
*

View File

@ -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 <malloc.h>
#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.
*

View File

@ -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.
*