From 3cc5fa5fd4adca0b456bbce800c1550e38de750f Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Sat, 19 Nov 2022 10:15:15 +0000 Subject: [PATCH] Remove flags argument to eval_new --- src/elab.c | 2 +- src/eval.c | 19 +++++++++---------- src/eval.h | 8 +------- src/nvc.c | 2 +- test/jitperf.c | 2 +- test/test_bounds.c | 22 +++++++++++----------- test/test_lower.c | 2 +- test/test_simp.c | 16 ++++++++-------- test/test_util.c | 4 ++-- 9 files changed, 35 insertions(+), 42 deletions(-) diff --git a/src/elab.c b/src/elab.c index ea078fe6..36cfbdac 100644 --- a/src/elab.c +++ b/src/elab.c @@ -1828,7 +1828,7 @@ tree_t elab(tree_t top) .path = NULL, .inst = NULL, .library = lib_work(), - .eval = eval_new(EVAL_FCALL), + .eval = eval_new(), }; ctx.subprograms = hash_new(256); diff --git a/src/eval.c b/src/eval.c index 08556aca..85b65e8f 100644 --- a/src/eval.c +++ b/src/eval.c @@ -39,6 +39,11 @@ #include #include +typedef enum { + EVAL_WARN = (1 << 2), + EVAL_VERBOSE = (1 << 3), +} eval_flags_t; + struct _eval { eval_flags_t flags; jit_t *jit; @@ -96,13 +101,11 @@ static tree_t eval_value_to_tree(jit_scalar_t value, type_t type, return tree; } -eval_t *eval_new(eval_flags_t flags) +eval_t *eval_new(void) { + eval_flags_t flags = 0; if (opt_get_verbose(OPT_EVAL_VERBOSE, NULL)) - flags |= EVAL_VERBOSE; - - if (flags & EVAL_VERBOSE) - flags |= EVAL_WARN; + flags |= EVAL_VERBOSE | EVAL_WARN; eval_t *ex = xcalloc(sizeof(eval_t)); ex->flags = flags; @@ -194,9 +197,7 @@ bool eval_possible(eval_t *e, tree_t t) tree_t decl = tree_ref(t); const subprogram_kind_t kind = tree_subkind(decl); - if (kind == S_USER && !(e->flags & EVAL_FCALL)) - return eval_not_possible(e, t, "call to user defined function"); - else if (kind == S_FOREIGN || kind == S_VHPIDIRECT) + if (kind == S_FOREIGN || kind == S_VHPIDIRECT) return eval_not_possible(e, t, "call to foreign function"); else if (tree_flags(decl) & TREE_F_IMPURE) return eval_not_possible(e, t, "call to impure function"); @@ -237,8 +238,6 @@ bool eval_possible(eval_t *e, tree_t t) case T_CONST_DECL: if (tree_has_value(decl)) return eval_possible(e, tree_value(decl)); - else if (!(e->flags & EVAL_FCALL)) - return eval_not_possible(e, t, "deferred constant"); else return true; diff --git a/src/eval.h b/src/eval.h index ae4c77e6..5e15ec22 100644 --- a/src/eval.h +++ b/src/eval.h @@ -21,15 +21,9 @@ #include "prim.h" #include "phase.h" -typedef enum { - EVAL_FCALL = (1 << 1), - EVAL_WARN = (1 << 2), - EVAL_VERBOSE = (1 << 3), -} eval_flags_t; - typedef vcode_unit_t (*lower_fn_t)(ident_t, void *); -eval_t *eval_new(eval_flags_t flags); +eval_t *eval_new(void); void eval_free(eval_t *ex); tree_t eval_try_fold(eval_t *ex, tree_t expr); tree_t eval_must_fold(eval_t *ex, tree_t expr); diff --git a/src/nvc.c b/src/nvc.c index 37a57985..3aa67afa 100644 --- a/src/nvc.c +++ b/src/nvc.c @@ -152,7 +152,7 @@ static int analyse(int argc, char **argv) } lib_t work = lib_work(); - eval_t *eval = eval_new(EVAL_FCALL); + eval_t *eval = eval_new(); for (int i = optind; i < next_cmd; i++) { input_from_file(argv[i]); diff --git a/test/jitperf.c b/test/jitperf.c index 6a2ffee7..9385983d 100644 --- a/test/jitperf.c +++ b/test/jitperf.c @@ -190,7 +190,7 @@ int main(int argc, char **argv) lib_t work = lib_tmp("PERF"); lib_set_work(work); - eval_t *eval = eval_new(0); + eval_t *eval = eval_new(); for (int i = optind; i < argc; i++) { color_printf("$!cyan$--\n-- %s\n--$$\n\n", argv[i]); diff --git a/test/test_bounds.c b/test/test_bounds.c index 5696796f..5ab4fde5 100644 --- a/test/test_bounds.c +++ b/test/test_bounds.c @@ -87,7 +87,7 @@ START_TEST(test_bounds) tree_t a = parse_and_check(T_ENTITY, T_ARCH); fail_unless(error_count() == 0); - eval_t *ex = eval_new(EVAL_FCALL); + eval_t *ex = eval_new(); simplify_global(a, NULL, ex); // Global to fold TIME expressions eval_free(ex); bounds_check(a); @@ -130,7 +130,7 @@ START_TEST(test_bounds2) tree_t a = parse_and_check(T_ENTITY, T_ARCH); fail_unless(error_count() == 0); - eval_t *ex = eval_new(EVAL_FCALL); + eval_t *ex = eval_new(); simplify_global(a, NULL, ex); // Global to fold TIME expressions eval_free(ex); bounds_check(a); @@ -170,7 +170,7 @@ START_TEST(test_case) tree_t a = parse_and_check(T_ENTITY, T_ARCH); fail_unless(error_count() == 0); - eval_t *eval = eval_new(0); + eval_t *eval = eval_new(); simplify_local(a, eval); bounds_check(a); eval_free(eval); @@ -185,7 +185,7 @@ START_TEST(test_issue36) tree_t e = parse_and_check(T_ENTITY); - eval_t *eval = eval_new(0); + eval_t *eval = eval_new(); simplify_local(e, eval); bounds_check(e); eval_free(eval); @@ -212,7 +212,7 @@ START_TEST(test_issue54) tree_t a = parse_and_check(T_ENTITY, T_ARCH); fail_unless(error_count() == 0); - eval_t *eval = eval_new(0); + eval_t *eval = eval_new(); simplify_local(a, eval); bounds_check(a); eval_free(eval); @@ -235,7 +235,7 @@ START_TEST(test_issue99) tree_t a = parse_and_check(T_ENTITY, T_ARCH); fail_unless(error_count() == 0); - eval_t *eval = eval_new(0); + eval_t *eval = eval_new(); simplify_local(a, eval); bounds_check(a); @@ -257,7 +257,7 @@ START_TEST(test_issue150) tree_t a = parse_and_check(T_ENTITY, T_ARCH); fail_unless(error_count() == 0); - eval_t *eval = eval_new(0); + eval_t *eval = eval_new(); simplify_local(a, eval); bounds_check(a); eval_free(eval); @@ -273,7 +273,7 @@ START_TEST(test_issue200) tree_t a = parse_and_check(T_ENTITY, T_ARCH); fail_unless(error_count() == 0); - eval_t *eval = eval_new(0); + eval_t *eval = eval_new(); simplify_local(a, eval); bounds_check(a); eval_free(eval); @@ -295,7 +295,7 @@ START_TEST(test_issue208) tree_t a = parse_and_check(T_ENTITY, T_ARCH); fail_unless(error_count() == 0); - eval_t *eval = eval_new(0); + eval_t *eval = eval_new(); simplify_local(a, eval); bounds_check(a); eval_free(eval); @@ -316,7 +316,7 @@ START_TEST(test_issue247) tree_t a = parse_and_check(T_PACKAGE); fail_unless(error_count() == 0); - eval_t *eval = eval_new(0); + eval_t *eval = eval_new(); simplify_local(a, eval); bounds_check(a); eval_free(eval); @@ -337,7 +337,7 @@ START_TEST(test_issue269) tree_t a = parse_and_check(T_PACKAGE); fail_unless(error_count() == 0); - eval_t *eval = eval_new(0); + eval_t *eval = eval_new(); simplify_local(a, eval); bounds_check(a); eval_free(eval); diff --git a/test/test_lower.c b/test/test_lower.c index a496410d..941f907e 100644 --- a/test/test_lower.c +++ b/test/test_lower.c @@ -2287,7 +2287,7 @@ START_TEST(test_issue158) { input_from_file(TESTDIR "/lower/issue158.vhd"); - eval_t *eval = eval_new(0); + eval_t *eval = eval_new(); tree_t p = parse_and_check(T_PACKAGE, T_PACK_BODY); simplify_local(p, eval); lower_unit(p, NULL); diff --git a/test/test_simp.c b/test/test_simp.c index c38f0427..35ab5013 100644 --- a/test/test_simp.c +++ b/test/test_simp.c @@ -81,7 +81,7 @@ START_TEST(test_cfold) fail_if_errors(); - eval_t *eval = eval_new(0); + eval_t *eval = eval_new(); simplify_local(a, eval); eval_free(eval); @@ -201,7 +201,7 @@ START_TEST(test_proc) fail_if_errors(); - eval_t *eval = eval_new(0); + eval_t *eval = eval_new(); simplify_local(a, eval); eval_free(eval); @@ -282,7 +282,7 @@ START_TEST(test_args) fail_if_errors(); - eval_t *eval = eval_new(0); + eval_t *eval = eval_new(); simplify_local(a, eval); eval_free(eval); @@ -324,7 +324,7 @@ START_TEST(test_ffold) tree_t b = tree_stmt(a, 0); fail_unless(tree_kind(b) == T_BLOCK); - eval_t *ex = eval_new(EVAL_FCALL); + eval_t *ex = eval_new(); simplify_global(b, NULL, ex); eval_free(ex); fail_if_errors(); @@ -372,7 +372,7 @@ START_TEST(test_ffold2) tree_t b = tree_stmt(a, 0); fail_unless(tree_kind(b) == T_BLOCK); - eval_t *ex = eval_new(EVAL_FCALL); + eval_t *ex = eval_new(); simplify_global(b, NULL, ex); eval_free(ex); fail_if_errors(); @@ -388,7 +388,7 @@ START_TEST(test_issue49) tree_t a = parse_and_check(T_ENTITY, T_ARCH); fail_if_errors(); - eval_t *eval = eval_new(0); + eval_t *eval = eval_new(); simplify_local(a, eval); eval_free(eval); } @@ -401,7 +401,7 @@ START_TEST(test_issue155) tree_t p = parse_and_check(T_PACKAGE); fail_if_errors(); - eval_t *ex = eval_new(EVAL_FCALL); + eval_t *ex = eval_new(); simplify_global(p, NULL, ex); eval_free(ex); @@ -441,7 +441,7 @@ START_TEST(test_context) fail_unless(tree_contexts(e) == 5); - eval_t *eval = eval_new(0); + eval_t *eval = eval_new(); simplify_local(e, eval); eval_free(eval); diff --git a/test/test_util.c b/test/test_util.c index 06ce8f4e..f97fc7ac 100644 --- a/test/test_util.c +++ b/test/test_util.c @@ -141,7 +141,7 @@ TCase *nvc_unit_test(void) tree_t run_elab(void) { - eval_t *eval = eval_new(EVAL_FCALL); + eval_t *eval = eval_new(); tree_t t, last_ent = NULL; while ((t = parse())) { @@ -168,7 +168,7 @@ tree_t run_elab(void) tree_t _parse_and_check(const tree_kind_t *array, int num, bool simp, bool lower) { - eval_t *eval = simp ? eval_new(EVAL_FCALL) : NULL; + eval_t *eval = simp ? eval_new() : NULL; tree_t last = NULL; for (int i = 0; i < num; i++) { -- 2.39.2