summaryrefslogtreecommitdiff
path: root/src/bytecode_util.ml
diff options
context:
space:
mode:
authorAlasdair2018-08-13 19:55:23 +0100
committerAlasdair2018-08-13 19:55:23 +0100
commit82642087083f6c7c548e7c8b14233fde8198e9c7 (patch)
tree41ca0bf065970e1678af30e16247206cae370e82 /src/bytecode_util.ml
parent01fd68577abfa98a901b220a9928b397047e9fd4 (diff)
Sort ctype_defs in dependency order after specialisation
We now generate anonymous types in the correct order, but post specialisation more dependencies can occur between named types, so an additional sorting step is needed to ensure that these happen in the correct order. In theory we could end up with circular dependencies here that don't exist at the Sail source level, but this shouldn't occur often (or ever) in practice. I think this is fixable but it would require some code generator changes.
Diffstat (limited to 'src/bytecode_util.ml')
-rw-r--r--src/bytecode_util.ml9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/bytecode_util.ml b/src/bytecode_util.ml
index 188d71cc..c612660a 100644
--- a/src/bytecode_util.ml
+++ b/src/bytecode_util.ml
@@ -259,6 +259,15 @@ let rec ctyp_suprema = function
| CT_ref ctyp -> CT_ref (ctyp_suprema ctyp)
| CT_poly -> CT_poly
+let rec ctyp_ids = function
+ | CT_enum (id, _) -> IdSet.singleton id
+ | CT_struct (id, ctors) | CT_variant (id, ctors) ->
+ IdSet.add id (List.fold_left (fun ids (_, ctyp) -> IdSet.union (ctyp_ids ctyp) ids) IdSet.empty ctors)
+ | CT_tup ctyps -> List.fold_left (fun ids ctyp -> IdSet.union (ctyp_ids ctyp) ids) IdSet.empty ctyps
+ | CT_vector (_, ctyp) | CT_list ctyp | CT_ref ctyp -> ctyp_ids ctyp
+ | CT_int | CT_int64 | CT_bits _ | CT_bits64 _ | CT_unit
+ | CT_bool | CT_real | CT_bit | CT_string | CT_poly -> IdSet.empty
+
let rec unpoly = function
| F_poly f -> unpoly f
| F_call (call, fs) -> F_call (call, List.map unpoly fs)