Skip to content

Commit

Permalink
Fix handling of multi-line PSL comments
Browse files Browse the repository at this point in the history
Fixes #910
Fixes #913
  • Loading branch information
nickg committed Jul 11, 2024
1 parent 2f691b8 commit 017153a
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/lexer.l
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,6 @@ UNION ?i:union
{ACCESS} { TOKEN(tACCESS); }
{FILE} { TOKEN(tFILE); }
{OPEN} { TOKEN(tOPEN); }
{UNTIL} { TOKEN(tUNTIL); }
{RECORD} { TOKEN(tRECORD); }
{NEW} { TOKEN(tNEW); }
{SHARED} { TOKEN(tSHARED); }
Expand Down Expand Up @@ -422,6 +421,7 @@ UNION ?i:union
<INITIAL,PSL>{RANGE} { TOKEN(tRANGE); }
<INITIAL,PSL>{TO} { TOKEN(tTO); }
<INITIAL,PSL>{DOWNTO} { TOKEN(tDOWNTO); }
<INITIAL,PSL>{UNTIL} { TOKEN(tUNTIL); }

<*>"(" { TOKEN(tLPAREN); }
<*>")" { TOKEN(tRPAREN); }
Expand Down
27 changes: 0 additions & 27 deletions src/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -6779,13 +6779,9 @@ static tree_t p_psl_condition(void)
{
BEGIN("condition");

scan_as_vhdl();

tree_t value = p_expression();
solve_psl_condition(nametab, value);

scan_as_psl();

return value;
}

Expand Down Expand Up @@ -11131,8 +11127,6 @@ static psl_node_t p_psl_value_range(void)

// TODO: Enforce Numeric or Boolean on "l" and "r"

scan_as_vhdl();

tree_t l = p_expression();
tree_t tgt = l;

Expand All @@ -11149,8 +11143,6 @@ static psl_node_t p_psl_value_range(void)
psl_node_t p = psl_new(P_HDL_EXPR);
psl_set_tree(p, tgt);

scan_as_psl();

return p;
}

Expand Down Expand Up @@ -11373,18 +11365,13 @@ static psl_node_t p_psl_parameter_definition(void)
insert_name(nametab, param, NULL);

if (optional(tLSQUARE)) {

scan_as_vhdl();

// TODO: Enforce left and right to be numeric
tree_t range = tree_new(T_RANGE);
tree_set_left(range, p_expression());
consume(tTO);
tree_set_subkind(range, RANGE_TO);
tree_set_right(range, p_expression());

scan_as_psl();

tree_set_value(param, range);
psl_set_tree(p, param);

Expand Down Expand Up @@ -11553,17 +11540,13 @@ static tree_t p_psl_count(void)

BEGIN("PSL Count");

scan_as_vhdl();

tree_t count = p_expression();

if (peek() == tTO)
count = p_range(count);

solve_types(nametab, count, std_type(NULL, STD_INTEGER));

scan_as_psl();

return count;
}

Expand Down Expand Up @@ -11950,8 +11933,6 @@ static psl_node_t p_psl_fl_property(void)
psl_set_flag(p, PSL_F_STRONG);

if (optional(tLSQUARE)) {
scan_as_vhdl();

type_t std_int = std_type(NULL, STD_INTEGER);

tree_t expr = p_expression();
Expand All @@ -11960,7 +11941,6 @@ static psl_node_t p_psl_fl_property(void)

psl_set_delay(p, expr);

scan_as_psl();
consume(tRSQUARE);
}

Expand All @@ -11980,9 +11960,7 @@ static psl_node_t p_psl_fl_property(void)

consume(tLSQUARE);

scan_as_vhdl();
psl_set_delay(p, p_discrete_range(NULL));
scan_as_psl();

consume(tRSQUARE);

Expand All @@ -12002,9 +11980,7 @@ static psl_node_t p_psl_fl_property(void)

consume(tLSQUARE);

scan_as_vhdl();
psl_set_delay(p, p_discrete_range(NULL));
scan_as_psl();

consume(tRSQUARE);

Expand All @@ -12027,16 +12003,13 @@ static psl_node_t p_psl_fl_property(void)
consume(tRPAREN);

if (optional(tLSQUARE)) {
scan_as_vhdl();

type_t std_int = std_type(NULL, STD_INTEGER);

tree_t expr = p_expression();
solve_types(nametab, expr, std_int);
sem_check(expr, nametab);

psl_set_delay(p, expr);
scan_as_psl();

consume(tRSQUARE);
}
Expand Down
16 changes: 16 additions & 0 deletions test/psl/issue910.vhd
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
entity psl_multiline is
end entity;

architecture tb of psl_multiline is
signal a,b,c : bit;
begin

-- psl cov_1 : cover
-- {a = '1' and
-- b = '1' and
-- c = '1'};

-- psl cov_2 : cover
-- {a = '1' and b = '0'};

end architecture;
23 changes: 22 additions & 1 deletion test/test_psl.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (C) 2022-2023 Nick Gasson
// Copyright (C) 2022-2024 Nick Gasson
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -277,6 +277,26 @@ START_TEST(test_parse5)
}
END_TEST

START_TEST(test_issue910)
{
opt_set_int(OPT_PSL_COMMENTS, 1);

input_from_file(TESTDIR "/psl/issue910.vhd");

tree_t a = parse_and_check(T_ENTITY, T_ARCH);

psl_node_t p0 = tree_psl(tree_stmt(a, 0));
fail_unless(psl_kind(p0) == P_COVER);
fail_unless(psl_kind(psl_value(p0)) == P_HDL_EXPR);

psl_node_t p1 = tree_psl(tree_stmt(a, 0));
fail_unless(psl_kind(p1) == P_COVER);
fail_unless(psl_kind(psl_value(p1)) == P_HDL_EXPR);

fail_if_errors();
}
END_TEST

Suite *get_psl_tests(void)
{
Suite *s = suite_create("psl");
Expand All @@ -288,6 +308,7 @@ Suite *get_psl_tests(void)
tcase_add_test(tc_core, test_parse3);
tcase_add_test(tc_core, test_parse4);
tcase_add_test(tc_core, test_parse5);
tcase_add_test(tc_core, test_issue910);
suite_add_tcase(s, tc_core);

return s;
Expand Down

0 comments on commit 017153a

Please sign in to comment.