120 likes | 134 Views
Learn how to share data between C/C++ and Ada languages efficiently using a type generator tool. This solution allows for better performance than language-independent formats like XML, ensuring binary compatibility of shared data types.
E N D
Data sharing between C/C++ and Ada Matt Mark - matt.mark@lmco.com
Introduction • Development of real time Air Traffic Control system (ERAM - EnRoute Automation Modernization) with strict response time requirements. • Legacy components include Ada and C code. These legacy components are being integrated together. • Components typically are implemented in Ada or C/C++ and provide APIs in both languages. • Due to the to frequency of calls between languages, we wanted better performance than a language independent format such as XML. Matt Mark - matt.mark@lmco.com
Dictionaries • From previous programs, we have tools that use ASIS to gather information about data structures and build dictionary files. • Similar tools available for C structures. • Dictionary files include information such as: type names / field names / kind of field (float , integer, enumeration) / ranges / offsets • Ada95 unique features such as tagged types not supported • Dictionaries used by support tools. For example, to format binary recorded data into text. Matt Mark - matt.mark@lmco.com
Solution / type generator • Wrote a type generator tool that uses information in dictionary entry and creates Ada and C types. • Entire type is defined in a single Ada package / C header file which can be compiled. • Types supported limited to those naturally defined in Ada and C/C++ (no variant records, unions). Matt Mark - matt.mark@lmco.com
Usage • Define type to be shared in Ada, C, C++ • Create dictionary entry • Run type generator to create to create opposite language type. • Use “opposite language” type (modification allowed). • Create dictionary entry for “opposite language” type. • At system build time, two types checked to be binary compatible. Matt Mark - matt.mark@lmco.com
Example – original type package Rel is subtype Name_T is String (1 .. 8); type Kind_T is (None, Os, Firm, Appl); end Rel; with Rel; package Rel_Msg is type Delete_Rel_T is record Kind : Rel.Kind_T; Name : Rel.Name_T; end record; end Rel_Msg; Matt Mark - matt.mark@lmco.com
Generated Ada code package Test2 is type Rel_Kind_T is (None, Os, Firm, Appl); subtype Rel_Name_T is String (1 .. 8); type Rel_Msg_Delete_Rel_T is record Kind : Rel_Kind_T; Name : Rel_Name_T; end record; for Rel_Msg_Delete_Rel_T use record Kind at 0 range 0 .. 7; Name at 0 range 8 .. 71; end record; for Rel_Msg_Delete_Rel_T'Size use 72; end Test2; Matt Mark - matt.mark@lmco.com
Generated C code typedef enum e_REL_KIND_T {NONE, OS, FIRM, APPL } REL_KIND_T; typedef struct {unsigned char KIND; char NAME[8]; } REL_MSG_DELETE_REL_T; Matt Mark - matt.mark@lmco.com
Notes about generated types • Generated code contained in single package for simplicity of the type generator tool – although, this results in awkward naming of types. • Generated types contain rep spec regardless of whether original type did. • Pad fields added to C types where necessary Matt Mark - matt.mark@lmco.com
Modification of generated types • Modification of generated types allows for more natural type definitions in each language. For example, character arrays in C are defined in arrays of characters in generated Ada types. • At build time, generated types are compared to original types. • Dictionary entries of original type and generated type are compared. Some comparison rules are: • Array types and fields, the bit locations, number of elements, and element sizes must match • For integer fields, the bit locations must match and have overlapping ranges • A switch on the type matching tool control if field names must match. Matt Mark - matt.mark@lmco.com
Other applications • Systems that transitions to new compilers or platforms and go through periods where old and updates systems co-exist. • Sharing data between support and operational systems. Matt Mark - matt.mark@lmco.com
Conclusion • We’ve started using these tools with success. • Currently completing SW development and the type generator tool has been used more than the type matching tool. • Expect more use from type matching tool as we transition from primarily developing code to integration. Matt Mark - matt.mark@lmco.com