A source code byte alignment checking method, electronic device, and storage medium

By converting the source code into an abstract syntax tree and combining the byte alignment rules of the target platform, the byte alignment of the data structure is automatically checked, which solves the problems of inefficiency and error-prone in the existing technology, and realizes efficient and accurate byte alignment checks.

CN119902960BActive Publication Date: 2025-06-20POWERLEADER COMPUTER SYST CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202510386934.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-03-31
Publication Date
2025-06-20
Estimated Expiration
2045-03-31

AI Technical Summary

Technical Problem

In the prior art, developers need to manually analyze and check the byte alignment of data structures, which is inefficient and prone to errors.

Method used

By converting the source code into an abstract syntax tree, extracting member variables and information in the data structure, loading the byte alignment rules of the target platform, calculating the actual memory layout of the data structure, and checking whether it complies with the byte alignment rules, and generating an analysis report.

Benefits of technology

It improves the efficiency and accuracy of source code byte alignment checks, achieves a balance between flexibility and accuracy, and reduces the burden of developers' manual inspections.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119902960B_ABST
    Figure CN119902960B_ABST
Patent Text Reader

Abstract

The present invention relates to a source code byte alignment checking method, an electronic device and a storage medium, which convert source code into an abstract syntax tree, extract data structures according to the abstract syntax tree, and record member variables and member variable information in the data structures; then load byte alignment rules of a target platform from a target source; traverse the member variables of the data structures, calculate a first actual memory layout of the data structures according to the member variable information and offsets, check whether the first actual memory layout conforms to the byte alignment rules, and obtain alignment problem information; and generate an analysis report according to the alignment problem information. By extracting source code information for static analysis and combining with dynamically loading byte alignment rules, the efficiency and accuracy of source code byte alignment checking are improved, and a balance between flexibility and accuracy is achieved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and particularly to a source code byte alignment checking method, an electronic device, and a storage medium. Background Art

[0002] Byte Alignment is a memory allocation mechanism in a computer system, which is used to ensure that member variables in a data structure are stored in memory according to specific rules. The main purpose of byte alignment is to improve the efficiency of the processor accessing memory, reduce the number of cache misses, and optimize performance. However, developers usually manually analyze and check the byte alignment of data structures by reading source code. This method is inefficient and error-prone. Summary of the Invention

[0003] The present invention provides a source code byte alignment checking method, an electronic device, and a storage medium, aiming to solve at least one of the technical problems existing in the prior art.

[0004] The technical solution of the present invention is a source code byte alignment checking method, including:

[0005] Converting the source code into an abstract syntax tree;

[0006] Extracting a data structure according to the abstract syntax tree, and recording member variables and member variable information in the data structure;

[0007] Loading byte alignment rules of a target platform from a target source;

[0008] Traversing the member variables of the data structure, and calculating a first actual memory layout of the data structure according to the member variable information and an offset;

[0009] Checking whether the first actual memory layout conforms to the byte alignment rules to obtain alignment problem information;

[0010] Generating an analysis report according to the alignment problem information.

[0011] According to some embodiments of the present invention, the member variable information includes a member variable type, a member variable size, and a member variable order;

[0012] Traversing the member variables of the data structure, and calculating a first actual memory layout of the data structure according to the member variable information and an offset, including:

[0013] Initializing the offset to 0;

[0014] Traverse each of the member variables of the data structure, calculate the required alignment padding according to the byte alignment rule, the member variable type, the member variable size, and the member variable order, and update the offset to the end position of the current member variable;

[0015] Based on the offset, determine whether the data structure conforms to the byte alignment rule. If the data structure does not conform to the byte alignment rule, add tail padding at the end of the data structure to obtain the first actual memory layout.

[0016] According to some embodiments of the present invention, the converting the source code into an abstract syntax tree includes:

[0017] Use a lexical analyzer and a syntax analyzer to convert the source code into the abstract syntax tree.

[0018] According to some embodiments of the present invention, the target source includes one or more combinations of a custom configuration file, compiler default settings, and a predefined multi-platform rule library;

[0019] The loading the byte alignment rule of the target platform from the target source includes:

[0020] Load the byte alignment rule from one or more combinations of the custom configuration file, the compiler default settings, and the predefined multi-platform rule library.

[0021] According to some embodiments of the present invention, generating an analysis report according to the alignment problem information includes:

[0022] Formulate a repair plan according to the alignment problem information;

[0023] Record the data structure name, member variable list, the offset, the alignment problem information, and the repair plan to obtain the analysis report.

[0024] According to some embodiments of the present invention, the alignment problem information includes the location of the problem, the type of the problem, and the content of the problem;

[0025] Formulate a repair plan according to the alignment problem information; record the data structure name, member variable list, the offset, the alignment problem information, and the repair plan to obtain the analysis report, including:

[0026] Formulate the repair plan according to the location of the problem, the type of the problem, and the content of the problem, and record the data structure name, the member variable list, the offset, the location of the problem, the type of the problem, the content of the problem, and the repair plan to obtain the analysis report.

[0027] After generating an analysis report based on the alignment problem information, the source code byte alignment checking method further includes:

[0028] Based on the byte alignment rules of multiple target platforms, calculate the second actual memory layout of the data structure respectively;

[0029] Check whether the second actual memory layout conforms to the byte alignment rules of multiple target platforms respectively, and obtain the inspection results of multiple target platforms;

[0030] Compare the inspection results of multiple target platforms and generate a cross-platform compatibility report.

[0031] After generating an analysis report based on the alignment problem information, the source code byte alignment checking method further includes:

[0032] If the source code has been modified according to the analysis report, only perform source code byte alignment checking on the modified part of the source code.

[0033] The technical solution of the present invention also relates to an electronic device, which includes a memory and a processor. The memory stores a computer program, and when the processor executes the computer program, it implements a source code byte alignment checking method as described above.

[0034] The technical solution of the present invention also relates to a storage medium, which stores a computer program, and when the computer program is executed by a processor, it implements a source code byte alignment checking method as described above.

[0035] The beneficial effects of the present invention include: converting the source code into an abstract syntax tree, extracting the data structure according to the abstract syntax tree, and recording the member variables and member variable information in the data structure; then loading the byte alignment rules of the target platform from the target source; traversing the member variables of the data structure, calculating the first actual memory layout of the data structure according to the member variable information and the offset, checking whether the first actual memory layout conforms to the byte alignment rules, and obtaining alignment problem information; generating an analysis report according to the alignment problem information. By extracting source code information for static analysis and combining with dynamically loading byte alignment rules, the efficiency and accuracy of source code byte alignment checking are improved, and the balance between flexibility and accuracy is achieved.

[0036] In addition, additional aspects and advantages of the present invention will be given in part in the following description, become apparent in part from the following description, or be understood through the practice of the present invention. Description of the Drawings

[0037] Figure 1It is an alternative flowchart of a source code byte alignment check method in an embodiment of the present invention.

[0038] Figure 2 It is an alternative flowchart of calculating the first actual memory layout of a data structure in an embodiment of the present invention.

[0039] Figure 3 It is an alternative flowchart of generating an analysis report according to alignment problem information in an embodiment of the present invention. Detailed implementation manners

[0040] The following will clearly and completely describe the concept, specific structure and technical effects of the present invention in combination with embodiments and drawings, so as to fully understand the purpose, solution and effects of the present invention. It should be noted that, without conflict, the embodiments in the present application and the features in the embodiments can be combined with each other.

[0041] It should be noted that, unless otherwise specified, when a certain feature is referred to as "fixed" or "connected" to another feature, it can be directly fixed or connected to the other feature, or indirectly fixed or connected to the other feature. In addition, the up, down, left, right, top, bottom, etc. used in the present invention are only relative to the mutual positional relationship of the components of the present invention in the drawings.

[0042] In addition, unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by those skilled in the technical field of the present invention. The terms used in the description of the present specification are only for describing specific embodiments, rather than for limiting the present invention. The term "and / or" used herein includes any combination of one or more of the related listed items.

[0043] It should be understood that although the terms first, second, third, etc. may be used in the present invention to describe various elements, these elements should not be limited to these terms. These terms are only used to distinguish elements of the same type from each other. For example, without departing from the scope of the present invention, the first element may also be referred to as the second element, and similarly, the second element may also be referred to as the first element.

[0044] Refer to Figures 1 to 3 , in some embodiments, the technical solution of the present invention is a source code byte alignment check method, including but not limited to steps 101 to 106, and each step will be introduced below in turn.

[0045] Step 101: Convert the source code into an abstract syntax tree.

[0046] Specifically, an Abstract Syntax Tree (AST) is a tree - shaped data structure used in computer science to represent the structure of source code. It is a tree - like representation of the abstract syntactic structure of the source code, and each node in each tree represents a structure in the source code.

[0047] In some embodiments, before converting the source code into an abstract syntax tree, the source code byte alignment check method further includes loading the source code file.

[0048] In a specific embodiment, the LoadSourceCode function is used to load and read the content of the source code file.

[0049] In some embodiments, converting the source code into an abstract syntax tree includes: using a lexical analyzer and a syntax analyzer to convert the source code into an abstract syntax tree.

[0050] Specifically, the lexical analyzer is used to convert a character sequence into a word sequence, and the syntax analyzer is used to analyze the syntactic structure of the source code from the word sequence generated by the lexical analyzer and construct an abstract syntax tree that conforms to the syntax rules of the programming language. It can be understood that using a lexical analyzer and a syntax analyzer can improve the efficiency of converting the source code into an abstract syntax tree.

[0051] In a specific embodiment, the ParseSourceCode function is used to parse the source code into an abstract syntax tree.

[0052] In a specific embodiment, Clang's LibTooling or Python's AST module is used to convert the source code into an abstract syntax tree.

[0053] Step 102: Extract data structures according to the abstract syntax tree, and record the member variables and member variable information in the data structures.

[0054] Specifically, data structures include struct and union, etc.

[0055] In a specific embodiment, the ExtractStructures function is used to extract data structures from the abstract syntax tree and record the member variables and member variable information in the data structures.

[0056] Step 103: Load the byte alignment rules of the target platform from the target source.

[0057] In some embodiments, the target source includes one or more combinations of a custom configuration file, compiler default settings, and a predefined multi-platform rule library; loading the byte alignment rules for the target platform from the target source includes: loading the byte alignment rules from one or more combinations of a custom configuration file, compiler default settings, and a predefined multi-platform rule library.

[0058] It can be understood that the compiler includes GCC and Clang. Supporting the loading of byte alignment rules from a custom configuration file or a predefined multi-platform rule library improves flexibility. Providing a flexible predefined multi-platform rule library allows for easy switching between different byte alignment rules to adapt to various development environments.

[0059] In a specific embodiment, the LoadAlignmentRules function is used to load the byte alignment rules for the target platform from the target source.

[0060] Step 104: Traverse the member variables of the data structure and calculate the first actual memory layout of the data structure based on the member variable information and the offset.

[0061] In some embodiments, the member variable information includes the member variable type, the member variable size, and the member variable order.

[0062] Refer to Figure 2 As shown, traversing the member variables of the data structure and calculating the first actual memory layout of the data structure based on the member variable information and the offset includes, but is not limited to, the following steps 201 to 203.

[0063] Step 201: Initialize the offset to 0.

[0064] Step 202: Traverse each member variable of the data structure, calculate the required alignment padding based on the byte alignment rules, the member variable type, the member variable size, and the member variable order, and update the offset to the end position of the current member variable.

[0065] Step 203: Based on the offset, determine whether the data structure conforms to the byte alignment rules. If the data structure does not conform to the byte alignment rules, add trailing padding at the end of the data structure to obtain the first actual memory layout.

[0066] Specifically, the member variable types include char, int, double, etc. The unit of the member variable size is bytes.

[0067] In a specific embodiment, before traversing each member variable of the data structure, it also includes traversing each data structure.

[0068] In a specific embodiment, the CalculatePadding function is used to calculate the required alignment padding for each member variable of the data structure.

[0069] In a specific embodiment, based on the offset, it is determined whether the data structure conforms to the byte alignment rule. If the data structure does not conform to the byte alignment rule, the problem is recorded, and tail padding is added at the end of the data structure.

[0070] In a specific embodiment, the CalculateTailPadding function is used to calculate the number of bytes of the tail padding.

[0071] Step 105: Check whether the first actual memory layout conforms to the byte alignment rule to obtain alignment problem information.

[0072] Specifically, by checking whether the first actual memory layout conforms to the byte alignment rule, alignment problems are found, such as incorrect alignment or unnecessary padding. Also, by parsing the source code to generate an abstract syntax tree and combining the byte alignment rules of the target platform, the first actual memory layout of the data structure can be accurately calculated, covering a wider range of byte alignment problems, including simple padding bytes, complex alignment rules, and cross-platform compatibility issues.

[0073] In a specific embodiment, the rule configuration interface is used to load and obtain the byte alignment rule from the target source. It can be understood that the rule configuration interface can be used to specify the loading and obtaining of the byte alignment rule according to actual needs, enhancing flexibility.

[0074] Step 106: Generate an analysis report based on the alignment problem information.

[0075] In a specific embodiment, before generating an analysis report based on the alignment problem information, the source code byte alignment check method further includes: initializing the analysis report.

[0076] Refer to Figure 3 , in some embodiments, generating an analysis report based on the alignment problem information includes, but is not limited to, the following steps 301 to 302.

[0077] Step 301: Develop a repair plan based on the alignment problem information.

[0078] Step 302: Record the data structure name, member variable list, offset, alignment problem information, and repair plan to obtain the analysis report.

[0079] It can be understood that in addition to providing alignment problem information, the analysis report also provides a corresponding repair plan, reducing the difficulty of repairing the source code, facilitating developers to quickly improve the source code, and improving efficiency. Specifically, the repair plan can be to insert appropriate alignment instructions.

[0080] Specifically, the source code byte alignment checking method uses an open-source development framework, eliminating the need to purchase expensive commercial tools additionally, thus reducing costs.

[0081] In some embodiments, the alignment problem information includes the location of the problem, the type of the problem, and the content of the problem.

[0082] A repair plan is formulated based on the alignment problem information; the data structure name, member variable list, offset, alignment problem information, and repair plan are recorded to obtain an analysis report, including:

[0083] A repair plan is formulated according to the location of the problem, the type of the problem, and the content of the problem, and the data structure name, member variable list, offset, location of the problem, type of the problem, content of the problem, and repair plan are recorded to obtain an analysis report.

[0084] It can be understood that the analysis report provides detailed alignment problem information, namely the location of the problem, the type of the problem, and the content of the problem, facilitating developers to quickly understand the byte alignment problems of the source code and thus improve the source code, enhancing efficiency.

[0085] An application example of the source code byte alignment checking method is as follows:

[0086] The example source code is as follows:

[0087] struct Example {

[0088] char a;

[0089] int b;

[0090] double c;

[0091] };

[0092] The source code is converted into an abstract syntax tree, the data structure is extracted according to the abstract syntax tree, and the member variables and member variable information in the data structure are recorded. The example results are as follows:

[0093] Data structure name: Example

[0094] Member variable list:

[0095] a: type is char, size is 1 byte.

[0096] b: type is int, size is 4 bytes.

[0097] c: type is double, size is 8 bytes.

[0098] The example byte alignment rules are as follows:

[0099] char: 1 byte alignment

[0100] int: 4 byte alignment

[0101] double: 8 byte alignment

[0102] Example of the first actual memory layout calculation process:

[0103] Initial offset: offset = 0

[0104] Member variable a:

[0105] Type is char, size is 1 byte.

[0106] Alignment required is 1 byte, no padding needed.

[0107] Update offset: offset = offset + 1 = 1

[0108] Member variable b:

[0109] Type is int, size is 4 bytes.

[0110] Alignment required is 4 bytes, padding 3 bytes.

[0111] Update offset: offset = offset + padding + size = 1 + 3 + 4 = 8

[0112] Member variable c:

[0113] Type is double, size is 8 bytes.

[0114] Alignment required is 8 bytes, no padding needed.

[0115] Update offset: offset = offset + size = 8 + 8 = 16

[0116] Trailing padding:

[0117] The total size of the data structure is 16 bytes, meeting the alignment rules.

[0118] Example analysis report:

[0119] Byte Alignment Report for struct Example:

[0120] - Member 'a': Offset 0, Size 1 (Aligned)

[0121] - Member 'b': Offset 4, Size 4 (Aligned after 3 bytes of padding)

[0122] - Member 'c': Offset 8, Size 8 (Aligned)

[0123] - Total size: 16 bytes

[0124] Issues Found:

[0125] - Padding added between 'a' and 'b': 3 bytes

[0126] Suggestion: Consider reordering members to minimize padding.

[0127] In some embodiments, after generating an analysis report according to the alignment issue information, the source code byte alignment checking method further includes:

[0128] Based on the byte alignment rules of multiple target platforms, calculate the second actual memory layout of the data structure respectively;

[0129] Check whether the second actual memory layout conforms to the byte alignment rules of multiple target platforms respectively, and obtain the inspection results of multiple target platforms;

[0130] Compare the inspection results of multiple platforms and generate a cross-platform compatibility report.

[0131] It can be understood that providing the comparison function of cross-platform byte alignment rules can help developers identify the differences between different platforms. And supporting multi-platform comparison improves flexibility.

[0132] An example of multi-platform comparison is as follows:

[0133] Check the byte alignment of the following C code on x86 and ARM platforms:

[0134] struct Data {

[0135] short a;

[0136] int b;

[0137] char c;

[0138] };

[0139] Example byte alignment rules are as follows:

[0140] x86 platform:

[0141] short: 2 byte alignment

[0142] int: 4 byte alignment

[0143] char: 1 byte alignment

[0144] ARM platform:

[0145] short: 2 byte alignment

[0146] int: 4 byte alignment

[0147] char: 1 byte alignment

[0148] Example second actual memory layout calculation result:

[0149] x86 platform:

[0150] Member variable a: offset 0, no padding required.

[0151] Member variable b: offset 2, padding 2 bytes.

[0152] Member variable c: offset 8, no padding required.

[0153] Total size: 12 bytes.

[0154] ARM platform:

[0155] Member variable a: offset 0, no padding required.

[0156] Member variable b: offset 2, padding 2 bytes.

[0157] Member variable c: offset 8, no padding required.

[0158] Total size: 12 bytes.

[0159] Example cross-platform compatibility report:

[0160] Cross-Platform Byte Alignment Report for struct Data:

[0161] - Platform x86:

[0162] - Member 'a': Offset 0, Size 2 (Aligned)

[0163] - Member 'b': Offset 4, Size 4 (Aligned after 2 bytes of padding)

[0164] - Member 'c': Offset 8, Size 1 (Aligned)

[0165] - Total size: 12 bytes

[0166] - Platform ARM:

[0167] - Member 'a': Offset 0, Size 2 (Aligned)

[0168] - Member 'b': Offset 4, Size 4 (Aligned after 2 bytes of padding)

[0169] - Member 'c': Offset 8, Size 1 (Aligned)

[0170] - Total size: 12 bytes

[0171] No cross-platform alignment issues detected.

[0172] In some embodiments, after generating an analysis report based on alignment issue information, the source code byte alignment checking method further includes: if the source code has been modified according to the analysis report, only the modified part of the source code is subjected to source code byte alignment checking.

[0173] In a specific embodiment, during the process of source code byte alignment checking, a cache is used to save intermediate results to further improve performance.

[0174] It can be understood that by accelerating the repeated checking process through incremental analysis and cache mechanism, the checking time and resource consumption are reduced, and the development efficiency is improved.

[0175] It can be seen that the source code is converted into an abstract syntax tree, data structures are extracted according to the abstract syntax tree, and member variables and member variable information in the data structures are recorded. The byte alignment rules of the target platform are loaded from the target source. The member variables of the data structure are traversed, and the first actual memory layout of the data structure is calculated according to the member variable information and the offset, and it is checked whether the first actual memory layout conforms to the byte alignment rules to obtain alignment problem information. An analysis report is generated according to the alignment problem information. By extracting source code information for static analysis and combining with dynamically loading byte alignment rules, the efficiency and accuracy of source code byte alignment checking are improved, and a balance between flexibility and accuracy is achieved.

[0176] In a specific embodiment, the OutputReport function is used to output the analysis report or the cross-platform compatibility report to the developer.

[0177] An embodiment of the present invention also provides an electronic device, which includes a memory and a processor. The memory stores a computer program, and when the processor executes the computer program, the above-mentioned method for checking source code byte alignment is implemented. The electronic device can be any intelligent terminal including a computer, etc.

[0178] An embodiment of the present invention also provides a storage medium, which stores a computer program, and when the computer program is executed by a processor, the above-mentioned method for checking source code byte alignment is implemented.

[0179] It should be recognized that the method steps in the embodiments of the present invention can be implemented or implemented by computer hardware, a combination of hardware and software, or computer instructions stored in a non-transitory computer-readable memory. The method can use standard programming techniques. Each program can be implemented in a high-level procedural or object-oriented programming language to communicate with the computer system. However, if necessary, the program can be implemented in assembly or machine language. In any case, the language can be a compiled or interpreted language. In addition, for this purpose, the program can run on a dedicated integrated circuit for programming.

[0180] In addition, the operations of the processes described herein can be performed in any suitable order, unless otherwise indicated herein or otherwise clearly contradicted by the context. The processes described herein (or variations and / or combinations thereof) can be executed under the control of one or more computer systems configured with executable instructions, and can be implemented as code (e.g., executable instructions, one or more computer programs, or one or more applications) that are commonly executed on one or more processors, by hardware, or by a combination thereof. The computer program includes multiple instructions that can be executed by one or more processors.

[0181] Further, the method can be implemented in any type of computing platform operatively connected to a suitable one, including but not limited to personal computers, minicomputers, mainframes, workstations, network or distributed computing environments, separate or integrated computer platforms, or communicating with charged particle tools or other imaging devices, etc. Aspects of the present invention can be implemented in machine-readable code stored on a non-transitory storage medium or device, whether removable or integrated into the computing platform, such as a hard disk, optical read and / or write storage medium, RAM, ROM, etc., such that it can be read by a programmable computer and can be used to configure and operate the computer to perform the processes described herein when the storage medium or device is read by the computer. Additionally, the machine-readable code, or portions thereof, can be transmitted via a wired or wireless network. When such media includes instructions or programs that implement the above-described steps in conjunction with a microprocessor or other data processor, the invention described herein includes these and other different types of non-transitory computer-readable storage media. When programmed according to the methods and techniques of the present invention, the present invention can also include the computer itself.

[0182] A computer program can be applied to input data to perform the functions described herein, thereby transforming the input data to generate output data stored in non-volatile memory. The output information can also be applied to one or more output devices such as a display. In a preferred embodiment of the present invention, the transformed data represents physical and tangible objects, including a specific visual depiction of the physical and tangible objects generated on the display.

[0183] As described above, these are only the preferred embodiments of the present invention. The present invention is not limited to the above-described embodiments. As long as the same means are used to achieve the technical effects of the present invention, any modifications, equivalent replacements, improvements, etc., made within the spirit and principles of the present invention shall be included within the scope of protection of the present invention. Within the scope of protection of the present invention, its technical solutions and / or implementation manners can have various different modifications and variations.

Claims

1. A source code byte alignment checking method, characterized in that: include: Convert source code into an abstract syntax tree; Extracting a data structure according to the abstract syntax tree, and recording member variables and member variable information in the data structure; Use the rule configuration interface to specify the target source according to actual needs, and load the byte alignment rules of the target platform from the target source; Traversing the member variables of the data structure, and calculating a first actual memory layout of the data structure according to the member variable information and the offset; Check whether the first actual memory layout complies with the byte alignment rule, and obtain alignment problem information; generating an analysis report according to the alignment problem information; The member variable information includes member variable type, member variable size and member variable order; Traversing the member variables of the data structure, and calculating a first actual memory layout of the data structure according to the member variable information and the offset, comprising: Initialize the offset to 0; Traversing each member variable of the data structure, calculating the required alignment padding according to the byte alignment rule, the member variable type, the member variable size, and the member variable sequence, and updating the offset to the end position of the current member variable; Determining whether the data structure complies with the byte alignment rule based on the offset, and if the data structure does not comply with the byte alignment rule, adding tail padding at the end of the data structure to obtain the first actual memory layout; The CalculatePadding function is used to calculate the required alignment padding of each member variable of the data structure.

2. A source code byte alignment checking method according to claim 1, characterized in that: The step of converting the source code into an abstract syntax tree includes: The source code is converted into the abstract syntax tree using a lexical analyzer and a syntax analyzer.

3. A source code byte alignment checking method according to claim 1, characterized in that: The target source includes one or more combinations of a custom configuration file, a compiler default setting, and a predefined multi-platform rule library; The step of loading the byte alignment rule of the target platform from the target source includes: The byte alignment rules are loaded from one or more combinations of the custom configuration file, the compiler default settings, and the predefined multi-platform rule base.

4. A source code byte alignment checking method according to claim 1, characterized in that: Generate an analysis report based on the alignment problem information, including: Formulate a repair plan based on the alignment problem information; The data structure name, the member variable list, the offset, the alignment problem information and the repair solution are recorded to obtain the analysis report.

5. A source code byte alignment checking method according to claim 4, characterized in that: The alignment question information includes the location of the question, the question type and the question content; Formulate a repair plan based on the alignment problem information; Record the data structure name, the member variable list, the offset, the alignment problem information and the repair solution to obtain the analysis report, including: The repair plan is formulated according to the location of the problem, the type of problem and the content of the problem, and the data structure name, the member variable list, the offset, the location of the problem, the type of problem, the content of the problem and the repair plan are recorded to obtain the analysis report.

6. A source code byte alignment checking method according to claim 1, characterized in that: After generating an analysis report according to the alignment problem information, the source code byte alignment checking method further includes: Based on the byte alignment rules of the plurality of target platforms, respectively calculating a second actual memory layout of the data structure; respectively checking whether the second actual memory layout complies with the byte alignment rules of the plurality of target platforms, and obtaining checking results of the plurality of target platforms; Compare the plurality of inspection results and generate a cross-platform compatibility report.

7. A source code byte alignment checking method according to claim 1, characterized in that: After generating an analysis report according to the alignment problem information, the source code byte alignment checking method further includes: If the source code has been modified according to the analysis report, a source code byte alignment check is performed only on the modified portion of the source code.

8. An electronic device, characterized in that: The electronic device includes a memory and a processor, the memory stores a computer program, and the processor implements a source code byte alignment checking method as described in any one of claims 1 to 7 when executing the computer program.

9. A storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, a source code byte alignment checking method according to any one of claims 1 to 7 is implemented.

Citation Information

Patent Citations

  • LLVM-based compiling optimization method and device, equipment and medium

    CN115373689A