-
Notifications
You must be signed in to change notification settings - Fork 298
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle mapping of record members to external C code types and layout. #9399
Conversation
- This is done in preparation for implementing of conversion types and function for sending and receiving record types to external C functions while making sure that types are interpreted correctly modelica_integer (a.k.a long) vs int right now.'
- Each Modelica record now gets two struct definitions. The first, already existing, version uses OpenModelica types for the record members. The new additional type uses types specified in Modelica Standard for mapping of external arguments, i.e., uses `double`, `int`, `int`, ' `const char*`, and `int` for Real, Integer, Boolean, String, and Enumeration repsectively, regardless of our internal representations. - Each Modelica record also gets two addition functions for converting to/from one representation of the record to the other. - This is a lot of additional code generation. However, it can be mitigated by identifying the only records that need it and avoiding it for the others. - Records that contain arrays or other records are not yet supported in this mode.
- Extend the record conversion functions to handle nested records. - We do not support arrays yet.
- This marker is set to false for all record types at the moment. The additional code is generated for all records regardless of the value. Once we implement the necessary analysis we can change the value for records that need it and disable the generation being done for all records right now.
@casella This should provide support for mapping of record members to external C structs. It fixes the original issue in #8591 and the MWE posted in there. @perost is working on identifying and marking the records that need this additional handling. That should considerably reduce the amount of additional code we generate. We will do a follow up fix once that is ready. |
OK, I see this passed the core testsuite, so I'd merge it and see what it does to the library testsuite, and also test it with ExternalMedia myself, since it is not yet in the library testsuite. Then we can decide if we keep it for 1.20.0 and roll it back aftwards, or if it really doesn't work well, so we roll it back now. |
- Implement marking of externally used records as needed by OpenModelica#9399.
- Implement marking of externally used records as needed by #9399.
* Use the externally used records marker. * Set marker to always be true for the OF. * Use a map/dictionary instead of keeping separate lists. - Use a map (string, record Declaration) to keep a track of records in the SimCode. This allows for a simpler and quicker check. In addition we can update entries easily. * Add MetaModelica records to the map as well. * Debug help * Fix traversal order to avoid possible(?) infinite recursion. * Disable the old creation of record declarations. - See what fails in the testsuite. - It was actually affecting some tests because nested records were cycling back and messing with the order. Not exactly sure how but is not relevant anymore. * Simplify processing of record declrations. - Remove returned lists from functions: elaborateNestedRecordDeclarations elaborateRecordDeclarationsFromTypes elaborateRecordDeclarationsForRecord elaborateNestedRecordDeclarations - Remove input lists from functions: - elaborateRecordDeclarationsFromTypes * Make sure we do not overwrite true values to false. - If an entry already exists in the map and we always update, then there is a chance we might overwrite a 'true' value with a 'false' value for external conversion marker. Check if the entry exists and if it is marked false while then new incoming entry is marked true, then update it. Otherwise do nothing. * Remove input lists from functions - Remove input lists from functions: - elaborateNestedRecordDeclarations - elaborateRecordDeclarationsForRecord * Remove input and output lists from more functions. - Removed from - elaborateRecordDeclarationsForMetarecords * Remove input and output lists from elaborateRecordDeclarations. * Remove input and output lists from more functions. - Remove input and output lists from functions: - elaborateFunctions2 - elaborateFunction * Convert recursive functions to loops. - Recursive functions converted to loops: - elaborateNestedRecordDeclarations - elaborateRecordDeclarationsForMetarecords - elaborateRecordDeclarationsFromTypes * Rename some functions to be more descriptive. - elaborateRecordDeclarationsForMetarecords -> collectRecDeclsFromMetaRecordCallExps - elaborateNestedRecordDeclarations -> collectRecDeclsFromTypesVars - elaborateRecordDeclarationsFromTypes -> collectRecDeclsFromTypes - elaborateRecordDeclarationsForRecord -> collectRecDeclsFromType * Change how records are collected from metarecordcalls - Instead of: - traversing all expressions, collecting all meta record calls to a list, and then traversing this list to collect record declarations - collect record declarations while traversing all expressions (without collecting metarecordcalls into a whole new list.) * Rename functions to be more descriptive. - elaborateRecordDeclarations -> collectRecDeclsFromElems * Convert recursive functions to loops. - Convert recursive functions to loops: - collectRecDeclsFromElems (used to be `elaborateRecordDeclarations`) * Some minor cleanup and renaming. - declMap -> recDeclsMap - needsExternalConversion -> usedExternally
Cleanup external function handling.
function for sending and receiving record types to external C functions
while making sure that types are interpreted correctly
modelica_integer
(a.k.along
) vs int right now.'Handle mapping of recrods to external function arguments.
Each Modelica record now gets two struct definitions. The first,
already existing, version uses OpenModelica types for the record members.
The new additional type uses types specified in Modelica Standard for
mapping of external arguments, i.e., uses
double
,int
,int
, 'const char*
, andint
for Real, Integer, Boolean, String, and Enumerationrepsectively, regardless of our internal representations.
Each Modelica record also gets two addition functions for converting
to/from one representation of the record to the other.
This is a lot of additional code generation. However, it can be mitigated
by identifying the only records that need it and avoiding it for the others.
Records that contain arrays or other records are not yet supported in
this mode.
Add mapping support for record record members.
typedef external versions for alias records too.
Add marker for records needing conversion to external versions.
This marker is set to false for all record types at the moment. The
additional code is generated for all records regardless of the value.
Once we implement the necessary analysis, we can change the value for
records that need it and disable the generation being done for all
records right now.
Improves #8591.