From c39dd3354a2dc1df3f4a9b5ef1886048bb528400 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Sat, 12 Sep 2015 12:21:45 +0100 Subject: [PATCH] Split `lower_decls` into two passes. Issue #217 --- src/lower.c | 44 +++++++++++++++++++++++++-------------- test/regress/issue217.vhd | 42 +++++++++++++++++++++++++++++++++++++ test/regress/testlist.txt | 1 + 3 files changed, 71 insertions(+), 16 deletions(-) create mode 100644 test/regress/issue217.vhd diff --git a/src/lower.c b/src/lower.c index 6dd050e3..23c7ac19 100644 --- a/src/lower.c +++ b/src/lower.c @@ -4113,32 +4113,44 @@ static void lower_decls(tree_t scope, vcode_unit_t context) const int nest_depth = tree_attr_int(scope, nested_i, 0); + // Lower declarations in two passes with subprograms after signals, + // variables, constants, etc. + const int ndecls = tree_decls(scope); + for (int i = 0; i < ndecls; i++) { tree_t d = tree_decl(scope, i); const tree_kind_t kind = tree_kind(d); - if (kind == T_FUNC_BODY || kind == T_PROC_BODY || kind == T_PROT_BODY) { - vcode_block_t bb = vcode_active_block(); + if (nested) { + tree_add_attr_int(d, nested_i, nest_depth + 1); + lower_mangle_func(d, context); + } + } + else + lower_decl(d); + } - if (kind != T_PROT_BODY && tree_has_code(d)) - continue; + for (int i = 0; i < ndecls; i++) { + tree_t d = tree_decl(scope, i); + const tree_kind_t kind = tree_kind(d); + if (kind != T_FUNC_BODY && kind != T_PROC_BODY && kind != T_PROT_BODY) + continue; - if (nested) - tree_add_attr_int(d, nested_i, nest_depth + 1); + vcode_block_t bb = vcode_active_block(); - switch (kind) { - case T_FUNC_BODY: lower_func_body(d, context); break; - case T_PROC_BODY: lower_proc_body(d, context); break; - case T_PROT_BODY: lower_protected_body(d); break; - default: break; - } + if (kind != T_PROT_BODY && tree_has_code(d)) + continue; - vcode_select_unit(context); - vcode_select_block(bb); + switch (kind) { + case T_FUNC_BODY: lower_func_body(d, context); break; + case T_PROC_BODY: lower_proc_body(d, context); break; + case T_PROT_BODY: lower_protected_body(d); break; + default: break; } - else if (scope_kind != T_PROT_BODY) - lower_decl(d); + + vcode_select_unit(context); + vcode_select_block(bb); } } diff --git a/test/regress/issue217.vhd b/test/regress/issue217.vhd new file mode 100644 index 00000000..2ebfd84c --- /dev/null +++ b/test/regress/issue217.vhd @@ -0,0 +1,42 @@ +entity SUB is + port ( + USER_I : in bit_vector(1 downto 0); + RESULT : out boolean + ); +end SUB; +architecture MODEL of SUB is + procedure match(user:in bit_vector; ok: out boolean) is begin + ok := (user(USER_I'range) = USER_I); + end procedure; +begin + process(USER_I) + variable ok : boolean; + constant user : bit_vector(1 downto 0) := "01"; + begin + match(user, ok); + RESULT <= ok; + end process; +end MODEL; + +entity issue217 is +end issue217; +architecture MODEL of issue217 is + signal USER : bit_vector(1 downto 0); + signal OK : boolean; +begin + U: entity WORK.SUB port map ( + USER_I => USER, + RESULT => OK + ); + + user <= "01"; + + process is + begin + assert not ok; + wait on ok; + assert ok; + wait; + end process; + +end MODEL; diff --git a/test/regress/testlist.txt b/test/regress/testlist.txt index fcb71080..9d896159 100644 --- a/test/regress/testlist.txt +++ b/test/regress/testlist.txt @@ -301,3 +301,4 @@ elab25 normal logical2 normal attr12 normal,gold issue229 normal +issue217 normal -- 2.39.2