Fix for assertion error when expanding macro.
[iverilog.git] / vpip / vpi_iter.c
bloba9bdd5a4559625ed9021f6cd4cfff1a4db20d94c
1 /*
2 * Copyright (c) 1999 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)
8 * any later version.
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
19 #ifdef HAVE_CVS_IDENT
20 #ident "$Id: vpi_iter.c,v 1.2 2002/08/12 01:35:05 steve Exp $"
21 #endif
24 * Find here the methods functions in support of iterator objects.
27 # include "vpi_priv.h"
28 # include <stdlib.h>
29 # include <assert.h>
31 static const struct __vpirt vpip_iterator_rt = {
32 vpiIterator,
41 vpiHandle vpip_make_iterator(unsigned nargs, vpiHandle*args)
43 struct __vpiIterator*res = calloc(1, sizeof(struct __vpiIterator));
44 res->base.vpi_type = &vpip_iterator_rt;
45 res->args = args;
46 res->nargs = nargs;
47 res->next = 0;
49 return &(res->base);
53 * The vpi_scan function only applies to iterators. It returns the
54 * next vpiHandle in the iterated list.
56 vpiHandle vpi_scan(vpiHandle ref)
58 struct __vpiIterator*hp = (struct __vpiIterator*)ref;
59 assert(ref->vpi_type->type_code == vpiIterator);
61 if (hp->next == hp->nargs) {
62 vpi_free_object(ref);
63 return 0;
66 return hp->args[hp->next++];
70 * $Log: vpi_iter.c,v $
71 * Revision 1.2 2002/08/12 01:35:05 steve
72 * conditional ident string using autoconfig.
74 * Revision 1.1 2001/03/14 19:27:44 steve
75 * Rearrange VPI support libraries.
77 * Revision 1.3 2000/02/23 02:56:56 steve
78 * Macintosh compilers do not support ident.
80 * Revision 1.2 1999/12/15 04:01:14 steve
81 * Add the VPI implementation of $readmemh.
83 * Revision 1.1 1999/10/28 00:47:25 steve
84 * Rewrite vvm VPI support to make objects more
85 * persistent, rewrite the simulation scheduler
86 * in C (to interface with VPI) and add VPI support
87 * for callbacks.