3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2025-08-11 13:40:53 +00:00

implement package import

This commit is contained in:
Rahul Bhagwat 2025-08-03 23:31:54 -04:00
parent 15b4716d18
commit b776283d79
No known key found for this signature in database
6 changed files with 51 additions and 0 deletions

View file

@ -174,6 +174,7 @@ std::string AST::type2str(AstNodeType type)
X(AST_MODPORT)
X(AST_MODPORTMEMBER)
X(AST_PACKAGE)
X(AST_IMPORT)
X(AST_WIRETYPE)
X(AST_TYPEDEF)
X(AST_STRUCT)

View file

@ -153,6 +153,7 @@ namespace AST
AST_MODPORT,
AST_MODPORTMEMBER,
AST_PACKAGE,
AST_IMPORT,
AST_WIRETYPE,
AST_TYPEDEF,

View file

@ -1361,6 +1361,7 @@ RTLIL::SigSpec AstNode::genRTLIL(int width_hint, bool sign_hint)
case AST_GENIF:
case AST_GENCASE:
case AST_PACKAGE:
case AST_IMPORT:
case AST_ENUM:
case AST_MODPORT:
case AST_MODPORTMEMBER:

View file

@ -1103,6 +1103,42 @@ bool AstNode::simplify(bool const_fold, int stage, int width_hint, bool sign_hin
int counter = 0;
label_genblks(existing, counter);
std::map<std::string, AstNode*> this_wire_scope;
// Process package imports after clearing the scope but before processing module declarations
for (auto &child : children) {
if (child->type == AST_IMPORT) {
// Find the package in the design
AstNode *package_node = nullptr;
for (auto &design_child : current_ast->children) {
if (design_child->type == AST_PACKAGE && design_child->str == child->str) {
package_node = design_child;
break;
}
}
if (package_node) {
// Import all names from the package into current scope
for (auto &pkg_child : package_node->children) {
if (pkg_child->type == AST_PARAMETER || pkg_child->type == AST_LOCALPARAM ||
pkg_child->type == AST_TYPEDEF || pkg_child->type == AST_FUNCTION ||
pkg_child->type == AST_TASK || pkg_child->type == AST_ENUM) {
current_scope[pkg_child->str] = pkg_child;
}
if (pkg_child->type == AST_ENUM) {
for (auto enode : pkg_child->children) {
log_assert(enode->type==AST_ENUM_ITEM);
if (current_scope.count(enode->str) == 0)
current_scope[enode->str] = enode;
else
input_error("enum item %s already exists in current scope\n", enode->str.c_str());
}
}
}
} else {
input_error("Package `%s' not found for import\n", child->str.c_str());
}
}
}
for (size_t i = 0; i < children.size(); i++) {
AstNode *node = children[i];