Full support for $readmem ranges (Tom Verbeure)
This commit is contained in:
parent
a624021a2e
commit
9fa0f95003
|
|
@ -17,7 +17,7 @@
|
||||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
||||||
*/
|
*/
|
||||||
#if !defined(WINNT) && !defined(macintosh)
|
#if !defined(WINNT) && !defined(macintosh)
|
||||||
#ident "$Id: sys_readmem.c,v 1.8 2001/12/01 02:40:10 steve Exp $"
|
#ident "$Id: sys_readmem.c,v 1.9 2002/01/31 04:28:17 steve Exp $"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
# include "config.h"
|
# include "config.h"
|
||||||
|
|
@ -29,11 +29,45 @@
|
||||||
# include <assert.h>
|
# include <assert.h>
|
||||||
# include "sys_readmem_lex.h"
|
# include "sys_readmem_lex.h"
|
||||||
|
|
||||||
|
static int check_integer_constant(char*name, vpiHandle handle)
|
||||||
|
{
|
||||||
|
if (vpi_get(vpiType, handle) != vpiConstant){
|
||||||
|
vpi_printf("ERROR: %s parameter must be a constant\n", name);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch(vpi_get(vpiConstType, handle)){
|
||||||
|
case vpiDecConst:
|
||||||
|
case vpiBinaryConst:
|
||||||
|
case vpiOctConst:
|
||||||
|
case vpiHexConst:
|
||||||
|
return 1;
|
||||||
|
break;
|
||||||
|
|
||||||
|
/* We rely on vpi_get_value for reals and strings to return a correct */
|
||||||
|
/* integer value when this is requested. So only a warning is generated. */
|
||||||
|
case vpiRealConst:
|
||||||
|
vpi_printf("Warning: real supplied to %s instead of integer.\n", name);
|
||||||
|
return 1;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case vpiStringConst:
|
||||||
|
vpi_printf("Warning: string supplied to %s instead of integer.\n", name);
|
||||||
|
return 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* switch statement covers all possibilities. Code should never come here... */
|
||||||
|
assert(0);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int sys_readmem_calltf(char*name)
|
static int sys_readmem_calltf(char*name)
|
||||||
{
|
{
|
||||||
int code;
|
int code;
|
||||||
int wwid;
|
int wwid;
|
||||||
char*path;
|
char*path;
|
||||||
|
char*mem_name;
|
||||||
FILE*file;
|
FILE*file;
|
||||||
unsigned addr;
|
unsigned addr;
|
||||||
s_vpi_value value;
|
s_vpi_value value;
|
||||||
|
|
@ -42,6 +76,28 @@ static int sys_readmem_calltf(char*name)
|
||||||
vpiHandle argv = vpi_iterate(vpiArgument, sys);
|
vpiHandle argv = vpi_iterate(vpiArgument, sys);
|
||||||
vpiHandle item = vpi_scan(argv);
|
vpiHandle item = vpi_scan(argv);
|
||||||
vpiHandle mitem;
|
vpiHandle mitem;
|
||||||
|
vpiHandle start_item;
|
||||||
|
vpiHandle stop_item;
|
||||||
|
vpiHandle left_range;
|
||||||
|
vpiHandle right_range;
|
||||||
|
vpiHandle word_index;
|
||||||
|
|
||||||
|
/* These are left and right hand side parameters in the
|
||||||
|
declaration of the memory. */
|
||||||
|
int left_addr, right_addr;
|
||||||
|
|
||||||
|
/* start_addr and stop_addr are the parameters given to $readmem in the
|
||||||
|
verilog code. When not specified, start_addr is equal to the lower of
|
||||||
|
the [left,right]_addr and stop_addr is equal to the higher of the
|
||||||
|
[left,right]_addr. */
|
||||||
|
int start_addr, stop_addr, addr_incr;
|
||||||
|
|
||||||
|
/* min_addr and max_addr are equal to start_addr and stop_addr if
|
||||||
|
start_addr<stop_addr or vice versa if not... */
|
||||||
|
int min_addr, max_addr;
|
||||||
|
|
||||||
|
|
||||||
|
/*======================================== Get parameters */
|
||||||
|
|
||||||
if (item == 0) {
|
if (item == 0) {
|
||||||
vpi_printf("%s: file name parameter missing.\n", name);
|
vpi_printf("%s: file name parameter missing.\n", name);
|
||||||
|
|
@ -55,7 +111,7 @@ static int sys_readmem_calltf(char*name)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vpi_get(vpiConstType, item) != vpiStringConst) {
|
if (vpi_get(vpiConstType, item) != vpiStringConst) {
|
||||||
vpi_printf("ERROR: %s parameter must be a constant\n", name);
|
vpi_printf("ERROR: %s parameter must be a string\n", name);
|
||||||
vpi_free_object(argv);
|
vpi_free_object(argv);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -64,7 +120,7 @@ static int sys_readmem_calltf(char*name)
|
||||||
vpi_get_value(item, &value);
|
vpi_get_value(item, &value);
|
||||||
path = strdup(value.value.str);
|
path = strdup(value.value.str);
|
||||||
|
|
||||||
/* Get and check the second paramter. It must be a memory. */
|
/* Get and check the second parameter. It must be a memory. */
|
||||||
mitem = vpi_scan(argv);
|
mitem = vpi_scan(argv);
|
||||||
if (mitem == 0) {
|
if (mitem == 0) {
|
||||||
vpi_printf("%s: Missing memory parameter\n", name);
|
vpi_printf("%s: Missing memory parameter\n", name);
|
||||||
|
|
@ -79,10 +135,40 @@ static int sys_readmem_calltf(char*name)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* XXXX remaining parameters not supported. */
|
mem_name = vpi_get_str(vpiFullName, mitem);
|
||||||
vpi_free_object(argv);
|
|
||||||
|
|
||||||
/* Open the data file. */
|
/* Get optional third parameter. It must be a constant. */
|
||||||
|
start_item = vpi_scan(argv);
|
||||||
|
if (start_item!=0){
|
||||||
|
if (check_integer_constant(name, start_item) == 0){
|
||||||
|
vpi_free_object(argv);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Get optional forth parameter. It must be a constant. */
|
||||||
|
stop_item = vpi_scan(argv);
|
||||||
|
if (stop_item!=0){
|
||||||
|
if (check_integer_constant(name, stop_item) == 0){
|
||||||
|
vpi_free_object(argv);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check that ther is no 5th parameter */
|
||||||
|
if (vpi_scan(argv) != 0){
|
||||||
|
vpi_printf("ERROR: %s accepts maximum 4 parameters!\n", name );
|
||||||
|
vpi_free_object(argv);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
stop_item = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*======================================== Process parameters */
|
||||||
|
|
||||||
|
/* Open the data file. */
|
||||||
file = fopen(path, "r");
|
file = fopen(path, "r");
|
||||||
if (file == 0) {
|
if (file == 0) {
|
||||||
vpi_printf("%s: Unable to open %s for reading.\n", name, path);
|
vpi_printf("%s: Unable to open %s for reading.\n", name, path);
|
||||||
|
|
@ -90,56 +176,128 @@ static int sys_readmem_calltf(char*name)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Get left addr of memory */
|
||||||
|
left_range = vpi_handle(vpiLeftRange, mitem);
|
||||||
|
value.format = vpiIntVal;
|
||||||
|
vpi_get_value(left_range, &value);
|
||||||
|
left_addr = value.value.integer;
|
||||||
|
|
||||||
|
/* Get right addr of memory */
|
||||||
|
right_range = vpi_handle(vpiRightRange, mitem);
|
||||||
|
value.format = vpiIntVal;
|
||||||
|
vpi_get_value(right_range, &value);
|
||||||
|
right_addr = value.value.integer;
|
||||||
|
|
||||||
|
/* Get start_addr, stop_addr and addr_incr */
|
||||||
|
if (start_item==0){
|
||||||
|
start_addr = left_addr<right_addr ? left_addr : right_addr;
|
||||||
|
stop_addr = left_addr<right_addr ? right_addr : left_addr;
|
||||||
|
addr_incr = 1;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
s_vpi_value value;
|
||||||
|
value.format = vpiIntVal;
|
||||||
|
vpi_get_value(start_item, &value);
|
||||||
|
start_addr = value.value.integer;
|
||||||
|
|
||||||
|
if (stop_item==0){
|
||||||
|
stop_addr = left_addr<right_addr ? right_addr : left_addr;
|
||||||
|
addr_incr = 1;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
s_vpi_value value;
|
||||||
|
value.format = vpiIntVal;
|
||||||
|
vpi_get_value(stop_item, &value);
|
||||||
|
stop_addr = value.value.integer;
|
||||||
|
|
||||||
|
addr_incr = start_addr<stop_addr ? 1 : -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
min_addr = start_addr<stop_addr ? start_addr : stop_addr ;
|
||||||
|
max_addr = start_addr<stop_addr ? stop_addr : start_addr;
|
||||||
|
|
||||||
|
/* Check that start_addr and stop_addr are within the memory
|
||||||
|
range */
|
||||||
|
if (left_addr<right_addr){
|
||||||
|
if (start_addr<left_addr || start_addr > right_addr) {
|
||||||
|
vpi_printf("%s: Start address is out of bounds for memory \'%s\'!\n", name, mem_name);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stop_addr<left_addr || stop_addr > right_addr) {
|
||||||
|
vpi_printf("%s: Stop address is out of bounds for memory \'%s\'!\n", name, mem_name);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
if (start_addr<right_addr || start_addr > left_addr) {
|
||||||
|
vpi_printf("%s: Start address is out of bounds for memory \'%s\'!\n", name, mem_name);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stop_addr<right_addr || stop_addr > left_addr) {
|
||||||
|
vpi_printf("%s: Stop address is out of bounds for memory \'%s\'!\n", name, mem_name);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
words = vpi_iterate(vpiMemoryWord, mitem);
|
words = vpi_iterate(vpiMemoryWord, mitem);
|
||||||
assert(words);
|
assert(words);
|
||||||
|
|
||||||
item = vpi_scan(words);
|
item = vpi_scan(words);
|
||||||
wwid = vpi_get(vpiSize, item);
|
wwid = vpi_get(vpiSize, item);
|
||||||
|
|
||||||
|
/* variable that will be uses by the lexer to pass values
|
||||||
|
back to this code */
|
||||||
value.format = vpiVectorVal;
|
value.format = vpiVectorVal;
|
||||||
value.value.vector = calloc((wwid+31)/32, sizeof (s_vpi_vecval));
|
value.value.vector = calloc((wwid+31)/32, sizeof(s_vpi_vecval));
|
||||||
|
|
||||||
|
/* Configure the readmem lexer */
|
||||||
if (strcmp(name,"$readmemb") == 0)
|
if (strcmp(name,"$readmemb") == 0)
|
||||||
sys_readmem_start_file(file, 1, wwid, value.value.vector);
|
sys_readmem_start_file(file, 1, wwid, value.value.vector);
|
||||||
else
|
else
|
||||||
sys_readmem_start_file(file, 0, wwid, value.value.vector);
|
sys_readmem_start_file(file, 0, wwid, value.value.vector);
|
||||||
|
|
||||||
addr = 0;
|
|
||||||
|
|
||||||
|
/*======================================== Read memory file */
|
||||||
|
|
||||||
|
/* Run through the input file and store the new contents in the memory */
|
||||||
|
addr = start_addr;
|
||||||
while ((code = readmemlex()) != 0) {
|
while ((code = readmemlex()) != 0) {
|
||||||
switch (code) {
|
switch (code) {
|
||||||
case MEM_ADDRESS:
|
case MEM_ADDRESS:
|
||||||
if (addr > value.value.vector->aval) {
|
addr = value.value.vector->aval;
|
||||||
vpi_free_object(words);
|
break;
|
||||||
words = vpi_iterate(vpiMemoryWord, mitem);
|
|
||||||
item = vpi_scan(words);
|
case MEM_WORD:
|
||||||
addr = 0;
|
if (addr >= min_addr && addr <= max_addr){
|
||||||
}
|
word_index = vpi_handle_by_index(mitem, addr);
|
||||||
while (item && addr < value.value.vector->aval) {
|
assert(word_index);
|
||||||
item = vpi_scan(words);
|
vpi_put_value(word_index, &value, 0, vpiNoDelay);
|
||||||
addr += 1;
|
}
|
||||||
}
|
else{
|
||||||
break;
|
vpi_printf("%s(%s): address (0x%x) out of range (0x%x:0x%x)\n",
|
||||||
case MEM_WORD:
|
name, path, addr, start_addr, stop_addr);
|
||||||
if (item) {
|
goto bailout;
|
||||||
vpi_put_value(item, &value, 0, vpiNoDelay);
|
}
|
||||||
item = vpi_scan(words);
|
|
||||||
addr += 1;
|
addr += addr_incr;
|
||||||
} else {
|
break;
|
||||||
vpi_printf("%s(%s): too much data (addr=0x%x)\n",
|
|
||||||
name, path, addr);
|
default:
|
||||||
goto bailout;
|
vpi_printf("Huh?! (%d)\n", code);
|
||||||
}
|
break;
|
||||||
break;
|
}
|
||||||
default:
|
|
||||||
vpi_printf("Huh?! (%d)\n", code);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bailout:
|
bailout:
|
||||||
if (item) vpi_free_object(words);
|
|
||||||
free(path);
|
|
||||||
free(value.value.vector);
|
free(value.value.vector);
|
||||||
|
|
||||||
|
if (item)
|
||||||
|
vpi_free_object(words);
|
||||||
|
free(path);
|
||||||
fclose(file);
|
fclose(file);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -177,7 +335,7 @@ static int sys_writemem_calltf(char*name)
|
||||||
vpi_get_value(item, &value);
|
vpi_get_value(item, &value);
|
||||||
path = strdup(value.value.str);
|
path = strdup(value.value.str);
|
||||||
|
|
||||||
/* Get and check the second paramter. It must be a memory. */
|
/* Get and check the second parameter. It must be a memory. */
|
||||||
item = vpi_scan(argv);
|
item = vpi_scan(argv);
|
||||||
if (item == 0) {
|
if (item == 0) {
|
||||||
vpi_printf("%s: Missing memory parameter\n", name);
|
vpi_printf("%s: Missing memory parameter\n", name);
|
||||||
|
|
@ -253,6 +411,9 @@ void sys_readmem_register()
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* $Log: sys_readmem.c,v $
|
* $Log: sys_readmem.c,v $
|
||||||
|
* Revision 1.9 2002/01/31 04:28:17 steve
|
||||||
|
* Full support for $readmem ranges (Tom Verbeure)
|
||||||
|
*
|
||||||
* Revision 1.8 2001/12/01 02:40:10 steve
|
* Revision 1.8 2001/12/01 02:40:10 steve
|
||||||
* Support addresses in readmemh.
|
* Support addresses in readmemh.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@
|
||||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
||||||
*/
|
*/
|
||||||
#if !defined(WINNT)
|
#if !defined(WINNT)
|
||||||
#ident "$Id: memory.cc,v 1.14 2001/12/06 03:31:24 steve Exp $"
|
#ident "$Id: memory.cc,v 1.15 2002/01/31 04:28:17 steve Exp $"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
|
|
@ -63,6 +63,10 @@ struct vvp_memory_index_s
|
||||||
{
|
{
|
||||||
int first; // first memory address
|
int first; // first memory address
|
||||||
unsigned size; // number of valid addresses
|
unsigned size; // number of valid addresses
|
||||||
|
|
||||||
|
// Added to correctly support vpiLeftRange and vpiRightRange
|
||||||
|
int left;
|
||||||
|
int right;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct vvp_memory_port_s : public functor_s
|
struct vvp_memory_port_s : public functor_s
|
||||||
|
|
@ -95,6 +99,30 @@ unsigned memory_root(vvp_memory_t mem, unsigned ix)
|
||||||
return mem->a_idx[ix].first;
|
return mem->a_idx[ix].first;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned memory_left_range(vvp_memory_t mem, unsigned ix)
|
||||||
|
{
|
||||||
|
if (ix >= mem->a_idxs)
|
||||||
|
return 0;
|
||||||
|
return mem->a_idx[ix].left;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned memory_right_range(vvp_memory_t mem, unsigned ix)
|
||||||
|
{
|
||||||
|
if (ix >= mem->a_idxs)
|
||||||
|
return 0;
|
||||||
|
return mem->a_idx[ix].right;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned memory_word_left_range(vvp_memory_t mem)
|
||||||
|
{
|
||||||
|
return mem->msb;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned memory_word_right_range(vvp_memory_t mem)
|
||||||
|
{
|
||||||
|
return mem->lsb;
|
||||||
|
}
|
||||||
|
|
||||||
char *memory_name(vvp_memory_t mem)
|
char *memory_name(vvp_memory_t mem)
|
||||||
{
|
{
|
||||||
return mem->name;
|
return mem->name;
|
||||||
|
|
@ -146,6 +174,10 @@ void memory_new(vvp_memory_t mem, char *name, int msb, int lsb,
|
||||||
vvp_memory_index_t x = mem->a_idx + i;
|
vvp_memory_index_t x = mem->a_idx + i;
|
||||||
int msw = *(idx++);
|
int msw = *(idx++);
|
||||||
int lsw = *(idx++);
|
int lsw = *(idx++);
|
||||||
|
|
||||||
|
x->left = msw;
|
||||||
|
x->right = lsw;
|
||||||
|
|
||||||
if (msw > lsw) {
|
if (msw > lsw) {
|
||||||
x->size = msw - lsw + 1;
|
x->size = msw - lsw + 1;
|
||||||
x->first = lsw;
|
x->first = lsw;
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@
|
||||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
||||||
*/
|
*/
|
||||||
#if !defined(WINNT)
|
#if !defined(WINNT)
|
||||||
#ident "$Id: memory.h,v 1.4 2001/10/31 04:27:47 steve Exp $"
|
#ident "$Id: memory.h,v 1.5 2002/01/31 04:28:17 steve Exp $"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "pointers.h"
|
#include "pointers.h"
|
||||||
|
|
@ -52,6 +52,10 @@ unsigned memory_size(vvp_memory_t mem);
|
||||||
char *memory_name(vvp_memory_t mem);
|
char *memory_name(vvp_memory_t mem);
|
||||||
unsigned memory_data_width(vvp_memory_t mem);
|
unsigned memory_data_width(vvp_memory_t mem);
|
||||||
unsigned memory_root(vvp_memory_t mem, unsigned ix = 0);
|
unsigned memory_root(vvp_memory_t mem, unsigned ix = 0);
|
||||||
|
unsigned memory_left_range(vvp_memory_t mem, unsigned ix = 0);
|
||||||
|
unsigned memory_right_range(vvp_memory_t mem, unsigned ix = 0);
|
||||||
|
unsigned memory_word_left_range(vvp_memory_t mem);
|
||||||
|
unsigned memory_word_right_range(vvp_memory_t mem);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Access to the memory symbol table.
|
** Access to the memory symbol table.
|
||||||
|
|
@ -61,6 +65,9 @@ vvp_memory_t memory_create(char *label);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* $Log: memory.h,v $
|
* $Log: memory.h,v $
|
||||||
|
* Revision 1.5 2002/01/31 04:28:17 steve
|
||||||
|
* Full support for $readmem ranges (Tom Verbeure)
|
||||||
|
*
|
||||||
* Revision 1.4 2001/10/31 04:27:47 steve
|
* Revision 1.4 2001/10/31 04:27:47 steve
|
||||||
* Rewrite the functor type to have fewer functor modes,
|
* Rewrite the functor type to have fewer functor modes,
|
||||||
* and use objects to manage the different types.
|
* and use objects to manage the different types.
|
||||||
|
|
|
||||||
106
vvp/vpi_const.cc
106
vvp/vpi_const.cc
|
|
@ -17,7 +17,7 @@
|
||||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
||||||
*/
|
*/
|
||||||
#if !defined(WINNT)
|
#if !defined(WINNT)
|
||||||
#ident "$Id: vpi_const.cc,v 1.9 2002/01/25 03:24:19 steve Exp $"
|
#ident "$Id: vpi_const.cc,v 1.10 2002/01/31 04:28:17 steve Exp $"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
# include "vpi_priv.h"
|
# include "vpi_priv.h"
|
||||||
|
|
@ -336,10 +336,110 @@ vpiHandle vpip_make_binary_const(unsigned wid, char*bits)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static int dec_get(int code, vpiHandle ref)
|
||||||
|
{
|
||||||
|
|
||||||
|
switch (code) {
|
||||||
|
case vpiConstType:
|
||||||
|
return vpiDecConst;
|
||||||
|
|
||||||
|
case vpiSigned:
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
case vpiSize:
|
||||||
|
return 32;
|
||||||
|
|
||||||
|
default:
|
||||||
|
fprintf(stderr, "vvp error: get %d not supported "
|
||||||
|
"by vpiDecConst\n", code);
|
||||||
|
assert(0);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void dec_value(vpiHandle ref, p_vpi_value vp)
|
||||||
|
{
|
||||||
|
struct __vpiDecConst*rfp = (struct __vpiDecConst*)ref;
|
||||||
|
char* cp;
|
||||||
|
assert(ref->vpi_type->type_code == vpiConstant);
|
||||||
|
|
||||||
|
switch (vp->format) {
|
||||||
|
|
||||||
|
case vpiObjTypeVal:
|
||||||
|
case vpiIntVal: {
|
||||||
|
vp->value.integer = rfp->value;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case vpiDecStrVal:
|
||||||
|
sprintf(buf, "%d", rfp->value);
|
||||||
|
|
||||||
|
vp->format = vpiDecStrVal;
|
||||||
|
vp->value.str = buf;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case vpiBinStrVal:
|
||||||
|
cp = buf;
|
||||||
|
for(int bit=31; bit<=0;bit--){
|
||||||
|
*cp++ = "01"[ (rfp->value>>bit)&1 ];
|
||||||
|
}
|
||||||
|
*cp = 0;
|
||||||
|
|
||||||
|
vp->format = vpiBinStrVal;
|
||||||
|
vp->value.str = buf;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case vpiHexStrVal:
|
||||||
|
sprintf(buf, "%08x", rfp->value);
|
||||||
|
|
||||||
|
vp->format = vpiHexStrVal;
|
||||||
|
vp->value.str = buf;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case vpiOctStrVal:
|
||||||
|
sprintf(buf, "%011x", rfp->value);
|
||||||
|
|
||||||
|
vp->format = vpiOctStrVal;
|
||||||
|
vp->value.str = buf;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
fprintf(stderr, "vvp error (vpi_const.cc): format %d not supported "
|
||||||
|
"by vpiDecConst\n", vp->format);
|
||||||
|
vp->format = vpiSuppressVal;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static const struct __vpirt vpip_dec_rt = {
|
||||||
|
vpiConstant,
|
||||||
|
dec_get,
|
||||||
|
0,
|
||||||
|
dec_value,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0
|
||||||
|
};
|
||||||
|
|
||||||
|
vpiHandle vpip_make_dec_const(int value)
|
||||||
|
{
|
||||||
|
struct __vpiDecConst*obj;
|
||||||
|
|
||||||
|
obj = (struct __vpiDecConst*)
|
||||||
|
malloc(sizeof (struct __vpiDecConst));
|
||||||
|
obj->base.vpi_type = &vpip_dec_rt;
|
||||||
|
obj->value = value;
|
||||||
|
|
||||||
|
return &(obj->base);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* $Log: vpi_const.cc,v $
|
* $Log: vpi_const.cc,v $
|
||||||
* Revision 1.9 2002/01/25 03:24:19 steve
|
* Revision 1.10 2002/01/31 04:28:17 steve
|
||||||
* Support display of strings with umber formats. (Tom Verbeure)
|
* Full support for $readmem ranges (Tom Verbeure)
|
||||||
*
|
*
|
||||||
* Revision 1.8 2002/01/15 03:21:18 steve
|
* Revision 1.8 2002/01/15 03:21:18 steve
|
||||||
* Support DesSTrVal for binary constants.
|
* Support DesSTrVal for binary constants.
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@
|
||||||
* Picture Elements, Inc., 777 Panoramic Way, Berkeley, CA 94704.
|
* Picture Elements, Inc., 777 Panoramic Way, Berkeley, CA 94704.
|
||||||
*/
|
*/
|
||||||
#if !defined(WINNT) && !defined(macintosh)
|
#if !defined(WINNT) && !defined(macintosh)
|
||||||
#ident "$Id: vpi_memory.cc,v 1.3 2001/12/07 23:23:05 steve Exp $"
|
#ident "$Id: vpi_memory.cc,v 1.4 2002/01/31 04:28:17 steve Exp $"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
# include "vpi_priv.h"
|
# include "vpi_priv.h"
|
||||||
|
|
@ -40,6 +40,8 @@ struct __vpiMemoryWord {
|
||||||
struct __vpiHandle base;
|
struct __vpiHandle base;
|
||||||
struct __vpiMemory*mem;
|
struct __vpiMemory*mem;
|
||||||
int index;
|
int index;
|
||||||
|
struct __vpiDecConst*left_range;
|
||||||
|
struct __vpiDecConst*right_range;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct __vpiMemory {
|
struct __vpiMemory {
|
||||||
|
|
@ -47,8 +49,28 @@ struct __vpiMemory {
|
||||||
/* The signal has a name (this points to static memory.) */
|
/* The signal has a name (this points to static memory.) */
|
||||||
struct __vpiMemoryWord word;
|
struct __vpiMemoryWord word;
|
||||||
vvp_memory_t mem;
|
vvp_memory_t mem;
|
||||||
|
struct __vpiDecConst*left_range;
|
||||||
|
struct __vpiDecConst*right_range;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static vpiHandle memory_get_handle(int code, vpiHandle obj)
|
||||||
|
{
|
||||||
|
struct __vpiMemory*rfp = (struct __vpiMemory*)obj;
|
||||||
|
|
||||||
|
assert(obj->vpi_type->type_code==vpiMemory);
|
||||||
|
|
||||||
|
switch(code){
|
||||||
|
case vpiLeftRange:
|
||||||
|
return &(rfp->left_range->base);
|
||||||
|
|
||||||
|
case vpiRightRange:
|
||||||
|
return &(rfp->right_range->base);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int vpi_memory_get(int code, vpiHandle ref)
|
static int vpi_memory_get(int code, vpiHandle ref)
|
||||||
{
|
{
|
||||||
struct __vpiMemory*rfp = (struct __vpiMemory*)ref;
|
struct __vpiMemory*rfp = (struct __vpiMemory*)ref;
|
||||||
|
|
@ -139,6 +161,25 @@ static vpiHandle memory_index(vpiHandle ref, int index)
|
||||||
return &rfp->word.base;
|
return &rfp->word.base;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//==============================
|
||||||
|
|
||||||
|
static vpiHandle memory_word_get_handle(int code, vpiHandle obj)
|
||||||
|
{
|
||||||
|
struct __vpiMemoryWord*rfp = (struct __vpiMemoryWord*)obj;
|
||||||
|
|
||||||
|
assert(obj->vpi_type->type_code==vpiMemoryWord);
|
||||||
|
|
||||||
|
switch(code){
|
||||||
|
case vpiLeftRange:
|
||||||
|
return &(rfp->left_range->base);
|
||||||
|
|
||||||
|
case vpiRightRange:
|
||||||
|
return &(rfp->right_range->base);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int memory_word_get(int code, vpiHandle ref)
|
static int memory_word_get(int code, vpiHandle ref)
|
||||||
{
|
{
|
||||||
struct __vpiMemoryWord*rfp = (struct __vpiMemoryWord*)ref;
|
struct __vpiMemoryWord*rfp = (struct __vpiMemoryWord*)ref;
|
||||||
|
|
@ -234,7 +275,7 @@ static const struct __vpirt vpip_memory_rt = {
|
||||||
memory_get_str,
|
memory_get_str,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
0,
|
memory_get_handle,
|
||||||
memory_iterate,
|
memory_iterate,
|
||||||
memory_index,
|
memory_index,
|
||||||
};
|
};
|
||||||
|
|
@ -245,7 +286,7 @@ static const struct __vpirt vpip_memory_word_rt = {
|
||||||
0,
|
0,
|
||||||
memory_word_get_value,
|
memory_word_get_value,
|
||||||
memory_word_put,
|
memory_word_put,
|
||||||
0,
|
memory_word_get_handle,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
};
|
};
|
||||||
|
|
@ -256,15 +297,23 @@ vpiHandle vpip_make_memory(vvp_memory_t mem)
|
||||||
malloc(sizeof(struct __vpiMemory));
|
malloc(sizeof(struct __vpiMemory));
|
||||||
|
|
||||||
obj->base.vpi_type = &vpip_memory_rt;
|
obj->base.vpi_type = &vpip_memory_rt;
|
||||||
obj->word.base.vpi_type = &vpip_memory_word_rt;
|
|
||||||
obj->mem = mem;
|
obj->mem = mem;
|
||||||
|
obj->left_range = (struct __vpiDecConst*)vpip_make_dec_const(memory_left_range(mem));
|
||||||
|
obj->right_range = (struct __vpiDecConst*)vpip_make_dec_const(memory_right_range(mem));
|
||||||
|
|
||||||
|
obj->word.base.vpi_type = &vpip_memory_word_rt;
|
||||||
obj->word.mem = obj;
|
obj->word.mem = obj;
|
||||||
|
obj->word.left_range = (struct __vpiDecConst*)vpip_make_dec_const(memory_word_left_range(mem));
|
||||||
|
obj->word.right_range = (struct __vpiDecConst*)vpip_make_dec_const(memory_word_right_range(mem));
|
||||||
|
|
||||||
return &(obj->base);
|
return &(obj->base);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* $Log: vpi_memory.cc,v $
|
* $Log: vpi_memory.cc,v $
|
||||||
|
* Revision 1.4 2002/01/31 04:28:17 steve
|
||||||
|
* Full support for $readmem ranges (Tom Verbeure)
|
||||||
|
*
|
||||||
* Revision 1.3 2001/12/07 23:23:05 steve
|
* Revision 1.3 2001/12/07 23:23:05 steve
|
||||||
* vpi_put_value of vpiIntVal for memory words.
|
* vpi_put_value of vpiIntVal for memory words.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@
|
||||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
||||||
*/
|
*/
|
||||||
#if !defined(WINNT)
|
#if !defined(WINNT)
|
||||||
#ident "$Id: vpi_priv.h,v 1.26 2002/01/06 17:50:50 steve Exp $"
|
#ident "$Id: vpi_priv.h,v 1.27 2002/01/31 04:28:17 steve Exp $"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
# include "vpi_user.h"
|
# include "vpi_user.h"
|
||||||
|
|
@ -183,6 +183,13 @@ struct __vpiBinaryConst {
|
||||||
|
|
||||||
vpiHandle vpip_make_binary_const(unsigned wid, char*bits);
|
vpiHandle vpip_make_binary_const(unsigned wid, char*bits);
|
||||||
|
|
||||||
|
struct __vpiDecConst {
|
||||||
|
struct __vpiHandle base;
|
||||||
|
int value;
|
||||||
|
};
|
||||||
|
|
||||||
|
vpiHandle vpip_make_dec_const(int value);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This one looks like a constant, but really is a vector in the current
|
* This one looks like a constant, but really is a vector in the current
|
||||||
* thread.
|
* thread.
|
||||||
|
|
@ -250,6 +257,9 @@ extern void functor_set_scope(vpiHandle scope);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* $Log: vpi_priv.h,v $
|
* $Log: vpi_priv.h,v $
|
||||||
|
* Revision 1.27 2002/01/31 04:28:17 steve
|
||||||
|
* Full support for $readmem ranges (Tom Verbeure)
|
||||||
|
*
|
||||||
* Revision 1.26 2002/01/06 17:50:50 steve
|
* Revision 1.26 2002/01/06 17:50:50 steve
|
||||||
* Support scope for functors. (Stephan Boettcher)
|
* Support scope for functors. (Stephan Boettcher)
|
||||||
*
|
*
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue