Dynamic resizevpi result buf in more places.
This commit is contained in:
parent
2b06a293b6
commit
e1a4e27173
|
|
@ -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.16 2002/07/05 17:14:15 steve Exp $"
|
#ident "$Id: vpi_memory.cc,v 1.17 2002/07/09 03:24:37 steve Exp $"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
# include "vpi_priv.h"
|
# include "vpi_priv.h"
|
||||||
|
|
@ -40,7 +40,6 @@
|
||||||
# include <stdio.h>
|
# include <stdio.h>
|
||||||
|
|
||||||
extern const char hex_digits[256];
|
extern const char hex_digits[256];
|
||||||
extern char*need_result_buf(size_t, int);
|
|
||||||
|
|
||||||
static void memory_make_word_handles(struct __vpiMemory*rfp);
|
static void memory_make_word_handles(struct __vpiMemory*rfp);
|
||||||
|
|
||||||
|
|
@ -113,7 +112,7 @@ static char* memory_get_str(int code, vpiHandle ref)
|
||||||
char *bn = vpi_get_str(vpiFullName, &rfp->scope->base);
|
char *bn = vpi_get_str(vpiFullName, &rfp->scope->base);
|
||||||
char *nm = memory_name(rfp->mem);
|
char *nm = memory_name(rfp->mem);
|
||||||
|
|
||||||
char *rbuf = need_result_buf(strlen(bn) + strlen(nm) + 1, 1);
|
char *rbuf = need_result_buf(strlen(bn) + strlen(nm) + 1, RBUF_STR);
|
||||||
|
|
||||||
switch (code) {
|
switch (code) {
|
||||||
case vpiFullName:
|
case vpiFullName:
|
||||||
|
|
@ -348,7 +347,7 @@ static char* memory_word_get_str(int code, vpiHandle ref)
|
||||||
char *bn = vpi_get_str(vpiFullName, &rfp->mem->scope->base);
|
char *bn = vpi_get_str(vpiFullName, &rfp->mem->scope->base);
|
||||||
char *nm = memory_name(rfp->mem->mem);
|
char *nm = memory_name(rfp->mem->mem);
|
||||||
|
|
||||||
char *rbuf = need_result_buf(strlen(bn) + strlen(nm) + 1, 1);
|
char *rbuf = need_result_buf(strlen(bn) + strlen(nm) + 1, RBUF_STR);
|
||||||
|
|
||||||
switch (code) {
|
switch (code) {
|
||||||
case vpiFullName:
|
case vpiFullName:
|
||||||
|
|
@ -381,7 +380,7 @@ static void memory_word_get_value(vpiHandle ref, s_vpi_value*vp)
|
||||||
assert("format not implemented");
|
assert("format not implemented");
|
||||||
|
|
||||||
case vpiBinStrVal:
|
case vpiBinStrVal:
|
||||||
rbuf = need_result_buf(width+1, 0);
|
rbuf = need_result_buf(width+1, RBUF_VAL);
|
||||||
for (unsigned idx = 0 ; idx < width ; idx += 1) {
|
for (unsigned idx = 0 ; idx < width ; idx += 1) {
|
||||||
unsigned bit = memory_get(rfp->mem->mem, bidx+idx);
|
unsigned bit = memory_get(rfp->mem->mem, bidx+idx);
|
||||||
|
|
||||||
|
|
@ -405,7 +404,7 @@ static void memory_word_get_value(vpiHandle ref, s_vpi_value*vp)
|
||||||
bits[bb] |= val << bs;
|
bits[bb] |= val << bs;
|
||||||
}
|
}
|
||||||
|
|
||||||
rbuf = need_result_buf(hwid+1, 0);
|
rbuf = need_result_buf(hwid+1, RBUF_VAL);
|
||||||
vpip_bits_to_oct_str(bits, width, rbuf, hwid+1, false);
|
vpip_bits_to_oct_str(bits, width, rbuf, hwid+1, false);
|
||||||
|
|
||||||
delete[]bits;
|
delete[]bits;
|
||||||
|
|
@ -417,7 +416,7 @@ static void memory_word_get_value(vpiHandle ref, s_vpi_value*vp)
|
||||||
unsigned hval, hwid;
|
unsigned hval, hwid;
|
||||||
hwid = (width + 3) / 4;
|
hwid = (width + 3) / 4;
|
||||||
|
|
||||||
rbuf = need_result_buf(hwid+1, 0);
|
rbuf = need_result_buf(hwid+1, RBUF_VAL);
|
||||||
rbuf[hwid] = 0;
|
rbuf[hwid] = 0;
|
||||||
|
|
||||||
hval = 0;
|
hval = 0;
|
||||||
|
|
@ -458,7 +457,7 @@ static void memory_word_get_value(vpiHandle ref, s_vpi_value*vp)
|
||||||
for (unsigned idx = 0 ; idx < width ; idx += 1)
|
for (unsigned idx = 0 ; idx < width ; idx += 1)
|
||||||
bits[idx] = memory_get(rfp->mem->mem, bidx+idx);
|
bits[idx] = memory_get(rfp->mem->mem, bidx+idx);
|
||||||
|
|
||||||
rbuf = need_result_buf(width+1, 0);
|
rbuf = need_result_buf(width+1, RBUF_VAL);
|
||||||
vpip_bits_to_dec_str(bits, width, rbuf, width+1, false);
|
vpip_bits_to_dec_str(bits, width, rbuf, width+1, false);
|
||||||
|
|
||||||
delete[]bits;
|
delete[]bits;
|
||||||
|
|
@ -485,7 +484,7 @@ static void memory_word_get_value(vpiHandle ref, s_vpi_value*vp)
|
||||||
case vpiVectorVal: {
|
case vpiVectorVal: {
|
||||||
unsigned hwid = (width - 1)/32 + 1;
|
unsigned hwid = (width - 1)/32 + 1;
|
||||||
|
|
||||||
rbuf = need_result_buf(hwid * sizeof(s_vpi_vecval), 0);
|
rbuf = need_result_buf(hwid * sizeof(s_vpi_vecval), RBUF_VAL);
|
||||||
s_vpi_vecval *op = (p_vpi_vecval)rbuf;
|
s_vpi_vecval *op = (p_vpi_vecval)rbuf;
|
||||||
vp->value.vector = op;
|
vp->value.vector = op;
|
||||||
|
|
||||||
|
|
@ -581,6 +580,9 @@ vpiHandle vpip_make_memory(vvp_memory_t mem)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* $Log: vpi_memory.cc,v $
|
* $Log: vpi_memory.cc,v $
|
||||||
|
* Revision 1.17 2002/07/09 03:24:37 steve
|
||||||
|
* Dynamic resizevpi result buf in more places.
|
||||||
|
*
|
||||||
* Revision 1.16 2002/07/05 17:14:15 steve
|
* Revision 1.16 2002/07/05 17:14:15 steve
|
||||||
* Names of vpi objects allocated as vpip_strings.
|
* Names of vpi objects allocated as vpip_strings.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -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.38 2002/07/05 17:14:15 steve Exp $"
|
#ident "$Id: vpi_priv.h,v 1.39 2002/07/09 03:24:37 steve Exp $"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
# include "vpi_user.h"
|
# include "vpi_user.h"
|
||||||
|
|
@ -360,8 +360,23 @@ extern void vpip_bits_to_oct_str(const unsigned char*bits, unsigned nbits,
|
||||||
extern void vpip_oct_str_to_bits(unsigned char*bits, unsigned nbits,
|
extern void vpip_oct_str_to_bits(unsigned char*bits, unsigned nbits,
|
||||||
const char*buf, bool signed_flag);
|
const char*buf, bool signed_flag);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Function defined in vpi_signal.cc to manage vpi_get_* persistent
|
||||||
|
* storage.
|
||||||
|
*/
|
||||||
|
enum vpi_rbuf_t {
|
||||||
|
RBUF_VAL =0,
|
||||||
|
/* Storage for *_get_value() */
|
||||||
|
RBUF_STR
|
||||||
|
/* Storage for *_get_str() */
|
||||||
|
};
|
||||||
|
extern char *need_result_buf(unsigned cnt, vpi_rbuf_t type);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* $Log: vpi_priv.h,v $
|
* $Log: vpi_priv.h,v $
|
||||||
|
* Revision 1.39 2002/07/09 03:24:37 steve
|
||||||
|
* Dynamic resizevpi result buf in more places.
|
||||||
|
*
|
||||||
* Revision 1.38 2002/07/05 17:14:15 steve
|
* Revision 1.38 2002/07/05 17:14:15 steve
|
||||||
* Names of vpi objects allocated as vpip_strings.
|
* Names of vpi objects allocated as vpip_strings.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -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_signal.cc,v 1.41 2002/07/05 17:14:15 steve Exp $"
|
#ident "$Id: vpi_signal.cc,v 1.42 2002/07/09 03:24:37 steve Exp $"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -55,20 +55,19 @@ extern const char oct_digits[256];
|
||||||
* buffer can be reused for that purpose. Whenever I have a need, the
|
* buffer can be reused for that purpose. Whenever I have a need, the
|
||||||
* need_result_buf function makes sure that need can be met.
|
* need_result_buf function makes sure that need can be met.
|
||||||
*/
|
*/
|
||||||
char *need_result_buf(size_t cnt, int type)
|
char *need_result_buf(unsigned cnt, vpi_rbuf_t type)
|
||||||
{
|
{
|
||||||
static char*result_buf[2] = {0, 0};
|
static char*result_buf[2] = {0, 0};
|
||||||
static size_t result_buf_size[2] = {0, 0};
|
static size_t result_buf_size[2] = {0, 0};
|
||||||
int idx = type ? 1 : 0;
|
|
||||||
|
|
||||||
if (result_buf_size[idx] == 0) {
|
if (result_buf_size[type] == 0) {
|
||||||
result_buf[idx] = (char*)malloc(cnt);
|
result_buf[type] = (char*)malloc(cnt);
|
||||||
} else if (result_buf_size[idx] < cnt) {
|
} else if (result_buf_size[type] < cnt) {
|
||||||
result_buf[idx] = (char*)realloc(result_buf[idx], cnt);
|
result_buf[type] = (char*)realloc(result_buf[type], cnt);
|
||||||
}
|
}
|
||||||
result_buf_size[idx] = cnt;
|
result_buf_size[type] = cnt;
|
||||||
|
|
||||||
return result_buf[idx];
|
return result_buf[type];
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -113,7 +112,7 @@ static char* signal_get_str(int code, vpiHandle ref)
|
||||||
char *bn = vpi_get_str(vpiFullName, &rfp->scope->base);
|
char *bn = vpi_get_str(vpiFullName, &rfp->scope->base);
|
||||||
char *nm = (char*)rfp->name;
|
char *nm = (char*)rfp->name;
|
||||||
|
|
||||||
char *rbuf = need_result_buf(strlen(bn) + strlen(nm) + 1, 1);
|
char *rbuf = need_result_buf(strlen(bn) + strlen(nm) + 1, RBUF_STR);
|
||||||
|
|
||||||
switch (code) {
|
switch (code) {
|
||||||
|
|
||||||
|
|
@ -159,7 +158,7 @@ static char *signal_vpiDecStrVal(struct __vpiSignal*rfp, s_vpi_value*vp)
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned hwid = (wid+2) / 3 + 1;
|
unsigned hwid = (wid+2) / 3 + 1;
|
||||||
char *rbuf = need_result_buf(hwid, 0);
|
char *rbuf = need_result_buf(hwid, RBUF_VAL);
|
||||||
|
|
||||||
vpip_bits_to_dec_str(bits, wid, rbuf, hwid, rfp->signed_flag);
|
vpip_bits_to_dec_str(bits, wid, rbuf, hwid, rfp->signed_flag);
|
||||||
|
|
||||||
|
|
@ -179,7 +178,7 @@ static char *signal_vpiStringVal(struct __vpiSignal*rfp, s_vpi_value*vp)
|
||||||
/* The result will use a character for each 8 bits of the
|
/* The result will use a character for each 8 bits of the
|
||||||
vector. Add one extra character for the highest bits that
|
vector. Add one extra character for the highest bits that
|
||||||
don't form an 8 bit group. */
|
don't form an 8 bit group. */
|
||||||
char *rbuf = need_result_buf(wid/8 + ((wid&7)!=0) + 1, 0);
|
char *rbuf = need_result_buf(wid/8 + ((wid&7)!=0) + 1, RBUF_VAL);
|
||||||
char *cp = rbuf;
|
char *cp = rbuf;
|
||||||
|
|
||||||
char tmp = 0;
|
char tmp = 0;
|
||||||
|
|
@ -247,7 +246,7 @@ static void signal_get_value(vpiHandle ref, s_vpi_value*vp)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case vpiBinStrVal:
|
case vpiBinStrVal:
|
||||||
rbuf = need_result_buf(wid+1, 0);
|
rbuf = need_result_buf(wid+1, RBUF_VAL);
|
||||||
|
|
||||||
for (unsigned idx = 0 ; idx < wid ; idx += 1) {
|
for (unsigned idx = 0 ; idx < wid ; idx += 1) {
|
||||||
vvp_ipoint_t fptr = vvp_fvector_get(rfp->bits, idx);
|
vvp_ipoint_t fptr = vvp_fvector_get(rfp->bits, idx);
|
||||||
|
|
@ -261,7 +260,7 @@ static void signal_get_value(vpiHandle ref, s_vpi_value*vp)
|
||||||
unsigned hval, hwid;
|
unsigned hval, hwid;
|
||||||
hwid = (wid + 3) / 4;
|
hwid = (wid + 3) / 4;
|
||||||
|
|
||||||
rbuf = need_result_buf(hwid+1, 0);
|
rbuf = need_result_buf(hwid+1, RBUF_VAL);
|
||||||
rbuf[hwid] = 0;
|
rbuf[hwid] = 0;
|
||||||
hval = 0;
|
hval = 0;
|
||||||
for (unsigned idx = 0 ; idx < wid ; idx += 1) {
|
for (unsigned idx = 0 ; idx < wid ; idx += 1) {
|
||||||
|
|
@ -298,7 +297,7 @@ static void signal_get_value(vpiHandle ref, s_vpi_value*vp)
|
||||||
unsigned hval, hwid;
|
unsigned hval, hwid;
|
||||||
hwid = (wid + 2) / 3;
|
hwid = (wid + 2) / 3;
|
||||||
|
|
||||||
rbuf = need_result_buf(hwid+1, 0);
|
rbuf = need_result_buf(hwid+1, RBUF_VAL);
|
||||||
rbuf[hwid] = 0;
|
rbuf[hwid] = 0;
|
||||||
hval = 0;
|
hval = 0;
|
||||||
for (unsigned idx = 0 ; idx < wid ; idx += 1) {
|
for (unsigned idx = 0 ; idx < wid ; idx += 1) {
|
||||||
|
|
@ -343,7 +342,7 @@ static void signal_get_value(vpiHandle ref, s_vpi_value*vp)
|
||||||
unsigned int obit = 0;
|
unsigned int obit = 0;
|
||||||
unsigned hwid = (wid - 1)/32 + 1;
|
unsigned hwid = (wid - 1)/32 + 1;
|
||||||
|
|
||||||
rbuf = need_result_buf(hwid * sizeof(s_vpi_vecval), 0);
|
rbuf = need_result_buf(hwid * sizeof(s_vpi_vecval), RBUF_VAL);
|
||||||
s_vpi_vecval *op = (p_vpi_vecval)rbuf;
|
s_vpi_vecval *op = (p_vpi_vecval)rbuf;
|
||||||
vp->value.vector = op;
|
vp->value.vector = op;
|
||||||
|
|
||||||
|
|
@ -676,6 +675,9 @@ vpiHandle vpip_make_net(const char*name, int msb, int lsb,
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* $Log: vpi_signal.cc,v $
|
* $Log: vpi_signal.cc,v $
|
||||||
|
* Revision 1.42 2002/07/09 03:24:37 steve
|
||||||
|
* Dynamic resizevpi result buf in more places.
|
||||||
|
*
|
||||||
* Revision 1.41 2002/07/05 17:14:15 steve
|
* Revision 1.41 2002/07/05 17:14:15 steve
|
||||||
* Names of vpi objects allocated as vpip_strings.
|
* Names of vpi objects allocated as vpip_strings.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue