diff options
author | whitequark <whitequark@whitequark.org> | 2020-04-14 03:25:22 +0000 |
---|---|---|
committer | whitequark <whitequark@whitequark.org> | 2020-04-15 14:14:50 +0000 |
commit | 2106f78bb14eab6c234a0a367ec32ff6680fc6d9 (patch) | |
tree | dfe37680bcce6a05d8974e3645fc7afc1ca9f0cb /frontends/ast | |
parent | f44b287f8e36684607447beb05556f1a5a34d625 (diff) | |
download | yosys-2106f78bb14eab6c234a0a367ec32ff6680fc6d9.tar.gz yosys-2106f78bb14eab6c234a0a367ec32ff6680fc6d9.tar.bz2 yosys-2106f78bb14eab6c234a0a367ec32ff6680fc6d9.zip |
ast/simplify: improve enum handling.
Before this commit, enum values were serialized as attributes of form
\enum_<width>_<value>
where <value> was a decimal signed integer.
This has multiple drawbacks:
* Enums with large values would be hard to process for downstream
tooling that cannot parse arbitrary precision decimals. (In fact
Yosys also did not correctly process enums with large values,
and would overflow `int`.)
* Enum value attributes were not confined to their own namespace,
making it harder for downstream tooling to enumerate all such
attributes, as opposed to looking up any specific value.
* Enum values could not include x or z, which are explicitly
permitted in the SystemVerilog standard.
After this commit, enum values are serialized as attributes of form
\enum_value_<value>
where <value> is a bit sequence of the appropriate width.
Diffstat (limited to 'frontends/ast')
-rw-r--r-- | frontends/ast/simplify.cc | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/frontends/ast/simplify.cc b/frontends/ast/simplify.cc index b87af0f8c..5e7518f68 100644 --- a/frontends/ast/simplify.cc +++ b/frontends/ast/simplify.cc @@ -907,9 +907,7 @@ bool AstNode::simplify(bool const_fold, bool at_zero, bool in_lvalue, int stage, ); } //start building attribute string - std::string enum_item_str = "\\enum_"; - enum_item_str.append(std::to_string(width)); - enum_item_str.append("_"); + std::string enum_item_str = "\\enum_value_"; //get enum item value if(enum_item->children[0]->type != AST_CONSTANT){ log_error("expected const, got %s for %s (%s)\n", @@ -917,8 +915,8 @@ bool AstNode::simplify(bool const_fold, bool at_zero, bool in_lvalue, int stage, enum_item->str.c_str(), enum_node->str.c_str() ); } - int val = enum_item->children[0]->asInt(is_signed); - enum_item_str.append(std::to_string(val)); + RTLIL::Const val = enum_item->children[0]->bitsAsConst(width, is_signed); + enum_item_str.append(val.as_string()); //set attribute for available val to enum item name mappings attributes[enum_item_str.c_str()] = mkconst_str(enum_item->str); } |