sv: check validity of package end label
authorZachary Snow <zach@zachjs.com>
Mon, 10 May 2021 15:06:02 +0000 (11:06 -0400)
committerZachary Snow <zachary.j.snow@gmail.com>
Mon, 10 May 2021 18:37:32 +0000 (14:37 -0400)
frontends/verilog/verilog_parser.y
tests/verilog/package_end_label.ys [new file with mode: 0644]

index e4b3258c23f39ed85d198847e92d2bad319ae015..dd25f412f177dc4da6e195e0c853b6b2dff806d6 100644 (file)
@@ -579,6 +579,8 @@ package:
                append_attr(mod, $1);
        } ';' package_body TOK_ENDPACKAGE opt_label {
                ast_stack.pop_back();
+               if ($4 != NULL && $9 != NULL && *$4 != *$9)
+                       frontend_verilog_yyerror("Package name (%s) and end label (%s) don't match.", $4->c_str()+1, $9->c_str()+1);
                current_ast_mod = NULL;
                exitTypeScope();
        };
diff --git a/tests/verilog/package_end_label.ys b/tests/verilog/package_end_label.ys
new file mode 100644 (file)
index 0000000..ccc5c96
--- /dev/null
@@ -0,0 +1,15 @@
+logger -expect-no-warnings
+read_verilog -sv <<EOF
+package correct_name;
+localparam X = 1;
+endpackage : correct_name
+EOF
+
+design -reset
+
+logger -expect error "Package name \(correct_name\) and end label \(incorrect_name\) don't match\." 1
+read_verilog -sv <<EOF
+package correct_name;
+localparam X = 1;
+endpackage : incorrect_name
+EOF