diff --git a/dev_tools/pylibs/edgifc/spec_files/0.44.json b/dev_tools/pylibs/edgifc/spec_files/0.44.json index d64e3beac7..b15496aa5f 100644 --- a/dev_tools/pylibs/edgifc/spec_files/0.44.json +++ b/dev_tools/pylibs/edgifc/spec_files/0.44.json @@ -351,6 +351,18 @@ "0x4": "GenConstant" } }, + "EdgFloatType": { + "size": 4, + "values": { + "0x0": "Float16", + "0x1": "Fp16", + "0x2": "Float32x", + "0x3": "Float64x", + "0x4": "Float80", + "0x5": "Float128", + "0x6": "StdBfloat16" + } + }, "ExpansionMode": { "size": 1, "values": { @@ -1153,7 +1165,8 @@ "bitwidth": 5, "non_null": true, "values": { - "0x0": "EdgTypeSubstituted" + "0x0": "EdgTypeSubstituted", + "0x1": "EdgTypeFloat" } }, "Expr": { @@ -2362,6 +2375,12 @@ "initializer": "EdgTokenCacheOffset" } }, + "EdgTypeFloat": { + "padding": 0, + "fields": { + "kind": "EdgFloatTypeSort" + } + }, "EdgTypeSubstituted": { "padding": 0, "fields": { @@ -4636,6 +4655,7 @@ ".edg.token.complex.textual": "EdgTokenTextual", ".edg.trait.class-template-definition": "EdgTraitClassTemplateDefinition", ".edg.trait.function-definition": "EdgTraitFunctionDefinition", + ".edg.type.float": "EdgTypeFloat", ".edg.type.substitued": "EdgTypeSubstituted", ".msvc.trait.decl-attrs": "TraitMsvcDeclAttrs", ".msvc.trait.named-function-parameters": "TraitMsvcFuncParams", diff --git a/src/ifc_map.h b/src/ifc_map.h index 2830c42b86..18ed8a7d3d 100644 --- a/src/ifc_map.h +++ b/src/ifc_map.h @@ -4,7 +4,6 @@ Exceptions. See https://edgcpp.org/LICENSE.txt for license information. SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ - /* ifc_map.h -- Types for IFC-based modules. @@ -950,6 +949,21 @@ struct an_ifc_encoded_edg_extension_type_offset : Implicit_numeric_entry< }; /* an_ifc_encoded_edg_extension_type_offset */ +enum an_ifc_encoded_edg_float_type_sort_0_44 : uint32_t; +using an_ifc_encoded_edg_float_type_sort_storage = uint32_t; + + +/* +The universal representation for an IFC EncodedEdgFloatTypeSort. +*/ +struct an_ifc_encoded_edg_float_type_sort : Implicit_numeric_entry< + an_ifc_encoded_edg_float_type_sort_storage> { + using storage_type = an_ifc_encoded_edg_float_type_sort_storage; + using base_type = Implicit_numeric_entry; + using base_type::Implicit_numeric_entry; +}; /* an_ifc_encoded_edg_float_type_sort */ + + enum an_ifc_encoded_edg_heap_complex_token_offset_0_43 : uint32_t; using an_ifc_encoded_edg_heap_complex_token_offset_storage = uint32_t; @@ -3242,6 +3256,28 @@ enum an_ifc_edg_expr_sort : uint32_t { }; /* an_ifc_edg_expr_sort */ +enum an_ifc_edg_float_type_sort_0_44 : uint32_t { + ifc_0_44_efts_float16 = 0, + ifc_0_44_efts_fp16 = 1, + ifc_0_44_efts_float32x = 2, + ifc_0_44_efts_float64x = 3, + ifc_0_44_efts_float80 = 4, + ifc_0_44_efts_float128 = 5, + ifc_0_44_efts_std_bfloat16 = 6 +}; /* an_ifc_edg_float_type_sort_0_44 */ + + +enum an_ifc_edg_float_type_sort : uint32_t { + ifc_efts_float128, + ifc_efts_float16, + ifc_efts_float32x, + ifc_efts_float64x, + ifc_efts_float80, + ifc_efts_fp16, + ifc_efts_std_bfloat16 +}; /* an_ifc_edg_float_type_sort */ + + enum an_ifc_edg_template_argument_sort_0_43 : uint32_t { ifc_0_43_etas_edg_template_argument_type = 0, ifc_0_43_etas_edg_template_argument_non_type = 1, @@ -3261,7 +3297,14 @@ enum an_ifc_edg_type_sort_0_43 : uint32_t { }; /* an_ifc_edg_type_sort_0_43 */ +enum an_ifc_edg_type_sort_0_44 : uint32_t { + ifc_0_44_ets_edg_type_substituted = 0, + ifc_0_44_ets_edg_type_float = 1 +}; /* an_ifc_edg_type_sort_0_44 */ + + enum an_ifc_edg_type_sort : uint32_t { + ifc_ets_edg_type_float, ifc_ets_edg_type_substituted }; /* an_ifc_edg_type_sort */ @@ -6011,6 +6054,7 @@ two instances are equivalent, return FALSE; otherwise return TRUE. enum an_ifc_edg_type_index_0_43 : uint32_t {}; +enum an_ifc_edg_type_index_0_44 : uint32_t {}; /* @@ -10957,6 +11001,14 @@ struct an_ifc_edg_extension_expr : |-------|--------------|---------|------| | value | EdgTypeIndex | 0.43 | 4 | |-------|--------------|---------|------| + + |---------------------------------------| + | EdgExtensionType - 0.44 (4 bytes) | + |-------|--------------|---------|------| + | Name | Type | Version | Size | + |-------|--------------|---------|------| + | value | EdgTypeIndex | 0.44 | 4 | + |-------|--------------|---------|------| */ enum an_ifc_edg_extension_type_part : uint8_t {}; using an_ifc_edg_extension_type_storage = an_ifc_edg_extension_type_part[4]; @@ -11437,6 +11489,36 @@ struct an_ifc_edg_trait_function_definition : }; /* an_ifc_edg_trait_function_definition */ +/* + |------------------------------------------| + | EdgTypeFloat - 0.44 (4 bytes) | + |------|------------------|---------|------| + | Name | Type | Version | Size | + |------|------------------|---------|------| + | kind | EdgFloatTypeSort | 0.44 | 4 | + |------|------------------|---------|------| +*/ +enum an_ifc_edg_type_float_part : uint8_t {}; +using an_ifc_edg_type_float_storage = an_ifc_edg_type_float_part[4]; +#if USE_MMAP_FOR_MODULES +using an_ifc_edg_type_float_bytes = const an_ifc_edg_type_float_storage*; +#else /* !USE_MMAP_FOR_MODULES */ +using an_ifc_edg_type_float_bytes = an_ifc_edg_type_float_storage; +#endif /* USE_MMAP_FOR_MODULES */ +/* +The universal representation of an IFC EdgTypeFloat node. + +The representation is declared as a derived struct of Byte_buffer_entry rather +than simply an alias of the instantiation to improve the debugger experience. +*/ +struct an_ifc_edg_type_float : + Byte_buffer_entry { + using storage_type = an_ifc_edg_type_float_storage; + using base_type = Byte_buffer_entry; + using base_type::Byte_buffer_entry; +}; /* an_ifc_edg_type_float */ + + /* |----------------------------------------------------------------| | EdgTypeSubstituted - 0.43 (12 bytes) | @@ -23163,6 +23245,7 @@ enum an_ifc_partition_kind : uint32_t { ifc_pk_edg_token_complex_textual, ifc_pk_edg_trait_class_template_definition, ifc_pk_edg_trait_function_definition, + ifc_pk_edg_type_float, ifc_pk_edg_type_substitued, ifc_pk_msvc_trait_decl_attrs, ifc_pk_msvc_trait_named_function_parameters, @@ -23485,7 +23568,7 @@ enum an_ifc_partition_kind : uint32_t { }; /* an_ifc_partition_kind */ -#define IFC_PARTITION_COUNT 337 +#define IFC_PARTITION_COUNT 338 /* A method for mapping partition names to an_ifc_partition_kind values. Used @@ -23522,6 +23605,7 @@ EXTERN an_ifc_partition_map ifc_partition_map[IFC_PARTITION_COUNT] { ".edg.trait.class-template-definition", ifc_pk_edg_trait_class_template_definition }, { ".edg.trait.function-definition", ifc_pk_edg_trait_function_definition }, + { ".edg.type.float", ifc_pk_edg_type_float }, { ".edg.type.substitued", ifc_pk_edg_type_substitued }, { ".msvc.trait.decl-attrs", ifc_pk_msvc_trait_decl_attrs }, { ".msvc.trait.named-function-parameters", @@ -23865,3 +23949,9 @@ END_DISABLE_GCC_WARNING_MAYBE_UNITIALIZED /* Conditionally close the "edg" namespace. */ END_EDG_NAMESPACE +/* +Part of the EDG Compiler Project, under the Apache License v2.0 with LLVM +Exceptions. +See https://edgcpp.org/LICENSE.txt for license information. +SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +*/ diff --git a/src/ifc_map_functions.c b/src/ifc_map_functions.c index 26f39de8b0..aa88c29135 100644 --- a/src/ifc_map_functions.c +++ b/src/ifc_map_functions.c @@ -4,7 +4,6 @@ Exceptions. See https://edgcpp.org/LICENSE.txt for license information. SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ - /* ifc_map_functions.c -- Function implementations for interacting with types for @@ -5777,6 +5776,129 @@ universal representation. } /* to_universal_sort */ +/* +Functions for interacting with IFC EdgFloatTypeSort sorts. +*/ + + +a_const_char* str_for(an_ifc_edg_float_type_sort universal) +/* +Given the universal representation of EdgFloatTypeSort, return the textual name +in the form of a c-string. +*/ +{ + a_const_char *result; + + switch (universal) { + case ifc_efts_float128: + result = "EdgFloatTypeSort::Float128"; + break; + case ifc_efts_float16: + result = "EdgFloatTypeSort::Float16"; + break; + case ifc_efts_float32x: + result = "EdgFloatTypeSort::Float32x"; + break; + case ifc_efts_float64x: + result = "EdgFloatTypeSort::Float64x"; + break; + case ifc_efts_float80: + result = "EdgFloatTypeSort::Float80"; + break; + case ifc_efts_fp16: + result = "EdgFloatTypeSort::Fp16"; + break; + case ifc_efts_std_bfloat16: + result = "EdgFloatTypeSort::StdBfloat16"; + break; + default: + unexpected_condition_str("Invalid value for a EdgFloatTypeSort."); + break; + } /* switch */ + return result; +} /* str_for */ + + +an_ifc_encoded_edg_float_type_sort to_encoded( + an_ifc_module_file *file, + an_ifc_edg_float_type_sort universal) +/* +Given the universal representation of EdgFloatTypeSort and the destination +module, return a reencoded sort value. +*/ +{ + using ue_ty = an_ifc_encoded_edg_float_type_sort_storage; + an_ifc_encoded_edg_float_type_sort_storage result; + + switch (universal) { + case ifc_efts_float16: + result = (ue_ty)ifc_0_44_efts_float16; + break; + case ifc_efts_fp16: + result = (ue_ty)ifc_0_44_efts_fp16; + break; + case ifc_efts_float32x: + result = (ue_ty)ifc_0_44_efts_float32x; + break; + case ifc_efts_float64x: + result = (ue_ty)ifc_0_44_efts_float64x; + break; + case ifc_efts_float80: + result = (ue_ty)ifc_0_44_efts_float80; + break; + case ifc_efts_float128: + result = (ue_ty)ifc_0_44_efts_float128; + break; + case ifc_efts_std_bfloat16: + result = (ue_ty)ifc_0_44_efts_std_bfloat16; + break; + default: + unexpected_condition_str("Invalid value for a EdgFloatTypeSort."); + break; + } /* switch */ + return an_ifc_encoded_edg_float_type_sort{file, result}; +} /* to_encoded */ + + +an_ifc_edg_float_type_sort to_universal_sort( + an_ifc_edg_float_type_sort_0_44 versioned) +/* +Given the versioned representation of EdgFloatTypeSort, return the +corresponding universal representation. +*/ +{ + an_ifc_edg_float_type_sort result; + + switch (versioned) { + case ifc_0_44_efts_float16: + result = ifc_efts_float16; + break; + case ifc_0_44_efts_fp16: + result = ifc_efts_fp16; + break; + case ifc_0_44_efts_float32x: + result = ifc_efts_float32x; + break; + case ifc_0_44_efts_float64x: + result = ifc_efts_float64x; + break; + case ifc_0_44_efts_float80: + result = ifc_efts_float80; + break; + case ifc_0_44_efts_float128: + result = ifc_efts_float128; + break; + case ifc_0_44_efts_std_bfloat16: + result = ifc_efts_std_bfloat16; + break; + default: + unexpected_condition_str("Invalid value for a EdgFloatTypeSort."); + break; + } /* switch */ + return result; +} /* to_universal_sort */ + + /* Functions for interacting with IFC EdgTemplateArgumentSort sorts. */ @@ -5881,6 +6003,9 @@ the form of a c-string. a_const_char *result; switch (universal) { + case ifc_ets_edg_type_float: + result = "EdgTypeSort::EdgTypeFloat"; + break; case ifc_ets_edg_type_substituted: result = "EdgTypeSort::EdgTypeSubstituted"; break; @@ -5902,19 +6027,53 @@ return a reencoded sort value. using ue_ty = an_ifc_encoded_edg_type_sort_storage; an_ifc_encoded_edg_type_sort_storage result; - switch (universal) { - case ifc_ets_edg_type_substituted: - result = (ue_ty)ifc_0_43_ets_edg_type_substituted; + if (is_at_least(file, 0, 44)) { + switch (universal) { + case ifc_ets_edg_type_substituted: + result = (ue_ty)ifc_0_44_ets_edg_type_substituted; + break; + case ifc_ets_edg_type_float: + result = (ue_ty)ifc_0_44_ets_edg_type_float; + break; + default: + unexpected_condition_str("Invalid value for a EdgTypeSort."); + break; + } /* switch */ + } else { + switch (universal) { + case ifc_ets_edg_type_substituted: + result = (ue_ty)ifc_0_43_ets_edg_type_substituted; + break; + default: + unexpected_condition_str("Invalid value for a EdgTypeSort."); + break; + } /* switch */ + } /* if */ + return an_ifc_encoded_edg_type_sort{file, result}; +} /* to_encoded */ + + +an_ifc_edg_type_sort to_universal_sort(an_ifc_edg_type_sort_0_43 versioned) +/* +Given the versioned representation of EdgTypeSort, return the corresponding +universal representation. +*/ +{ + an_ifc_edg_type_sort result; + + switch (versioned) { + case ifc_0_43_ets_edg_type_substituted: + result = ifc_ets_edg_type_substituted; break; default: unexpected_condition_str("Invalid value for a EdgTypeSort."); break; } /* switch */ - return an_ifc_encoded_edg_type_sort{file, result}; -} /* to_encoded */ + return result; +} /* to_universal_sort */ -an_ifc_edg_type_sort to_universal_sort(an_ifc_edg_type_sort_0_43 versioned) +an_ifc_edg_type_sort to_universal_sort(an_ifc_edg_type_sort_0_44 versioned) /* Given the versioned representation of EdgTypeSort, return the corresponding universal representation. @@ -5923,9 +6082,12 @@ universal representation. an_ifc_edg_type_sort result; switch (versioned) { - case ifc_0_43_ets_edg_type_substituted: + case ifc_0_44_ets_edg_type_substituted: result = ifc_ets_edg_type_substituted; break; + case ifc_0_44_ets_edg_type_float: + result = ifc_ets_edg_type_float; + break; default: unexpected_condition_str("Invalid value for a EdgTypeSort."); break; @@ -18934,6 +19096,40 @@ return the corresponding universal representation. } /* to_universal_index */ +an_ifc_edg_type_sort_0_44 edg_type_sort(an_ifc_edg_type_index_0_44 versioned) +/* +Given the versioned representation of EdgTypeIndex, return the extracted +versioned representation of EdgTypeSort. +*/ +{ + return (an_ifc_edg_type_sort_0_44)(0x1f & (uint32_t)versioned); + +} /* edg_type_sort */ + + +uint32_t edg_type_value(an_ifc_edg_type_index_0_44 versioned) +/* +Given the versioned representation of EdgTypeIndex, return the extracted value. +*/ +{ + return versioned >> 5; +} /* edg_type_value */ + + +an_ifc_edg_type_index to_universal_index(an_ifc_module_file *file, + an_ifc_edg_type_index_0_44 versioned) +/* +Given the versioned representation of EdgTypeIndex and the associated module, +return the corresponding universal representation. +*/ +{ + an_ifc_edg_type_sort sort = to_universal_sort(edg_type_sort(versioned)); + uint32_t index = edg_type_value(versioned); + + return an_ifc_edg_type_index{file, sort, index}; +} /* to_universal_index */ + + an_ifc_encoded_edg_type_index to_encoded(an_ifc_module_file *file, an_ifc_edg_type_index universal) /* @@ -27312,6 +27508,72 @@ Return the corresponding partition kind for EdgTraitFunctionDefinition. } /* get_ifc_partition_kind */ +template<> +size_t get_ifc_buffer_size( + an_ifc_module_file *file) +/* +Given the associated module file, return the number of bytes required for an +IFC EdgTypeFloat node. +*/ +{ + size_t result; + + result = 4; + return result; +} /* get_ifc_buffer_size */ + + +template<> +an_ifc_edg_type_float_storage* get( + an_ifc_module_file *file, + an_ifc_edg_type_float_storage *storage, + a_boolean fill_storage) +/* +Retrieve an instance of EdgTypeFloat from the IFC module file. + +If memory mapping is used and both the host and the target have the same +endianness, then the file layout and the alignment/padding of the host must +have exactly the same characteristics. In this case, simply return a pointer +to a suitably-cast byte_buffer and increment it as appropriate (the storage +argument is unused in this scenario). + +Otherwise, the storage passed in to the function is used to store copies of +each field of the structure and each field is individually copied (and +byte-swapped if necessary). + +If fill_storage is TRUE, always copy the data into the passed storage (i.e., +the storage specified by the storage argument). +*/ +{ +#if USE_MMAP_FOR_MODULES + using storage_type = an_ifc_edg_type_float_storage; + if (has_matching_endianness(file)) { + if (fill_storage) { + memcpy(*storage, get_byte_buffer(file), /*size=*/4); + } else { + storage = (storage_type*)(get_byte_buffer(file)); + } /* if */ + } else +#endif /* USE_MMAP_FOR_MODULES */ + /* Do not put code here. */ + { + /* kind */ + get_bytes(file, (*storage) + 0, /*num_bytes=*/4, /*from_header=*/FALSE); + } /* if */ + return storage; +} /* get */ + + +template<> +an_ifc_partition_kind get_ifc_partition_kind() +/* +Return the corresponding partition kind for EdgTypeFloat. +*/ +{ + return ifc_pk_edg_type_float; +} /* get_ifc_partition_kind */ + + template<> size_t get_ifc_buffer_size( an_ifc_module_file *file) @@ -47763,6 +48025,9 @@ corresponding expected partition element size. case ifc_pk_edg_trait_function_definition: result = 8; break; + case ifc_pk_edg_type_float: + result = 4; + break; case ifc_pk_edg_type_substitued: result = 12; break; @@ -49290,6 +49555,7 @@ representation of EdgTypeSort; otherwise, return FALSE. a_boolean result; switch (kind) { + case ifc_pk_edg_type_float: case ifc_pk_edg_type_substitued: result = TRUE; break; @@ -49310,6 +49576,9 @@ EdgTypeSort. If no corresponding sort kind exists for EdgTypeSort, abort. an_ifc_edg_type_sort result; switch (kind) { + case ifc_pk_edg_type_float: + result = ifc_ets_edg_type_float; + break; case ifc_pk_edg_type_substitued: result = ifc_ets_edg_type_substituted; break; @@ -51045,6 +51314,7 @@ corresponding partition kind; otherwise, return FALSE. a_boolean result; switch (sort) { + case ifc_ets_edg_type_float: case ifc_ets_edg_type_substituted: result = TRUE; break; @@ -51065,6 +51335,9 @@ partition kind. If no corresponding partition kind exists, abort. an_ifc_partition_kind result; switch (sort) { + case ifc_ets_edg_type_float: + result = ifc_pk_edg_type_float; + break; case ifc_ets_edg_type_substituted: result = ifc_pk_edg_type_substitued; break; @@ -52920,6 +53193,13 @@ node's representation is valid; otherwise, return FALSE. a_boolean result = FALSE; switch (idx.sort) { + case ifc_ets_edg_type_float: + { Opt opt_universal; + + construct_node(&opt_universal, idx); + result = opt_universal.has_value(); + } + break; case ifc_ets_edg_type_substituted: { Opt opt_universal; @@ -58181,3 +58461,9 @@ END_EDG_NAMESPACE #endif /* !STANDALONE_UTILITY_PROGRAM */ +/* +Part of the EDG Compiler Project, under the Apache License v2.0 with LLVM +Exceptions. +See https://edgcpp.org/LICENSE.txt for license information. +SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +*/ diff --git a/src/ifc_map_functions.h b/src/ifc_map_functions.h index 6a3c38b3a7..06f8c731d4 100644 --- a/src/ifc_map_functions.h +++ b/src/ifc_map_functions.h @@ -4,7 +4,6 @@ Exceptions. See https://edgcpp.org/LICENSE.txt for license information. SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ - /* ifc_map_functions.h -- Function declarations for interacting with types for @@ -364,6 +363,25 @@ extern a_boolean validate_sort(an_ifc_module_file *file, extern an_ifc_edg_expr_sort to_universal_sort( an_ifc_edg_expr_sort_0_43 versioned); +/* +Functions for interacting with IFC EdgFloatTypeSort sorts. +*/ + +extern a_const_char* str_for(an_ifc_edg_float_type_sort universal); + +extern an_ifc_encoded_edg_float_type_sort to_encoded( + an_ifc_module_file *file, + an_ifc_edg_float_type_sort universal); + +extern a_boolean is_known_sort(an_ifc_edg_float_type_sort_0_44 versioned); + +extern a_boolean validate_sort(an_ifc_module_file *file, + an_ifc_edg_float_type_sort_0_44 versioned, + const an_ifc_validation_trace *parent); + +extern an_ifc_edg_float_type_sort to_universal_sort( + an_ifc_edg_float_type_sort_0_44 versioned); + /* Functions for interacting with IFC EdgTemplateArgumentSort sorts. */ @@ -403,6 +421,15 @@ extern a_boolean validate_sort(an_ifc_module_file *file, extern an_ifc_edg_type_sort to_universal_sort( an_ifc_edg_type_sort_0_43 versioned); +extern a_boolean is_known_sort(an_ifc_edg_type_sort_0_44 versioned); + +extern a_boolean validate_sort(an_ifc_module_file *file, + an_ifc_edg_type_sort_0_44 versioned, + const an_ifc_validation_trace *parent); + +extern an_ifc_edg_type_sort to_universal_sort( + an_ifc_edg_type_sort_0_44 versioned); + /* Functions for interacting with IFC ExpansionModeSort sorts. */ @@ -1383,6 +1410,19 @@ extern an_ifc_edg_type_index to_universal_index( an_ifc_module_file *file, an_ifc_edg_type_index_0_43 versioned); +extern an_ifc_edg_type_sort_0_44 edg_type_sort( + an_ifc_edg_type_index_0_44 versioned); + +extern uint32_t edg_type_value(an_ifc_edg_type_index_0_44 versioned); + +extern a_boolean validate_index(an_ifc_module_file *file, + an_ifc_edg_type_index_0_44 versioned, + const an_ifc_validation_trace *parent); + +extern an_ifc_edg_type_index to_universal_index( + an_ifc_module_file *file, + an_ifc_edg_type_index_0_44 versioned); + extern an_ifc_encoded_edg_type_index to_encoded( an_ifc_module_file *file, an_ifc_edg_type_index universal); @@ -4646,6 +4686,16 @@ struct an_ifc_kind_metadata { }; /* an_ifc_kind_metadata */ +/* +The IFC kind field has multiple return types. This type is a metadata type +that allows resolution of the return type for EdgTypeFloat nodes. +*/ +template<> +struct an_ifc_kind_metadata { + using return_type = an_ifc_edg_float_type_sort; +}; /* an_ifc_kind_metadata */ + + /* The IFC label field has multiple return types. This type is a metadata type that allows resolution of those return types based on the respective node type. @@ -20538,6 +20588,46 @@ get_ifc_partition_kind(); +template<> +size_t get_ifc_buffer_size( + an_ifc_module_file *file); + +/* +Functions for interacting with IFC EdgTypeFloat nodes. +*/ + +template<> +a_boolean has_ifc_kind(const an_ifc_edg_type_float &universal); + +template<> +an_ifc_edg_float_type_sort get_ifc_kind( + const an_ifc_edg_type_float &universal); + +template<> +void set_ifc_kind(an_ifc_edg_type_float *universal, + const an_ifc_edg_float_type_sort &value); + +template<> +a_boolean validate(const an_ifc_edg_type_float &universal, + const an_ifc_validation_trace *parent); + +#if DEBUG +extern void db_node(const an_ifc_edg_type_float &universal, unsigned indent); + +extern void db_node(const an_ifc_edg_type_float &universal); +#endif /* DEBUG */ + +template<> +an_ifc_edg_type_float_storage* get( + an_ifc_module_file *file, + an_ifc_edg_type_float_storage *storage, + a_boolean fill_storage); + +template<> +an_ifc_partition_kind get_ifc_partition_kind(); + + + template<> size_t get_ifc_buffer_size( an_ifc_module_file *file); @@ -38567,3 +38657,9 @@ END_DISABLE_GCC_WARNING_MAYBE_UNITIALIZED /* Conditionally close the "edg" namespace. */ END_EDG_NAMESPACE +/* +Part of the EDG Compiler Project, under the Apache License v2.0 with LLVM +Exceptions. +See https://edgcpp.org/LICENSE.txt for license information. +SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +*/ diff --git a/src/ifc_map_functions_acc.c b/src/ifc_map_functions_acc.c index b1572b1b7a..83f97b74e1 100644 --- a/src/ifc_map_functions_acc.c +++ b/src/ifc_map_functions_acc.c @@ -4,7 +4,6 @@ Exceptions. See https://edgcpp.org/LICENSE.txt for license information. SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ - /* ifc_map_functions_acc.c -- Function implementations for IFC-based module @@ -17524,16 +17523,29 @@ representation of the field "value". /* Ensure the value field exists in the current module version. */ check_assertion(has_ifc_value(universal)); - an_ifc_edg_type_index_0_43 stage_0; - an_ifc_edg_type_index stage_1; + if (is_at_least(universal.get_file(), 0, 44)) { + an_ifc_edg_type_index_0_44 stage_0; + an_ifc_edg_type_index stage_1; - /* Copy the field (EdgExtensionType::value - EdgTypeIndex) into - version-specific storage. */ - static_assert(sizeof(stage_0) == 4, - "stage_0 is not properly sized storage!"); - copy_from_node_field(&stage_0, universal.get_storage(), /*offset=*/0); - stage_1 = to_universal_index(universal.get_file(), stage_0); - result = stage_1; + /* Copy the field (EdgExtensionType::value - EdgTypeIndex) into + version-specific storage. */ + static_assert(sizeof(stage_0) == 4, + "stage_0 is not properly sized storage!"); + copy_from_node_field(&stage_0, universal.get_storage(), /*offset=*/0); + stage_1 = to_universal_index(universal.get_file(), stage_0); + result = stage_1; + } else { + an_ifc_edg_type_index_0_43 stage_0; + an_ifc_edg_type_index stage_1; + + /* Copy the field (EdgExtensionType::value - EdgTypeIndex) into + version-specific storage. */ + static_assert(sizeof(stage_0) == 4, + "stage_0 is not properly sized storage!"); + copy_from_node_field(&stage_0, universal.get_storage(), /*offset=*/0); + stage_1 = to_universal_index(universal.get_file(), stage_0); + result = stage_1; + } /* if */ return result; } /* get_ifc_value */ @@ -18595,6 +18607,53 @@ universal representation of the field "initializer". } /* get_ifc_initializer */ +/* +Functions for reading data from IFC EdgTypeFloat nodes. +*/ + + +template<> +a_boolean has_ifc_kind(const an_ifc_edg_type_float &universal) +/* +Return TRUE if the given universal representation has the field "kind"; +otherwise, return FALSE. +*/ +{ + an_ifc_module_file *file = universal.get_file(); + a_boolean result = FALSE; + + if (is_at_least(file, 0, 44)) { + result = TRUE; + } /* if */ + return result; +} /* has_ifc_kind */ + + +template<> +an_ifc_edg_float_type_sort get_ifc_kind(const an_ifc_edg_type_float &universal) +/* +Given the universal representation of EdgTypeFloat, return the universal +representation of the field "kind". +*/ +{ + an_ifc_edg_float_type_sort result; + + /* Ensure the kind field exists in the current module version. */ + check_assertion(has_ifc_kind(universal)); + an_ifc_edg_float_type_sort_0_44 stage_0; + an_ifc_edg_float_type_sort stage_1; + + /* Copy the field (EdgTypeFloat::kind - EdgFloatTypeSort) into + version-specific storage. */ + static_assert(sizeof(stage_0) == 4, + "stage_0 is not properly sized storage!"); + copy_from_node_field(&stage_0, universal.get_storage(), /*offset=*/0); + stage_1 = to_universal_sort(stage_0); + result = stage_1; + return result; +} /* get_ifc_kind */ + + /* Functions for reading data from IFC EdgTypeSubstituted nodes. */ @@ -62788,3 +62847,9 @@ END_EDG_NAMESPACE #endif /* !STANDALONE_UTILITY_PROGRAM */ +/* +Part of the EDG Compiler Project, under the Apache License v2.0 with LLVM +Exceptions. +See https://edgcpp.org/LICENSE.txt for license information. +SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +*/ diff --git a/src/ifc_map_functions_dbg.c b/src/ifc_map_functions_dbg.c index b262ee283c..f6aeb3c49e 100644 --- a/src/ifc_map_functions_dbg.c +++ b/src/ifc_map_functions_dbg.c @@ -4,7 +4,6 @@ Exceptions. See https://edgcpp.org/LICENSE.txt for license information. SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ - /* ifc_map_functions_dbg.c -- Function implementations for IFC-based module @@ -6660,6 +6659,34 @@ diagnostic textual representation. } /* db_node */ +void db_node(const an_ifc_edg_type_float &universal, unsigned indent) +/* +Given the universal representation of EdgTypeFloat, print a diagnostic textual +representation with the given indent. +*/ +{ + if (has_ifc_kind(universal)) { + an_ifc_edg_float_type_sort field = get_ifc_kind(universal); + + db_print_indent(indent); + fprintf(f_debug, "kind: %s\n", str_for(field)); + } /* if */ +} /* db_node */ + + +void db_node(const an_ifc_edg_type_float &universal) +/* +Given the universal representation of EdgTypeFloat, print a diagnostic textual +representation. +*/ +{ + fprintf(f_debug, "================================= "); + fprintf(f_debug, "EdgTypeFloat "); + fprintf(f_debug, "=================================\n"); + db_node(universal, 0); +} /* db_node */ + + void db_node(const an_ifc_edg_type_substituted &universal, unsigned indent) /* Given the universal representation of EdgTypeSubstituted, print a diagnostic @@ -23200,6 +23227,13 @@ associated node. { if (validate(idx)) { switch (idx.sort) { + case ifc_ets_edg_type_float: + { an_ifc_edg_type_float universal; + + construct_node_prechecked(&universal, idx); + db_node(universal); + } + break; case ifc_ets_edg_type_substituted: { an_ifc_edg_type_substituted universal; @@ -25052,3 +25086,9 @@ END_EDG_NAMESPACE #endif /* !STANDALONE_UTILITY_PROGRAM */ +/* +Part of the EDG Compiler Project, under the Apache License v2.0 with LLVM +Exceptions. +See https://edgcpp.org/LICENSE.txt for license information. +SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +*/ diff --git a/src/ifc_map_functions_mut.c b/src/ifc_map_functions_mut.c index ec3f33e758..4c1708464c 100644 --- a/src/ifc_map_functions_mut.c +++ b/src/ifc_map_functions_mut.c @@ -4,7 +4,6 @@ Exceptions. See https://edgcpp.org/LICENSE.txt for license information. SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ - /* ifc_map_functions_mut.c -- Function implementations for IFC-based module @@ -7986,16 +7985,29 @@ field "value" to the given EdgTypeIndex value. { /* Ensure the value field exists in the current module version. */ check_assertion(has_ifc_value(*universal)); - an_ifc_encoded_edg_type_index stage_0; - an_ifc_edg_type_index_0_43 stage_1; + if (is_at_least(universal->get_file(), 0, 44)) { + an_ifc_encoded_edg_type_index stage_0; + an_ifc_edg_type_index_0_44 stage_1; - stage_0 = to_encoded(universal->get_file(), value); - stage_1 = (an_ifc_edg_type_index_0_43)stage_0.value; - /* Copy from version-specific storage into the field (EdgExtensionType::value - - EdgTypeIndex). */ - static_assert(sizeof(stage_1) == 4, - "stage_1 is not properly sized storage!"); - copy_to_node_field(&stage_1, universal->get_storage(), /*offset=*/0); + stage_0 = to_encoded(universal->get_file(), value); + stage_1 = (an_ifc_edg_type_index_0_44)stage_0.value; + /* Copy from version-specific storage into the field + (EdgExtensionType::value - EdgTypeIndex). */ + static_assert(sizeof(stage_1) == 4, + "stage_1 is not properly sized storage!"); + copy_to_node_field(&stage_1, universal->get_storage(), /*offset=*/0); + } else { + an_ifc_encoded_edg_type_index stage_0; + an_ifc_edg_type_index_0_43 stage_1; + + stage_0 = to_encoded(universal->get_file(), value); + stage_1 = (an_ifc_edg_type_index_0_43)stage_0.value; + /* Copy from version-specific storage into the field + (EdgExtensionType::value - EdgTypeIndex). */ + static_assert(sizeof(stage_1) == 4, + "stage_1 is not properly sized storage!"); + copy_to_node_field(&stage_1, universal->get_storage(), /*offset=*/0); + } /* if */ } /* set_ifc_value */ @@ -8563,6 +8575,34 @@ value of the field "initializer" to the given EdgTokenCacheOffset value. } /* set_ifc_initializer */ +/* +Functions for writing data to IFC EdgTypeFloat nodes. +*/ + + +template<> +void set_ifc_kind(an_ifc_edg_type_float *universal, + const an_ifc_edg_float_type_sort &value) +/* +Given the universal representation of EdgTypeFloat update the value of the +field "kind" to the given EdgFloatTypeSort value. +*/ +{ + /* Ensure the kind field exists in the current module version. */ + check_assertion(has_ifc_kind(*universal)); + an_ifc_encoded_edg_float_type_sort stage_0; + an_ifc_edg_float_type_sort_0_44 stage_1; + + stage_0 = to_encoded(universal->get_file(), value); + stage_1 = (an_ifc_edg_float_type_sort_0_44)stage_0.value; + /* Copy from version-specific storage into the field (EdgTypeFloat::kind - + EdgFloatTypeSort). */ + static_assert(sizeof(stage_1) == 4, + "stage_1 is not properly sized storage!"); + copy_to_node_field(&stage_1, universal->get_storage(), /*offset=*/0); +} /* set_ifc_kind */ + + /* Functions for writing data to IFC EdgTypeSubstituted nodes. */ @@ -31616,3 +31656,9 @@ END_EDG_NAMESPACE #endif /* !STANDALONE_UTILITY_PROGRAM */ +/* +Part of the EDG Compiler Project, under the Apache License v2.0 with LLVM +Exceptions. +See https://edgcpp.org/LICENSE.txt for license information. +SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +*/ diff --git a/src/ifc_map_functions_val.c b/src/ifc_map_functions_val.c index 62b07c3a1f..d94e071831 100644 --- a/src/ifc_map_functions_val.c +++ b/src/ifc_map_functions_val.c @@ -4,7 +4,6 @@ Exceptions. See https://edgcpp.org/LICENSE.txt for license information. SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ - /* ifc_map_functions_val.c -- Function implementations for IFC-based module @@ -1329,6 +1328,49 @@ represents a valid sort value; otherwise, return FALSE. } /* validate_sort */ +a_boolean is_known_sort(an_ifc_edg_float_type_sort_0_44 versioned) +/* +Given the versioned representation of EdgFloatTypeSort, return TRUE if the +value represents a valid sort value; otherwise, return FALSE. +*/ +{ + a_boolean result = FALSE; + + switch (versioned) { + case ifc_0_44_efts_float16: + case ifc_0_44_efts_fp16: + case ifc_0_44_efts_float32x: + case ifc_0_44_efts_float64x: + case ifc_0_44_efts_float80: + case ifc_0_44_efts_float128: + case ifc_0_44_efts_std_bfloat16: + result = TRUE; + break; + default: + break; + } /* switch */ + return result; +} /* is_known_sort */ + + +a_boolean validate_sort(an_ifc_module_file *file, + an_ifc_edg_float_type_sort_0_44 versioned, + const an_ifc_validation_trace *parent) +/* +Given the versioned representation of EdgFloatTypeSort, return TRUE if the +value represents a valid sort value; otherwise, return FALSE. +*/ +{ + a_boolean result = TRUE; + + if (!is_known_sort(versioned)) { + invalid_sort(file, parent); + result = FALSE; + } /* if */ + return result; +} /* validate_sort */ + + a_boolean is_known_sort(an_ifc_edg_template_argument_sort_0_43 versioned) /* Given the versioned representation of EdgTemplateArgumentSort, return TRUE if @@ -1405,6 +1447,44 @@ represents a valid sort value; otherwise, return FALSE. } /* validate_sort */ +a_boolean is_known_sort(an_ifc_edg_type_sort_0_44 versioned) +/* +Given the versioned representation of EdgTypeSort, return TRUE if the value +represents a valid sort value; otherwise, return FALSE. +*/ +{ + a_boolean result = FALSE; + + switch (versioned) { + case ifc_0_44_ets_edg_type_substituted: + case ifc_0_44_ets_edg_type_float: + result = TRUE; + break; + default: + break; + } /* switch */ + return result; +} /* is_known_sort */ + + +a_boolean validate_sort(an_ifc_module_file *file, + an_ifc_edg_type_sort_0_44 versioned, + const an_ifc_validation_trace *parent) +/* +Given the versioned representation of EdgTypeSort, return TRUE if the value +represents a valid sort value; otherwise, return FALSE. +*/ +{ + a_boolean result = TRUE; + + if (!is_known_sort(versioned)) { + invalid_sort(file, parent); + result = FALSE; + } /* if */ + return result; +} /* validate_sort */ + + a_boolean is_known_sort(an_ifc_expansion_mode_sort_0_33 versioned) /* Given the versioned representation of ExpansionModeSort, return TRUE if the @@ -4730,6 +4810,45 @@ return FALSE. } /* validate_index */ +a_boolean validate_index(an_ifc_module_file *file, + an_ifc_edg_type_index_0_44 versioned, + const an_ifc_validation_trace *parent) +/* +Given the versioned representation of EdgTypeIndex and the associated module +file, return TRUE if the value represents a valid node position; otherwise, +return FALSE. +*/ +{ + a_boolean result = TRUE; + an_ifc_edg_type_sort_0_44 sort = edg_type_sort(versioned); + + if (!is_known_sort(sort)) { + invalid_partition(file, parent); + result = FALSE; + } else { + an_ifc_edg_type_sort univ_sort = to_universal_sort(sort); + + if (has_partition_kind(univ_sort)) { + an_ifc_partition_kind kind = to_partition_kind(univ_sort); + uint32_t value = edg_type_value(versioned); + + if (!validate_element_exists(file, kind, value, parent)) { + result = FALSE; + } /* if */ + } else { + an_ifc_edg_type_index univ_idx = to_universal_index(file, versioned); + + if (!is_null_index(univ_idx)) { + unknown_partition_conversion(file, str_for(univ_sort), univ_idx.value, + parent); + result = FALSE; + } /* if */ + } /* if */ + } /* if */ + return result; +} /* validate_index */ + + a_boolean validate_index(an_ifc_module_file *file, an_ifc_expr_index_0_33 versioned, const an_ifc_validation_trace *parent) @@ -15060,17 +15179,34 @@ representation is valid; otherwise, return FALSE. a_boolean result = TRUE; if (has_ifc_value(universal)) { - an_ifc_edg_type_index_0_43 stage_0; - an_ifc_validation_trace stage_0_trace = {"value", /*offset=*/0, parent}; + if (is_at_least(universal.get_file(), 0, 44)) { + an_ifc_edg_type_index_0_44 stage_0; + an_ifc_validation_trace stage_0_trace = + {"value", /*offset=*/0, parent}; - /* Copy the field (EdgExtensionType::value - EdgTypeIndex) into - version-specific storage. */ - static_assert(sizeof(stage_0) == 4, - "stage_0 is not properly sized storage!"); - copy_from_node_field(&stage_0, universal.get_storage(), /*offset=*/0); - if (!validate_index(universal.get_file(), stage_0, &stage_0_trace)) { - result = FALSE; - goto done; + /* Copy the field (EdgExtensionType::value - EdgTypeIndex) into + version-specific storage. */ + static_assert(sizeof(stage_0) == 4, + "stage_0 is not properly sized storage!"); + copy_from_node_field(&stage_0, universal.get_storage(), /*offset=*/0); + if (!validate_index(universal.get_file(), stage_0, &stage_0_trace)) { + result = FALSE; + goto done; + } /* if */ + } else { + an_ifc_edg_type_index_0_43 stage_0; + an_ifc_validation_trace stage_0_trace = + {"value", /*offset=*/0, parent}; + + /* Copy the field (EdgExtensionType::value - EdgTypeIndex) into + version-specific storage. */ + static_assert(sizeof(stage_0) == 4, + "stage_0 is not properly sized storage!"); + copy_from_node_field(&stage_0, universal.get_storage(), /*offset=*/0); + if (!validate_index(universal.get_file(), stage_0, &stage_0_trace)) { + result = FALSE; + goto done; + } /* if */ } /* if */ } /* if */ done: @@ -15536,6 +15672,36 @@ if the representation is valid; otherwise, return FALSE. } /* validate */ +template<> +a_boolean validate(const an_ifc_edg_type_float &universal, + const an_ifc_validation_trace *parent) +/* +Given the universal representation of EdgTypeFloat, return TRUE if the +representation is valid; otherwise, return FALSE. +*/ +{ + a_boolean result = TRUE; + + if (has_ifc_kind(universal)) { + an_ifc_edg_float_type_sort_0_44 stage_0; + an_ifc_validation_trace stage_0_trace = + {"kind", /*offset=*/0, parent}; + + /* Copy the field (EdgTypeFloat::kind - EdgFloatTypeSort) into + version-specific storage. */ + static_assert(sizeof(stage_0) == 4, + "stage_0 is not properly sized storage!"); + copy_from_node_field(&stage_0, universal.get_storage(), /*offset=*/0); + if (!validate_sort(universal.get_file(), stage_0, &stage_0_trace)) { + result = FALSE; + goto done; + } /* if */ + } /* if */ +done: + return result; +} /* validate */ + + template<> a_boolean validate(const an_ifc_edg_type_substituted &universal, const an_ifc_validation_trace *parent) @@ -37104,3 +37270,9 @@ END_EDG_NAMESPACE #endif /* !STANDALONE_UTILITY_PROGRAM */ +/* +Part of the EDG Compiler Project, under the Apache License v2.0 with LLVM +Exceptions. +See https://edgcpp.org/LICENSE.txt for license information. +SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +*/ diff --git a/src/ifc_modules_inst.h b/src/ifc_modules_inst.h index 95f7683546..2a07299fea 100644 --- a/src/ifc_modules_inst.h +++ b/src/ifc_modules_inst.h @@ -4,7 +4,6 @@ Exceptions. See https://edgcpp.org/LICENSE.txt for license information. SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ - /* ifc_modules_inst.h -- Explicit template instantiations needed at link time by @@ -613,6 +612,13 @@ INST_CONSTRUCT_NODE_ALL(an_ifc_edg_token_textual, an_ifc_edg_complex_token_index) INST_NODE_DECL(an_ifc_edg_trait_class_template_definition_storage) INST_NODE_DECL(an_ifc_edg_trait_function_definition_storage) +INST_NODE_DECL(an_ifc_edg_type_float_storage) + + +/* +Explicit instantiations of functions for EdgTypeFloat. +*/ +INST_CONSTRUCT_NODE_ALL(an_ifc_edg_type_float, an_ifc_edg_type_index) INST_NODE_DECL(an_ifc_edg_type_substituted_storage) @@ -2421,3 +2427,9 @@ END_DISABLE_GCC_WARNING_MAYBE_UNITIALIZED /* Conditionally close the "edg" namespace. */ END_EDG_NAMESPACE +/* +Part of the EDG Compiler Project, under the Apache License v2.0 with LLVM +Exceptions. +See https://edgcpp.org/LICENSE.txt for license information. +SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +*/ diff --git a/src/ifc_modules_read.c b/src/ifc_modules_read.c index e2d8e428fd..7e09a024c6 100644 --- a/src/ifc_modules_read.c +++ b/src/ifc_modules_read.c @@ -16120,6 +16120,67 @@ the EDG type index, instead return an empty optional. } /* load_edg_type_vendor_extension */ +static a_float_kind float_kind_for_edg_float_type( + an_ifc_edg_float_type_sort float_sort) +/* +Given an EDG floating-point type extension sort, return the corresponding +float kind. If the sort does not denote a known floating-point type, return +fk_last. +*/ +{ + a_float_kind result = (a_float_kind)fk_last; + + switch (float_sort) { + case ifc_efts_float16: + result = (a_float_kind)fk_float16; + break; + case ifc_efts_fp16: + result = (a_float_kind)fk_fp16; + break; + case ifc_efts_float32x: + result = (a_float_kind)fk_float32x; + break; + case ifc_efts_float64x: + result = (a_float_kind)fk_float64x; + break; + case ifc_efts_float80: + result = (a_float_kind)fk_float80; + break; + case ifc_efts_float128: + result = (a_float_kind)fk_float128; + break; + case ifc_efts_std_bfloat16: + result = (a_float_kind)fk_std_bfloat16; + break; + default_is_unexpected(); + } /* switch */ + return result; +} /* float_kind_for_edg_float_type */ + + +static a_type_ptr type_for_edg_float_type(an_ifc_edg_type_index type_idx) +/* +Given an EDG floating-point type extension index, return the corresponding +float type. If a problem occurs while retrieving the type, return NULL. +*/ +{ + a_type_ptr result = NULL; + Opt opt_ietf; + + construct_node(&opt_ietf, type_idx); + if (opt_ietf.has_value()) { + an_ifc_edg_type_float ietf = *opt_ietf; + a_float_kind float_kind = + float_kind_for_edg_float_type(get_ifc_kind(ietf)); + + if (float_kind != (a_float_kind)fk_last) { + result = float_type(float_kind); + } /* if */ + } /* if */ + return result; +} /* type_for_edg_float_type */ + + static a_type_ptr process_edg_type(an_ifc_edg_type_index type_idx) /* Return the type that corresponds to the specified EDG TypeIndex. If there is @@ -16131,26 +16192,35 @@ prefer type_for_type_index in other cases. { a_type_ptr result = NULL; - /* FIXME: As the path of least resistance, we just cache the type as a - typename-specifier and parse it; eventually we should be able to do - something smarter here. */ - { - a_module_token_cache cache; + switch (type_idx.sort) { + case ifc_ets_edg_type_float: + /* A floating-point type extension denotes a float type directly, so + there is nothing to parse. */ + result = type_for_edg_float_type(type_idx); + break; + case ifc_ets_edg_type_substituted: + /* FIXME: As the path of least resistance, we just cache the type as a + typename-specifier and parse it; eventually we should be able to do + something smarter here. */ + { a_module_token_cache cache; - /* Create a fake "typename-specifier" and use that to parse the - type. */ - cache_token(&cache, tok_typename); - cache_edg_type_first_part(&cache, type_idx, /*cinfo=*/{}); - cache_edg_type_second_part(&cache, type_idx, /*cinfo=*/{}); - if (!cache.is_valid()) { - goto invalid; - } /* if */ + /* Create a fake "typename-specifier" and use that to parse the + type. */ + cache_token(&cache, tok_typename); + cache_edg_type_first_part(&cache, type_idx, /*cinfo=*/{}); + cache_edg_type_second_part(&cache, type_idx, /*cinfo=*/{}); + if (!cache.is_valid()) { + goto invalid; + } /* if */ - result = parse_typename_specifier_cache(module_of(type_idx), &cache); - if (result == NULL) { - goto invalid; - } /* if */ - } + result = parse_typename_specifier_cache(module_of(type_idx), &cache); + } + break; + default_is_unexpected(); + } /* switch */ + if (result == NULL) { + goto invalid; + } /* if */ goto done; invalid: result = error_type(); @@ -22187,6 +22257,21 @@ scope); otherwise, return FALSE. goto invalid; default_is_unexpected(); } /* switch */ + } else if (elaboration.sort == ifc_ts_type_vendor_extension && + is_edg_authored(elaboration)) { + Opt opt_edg_type_idx = + load_edg_type_vendor_extension(elaboration); + + if (!opt_edg_type_idx.has_value()) { + goto invalid; + } /* if */ + + an_ifc_edg_type_index edg_type_idx = *opt_edg_type_idx; + if (edg_type_idx.sort == ifc_ets_edg_type_float) { + /* A floating-point type extension can always be expressed by direct + reference. */ + result = TRUE; + } /* if */ } else if (elaboration.sort == ifc_ts_type_pointer) { Opt opt_itp; @@ -24391,6 +24476,15 @@ See cache_type_first_part for additional information. */ { switch (type_idx.sort) { + case ifc_ets_edg_type_float: + { a_type_ptr edg_float_type = type_for_edg_float_type(type_idx); + + if (edg_float_type == NULL) { + goto invalid; + } /* if */ + cache_resolved_type_token(cache, edg_float_type); + } + break; case ifc_ets_edg_type_substituted: { Opt opt_subst_type; @@ -24452,6 +24546,7 @@ See cache_type_second_part for additional information. */ { switch (type_idx.sort) { + case ifc_ets_edg_type_float: case ifc_ets_edg_type_substituted: /* Nothing to do for these types. */ break; diff --git a/src/ifc_modules_spec.h b/src/ifc_modules_spec.h index a63e1916d4..4908e64fcf 100644 --- a/src/ifc_modules_spec.h +++ b/src/ifc_modules_spec.h @@ -4,7 +4,6 @@ Exceptions. See https://edgcpp.org/LICENSE.txt for license information. SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ - /* ifc_modules_spec.h -- Explicit template specializations needed at link time by @@ -110,3 +109,9 @@ END_DISABLE_GCC_WARNING_MAYBE_UNITIALIZED /* Conditionally close the "edg" namespace. */ END_EDG_NAMESPACE +/* +Part of the EDG Compiler Project, under the Apache License v2.0 with LLVM +Exceptions. +See https://edgcpp.org/LICENSE.txt for license information. +SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +*/ diff --git a/src/ifc_modules_write.c b/src/ifc_modules_write.c index 3b6c4c674e..1e29efef1b 100644 --- a/src/ifc_modules_write.c +++ b/src/ifc_modules_write.c @@ -2687,6 +2687,62 @@ the enum type. return result; } /* an_ifc_il_map::enter_enum_type */ +} /* namespace */ + +static an_ifc_edg_float_type_sort float_kind_to_edg_float_type( + a_float_kind float_kind) +/* +Given a float kind that has no IFC fundamental type representation, return the +corresponding EDG floating-point type extension sort. +*/ +{ + /* The initializer is never used: the cases below cover every float kind, + and the ones that cannot occur assert. It is present because MSVC's + definitely-assigned analysis does not account for the [[noreturn]] on + assertion_failed reached through the case group below, and warns. */ + an_ifc_edg_float_type_sort result = ifc_efts_float16; + + switch (float_kind) { + case fk_float16: + result = ifc_efts_float16; + break; + case fk_fp16: + result = ifc_efts_fp16; + break; + case fk_float32x: + result = ifc_efts_float32x; + break; + case fk_float64x: + result = ifc_efts_float64x; + break; + case fk_float80: + result = ifc_efts_float80; + break; + case fk_float128: + result = ifc_efts_float128; + break; + case fk_std_bfloat16: + result = ifc_efts_std_bfloat16; + break; + case fk_float: + case fk_double: + case fk_long_double: + case fk_std_float16: + case fk_std_float32: + case fk_std_float64: + case fk_std_float128: + case fk_last: + /* The traditional float kinds are written as IFC fundamental types + rather than as an extension, and fk_last should not appear in the + IL. */ + unexpected_condition(); + break; + default_is_unexpected(); + } /* switch */ + return result; +} /* float_kind_to_edg_float_type */ + +namespace { an_ifc_type_index an_ifc_il_map::enter_float_type(a_type_ptr type) /* @@ -2695,58 +2751,77 @@ for the float type. */ { check_assertion(type->kind == tk_float); - an_ifc_type_fundamental - fund_type; + a_float_kind float_kind = type->variant.float_kind; an_ifc_type_index - result = this->map_new_type(type, &fund_type); + result; - switch (type->variant.float_kind) { + switch (float_kind) { case fk_float: - set_ifc_basis(&fund_type, ifc_tbs_float); - set_ifc_precision(&fund_type, ifc_tps_default); - break; case fk_double: - set_ifc_basis(&fund_type, ifc_tbs_double); - set_ifc_precision(&fund_type, ifc_tps_default); - break; case fk_long_double: - set_ifc_basis(&fund_type, ifc_tbs_double); - set_ifc_precision(&fund_type, ifc_tps_long); - break; case fk_std_float128: - set_ifc_basis(&fund_type, ifc_tbs_float); - set_ifc_precision(&fund_type, ifc_tps_bit128); - break; case fk_std_float16: - set_ifc_basis(&fund_type, ifc_tbs_float); - set_ifc_precision(&fund_type, ifc_tps_bit16); - break; case fk_std_float32: - set_ifc_basis(&fund_type, ifc_tbs_float); - set_ifc_precision(&fund_type, ifc_tps_bit32); - break; case fk_std_float64: - set_ifc_basis(&fund_type, ifc_tbs_float); - set_ifc_precision(&fund_type, ifc_tps_bit64); - break; + { an_ifc_type_fundamental fund_type; + result = this->map_new_type(type, &fund_type); + switch(float_kind) { + case fk_float: + set_ifc_basis(&fund_type, ifc_tbs_float); + set_ifc_precision(&fund_type, ifc_tps_default); + break; + case fk_double: + set_ifc_basis(&fund_type, ifc_tbs_double); + set_ifc_precision(&fund_type, ifc_tps_default); + break; + case fk_long_double: + set_ifc_basis(&fund_type, ifc_tbs_double); + set_ifc_precision(&fund_type, ifc_tps_long); + break; + case fk_std_float128: + set_ifc_basis(&fund_type, ifc_tbs_float); + set_ifc_precision(&fund_type, ifc_tps_bit128); + break; + case fk_std_float16: + set_ifc_basis(&fund_type, ifc_tbs_float); + set_ifc_precision(&fund_type, ifc_tps_bit16); + break; + case fk_std_float32: + set_ifc_basis(&fund_type, ifc_tbs_float); + set_ifc_precision(&fund_type, ifc_tps_bit32); + break; + case fk_std_float64: + set_ifc_basis(&fund_type, ifc_tbs_float); + set_ifc_precision(&fund_type, ifc_tps_bit64); + break; + default: + unexpected_condition(); + break; + } /* switch */ + } + break; case fk_float16: - case fk_float128: case fk_fp16: case fk_float32x: case fk_float64x: case fk_float80: + case fk_float128: case fk_std_bfloat16: - case fk_last: - /* These extended floating-point kinds have no IFC fundamental-type - encoding that distinguishes them from other floating-point types - of the same size ("__fp16" and "__float128" in particular have - different manglings than "_Float16" and "_Float128"); they will - be covered by an EDG extension type. */ - ifc_write_catastrophe(); + /* The IFC has no fundamental type representation for these types, so + they are written using the EDG floating-point type extension. */ + { an_ifc_edg_type_float + edg_float_type; + + result = this->map_new_type(type, &edg_float_type); + set_ifc_kind(&edg_float_type, + float_kind_to_edg_float_type(float_kind)); + } break; + case fk_last: + /* fk_last should not appear in the IL. */ + unexpected_condition(); default_is_unexpected(); } /* switch */ - set_ifc_sign(&fund_type, ifc_tss_signed); return result; } /* an_ifc_il_map::enter_float_type */