From f6cf322583db2e6af29375820ff6e7642514de4f Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Wed, 16 Dec 2015 21:33:30 +0000 Subject: [PATCH] Fix LLVM link error with use clause in block or generate. Fixes #225 --- src/dump.c | 7 +++++++ src/elab.c | 36 ++++++++++++++++++++-------------- test/regress/gold/issue225.txt | 1 + test/regress/issue225.vhd | 28 ++++++++++++++++++++++++++ test/regress/testlist.txt | 1 + 5 files changed, 58 insertions(+), 15 deletions(-) create mode 100644 test/regress/gold/issue225.txt create mode 100644 test/regress/issue225.vhd diff --git a/src/dump.c b/src/dump.c index a7177625..5cf6d2dd 100644 --- a/src/dump.c +++ b/src/dump.c @@ -549,6 +549,13 @@ static void dump_decl(tree_t t, int indent) printf(";\n"); return; + case T_USE: + printf("use %s", istr(tree_ident(t))); + if (tree_has_ident2(t)) + printf(".%s", istr(tree_ident2(t))); + printf(";\n"); + return; + default: cannot_dump(t, "decl"); } diff --git a/src/elab.c b/src/elab.c index fc62228b..bd93b424 100644 --- a/src/elab.c +++ b/src/elab.c @@ -337,26 +337,29 @@ static void elab_context_walk_fn(ident_t name, int kind, void *context) } } -static void elab_copy_context(tree_t src, const elab_ctx_t *ctx) +static void elab_use_clause(tree_t use, const elab_ctx_t *ctx) { - const int nsrc = tree_contexts(src); - for (int i = 0; i < nsrc; i++) { - tree_t c = tree_context(src, i); - if (tree_kind(c) != T_USE) - continue; + tree_set_ident2(use, all_i); - tree_set_ident2(c, all_i); + ident_t name = tree_ident(use); + ident_t lname = ident_until(name, '.'); - ident_t name = tree_ident(c); - ident_t lname = ident_until(name, '.'); + elab_ctx_t new_ctx = *ctx; + new_ctx.library = elab_find_lib(lname, ctx); - elab_ctx_t new_ctx = *ctx; - new_ctx.library = elab_find_lib(lname, ctx); + if (name == lname) + lib_walk_index(new_ctx.library, elab_context_walk_fn, &new_ctx); + else if (!elab_have_context(ctx->out, name)) + elab_add_context(use, &new_ctx); +} - if (name == lname) - lib_walk_index(new_ctx.library, elab_context_walk_fn, &new_ctx); - else if (!elab_have_context(ctx->out, name)) - elab_add_context(c, &new_ctx); +static void elab_copy_context(tree_t src, const elab_ctx_t *ctx) +{ + const int nsrc = tree_contexts(src); + for (int i = 0; i < nsrc; i++) { + tree_t c = tree_context(src, i); + if (tree_kind(c) == T_USE) + elab_use_clause(c, ctx); } } @@ -1086,6 +1089,9 @@ static void elab_decls(tree_t t, const elab_ctx_t *ctx) tree_add_attr_str(d, inst_name_i, ninst); tree_add_decl(ctx->out, d); break; + case T_USE: + elab_use_clause(d, ctx); + break; default: break; } diff --git a/test/regress/gold/issue225.txt b/test/regress/gold/issue225.txt new file mode 100644 index 00000000..9766475a --- /dev/null +++ b/test/regress/gold/issue225.txt @@ -0,0 +1 @@ +ok diff --git a/test/regress/issue225.vhd b/test/regress/issue225.vhd new file mode 100644 index 00000000..bb51ea10 --- /dev/null +++ b/test/regress/issue225.vhd @@ -0,0 +1,28 @@ +-- use std.textio.all; -- this does work +entity issue225 is + -- use std.textio.all; -- doesn't work +end entity issue225; +-- use std.textio.all; -- this does work +architecture test of issue225 is + use std.textio.all; -- doesn't work +begin + g1: if true generate + -- use std.textio.all; -- doesn't work (this one doesn't compile unless parse.c's p_generate_statement's call to scan() is amended to include pUSE (issue 223) + begin + b1: block + -- use std.textio.all; -- doesn't work + begin + p1: process + -- use std.textio.all; -- doesn't work + procedure doit is + -- use std.textio.all; -- doesn't work + begin + write(OUTPUT, "ok" & LF); + wait; + end procedure doit; + begin + doit; + end process p1; + end block b1; + end generate g1; +end architecture test; diff --git a/test/regress/testlist.txt b/test/regress/testlist.txt index 4112eb75..8bcee988 100644 --- a/test/regress/testlist.txt +++ b/test/regress/testlist.txt @@ -307,3 +307,4 @@ issue227 normal,gold real3 normal,gold for3 normal,gold issue197 normal +issue225 normal,gold -- 2.39.2