From 4b1a8a3b667d133fc583ba40e20192f3f4e520da Mon Sep 17 00:00:00 2001 From: "Emil J. Tywoniak" Date: Fri, 11 Jul 2025 18:27:19 +0200 Subject: [PATCH] libparse: add LibertyExpression::str for testing --- passes/techmap/dfflibmap.cc | 1 + passes/techmap/libparse.cc | 41 +++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/passes/techmap/dfflibmap.cc b/passes/techmap/dfflibmap.cc index f0b0ef20b..ae9498a9c 100644 --- a/passes/techmap/dfflibmap.cc +++ b/passes/techmap/dfflibmap.cc @@ -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)) { diff --git a/passes/techmap/libparse.cc b/passes/techmap/libparse.cc index 85ed35ea1..0df7af347 100644 --- a/passes/techmap/libparse.cc +++ b/passes/techmap/libparse.cc @@ -306,6 +306,47 @@ bool LibertyExpression::eval(dict& 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)