Handle strings as arguments to automatic functions.
This commit is contained in:
parent
16414f921f
commit
13bb927d8a
|
|
@ -65,6 +65,12 @@ static void function_argument_class(ivl_signal_t port, ivl_expr_t expr)
|
|||
fprintf(vvp_out, " %%store/obj v%p_0;\n", port);
|
||||
}
|
||||
|
||||
static void function_argument_string(ivl_signal_t port, ivl_expr_t expr)
|
||||
{
|
||||
draw_eval_string(expr);
|
||||
fprintf(vvp_out, " %%store/str v%p_0;\n", port);
|
||||
}
|
||||
|
||||
static void draw_function_argument(ivl_signal_t port, ivl_expr_t expr)
|
||||
{
|
||||
ivl_variable_type_t dtype = ivl_signal_data_type(port);
|
||||
|
|
@ -81,6 +87,9 @@ static void draw_function_argument(ivl_signal_t port, ivl_expr_t expr)
|
|||
case IVL_VT_CLASS:
|
||||
function_argument_class(port, expr);
|
||||
break;
|
||||
case IVL_VT_STRING:
|
||||
function_argument_string(port, expr);
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "XXXX function argument %s type=%d?!\n",
|
||||
ivl_signal_basename(port), dtype);
|
||||
|
|
|
|||
|
|
@ -296,6 +296,11 @@ vvp_net_fil_t::prop_t vvp_net_fil_t::filter_long(long&)
|
|||
return PROP;
|
||||
}
|
||||
|
||||
vvp_net_fil_t::prop_t vvp_net_fil_t::filter_string(const string&)
|
||||
{
|
||||
return PROP;
|
||||
}
|
||||
|
||||
vvp_net_fil_t::prop_t vvp_net_fil_t::filter_object(vvp_object_t&)
|
||||
{
|
||||
return PROP;
|
||||
|
|
|
|||
|
|
@ -1229,6 +1229,7 @@ class vvp_net_fil_t : public vvp_vpi_callback {
|
|||
virtual prop_t filter_real(double&val);
|
||||
virtual prop_t filter_long(long&val);
|
||||
virtual prop_t filter_object(vvp_object_t&val);
|
||||
virtual prop_t filter_string(const std::string&val);
|
||||
|
||||
virtual void release(vvp_net_ptr_t ptr, bool net_flag) =0;
|
||||
virtual void release_pv(vvp_net_ptr_t ptr, unsigned base, unsigned wid, bool net_flag) =0;
|
||||
|
|
@ -1708,7 +1709,9 @@ inline void vvp_net_t::send_real(double val, vvp_context_t context)
|
|||
|
||||
inline void vvp_net_t::send_string(const std::string&val, vvp_context_t context)
|
||||
{
|
||||
assert(!fil);
|
||||
if (fil && !fil->filter_string(val))
|
||||
return;
|
||||
|
||||
vvp_send_string(out_, val, context);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -613,6 +613,11 @@ void vvp_fun_signal_string_sa::recv_string(vvp_net_ptr_t ptr, const std::string&
|
|||
}
|
||||
}
|
||||
|
||||
const string& vvp_fun_signal_string_sa::get_string() const
|
||||
{
|
||||
return value_;
|
||||
}
|
||||
|
||||
vvp_fun_signal_string_aa::vvp_fun_signal_string_aa()
|
||||
{
|
||||
context_idx_ = vpip_add_item_to_context(this, vpip_peek_context_scope());
|
||||
|
|
@ -623,14 +628,41 @@ vvp_fun_signal_string_aa::~vvp_fun_signal_string_aa()
|
|||
assert(0);
|
||||
}
|
||||
|
||||
void vvp_fun_signal_string_aa::alloc_instance(vvp_context_t)
|
||||
void vvp_fun_signal_string_aa::alloc_instance(vvp_context_t context)
|
||||
{
|
||||
assert(0);
|
||||
string*bits = new std::string;
|
||||
vvp_set_context_item(context, context_idx_, bits);
|
||||
*bits = "";
|
||||
}
|
||||
|
||||
void vvp_fun_signal_string_aa::reset_instance(vvp_context_t)
|
||||
void vvp_fun_signal_string_aa::reset_instance(vvp_context_t context)
|
||||
{
|
||||
assert(0);
|
||||
string*bits = static_cast<std::string*>
|
||||
(vvp_get_context_item(context, context_idx_));
|
||||
*bits = "";
|
||||
}
|
||||
|
||||
#ifdef CHECK_WITH_VALGRIND
|
||||
void vvp_fun_signal_string_aa::free_instance(vvp_context_t context)
|
||||
{
|
||||
string*bits = static_cast<std::string*>
|
||||
(vvp_get_context_item(context, context_idx_));
|
||||
delete bits;
|
||||
}
|
||||
#endif
|
||||
|
||||
void vvp_fun_signal_string_aa::recv_string(vvp_net_ptr_t ptr, const std::string&bit, vvp_context_t context)
|
||||
{
|
||||
assert(ptr.port() == 0);
|
||||
assert(context);
|
||||
|
||||
string*bits = static_cast<std::string*>
|
||||
(vvp_get_context_item(context, context_idx_));
|
||||
|
||||
if (*bits != bit) {
|
||||
*bits = bit;
|
||||
ptr.ptr()->send_string(bit, context);
|
||||
}
|
||||
}
|
||||
|
||||
unsigned vvp_fun_signal_string_aa::value_size() const
|
||||
|
|
@ -662,6 +694,14 @@ double vvp_fun_signal_string_aa::real_value() const
|
|||
return 0.0;
|
||||
}
|
||||
|
||||
const std::string& vvp_fun_signal_string_aa::get_string() const
|
||||
{
|
||||
string*bits = static_cast<std::string*>
|
||||
(vthread_get_rd_context_item(context_idx_));
|
||||
|
||||
return *bits;
|
||||
}
|
||||
|
||||
void* vvp_fun_signal_string_aa::operator new(std::size_t size)
|
||||
{
|
||||
return vvp_net_fun_t::heap_.alloc(size);
|
||||
|
|
|
|||
|
|
@ -270,7 +270,7 @@ class vvp_fun_signal_string : public vvp_fun_signal_base {
|
|||
|
||||
unsigned size() const { return 1; }
|
||||
|
||||
inline const std::string& get_string() const { return value_; }
|
||||
virtual const std::string& get_string() const =0;
|
||||
|
||||
protected:
|
||||
std::string value_;
|
||||
|
|
@ -286,6 +286,11 @@ class vvp_fun_signal_string_sa : public vvp_fun_signal_string {
|
|||
|
||||
void recv_string(vvp_net_ptr_t port, const std::string&bit,
|
||||
vvp_context_t context);
|
||||
|
||||
const std::string& get_string() const;
|
||||
|
||||
private:
|
||||
std::string value_;
|
||||
};
|
||||
|
||||
/*
|
||||
|
|
@ -302,6 +307,8 @@ class vvp_fun_signal_string_aa : public vvp_fun_signal_string, public automatic_
|
|||
#ifdef CHECK_WITH_VALGRIND
|
||||
void free_instance(vvp_context_t context);
|
||||
#endif
|
||||
void recv_string(vvp_net_ptr_t port, const std::string&bit,
|
||||
vvp_context_t context);
|
||||
|
||||
// Get information about the vector value.
|
||||
unsigned value_size() const;
|
||||
|
|
@ -309,6 +316,7 @@ class vvp_fun_signal_string_aa : public vvp_fun_signal_string, public automatic_
|
|||
vvp_scalar_t scalar_value(unsigned idx) const;
|
||||
void vec4_value(vvp_vector4_t&) const;
|
||||
double real_value() const;
|
||||
const std::string& get_string() const;
|
||||
void get_signal_value(struct t_vpi_value*vp);
|
||||
|
||||
public: // These objects are only permallocated.
|
||||
|
|
|
|||
Loading…
Reference in New Issue