1 /*
2  * Copyright (c) 2001-2010  Stephen Williams (steve@icarus.com)
3  *
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)
8  *    any later version.
9  *
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.
14  *
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  */
19 
20 # include  "parse_misc.h"
21 # include  "compile.h"
22 # include  <cstdio>
23 # include  <cstdlib>
24 # include  "ivl_alloc.h"
25 
26 const char*yypath;
27 unsigned yyline;
28 
yyerror(const char * msg)29 void yyerror(const char*msg)
30 {
31       fprintf(stderr, "%s:%u: %s\n", yypath, yyline, msg);
32 }
33 
symbv_init(struct symbv_s * obj)34 void symbv_init(struct symbv_s*obj)
35 {
36       obj->cnt = 0;
37       obj->vect = 0;
38 }
39 
symbv_add(struct symbv_s * obj,struct symb_s item)40 void symbv_add(struct symbv_s*obj, struct symb_s item)
41 {
42       obj->vect = (struct symb_s*)
43 	    realloc(obj->vect, (obj->cnt+1) * sizeof(struct symb_s));
44       obj->vect[obj->cnt] = item;
45       obj->cnt += 1;
46 }
47 
numbv_init(struct numbv_s * obj)48 void numbv_init(struct numbv_s*obj)
49 {
50       obj->cnt = 0;
51       obj->nvec = 0;
52 }
53 
numbv_add(struct numbv_s * obj,long item)54 void numbv_add(struct numbv_s*obj, long item)
55 {
56       obj->nvec = (long*) realloc(obj->nvec, (obj->cnt+1) * sizeof(long));
57       obj->nvec[obj->cnt] = item;
58       obj->cnt += 1;
59 }
60 
numbv_clear(struct numbv_s * obj)61 void numbv_clear(struct numbv_s*obj)
62 {
63       free(obj->nvec);
64       obj->nvec = 0;
65       obj->cnt = 0;
66 }
67 
argv_init(struct argv_s * obj)68 void argv_init(struct argv_s*obj)
69 {
70       obj->argc = 0;
71       obj->argv = 0;
72       obj->syms = 0;
73 }
74 
argv_add(struct argv_s * obj,vpiHandle item)75 void argv_add(struct argv_s*obj, vpiHandle item)
76 {
77       obj->argv = (vpiHandle*)
78 	    realloc(obj->argv, (obj->argc+1)*sizeof(vpiHandle));
79       obj->argv[obj->argc] = item;
80       obj->argc += 1;
81 }
82 
argv_sym_add(struct argv_s * obj,char * item)83 void argv_sym_add(struct argv_s*obj, char *item)
84 {
85       argv_add(obj, 0x0);
86       obj->syms = (char**)
87 	    realloc(obj->syms, (obj->argc)*sizeof(char*));
88       obj->syms[obj->argc-1] = item;
89 }
90 
argv_sym_lookup(struct argv_s * obj)91 void argv_sym_lookup(struct argv_s*obj)
92 {
93       if (!obj->syms)
94 	    return;
95       for (unsigned i=0; i < obj->argc; i++)
96 	    if (!obj->argv[i])
97 		  compile_vpi_lookup(&obj->argv[i], obj->syms[i]);
98       free(obj->syms);
99 }
100