From 1810b3187a1bcf8d6edc7afea5a862b7d763d395 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Thu, 24 Jun 2021 12:02:58 +0800 Subject: [PATCH] Fix some more unit tests --- src/elab.c | 41 +++++++++++++++++++++-------------------- src/enode.c | 13 +++++++------ test/test_elab.c | 40 +++++++++++++++++++++++++++++++++++----- 3 files changed, 63 insertions(+), 31 deletions(-) diff --git a/src/elab.c b/src/elab.c index bdd3ef11..32bad191 100644 --- a/src/elab.c +++ b/src/elab.c @@ -49,6 +49,8 @@ typedef struct { hash_t *signals; vcode_unit_t reset; A(elab_init_t) init; + ident_t ninst; + ident_t npath; } elab_ctx_t; typedef struct _generic_list generic_list_t; @@ -1308,11 +1310,9 @@ static void elab_instance(tree_t inst, elab_ctx_t *ctx) tree_genmaps, tree_genmap); #endif - ident_t ninst = hpathf(e_instance(ctx->cursor), '@', "%s(%s)", - simple_name(istr(tree_ident2(arch))), - simple_name(istr(tree_ident(arch)))); - ident_t npath = hpathf(e_path(ctx->cursor), ':', "%s", - istr(tree_ident(inst))); + ctx->ninst = hpathf(ctx->ninst, '@', "%s(%s)", + simple_name(istr(tree_ident2(arch))), + simple_name(istr(tree_ident(arch)))); #if 0 elab_remangle_subprogram_names(arch, ctx->path); @@ -1349,8 +1349,8 @@ static void elab_instance(tree_t inst, elab_ctx_t *ctx) #endif e_node_t scope = e_new(E_SCOPE); - e_set_path(scope, npath); - e_set_instance(scope, ninst); + e_set_path(scope, ctx->npath); + e_set_instance(scope, ctx->ninst); elab_push_scope(ctx, scope); elab_ports(entity, ctx); @@ -1958,7 +1958,7 @@ static void elab_signal_decl(tree_t decl, elab_ctx_t *ctx) type_t type = tree_type(decl); const int width = type_width(type); - const int size = bit_width(type) / 8; + const int size = MAX(bit_width(type) / 8, 1); e_node_t s = e_new(E_SIGNAL); e_set_loc(s, tree_loc(decl)); @@ -2004,6 +2004,13 @@ static void elab_decls(tree_t container, elab_ctx_t *ctx) case T_SIGNAL_DECL: elab_signal_decl(d, ctx); break; + case T_TYPE_DECL: + case T_FUNC_DECL: + case T_FUNC_BODY: + case T_PROC_DECL: + case T_PROC_BODY: + case T_CONST_DECL: + break; default: fatal_trace("cannot elaborate decl kind %s", tree_kind_str(tree_kind(d))); @@ -2044,20 +2051,13 @@ static void elab_process_driver_fn(tree_t t, void *_ctx) static void elab_process(tree_t proc, elab_ctx_t *ctx) { - const char *label = simple_name(istr(tree_ident(proc))); - ident_t ninst = hpathf(e_instance(ctx->cursor), ':', "%s", label); - ident_t npath = hpathf(e_path(ctx->cursor), ':', "%s", label); - - printf("elab_process %s ninst=%s\n", istr(tree_ident(proc)), - istr(ninst)); - ident_t name = tree_ident(proc); e_node_t e = e_new(E_PROCESS); e_set_ident(e, name); e_set_loc(e, tree_loc(proc)); - e_set_instance(e, ninst); - e_set_path(e, npath); + e_set_instance(e, ctx->ninst); + e_set_path(e, ctx->npath); e_set_vcode(e, ident_prefix(tree_ident(ctx->arch), name, '.')); // TODO: just a hack to get things working @@ -2087,9 +2087,10 @@ static void elab_stmts(tree_t container, elab_ctx_t *ctx) const int nstmts = tree_stmts(container); for (int i = 0; i < nstmts; i++) { tree_t s = tree_stmt(container, i); - //const char *label = istr(tree_ident(s)); - //ident_t npath = hpathf(ctx->path, ':', "%s", label); - //ident_t ninst = hpathf(ctx->inst, ':', "%s", label); + + const char *label = istr(tree_ident(s)); + ctx->npath = hpathf(e_path(ctx->cursor), ':', "%s", label); + ctx->ninst = hpathf(e_instance(ctx->cursor), ':', "%s", label); switch (tree_kind(s)) { case T_INSTANCE: diff --git a/src/enode.c b/src/enode.c index a4b2cb7e..74bd7034 100644 --- a/src/enode.c +++ b/src/enode.c @@ -392,8 +392,8 @@ static void _e_dump(e_node_t e, int indent) for (int i = 0; i < nnexus; i++) { e_node_t n = e_nexus(e, i); e_dump_indent(indent + 2); - color_printf("$cyan$nexus$$ %s $cyan$width$$ %u\n", - istr(e_ident(n)), e_width(n)); + color_printf("$cyan$nexus$$ %s $cyan$id$$ %u $cyan$width$$ %u\n", + istr(e_ident(n)), e_pos(n), e_width(n)); } } break; @@ -415,7 +415,8 @@ static void _e_dump(e_node_t e, int indent) if (nnexus != 1) e_dump_indent(indent + 2); color_printf("$cyan$nexus$$ %s", istr(e_ident(n))); if (nnexus != 1 || e_width(n) != e_width(e)) - color_printf(" $cyan$width$$ %u", e_width(n)); + color_printf(" $cyan$id$$ %u $cyan$width$$ %u", + e_pos(n), e_width(n)); printf("\n"); } } @@ -423,9 +424,9 @@ static void _e_dump(e_node_t e, int indent) case E_NEXUS: { - color_printf("$cyan$nexus$$ %s $cyan$width$$ %u $cyan$size$$ %u " - "$cyan$id$$ %u\n", - istr(e_ident(e)), e_width(e), e_size(e), e_pos(e)); + color_printf("$cyan$nexus$$ %s $cyan$id$$ %u $cyan$width$$ %u " + "$cyan$size$$ %u\n", + istr(e_ident(e)), e_pos(e), e_width(e), e_size(e)); const int nsignals = e_signals(e); for (int i = 0; i < nsignals; i++) diff --git a/test/test_elab.c b/test/test_elab.c index b218308a..4c73b1ee 100644 --- a/test/test_elab.c +++ b/test/test_elab.c @@ -148,7 +148,24 @@ START_TEST(test_elab2) }; expect_errors(expect); - (void)run_elab(); + e_node_t e = run_elab(); + check_elab(e); + + fail_unless(e_nexuses(e) == 3); + + e_node_t s0 = e_scope(e_scope(e, 0), 0); + fail_unless(e_path(s0) == ident_new(":elab2_top:bot1")); + fail_unless(e_instance(s0) == + ident_new(":elab2_top(test):bot1@elab2_bot(test)")); + + e_node_t s1 = e_scope(e_scope(e, 0), 1); + fail_unless(e_path(s1) == ident_new(":elab2_top:bot2")); + fail_unless(e_instance(s1) == + ident_new(":elab2_top(test):bot2@elab2_bot(test)")); + + e_node_t n1 = e_nexus(e, 1); + fail_unless(e_ident(n1) == ident_new(":elab2_top:b")); + fail_unless(e_signals(n1) == 3); } END_TEST @@ -161,7 +178,22 @@ START_TEST(test_elab3) }; expect_errors(expect); - (void)run_elab(); + e_node_t e = run_elab(); + check_elab(e); + + e_node_t n0 = e_nexus(e, 0); + fail_unless(e_pos(n0) == 0); + fail_unless(e_width(n0) == 4); + fail_unless(e_size(n0) == 1); + fail_unless(e_signals(n0) == 1); + + e_node_t s0 = e_signal(n0, 0); + fail_unless(e_path(s0) == ident_new(":top2:s")); + fail_unless(e_ident(s0) == ident_new("S")); + fail_unless(e_width(s0) == 4); + fail_unless(e_size(s0) == 1); + fail_unless(e_nexuses(s0) == 1); + fail_unless(e_nexus(s0, 0) == n0); } END_TEST @@ -792,8 +824,6 @@ START_TEST(test_signal1) e_node_t e = run_elab(); check_elab(e); - e_dump(e); - fail_unless(e_deps(e) == 3); fail_unless(e_dep(e, 0) == ident_new("STD.STANDARD")); fail_unless(e_dep(e, 1) == ident_new("WORK.SIGNAL1")); @@ -815,9 +845,9 @@ Suite *get_elab_tests(void) TCase *tc = nvc_unit_test(); tcase_add_test(tc, test_elab1); -#if 0 tcase_add_test(tc, test_elab2); tcase_add_test(tc, test_elab3); +#if 0 tcase_add_test(tc, test_elab4); tcase_add_test(tc, test_open); tcase_add_test(tc, test_genagg); -- 2.39.2