Skip to content

Commit

Permalink
Merge pull request #992 from larsclausen/tf-named-ports
Browse files Browse the repository at this point in the history
Add support for binding function/task arguments by name
  • Loading branch information
caryr authored Aug 21, 2023
2 parents 8bcdb5d + 250c456 commit e1f5dbc
Show file tree
Hide file tree
Showing 106 changed files with 1,625 additions and 530 deletions.
3 changes: 2 additions & 1 deletion Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ O = main.o async.o design_dump.o discipline.o dup_expr.o elaborate.o \
net_event.o net_expr.o net_func.o \
net_func_eval.o net_link.o net_modulo.o \
net_nex_input.o net_nex_output.o net_proc.o net_scope.o net_tran.o \
net_udp.o pad_to_width.o parse.o parse_misc.o pform.o pform_analog.o \
net_udp.o map_named_args.o \
pad_to_width.o parse.o parse_misc.o pform.o pform_analog.o \
pform_disciplines.o pform_dump.o pform_package.o pform_pclass.o \
pform_types.o \
symbol_search.o sync.o sys_funcs.o verinum.o verireal.o vpi_modules.o target.o \
Expand Down
70 changes: 19 additions & 51 deletions PExpr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,8 @@ PEAssignPattern::PEAssignPattern()
}

PEAssignPattern::PEAssignPattern(const list<PExpr*>&p)
: parms_(p.size())
: parms_(p.begin(), p.end())
{
size_t idx = 0;
for (list<PExpr*>::const_iterator cur = p.begin()
; cur != p.end() ; ++cur) {
parms_[idx] = *cur;
idx += 1;
}
}

PEAssignPattern::~PEAssignPattern()
Expand Down Expand Up @@ -221,12 +215,12 @@ PEBShift::~PEBShift()
{
}

PECallFunction::PECallFunction(const pform_name_t&n, const vector<PExpr *> &parms)
PECallFunction::PECallFunction(const pform_name_t &n, const vector<named_pexpr_t> &parms)
: path_(n), parms_(parms), is_overridden_(false)
{
}

PECallFunction::PECallFunction(PPackage*pkg, const pform_name_t&n, const vector<PExpr *> &parms)
PECallFunction::PECallFunction(PPackage *pkg, const pform_name_t &n, const vector<named_pexpr_t> &parms)
: path_(pkg, n), parms_(parms), is_overridden_(false)
{
}
Expand All @@ -239,17 +233,12 @@ static pform_name_t pn_from_ps(perm_string n)
return tmp;
}

PECallFunction::PECallFunction(PPackage*pkg, const pform_name_t &n, const list<PExpr *> &parms)
: path_(pkg, n), parms_(parms.size()), is_overridden_(false)
PECallFunction::PECallFunction(PPackage *pkg, const pform_name_t &n, const list<named_pexpr_t> &parms)
: path_(pkg, n), parms_(parms.begin(), parms.end()), is_overridden_(false)
{
int tmp_idx = 0;
ivl_assert(*this, parms_.size() == parms.size());
for (list<PExpr*>::const_iterator idx = parms.begin()
; idx != parms.end() ; ++idx)
parms_[tmp_idx++] = *idx;
}

PECallFunction::PECallFunction(perm_string n, const vector<PExpr*>&parms)
PECallFunction::PECallFunction(perm_string n, const vector<named_pexpr_t> &parms)
: path_(pn_from_ps(n)), parms_(parms), is_overridden_(false)
{
}
Expand All @@ -260,24 +249,14 @@ PECallFunction::PECallFunction(perm_string n)
}

// NOTE: Anachronism. Try to work all use of svector out.
PECallFunction::PECallFunction(const pform_name_t&n, const list<PExpr *> &parms)
: path_(n), parms_(parms.size()), is_overridden_(false)
PECallFunction::PECallFunction(const pform_name_t &n, const list<named_pexpr_t> &parms)
: path_(n), parms_(parms.begin(), parms.end()), is_overridden_(false)
{
int tmp_idx = 0;
ivl_assert(*this, parms_.size() == parms.size());
for (list<PExpr*>::const_iterator idx = parms.begin()
; idx != parms.end() ; ++idx)
parms_[tmp_idx++] = *idx;
}

PECallFunction::PECallFunction(perm_string n, const list<PExpr*>&parms)
: path_(pn_from_ps(n)), parms_(parms.size()), is_overridden_(false)
PECallFunction::PECallFunction(perm_string n, const list<named_pexpr_t> &parms)
: path_(pn_from_ps(n)), parms_(parms.begin(), parms.end()), is_overridden_(false)
{
int tmp_idx = 0;
ivl_assert(*this, parms_.size() == parms.size());
for (list<PExpr*>::const_iterator idx = parms.begin()
; idx != parms.end() ; ++idx)
parms_[tmp_idx++] = *idx;
}

PECallFunction::~PECallFunction()
Expand All @@ -286,31 +265,25 @@ PECallFunction::~PECallFunction()

void PECallFunction::declare_implicit_nets(LexicalScope*scope, NetNet::Type type)
{
for (unsigned idx = 0 ; idx < parms_.size() ; idx += 1) {
if (parms_[idx])
parms_[idx]->declare_implicit_nets(scope, type);
for (const auto &parm : parms_) {
if (parm.parm)
parm.parm->declare_implicit_nets(scope, type);
}
}

bool PECallFunction::has_aa_term(Design*des, NetScope*scope) const
{
bool flag = false;
for (unsigned idx = 0 ; idx < parms_.size() ; idx += 1) {
if (parms_[idx])
flag |= parms_[idx]->has_aa_term(des, scope);
for (const auto &parm : parms_) {
if (parm.parm)
flag |= parm.parm->has_aa_term(des, scope);
}
return flag;
}

PEConcat::PEConcat(const list<PExpr*>&p, PExpr*r)
: parms_(p.size()), width_modes_(SIZED, p.size()), repeat_(r)
: parms_(p.begin(), p.end()), width_modes_(SIZED, p.size()), repeat_(r)
{
int tmp_idx = 0;
ivl_assert(*this, parms_.size() == p.size());
for (list<PExpr*>::const_iterator idx = p.begin()
; idx != p.end() ; ++idx)
parms_[tmp_idx++] = *idx;

tested_scope_ = 0;
repeat_count_ = 1;
}
Expand Down Expand Up @@ -493,14 +466,9 @@ PENewClass::PENewClass(void)
{
}

PENewClass::PENewClass(const list<PExpr*>&p, data_type_t *class_type)
: parms_(p.size()), class_type_(class_type)
PENewClass::PENewClass(const list<named_pexpr_t> &p, data_type_t *class_type)
: parms_(p.begin(), p.end()), class_type_(class_type)
{
size_t tmp_idx = 0;
for (list<PExpr*>::const_iterator cur = p.begin()
; cur != p.end() ; ++ cur) {
parms_[tmp_idx++] = *cur;
}
}

PENewClass::~PENewClass()
Expand Down
18 changes: 9 additions & 9 deletions PExpr.h
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ class PENewClass : public PExpr {
// New without (or with default) constructor
explicit PENewClass ();
// New with constructor arguments
explicit PENewClass (const std::list<PExpr*>&p,
explicit PENewClass (const std::list<named_pexpr_t> &p,
data_type_t *class_type = nullptr);

~PENewClass();
Expand All @@ -592,7 +592,7 @@ class PENewClass : public PExpr {
NetExpr*obj, unsigned flags) const;

private:
std::vector<PExpr*>parms_;
std::vector<named_pexpr_t> parms_;
data_type_t *class_type_;
};

Expand Down Expand Up @@ -895,20 +895,20 @@ class PETernary : public PExpr {
*/
class PECallFunction : public PExpr {
public:
explicit PECallFunction(const pform_name_t&n, const std::vector<PExpr *> &parms);
explicit PECallFunction(const pform_name_t &n, const std::vector<named_pexpr_t> &parms);
// Call function defined in package.
explicit PECallFunction(PPackage*pkg, const pform_name_t&n, const std::list<PExpr *> &parms);
explicit PECallFunction(PPackage *pkg, const pform_name_t &n, const std::list<named_pexpr_t> &parms);

// Used to convert a user function called as a task
explicit PECallFunction(PPackage*pkg, const pform_name_t&n, const std::vector<PExpr *> &parms);
explicit PECallFunction(PPackage *pkg, const pform_name_t &n, const std::vector<named_pexpr_t> &parms);

// Call of system function (name is not hierarchical)
explicit PECallFunction(perm_string n, const std::vector<PExpr *> &parms);
explicit PECallFunction(perm_string n, const std::vector<named_pexpr_t> &parms);
explicit PECallFunction(perm_string n);

// std::list versions. Should be removed!
explicit PECallFunction(const pform_name_t&n, const std::list<PExpr *> &parms);
explicit PECallFunction(perm_string n, const std::list<PExpr *> &parms);
explicit PECallFunction(const pform_name_t &n, const std::list<named_pexpr_t> &parms);
explicit PECallFunction(perm_string n, const std::list<named_pexpr_t> &parms);

~PECallFunction();

Expand All @@ -929,7 +929,7 @@ class PECallFunction : public PExpr {

private:
pform_scoped_name_t path_;
std::vector<PExpr *> parms_;
std::vector<named_pexpr_t> parms_;

// For system functions.
bool is_overridden_;
Expand Down
4 changes: 2 additions & 2 deletions PGate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ PGModule::PGModule(perm_string type, perm_string name, list<PExpr*>*pins)
}

PGModule::PGModule(perm_string type, perm_string name,
named<PExpr*>*pins, unsigned npins)
named_pexpr_t *pins, unsigned npins)
: PGate(name, 0), bound_type_(0), type_(type), overrides_(0), pins_(pins),
npins_(npins), parms_(0), nparms_(0)
{
Expand All @@ -292,7 +292,7 @@ void PGModule::set_parameters(list<PExpr*>*o)
overrides_ = o;
}

void PGModule::set_parameters(named<PExpr*>*pa, unsigned npa)
void PGModule::set_parameters(named_pexpr_t *pa, unsigned npa)
{
ivl_assert(*this, parms_ == 0);
ivl_assert(*this, overrides_ == 0);
Expand Down
8 changes: 4 additions & 4 deletions PGate.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ class PGModule : public PGate {
// If the binding of ports is by name, this constructor takes
// the bindings and stores them for later elaboration.
explicit PGModule(perm_string type, perm_string name,
named<PExpr*>*pins, unsigned npins);
named_pexpr_t *pins, unsigned npins);

// If the module type is known by design, then use this
// constructor.
Expand All @@ -215,7 +215,7 @@ class PGModule : public PGate {
// Parameter overrides can come as an ordered list, or a set
// of named expressions.
void set_parameters(std::list<PExpr*>*o);
void set_parameters(named<PExpr*>*pa, unsigned npa);
void set_parameters(named_pexpr_t *pa, unsigned npa);

std::map<perm_string,PExpr*> attributes;

Expand All @@ -232,11 +232,11 @@ class PGModule : public PGate {
Module*bound_type_;
perm_string type_;
std::list<PExpr*>*overrides_;
named<PExpr*>*pins_;
named_pexpr_t *pins_;
unsigned npins_;

// These members support parameter override by name
named<PExpr*>*parms_;
named_pexpr_t *parms_;
unsigned nparms_;

friend class delayed_elaborate_scope_mod_instances;
Expand Down
7 changes: 4 additions & 3 deletions PSpec.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@

# include "PSpec.h"

PSpecPath::PSpecPath(unsigned src_cnt, unsigned dst_cnt, char polarity,
bool full_flag)
PSpecPath::PSpecPath(const std::list<perm_string> &src_list,
const std::list<perm_string> &dst_list,
char polarity, bool full_flag)
: conditional(false), condition(0), edge(0),
src(src_cnt), dst(dst_cnt),
src(src_list.begin(), src_list.end()), dst(dst_list.begin(), dst_list.end()),
data_source_expression(0)
{
full_flag_ = full_flag;
Expand Down
6 changes: 4 additions & 2 deletions PSpec.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
# include "LineInfo.h"
# include "StringHeap.h"
# include <vector>
# include <list>

class PExpr;

Expand Down Expand Up @@ -56,8 +57,9 @@ class PExpr;
class PSpecPath : public LineInfo {

public:
PSpecPath(unsigned src_cnt, unsigned dst_cnt, char polarity,
bool full_flag);
PSpecPath(const std::list<perm_string> &src_list,
const std::list<perm_string> &dst_list,
char polarity, bool full_flag);
~PSpecPath();

void elaborate(class Design*des, class NetScope*scope) const;
Expand Down
3 changes: 2 additions & 1 deletion PTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ class PTaskFunc : public PScope, public PNamedItem {
// default value expressions, if any.
void elaborate_sig_ports_(Design*des, NetScope*scope,
std::vector<NetNet*>&ports,
std::vector<NetExpr*>&pdefs) const;
std::vector<NetExpr*> &pdefs,
std::vector<perm_string> &port_names) const;

void dump_ports_(std::ostream&out, unsigned ind) const;

Expand Down
51 changes: 14 additions & 37 deletions Statement.cc
Original file line number Diff line number Diff line change
Expand Up @@ -166,37 +166,19 @@ PNamedItem::SymbolType PBlock::symbol_type() const
return BLOCK;
}

PCallTask::PCallTask(const pform_name_t&n, const list<PExpr*>&p)
: package_(0), path_(n), parms_(p.size())
PCallTask::PCallTask(const pform_name_t &n, const list<named_pexpr_t> &p)
: package_(0), path_(n), parms_(p.begin(), p.end())
{
list<PExpr*>::const_iterator cur = p.begin();
for (size_t idx = 0 ; idx < parms_.size() ; idx += 1) {
parms_[idx] = *cur;
++cur;
}
ivl_assert(*this, cur == p.end());
}

PCallTask::PCallTask(PPackage*pkg, const pform_name_t&n, const list<PExpr*>&p)
: package_(pkg), path_(n), parms_(p.size())
PCallTask::PCallTask(PPackage *pkg, const pform_name_t &n, const list<named_pexpr_t> &p)
: package_(pkg), path_(n), parms_(p.begin(), p.end())
{
list<PExpr*>::const_iterator cur = p.begin();
for (size_t idx = 0 ; idx < parms_.size() ; idx += 1) {
parms_[idx] = *cur;
++cur;
}
ivl_assert(*this, cur == p.end());
}

PCallTask::PCallTask(perm_string n, const list<PExpr*>&p)
: package_(0), parms_(p.size())
PCallTask::PCallTask(perm_string n, const list<named_pexpr_t> &p)
: package_(0), parms_(p.begin(), p.end())
{
list<PExpr*>::const_iterator cur = p.begin();
for (size_t idx = 0 ; idx < parms_.size() ; idx += 1) {
parms_[idx] = *cur;
++cur;
}
ivl_assert(*this, cur == p.end());
path_.push_back(name_component_t(n));
}

Expand Down Expand Up @@ -234,15 +216,14 @@ PCAssign::~PCAssign()
delete expr_;
}

PChainConstructor::PChainConstructor(const list<PExpr*>&parms)
: parms_(parms.size())
PChainConstructor::PChainConstructor(const list<named_pexpr_t> &parms)
: parms_(parms.begin(), parms.end())
{
}

PChainConstructor::PChainConstructor(const vector<named_pexpr_t> &parms)
: parms_(parms)
{
list<PExpr*>::const_iterator cur = parms.begin();
for (size_t idx = 0 ; idx < parms_.size() ; idx += 1) {
parms_[idx] = *cur;
++cur;
}
ivl_assert(*this, cur == parms.end());
}

PChainConstructor::~PChainConstructor()
Expand Down Expand Up @@ -350,12 +331,8 @@ PForce::~PForce()
}

PForeach::PForeach(perm_string av, const list<perm_string>&ix, Statement*s)
: array_var_(av), index_vars_(ix.size()), statement_(s)
: array_var_(av), index_vars_(ix.begin(), ix.end()), statement_(s)
{
size_t idx = 0;
for (list<perm_string>::const_iterator cur = ix.begin()
; cur != ix.end() ; ++cur)
index_vars_[idx++] = *cur;
}

PForeach::~PForeach()
Expand Down
Loading

0 comments on commit e1f5dbc

Please sign in to comment.