foreach multiple indices through the pform.
This commit is contained in:
parent
fe8e7a6261
commit
9fa764285a
|
|
@ -336,9 +336,13 @@ PForce::~PForce()
|
||||||
delete expr_;
|
delete expr_;
|
||||||
}
|
}
|
||||||
|
|
||||||
PForeach::PForeach(perm_string av, perm_string ix, Statement*s)
|
PForeach::PForeach(perm_string av, const list<perm_string>&ix, Statement*s)
|
||||||
: array_var_(av), index_var_(ix), statement_(s)
|
: array_var_(av), index_vars_(ix.size()), 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()
|
PForeach::~PForeach()
|
||||||
|
|
|
||||||
|
|
@ -445,7 +445,7 @@ class PForce : public Statement {
|
||||||
|
|
||||||
class PForeach : public Statement {
|
class PForeach : public Statement {
|
||||||
public:
|
public:
|
||||||
explicit PForeach(perm_string var, perm_string ix, Statement*stmt);
|
explicit PForeach(perm_string var, const std::list<perm_string>&ix, Statement*stmt);
|
||||||
~PForeach();
|
~PForeach();
|
||||||
|
|
||||||
virtual NetProc* elaborate(Design*des, NetScope*scope) const;
|
virtual NetProc* elaborate(Design*des, NetScope*scope) const;
|
||||||
|
|
@ -455,7 +455,7 @@ class PForeach : public Statement {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
perm_string array_var_;
|
perm_string array_var_;
|
||||||
perm_string index_var_;
|
std::vector<perm_string> index_vars_;
|
||||||
Statement*statement_;
|
Statement*statement_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4591,9 +4591,15 @@ NetForce* PForce::elaborate(Design*des, NetScope*scope) const
|
||||||
*/
|
*/
|
||||||
NetProc* PForeach::elaborate(Design*des, NetScope*scope) const
|
NetProc* PForeach::elaborate(Design*des, NetScope*scope) const
|
||||||
{
|
{
|
||||||
|
if (index_vars_.size() != 1) {
|
||||||
|
cerr << get_fileline() << ": sorry: "
|
||||||
|
<< "Multi-index foreach loops not supported." << endl;
|
||||||
|
des->errors += 1;
|
||||||
|
}
|
||||||
|
|
||||||
// Get the signal for the index variable.
|
// Get the signal for the index variable.
|
||||||
pform_name_t index_name;
|
pform_name_t index_name;
|
||||||
index_name.push_back(name_component_t(index_var_));
|
index_name.push_back(name_component_t(index_vars_[0]));
|
||||||
NetNet*idx_sig = des->find_signal(scope, index_name);
|
NetNet*idx_sig = des->find_signal(scope, index_name);
|
||||||
ivl_assert(*this, idx_sig);
|
ivl_assert(*this, idx_sig);
|
||||||
|
|
||||||
|
|
|
||||||
15
pform.cc
15
pform.cc
|
|
@ -728,19 +728,18 @@ PForeach* pform_make_foreach(const struct vlltype&loc,
|
||||||
perm_string use_name = lex_strings.make(name);
|
perm_string use_name = lex_strings.make(name);
|
||||||
delete[]name;
|
delete[]name;
|
||||||
|
|
||||||
perm_string use_index = loop_vars->front();
|
if (loop_vars==0 || loop_vars->empty()) {
|
||||||
loop_vars->pop_front();
|
cerr << loc.get_fileline() << ": error: "
|
||||||
|
<< "No loop variables at all in foreach index." << endl;
|
||||||
if (! loop_vars->empty()) {
|
|
||||||
cerr << loc.get_fileline() << ": sorry: "
|
|
||||||
<< "Multi-dimension foreach indices not supported." << endl;
|
|
||||||
error_count += 1;
|
error_count += 1;
|
||||||
}
|
}
|
||||||
delete loop_vars;
|
|
||||||
|
|
||||||
PForeach*fe = new PForeach(use_name, use_index, stmt);
|
ivl_assert(loc, loop_vars);
|
||||||
|
PForeach*fe = new PForeach(use_name, *loop_vars, stmt);
|
||||||
FILE_NAME(fe, loc);
|
FILE_NAME(fe, loc);
|
||||||
|
|
||||||
|
delete loop_vars;
|
||||||
|
|
||||||
return fe;
|
return fe;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -973,8 +973,13 @@ void PForeach::dump(ostream&fd, unsigned ind) const
|
||||||
{
|
{
|
||||||
fd << setw(ind) << "" << "foreach "
|
fd << setw(ind) << "" << "foreach "
|
||||||
<< "variable=" << array_var_
|
<< "variable=" << array_var_
|
||||||
<< ", index=" << index_var_
|
<< ", indices=[";
|
||||||
<< " /* " << get_fileline() << " */" << endl;
|
for (size_t idx = 0 ; idx < index_vars_.size() ; idx += 1) {
|
||||||
|
if (idx > 0) fd << ",";
|
||||||
|
fd << index_vars_[idx];
|
||||||
|
}
|
||||||
|
|
||||||
|
fd << "] /* " << get_fileline() << " */" << endl;
|
||||||
statement_->dump(fd, ind+3);
|
statement_->dump(fd, ind+3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue