diff options
author | Clifford Wolf <clifford@clifford.at> | 2019-08-16 11:47:51 +0200 |
---|---|---|
committer | Clifford Wolf <clifford@clifford.at> | 2019-08-16 11:47:51 +0200 |
commit | 4a57b7e1abe148b36827a393fd7fe62e46c2b1a7 (patch) | |
tree | 5c3f2bea48424d918d3eea9a225faa5e95d4591a /passes/pmgen/test_pmgen.pmg | |
parent | 016036f247f9538016f4e8cbdb889ac631f4a5c0 (diff) | |
download | yosys-4a57b7e1abe148b36827a393fd7fe62e46c2b1a7.tar.gz yosys-4a57b7e1abe148b36827a393fd7fe62e46c2b1a7.tar.bz2 yosys-4a57b7e1abe148b36827a393fd7fe62e46c2b1a7.zip |
Refactor demo_reduce into test_pmgen
Signed-off-by: Clifford Wolf <clifford@clifford.at>
Diffstat (limited to 'passes/pmgen/test_pmgen.pmg')
-rw-r--r-- | passes/pmgen/test_pmgen.pmg | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/passes/pmgen/test_pmgen.pmg b/passes/pmgen/test_pmgen.pmg new file mode 100644 index 000000000..ccb37e553 --- /dev/null +++ b/passes/pmgen/test_pmgen.pmg @@ -0,0 +1,83 @@ +pattern reduce + +state <IdString> portname +udata <vector<pair<Cell*, IdString>>> chain longest_chain +udata <pool<Cell*>> non_first_cells +udata <SigSpec> leaves + +code + non_first_cells.clear(); + subpattern(setup); +endcode + +match first + select first->type.in($_AND_, $_OR_, $_XOR_) + filter !non_first_cells.count(first) +endmatch + +code + leaves = SigSpec(); + longest_chain.clear(); + chain.push_back(make_pair(first, \A)); + subpattern(tail); + chain.back().second = \B; + subpattern(tail); +finally + chain.pop_back(); + log_assert(chain.empty()); + accept; +endcode + +// ------------------------------------------------------------------ + +subpattern setup + +match first + select first->type.in($_AND_, $_OR_, $_XOR_) +endmatch + +code portname + portname = \A; + branch; + portname = \B; +endcode + +match next + select nusers(port(next, \Y)) == 2 + select next->type.in($_AND_, $_OR_, $_XOR_) + index <IdString> next->type === first->type + index <SigSpec> port(next, \Y) === port(first, portname) +endmatch + +code + non_first_cells.insert(next); +endcode + +// ------------------------------------------------------------------ + +subpattern tail +arg first + +match next + semioptional + select nusers(port(next, \Y)) == 2 + select next->type.in($_AND_, $_OR_, $_XOR_) + index <IdString> next->type === chain.back().first->type + index <SigSpec> port(next, \Y) === port(chain.back().first, chain.back().second) +endmatch + +code + if (next) { + chain.push_back(make_pair(next, \A)); + subpattern(tail); + chain.back().second = \B; + subpattern(tail); + } else { + if (GetSize(chain) > GetSize(longest_chain)) + longest_chain = chain; + leaves.append(port(chain.back().first, chain.back().second)); + } +finally + if (next) + chain.pop_back(); +endcode |