From 04cd83fb46bee1e7a7b37be95bee73449af9c8b8 Mon Sep 17 00:00:00 2001 From: Tristan Gingold Date: Fri, 24 Jul 2020 18:31:11 +0200 Subject: ortho: add unbounded records, rework array subtypes. --- src/ortho/gcc/ortho-lang-6.c | 53 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 49 insertions(+), 4 deletions(-) (limited to 'src/ortho/gcc/ortho-lang-6.c') diff --git a/src/ortho/gcc/ortho-lang-6.c b/src/ortho/gcc/ortho-lang-6.c index bd989d9a8..706b23574 100644 --- a/src/ortho/gcc/ortho-lang-6.c +++ b/src/ortho/gcc/ortho-lang-6.c @@ -1090,6 +1090,14 @@ struct GTY(()) o_element_list struct chain_constr_type chain; }; +struct GTY(()) o_element_sublist +{ + tree base; + tree field; + tree res; + struct chain_constr_type chain; +}; + void new_uncomplete_record_type (tree *res) { @@ -1147,10 +1155,41 @@ finish_record_type (struct o_element_list *elements, tree *res) } } +void +start_record_subtype (tree rtype, struct o_element_sublist *elements) +{ + elements->base = rtype; + elements->field = TYPE_FIELDS (rtype); + elements->res = make_node (RECORD_TYPE); + chain_init (&elements->chain); +} + +void +new_subrecord_field (struct o_element_sublist *list, + tree *el, + tree etype) +{ + tree res; + + res = build_decl (input_location, FIELD_DECL, DECL_NAME(list->field), etype); + DECL_CONTEXT (res) = list->res; + chain_append (&list->chain, res); + list->field = TREE_CHAIN(list->field); + *el = res; +} + +void +finish_record_subtype (struct o_element_sublist *elements, tree *res) +{ + TYPE_FIELDS (elements->res) = elements->chain.first; + layout_type (elements->res); + *res = elements->res; +} + void start_union_type (struct o_element_list *elements) { - elements->res = make_node (UNION_TYPE); + elements->res = make_node (UNION_TYPE); chain_init (&elements->chain); } @@ -1255,7 +1294,7 @@ new_array_type (tree el_type, tree index_type) } tree -new_constrained_array_type (tree atype, tree length) +new_array_subtype (tree atype, tree eltype, tree length) { tree range_type; tree index_type; @@ -1264,7 +1303,7 @@ new_constrained_array_type (tree atype, tree length) index_type = TYPE_DOMAIN (atype); range_type = ortho_build_array_range(index_type, length); - res = build_array_type (TREE_TYPE (atype), range_type); + res = build_array_type (eltype, range_type); /* Constrained arrays are *always* a subtype of its array type. Just copy alias set. */ @@ -1368,7 +1407,7 @@ start_array_aggr (struct o_array_aggr_list *list, tree atype, unsigned len) tree length; length = new_unsigned_literal (sizetype, len); - list->atype = new_constrained_array_type (atype, length); + list->atype = new_array_subtype (atype, TREE_TYPE (atype), length); vec_alloc(list->elts, len); } @@ -1483,6 +1522,12 @@ new_sizeof (tree atype, tree rtype) return fold (build1 (NOP_EXPR, rtype, size)); } +tree +new_record_sizeof (tree atype, tree rtype) +{ + return new_sizeof (atype, rtype); +} + tree new_alignof (tree atype, tree rtype) { -- cgit v1.2.3