2 * Copyright (c) 2003 Stephen Williams (steve@icarus.com)
4 * This source code is free software; you can redistribute it
5 * and/or modify it in source code form under the terms of the GNU
6 * General Public License as published by the Free Software
7 * Foundation; either version 2 of the License, or (at your option)
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
20 #ident "$Id: vcd_priv.c,v 1.6 2004/10/04 01:10:58 steve Exp $"
23 # include "vpi_config.h"
24 # include "vcd_priv.h"
32 # include "stringheap.h"
34 struct stringheap_s name_heap
= {0, 0};
38 struct vcd_names_s
*next
;
41 void vcd_names_add(struct vcd_names_list_s
*tab
, const char *name
)
43 struct vcd_names_s
*nl
= (struct vcd_names_s
*)
44 malloc(sizeof(struct vcd_names_s
));
46 nl
->name
= strdup_sh(&name_heap
, name
);
47 nl
->next
= tab
->vcd_names_list
;
48 tab
->vcd_names_list
= nl
;
52 static int vcd_names_compare(const void *s1
, const void *s2
)
54 const char *v1
= *(const char **) s1
;
55 const char *v2
= *(const char **) s2
;
57 return strcmp(v1
, v2
);
60 const char *vcd_names_search(struct vcd_names_list_s
*tab
, const char *key
)
64 if (tab
->vcd_names_sorted
== 0)
67 v
= (const char **) bsearch(&key
,
68 tab
->vcd_names_sorted
, tab
->sorted_names
,
69 sizeof(const char *), vcd_names_compare
);
71 return(v
? *v
: NULL
);
74 void vcd_names_sort(struct vcd_names_list_s
*tab
)
76 if (tab
->listed_names
) {
77 struct vcd_names_s
*r
;
80 tab
->sorted_names
+= tab
->listed_names
;
81 tab
->vcd_names_sorted
= (const char **)
82 realloc(tab
->vcd_names_sorted
,
83 tab
->sorted_names
*(sizeof(const char *)));
84 assert(tab
->vcd_names_sorted
);
86 l
= tab
->vcd_names_sorted
+ tab
->sorted_names
- tab
->listed_names
;
87 tab
->listed_names
= 0;
89 r
= tab
->vcd_names_list
;
90 tab
->vcd_names_list
= 0x0;
93 struct vcd_names_s
*rr
= r
;
99 qsort(tab
->vcd_names_sorted
, tab
->sorted_names
,
100 sizeof(const char **), vcd_names_compare
);
108 In structural models, many signals refer to the same nexus.
109 Some structural models also have very many signals. This cache
110 saves nexus_id - vcd_id pairs, and reuses the vcd_id when a signal
111 refers to a nexus that is already dumped.
113 The new signal will be listed as a $var, but no callback
114 will be installed. This saves considerable CPU time and leads
117 The _vpiNexusId is a private (int) property of IVL simulators.
123 struct vcd_id_s
*next
;
127 static inline unsigned ihash(int nex
)
135 static struct vcd_id_s
**vcd_ids
= 0;
137 const char *find_nexus_ident(int nex
)
139 struct vcd_id_s
*bucket
;
142 vcd_ids
= (struct vcd_id_s
**)
143 calloc(256, sizeof(struct vcd_id_s
*));
147 bucket
= vcd_ids
[ihash(nex
)];
149 if (nex
== bucket
->nex
)
151 bucket
= bucket
->next
;
157 void set_nexus_ident(int nex
, const char *id
)
159 struct vcd_id_s
*bucket
;
163 bucket
= (struct vcd_id_s
*) malloc(sizeof(struct vcd_id_s
));
164 bucket
->next
= vcd_ids
[ihash(nex
)];
167 vcd_ids
[ihash(nex
)] = bucket
;
172 * $Log: vcd_priv.c,v $
173 * Revision 1.6 2004/10/04 01:10:58 steve
174 * Clean up spurious trailing white space.
176 * Revision 1.5 2004/01/21 01:22:53 steve
177 * Give the vip directory its own configure and vpi_config.h
179 * Revision 1.4 2003/11/10 20:18:02 steve
182 * Revision 1.3 2003/04/28 01:03:11 steve
183 * Fix stringheap list management failure.
185 * Revision 1.2 2003/02/13 18:13:28 steve
186 * Make lxt use stringheap to perm-allocate strings.
188 * Revision 1.1 2003/02/11 05:21:33 steve
189 * Support dump of vpiRealVar objects.