A method for automatically converting bit field member size and end of a header file

CN117369778BActive Publication Date: 2026-08-11XIAN AVIATION COMPUTING TECH RES INST OF AVIATION IND CORP OF CHINA
View PDF 1 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-08-22
Publication Date
2026-08-11

AI Technical Summary

Technical Problem

[0002]在机载嵌入式设备研发过程的不同阶段、状态中,常出现处理器型号的变化,而这往往又代表着处理器大小端的变化,这便使得原本针对大/小端模式处理器开发的软件无法正常工作,设备功能丧失,重新开发软件后才能使设备正常工作

Benefits of technology

[0027] When processor endianness changes, this application's modification method saves time and manpower costs compared to redevelopment. Furthermore, this application utilizes computer programs to perform each step, resulting in high efficiency through automatic modification and preventing the introduction of erroneous modifications.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117369778B_ABST
    Figure CN117369778B_ABST
Patent Text Reader

Abstract

This application provides a method for automatically converting the endianness of header file bit field members, belonging to the technical field of computer software applications. Specifically, it involves automatically converting the order of header file bit field members, including four steps: reading the header file and extracting structure information, making implicit bit field members explicit, determining the inversion group based on the structure information, reversing the order, and saving the file as a new file. This application's processing scheme achieves automatic endianness conversion of header file bit field members.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer software applications, and in particular to a method for automatic endianness conversion of header file bit field members. Background Technology

[0002] During different stages and states of the development of airborne embedded devices, processor models often change, which often represents changes in the endianness of the processor. This causes software originally developed for big / little endian processors to malfunction, resulting in the loss of device functionality. Only after redeveloping the software can the device function properly. Summary of the Invention

[0003] In view of this, this application provides a method for automatic endianness conversion of header file bit field members, which solves the problems in the prior art. Compared with redevelopment, using the automatic conversion method provided by this application to modify the software saves time and manpower costs, is highly efficient, and does not introduce erroneous modifications.

[0004] This application provides a method for automatic endianness conversion of header file bit field members, which adopts the following technical solution:

[0005] A method for automatically converting the endianness of bit field members in header files, wherein each header file includes several structures, and the method for automatically converting the endianness of bit field members in header files includes the following steps:

[0006] Step 1: Read the header file and extract information from all structures;

[0007] Step 2: Based on the information of all structures extracted in Step 1, group the consecutive bit-field members of the same type in the structure into a quasi-inversion group. Find all multiple quasi-inversion groups in the structure. Each quasi-inversion group includes multiple first members of type 1. Determine the relationship between the sum of the bit-field lengths of the found first members and the proportion of ordinary variables corresponding to type 1. If the sum of the bit-field lengths of the found first members is greater than the proportion of ordinary variables corresponding to type 1, it means that the current quasi-inversion group can be divided into multiple quasi-inversion groups. The quasi-inversion after division should maximize the sum of the bit-field lengths of the found first members without exceeding the proportion of ordinary variables corresponding to type 1. If the sum of the bit-field lengths of the found first members is less than the proportion of ordinary variables corresponding to type 1, it means that there is an implicit bit-field member. Add the implicit bit-field member as the second member. If the sum of the bit-field lengths of the found first members is the same as the proportion of ordinary variables corresponding to type 1, it means that there is no implicit bit-field member.

[0008] Step 3: When the quasi-inversion group has implicit bit field members, the multiple first members and second members are combined into an inversion group, and the set of row numbers of the multiple first members and second members is used as the inversion row number group; when the quasi-inversion group does not have implicit bit field members, the multiple first members are combined into an inversion group, and the set of row numbers of the first members is used as the inversion row number group.

[0009] Step 4: Reverse the reverse line number group corresponding to each reverse group to obtain the new line number of each member in the reverse group, and readjust the line number of the member in the file according to the new line number; after all reverse groups are processed, save the file to complete the conversion.

[0010] Optionally, step 1 includes:

[0011] Step 101: Locate each structure based on its character characteristics. A structure includes one or more ordinary members and bit field members. Extract the sequence number, whether it is a bit field member, type, bit field length, and file line number of each member in each structure and record them.

[0012] Optionally, step 1 may further include the following after step 101:

[0013] Step 102: Based on the information recorded in step 101, a structure member information table is formed for each structure.

[0014] In step 2, multiple quasi-inversion groups in the structure are identified based on the structure member information table.

[0015] Optionally, steps 1-4 are executed by a computer program, wherein all structure member information tables are used as input for step 2.

[0016] Optionally, step 1 includes extracting structure information through a computer program and recording the sequence number of each member of each structure in the structure, whether it is a bit field member, its type, bit field length, and the line number of the file it is located in.

[0017] Optionally, the specific steps for extracting structure information using a computer program and recording the sequence number of each member in the structure, whether it is a bit-field member, its type, bit-field length, and the line number in the file include:

[0018] Step 1001: Locate the beginning of the structure using the keyword struct. After struct, you can find the left curly brace, right curly brace, and semicolon of the structure.

[0019] Step 1002: Skip the newline character '\n' after the left curly brace;

[0020] Step 1003: After skipping whitespace characters and alignment characters, the string before the characters become whitespace or alignment again is the member type, and the member type is determined;

[0021] Step 1004: After skipping the space character or alignment character after the member type, the string before the character becomes a space character, alignment character, colon, or semicolon is the member name. Determine the member name, and at the same time, check whether there is a colon before encountering a semicolon. If there is, it means that the member is a bit field member; otherwise, it is a normal member.

[0022] Step 1005: If it is a bit field member, obtain the length of the bit field member from the colon after the member name; otherwise, proceed to the next step.

[0023] Step 1006: Record member information into the member information table of the corresponding structure;

[0024] Step 1007: Determine if the next character after the semicolon of a member (excluding '\n', spaces, and alignment) is a right curly brace. If it is not a right curly brace, it means that the current structure has another member, and return to step 1002 to continue searching for the next member; if it is, it means that the member information of the current structure has been extracted.

[0025] Step 1008: Check if there are any more structures after the current structure. If so, jump back to step 1001. If not, end the extraction of member information of all structures in the entire header file.

[0026] In summary, this application includes the following beneficial technical effects:

[0027] When processor endianness changes, this application's modification method saves time and manpower costs compared to redevelopment. Furthermore, this application utilizes computer programs to perform each step, resulting in high efficiency through automatic modification and preventing the introduction of erroneous modifications. Attached Figure Description

[0028] To more clearly illustrate the technical solutions of the embodiments of this application, the drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0029] Figure 1 The process for reading header files and extracting structure information;

[0030] Figure 2 The process for determining the reverse order scheme based on the structure information. Detailed Implementation

[0031] The embodiments of this application will now be described in detail with reference to the accompanying drawings.

[0032] The following specific examples illustrate the implementation of this application. Those skilled in the art can easily understand other advantages and effects of this application from the content disclosed in this specification. Obviously, the described embodiments are only a part of the embodiments of this application, and not all of them. This application can also be implemented or applied through other different specific embodiments, and the details in this specification can also be modified or changed based on different viewpoints and applications without departing from the spirit of this application. It should be noted that, in the absence of conflict, the following embodiments and features in the embodiments can be combined with each other. Based on the embodiments in this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0033] It should be noted that various aspects of embodiments within the scope of the appended claims are described below. It will be apparent that the aspects described herein can be embodied in a wide variety of forms, and any particular structure and / or function described herein is merely illustrative. Based on this application, those skilled in the art will understand that one aspect described herein can be implemented independently of any other aspect, and two or more of these aspects can be combined in various ways. For example, any number of aspects set forth herein can be used to implement the device and / or practice the method. Additionally, this device and / or method can be implemented using structures and / or functionalities other than one or more of the aspects set forth herein.

[0034] It should also be noted that the illustrations provided in the following embodiments are only schematic representations of the basic concept of this application. The drawings only show the components related to this application and are not drawn according to the actual number, shape and size of the components in the actual implementation. In the actual implementation, the form, quantity and proportion of each component can be arbitrarily changed, and the layout of the components may also be more complex.

[0035] Furthermore, specific details are provided in the following description to facilitate a thorough understanding of the examples. However, those skilled in the art will understand that the described aspects can be practiced without these specific details.

[0036] This application provides a method for automatic endianness conversion of header file bit field members.

[0037] like Figure 1 and Figure 2 As shown, a method for automatic endianness conversion of header file bit field members is described. Each header file includes several structures, and the method for automatic endianness conversion of header file bit field members includes the following steps:

[0038] Step 1: Read the header file and extract information from all structures.

[0039] Step 2: Based on the information of all structures extracted in Step 1, group consecutive bit-field members of the same type in the structure into a quasi-inversion group. Find all multiple quasi-inversion groups in the structure. Each quasi-inversion group includes multiple first members of type 1. Determine the relationship between the sum of the bit-field lengths of the found first members and the proportion of ordinary variables corresponding to type 1. If the sum of the bit-field lengths of the found first members is greater than the proportion of ordinary variables corresponding to type 1, it means that the current quasi-inversion group can be divided into multiple quasi-inversion groups. The quasi-inversion after division should maximize the sum of the bit-field lengths of the found first members without exceeding the proportion of ordinary variables corresponding to type 1. If the sum of the bit-field lengths of the found first members is less than the proportion of ordinary variables corresponding to type 1, it means that there is an implicit bit-field member. Add the implicit bit-field member as the second member. If the sum of the bit-field lengths of the found first members is the same as the proportion of ordinary variables corresponding to type 1, it means that there is no implicit bit-field member.

[0040] Step 3: When the quasi-inversion group has implicit bit field members, multiple first members and second members are combined into an inversion group, and the set of row numbers of multiple first members and second members is used as the inversion row number group; when the quasi-inversion group does not have implicit bit field members, multiple first members are combined into an inversion group, and the set of row numbers of the first members is used as the inversion row number group.

[0041] Step 4: Reverse the reverse line number group corresponding to each reverse group to obtain the new line number of each member in the reverse group, and readjust the line number of the member in the file according to the new line number; after all reverse groups are processed, save the file to complete the conversion.

[0042] Step 1 includes:

[0043] Step 101: Locate each structure based on its character characteristics. A structure includes one or more ordinary members and bit field members. Extract the sequence number, whether it is a bit field member, type, bit field length, and file line number of each member in each structure and record them.

[0044] Step 102: Based on the information recorded in step 101, a structure member information table is generated for each structure; as shown in Table 1, this is an example structure and its member information table:

[0045] Table 1 Example Structure and its Member Information Table

[0046]

[0047] Where b represents whether it is a bit-field member, t represents the type, l represents the length of the bit-field member, n represents the name, and r represents the line number. Using S... i This represents each structure in the header file H, where i = 1, 2, ..., g, indicating that there are g structures, and H = {S1, S2, ..., S...} g}. For structure S i In other words, it has n i It consists of 1 member, denoted as S. i ={M i,1 M i,2 ,...,M i,ni}, where M i,1 ={b i,1 ,t i,1 ,l i,1 ,n i,1 ,r i,1 ,}

[0048] In step 2, multiple quasi-inversion groups in the structure are identified based on the structure member information table.

[0049] Step 1 includes extracting structure information using a computer program and recording the sequence number of each member in the structure, whether it is a bit-field member, its type, bit-field length, and the line number in the file. The specific steps are as follows:

[0050] Step 1001: Locate the beginning of the structure using the keyword struct. After struct, you can find the left curly brace, right curly brace, and semicolon of the structure.

[0051] Step 1002: Skip the newline character '\n' after the left curly brace;

[0052] Step 1003: After skipping whitespace characters and alignment characters, determine the member type of the string before the characters become whitespace or alignment again; find the member type of each member in the structure.

[0053] Step 1004: After skipping the space character or alignment character after the member type, the string before the character becomes a space character, alignment character, colon, or semicolon is the member name. Determine the member name, and at the same time, check whether there is a colon before encountering a semicolon. If there is, it means that the member is a bit field member; otherwise, it is a normal member.

[0054] Step 1005: If it is a bit field member, obtain the length of the bit field member from the colon after the member name; otherwise, proceed to the next step.

[0055] Step 1006: Record member information into the member information table of the corresponding structure;

[0056] Step 1007: Determine if the next character after the semicolon of a member (excluding '\n', spaces, and alignment) is a right curly brace. If it is not a right curly brace, it means that the current structure has another member, and return to step 1002 to continue searching for the next member; if it is, it means that the member information of the current structure has been extracted.

[0057] Step 1008: Check if there are any more structures after the current structure. If so, jump back to step 1001. If not, end the extraction of member information of all structures in the entire header file.

[0058] Steps 1-4 are executed by a computer program, wherein all structure member information tables are used as input for step 2.

[0059] An inversion group is a set of consecutive bit-field members of the same type within the same structure, where the total length of the bit-field members equals the number of bits corresponding to their type. The corresponding inversion row number group can be represented as V = {line1, line2, ...}. A structure may have several inversion groups. For example, the structure shown in Table 1 has three inversion groups, corresponding to inversion row number groups V1 = {3, 4}, V2 = {6, 7}, and V3 = {8, 9, 10}.

[0060] In the second step, which is to explicitly specify implicit bit-field members, and the third step, which is to determine the inversion group based on the structure information: First, find a group of members in the structure that appear consecutively, are of the same type, and whose total bit-field length equals the number of bits corresponding to their type. If the total bit-field length cannot equal the number of bits corresponding to their type, it indicates the existence of implicit bit-field members, which need to be explicitly added to obtain an inversion group. Then, record the row numbers of these members sequentially to obtain an inverted row number group. In one embodiment, the specific steps of steps 2 and 3 executed by a computer program are as follows:

[0061] 301, starting with the first struct;

[0062] 302. Find the first bit-field member, denoted as M1;

[0063] 303. Determine whether the bit field length l1 of M1 is equal to the number of bits corresponding to its type t1. If so, record the next bit field member after M1 as the new M1 and jump to step 303. Otherwise, proceed directly to the next step.

[0064] 304. Let σ represent the sum of bit field lengths of consecutive bit field members of the same type, and let σ = 0;

[0065] 305, add the length l1 of bit field M1 into σ;

[0066] 306. Determine whether the next member of M1 is a bit field member of the same type as M1. If not, it means that there is an implicit bit field member after M1. After filling it out, form an inverted group with M1 and jump to step 310. If it is, proceed to the next step.

[0067] 307. Let M2 be the next bit field member of the same type that is consecutive to M1, and add the bit field length l2 of M2 into σ;

[0068] 308. Determine if σ is less than the number of bits corresponding to type M1. If so, continue searching for bit field members M3, M4, ..., M that are consecutive to M2 and of the same type. n+1 The found bit field members are added to the length σ, and then the next step is performed; otherwise, the next step is performed directly.

[0069] 309. Determine if σ is equal to the number of bits corresponding to type M1. If not, it means there is an implicit bit field member. Add the implicit bit field member and compare it with M1, M2, ..., M n If a group is formed in reverse order, then M1, M2, ..., M n+1 It is an inversion group;

[0070] 310. Continue searching for other inversion groups within this structure. Once the search within this structure is complete, proceed to the next step.

[0071] 311, Starting from the next struct, jump to step 302, until all inversion groups of all structs are found;

[0072] 312. Recalculate the row numbers and calculate the inverted row number group corresponding to each inverted group.

[0073] In one embodiment, step 4 involves reversing the order and saving the file; based on each group of reversed line numbers, the corresponding lines are reversed; after all groups of reversed line numbers have been processed, the file is saved to complete the modification.

[0074] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.

Claims

1. A method for automatically converting the size of a bitfield member of a header file, characterized in that, Each header file contains several structures. The method for automatic endianness conversion of bit field members in header files includes the following steps: Step 1: Read the header file and extract information from all structures; Step 2: Based on the information of all structures extracted in Step 1, group the consecutive bit-field members of the same type in the structure into a quasi-inversion group. Find all multiple quasi-inversion groups in the structure. Each quasi-inversion group includes multiple first members of type 1. Determine the relationship between the sum of the bit-field lengths of the found first members and the proportion of ordinary variables corresponding to type 1. If the sum of the bit-field lengths of the found first members is greater than the proportion of ordinary variables corresponding to type 1, it means that the current quasi-inversion group can be divided into multiple quasi-inversion groups. The quasi-inversion after division should maximize the sum of the bit-field lengths of the found first members without exceeding the proportion of ordinary variables corresponding to type 1. If the sum of the bit-field lengths of the found first members is less than the proportion of ordinary variables corresponding to type 1, it means that there is an implicit bit-field member. Add the implicit bit-field member as the second member. If the sum of the bit-field lengths of the found first members is the same as the proportion of ordinary variables corresponding to type 1, it means that there is no implicit bit-field member. Step 3: When the quasi-inversion group has implicit bit field members, the multiple first members and second members are combined into an inversion group, and the set of row numbers of the multiple first members and second members is used as the inversion row number group; when the quasi-inversion group does not have implicit bit field members, the multiple first members are combined into an inversion group, and the set of row numbers of the first members is used as the inversion row number group. Step 4: Reverse the reverse line number group corresponding to each reverse group to obtain the new line number of each member in the reverse group, and readjust the line number of the member in the file according to the new line number; after all reverse groups are processed, save the file to complete the conversion.

2. The method of claim 1, wherein Step 1 includes: Step 101: Locate each structure based on its character characteristics. A structure includes one or more ordinary members and bit field members. Extract the sequence number, whether it is a bit field member, type, bit field length, and file line number of each member in each structure and record them.

3. The header file bitfield member size endianness automatic conversion method of claim 2, wherein Step 1, following step 101, further includes: Step 102: Based on the information recorded in step 101, a structure member information table is formed for each structure. In step 2, multiple quasi-inversion groups in the structure are identified based on the structure member information table.

4. The header file bitfield member size endianness automatic conversion method of claim 3, wherein Steps 1-4 are executed by a computer program, wherein all structure member information tables are used as input for step 2.

5. The header file bitfield member size endianness automatic conversion method of claim 2, wherein Step 1 includes extracting structure information through a computer program and recording the sequence number of each member in the structure, whether it is a bit field member, its type, bit field length, and the line number in the file.

6. The header file bitfield member size endianness automatic conversion method of claim 5, wherein The specific steps for extracting structure information using a computer program and recording the sequence number, bit-field member, type, bit-field length, and file line number of each member in the structure include: Step 1001: Locate the beginning of the structure using the keyword struct. After struct, you can find the left curly brace, right curly brace, and semicolon of the structure. Step 1002: Skip the newline character '\n' after the left curly brace; Step 1003: After skipping whitespace characters and alignment characters, the string before the characters become whitespace or alignment again is the member type, and the member type is determined; Step 1004: After skipping the space character or alignment character after the member type, the string before the character becomes a space character, alignment character, colon, or semicolon is the member name. Determine the member name, and at the same time, check whether there is a colon before encountering a semicolon. If there is, it means that the member is a bit field member; otherwise, it is a normal member. Step 1005: If it is a bit field member, obtain the length of the bit field member from the colon after the member name; otherwise, proceed to the next step. Step 1006: Record member information into the member information table of the corresponding structure; Step 1007: Determine if the next character after the semicolon of a member (excluding '\n', spaces, and alignment) is a right curly brace. If it is not a right curly brace, it means that the current structure has another member, and return to step 1002 to continue searching for the next member; if it is, it means that the member information of the current structure has been extracted. Step 1008: Check if there are any more structures after the current structure. If so, jump back to step 1001. If not, end the extraction of member information of all structures in the entire header file.

Citation Information

Patent Citations

  • Cross-byte definition data chain information big and small end conversion method and device

    CN118426776A