mirror of
https://github.com/YosysHQ/yosys
synced 2025-07-20 19:32:05 +00:00
libparse: add LibertyExpression::str for testing
This commit is contained in:
parent
6ee01308f2
commit
4b1a8a3b66
2 changed files with 42 additions and 0 deletions
|
@ -117,6 +117,7 @@ static bool parse_next_state(const LibertyAst *cell, const LibertyAst *attr, std
|
|||
// the next_state variable isn't just a pin name; perhaps this is an enable?
|
||||
auto helper = LibertyExpression::Lexer(expr);
|
||||
auto tree = LibertyExpression::parse(helper);
|
||||
log_debug("liberty expression:\n%s\n", tree.str().c_str());
|
||||
|
||||
if (tree.kind == LibertyExpression::Kind::EMPTY) {
|
||||
if (!warned_cells.count(cell_name)) {
|
||||
|
|
|
@ -306,6 +306,47 @@ bool LibertyExpression::eval(dict<std::string, bool>& values) {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string LibertyExpression::str(int indent)
|
||||
{
|
||||
std::string prefix;
|
||||
prefix = std::string(indent, ' ');
|
||||
switch (kind) {
|
||||
case AND:
|
||||
prefix += "(and ";
|
||||
break;
|
||||
case OR:
|
||||
prefix += "(or ";
|
||||
break;
|
||||
case NOT:
|
||||
prefix += "(not ";
|
||||
break;
|
||||
case XOR:
|
||||
prefix += "(xor ";
|
||||
break;
|
||||
case PIN:
|
||||
prefix += "(pin \"" + name + "\"";
|
||||
break;
|
||||
case EMPTY:
|
||||
prefix += "(";
|
||||
break;
|
||||
default:
|
||||
log_assert(false);
|
||||
}
|
||||
size_t add_indent = prefix.length();
|
||||
bool first = true;
|
||||
for (auto child : children) {
|
||||
if (!first) {
|
||||
prefix += "\n" + child.str(indent + add_indent);
|
||||
} else {
|
||||
prefix += child.str(0);
|
||||
}
|
||||
first = false;
|
||||
}
|
||||
prefix += ")";
|
||||
return prefix;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
int LibertyParser::lexer(std::string &str)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue