General cleanup of the __vpiHandle class work.

This commit is contained in:
Stephen Williams 2012-01-20 17:16:42 -08:00
parent d6dba0456c
commit 43e11574e1
7 changed files with 411 additions and 685 deletions

View File

@ -113,8 +113,6 @@ struct __vpiArray : public __vpiHandle {
struct __vpiArrayIterator : public __vpiHandle {
__vpiArrayIterator();
int get_type_code(void) const;
int vpi_get(int code);
char* vpi_get_str(int code);
vpiHandle vpi_index(int idx);
free_object_fun_t free_object_fun(void);
@ -125,8 +123,6 @@ struct __vpiArrayIterator : public __vpiHandle {
struct __vpiArrayIndex : public __vpiHandle {
__vpiArrayIndex();
int get_type_code(void) const;
int vpi_get(int code);
char* vpi_get_str(int code);
vpiHandle vpi_iterate(int code);
vpiHandle vpi_index(int idx);
free_object_fun_t free_object_fun(void);
@ -300,12 +296,7 @@ struct __vpiArrayWord {
};
};
static int vpi_array_get(int code, vpiHandle ref);
static char*vpi_array_get_str(int code, vpiHandle ref);
static vpiHandle vpi_array_get_handle(int code, vpiHandle ref);
static vpiHandle vpi_array_iterate(int code, vpiHandle ref);
static vpiHandle vpi_array_index(vpiHandle ref, int index);
static void array_make_vals_words(struct __vpiArray*parent);
static vpiHandle array_iterator_scan(vpiHandle ref, int);
static int array_iterator_free_object(vpiHandle ref);
@ -338,19 +329,92 @@ int __vpiArray::get_type_code(void) const
{ return vpiMemory; }
int __vpiArray::vpi_get(int code)
{ return vpi_array_get(code, this); }
{
switch (code) {
case vpiLineNo:
return 0; // Not implemented for now!
case vpiSize:
return (int) array_count;
case vpiAutomatic:
return (int) scope->is_automatic;
default:
return 0;
}
}
char* __vpiArray::vpi_get_str(int code)
{ return vpi_array_get_str(code, this); }
{
if (code == vpiFile) { // Not implemented for now!
return simple_set_rbuf_str(file_names[0]);
}
return generic_get_str(code, scope, name, NULL);
}
vpiHandle __vpiArray::vpi_handle(int code)
{ return vpi_array_get_handle(code, this); }
{
switch (code) {
case vpiLeftRange:
if (swap_addr) return &last_addr;
else return &first_addr;
case vpiRightRange:
if (swap_addr) return &first_addr;
else return &last_addr;
case vpiScope:
return scope;
case vpiModule:
return vpip_module(scope);
}
return 0;
}
vpiHandle __vpiArray::vpi_iterate(int code)
{ return vpi_array_iterate(code, this); }
{
switch (code) {
case vpiMemoryWord: {
struct __vpiArrayIterator*res;
res = new __vpiArrayIterator;
res->array = this;
res->next = 0;
return res;
}
}
return 0;
}
/*
* VPI code passes indices that are not yet converted to canonical
* form, so this index function does it here.
*/
vpiHandle __vpiArray::vpi_index(int index)
{
index -= first_addr.value;
if (index >= (long)array_count)
return 0;
if (index < 0)
return 0;
if (nets != 0) {
return nets[index];
}
if (vals_words == 0)
array_make_vals_words(this);
return &(vals_words[index].as_word);
}
vpiHandle __vpiArray::vpi_index(int idx)
{ return vpi_array_index(this, idx); }
inline __vpiArrayIterator::__vpiArrayIterator()
{ }
@ -358,14 +422,25 @@ inline __vpiArrayIterator::__vpiArrayIterator()
int __vpiArrayIterator::get_type_code(void) const
{ return vpiIterator; }
int __vpiArrayIterator::vpi_get(int)
{ return vpiUndefined; }
vpiHandle __vpiArrayIterator::vpi_index(int)
{
if (next >= array->array_count) {
vpi_free_object(this);
return 0;
}
char* __vpiArrayIterator::vpi_get_str(int)
{ return 0; }
unsigned use_index = next;
next += 1;
if (array->nets) return array->nets[use_index];
assert(array->vals4 || array->valsr);
if (array->vals_words == 0) array_make_vals_words(array);
return &(array->vals_words[use_index].as_word);
}
vpiHandle __vpiArrayIterator::vpi_index(int code)
{ return array_iterator_scan(this, code); }
__vpiHandle::free_object_fun_t __vpiArrayIterator::free_object_fun(void)
{ return &array_iterator_free_object; }
@ -376,12 +451,6 @@ inline __vpiArrayIndex::__vpiArrayIndex()
int __vpiArrayIndex::get_type_code(void) const
{ return vpiIterator; }
int __vpiArrayIndex::vpi_get(int)
{ return vpiUndefined; }
char* __vpiArrayIndex::vpi_get_str(int)
{ return 0; }
vpiHandle __vpiArrayIndex::vpi_iterate(int code)
{ return array_index_iterate(code, this); }
@ -506,103 +575,6 @@ static unsigned decode_array_word_pointer(struct __vpiArrayWord*word,
return word - word0;
}
static int vpi_array_get(int code, vpiHandle ref)
{
struct __vpiArray*obj = dynamic_cast<__vpiArray*> (ref);
switch (code) {
case vpiLineNo:
return 0; // Not implemented for now!
case vpiSize:
return (int) obj->array_count;
case vpiAutomatic:
return (int) obj->scope->is_automatic;
default:
return 0;
}
}
static char*vpi_array_get_str(int code, vpiHandle ref)
{
struct __vpiArray*obj = dynamic_cast<__vpiArray*>(ref);
if (code == vpiFile) { // Not implemented for now!
return simple_set_rbuf_str(file_names[0]);
}
return generic_get_str(code, obj->scope, obj->name, NULL);
}
static vpiHandle vpi_array_get_handle(int code, vpiHandle ref)
{
struct __vpiArray*obj = dynamic_cast<__vpiArray*>(ref);
switch (code) {
case vpiLeftRange:
if (obj->swap_addr) return &(obj->last_addr);
else return &(obj->first_addr);
case vpiRightRange:
if (obj->swap_addr) return &(obj->first_addr);
else return &(obj->last_addr);
case vpiScope:
return obj->scope;
case vpiModule:
return vpip_module(obj->scope);
}
return 0;
}
static vpiHandle vpi_array_iterate(int code, vpiHandle ref)
{
struct __vpiArray*obj = dynamic_cast<__vpiArray*>(ref);
switch (code) {
case vpiMemoryWord: {
struct __vpiArrayIterator*res;
res = new __vpiArrayIterator;
res->array = obj;
res->next = 0;
return res;
}
}
return 0;
}
/*
* VPI code passes indices that are not yet converted to canonical
* form, so this index function does it here.
*/
static vpiHandle vpi_array_index(vpiHandle ref, int index)
{
struct __vpiArray*obj = dynamic_cast<__vpiArray*>(ref);
index -= obj->first_addr.value;
if (index >= (long)obj->array_count)
return 0;
if (index < 0)
return 0;
if (obj->nets != 0) {
return obj->nets[index];
}
if (obj->vals_words == 0)
array_make_vals_words(obj);
return &(obj->vals_words[index].as_word);
}
static int vpi_array_var_word_get(int code, vpiHandle ref)
{
struct __vpiArrayWord*obj = array_var_word_from_handle(ref);
@ -731,27 +703,6 @@ static void vpi_array_var_index_get_value(vpiHandle ref, p_vpi_value vp)
vp->value.integer = index;
}
static vpiHandle array_iterator_scan(vpiHandle ref, int)
{
struct __vpiArrayIterator*obj = dynamic_cast<__vpiArrayIterator*>(ref);
if (obj->next >= obj->array->array_count) {
vpi_free_object(ref);
return 0;
}
unsigned use_index = obj->next;
obj->next += 1;
if (obj->array->nets) return obj->array->nets[use_index];
assert(obj->array->vals4 || obj->array->valsr);
if (obj->array->vals_words == 0) array_make_vals_words(obj->array);
return &(obj->array->vals_words[use_index].as_word);
}
static int array_iterator_free_object(vpiHandle ref)
{
struct __vpiArrayIterator*obj = dynamic_cast<__vpiArrayIterator*>(ref);

View File

@ -48,24 +48,28 @@ struct __vpiEnumTypespec : public __vpiHandle {
bool is_signed;
};
static int enum_type_get(int code, vpiHandle obj)
{
struct __vpiEnumTypespec*ref = dynamic_cast<__vpiEnumTypespec*>(obj);
assert(ref);
inline __vpiEnumTypespec::__vpiEnumTypespec()
{ }
int __vpiEnumTypespec::get_type_code(void) const
{ return vpiEnumTypespec; }
int __vpiEnumTypespec::vpi_get(int code)
{
switch (code) {
case vpiSize:
return ref->names.size();
return names.size();
/* This is not currently set correctly. We always use vpiReg for
* four state variables and vpiBitVar for two state variables.
* This minimal functionality is needed to get the next() and
* prev() methods to work correctly with invalid values. */
case vpiBaseTypespec:
return ref->base_type_code;
return base_type_code;
case vpiSigned:
return ref->is_signed;
return is_signed;
default:
fprintf(stderr, "vvp error: get %d not supported "
@ -75,73 +79,22 @@ static int enum_type_get(int code, vpiHandle obj)
}
}
static vpiHandle enum_type_iterate(int code, vpiHandle obj)
{
struct __vpiEnumTypespec*ref = dynamic_cast<__vpiEnumTypespec*>(obj);
assert(ref);
vpiHandle __vpiEnumTypespec::vpi_iterate(int code)
{
if (code == vpiEnumConst) {
vpiHandle*args = (vpiHandle*)
calloc(ref->names.size(), sizeof(vpiHandle*));
for (size_t idx = 0 ; idx < ref->names.size() ; idx += 1)
args[idx] = &ref->names[idx];
calloc(names.size(), sizeof(vpiHandle*));
for (size_t idx = 0 ; idx < names.size() ; idx += 1)
args[idx] = &names[idx];
return vpip_make_iterator(ref->names.size(), args, true);
return vpip_make_iterator(names.size(), args, true);
}
return 0;
}
inline __vpiEnumTypespec::__vpiEnumTypespec()
{ }
int __vpiEnumTypespec::get_type_code(void) const
{ return vpiEnumTypespec; }
int __vpiEnumTypespec::vpi_get(int code)
{ return enum_type_get(code, this); }
vpiHandle __vpiEnumTypespec::vpi_iterate(int code)
{ return enum_type_iterate(code, this); }
static int enum_name_get(int code, vpiHandle obj)
{
struct enumconst_s*ref = dynamic_cast<enumconst_s*>(obj);
assert(ref);
switch (code) {
case vpiSize:
return ref->val4.size()? ref->val4.size() : ref->val2.size();
default:
return 0;
}
}
static char* enum_name_get_str(int code, vpiHandle obj)
{
struct enumconst_s*ref = dynamic_cast<enumconst_s*>(obj);
assert(ref);
switch (code) {
case vpiName:
return const_cast<char*> (ref->name);
default:
return 0;
}
}
static void enum_name_get_value(vpiHandle obj, p_vpi_value value)
{
struct enumconst_s*ref = dynamic_cast<enumconst_s*>(obj);
assert(ref);
if (ref->val4.size() > 0)
vpip_vec4_get_value(ref->val4, ref->val4.size(), false, value);
else
vpip_vec2_get_value(ref->val2, ref->val2.size(), false, value);
}
inline enumconst_s::enumconst_s()
{ }
@ -149,13 +102,35 @@ int enumconst_s::get_type_code(void) const
{ return vpiEnumConst; }
int enumconst_s::vpi_get(int code)
{ return enum_name_get(code, this); }
{
switch (code) {
case vpiSize:
return val4.size()? val4.size() : val2.size();
default:
return 0;
}
}
char* enumconst_s::vpi_get_str(int code)
{ return enum_name_get_str(code, this); }
{
switch (code) {
case vpiName:
return const_cast<char*> (name);
default:
return 0;
}
}
void enumconst_s::vpi_get_value(p_vpi_value val)
{ enum_name_get_value(this, val); }
{
if (val4.size() > 0)
vpip_vec4_get_value(val4, val4.size(), false, val);
else
vpip_vec2_get_value(val2, val2.size(), false, val);
}
void compile_enum2_type(char*label, long width, bool signed_flag,
std::list<struct enum_name_s>*names)

View File

@ -62,10 +62,8 @@ void sfunc_core::recv_vec4(vvp_net_ptr_t, const vvp_vector4_t&/*bit*/,
void sfunc_core::recv_vec4_from_inputs(unsigned port)
{
vpiHandle vpi = argv_[port];
assert(vpi_get(vpiConstType,vpi) == vpiBinaryConst);
struct __vpiBinaryConst*obj
= (struct __vpiBinaryConst*)vpi;
struct __vpiBinaryConst*obj = dynamic_cast<__vpiBinaryConst*>(vpi);
assert(obj);
obj->bits = value(port);
@ -76,10 +74,8 @@ void sfunc_core::recv_vec4_from_inputs(unsigned port)
void sfunc_core::recv_real_from_inputs(unsigned port)
{
vpiHandle vpi = argv_[port];
assert(vpi_get(vpiConstType,vpi) == vpiRealConst);
struct __vpiRealConst*obj
= (struct __vpiRealConst*)vpi;
struct __vpiRealConst*obj = dynamic_cast<__vpiRealConst*>(vpi);
assert(obj);
obj->value = value_r(port);

View File

@ -29,14 +29,18 @@
# include <cassert>
# include "ivl_alloc.h"
static int string_get(int code, vpiHandle ref)
{
struct __vpiStringConst*rfp;
inline __vpiStringConst::__vpiStringConst()
{ }
int __vpiStringConst::get_type_code(void) const
{ return vpiConstant; }
int __vpiStringConst::vpi_get(int code)
{
switch (code) {
case vpiSize:
rfp = dynamic_cast<__vpiStringConst*>(ref);
return strlen(rfp->value)*8;
return strlen(value)*8;
case vpiSigned:
return 0;
@ -60,12 +64,11 @@ static int string_get(int code, vpiHandle ref)
}
}
static void string_value(vpiHandle ref, p_vpi_value vp)
void __vpiStringConst::vpi_get_value(p_vpi_value vp)
{
unsigned uint_value;
p_vpi_vecval vecp;
struct __vpiStringConst*rfp = dynamic_cast<__vpiStringConst*>(ref);
int size = strlen(rfp->value);
int size = strlen(value);
char*rbuf = 0;
char*cp;
@ -76,7 +79,7 @@ static void string_value(vpiHandle ref, p_vpi_value vp)
case vpiStringVal:
rbuf = need_result_buf(size + 1, RBUF_VAL);
strcpy(rbuf, (char*)rfp->value);
strcpy(rbuf, (char*)value);
vp->value.str = rbuf;
break;
@ -91,7 +94,7 @@ static void string_value(vpiHandle ref, p_vpi_value vp)
uint_value = 0;
for(int i=0; i<size;i ++){
uint_value <<=8;
uint_value += (unsigned char)(rfp->value[i]);
uint_value += (unsigned char)(value[i]);
}
sprintf(rbuf, "%u", uint_value);
vp->value.str = rbuf;
@ -102,7 +105,7 @@ static void string_value(vpiHandle ref, p_vpi_value vp)
cp = rbuf;
for(int i=0; i<size;i ++){
for(int bit=7;bit>=0; bit--){
*cp++ = "01"[ (rfp->value[i]>>bit)&1 ];
*cp++ = "01"[ (value[i]>>bit)&1 ];
}
}
*cp = 0;
@ -114,7 +117,7 @@ static void string_value(vpiHandle ref, p_vpi_value vp)
cp = rbuf;
for(int i=0; i<size;i++){
for(int nibble=1;nibble>=0; nibble--){
*cp++ = "0123456789abcdef"[ (rfp->value[i]>>(nibble*4))&15 ];
*cp++ = "0123456789abcdef"[ (value[i]>>(nibble*4))&15 ];
}
}
*cp = 0;
@ -131,7 +134,7 @@ static void string_value(vpiHandle ref, p_vpi_value vp)
for(int i=0; i<size;i ++){
for(int bit=7;bit>=0; bit--){
vp->value.integer <<= 1;
vp->value.integer += (rfp->value[i]>>bit)&1;
vp->value.integer += (value[i]>>bit)&1;
}
}
break;
@ -145,7 +148,7 @@ static void string_value(vpiHandle ref, p_vpi_value vp)
vecp = vp->value.vector;
vecp->aval = vecp->bval = 0;
for(int i=0; i<size;i ++){
vecp->aval |= rfp->value[i] << uint_value*8;
vecp->aval |= value[i] << uint_value*8;
uint_value += 1;
if (uint_value > 3) {
uint_value = 0;
@ -166,41 +169,9 @@ static void string_value(vpiHandle ref, p_vpi_value vp)
}
}
inline __vpiStringConst::__vpiStringConst()
{ }
int __vpiStringConst::get_type_code(void) const
{ return vpiConstant; }
int __vpiStringConst::vpi_get(int code)
{ return string_get(code, this); }
char*__vpiStringConst::vpi_get_str(int)
{ return 0; }
void __vpiStringConst::vpi_get_value(p_vpi_value val)
{ string_value(this, val); }
vpiHandle __vpiStringConst::vpi_put_value(p_vpi_value, int)
{ return 0; }
vpiHandle __vpiStringConst::vpi_handle(int)
{ return 0; }
vpiHandle __vpiStringConst::vpi_iterate(int)
{ return 0; }
vpiHandle __vpiStringConst::vpi_index(int)
{ return 0; }
void __vpiStringConst::vpi_get_delays(p_vpi_delay)
{ }
void __vpiStringConst::vpi_put_delays(p_vpi_delay)
{ }
struct __vpiStringConstTEMP : public __vpiStringConst {
__vpiStringConstTEMP();
inline __vpiStringConstTEMP() { }
free_object_fun_t free_object_fun(void);
};
@ -213,9 +184,6 @@ static int free_temp_string(vpiHandle obj)
return 1;
}
inline __vpiStringConstTEMP::__vpiStringConstTEMP()
{ }
__vpiHandle::free_object_fun_t __vpiStringConstTEMP::free_object_fun(void)
{ return &free_temp_string; }
@ -276,48 +244,6 @@ struct __vpiStringParam : public __vpiStringConst {
unsigned lineno;
};
static int string_param_get(int code, vpiHandle ref)
{
struct __vpiStringParam*rfp = dynamic_cast<__vpiStringParam*>(ref);
assert(ref);
if (code == vpiLineNo) {
return rfp->lineno;
}
return string_get(code, ref);
}
static char* string_param_get_str(int code, vpiHandle obj)
{
struct __vpiStringParam*rfp = dynamic_cast<__vpiStringParam*>(obj);
assert(rfp);
if (code == vpiFile) {
return simple_set_rbuf_str(file_names[rfp->file_idx]);
}
return generic_get_str(code, rfp->scope, rfp->basename, NULL);
}
static vpiHandle string_param_handle(int code, vpiHandle obj)
{
struct __vpiStringParam*rfp = dynamic_cast<__vpiStringParam*>(obj);
assert(rfp);
switch (code) {
case vpiScope:
return rfp->scope;
case vpiModule:
return vpip_module(rfp->scope);
default:
return 0;
}
}
inline __vpiStringParam::__vpiStringParam()
{ }
@ -325,13 +251,37 @@ int __vpiStringParam::get_type_code(void) const
{ return vpiParameter; }
int __vpiStringParam::vpi_get(int code)
{ return string_param_get(code, this); }
{
if (code == vpiLineNo)
return lineno;
return __vpiStringConst::vpi_get(code);
}
char*__vpiStringParam::vpi_get_str(int code)
{ return string_param_get_str(code, this); }
{
if (code == vpiFile) {
return simple_set_rbuf_str(file_names[file_idx]);
}
return generic_get_str(code, scope, basename, NULL);
}
vpiHandle __vpiStringParam::vpi_handle(int code)
{ return string_param_handle(code, this); }
{
switch (code) {
case vpiScope:
return scope;
case vpiModule:
return vpip_module(scope);
default:
return 0;
}
}
vpiHandle vpip_make_string_param(char*name, char*text,
long file_idx, long lineno)
@ -349,10 +299,16 @@ vpiHandle vpip_make_string_param(char*name, char*text,
return obj;
}
static int binary_get(int code, vpiHandle ref)
{
struct __vpiBinaryConst*rfp = dynamic_cast<__vpiBinaryConst*>(ref);
inline __vpiBinaryConst::__vpiBinaryConst()
{ }
int __vpiBinaryConst::get_type_code(void) const
{ return vpiConstant; }
int __vpiBinaryConst::vpi_get(int code)
{
switch (code) {
case vpiConstType:
return vpiBinaryConst;
@ -361,10 +317,10 @@ static int binary_get(int code, vpiHandle ref)
return 0; // Not implemented for now!
case vpiSigned:
return rfp->signed_flag? 1 : 0;
return signed_flag? 1 : 0;
case vpiSize:
return rfp->bits.size();
return bits.size();
case vpiAutomatic:
return 0;
@ -383,11 +339,9 @@ static int binary_get(int code, vpiHandle ref)
}
static void binary_value(vpiHandle ref, p_vpi_value vp)
void __vpiBinaryConst::vpi_get_value(p_vpi_value val)
{
struct __vpiBinaryConst*rfp = dynamic_cast<__vpiBinaryConst*>(ref);
switch (vp->format) {
switch (val->format) {
case vpiObjTypeVal:
case vpiBinStrVal:
@ -399,52 +353,18 @@ static void binary_value(vpiHandle ref, p_vpi_value vp)
case vpiVectorVal:
case vpiStringVal:
case vpiRealVal:
vpip_vec4_get_value(rfp->bits, rfp->bits.size(),
rfp->signed_flag, vp);
vpip_vec4_get_value(bits, bits.size(), signed_flag, val);
break;
default:
fprintf(stderr, "vvp error: format %d not supported "
"by vpiBinaryConst\n", (int)vp->format);
vp->format = vpiSuppressVal;
"by vpiBinaryConst\n", (int)val->format);
val->format = vpiSuppressVal;
break;
}
}
inline __vpiBinaryConst::__vpiBinaryConst()
{ }
int __vpiBinaryConst::get_type_code(void) const
{ return vpiConstant; }
int __vpiBinaryConst::vpi_get(int code)
{ return binary_get(code, this); }
char* __vpiBinaryConst::vpi_get_str(int)
{ return 0; }
void __vpiBinaryConst::vpi_get_value(p_vpi_value val)
{ binary_value(this, val); }
vpiHandle __vpiBinaryConst::vpi_put_value(p_vpi_value, int)
{ return 0; }
vpiHandle __vpiBinaryConst::vpi_handle(int)
{ return 0; }
vpiHandle __vpiBinaryConst::vpi_iterate(int)
{ return 0; }
vpiHandle __vpiBinaryConst::vpi_index(int)
{ return 0; }
void __vpiBinaryConst::vpi_get_delays(p_vpi_delay)
{ }
void __vpiBinaryConst::vpi_put_delays(p_vpi_delay)
{ }
/*
* Make a VPI constant from a vector string. The string is normally a
* ASCII string, with each letter a 4-value bit. The first character
@ -508,44 +428,6 @@ struct __vpiBinaryParam : public __vpiBinaryConst {
unsigned lineno;
};
static int binary_param_get(int code, vpiHandle ref)
{
struct __vpiBinaryParam*rfp = dynamic_cast<__vpiBinaryParam*>(ref);
if (code == vpiLineNo) {
return rfp->lineno;
}
return binary_get(code, ref);
}
static char* binary_param_get_str(int code, vpiHandle obj)
{
struct __vpiBinaryParam*rfp = dynamic_cast<__vpiBinaryParam*>(obj);
if (code == vpiFile) {
return simple_set_rbuf_str(file_names[rfp->file_idx]);
}
return generic_get_str(code, rfp->scope, rfp->basename, NULL);
}
static vpiHandle binary_param_handle(int code, vpiHandle obj)
{
struct __vpiBinaryParam*rfp = dynamic_cast<__vpiBinaryParam*>(obj);
switch (code) {
case vpiScope:
return rfp->scope;
case vpiModule:
return vpip_module(rfp->scope);
default:
return 0;
}
}
inline __vpiBinaryParam::__vpiBinaryParam()
{ }
@ -553,13 +435,36 @@ int __vpiBinaryParam::get_type_code(void) const
{ return vpiParameter; }
int __vpiBinaryParam::vpi_get(int code)
{ return binary_param_get(code, this); }
{
if (code == vpiLineNo)
return lineno;
return __vpiBinaryConst::vpi_get(code);
}
char*__vpiBinaryParam::vpi_get_str(int code)
{ return binary_param_get_str(code, this); }
{
if (code == vpiFile)
return simple_set_rbuf_str(file_names[file_idx]);
return generic_get_str(code, scope, basename, NULL);
}
vpiHandle __vpiBinaryParam::vpi_handle(int code)
{ return binary_param_handle(code, this); }
{
switch (code) {
case vpiScope:
return scope;
case vpiModule:
return vpip_module(scope);
default:
return 0;
}
}
vpiHandle vpip_make_binary_param(char*name, const vvp_vector4_t&bits,
bool signed_flag,
@ -579,9 +484,17 @@ vpiHandle vpip_make_binary_param(char*name, const vvp_vector4_t&bits,
}
static int dec_get(int code, vpiHandle)
{
__vpiDecConst::__vpiDecConst(int val)
{
value = val;
}
int __vpiDecConst::get_type_code(void) const
{ return vpiConstant; }
int __vpiDecConst::vpi_get(int code)
{
switch (code) {
case vpiConstType:
return vpiDecConst;
@ -609,9 +522,8 @@ static int dec_get(int code, vpiHandle)
}
static void dec_value(vpiHandle ref, p_vpi_value vp)
void __vpiDecConst::vpi_get_value(p_vpi_value vp)
{
struct __vpiDecConst*rfp = dynamic_cast<__vpiDecConst*>(ref);
char*rbuf = need_result_buf(64 + 1, RBUF_VAL);
char*cp = rbuf;
@ -619,19 +531,19 @@ static void dec_value(vpiHandle ref, p_vpi_value vp)
case vpiObjTypeVal:
case vpiIntVal: {
vp->value.integer = rfp->value;
vp->value.integer = value;
break;
}
case vpiDecStrVal:
sprintf(rbuf, "%d", rfp->value);
sprintf(rbuf, "%d", value);
vp->value.str = rbuf;
break;
case vpiBinStrVal:
for(int bit=31; bit<=0;bit--){
*cp++ = "01"[ (rfp->value>>bit)&1 ];
*cp++ = "01"[ (value>>bit)&1 ];
}
*cp = 0;
@ -639,13 +551,13 @@ static void dec_value(vpiHandle ref, p_vpi_value vp)
break;
case vpiHexStrVal:
sprintf(rbuf, "%08x", rfp->value);
sprintf(rbuf, "%08x", value);
vp->value.str = rbuf;
break;
case vpiOctStrVal:
sprintf(rbuf, "%011x", rfp->value);
sprintf(rbuf, "%011x", value);
vp->value.str = rbuf;
break;
@ -658,23 +570,15 @@ static void dec_value(vpiHandle ref, p_vpi_value vp)
}
}
__vpiDecConst::__vpiDecConst(int val)
{
value = val;
}
int __vpiDecConst::get_type_code(void) const
inline __vpiRealConst::__vpiRealConst()
{ }
int __vpiRealConst::get_type_code(void) const
{ return vpiConstant; }
int __vpiDecConst::vpi_get(int code)
{ return dec_get(code, this); }
void __vpiDecConst::vpi_get_value(p_vpi_value val)
{ dec_value(this, val); }
static int real_get(int code, vpiHandle)
int __vpiRealConst::vpi_get(int code)
{
switch (code) {
case vpiLineNo:
return 0; // Not implemented for now!
@ -704,23 +608,12 @@ static int real_get(int code, vpiHandle)
}
}
static void real_value(vpiHandle ref, p_vpi_value vp)
{
struct __vpiRealConst*rfp = dynamic_cast<__vpiRealConst*>(ref);
vpip_real_get_value(rfp->value, vp);
}
inline __vpiRealConst::__vpiRealConst()
{ }
int __vpiRealConst::get_type_code(void) const
{ return vpiConstant; }
int __vpiRealConst::vpi_get(int code)
{ return real_get(code, this); }
void __vpiRealConst::vpi_get_value(p_vpi_value val)
{ real_value(this, val); }
{
vpip_real_get_value(value, val);
}
vpiHandle vpip_make_real_const(double value)
{
@ -742,44 +635,6 @@ struct __vpiRealParam : public __vpiRealConst {
unsigned lineno;
};
static int real_param_get(int code, vpiHandle ref)
{
struct __vpiRealParam*rfp = dynamic_cast<__vpiRealParam*>(ref);
if (code == vpiLineNo) {
return rfp->lineno;
}
return real_get(code, ref);
}
static char* real_param_get_str(int code, vpiHandle obj)
{
struct __vpiRealParam*rfp = dynamic_cast<__vpiRealParam*>(obj);
if (code == vpiFile) {
return simple_set_rbuf_str(file_names[rfp->file_idx]);
}
return generic_get_str(code, rfp->scope, rfp->basename, NULL);
}
static vpiHandle real_param_handle(int code, vpiHandle obj)
{
struct __vpiRealParam*rfp = dynamic_cast<__vpiRealParam*>(obj);
switch (code) {
case vpiScope:
return rfp->scope;
case vpiModule:
return vpip_module(rfp->scope);
default:
return 0;
}
}
inline __vpiRealParam::__vpiRealParam()
{ }
@ -788,13 +643,34 @@ int __vpiRealParam::get_type_code(void) const
{ return vpiParameter; }
int __vpiRealParam::vpi_get(int code)
{ return real_param_get(code, this); }
{
if (code == vpiLineNo)
return lineno;
return __vpiRealConst::vpi_get(code);
}
char* __vpiRealParam::vpi_get_str(int code)
{ return real_param_get_str(code, this); }
{
if (code == vpiFile)
return simple_set_rbuf_str(file_names[file_idx]);
return generic_get_str(code, scope, basename, NULL);
}
vpiHandle __vpiRealParam::vpi_handle(int code)
{ return real_param_handle(code, this); }
{
switch (code) {
case vpiScope:
return scope;
case vpiModule:
return vpip_module(scope);
default:
return 0;
}
}
vpiHandle vpip_make_real_param(char*name, double value,

View File

@ -25,47 +25,6 @@
# include <cassert>
# include "ivl_alloc.h"
static int named_event_get(int code, vpiHandle ref)
{
struct __vpiNamedEvent*obj = dynamic_cast<__vpiNamedEvent*>(ref);
assert(obj);
switch (code) {
case vpiAutomatic:
return (int) obj->scope->is_automatic;
}
return 0;
}
static char* named_event_get_str(int code, vpiHandle ref)
{
struct __vpiNamedEvent*obj = dynamic_cast<__vpiNamedEvent*>(ref);
assert(obj);
if (code == vpiFile) { // Not implemented for now!
return simple_set_rbuf_str(file_names[0]);
}
return generic_get_str(code, obj->scope, obj->name, NULL);
}
static vpiHandle named_event_get_handle(int code, vpiHandle ref)
{
struct __vpiNamedEvent*obj = dynamic_cast<__vpiNamedEvent*>(ref);
assert(obj);
switch (code) {
case vpiScope:
return obj->scope;
case vpiModule:
return vpip_module(obj->scope);
}
return 0;
}
inline __vpiNamedEvent::__vpiNamedEvent()
{ }
@ -73,13 +32,38 @@ int __vpiNamedEvent::get_type_code(void) const
{ return vpiNamedEvent; }
int __vpiNamedEvent::vpi_get(int code)
{ return named_event_get(code, this); }
{
switch (code) {
case vpiAutomatic:
return (int) scope->is_automatic;
}
return 0;
}
char* __vpiNamedEvent::vpi_get_str(int code)
{ return named_event_get_str(code, this); }
{
if (code == vpiFile) { // Not implemented for now!
return simple_set_rbuf_str(file_names[0]);
}
return generic_get_str(code, scope, name, NULL);
}
vpiHandle __vpiNamedEvent::vpi_handle(int code)
{ return named_event_get_handle(code, this); }
{
switch (code) {
case vpiScope:
return scope;
case vpiModule:
return vpip_module(scope);
}
return 0;
}
vpiHandle vpip_make_named_event(const char*name, vvp_net_t*funct)
{

View File

@ -175,19 +175,13 @@ struct __vpiSystemTime : public __vpiHandle {
int vpi_get(int code);
char*vpi_get_str(int code);
void vpi_get_value(p_vpi_value val);
vpiHandle vpi_put_value(p_vpi_value val, int flags);
vpiHandle vpi_handle(int code);
vpiHandle vpi_iterate(int code);
vpiHandle vpi_index(int idx);
void vpi_get_delays(p_vpi_delay del);
void vpi_put_delays(p_vpi_delay del);
struct __vpiScope*scope;
};
struct __vpiScopedTime : public __vpiSystemTime {
__vpiScopedTime();
int vpi_get(int code);
char*vpi_get_str(int code);
void vpi_get_value(p_vpi_value val);
};
@ -537,14 +531,7 @@ struct __vpiStringConst : public __vpiHandle {
__vpiStringConst();
int get_type_code(void) const;
int vpi_get(int code);
char*vpi_get_str(int code);
void vpi_get_value(p_vpi_value val);
vpiHandle vpi_put_value(p_vpi_value val, int flags);
vpiHandle vpi_handle(int code);
vpiHandle vpi_iterate(int code);
vpiHandle vpi_index(int idx);
void vpi_get_delays(p_vpi_delay del);
void vpi_put_delays(p_vpi_delay del);
char*value;
size_t value_len;
@ -558,14 +545,7 @@ struct __vpiBinaryConst : public __vpiHandle {
__vpiBinaryConst();
int get_type_code(void) const;
int vpi_get(int code);
char*vpi_get_str(int code);
void vpi_get_value(p_vpi_value val);
vpiHandle vpi_put_value(p_vpi_value val, int flags);
vpiHandle vpi_handle(int code);
vpiHandle vpi_iterate(int code);
vpiHandle vpi_index(int idx);
void vpi_get_delays(p_vpi_delay del);
void vpi_put_delays(p_vpi_delay del);
vvp_vector4_t bits;
/* TRUE if this constant is signed. */

View File

@ -94,121 +94,6 @@ vvp_time64_t vpip_scaled_real_to_time64(double val, struct __vpiScope*scope)
return delay;
}
static int timevar_time_get(int code, vpiHandle)
{
switch (code) {
case vpiSize:
return 64;
case vpiSigned:
return 0;
case vpiFuncType:
return vpiTimeFunc;
case vpiAutomatic:
return 0;
default:
fprintf(stderr, "Code: %d\n", code);
assert(0);
return 0;
}
}
static int timevar_stime_get(int code, vpiHandle ref)
{
switch (code) {
case vpiSize:
return 32;
default:
return timevar_time_get(code, ref);
}
}
static char* timevar_time_get_str(int code, vpiHandle)
{
switch (code) {
case vpiName:
return simple_set_rbuf_str("$time");
default:
fprintf(stderr, "Code: %d\n", code);
assert(0);
return 0;
}
}
static char* timevar_stime_get_str(int code, vpiHandle)
{
switch (code) {
case vpiName:
return simple_set_rbuf_str("$stime");
default:
fprintf(stderr, "Code: %d\n", code);
assert(0);
return 0;
}
}
static char* timevar_simtime_get_str(int code, vpiHandle)
{
switch (code) {
case vpiName:
return simple_set_rbuf_str("$simtime");
default:
fprintf(stderr, "Code: %d\n", code);
assert(0);
return 0;
}
}
static char* timevar_realtime_get_str(int code, vpiHandle)
{
switch (code) {
case vpiName:
return simple_set_rbuf_str("$realtime");
default:
fprintf(stderr, "Code: %d\n", code);
assert(0);
return 0;
}
}
static int timevar_realtime_get(int code, vpiHandle)
{
switch (code) {
case vpiSize:
return 1;
case vpiSigned:
return 0;
case vpiFuncType:
return vpiRealFunc;
case vpiAutomatic:
return 0;
default:
fprintf(stderr, "Code: %d\n", code);
assert(0);
return 0;
}
}
static vpiHandle timevar_handle(int code, vpiHandle ref)
{
struct __vpiSystemTime*rfp = dynamic_cast<__vpiSystemTime*>(ref);
switch (code) {
case vpiScope:
return rfp->scope;
default:
return 0;
}
}
static void timevar_get_value(vpiHandle ref, s_vpi_value*vp, bool is_int_func,
bool is_stime)
{
@ -314,11 +199,18 @@ static void timevar_get_rvalue(vpiHandle ref, s_vpi_value*vp)
__vpiScopedTime::__vpiScopedTime()
{ }
int __vpiScopedTime::vpi_get(int code)
{ return timevar_time_get(code, this); }
char* __vpiScopedTime::vpi_get_str(int code)
{ return timevar_time_get_str(code, this); }
{
switch (code) {
case vpiName:
return simple_set_rbuf_str("$time");
default:
fprintf(stderr, "Code: %d\n", code);
assert(0);
return 0;
}
}
void __vpiScopedTime::vpi_get_value(p_vpi_value val)
{ timevar_get_ivalue(this, val); }
@ -328,10 +220,29 @@ __vpiScopedSTime::__vpiScopedSTime()
{ }
int __vpiScopedSTime::vpi_get(int code)
{ return timevar_stime_get(code, this); }
{
switch (code) {
case vpiSize:
return 32;
default:
return __vpiSystemTime::vpi_get(code);
}
}
char* __vpiScopedSTime::vpi_get_str(int code)
{ return timevar_stime_get_str(code, this); }
{
switch (code) {
case vpiName:
return simple_set_rbuf_str("$stime");
default:
fprintf(stderr, "Code: %d\n", code);
assert(0);
return 0;
}
}
void __vpiScopedSTime::vpi_get_value(p_vpi_value val)
{ timevar_get_svalue(this, val); }
@ -345,40 +256,93 @@ int __vpiSystemTime::get_type_code(void) const
{ return vpiSysFuncCall; }
int __vpiSystemTime::vpi_get(int code)
{ return timevar_time_get(code, this); }
{
switch (code) {
case vpiSize:
return 64;
case vpiSigned:
return 0;
case vpiFuncType:
return vpiTimeFunc;
case vpiAutomatic:
return 0;
default:
fprintf(stderr, "Code: %d\n", code);
assert(0);
return 0;
}
}
char* __vpiSystemTime::vpi_get_str(int code)
{ return timevar_simtime_get_str(code, this); }
{
switch (code) {
case vpiName:
return simple_set_rbuf_str("$simtime");
default:
fprintf(stderr, "Code: %d\n", code);
assert(0);
return 0;
}
}
void __vpiSystemTime::vpi_get_value(p_vpi_value val)
{ timevar_get_ivalue(this, val); }
vpiHandle __vpiSystemTime::vpi_put_value(p_vpi_value, int)
{ return 0; }
vpiHandle __vpiSystemTime::vpi_handle(int code)
{ return timevar_handle(code, this); }
{
switch (code) {
case vpiScope:
return scope;
default:
return 0;
}
}
vpiHandle __vpiSystemTime::vpi_iterate(int)
{ return 0; }
vpiHandle __vpiSystemTime::vpi_index(int)
{ return 0; }
void __vpiSystemTime::vpi_get_delays(p_vpi_delay)
{ }
void __vpiSystemTime::vpi_put_delays(p_vpi_delay)
{ }
__vpiScopedRealtime::__vpiScopedRealtime()
{ }
int __vpiScopedRealtime::vpi_get(int code)
{ return timevar_realtime_get(code, this); }
{
switch (code) {
case vpiSize:
return 1;
case vpiSigned:
return 0;
case vpiFuncType:
return vpiRealFunc;
case vpiAutomatic:
return 0;
default:
fprintf(stderr, "Code: %d\n", code);
assert(0);
return 0;
}
}
char* __vpiScopedRealtime::vpi_get_str(int code)
{ return timevar_realtime_get_str(code, this); }
{
switch (code) {
case vpiName:
return simple_set_rbuf_str("$realtime");
default:
fprintf(stderr, "Code: %d\n", code);
assert(0);
return 0;
}
}
void __vpiScopedRealtime::vpi_get_value(p_vpi_value val)
{ timevar_get_rvalue(this, val); }