diff --git a/Documentation/usage/command_line_flags.rst b/Documentation/usage/command_line_flags.rst index 8f7f531b3..751818d42 100644 --- a/Documentation/usage/command_line_flags.rst +++ b/Documentation/usage/command_line_flags.rst @@ -131,6 +131,14 @@ These flags affect the general behavior of the compiler. containing an unsized constant number, and unsized constant numbers are not truncated to integer width. + * strict-parameter-declaration/no-strict-parameter-declaration + + The standards requires that parameters must be declared lexically + before they are used. Using -gno-strict-parameter-declaration + will allow using a parameter before declaration, e.g., in a port + declaration, with the parameter declared in the body of the + module. + * shared-loop-index/no-shared-loop-index Enable or disable the exclusion of for-loop control variables from diff --git a/compiler.h b/compiler.h index 307589aad..9548a85d0 100644 --- a/compiler.h +++ b/compiler.h @@ -210,6 +210,12 @@ extern bool gn_strict_expr_width_flag; loop. */ extern bool gn_shared_loop_index_flag; +/* If this flag is true (default), then parameters must be declared before + use. + use `-gno-strict-parameter-declaration` for pre version 13 behaviour. + */ +extern bool gn_strict_parameter_declaration; + static inline bool gn_system_verilog(void) { if (generation_flag >= GN_VER2005_SV) diff --git a/driver/iverilog.man.in b/driver/iverilog.man.in index be62ec10b..4f7bb40f2 100644 --- a/driver/iverilog.man.in +++ b/driver/iverilog.man.in @@ -150,6 +150,12 @@ parameter assignment is evaluated as a lossless expression, as is any expression containing an unsized constant number, and unsized constant numbers are not truncated to integer width. .TP 8 +.B -gstrict-parameter-declaration\fI|\fP-gno-strict-parameter-declaration +The standards requires that parameters must be declared lexically +before they are used. Using \fB\-gno\-strict\-parameter\-declaration\fP +will allow using a parameter before declaration, e.g., in a port +declaration, with the parameter declared in the body of the module. +.TP 8 .B -gshared-loop-index\fI|\fP-gno-shared-loop-index Enable (default) or disable the exclusion of for-loop control variables from implicit event_expression lists. When enabled, if a for-loop control diff --git a/driver/main.c b/driver/main.c index 352ab9f45..c1de20333 100644 --- a/driver/main.c +++ b/driver/main.c @@ -134,6 +134,7 @@ const char*gen_strict_ca_eval = "no-strict-ca-eval"; const char*gen_strict_expr_width = "no-strict-expr-width"; const char*gen_shared_loop_index = "shared-loop-index"; const char*gen_verilog_ams = "no-verilog-ams"; +const char*gen_strict_parameter_declaration = "strict-parameter-declaration"; /* Boolean: true means use a default include dir, false means don't */ int gen_std_include = 1; @@ -815,6 +816,12 @@ static int process_generation(const char*name) else if (strcmp(name,"no-verilog-ams") == 0) gen_verilog_ams = "no-verilog-ams"; + else if (strcmp(name,"strict-parameter-declaration") == 0) + gen_strict_parameter_declaration = "strict-parameter-declaration"; + + else if (strcmp(name,"no-strict-parameter-declaration") == 0) + gen_strict_parameter_declaration = "no-strict-parameter-declaration"; + else { fprintf(stderr, "Unknown/Unsupported Language generation " "%s\n\n", name); @@ -837,7 +844,8 @@ static int process_generation(const char*name) " io-range-error | no-io-range-error\n" " strict-ca-eval | no-strict-ca-eval\n" " strict-expr-width | no-strict-expr-width\n" - " shared-loop-index | no-shared-loop-index\n"); + " shared-loop-index | no-shared-loop-index\n" + " strict-parameter-declaration | no-strict-parameter-declaration\n"); return 1; } @@ -1385,6 +1393,7 @@ int main(int argc, char **argv) fprintf(iconfig_file, "generation:%s\n", gen_strict_expr_width); fprintf(iconfig_file, "generation:%s\n", gen_shared_loop_index); fprintf(iconfig_file, "generation:%s\n", gen_verilog_ams); + fprintf(iconfig_file, "generation:%s\n", gen_strict_parameter_declaration); fprintf(iconfig_file, "generation:%s\n", gen_icarus); fprintf(iconfig_file, "warnings:%s\n", warning_flags); fprintf(iconfig_file, "ignore_missing_modules:%s\n", ignore_missing_modules ? "true" : "false"); diff --git a/main.cc b/main.cc index 99c080e0a..7ed4c7c50 100644 --- a/main.cc +++ b/main.cc @@ -117,6 +117,7 @@ bool gn_strict_ca_eval_flag = false; bool gn_strict_expr_width_flag = false; bool gn_shared_loop_index_flag = true; bool gn_verilog_ams_flag = false; +bool gn_strict_parameter_declaration = true; /* * For some generations we allow a system function to be called @@ -386,6 +387,12 @@ static void process_generation_flag(const char*gen) } else if (strcmp(gen,"no-shared-loop-index") == 0) { gn_shared_loop_index_flag = false; + } else if (strcmp(gen,"strict-parameter-declaration") == 0) { + gn_strict_parameter_declaration = true; + + } else if (strcmp(gen,"no-strict-parameter-declaration") == 0) { + gn_strict_parameter_declaration = false; + } else { } } diff --git a/symbol_search.cc b/symbol_search.cc index be8580018..9c00920e7 100644 --- a/symbol_search.cc +++ b/symbol_search.cc @@ -189,7 +189,8 @@ bool symbol_search(const LineInfo*li, Design*des, NetScope*scope, } if (const NetExpr*par = scope->get_parameter(des, path_tail.name, res->type)) { - if (prefix_scope || (scope->get_parameter_lexical_pos(path_tail.name) <= lexical_pos)) { + if (!gn_strict_parameter_declaration || prefix_scope + || (scope->get_parameter_lexical_pos(path_tail.name) <= lexical_pos)) { path.push_back(path_tail); res->scope = scope; res->par_val = par;