mirror of
https://github.com/YosysHQ/yosys
synced 2025-04-07 18:05:24 +00:00
Merge pull request #1918 from whitequark/simplify-improve_enum
ast/simplify: improve enum handling
This commit is contained in:
commit
2d436bc4f1
|
@ -443,8 +443,8 @@ Verilog Attributes and non-standard features
|
||||||
- The ``wiretype`` attribute is added by the verilog parser for wires of a
|
- The ``wiretype`` attribute is added by the verilog parser for wires of a
|
||||||
typedef'd type to indicate the type identifier.
|
typedef'd type to indicate the type identifier.
|
||||||
|
|
||||||
- Various ``enum_{width}_{value}`` attributes are added to wires of an
|
- Various ``enum_value_{value}`` attributes are added to wires of an enumerated type
|
||||||
enumerated type to give a map of possible enum items to their values.
|
to give a map of possible enum items to their values.
|
||||||
|
|
||||||
- The ``enum_base_type`` attribute is added to enum items to indicate which
|
- The ``enum_base_type`` attribute is added to enum items to indicate which
|
||||||
enum they belong to (enums -- anonymous and otherwise -- are
|
enum they belong to (enums -- anonymous and otherwise -- are
|
||||||
|
|
|
@ -931,9 +931,7 @@ bool AstNode::simplify(bool const_fold, bool at_zero, bool in_lvalue, int stage,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
//start building attribute string
|
//start building attribute string
|
||||||
std::string enum_item_str = "\\enum_";
|
std::string enum_item_str = "\\enum_value_";
|
||||||
enum_item_str.append(std::to_string(width));
|
|
||||||
enum_item_str.append("_");
|
|
||||||
//get enum item value
|
//get enum item value
|
||||||
if(enum_item->children[0]->type != AST_CONSTANT){
|
if(enum_item->children[0]->type != AST_CONSTANT){
|
||||||
log_error("expected const, got %s for %s (%s)\n",
|
log_error("expected const, got %s for %s (%s)\n",
|
||||||
|
@ -941,8 +939,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()
|
enum_item->str.c_str(), enum_node->str.c_str()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
int val = enum_item->children[0]->asInt(is_signed);
|
RTLIL::Const val = enum_item->children[0]->bitsAsConst(width, is_signed);
|
||||||
enum_item_str.append(std::to_string(val));
|
enum_item_str.append(val.as_string());
|
||||||
//set attribute for available val to enum item name mappings
|
//set attribute for available val to enum item name mappings
|
||||||
attributes[enum_item_str.c_str()] = mkconst_str(enum_item->str);
|
attributes[enum_item_str.c_str()] = mkconst_str(enum_item->str);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue