@@ -36,52 +36,55 @@ void verilog_typecheckt::elaborate_constants()
36
36
37
37
std::vector<irep_idt> to_be_elaborated;
38
38
39
- auto add_parameter = [this , &to_be_elaborated](
40
- const verilog_parameter_declt::declaratort &declarator)
41
- {
42
- symbolt symbol;
43
- symbol.mode = mode;
44
- symbol.module = module_identifier;
45
- symbol.base_name = declarator.identifier ();
46
- symbol.name = hierarchical_identifier (symbol.base_name );
47
- symbol.pretty_name = strip_verilog_prefix (symbol.name );
48
- symbol.is_macro = true ;
49
- symbol.value = declarator.value ();
50
- symbol.type = typet (ID_to_be_elaborated);
51
- symbol.location = declarator.source_location ();
52
-
53
- auto result = symbol_table.insert (std::move (symbol));
54
-
55
- if (!result.second )
56
- {
57
- error ().source_location = declarator.source_location ();
58
- error () << " definition of symbol `" << declarator.identifier ()
59
- << " \' conflicts with earlier definition at "
60
- << result.first .location << eom;
61
- throw 0 ;
62
- }
63
-
64
- to_be_elaborated.push_back (result.first .name );
65
- };
39
+ auto add_parameter =
40
+ [this , &to_be_elaborated](
41
+ const typet &type,
42
+ const verilog_parameter_declt::declaratort &declarator) {
43
+ symbolt symbol{
44
+ hierarchical_identifier (declarator.identifier ()),
45
+ type_with_subtypet (ID_to_be_elaborated, type),
46
+ mode};
47
+
48
+ symbol.module = module_identifier;
49
+ symbol.base_name = declarator.identifier ();
50
+ symbol.pretty_name = strip_verilog_prefix (symbol.name );
51
+ symbol.is_macro = true ;
52
+ symbol.value = declarator.value ();
53
+ symbol.location = declarator.source_location ();
54
+
55
+ auto result = symbol_table.insert (std::move (symbol));
56
+
57
+ if (!result.second )
58
+ {
59
+ throw errort ().with_location (declarator.source_location ())
60
+ << " definition of symbol `" << declarator.identifier ()
61
+ << " \' conflicts with earlier definition at "
62
+ << result.first .location ;
63
+ }
64
+
65
+ to_be_elaborated.push_back (result.first .name );
66
+ };
66
67
67
68
// Gather the port declarations from the module source.
68
69
auto &module_source =
69
70
to_verilog_module_source (module_symbol.type .find (ID_module_source));
70
71
71
72
for (auto &decl : module_source.parameter_port_list ())
72
- add_parameter (decl);
73
+ add_parameter (typet (ID_nil), decl);
73
74
74
75
for (auto &item : module_source.module_items ())
75
76
{
76
77
if (item.id () == ID_parameter_decl)
77
78
{
78
- for (auto &decl : to_verilog_parameter_decl (item).declarations ())
79
- add_parameter (decl);
79
+ auto ¶meter_decl = to_verilog_parameter_decl (item);
80
+ for (auto &decl : parameter_decl.declarations ())
81
+ add_parameter (parameter_decl.type (), decl);
80
82
}
81
83
else if (item.id () == ID_local_parameter_decl)
82
84
{
83
- for (auto &decl : to_verilog_local_parameter_decl (item).declarations ())
84
- add_parameter (decl);
85
+ auto &localparam_decl = to_verilog_local_parameter_decl (item);
86
+ for (auto &decl : localparam_decl.declarations ())
87
+ add_parameter (localparam_decl.type (), decl);
85
88
}
86
89
}
87
90
@@ -110,11 +113,26 @@ void verilog_typecheckt::elaborate_parameter(irep_idt identifier)
110
113
if (symbol.type .id () == ID_to_be_elaborated)
111
114
{
112
115
// mark as "elaborating" to detect cycles
113
- symbol.type = typet (ID_elaborating);
116
+ symbol.type . id (ID_elaborating);
114
117
118
+ // first elaborate the value
115
119
convert_expr (symbol.value );
116
120
symbol.value = elaborate_constant_expression (symbol.value );
117
- symbol.type = symbol.value .type ();
121
+
122
+ // Now elaborate the type. It may be given or implicit.
123
+ if (to_type_with_subtype (symbol.type ).subtype ().is_nil ())
124
+ {
125
+ // It's implicit. Use type of value.
126
+ symbol.type = symbol.value .type ();
127
+ }
128
+ else
129
+ {
130
+ // It's given. Elaborate it, then cast value.
131
+ auto elaborated_type =
132
+ convert_type (to_type_with_subtype (symbol.type ).subtype ());
133
+ symbol.type = elaborated_type;
134
+ propagate_type (symbol.value , symbol.type );
135
+ }
118
136
}
119
137
else if (symbol.type .id () == ID_elaborating)
120
138
{
0 commit comments