Skip to content

Commit

Permalink
Dynamic resizevpi result buf in more places.
Browse files Browse the repository at this point in the history
  • Loading branch information
steve committed Jul 9, 2002
1 parent 2b06a29 commit e1a4e27
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 26 deletions.
20 changes: 11 additions & 9 deletions vvp/vpi_memory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
* Picture Elements, Inc., 777 Panoramic Way, Berkeley, CA 94704.
*/
#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

# include "vpi_priv.h"
Expand All @@ -40,7 +40,6 @@
# include <stdio.h>

extern const char hex_digits[256];
extern char*need_result_buf(size_t, int);

static void memory_make_word_handles(struct __vpiMemory*rfp);

Expand Down Expand Up @@ -113,7 +112,7 @@ static char* memory_get_str(int code, vpiHandle ref)
char *bn = vpi_get_str(vpiFullName, &rfp->scope->base);
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) {
case vpiFullName:
Expand Down Expand Up @@ -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 *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) {
case vpiFullName:
Expand Down Expand Up @@ -381,7 +380,7 @@ static void memory_word_get_value(vpiHandle ref, s_vpi_value*vp)
assert("format not implemented");

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) {
unsigned bit = memory_get(rfp->mem->mem, bidx+idx);

Expand All @@ -405,7 +404,7 @@ static void memory_word_get_value(vpiHandle ref, s_vpi_value*vp)
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);

delete[]bits;
Expand All @@ -417,7 +416,7 @@ static void memory_word_get_value(vpiHandle ref, s_vpi_value*vp)
unsigned hval, hwid;
hwid = (width + 3) / 4;

rbuf = need_result_buf(hwid+1, 0);
rbuf = need_result_buf(hwid+1, RBUF_VAL);
rbuf[hwid] = 0;

hval = 0;
Expand Down Expand Up @@ -458,7 +457,7 @@ static void memory_word_get_value(vpiHandle ref, s_vpi_value*vp)
for (unsigned idx = 0 ; idx < width ; idx += 1)
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);

delete[]bits;
Expand All @@ -485,7 +484,7 @@ static void memory_word_get_value(vpiHandle ref, s_vpi_value*vp)
case vpiVectorVal: {
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;
vp->value.vector = op;

Expand Down Expand Up @@ -581,6 +580,9 @@ vpiHandle vpip_make_memory(vvp_memory_t mem)

/*
* $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
* Names of vpi objects allocated as vpip_strings.
*
Expand Down
17 changes: 16 additions & 1 deletion vvp/vpi_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#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

# include "vpi_user.h"
Expand Down Expand Up @@ -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,
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 $
* 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
* Names of vpi objects allocated as vpip_strings.
*
Expand Down
34 changes: 18 additions & 16 deletions vvp/vpi_signal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#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

/*
Expand Down Expand Up @@ -55,20 +55,19 @@ extern const char oct_digits[256];
* buffer can be reused for that purpose. Whenever I have a need, the
* 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 size_t result_buf_size[2] = {0, 0};
int idx = type ? 1 : 0;

if (result_buf_size[idx] == 0) {
result_buf[idx] = (char*)malloc(cnt);
} else if (result_buf_size[idx] < cnt) {
result_buf[idx] = (char*)realloc(result_buf[idx], cnt);
if (result_buf_size[type] == 0) {
result_buf[type] = (char*)malloc(cnt);
} else if (result_buf_size[type] < 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];
}

/*
Expand Down Expand Up @@ -113,7 +112,7 @@ static char* signal_get_str(int code, vpiHandle ref)
char *bn = vpi_get_str(vpiFullName, &rfp->scope->base);
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) {

Expand Down Expand Up @@ -159,7 +158,7 @@ static char *signal_vpiDecStrVal(struct __vpiSignal*rfp, s_vpi_value*vp)
}

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);

Expand All @@ -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
vector. Add one extra character for the highest bits that
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 tmp = 0;
Expand Down Expand Up @@ -247,7 +246,7 @@ static void signal_get_value(vpiHandle ref, s_vpi_value*vp)
break;

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) {
vvp_ipoint_t fptr = vvp_fvector_get(rfp->bits, idx);
Expand All @@ -261,7 +260,7 @@ static void signal_get_value(vpiHandle ref, s_vpi_value*vp)
unsigned hval, hwid;
hwid = (wid + 3) / 4;

rbuf = need_result_buf(hwid+1, 0);
rbuf = need_result_buf(hwid+1, RBUF_VAL);
rbuf[hwid] = 0;
hval = 0;
for (unsigned idx = 0 ; idx < wid ; idx += 1) {
Expand Down Expand Up @@ -298,7 +297,7 @@ static void signal_get_value(vpiHandle ref, s_vpi_value*vp)
unsigned hval, hwid;
hwid = (wid + 2) / 3;

rbuf = need_result_buf(hwid+1, 0);
rbuf = need_result_buf(hwid+1, RBUF_VAL);
rbuf[hwid] = 0;
hval = 0;
for (unsigned idx = 0 ; idx < wid ; idx += 1) {
Expand Down Expand Up @@ -343,7 +342,7 @@ static void signal_get_value(vpiHandle ref, s_vpi_value*vp)
unsigned int obit = 0;
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;
vp->value.vector = op;

Expand Down Expand Up @@ -676,6 +675,9 @@ vpiHandle vpip_make_net(const char*name, int msb, int lsb,

/*
* $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
* Names of vpi objects allocated as vpip_strings.
*
Expand Down

0 comments on commit e1a4e27

Please sign in to comment.