From 6d0d9ddae341e2dde4c7161f415f8c38e382b1c0 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Sun, 19 Mar 2017 14:06:15 +0000 Subject: [PATCH] Stop lowering architectures early as this causes problems --- src/lower.c | 19 ---------- test/lower/arch1.vhd | 27 -------------- test/lower/issue304.vhd | 25 ------------- test/simp/ffold.vhd | 78 +++++++++++++++++++++++++++++++---------- test/test_lower.c | 77 ++++++++++------------------------------ test/test_simp.c | 7 ++-- test/test_util.c | 12 +++++-- test/test_util.h | 20 +++++++---- 8 files changed, 102 insertions(+), 163 deletions(-) delete mode 100644 test/lower/arch1.vhd delete mode 100644 test/lower/issue304.vhd diff --git a/src/lower.c b/src/lower.c index 252a03d0..cdacc094 100644 --- a/src/lower.c +++ b/src/lower.c @@ -4808,18 +4808,6 @@ static vcode_unit_t lower_package(tree_t unit) return context; } -static vcode_unit_t lower_arch(tree_t unit) -{ - vcode_unit_t context = emit_context(tree_ident(unit)); - - lower_decls(unit, context); - - emit_return(VCODE_INVALID_REG); - - lower_finished(); - return context; -} - static void lower_set_verbose(void) { static bool set = false; @@ -4851,13 +4839,6 @@ vcode_unit_t lower_unit(tree_t unit) case T_PACKAGE: context = lower_package(unit); break; - case T_ENTITY: - case T_CONFIG: - break; - case T_ARCH: - mode = LOWER_THUNK; - context = lower_arch(unit); - break; default: fatal("cannot lower unit kind %s to vcode", tree_kind_str(tree_kind(unit))); diff --git a/test/lower/arch1.vhd b/test/lower/arch1.vhd deleted file mode 100644 index 0665191d..00000000 --- a/test/lower/arch1.vhd +++ /dev/null @@ -1,27 +0,0 @@ -entity arch1 is - generic ( sld_node_n_scan : integer ); -end entity; - -architecture test of arch1 is - type rec is record - x, y : integer; - z : bit_vector(3 downto 0); - end record; - type scansArray is array (sld_node_n_scan - 1 downto 0) of rec; - type rec2 is record - r : scansArray; - end record; - - function f return scansArray is - variable v : rec2; - begin - return v.r; - end function; - - function g return integer is - begin - return 5; - end function; -begin - -end architecture; diff --git a/test/lower/issue304.vhd b/test/lower/issue304.vhd deleted file mode 100644 index e84c31de..00000000 --- a/test/lower/issue304.vhd +++ /dev/null @@ -1,25 +0,0 @@ -package TEST_TYPES is - type WIDTH_TYPE is record - DATA : integer; - end record; -end package; - -use work.test_types.all; - -entity TEST_NG is - generic ( - WIDTH : WIDTH_TYPE - ); - port ( - DATA_I : in bit_vector(WIDTH.DATA-1 downto 0); - DATA_O : out bit_vector(WIDTH.DATA-1 downto 0) - ); -end TEST_NG; - -architecture MODEL of TEST_NG is - procedure output_data is - begin - DATA_O <= DATA_I; - end procedure; -begin -end MODEL; diff --git a/test/simp/ffold.vhd b/test/simp/ffold.vhd index cd374205..60099bd8 100644 --- a/test/simp/ffold.vhd +++ b/test/simp/ffold.vhd @@ -2,6 +2,55 @@ package pack is function add4(x : in integer) return integer; + function add1(x : in integer) return integer; + + function log2(x : in integer) return integer; + + function case1(x : in integer) return integer; + + function adddef(x, y : in integer := 5) return integer; + + function chain1(x : string) return boolean; + + function chain2(x, y : string) return boolean; + + function flip(x : bit_vector(3 downto 0)) return bit_vector; + + type real_vector is array (natural range <>) of real; + + function lookup(index : integer) return real; + + function get_bitvec(x, y : integer) return bit_vector; + + function approx(x, y : real; t : real := 0.001) return boolean; + + function get_string(x : integer) return string; + + function get_string(x : real) return string; + + function get_string(x : character) return string; + + function get_string(x : time) return string; + + function needs_heap(x : integer) return integer; + + function sum_left_right(x : bit_vector) return integer; + + procedure p5(x : in integer; y : out integer); + + function call_proc(x : in integer) return integer; + + type rec is record + x : bit_vector(1 to 3); + y : integer; + end record; + + function make_rec(x : bit_vector(1 to 3); y : integer) return rec; + + function min(x, y : integer) return integer; + + function get_left(x : bit_vector) return bit; + end package; package body pack is @@ -11,17 +60,6 @@ package body pack is return x + 4; end function; -end package body; - -------------------------------------------------------------------------------- - -entity ffold is -end entity; - -use work.pack.all; - -architecture a of ffold is - function add1(x : in integer) return integer is begin return x + 1; @@ -89,8 +127,6 @@ architecture a of ffold is return r; end function; - type real_vector is array (natural range <>) of real; - function lookup(index : integer) return real is constant table : real_vector := ( 0.62, 61.62, 71.7, 17.25, 26.15, 651.6, 0.45, 5.761 ); @@ -156,11 +192,6 @@ architecture a of ffold is return y; end function; - type rec is record - x : bit_vector(1 to 3); - y : integer; - end record; - function make_rec(x : bit_vector(1 to 3); y : integer) return rec is variable r : rec; begin @@ -186,6 +217,17 @@ architecture a of ffold is return x(l); end function; +end package body; + +------------------------------------------------------------------------------- + +entity ffold is +end entity; + +use work.pack.all; + +architecture a of ffold is + begin b1: block is diff --git a/test/test_lower.c b/test/test_lower.c index 25259bce..a56f58ff 100644 --- a/test/test_lower.c +++ b/test/test_lower.c @@ -848,9 +848,9 @@ START_TEST(test_func1) EXPECT_BB(1) = { { VCODE_OP_CONST, .value = 2 }, #if LLVM_MANGLES_NAMES - { VCODE_OP_FCALL, .func = "WORK.FUNC1-TEST.ADD1__II", .args = 1 }, + { VCODE_OP_FCALL, .func = ":func1:add1__II", .args = 1 }, #else - { VCODE_OP_FCALL, .func = "WORK.FUNC1-TEST.ADD1$II", .args = 1 }, + { VCODE_OP_FCALL, .func = ":func1:add1$II", .args = 1 }, #endif { VCODE_OP_STORE, .name = "R" }, { VCODE_OP_WAIT, .target = 2 } @@ -1357,9 +1357,9 @@ START_TEST(test_proc1) { VCODE_OP_LOAD, .name = "A" }, { VCODE_OP_INDEX, .name = "B" }, #if LLVM_MANGLES_NAMES - { VCODE_OP_FCALL, .func = "WORK.PROC1-TEST.ADD1__vII", .args = 2 }, + { VCODE_OP_FCALL, .func = ":proc1:add1__vII", .args = 2 }, #else - { VCODE_OP_FCALL, .func = "WORK.PROC1-TEST.ADD1$vII", .args = 2 }, + { VCODE_OP_FCALL, .func = ":proc1:add1$vII", .args = 2 }, #endif { VCODE_OP_CONST, .value = 2 }, { VCODE_OP_LOAD, .name = "B" }, @@ -1368,9 +1368,9 @@ START_TEST(test_proc1) { VCODE_OP_ASSERT }, { VCODE_OP_CONST, .value = 5 }, #if LLVM_MANGLES_NAMES - { VCODE_OP_FCALL, .func = "WORK.PROC1-TEST.ADD1__vII", .args = 2 }, + { VCODE_OP_FCALL, .func = ":proc1:add1__vII", .args = 2 }, #else - { VCODE_OP_FCALL, .func = "WORK.PROC1-TEST.ADD1$vII", .args = 2 }, + { VCODE_OP_FCALL, .func = ":proc1:add1$vII", .args = 2 }, #endif { VCODE_OP_LOAD, .name = "B" }, { VCODE_OP_CONST, .value = 6 }, @@ -1517,10 +1517,10 @@ START_TEST(test_proc3) EXPECT_BB(1) = { { VCODE_OP_INDEX, .name = "X" }, #if LLVM_MANGLES_NAMES - { VCODE_OP_PCALL, .func = "WORK.PROC3-TEST.P1__vI", + { VCODE_OP_PCALL, .func = ":proc3:p1__vI", .target = 2, .args = 1 }, #else - { VCODE_OP_PCALL, .func = "WORK.PROC3-TEST.P1$vI", .target = 2, .args = 1 } + { VCODE_OP_PCALL, .func = ":proc3:p1$vI", .target = 2, .args = 1 } #endif }; @@ -1528,9 +1528,9 @@ START_TEST(test_proc3) EXPECT_BB(2) = { #if LLVM_MANGLES_NAMES - { VCODE_OP_RESUME, .func = "WORK.PROC3-TEST.P1__vI" }, + { VCODE_OP_RESUME, .func = ":proc3:p1__vI" }, #else - { VCODE_OP_RESUME, .func = "WORK.PROC3-TEST.P1$vI" }, + { VCODE_OP_RESUME, .func = ":proc3:p1$vI" }, #endif { VCODE_OP_WAIT, .target = 3 } }; @@ -1746,17 +1746,17 @@ START_TEST(test_func5) { VCODE_OP_CONST, .value = 2 }, { VCODE_OP_NETS, .name = ":func5:x" }, #if LLVM_MANGLES_NAMES - { VCODE_OP_FCALL, .func = "WORK.FUNC5-TEST.ADD_ONE_S__IsI", .args = 1 }, + { VCODE_OP_FCALL, .func = ":func5:add_one_s__IsI", .args = 1 }, #else - { VCODE_OP_FCALL, .func = "WORK.FUNC5-TEST.ADD_ONE_S$IsI", .args = 1 }, + { VCODE_OP_FCALL, .func = ":func5:add_one_s$IsI", .args = 1 }, #endif { VCODE_OP_CONST, .value = 6 }, { VCODE_OP_CMP, .cmp = VCODE_CMP_EQ }, { VCODE_OP_ASSERT }, #if LLVM_MANGLES_NAMES - { VCODE_OP_FCALL, .func = "WORK.FUNC5-TEST.EVENT__BsI", .args = 1 }, + { VCODE_OP_FCALL, .func = ":func5:event__BsI", .args = 1 }, #else - { VCODE_OP_FCALL, .func = "WORK.FUNC5-TEST.EVENT$BsI", .args = 1 }, + { VCODE_OP_FCALL, .func = ":func5:event$BsI", .args = 1 }, #endif { VCODE_OP_ASSERT }, { VCODE_OP_WAIT, .target = 2 } @@ -2014,10 +2014,10 @@ START_TEST(test_issue122) EXPECT_BB(0) = { #if LLVM_MANGLES_NAMES { VCODE_OP_NESTED_FCALL, - .func = "WORK.ISSUE122-TEST.FUNC__NESTED__II__NESTED__I" }, + .func = ":issue122:func__II__NESTED__I" }, #else { VCODE_OP_NESTED_FCALL, - .func = "WORK.ISSUE122-TEST.FUNC$II__NESTED$I" }, + .func = ":issue122:func$II__NESTED$I" }, #endif { VCODE_OP_STORE, .name = "V" }, { VCODE_OP_RETURN } @@ -2577,51 +2577,12 @@ START_TEST(test_thunk) } END_TEST -START_TEST(test_arch1) -{ - input_from_file(TESTDIR "/lower/arch1.vhd"); - - tree_t arch = parse_check_and_simplify(T_ENTITY, T_ARCH); - - vcode_unit_t t0 = lower_unit(arch); - fail_if(t0 == NULL); - - vcode_unit_t f = vcode_find_unit(ident_new("WORK.ARCH1-TEST.F$uSCANSARRAY")); - fail_unless(f == NULL); - - vcode_unit_t g = vcode_find_unit(ident_new("WORK.ARCH1-TEST.G$I")); - fail_if(g == NULL); -} -END_TEST - START_TEST(test_issue303) { input_from_file(TESTDIR "/lower/issue303.vhd"); - tree_t arch = parse_check_and_simplify(T_ENTITY, T_ARCH); - - vcode_unit_t t0 = lower_unit(arch); - fail_if(t0 == NULL); - - vcode_unit_t f = - vcode_find_unit(ident_new("WORK.TEST_NG-MODEL.WAIT_ON_SIGNALSv")); - fail_unless(f == NULL); - - vcode_unit_t g = vcode_find_unit(ident_new("WORK.TEST_NG-MODEL")); - fail_if(g == NULL); -} -END_TEST - -START_TEST(test_issue304) -{ - input_from_file(TESTDIR "/lower/issue304.vhd"); - - tree_t arch = parse_check_and_simplify(T_PACKAGE, T_ENTITY, T_ARCH); - - vcode_unit_t t0 = lower_unit(arch); - fail_if(t0 == NULL); - - fail_if(vcode_find_unit(ident_new("WORK.TEST_NG-MODEL.OUTPUT_DATAv"))); + tree_t e = run_elab(); + lower_unit(e); } END_TEST @@ -2685,9 +2646,7 @@ int main(void) tcase_add_test(tc, test_real1); tcase_add_test(tc, test_assert1); tcase_add_test(tc, test_thunk); - tcase_add_test(tc, test_arch1); tcase_add_test(tc, test_issue303); - tcase_add_test(tc, test_issue304); suite_add_tcase(s, tc); return nvc_run_test(s); diff --git a/test/test_simp.c b/test/test_simp.c index 6ed5c342..349475b8 100644 --- a/test/test_simp.c +++ b/test/test_simp.c @@ -281,13 +281,10 @@ START_TEST(test_ffold) { input_from_file(TESTDIR "/simp/ffold.vhd"); - tree_t a = parse_check_and_simplify(T_PACKAGE, T_PACK_BODY, - T_ENTITY, T_ARCH); + tree_t a = parse_check_simplify_and_lower(T_PACKAGE, T_PACK_BODY, + T_ENTITY, T_ARCH); fail_unless(sem_errors() == 0); - lower_unit(a); - simplify(a); - tree_t b = tree_stmt(a, 0); fail_unless(tree_kind(b) == T_BLOCK); diff --git a/test/test_util.c b/test/test_util.c index 9648b711..70332893 100644 --- a/test/test_util.c +++ b/test/test_util.c @@ -92,7 +92,8 @@ tree_t run_elab(void) fail_if(sem_errors() > 0); simplify(t); - lower_unit(t); + if (tree_kind(t) == T_PACKAGE || tree_kind(t) == T_PACK_BODY) + lower_unit(t); if (tree_kind(t) == T_ENTITY) last_ent = t; @@ -101,7 +102,8 @@ tree_t run_elab(void) return elab(last_ent); } -tree_t _parse_and_check(const tree_kind_t *array, int num, bool simp) +tree_t _parse_and_check(const tree_kind_t *array, int num, + bool simp, bool lower) { tree_t last = NULL; for (int i = 0; i < num; i++) { @@ -110,15 +112,19 @@ tree_t _parse_and_check(const tree_kind_t *array, int num, bool simp) last = parse(); fail_if(last == NULL); + const tree_kind_t kind = tree_kind(last); fail_unless(tree_kind(last) == array[i], "expected %s have %s", tree_kind_str(array[i]), - tree_kind_str(tree_kind(last))); + tree_kind_str(kind)); const bool sem_ok = sem_check(last); if (simp) { fail_unless(sem_ok, "semantic check failed"); simplify(last); } + + if (lower && (kind == T_PACKAGE || kind == T_PACK_BODY)) + lower_unit(last); } fail_unless(parse() == NULL); diff --git a/test/test_util.h b/test/test_util.h index 475c3a41..63d5182c 100644 --- a/test/test_util.h +++ b/test/test_util.h @@ -6,14 +6,19 @@ #include -#define parse_and_check(...) ({ \ - static const tree_kind_t array[] = { __VA_ARGS__ }; \ - _parse_and_check(array, ARRAY_LEN(array), false); \ +#define parse_and_check(...) ({ \ + static const tree_kind_t array[] = { __VA_ARGS__ }; \ + _parse_and_check(array, ARRAY_LEN(array), false, false); \ }) -#define parse_check_and_simplify(...) ({ \ - static const tree_kind_t array[] = { __VA_ARGS__ }; \ - _parse_and_check(array, ARRAY_LEN(array), true); \ +#define parse_check_and_simplify(...) ({ \ + static const tree_kind_t array[] = { __VA_ARGS__ }; \ + _parse_and_check(array, ARRAY_LEN(array), true, false); \ + }) + +#define parse_check_simplify_and_lower(...) ({ \ + static const tree_kind_t array[] = { __VA_ARGS__ }; \ + _parse_and_check(array, ARRAY_LEN(array), true, true); \ }) typedef struct { @@ -25,6 +30,7 @@ void expect_errors(const error_t *lines); TCase *nvc_unit_test(void); int nvc_run_test(Suite *s); tree_t run_elab(void); -tree_t _parse_and_check(const tree_kind_t *array, int num, bool simp); +tree_t _parse_and_check(const tree_kind_t *array, int num, + bool simp, bool lower); #endif // _TEST_UTIL_H -- 2.39.2