Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add 'LENGTH, 'LEFT, etc. for signals with array subtype type

  • Loading branch information...
commit 6177e6a5d16f92229ad582ad983778d235032a23 1 parent 524b338
@nickg authored
Showing with 21 additions and 19 deletions.
  1. +19 −19 src/sem.c
  2. +2 −0  test/sem/array.vhd
View
38 src/sem.c
@@ -1261,7 +1261,24 @@ static void sem_add_attributes(tree_t decl)
type_t type = tree_type(decl);
type_kind_t kind = type_kind(type);
- if (kind == T_CARRAY) {
+ if (kind == T_UARRAY) {
+ const char *funs[] = { "LOW", "HIGH", "LEFT", "RIGHT", NULL };
+ const char *impl[] = { "uarray_low", "uarray_high", "uarray_left",
+ "uarray_right", NULL };
+ const char **f, **imp;
+ for (f = funs, imp = impl; *f != NULL; f++, imp++) {
+ ident_t id = ident_new(*f);
+ tree_add_attr_tree(decl, id,
+ sem_builtin_fn(id, type_index_constr(type, 0),
+ *imp, type, NULL));
+ }
+
+ ident_t asc_i = ident_new("ASCENDING");
+ tree_add_attr_tree(decl, asc_i,
+ sem_builtin_fn(asc_i, std_bool,
+ "uarray_asc", type, NULL));
+ }
+ else if (type_is_array(type)) {
range_t r = type_dim(type, 0);
tree_add_attr_tree(decl, ident_new("LEFT"), r.left);
@@ -1286,25 +1303,8 @@ static void sem_add_attributes(tree_t decl)
tree_add_attr_tree(decl, ident_new("LOW"), r.right);
}
}
- else if (kind == T_UARRAY) {
- const char *funs[] = { "LOW", "HIGH", "LEFT", "RIGHT", NULL };
- const char *impl[] = { "uarray_low", "uarray_high", "uarray_left",
- "uarray_right", NULL };
- const char **f, **imp;
- for (f = funs, imp = impl; *f != NULL; f++, imp++) {
- ident_t id = ident_new(*f);
- tree_add_attr_tree(decl, id,
- sem_builtin_fn(id, type_index_constr(type, 0),
- *imp, type, NULL));
- }
-
- ident_t asc_i = ident_new("ASCENDING");
- tree_add_attr_tree(decl, asc_i,
- sem_builtin_fn(asc_i, std_bool,
- "uarray_asc", type, NULL));
- }
- if (kind == T_UARRAY || kind == T_CARRAY) {
+ if (type_is_array(type)) {
ident_t length_i = ident_new("LENGTH");
tree_add_attr_tree(decl, length_i,
sem_builtin_fn(length_i,
View
2  test/sem/array.vhd
@@ -155,8 +155,10 @@ begin
subtype int4_t is int_array(1 to 4);
type foo_t is array (integer'left to 10) of integer;
variable v : int_array(foo_t'range);
+ variable u : foo_t;
begin
assert int4_t'length = 4;
+ assert foo_t'length = 50;
end process;
end architecture;
Please sign in to comment.
Something went wrong with that request. Please try again.