From 79771b17b2bfc3ecb9cea6fafa57f6935d80cbd5 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Mon, 18 Apr 2022 10:23:23 +0200 Subject: [PATCH] Consolidate functions for task port declaration With the recent refactorings pform_make_task_ports_vec() and do_make_task_ports() are now very similar. Consolidate them into a single function. Signed-off-by: Lars-Peter Clausen --- pform.cc | 76 +++++++++++--------------------------------------------- 1 file changed, 15 insertions(+), 61 deletions(-) diff --git a/pform.cc b/pform.cc index c0d0595c3..e9deb4ba8 100644 --- a/pform.cc +++ b/pform.cc @@ -2749,31 +2749,33 @@ void pform_makewire(const struct vlltype&li, * constraints as those of tasks, so this works fine. Functions have * no output or inout ports. */ -static vector*pform_make_task_ports_vec(const struct vlltype&loc, - NetNet::PortType pt, - vector_type_t *vec_type, - list*ports, - bool allow_implicit) +vector*pform_make_task_ports(const struct vlltype&loc, + NetNet::PortType pt, + data_type_t*vtype, + list*ports, + bool allow_implicit) { assert(pt != NetNet::PIMPLICIT && pt != NetNet::NOT_A_PORT); assert(ports); - vector*res = new vector(0); + vector*res = new vector(0); PWSRType rt = SR_BOTH; - if (allow_implicit && vec_type->implicit_flag) + // If this is a non-ansi port declaration and the type is an implicit type + // this is only a port declaration. + vector_type_t*vec_type = dynamic_cast(vtype); + if (allow_implicit && (!vtype || (vec_type && vec_type->implicit_flag))) rt = SR_PORT; - for (list::iterator cur = ports->begin() - ; cur != ports->end() ; ++ cur ) { + for (list::iterator cur = ports->begin(); + cur != ports->end(); ++cur) { perm_string &name = cur->name; - /* Look for a preexisting wire. If it exists, set the - port direction. If not, create it. */ PWire*curw = pform_get_or_make_wire(loc, name, NetNet::IMPLICIT_REG, pt, rt); if (rt == SR_BOTH) - curw->set_data_type(vec_type); + curw->set_data_type(vtype); + pform_set_net_range(curw, vec_type, rt); if (cur->udims) { @@ -2784,56 +2786,8 @@ static vector*pform_make_task_ports_vec(const struct vlltype&lo res->push_back(pform_tf_port_t(curw)); } - return res; -} - -static vector*do_make_task_ports(const struct vlltype&loc, - NetNet::PortType pt, - data_type_t*data_type, - list*ports) -{ - assert(pt != NetNet::PIMPLICIT && pt != NetNet::NOT_A_PORT); - assert(ports); - vector*res = new vector(0); - PWSRType rt = data_type ? SR_BOTH : SR_PORT; - - for (list::iterator cur = ports->begin() - ; cur != ports->end() ; ++cur) { - perm_string &name = cur->name; - - PWire*curw = pform_get_or_make_wire(loc, name, NetNet::IMPLICIT_REG, - pt, rt); - - if (data_type) - curw->set_data_type(data_type); - - if (cur->udims) { - if (pform_requires_sv(loc, "Task/function port with unpacked dimensions")) - curw->set_unpacked_idx(*cur->udims); - } - - res->push_back(pform_tf_port_t(curw)); - } - return res; -} - -vector*pform_make_task_ports(const struct vlltype&loc, - NetNet::PortType pt, - data_type_t*vtype, - list*ports, - bool allow_implicit) -{ - vector*ret = NULL; - - if (vector_type_t*vec_type = dynamic_cast (vtype)) { - ret = pform_make_task_ports_vec(loc, pt, vec_type, ports, - allow_implicit); - } else { - ret = do_make_task_ports(loc, pt, vtype, ports); - } - delete ports; - return ret; + return res; } /*