2001-03-18 01:37:55 +01:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2001 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
|
|
|
|
|
*/
|
|
|
|
|
#if !defined(WINNT)
|
2001-11-02 06:43:11 +01:00
|
|
|
#ident "$Id: vpi_scope.cc,v 1.10 2001/11/02 05:43:11 steve Exp $"
|
2001-03-18 01:37:55 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
# include "compile.h"
|
|
|
|
|
# include "vpi_priv.h"
|
|
|
|
|
# include "symbols.h"
|
2001-09-15 20:27:04 +02:00
|
|
|
#ifdef HAVE_MALLOC_H
|
2001-03-18 01:37:55 +01:00
|
|
|
# include <malloc.h>
|
2001-09-15 20:27:04 +02:00
|
|
|
#endif
|
|
|
|
|
# include <stdlib.h>
|
2001-03-18 01:37:55 +01:00
|
|
|
# include <assert.h>
|
|
|
|
|
|
2001-04-03 05:46:14 +02:00
|
|
|
static char* scope_get_str(int code, vpiHandle obj)
|
|
|
|
|
{
|
|
|
|
|
struct __vpiScope*ref = (struct __vpiScope*)obj;
|
|
|
|
|
|
2001-10-15 03:49:50 +02:00
|
|
|
char *n, *nn;
|
2001-04-03 05:46:14 +02:00
|
|
|
|
|
|
|
|
assert((obj->vpi_type->type_code == vpiModule)
|
2001-10-15 04:58:27 +02:00
|
|
|
|| (obj->vpi_type->type_code == vpiFunction)
|
|
|
|
|
|| (obj->vpi_type->type_code == vpiTask)
|
2001-04-03 05:46:14 +02:00
|
|
|
|| (obj->vpi_type->type_code == vpiNamedBegin)
|
2001-10-15 04:58:27 +02:00
|
|
|
|| (obj->vpi_type->type_code == vpiNamedFork));
|
2001-04-03 05:46:14 +02:00
|
|
|
|
|
|
|
|
switch (code) {
|
|
|
|
|
case vpiFullName:
|
|
|
|
|
return ref->name;
|
2001-10-15 03:49:50 +02:00
|
|
|
|
|
|
|
|
case vpiName:
|
|
|
|
|
nn = n = ref->name;
|
|
|
|
|
while (*n)
|
|
|
|
|
if (*n=='\\' && *++n)
|
|
|
|
|
++n;
|
|
|
|
|
else if (*n=='.')
|
|
|
|
|
nn = ++n;
|
|
|
|
|
else
|
|
|
|
|
++n;
|
|
|
|
|
return nn;
|
|
|
|
|
|
2001-04-03 05:46:14 +02:00
|
|
|
default:
|
|
|
|
|
assert(0);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2001-10-15 03:49:50 +02:00
|
|
|
static vpiHandle scope_get_handle(int code, vpiHandle obj)
|
|
|
|
|
{
|
|
|
|
|
assert((obj->vpi_type->type_code == vpiModule)
|
2001-10-15 04:58:27 +02:00
|
|
|
|| (obj->vpi_type->type_code == vpiFunction)
|
|
|
|
|
|| (obj->vpi_type->type_code == vpiTask)
|
2001-10-15 03:49:50 +02:00
|
|
|
|| (obj->vpi_type->type_code == vpiNamedBegin)
|
2001-10-15 04:58:27 +02:00
|
|
|
|| (obj->vpi_type->type_code == vpiNamedFork));
|
2001-10-15 03:49:50 +02:00
|
|
|
|
|
|
|
|
struct __vpiScope*rfp = (struct __vpiScope*)obj;
|
|
|
|
|
|
|
|
|
|
switch (code) {
|
|
|
|
|
|
|
|
|
|
case vpiScope:
|
|
|
|
|
return &rfp->scope->base;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2001-04-03 05:46:14 +02:00
|
|
|
static vpiHandle module_iter(int code, vpiHandle obj)
|
|
|
|
|
{
|
|
|
|
|
struct __vpiScope*ref = (struct __vpiScope*)obj;
|
|
|
|
|
assert((obj->vpi_type->type_code == vpiModule)
|
2001-10-15 04:58:27 +02:00
|
|
|
|| (obj->vpi_type->type_code == vpiFunction)
|
2001-04-03 05:46:14 +02:00
|
|
|
|| (obj->vpi_type->type_code == vpiTask)
|
2001-10-15 04:58:27 +02:00
|
|
|
|| (obj->vpi_type->type_code == vpiNamedBegin)
|
|
|
|
|
|| (obj->vpi_type->type_code == vpiNamedFork));
|
2001-04-03 05:46:14 +02:00
|
|
|
|
|
|
|
|
switch (code) {
|
|
|
|
|
case vpiInternalScope:
|
2001-06-10 18:47:49 +02:00
|
|
|
return vpip_make_iterator(ref->nintern, ref->intern);
|
2001-04-03 05:46:14 +02:00
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2001-10-15 04:58:27 +02:00
|
|
|
static const struct __vpirt vpip_scope_module_rt = {
|
2001-04-03 05:46:14 +02:00
|
|
|
vpiModule,
|
|
|
|
|
0,
|
|
|
|
|
scope_get_str,
|
|
|
|
|
0,
|
|
|
|
|
0,
|
2001-10-15 03:49:50 +02:00
|
|
|
scope_get_handle,
|
2001-04-03 05:46:14 +02:00
|
|
|
module_iter
|
|
|
|
|
};
|
|
|
|
|
|
2001-10-15 04:58:27 +02:00
|
|
|
static const struct __vpirt vpip_scope_task_rt = {
|
|
|
|
|
vpiTask,
|
|
|
|
|
0,
|
|
|
|
|
scope_get_str,
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
scope_get_handle,
|
|
|
|
|
module_iter
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static const struct __vpirt vpip_scope_function_rt = {
|
|
|
|
|
vpiFunction,
|
|
|
|
|
0,
|
|
|
|
|
scope_get_str,
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
scope_get_handle,
|
|
|
|
|
module_iter
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static const struct __vpirt vpip_scope_begin_rt = {
|
|
|
|
|
vpiNamedBegin,
|
|
|
|
|
0,
|
|
|
|
|
scope_get_str,
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
scope_get_handle,
|
|
|
|
|
module_iter
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static const struct __vpirt vpip_scope_fork_rt = {
|
|
|
|
|
vpiNamedFork,
|
|
|
|
|
0,
|
|
|
|
|
scope_get_str,
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
scope_get_handle,
|
|
|
|
|
module_iter
|
|
|
|
|
};
|
|
|
|
|
|
2001-03-18 01:37:55 +01:00
|
|
|
static struct __vpiScope*current_scope = 0;
|
|
|
|
|
|
|
|
|
|
static void attach_to_scope_(struct __vpiScope*scope, vpiHandle obj)
|
|
|
|
|
{
|
|
|
|
|
assert(scope);
|
|
|
|
|
unsigned idx = scope->nintern++;
|
|
|
|
|
|
|
|
|
|
if (scope->intern == 0)
|
|
|
|
|
scope->intern = (vpiHandle*)
|
|
|
|
|
malloc(sizeof(vpiHandle));
|
|
|
|
|
else
|
|
|
|
|
scope->intern = (vpiHandle*)
|
|
|
|
|
realloc(scope->intern, sizeof(vpiHandle)*scope->nintern);
|
|
|
|
|
|
|
|
|
|
scope->intern[idx] = obj;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* When the compiler encounters a scope declaration, this function
|
|
|
|
|
* creates and initializes a __vpiScope object with the requested name
|
|
|
|
|
* and within the addressed parent. The label is used as a key in the
|
|
|
|
|
* symbol table and the name is used to construct the actual object.
|
|
|
|
|
*/
|
2001-10-15 04:58:27 +02:00
|
|
|
void compile_scope_decl(char*label, char*type, char*name, char*parent)
|
2001-03-18 01:37:55 +01:00
|
|
|
{
|
2001-04-18 06:21:23 +02:00
|
|
|
struct __vpiScope*scope = new struct __vpiScope;
|
2001-10-15 04:58:27 +02:00
|
|
|
|
|
|
|
|
switch(type[2]) {
|
2001-11-02 06:43:11 +01:00
|
|
|
case 'd': /* type == module */
|
|
|
|
|
scope->base.vpi_type = &vpip_scope_module_rt;
|
|
|
|
|
break;
|
|
|
|
|
case 'n': /* type == function */
|
|
|
|
|
scope->base.vpi_type = &vpip_scope_function_rt;
|
|
|
|
|
break;
|
|
|
|
|
case 's': /* type == task */
|
|
|
|
|
scope->base.vpi_type = &vpip_scope_task_rt;
|
|
|
|
|
break;
|
|
|
|
|
case 'r': /* type == fork */
|
|
|
|
|
scope->base.vpi_type = &vpip_scope_fork_rt;
|
|
|
|
|
break;
|
|
|
|
|
case 'g': /* type == begin */
|
|
|
|
|
scope->base.vpi_type = &vpip_scope_begin_rt;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
scope->base.vpi_type = &vpip_scope_module_rt;
|
|
|
|
|
assert(0);
|
2001-10-15 04:58:27 +02:00
|
|
|
}
|
|
|
|
|
|
2001-11-02 06:43:11 +01:00
|
|
|
assert(scope->base.vpi_type);
|
|
|
|
|
|
2001-03-18 01:37:55 +01:00
|
|
|
scope->name = name;
|
|
|
|
|
scope->intern = 0;
|
|
|
|
|
scope->nintern = 0;
|
2001-04-18 06:21:23 +02:00
|
|
|
scope->threads = 0;
|
2001-03-18 01:37:55 +01:00
|
|
|
|
|
|
|
|
current_scope = scope;
|
|
|
|
|
|
2001-03-21 06:13:03 +01:00
|
|
|
compile_vpi_symbol(label, &scope->base);
|
2001-03-18 01:37:55 +01:00
|
|
|
free(label);
|
|
|
|
|
|
|
|
|
|
if (parent) {
|
2001-07-11 06:43:57 +02:00
|
|
|
static vpiHandle obj;
|
|
|
|
|
compile_vpi_lookup(&obj, parent);
|
|
|
|
|
assert(obj);
|
2001-03-21 06:13:03 +01:00
|
|
|
struct __vpiScope*sp = (struct __vpiScope*) obj;
|
2001-03-18 01:37:55 +01:00
|
|
|
attach_to_scope_(sp, &scope->base);
|
2001-10-15 03:49:50 +02:00
|
|
|
scope->scope = (struct __vpiScope*)obj;
|
|
|
|
|
} else {
|
|
|
|
|
scope->scope = 0x0;
|
2001-03-18 01:37:55 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void compile_scope_recall(char*symbol)
|
|
|
|
|
{
|
2001-07-11 06:43:57 +02:00
|
|
|
compile_vpi_lookup((vpiHandle*)¤t_scope, symbol);
|
|
|
|
|
assert(current_scope);
|
2001-03-18 01:37:55 +01:00
|
|
|
}
|
|
|
|
|
|
2001-04-18 06:21:23 +02:00
|
|
|
struct __vpiScope* vpip_peek_current_scope(void)
|
2001-03-18 01:37:55 +01:00
|
|
|
{
|
2001-04-18 06:21:23 +02:00
|
|
|
return current_scope;
|
2001-03-18 01:37:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void vpip_attach_to_current_scope(vpiHandle obj)
|
|
|
|
|
{
|
|
|
|
|
attach_to_scope_(current_scope, obj);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* $Log: vpi_scope.cc,v $
|
2001-11-02 06:43:11 +01:00
|
|
|
* Revision 1.10 2001/11/02 05:43:11 steve
|
|
|
|
|
* Comment the scope type parser.
|
|
|
|
|
*
|
2001-10-15 04:58:27 +02:00
|
|
|
* Revision 1.9 2001/10/15 02:58:27 steve
|
|
|
|
|
* Carry the type of the scope (Stephan Boettcher)
|
|
|
|
|
*
|
2001-10-15 03:49:50 +02:00
|
|
|
* Revision 1.8 2001/10/15 01:49:50 steve
|
|
|
|
|
* Support getting scope of scope, and scope of signals.
|
|
|
|
|
*
|
2001-09-15 20:27:04 +02:00
|
|
|
* Revision 1.7 2001/09/15 18:27:05 steve
|
|
|
|
|
* Make configure detect malloc.h
|
|
|
|
|
*
|
2001-07-11 06:43:57 +02:00
|
|
|
* Revision 1.6 2001/07/11 04:43:57 steve
|
|
|
|
|
* support postpone of $systask parameters. (Stephan Boettcher)
|
|
|
|
|
*
|
2001-06-10 18:47:49 +02:00
|
|
|
* Revision 1.5 2001/06/10 16:47:49 steve
|
|
|
|
|
* support scan of scope from VPI.
|
|
|
|
|
*
|
2001-04-18 06:21:23 +02:00
|
|
|
* Revision 1.4 2001/04/18 04:21:23 steve
|
|
|
|
|
* Put threads into scopes.
|
|
|
|
|
*
|
2001-04-03 05:46:14 +02:00
|
|
|
* Revision 1.3 2001/04/03 03:46:14 steve
|
|
|
|
|
* VPI access time as a decimal string, and
|
|
|
|
|
* stub vpi access to the scopes.
|
|
|
|
|
*
|
2001-03-21 06:13:03 +01:00
|
|
|
* Revision 1.2 2001/03/21 05:13:03 steve
|
|
|
|
|
* Allow var objects as vpiHandle arguments to %vpi_call.
|
|
|
|
|
*
|
2001-03-18 01:37:55 +01:00
|
|
|
* Revision 1.1 2001/03/18 00:37:55 steve
|
|
|
|
|
* Add support for vpi scopes.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|