foreach multiple indices through the pform.

This commit is contained in:
Stephen Williams 2014-08-25 14:58:57 -07:00
parent fe8e7a6261
commit 9fa764285a
5 changed files with 29 additions and 15 deletions

View File

@ -336,9 +336,13 @@ PForce::~PForce()
delete expr_;
}
PForeach::PForeach(perm_string av, perm_string ix, Statement*s)
: array_var_(av), index_var_(ix), statement_(s)
PForeach::PForeach(perm_string av, const list<perm_string>&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()

View File

@ -445,7 +445,7 @@ class PForce : public Statement {
class PForeach : public Statement {
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();
virtual NetProc* elaborate(Design*des, NetScope*scope) const;
@ -455,7 +455,7 @@ class PForeach : public Statement {
private:
perm_string array_var_;
perm_string index_var_;
std::vector<perm_string> index_vars_;
Statement*statement_;
};

View File

@ -4591,9 +4591,15 @@ NetForce* PForce::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.
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);
ivl_assert(*this, idx_sig);

View File

@ -728,19 +728,18 @@ PForeach* pform_make_foreach(const struct vlltype&loc,
perm_string use_name = lex_strings.make(name);
delete[]name;
perm_string use_index = loop_vars->front();
loop_vars->pop_front();
if (! loop_vars->empty()) {
cerr << loc.get_fileline() << ": sorry: "
<< "Multi-dimension foreach indices not supported." << endl;
if (loop_vars==0 || loop_vars->empty()) {
cerr << loc.get_fileline() << ": error: "
<< "No loop variables at all in foreach index." << endl;
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);
delete loop_vars;
return fe;
}

View File

@ -973,8 +973,13 @@ void PForeach::dump(ostream&fd, unsigned ind) const
{
fd << setw(ind) << "" << "foreach "
<< "variable=" << array_var_
<< ", index=" << index_var_
<< " /* " << get_fileline() << " */" << endl;
<< ", indices=[";
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);
}