Permalink
Browse files

Parsing and elaboration for blocks

  • Loading branch information...
1 parent c575e1b commit 59b2f6171dd41ceb11f8cb341e50411a30f11eaf @nickg committed Mar 30, 2012
Showing with 141 additions and 27 deletions.
  1. +26 −5 src/elab.c
  2. +2 −0 src/lexer.l
  3. +30 −22 src/parse.y
  4. +15 −0 test/parse/block.vhd
  5. +39 −0 test/regress/block1.vhd
  6. +1 −0 test/regress/testlist.txt
  7. +28 −0 test/test_parse.c
View
@@ -24,6 +24,7 @@
#include <stdarg.h>
static void elab_arch(tree_t t, tree_t out, ident_t path);
+static void elab_block(tree_t t, tree_t out, ident_t path);
static ident_t hpathf(ident_t path, char sep, const char *fmt, ...)
{
@@ -217,10 +218,8 @@ static void elab_instance(tree_t t, tree_t out, ident_t path)
elab_arch(arch, out, path);
}
-static void elab_arch(tree_t t, tree_t out, ident_t path)
+static void elab_decls(tree_t t, tree_t out, ident_t path)
{
- elab_copy_context(out, t);
-
for (unsigned i = 0; i < tree_decls(t); i++) {
tree_t d = tree_decl(t, i);
ident_t pn = hpathf(path, ':', "%s",
@@ -248,19 +247,41 @@ static void elab_arch(tree_t t, tree_t out, ident_t path)
break;
}
}
+}
+static void elab_stmts(tree_t t, tree_t out, ident_t path)
+{
for (unsigned i = 0; i < tree_stmts(t); i++) {
tree_t s = tree_stmt(t, i);
ident_t npath = hpathf(path, ':', "%s", istr(tree_ident(s)));
tree_set_ident(s, npath);
- if (tree_kind(s) == T_INSTANCE)
+ switch (tree_kind(s)) {
+ case T_INSTANCE:
elab_instance(s, out, npath);
- else
+ break;
+ case T_BLOCK:
+ elab_block(s, out, npath);
+ break;
+ default:
tree_add_stmt(out, s);
+ }
}
}
+static void elab_block(tree_t t, tree_t out, ident_t path)
+{
+ elab_decls(t, out, path);
+ elab_stmts(t, out, path);
+}
+
+static void elab_arch(tree_t t, tree_t out, ident_t path)
+{
+ elab_copy_context(out, t);
+ elab_decls(t, out, path);
+ elab_stmts(t, out, path);
+}
+
static void elab_entity(tree_t t, tree_t out, ident_t path)
{
if (tree_ports(t) > 0 || tree_generics(t) > 0) {
View
@@ -157,6 +157,7 @@ CASE {C}{A}{S}{E}
TRANSPORT {T}{R}{A}{N}{S}{P}{O}{R}{T}
INERTIAL {I}{N}{E}{R}{T}{I}{A}{L}
REJECT {R}{E}{J}{E}{C}{T}
+BLOCK {B}{L}{O}{C}{K}
%%
@@ -234,6 +235,7 @@ REJECT {R}{E}{J}{E}{C}{T}
{TRANSPORT} { TOKEN(tTRANSPORT); }
{REJECT} { TOKEN(tREJECT); }
{INERTIAL} { TOKEN(tINERTIAL); }
+{BLOCK} { TOKEN(tBLOCK); }
"(" { TOKEN(tLPAREN); }
")" { TOKEN(tRPAREN); }
View
@@ -160,11 +160,11 @@
%type <t> package_decl name aggregate string_literal report
%type <t> waveform_element seq_stmt_without_label conc_assign_stmt
%type <t> comp_instance_stmt conc_stmt_without_label elsif_list
-%type <t> delay_mechanism bit_string_literal
+%type <t> delay_mechanism bit_string_literal block_stmt
%type <i> id opt_id selected_id func_name
%type <l> interface_object_decl interface_list
%type <l> port_clause generic_clause interface_decl signal_decl
-%type <l> block_decl_item arch_decl_part arch_stmt_part process_decl_part
+%type <l> block_decl_item block_decl_part conc_stmt_list process_decl_part
%type <l> variable_decl process_decl_item seq_stmt_list type_decl
%type <l> subtype_decl package_decl_part package_decl_item enum_lit_list
%type <l> constant_decl formal_param_list subprogram_decl name_list
@@ -197,7 +197,7 @@
%token tOTHERS tASSERT tSEVERITY tON tMAP tTHEN tELSE tELSIF tBODY
%token tWHILE tLOOP tAFTER tALIAS tATTRIBUTE tPROCEDURE tEXIT
%token tWHEN tCASE tBAR tLSQUARE tRSQUARE tINERTIAL tTRANSPORT
-%token tREJECT tBITSTRING
+%token tREJECT tBITSTRING tBLOCK
%left tAND tOR tNAND tNOR tXOR tXNOR
%left tEQ tNEQ tLT tLE tGT tGE
@@ -414,7 +414,7 @@ port_clause
;
arch_body
-: tARCHITECTURE id tOF id tIS arch_decl_part tBEGIN arch_stmt_part
+: tARCHITECTURE id tOF id tIS block_decl_part tBEGIN conc_stmt_list
tEND opt_arch_token opt_id tSEMI
{
$$ = tree_new(T_ARCH);
@@ -431,18 +431,6 @@ arch_body
}
;
-arch_decl_part
-: block_decl_item arch_decl_part
- {
- $$ = $1;
- tree_list_concat(&$$, $2);
- }
-| /* empty */
- {
- $$ = NULL;
- }
-;
-
block_decl_item
: signal_decl
| type_decl
@@ -556,8 +544,8 @@ entity_class
| tTYPE | tSUBTYPE | tCONSTANT | tSIGNAL | tVARIABLE
;
-arch_stmt_part
-: conc_stmt arch_stmt_part
+conc_stmt_list
+: conc_stmt conc_stmt_list
{
$$ = $2;
tree_list_prepend(&$$, $1);
@@ -660,7 +648,7 @@ conc_stmt
{
$$ = $3;
if (tree_has_ident($$) && tree_ident($$) != $1)
- parse_error(&@1, "%s does not match process name %s",
+ parse_error(&@1, "%s does not match statement name %s",
istr(tree_ident($$)), istr($1));
else
tree_set_ident($$, $1);
@@ -679,9 +667,8 @@ conc_stmt_without_label
: process_stmt
| comp_instance_stmt
| conc_assign_stmt
- /* | block_statement
- | process_statement
- | concurrent_procedure_call_statement
+| block_stmt
+ /* | concurrent_procedure_call_statement
| concurrent_assertion_statement
| generate_statement */
;
@@ -787,6 +774,27 @@ process_decl_item
*/
;
+block_stmt
+: tBLOCK /* [ ( guard_expression ) ] */ opt_is /*block_header*/
+ block_decl_part tBEGIN conc_stmt_list tEND tBLOCK opt_id tSEMI
+ {
+ $$ = tree_new(T_BLOCK);
+ copy_trees($3, tree_add_decl, $$);
+ copy_trees($5, tree_add_stmt, $$);
+ if ($8 != NULL)
+ tree_set_ident($$, $8);
+ }
+;
+
+block_decl_part
+: block_decl_item block_decl_part
+ {
+ $$ = $1;
+ tree_list_concat(&$$, $2);
+ }
+| /* empty */ { $$ = NULL; }
+;
+
subprogram_decl
: /* procedure designator [ ( formal_parameter_list ) ] | */
func_type func_name formal_param_list tRETURN type_mark tSEMI
View
@@ -0,0 +1,15 @@
+architecture a of e is
+begin
+
+ b: block is
+ begin
+ end block;
+
+ c: block is
+ signal x : integer;
+ signal y : real;
+ begin
+ x <= y;
+ end block;
+
+end architecture;
View
@@ -0,0 +1,39 @@
+entity block1 is
+end entity;
+
+architecture test of block1 is
+ signal u, v, w: integer;
+begin
+
+ process is
+ begin
+ u <= 1;
+ wait for 1 ns;
+ u <= 2;
+ wait;
+ end process;
+
+ a: block is
+ signal x : integer;
+ begin
+ x <= u + 2;
+ v <= x;
+ end block;
+
+ b: block is
+ signal x : integer;
+ begin
+ x <= v + 6;
+ w <= x;
+ end block;
+
+ process is
+ begin
+ wait for 1 ns;
+ assert w = 9;
+ wait for 1 ns;
+ assert w = 10;
+ wait;
+ end process;
+
+end architecture;
@@ -60,3 +60,4 @@ default1 normal
generic1 normal
signal7 normal
synopsys1 normal
+block1 normal
View
@@ -1368,6 +1368,33 @@ START_TEST(test_bitstring)
}
END_TEST
+START_TEST(test_block)
+{
+ tree_t a, b;
+
+ fail_unless(input_from_file(TESTDIR "/parse/block.vhd"));
+
+ a = parse();
+ fail_unless(tree_kind(a) == T_ARCH);
+ fail_unless(tree_stmts(a) == 2);
+
+ b = tree_stmt(a, 0);
+ fail_unless(tree_kind(b) == T_BLOCK);
+ fail_unless(tree_decls(b) == 0);
+ fail_unless(tree_stmts(b) == 0);
+
+ b = tree_stmt(a, 1);
+ fail_unless(tree_kind(b) == T_BLOCK);
+ fail_unless(tree_decls(b) == 2);
+ fail_unless(tree_stmts(b) == 1);
+
+ a = parse();
+ fail_unless(a == NULL);
+
+ fail_unless(parse_errors() == 0);
+}
+END_TEST
+
int main(void)
{
register_trace_signal_handlers();
@@ -1396,6 +1423,7 @@ int main(void)
tcase_add_test(tc_core, test_concat);
tcase_add_test(tc_core, test_based);
tcase_add_test(tc_core, test_bitstring);
+ tcase_add_test(tc_core, test_block);
suite_add_tcase(s, tc_core);
SRunner *sr = srunner_create(s);

0 comments on commit 59b2f61

Please sign in to comment.