Skip to content

Commit

Permalink
WIP: rest of SDF parsing tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrej.ille committed Aug 26, 2024
1 parent a2b54c8 commit 886c359
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/lexer.l
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ EXCEPTION ?i:EXCEPTION
<INITIAL,PSL>{ABS} { TOKEN(tABS); }
<INITIAL,PSL>{NOT} { TOKEN(tNOT); }
<INITIAL,PSL>{ALL} { TOKEN(tALL); }
<INITIAL,PSL>{TICK} { TOKEN(tTICK); }
<INITIAL,PSL,SDF>{TICK} { TOKEN(tTICK); }
<INITIAL,PSL>{SLL} { TOKEN(tSLL); }
<INITIAL,PSL>{SRL} { TOKEN(tSRL); }
<INITIAL,PSL>{SLA} { TOKEN(tSLA); }
Expand Down
7 changes: 4 additions & 3 deletions src/sdf/sdf-parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ static sdf_node_t p_signed_real_number(void)
return n;
}

static int p_scalar_const_id(void)
static int64_t p_scalar_const_id(void)
{
ident_t id = p_identifier();

Expand Down Expand Up @@ -524,12 +524,13 @@ static sdf_node_t p_scalar_constant(void)
BEGIN("scalar constant");

int tok = peek();
assert (tok == tINT || tok == tTICK);
consume(tok);

sdf_node_t c = sdf_new(S_NUMBER);
sdf_set_subkind(c, S_NUMBER_INTEGER);

int val = -1;
int64_t val = -1;
switch (tok) {
case tINT:
if (optional(tTICK))
Expand Down Expand Up @@ -2051,7 +2052,7 @@ static void p_deldef_list(sdf_node_t cell, sdf_flags_t flag)
case tNETDELAY:
p_netdelay_def(d);
break;
default:
default: // tDEVICE
p_device_def(d);
}

Expand Down
13 changes: 13 additions & 0 deletions test/sdf/parse15.sdf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
(DELAYFILE
(SDFVERSION "4.0")
(CELL
(CELLTYPE "DFF")
(INSTANCE hierarchy_example)
(DELAY
(PATHPULSE (0.4))
(PATHPULSE (0.1) (0.5))
(PATHPULSE my_inst.my_sub_inst.a my_inst_my_sub_inst.b (5.4))
(PATHPULSEPERCENT top.in top.out (10.2) (11.9))
)
)
)
67 changes: 67 additions & 0 deletions test/test_sdf.c
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,72 @@ START_TEST(test_sdf14)
}
END_TEST

START_TEST(test_sdf15)
{
input_from_file(TESTDIR "/sdf/parse15.sdf");

sdf_file_t *file = sdf_parse();
sdf_node_t s = file->root;

fail_if(s == NULL);

sdf_node_t c = sdf_cell(s, 0);
fail_unless(sdf_delays(c) == 4);

sdf_node_t d_0 = sdf_delay(c, 0);
fail_unless(sdf_subkind(d_0) == S_DELAY_KIND_PATHPULSE);
fail_unless(sdf_values(d_0) == 1);

sdf_node_t d_0_v_0 = sdf_value(d_0, 0);
fail_unless(sdf_kind(d_0_v_0) == S_VALUE);

sdf_node_t d_1 = sdf_delay(c, 1);
fail_unless(sdf_subkind(d_1) == S_DELAY_KIND_PATHPULSE);
fail_unless(sdf_values(d_1) == 2);

sdf_node_t d_1_v_0 = sdf_value(d_1, 0);
fail_unless(sdf_kind(d_1_v_0) == S_VALUE);
fail_unless_floats_equal(sdf_dval(sdf_number(d_1_v_0)), 0.1);

sdf_node_t d_1_v_1 = sdf_value(d_1, 1);
fail_unless(sdf_kind(d_1_v_1) == S_VALUE);
fail_unless_floats_equal(sdf_dval(sdf_number(d_1_v_1)), 0.5);

sdf_node_t d_2 = sdf_delay(c, 2);
fail_unless(sdf_subkind(d_2) == S_DELAY_KIND_PATHPULSE);
fail_unless(sdf_values(d_2) == 1);

sdf_node_t d_2_p_1 = sdf_port(d_2, 0);
sdf_node_t d_2_p_2 = sdf_port(d_2, 1);

fail_unless(icmp(sdf_ident(d_2_p_1), "my_inst.my_sub_inst.a"));
fail_unless(icmp(sdf_ident(d_2_p_2), "my_inst_my_sub_inst.b"));

sdf_node_t d_2_v_0 = sdf_value(d_2, 0);
fail_unless(sdf_kind(d_2_v_0) == S_VALUE);

sdf_node_t d_3 = sdf_delay(c, 3);
fail_unless(sdf_subkind(d_3) == S_DELAY_KIND_PATHPULSEP);
fail_unless(sdf_values(d_3) == 2);

sdf_node_t d_3_p_1 = sdf_port(d_3, 0);
sdf_node_t d_3_p_2 = sdf_port(d_3, 1);

fail_unless(icmp(sdf_ident(d_3_p_1), "top.in"));
fail_unless(icmp(sdf_ident(d_3_p_2), "top.out"));

fail_unless(sdf_values(d_3) == 2);

sdf_node_t d_3_v_0 = sdf_value(d_3, 0);
fail_unless(sdf_kind(d_3_v_0) == S_VALUE);
fail_unless_floats_equal(sdf_dval(sdf_number(d_3_v_0)), 10.2);

sdf_node_t d_3_v_1 = sdf_value(d_3, 1);
fail_unless(sdf_kind(d_3_v_1) == S_VALUE);
fail_unless_floats_equal(sdf_dval(sdf_number(d_3_v_1)), 11.9);
}
END_TEST

Suite *get_sdf_tests(void)
{
Suite *s = suite_create("sdf");
Expand All @@ -631,6 +697,7 @@ Suite *get_sdf_tests(void)
tcase_add_test(tc_core, test_sdf12);
tcase_add_test(tc_core, test_sdf13);
tcase_add_test(tc_core, test_sdf14);
tcase_add_test(tc_core, test_sdf15);
suite_add_tcase(s, tc_core);

return s;
Expand Down

0 comments on commit 886c359

Please sign in to comment.