Merge pull request #203 from antmicro/param_type
Add several fixes for segmentation faults
diff --git a/uhdm-plugin/UhdmAst.cc b/uhdm-plugin/UhdmAst.cc
index 3ba1282..f0412e6 100644
--- a/uhdm-plugin/UhdmAst.cc
+++ b/uhdm-plugin/UhdmAst.cc
@@ -1043,12 +1043,13 @@
void UhdmAst::process_design()
{
current_node = make_ast_node(AST::AST_DESIGN);
- visit_one_to_many({UHDM::uhdmallInterfaces, UHDM::uhdmallPackages, UHDM::uhdmallModules, UHDM::uhdmtopModules, vpiTypedef}, obj_h,
- [&](AST::AstNode *node) {
- if (node) {
- shared.top_nodes[node->str] = node;
- }
- });
+ visit_one_to_many(
+ {UHDM::uhdmallInterfaces, UHDM::uhdmallPackages, UHDM::uhdmallModules, UHDM::uhdmtopModules, vpiTypedef, vpiParameter, vpiParamAssign}, obj_h,
+ [&](AST::AstNode *node) {
+ if (node) {
+ shared.top_nodes[node->str] = node;
+ }
+ });
for (auto pair : shared.top_nodes) {
if (!pair.second)
continue;
@@ -1817,7 +1818,7 @@
}
});
visit_one_to_many({vpiTypedef}, obj_h, [&](AST::AstNode *node) {
- if (node) {
+ if (node && node->str != "") {
move_type_to_new_typedef(current_node, node);
}
});
@@ -2411,6 +2412,9 @@
auto key = node->children[0]->str;
key = key.substr(key.find('.') + 1);
auto param_type = shared.param_types[param_node->str];
+ if (!param_type) {
+ log_error("Couldn't find parameter type for node: %s\n", param_node->str.c_str());
+ }
size_t pos =
std::find_if(param_type->children.begin(), param_type->children.end(), [key](AST::AstNode *child) { return child->str == key; }) -
param_type->children.begin();
@@ -2511,6 +2515,9 @@
{
current_node = make_ast_node(AST::AST_CASE);
visit_one_to_one({vpiCondition}, obj_h, [&](AST::AstNode *node) {
+ if (!node) {
+ log_error("Couldn't find node in if stmt. This can happend if unsupported '$value$plusargs' function is used inside if.\n");
+ }
auto reduce_node = new AST::AstNode(AST::AST_REDUCE_BOOL, node);
current_node->children.push_back(reduce_node);
});
@@ -2899,7 +2906,11 @@
visit_one_to_many({vpiRange}, obj_h, [&](AST::AstNode *node) { packed_ranges.push_back(node); });
add_multirange_wire(current_node, packed_ranges, unpacked_ranges);
if (!current_node->str.empty()) {
- move_type_to_new_typedef(find_ancestor({AST::AST_MODULE, AST::AST_PACKAGE}), current_node->clone());
+ auto top_module = find_ancestor({AST::AST_MODULE, AST::AST_PACKAGE, AST::AST_DESIGN});
+ if (!top_module) {
+ log_error("Couldn't find top module for typedef: %s\n", current_node->str.c_str());
+ }
+ move_type_to_new_typedef(top_module, current_node->clone());
}
}
@@ -2915,7 +2926,11 @@
add_multirange_wire(current_node, packed_ranges, unpacked_ranges);
current_node->is_signed = true;
if (!current_node->str.empty()) {
- move_type_to_new_typedef(find_ancestor({AST::AST_MODULE, AST::AST_PACKAGE}), current_node);
+ auto top_module = find_ancestor({AST::AST_MODULE, AST::AST_PACKAGE, AST::AST_DESIGN});
+ if (!top_module) {
+ log_error("Couldn't find top module for typedef: %s\n", current_node->str.c_str());
+ }
+ move_type_to_new_typedef(top_module, current_node);
}
}
@@ -2970,7 +2985,11 @@
}
});
if (!current_node->str.empty()) {
- move_type_to_new_typedef(find_ancestor({AST::AST_MODULE, AST::AST_PACKAGE}), current_node);
+ auto top_module = find_ancestor({AST::AST_MODULE, AST::AST_PACKAGE, AST::AST_DESIGN});
+ if (!top_module) {
+ log_error("Couldn't find top module for typedef: %s\n", current_node->str.c_str());
+ }
+ move_type_to_new_typedef(top_module, current_node);
}
}