Skip to content
Browse files

Semantic checking for OPEN expressions

  • Loading branch information...
1 parent 2bd84af commit 9cb42cb5dc70399fea1777cfa5f7437f690a8552 @nickg committed Aug 19, 2012
Showing with 37 additions and 0 deletions.
  1. +26 −0 src/sem.c
  2. +10 −0 test/sem/ports.vhd
  3. +1 −0 test/test_sem.c
View
26 src/sem.c
@@ -423,6 +423,16 @@ static bool type_set_uniq_composite(type_t *pt)
return (*pt != NULL);
}
+static bool type_set_any(type_t *pt)
+{
+ if ((top_type_set == NULL) || (top_type_set->n_members == 0))
+ return false;
+ else {
+ *pt = top_type_set->members[0];
+ return true;
+ }
+}
+
#if 0
static void type_set_dump(void)
{
@@ -3185,6 +3195,9 @@ static bool sem_check_map(tree_t t, tree_t unit,
}
ok = sem_check_constrained(p.value, tree_type(decl)) && ok;
+
+ if ((tree_kind(p.value) == T_OPEN) && (tree_port_mode(decl) != PORT_OUT))
+ sem_error(p.value, "OPEN can only be used with OUT ports");
}
for (unsigned i = 0; i < nformals; i++) {
@@ -3574,6 +3587,17 @@ static bool sem_check_for_generate(tree_t t)
return ok;
}
+static bool sem_check_open(tree_t t)
+{
+ type_t type;
+ if (type_set_any(&type)) {
+ tree_set_type(t, type);
+ return true;
+ }
+ else
+ sem_error(t, "OPEN cannot be used here");
+}
+
static void sem_intern_strings(void)
{
// Intern some commonly used strings
@@ -3679,6 +3703,8 @@ bool sem_check(tree_t t)
return sem_check_if_generate(t);
case T_FOR_GENERATE:
return sem_check_for_generate(t);
+ case T_OPEN:
+ return sem_check_open(t);
default:
sem_error(t, "cannot check tree kind %d", tree_kind(t));
}
View
10 test/sem/ports.vhd
@@ -77,5 +77,15 @@ begin
port map ( cake => 4 );
bad1: entity work.bad; -- No such entity
+
+ open1: entity work.foo -- OK
+ port map (
+ i => x,
+ o => open );
+
+ open2: entity work.foo -- Cannot use OPEN with input
+ port map (
+ i => open,
+ o => open );
end architecture;
View
1 test/test_sem.c
@@ -148,6 +148,7 @@ START_TEST(test_ports)
{ 74, "too many positional actuals" },
{ 77, "WORK.FOO has no formal CAKE" },
{ 79, "cannot find unit WORK.BAD" },
+ { 88, "OPEN can only be used with OUT ports" },
{ -1, NULL }
};
expect_errors(expect);

0 comments on commit 9cb42cb

Please sign in to comment.
Something went wrong with that request. Please try again.