Skip to content

Commit

Permalink
Add support for package external names. Fixes nickg#1072
Browse files Browse the repository at this point in the history
  • Loading branch information
nickg committed Dec 1, 2024
1 parent 5554392 commit 5c6ec2e
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 23 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
fusion.
- Nested arrays more than two levels deep can now be dumped in FST
format (#1071).
- Added support for package external names (#1072).
- Several other minor bugs were resolved (#1038, #1057, #1067).

## Version 1.14.2 - 2024-11-23
Expand Down
67 changes: 44 additions & 23 deletions src/rt/ename.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,6 @@

static tree_t select_name(tree_t where, ident_t id)
{
const int nstmts = tree_stmts(where);
for (int i = 0; i < nstmts; i++) {
tree_t s = tree_stmt(where, i);
if (tree_ident(s) == id)
return s;
}

const int ndecls = tree_decls(where);
for (int i = 0; i < ndecls; i++) {
tree_t d = tree_decl(where, i);
Expand All @@ -53,6 +46,16 @@ static tree_t select_name(tree_t where, ident_t id)
return g;
}

if (is_package(where))
return NULL;

const int nstmts = tree_stmts(where);
for (int i = 0; i < nstmts; i++) {
tree_t s = tree_stmt(where, i);
if (tree_ident(s) == id)
return s;
}

const int nports = tree_ports(where);
for (int i = 0; i < nports; i++) {
tree_t p = tree_port(where, i);
Expand Down Expand Up @@ -113,12 +116,40 @@ void x_bind_external(tree_t name, jit_scalar_t *result)
id = ident_new(tb_get(tb));
}
break;
case PE_LIBRARY:
{
lib_t lib = lib_require(tree_ident(pe));

pe = tree_part(name, ++i);
assert(tree_subkind(pe) == PE_SIMPLE);

ident_t qual = ident_prefix(lib_name(lib), tree_ident(pe), '.');

tree_t pack = lib_get(lib, qual);
if (pack == NULL || !is_package(pack))
jit_msg(tree_loc(pe), DIAG_FATAL, "%s is not a package",
istr(qual));

next = pack;
}
continue;
default:
jit_msg(tree_loc(pe), DIAG_FATAL, "sorry, this form of external name "
"is not yet supported");
should_not_reach_here();
}

if (!is_concurrent_block(where)) {
if (tree_kind(where) == T_BLOCK) {
tree_t hier = tree_decl(where, 0);
assert(tree_kind(hier) == T_HIER);

if (tree_subkind(hier) == T_COMPONENT) {
// Skip over implicit block for component declaration
where = tree_stmt(where, 0);
assert(tree_kind(where) == T_BLOCK);
hier = tree_decl(where, 0);
path = ident_prefix(path, tree_ident(where), '.');
}
}
else if (!is_package(where)) {
diag_t *d = diag_new(DIAG_ERROR, tree_loc(pe));
diag_printf(d, "%s is not a concurrent region",
istr(tree_ident(where)));
Expand All @@ -128,19 +159,6 @@ void x_bind_external(tree_t name, jit_scalar_t *result)
jit_abort_with_status(1);
}

assert(tree_kind(where) == T_BLOCK);

tree_t hier = tree_decl(where, 0);
assert(tree_kind(hier) == T_HIER);

if (tree_subkind(hier) == T_COMPONENT) {
// Skip over implicit block for component declaration
where = tree_stmt(where, 0);
assert(tree_kind(where) == T_BLOCK);
hier = tree_decl(where, 0);
path = ident_prefix(path, tree_ident(where), '.');
}

if ((next = select_name(where, id)) == NULL) {
diag_t *d = diag_new(DIAG_ERROR, tree_loc(pe));
diag_printf(d, "external name %s not found",
Expand Down Expand Up @@ -189,7 +207,10 @@ void x_bind_external(tree_t name, jit_scalar_t *result)
}

jit_t *j = jit_for_thread();

jit_handle_t handle = jit_compile(j, path);
(void)jit_link(j, handle); // Package may not be loaded

void *ptr = jit_get_frame_var(j, handle, tree_ident(where));

if (type_is_array(type)) {
Expand Down
27 changes: 27 additions & 0 deletions test/regress/ename16.vhd
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package my_pkg is

signal sig_in_package : natural := 17;

end package;

entity ename16 is
end entity;

architecture test of ename16 is
begin

process
alias al is << signal @work.my_pkg.sig_in_package : natural >>;
begin
wait for 1 ns;
assert (al = 17);
al <= 5;
wait for 1 ns;
assert al = 5;
wait for 1 ns;

assert << signal @work.my_pkgxxxx.sig : natural >> = 1; -- Error
wait;
end process;

end architecture;
1 change: 1 addition & 0 deletions test/regress/gold/ename16.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3ns+0: WORK.MY_PKGXXXX is not a package
1 change: 1 addition & 0 deletions test/regress/testlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1078,3 +1078,4 @@ issue1071 wave,2008,dump-arrays
issue1079 normal,gold
ivtest4 verilog
psl17 gold,psl
ename16 fail,gold,2008

0 comments on commit 5c6ec2e

Please sign in to comment.