summaryrefslogtreecommitdiff
path: root/frontends
diff options
context:
space:
mode:
authorClifford Wolf <clifford@clifford.at>2013-12-04 21:19:54 +0100
committerClifford Wolf <clifford@clifford.at>2013-12-04 21:19:54 +0100
commit3c220e0b3271af2505f45c9828d878a492831174 (patch)
treec73b023725bcbb42e42fbf2a9117b7be53dbb9f5 /frontends
parent4a4a3fc3377243d85100b829a0f6b785376cce9f (diff)
Added support for $clog2 system function
Diffstat (limited to 'frontends')
-rw-r--r--frontends/ast/simplify.cc24
1 files changed, 20 insertions, 4 deletions
diff --git a/frontends/ast/simplify.cc b/frontends/ast/simplify.cc
index ae2f0caa..94b588f2 100644
--- a/frontends/ast/simplify.cc
+++ b/frontends/ast/simplify.cc
@@ -1052,11 +1052,27 @@ skip_dynamic_range_lvalue_expansion:;
// replace function and task calls with the code from the function or task
if ((type == AST_FCALL || type == AST_TCALL) && !str.empty())
{
- if (type == AST_FCALL) {
- if (current_scope.count(str) == 0 || current_scope[str]->type != AST_FUNCTION) {
- current_ast_mod->dumpAst(stderr, "> ");
- log_error("Can't resolve function name `%s' at %s:%d.\n", str.c_str(), filename.c_str(), linenum);
+ if (type == AST_FCALL)
+ {
+ if (str == "\\$clog2")
+ {
+ AstNode *buf = children[0]->clone();
+ while (buf->simplify(true, false, false, stage, width_hint, sign_hint)) { }
+ if (!buf->type == AST_CONSTANT)
+ log_error("Failed to evaluate system function `%s' with non-constant value at %s:%d.\n", str.c_str(), filename.c_str(), linenum);
+
+ RTLIL::Const arg_value = buf->bitsAsConst();
+ uint32_t result = 0;
+ for (size_t i = 0; i < arg_value.bits.size(); i++)
+ if (arg_value.bits.at(i) == RTLIL::State::S1)
+ result = i;
+
+ newNode = mkconst_int(result, false);
+ goto apply_newNode;
}
+
+ if (current_scope.count(str) == 0 || current_scope[str]->type != AST_FUNCTION)
+ log_error("Can't resolve function name `%s' at %s:%d.\n", str.c_str(), filename.c_str(), linenum);
}
if (type == AST_TCALL) {
if (current_scope.count(str) == 0 || current_scope[str]->type != AST_TASK)