Method and device for simultaneously compiling multiple architectures, computer equipment and storage medium
By generating unified intermediate files through a custom linker, the problem of low cross-platform compilation efficiency in traditional compilation methods is solved, achieving the effect of reducing compilation time and saving computing resources.
Patent Information
- Application Number
- CN202511231736.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-08-29
- Publication Date
- 2025-12-19
AI Technical Summary
Traditional software building methods suffer from significant efficiency issues when compiling across platforms, leading to prolonged compilation time and wasted computing resources. This is especially true when the same set of source code needs to build target artifacts for multiple hardware architectures or operating system platforms, requiring the repeated execution of a large number of indiscriminate analysis and transformation operations.
A custom linker is used to parse intermediate files, generate unified intermediate files, and continue compilation on different architectures, reducing the repetitive execution of parsing operations.
By pre-parsing and generating unified intermediate files, compilation time is reduced, computing resources are saved, and compilation efficiency is improved.
Smart Images

Figure CN121166129A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of computer compilation, in particular to a method and device for multi-architecture simultaneous compilation, a computer device and a storage medium. BACKGROUND
[0002] In the traditional software construction process, the main compilation method adopted is to compile each source code file (such as C files) independently. Specifically, each source file will first go through preprocessing, lexical analysis, syntax analysis, semantic analysis and other processing steps to generate corresponding intermediate files. Subsequently, the compiler compiles the intermediate files based on the target hardware architecture to generate object files (usually referred to as O files). These object files are further combined by the linker to resolve symbol references, allocate final addresses, and generate executable files or library files that can be executed on a specific platform.
[0003] However, when the same source code needs to be built for multiple different hardware architectures or operating system platforms, the traditional method has a significant efficiency problem: each compilation for a new architecture needs to completely repeat all the analysis work. This means that when the same set of source code is cross-platform built, a large number of non-discriminatory analysis and transformation operations are repeatedly performed in actual cross-platform compilation practice, resulting in unnecessary computing overhead and energy consumption. As modern software projects continue to grow in size, the number of source files can reach thousands, and this repeated processing results in prolonged compilation time and significant waste of computing resources. SUMMARY
[0004] Therefore, the present application provides a method and device for multi-architecture simultaneous compilation, a computer device and a storage medium to solve the problem of prolonged compilation time and waste of computing resources when the same set of source code is cross-platform built.
[0005] In a first aspect, the present application provides a method for multi-architecture simultaneous compilation, the method comprising:
[0006] determining one or more code files, and compiling each of the code files into a corresponding intermediate file;
[0007] loading each of the generated intermediate files into a custom linker, using the custom linker to resolve each of the intermediate files, and generating a unified intermediate file based on the main function and references obtained from the resolution;
[0008] using the unified intermediate file to continue the compilation in different architectures, and generating different executable files or library files corresponding to the different architectures.
[0009] The method for simultaneous compilation of multiple architectures provided by the embodiment can process the code file input by the user through a custom linker, parse multiple code files, and generate a unified intermediate file by advancing the parsing operation in the compilation process of each architecture. The generated unified intermediate file is then compiled in each architecture to obtain the executable file or library file corresponding to each architecture. By advancing the parsing operation and generating a unified intermediate file, the parsing operation is no longer required to be performed multiple times when the compilation is continued in each architecture, thereby reducing the compilation time and saving computing resources.
[0010] In an optional embodiment, the method comprises:
[0011] determining one or more code files, and compiling each code file into a corresponding intermediate file;
[0012] loading each generated intermediate file into a custom linker, parsing each intermediate file by using the custom linker, and generating a unified intermediate file according to the main function and references obtained by parsing;
[0013] In an optional embodiment, the parsing of each intermediate file by using the custom linker and the generation of a unified intermediate file according to the main function and references obtained by parsing comprise:
[0014] obtaining the data types of each variable according to the variables obtained by parsing the intermediate file; the references comprise variables;
[0015] in the case where there are different data types among the data types of each variable, setting a specified area in the data storage area for storing the variables of the intermediate file; the different data types are data types that differ in specification in different architectures, and the specified area is used to store the variables corresponding to the different data types.
[0016] In an optional embodiment, the parsing of each intermediate file by using the custom linker and the generation of a unified intermediate file according to the main function and references obtained by parsing further comprise:
[0017] finding the main function in the intermediate file by using the custom linker, and storing the main function in a preset code storage area;
[0018] In an optional embodiment, the finding of the main function in the intermediate file by using the custom linker comprises:
[0019] if the intermediate file is used to generate a library file, traversing all external interface functions of the intermediate file, and regarding each external interface function as a corresponding main function.
[0020] determining, by the custom linker, a type corresponding to each of the references in the main function;
[0021] In an optional implementation, the determining, by the custom linker, a type corresponding to each of the references in the main function comprises:
[0022] performing, by the custom linker, line-by-line traversal in the main function;
[0023] for a current line to which the traversal is performed, determining whether content of the current line is a reference, and if so, determining a type corresponding to the reference according to the content of the current line.
[0024] in a case where the type of the reference is a variable, storing the reference to a data storage area; and in a case where the type of the reference is a function, storing the reference to the code storage area;
[0025] In an optional implementation, the storing, in a case where the type of the reference is a variable, the reference to a data storage area; and in a case where the type of the reference is a function, the reference to the code storage area comprises:
[0026] if the type of the reference is a function, determining, in the intermediate file, a function implementation corresponding to the reference, if the function implementation cannot be determined, an exception is reported and the traversal is stopped; if the function implementation can be determined, the function implementation is copied to the code storage area, and the traversal is continued until the main function is traversed completely;
[0027] if the type of the reference is a variable, determining whether the variable has an initial value;
[0028] if the variable has the initial value, storing the variable to a first data storage area, and continuing the traversal until the main function is traversed completely;
[0029] if the variable has no initial value, storing the variable to a second data storage area, and continuing the traversal until the main function is traversed completely; wherein the data storage area comprises the first data storage area and the second data storage area.
[0030] after the traversal of the references in the main function is completed, merging, by the custom linker, the data storage area and the code storage area to generate a unified intermediate file.
[0031] In an optional implementation, the merging, by the custom linker, the data storage area and the code storage area to generate a unified intermediate file comprises:
[0032] establishing a reference table in a preset reference storage area; the reference table including an entry of a function and an entry of a public variable in the variables;
[0033] merging the code storage area, the data storage area and the reference storage area by using the self-defined linker to generate a unified self-defined intermediate file.
[0034] continuing the compilation in different architectures by using the unified intermediate file to generate executable files or library files corresponding to different architectures respectively.
[0035] In the embodiment, the main function is determined by the self-defined linker, that is, the entry of the main function in the intermediate file is determined, and the references in the main function are traversed to ensure that each reference is stored in the unified intermediate file. Then, the references are stored in the data storage area or the code storage area according to the content types of the references, and each reference is stored in a concentrated area by limiting the storage area, which facilitates management and modification. Meanwhile, a reference storage area is preset, and a reference table is established in the reference storage area to store the actual addresses of the public variables in the memory and the actual addresses of the functions in the memory. The reference storage area is merged into the unified intermediate file in the parsing process of the self-defined linker to finally generate a unified intermediate file. In the embodiment, the analysis and conversion operations are performed in advance in the compiling process by establishing the self-defined linker, and the reference table is established, so that the corresponding functions and variables can be located in the compiling process, and the unified intermediate file is generated to continue the compilation in each architecture to finally obtain the executable files or library files corresponding to each architecture, thereby reducing the compiling time and saving the computing resources.
[0036] In a second aspect, the present application provides a device for multi-architecture simultaneous compilation, which comprises:
[0037] a pre-compilation module for determining one or more code files and compiling each code file into a corresponding intermediate file;
[0038] a generation module for loading each generated intermediate file into a self-defined linker, parsing each intermediate file by using the self-defined linker, and generating a unified intermediate file according to the main function and the references obtained by the parsing;
[0039] a compilation module for continuing the compilation in different architectures by using the unified intermediate file to generate executable files or library files corresponding to different architectures respectively.
[0040] In a third aspect, the present application provides a computer device, comprising: a memory and a processor, which are connected with each other in communication, the memory stores computer instructions, and the processor executes the computer instructions to perform the multi-architecture simultaneous compilation method of the first aspect or any of the corresponding embodiments.
[0041] In a fourth aspect, the present application provides a computer readable storage medium, which stores computer instructions for making a computer execute the multi-architecture simultaneous compilation method of the first aspect or any of the corresponding embodiments. BRIEF DESCRIPTION OF DRAWINGS
[0042] In order to more clearly illustrate the specific embodiments of the present application or the technical solutions in the prior art, the drawings needed in the specific embodiments or prior art description will be briefly introduced as follows. Obviously, the drawings in the following description are some embodiments of the present application, and other drawings can be obtained by those skilled in the art without creative labor on the basis of these drawings.
[0043] Figure 1 is a flowchart of a multi-architecture simultaneous compilation method according to an embodiment of the present application;
[0044] Figure 2 is a multi-architecture simultaneous compilation method schematic diagram taking an SSA file as an intermediate file according to an embodiment of the present application;
[0045] Figure 3 is a flowchart of another multi-architecture simultaneous compilation method according to an embodiment of the present application;
[0046] Figure 4 is a flowchart of loading the generated intermediate files into a custom linker, using the custom linker to parse the intermediate files, and generating a unified intermediate file according to the main function and references obtained by parsing according to an embodiment of the present application;
[0047] Figure 5 is a structure schematic diagram of a unified intermediate file according to an embodiment of the present application;
[0048] Figure 6 is a structure block diagram of a multi-architecture simultaneous compilation device according to an embodiment of the present application;
[0049] Figure 7 is a hardware structure schematic diagram of a computer device according to an embodiment of the present application. DETAILED DESCRIPTION
[0050] In order to make the purposes, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be described clearly and completely below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only some of the embodiments of the present application, rather than all the embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative work fall within the scope of protection of the present application.
[0051] Before the embodiments of the present application are described in detail, some terms related to the embodiments will be explained first. The explanations are for the embodiments of the present application to be easier to understand, and should not be regarded as limiting the scope of protection required by the present application.
[0052] (1) Pre-compile: the process of processing pre-processing commands in the code, including macro definition replacement and header file loading.
[0053] (2) Compile: the process of converting code in text form into an architecture-dependent object file. The process of compilation is relatively complex and has many steps.
[0054] (3) Compilation tool chain: a series of tools for compiling code into a platform executable file for each architecture, usually including the compilation tool GCC (GNU Compiler Collection) and the linker, as well as some other debugging auxiliary tools.
[0055] (4) I file: that is, a pre-processed file, a kind of intermediate file in the compilation process, generated from a code file.
[0056] (5) AST file: that is, Abstract Syntax Tree (AST) file, a kind of intermediate file in the compilation process, generated by parsing an I file.
[0057] (6) GIMPLE file: that is, a simplified intermediate representation file, a kind of intermediate file in the compilation process, generated by converting an AST file.
[0058] (7) SSA file: that is, Static Single Assignment (SSA) file, a kind of intermediate file in the compilation process, used to represent the code structure of a program, each variable is assigned only once in the code, generated by converting a GIMPLE file.
[0059] When the same source code needs to build target products for multiple different hardware architectures or operating system platforms, the traditional method has a significant efficiency problem: that is, each compilation for a new architecture needs to completely repeat all the parsing work. This means that when the same set of source code is cross-platform built, a large number of indistinguishable analysis and transformation operations are repeatedly performed in actual cross-platform compilation practice, resulting in unnecessary computing overhead and energy consumption. As modern software projects continue to expand in size, the number of source files can reach thousands, and this repeated processing leads to a significant increase in compilation time and waste of computing resources.
[0060] Embodiments of the present application provide a multi-architecture simultaneous compilation method, which advances the parsing operation in the compilation process by establishing a custom linker, generates a unified intermediate file for subsequent compilation of each architecture, to reduce compilation time and save computing resources. This method does not need to convert code files into executable files under each architecture, but first generates a unified intermediate file suitable for each architecture, and then continues to compile based on the unified intermediate file under each architecture, reducing the processing amount of the intermediate file generation process; and when continuing to compile under each architecture, the parsing operation no longer needs to be performed multiple times, which can improve the compilation efficiency.
[0061] According to the embodiments of the present application, a multi-architecture simultaneous compilation method is provided. It should be noted that the steps shown in the flowchart can be executed in a computer system such as a set of computer executable instructions, and although the logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in a different order than here.
[0062] In this embodiment, a multi-architecture simultaneous compilation method is provided, which can be used in a computer device with a compilation function, Figure 1 is a flowchart of the multi-architecture simultaneous compilation method according to the embodiments of the present application, as Figure 1 shown, the flowchart includes steps S101 to S103.
[0063] Step S101, determine one or more code files, and compile each code file into a corresponding intermediate file.
[0064] When a user compiles multiple architectures using the same to-be-compiled file, one or more code files that need to be compiled can be determined, and the code files can be C files. For each code file, after selecting the code file, the code file is directly compiled, and each code file is processed to convert the code file into a corresponding file, i.e., an intermediate file.
[0065] In the compiling process, various types of intermediate files are generated, and I files, AST files, GIMPLE files and SSA files are generated gradually according to the steps of pre-compiling, lexical analysis, syntax analysis and semantic analysis and code optimization, wherein the I file is the pure text code of the code file expanded all macros and header files, the AST file is the syntax and static semantics parsed in the I file, the GIMPLE file is highly standardized and simplified to the AST file, and the SSA file is further optimized based on the GIMPLE file, and the core is that each variable is assigned only once. In the above process, the intermediate files are not translated into any architecture-related form, so the intermediate files can be directly used by multiple architectures.
[0066] In the embodiment, because the SSA file has a clear dependency relationship, that is, each variable has only one definition, the use-def relationship is very clear, and the SSA is the last step of the compiling process which is independent of the architecture, so in the embodiment, the SSA file is used as an intermediate file in subsequent operations.
[0067] In step S102, the generated various intermediate files are loaded into a custom linker, the various intermediate files are parsed by using the custom linker, and a unified intermediate file is generated according to the main function and the reference obtained by parsing.
[0068] In the embodiment, an additional linker, that is, a custom linker, is set based on actual needs. The principle of the custom linker is similar to that of the linker in each architecture, but does not include the last compiling work, only includes the parsing operation, that is, the symbol parsing and the segment merging operation. By referring to the custom linker in this step, the repeated parsing operation in the linking process of each architecture can be performed in advance.
[0069] Specifically, in the intermediate files such as the SSA file, there are the main function and the reference corresponding to the code file. At this time, the main function and the reference in the intermediate file can be obtained by performing symbol parsing on the obtained intermediate file by using the custom linker, and the main function and the reference are the main contents in the code file.
[0070] In the process of parsing the SSA file, the custom linker is used, which can perform the repeated parsing operation in the linking process of each architecture in advance, and generate a unified intermediate file containing the main function and all references in the intermediate file such as the SSA file which have been parsed. At this time, the number of parsing operations can be reduced when compiling in different architectures subsequently.
[0071] When using related technologies, different architectures parse and link the main function and references according to their respective compilation methods to generate corresponding executable files. In this embodiment, the main functions and references in various intermediate files (such as SSA files) are parsed to generate a unified intermediate file, which is then used by various architectures for subsequent compilation and linking.
[0072] Step S103: Use the unified intermediate file to continue compilation on different architectures to generate executable files or library files corresponding to different architectures.
[0073] After obtaining the unified intermediate file, it can be adapted to various architectures. The operation of this unified intermediate file on each architecture is similar to the operation of intermediate files on different architectures in related technologies. Because the parsing process is brought forward by a custom linker, the obtained unified intermediate file can be directly compiled on various architectures, eliminating the need for parsing.
[0074] By compiling a unified custom intermediate file according to the compilation method corresponding to each architecture across different architectures, target files corresponding to each architecture can be generated. Further linking of these target files yields executable files or library files specific to each architecture. Executable files can be run directly, while library files can be directly called during work or code writing.
[0075] In this embodiment, such as Figure 2 As shown in the example, using an SSA file as an intermediate file, after determining one or more code files (i.e., C files), the compilation process corresponding to this embodiment begins. First, each code file is pre-compiled, lexical analyzed, syntax analyzed, semantically analyzed, and code optimized. Finally, an SSA file corresponding to each code file is generated. Then, each SSA file is parsed to generate a unified SSA file (i.e., a unified intermediate file). At this point, each architecture can compile the unified SSA file to generate an executable file or library file corresponding to each architecture.
[0076] The multi-architecture simultaneous compilation method provided in this embodiment processes the user-input code files through a custom linker, parsing multiple code files. This advances the parsing operations within each architecture's compilation process, generating a unified intermediate file. The generated unified intermediate file is then used for further compilation on each architecture, ultimately yielding the corresponding executable file or library file for each architecture. By advancing the parsing operations and generating a unified intermediate file, multiple parsing operations are no longer required when compiling on different architectures, thus reducing compilation time and saving computational resources.
[0077] In the embodiment, a method for multi-architecture simultaneous compilation is provided, which can be applied to the mobile terminal such as a mobile phone, a tablet computer and the like. Figure 3 The flow chart of the method for multi-architecture simultaneous compilation according to the embodiment of the present application is shown in FIG. 3, which includes steps S301 to S303. Figure 3
[0078] In step S301, one or more code files are determined, and each code file is compiled into a corresponding intermediate file.
[0079] The details of step S101 of the embodiment shown in FIG. 1 are not described herein again. Figure 1
[0080] In step S302, each intermediate file is loaded into a custom linker, each intermediate file is parsed by the custom linker, and a unified intermediate file is generated according to the main function and references obtained by parsing.
[0081] In the parsing process, the main function and references can be determined in the intermediate file such as an SSA file, at this time, the main function and references in the intermediate file can be obtained by symbol parsing of the obtained intermediate file by the custom linker, wherein the references include variables and functions.
[0082] Specifically, the process of "parsing each intermediate file by the custom linker, and generating a unified intermediate file according to the main function and references obtained by parsing" in step S302 can include steps S3021 to S3026.
[0083] In step S3021, the data types of each variable are obtained according to the variables parsed in the intermediate file; the references include variables.
[0084] In the process of parsing the intermediate file, each reference can be obtained, wherein the references include functions and variables, in the process of processing the variables, all defined or declared variables can be extracted from an intermediate file, and the data types (such as integer, floating point, Boolean, array, etc.) of each variable are determined according to the statements of the variable definition and declaration, and it is ensured that this process includes the processing of all variables without omission. Through step S3021, each data type used in the intermediate file can be determined.
[0085] In step S3022, in the case that there are different data types in the data types of each variable, a specified area is set in a data storage area for storing the variables of the intermediate file. The different data types are data types with different specifications in different architectures, and the specified area is used to store the variables corresponding to the different data types.
[0086] In different architectures, due to different CPU architectures or operating systems, some data type specifications are inconsistent in different architectures, and these data types are difference data types. In order to ensure that the intermediate file can be correctly compiled on different architectures, the variables corresponding to the difference data types can be uniformly stored.
[0087] By storing the variables belonging to these difference data types in the data storage area, the variables that may have data type specification differences and the variables that do not have data type specification differences are separated. When each architecture processes the variables in the intermediate file, the data type specification of the specified area can be adjusted by the custom linker without processing the entire data storage area.
[0088] The specifications of the difference data types may be different in different compiler architectures, but in general, they are basically from 8 bits to 64 bits, for example, int and unsigned int, the possible specifications are 16 bits and 32 bits; long and unsigned long, the possible specifications are 32 bits and 64 bits; float, the possible specifications are 32 bits and 64 bits. The specifications of these difference data types can first set a commonly used default specification in the data storage area, that is, for the variables corresponding to these difference data types, the specified position in the data storage area can be stored according to the default specification. When the intermediate file needs to be compiled in a specified architecture, it is first determined whether each difference data type in the architecture linker conforms to each default value set in the data storage area. If there is a difference data type that does not conform to the default value, the custom linker is used to collectively process the difference data type that does not conform to the default value.
[0089] Optionally, a storage area can be constructed, the storage area includes a code storage area and a data storage area, the data storage area can be divided into a first data storage area and a second data storage area, these storage areas are essentially a plurality of files, each storage area corresponds to a storage file, wherein the storage area can further include a reference storage area. The code storage area, the data storage area, and the reference storage area will be described later.
[0090] In step S3023, the main function in the intermediate file is found by the custom linker and stored in the preset code storage area.
[0091] In the process of processing the intermediate file, the main function in the intermediate file needs to be found by the custom linker. In this embodiment, the main function in the intermediate file is the function named main. In the intermediate file, the main function is the standard entry point of the intermediate file, and other referenced functions or variables should be embodied in the main function or the referenced functions in the main function. Therefore, finding the main function is equivalent to finding all references of the intermediate file.
[0092] When the main function is found, the code segment of the main function in the intermediate file can be determined, all the codes corresponding to the main function can be extracted and copied to a preset code storage area. In this embodiment, the code storage area can be used to store codes, including the main function and the functions referenced in the main function. Through the preset code storage area, all the function-related contents can be stored in a fixed area.
[0093] In some cases, the main function can not be found, in which case the compilation process can be aborted, and "main function not found" can be fed back to the user as a result, so that the user can modify the code file accordingly.
[0094] In some optional embodiments, step S3023 "finding the main function in the intermediate file through the custom linker and storing it in the preset code storage area" includes step a1.
[0095] Step a1, if the intermediate file is used to generate a library file, all external interface functions of the intermediate file are traversed, and each external interface function is regarded as a corresponding main function.
[0096] In the development process, in order to save costs and code reuse, developers can compile some commonly used functions into one or more library files for other code to call. In some code structures, the code file determined by the user can be used to generate a library file. When the compilation target of the code file is a library file, the intermediate file corresponding to the code file is an intermediate file used to generate a library file. It can be understood that the intermediate file traversed refers to the intermediate file used to generate a library file.
[0097] In this embodiment, a library file can provide one or more functions or variables. In the library file, there is no corresponding main function, i.e. step S3023 cannot be executed. In this case, the custom linker can regard the external interface function in the library file as the corresponding main function. In the library file, the entry point of the library function is the external interface function, which is the function provided by the library file for other external programs or codes. Therefore, in this embodiment, the external interface function can be regarded as the corresponding main function, and the external interface function can be stored and traversed subsequently, so that step S3023 can be implemented.
[0098] Step S3024, traversing the references in the main function through the custom linker to determine the types of each reference.
[0099] As mentioned above, in a middle file, the main function is the standard entry point of the middle file, and other referenced functions or variables should be embodied in the main function or the referenced functions in the main function, so in this step, the custom linker traverses the code in the main function line by line, and can find all references, that is, all functions (that is, functions referenced in the main function) and variables. When traversing, the current traversed reference can be determined to correspond to the content type of the reference, and the content type of the reference is judged in the subsequent step, and according to the judgment result, the reference is classified and stored in the corresponding storage area.
[0100] In some optional embodiments, step S3024 "traversing the references in the main function by the custom linker, determining the type corresponding to each reference" includes steps b1 and b2.
[0101] Step b1, traversing the main function line by line by the custom linker.
[0102] The line-by-line traversal of the main function by the custom linker is a process of analyzing each instruction in the code in the main function. In the previous step, the custom linker has determined the main function in the middle file, and at this time, the custom linker can decode and traverse each instruction in the main function.
[0103] Step b2, for the current line traversed, judging whether the content of the current line is a reference, if the content of the current line is a reference, then according to the content of the current line, the type corresponding to the reference is judged.
[0104] In the process of line-by-line traversal of the main function by the custom linker, the custom linker can identify all references of the main function, so for each line in the main function, the custom linker can analyze the content of each line to judge whether the content of the current line is a reference. If the content of the current line is a reference, the type corresponding to the reference of the current line can be judged according to the analysis result of the content of the line.
[0105] In some optional embodiments, step S3024 "traversing the references in the main function by the custom linker, judging the content of the reference and judging and storing the processing according to the content of the reference" can further include:
[0106] Through the line-by-line traversal of the main function by the custom linker, the custom linker can optimize the main function by establishing a flowchart of the main function.
[0107] In this embodiment, the custom linker can identify functions that will not be executed and variables that are not used, which are called dead code in the computer. Deleting the dead code can optimize the storage space and the compilation efficiency.
[0108] In some cases, due to some debugging, logical errors, etc., there may be functions and variables in the intermediate file that will not be executed and will not be used. The custom linker can analyze the instructions when traversing the main function line by line to determine which functions and variables can be accessed from the entry (i.e., the main function). Functions and variables that cannot be accessed are marked as dead code and are deleted.
[0109] In step S3025, if the type of the reference is a variable, the reference is stored in the data storage area; if the type of the reference is a function, the reference is stored in the code storage area.
[0110] As mentioned above, when storing each reference, it needs to be stored in a classified manner, and variables and functions are stored in the data storage area and the code storage area, respectively. Functions, like the main function, are composed of a piece of code, so when storing, it needs to be stored in the corresponding storage area, so that all function-related content can be stored in a fixed storage area, i.e., the code storage area. Similarly, when storing variables, the variables also need to be stored and integrated into a fixed storage area, i.e., the data storage area.
[0111] In some optional embodiments, step S3025 "if the type of the reference is a variable, the reference is stored in the data storage area; if the type of the reference is a function, the reference is stored in the code storage area" includes steps c1 to c4.
[0112] In step c1, if the type of the reference is a function, the implementation of the function is determined in the intermediate file. If the implementation of the function cannot be determined, an exception is reported and the current traversal is stopped. If the implementation of the function is determined, the implementation of the function is copied to the code storage area, and the traversal continues until the main function traversal is completed.
[0113] If the type of the current reference is a function, the specific implementation of the function needs to be determined. When the function is referenced (e.g., when it is referenced by the main function), only the function name and method of the current reference are declared, and the function implementation is implemented in the referenced function. If the referenced function is not declared in the intermediate file or there is no corresponding function implementation in the referenced function, the reference to the function in the main function or the function is an invalid reference, that is, the reference cannot produce any effect. In this case, the current process needs to be terminated, and a message is returned to inform the user that the implementation of the referenced function cannot be determined in the intermediate file.
[0114] If the implementation of the referenced function can be determined, the function is a valid function, and the implementation of the function needs to be copied to the code storage area. In the subsequent compilation process, the reference to this function can also be normally referenced.
[0115] After the implementation of the function is copied to the code storage area, this step is completed, and the traversal of the main function is continued until the traversal of the main function is completed, so that all contents in the main function are copied into the unified intermediate file.
[0116] In step c2, if the type of the reference is a variable, it is determined whether the variable has an initial value.
[0117] As mentioned above, variables can generally be divided into two types, namely variables with initial values and variables without initial values. Therefore, in this step, it is determined whether the variable has an initial value, and the variable is stored according to the determination result.
[0118] In step c3, if the variable has an initial value, the variable is stored in the first data storage area, and the traversal is continued until the traversal of the main function is completed.
[0119] If the variable currently traversed has an initial value, the variable can be stored in the first data storage area, and the variable and the initial value are directly stored. In this embodiment, the first data storage area can be a data segment. After the variable is stored in the first data storage area, this step is completed, and the traversal of the main function is continued until the traversal of the main function is completed, so that all contents in the main function are copied into the unified intermediate file.
[0120] In step c4, if the variable has no initial value, the variable is stored in the second data storage area, and the traversal is continued until the traversal of the main function is completed.
[0121] If the variable currently traversed has no initial value, the variable can be stored in the second data storage area, and the variable is stored. In this embodiment, the second data storage area can be a BSS. After the variable is stored in the second data storage area, this step is completed, and the traversal of the main function is continued until the traversal of the main function is completed, so that all contents in the main function are copied into the unified intermediate file.
[0122] In step S3026, after the traversal of the references in the main function is completed, the data storage area and the code storage area are merged by using the self-defined linker to generate a unified intermediate file.
[0123] When all references of the main function are successfully found and stored, the self-defined linker merges the divided storage areas into a single, continuous, and structured file, that is, a merge segment operation. In the process of the merge segment operation, the files corresponding to the storage areas can be sorted and then merged. The file generated by the merge segment operation is the unified intermediate file. In the unified intermediate file, all functions and variables in the intermediate files are included, and each architecture can perform subsequent compilation on the unified intermediate file.
[0124] In the embodiment, the makefile automatic file construction tool is used for the merging segment operation of the file corresponding to the storage area.
[0125] Figure 4 In an embodiment of the present application, a flowchart about step S302 is shown. First, the custom linker needs to find the main function entry. If the main function entry is not found, an error is prompted to the user and the parsing process is aborted. If the main function entry is found, the main function is copied to the code storage area.
[0126] Then the main function is traversed line by line. First, it is determined whether the line-by-line traversal is completed. If the line-by-line traversal is not completed, it is determined whether the next reference exists, which means whether the referenced function or variable exists. If the next reference does not exist, an error is prompted to the user and the parsing process is aborted. If the next reference exists, the custom linker determines the type of the reference. If the type of the reference is a function, the implementation of the function is copied to the code storage area and it is determined whether the line-by-line traversal is completed. If the type of the reference is a variable, the variable is stored in the data segment or BSS according to whether the variable has an initial value, and it is determined whether the line-by-line traversal is completed. If the line-by-line traversal is completed, the data storage area and the code storage area are merged to generate a unified intermediate file.
[0127] In some optional embodiments, step S3026 "after the traversal of the reference in the main function is completed, the data storage area and the code storage area are merged by the custom linker to generate a unified intermediate file" includes step d1 and step d2.
[0128] Step d1, a reference table is established in the preset reference storage area. The reference table includes the entry of the function and the entry of the public variable in the variable.
[0129] In the embodiment, the reference table can be established in the reference storage area. In the data structure of the reference table, no ordinary program code or data is stored, but auxiliary information for addressing is stored, that is, each item therein is an address, which stores the actual address of the public variable in the memory and the actual address of the function in the memory. The reference table is established to enable all functions and variables to be indirectly accessed through the reference table. The functions and variables only need to know the address of the reference table itself, and then find the target address of the functions and variables in the memory through the reference table, so as to be able to locate the corresponding functions and variables in the compiling process. In the embodiment, a relative addressing table can be established as the reference table.
[0130] Step d2, the code storage area, the data storage area and the reference storage area are merged by the custom linker to generate a unified custom intermediate file.
[0131] When all references of the main function are successfully found and classified, and the reference table is established, the self-defined linker merges the code storage area, the data storage area and the reference storage area to generate a unified intermediate file. In the unified intermediate file, all codes and variables in the intermediate files are included, and the reference table corresponding to each code and variable is also included. In different architectures, the unified intermediate file can be compiled according to the compilation mode corresponding to each architecture.
[0132] In the embodiment, the structure of the unified intermediate file is as shown in Figure 5 In the code storage area, the functions of each intermediate file (SSA file in the embodiment) are stored, for example, SSAfile1.ssa, SSAfile2.ssa to SSAfileN.ssa in Figure 5 represent the functions in N SSA files; the data storage area includes a first data storage area and a second data storage area, i.e., a data segment and a BSS. The data segment stores variables with initial values and the initial values, and the BSS stores variables without initial values; and the reference storage area stores the reference table. In the embodiment, a relative addressing table is used as the reference table. The code storage area, the data storage area and the reference storage area are sorted and merged to obtain the unified intermediate file with the structure as shown in Figure 5
[0133] In step S303, the unified intermediate file is used to continue the compilation in different architectures to generate executable files or library files corresponding to different architectures respectively.
[0134] For details, please refer to step S103 of the embodiment shown in Figure 1 , which will not be described here again.
[0135] In the embodiment, the main function is determined by the self-defined linker, that is, the main function entry of the intermediate file is determined, and the references in the main function are traversed to ensure that each reference is stored in the unified intermediate file. Then, the references are stored in the data storage area or the code storage area according to the content types of the references, so that each reference is stored in a concentrated area in a targeted manner, facilitating management and modification. Meanwhile, a reference storage area is preset, a reference table is established in the reference storage area, the actual address of the public variable in the memory and the actual address of the function in the memory are stored, and the reference storage area is merged into the unified intermediate file in the analysis process of the self-defined linker, so as to finally generate a unified intermediate file. In the embodiment, the analysis and conversion operations are compiled in advance by establishing the self-defined linker, the reference table is established, the corresponding functions and variables can be located in the compilation process, the generated unified intermediate file is continuously compiled in each architecture, and finally the executable files or library files corresponding to each architecture are obtained, so that the compilation time is reduced and the computing resources are saved.
[0136] In the embodiment, a multi-architecture simultaneous compilation device is also provided, which is used to implement the above embodiments and preferred embodiments, and will not be described herein. As used below, the term "module" can be a combination of software and / or hardware that implements a predetermined function. Although the device described in the following embodiments is preferably implemented in software, hardware or a combination of software and hardware is also possible and is contemplated.
[0137] The embodiment provides a multi-architecture simultaneous compilation device, as shown in Figure 6 , comprising:
[0138] The pre-compilation module 601 is configured to determine one or more code files and compile each code file into a corresponding intermediate file.
[0139] The generation module 602 is configured to load each generated intermediate file into a self-defined linker, analyze each intermediate file by using the self-defined linker, and generate a unified intermediate file according to the main function and the references obtained by the analysis.
[0140] The compilation module 603 is configured to continue to compile the unified intermediate file in different architectures to generate executable files or library files corresponding to the different architectures, respectively.
[0141] In some optional embodiments, the generation module 602 comprises:
[0142] The variable analysis unit is configured to obtain the data types of each variable according to the variables obtained by the analysis of the intermediate file.
[0143] The data specification setting unit is configured to set a specified area in a data storage area of a variable used to store an intermediate file when there is a difference data type in the data type of each variable. The difference data type is a data type with a specification difference in different architectures, and the specified area is used to store a variable corresponding to the difference data type.
[0144] In some optional embodiments, the generating module 602 comprises:
[0145] The main function storage unit is configured to find a main function in the intermediate file through the custom linker and store the main function in a preset code storage area.
[0146] The reference judgment unit is configured to traverse the references in the main function through the custom linker, determine the type of the references in the main function, and judge the type of the references according to the content of the references.
[0147] The reference storage unit is configured to store the references in the data storage area when the type of the references is a variable, and store the references in the code storage area when the type of the references is a function.
[0148] The intermediate file merging unit is configured to merge the data storage area and the code storage area through the custom linker to generate a unified intermediate file after the traversal of the references in the main function is completed.
[0149] In some optional embodiments, the main function storage unit comprises:
[0150] The library file storage subunit is configured to, if the intermediate file is used to generate a library file, traverse all external interface functions of the intermediate file, and regard each external interface function as a corresponding main function.
[0151] In some optional embodiments, the reference judgment unit comprises:
[0152] The main function traversal subunit is configured to perform line-by-line traversal in the main function through the custom linker.
[0153] The reference type judgment subunit is configured to, for a current line reached in the traversal, judge whether the content of the current line is a reference, and if the content of the current line is a reference, continue to judge the type of the reference according to the content of the current line.
[0154] In some optional embodiments, the reference storage unit comprises:
[0155] If the type of the reference is a function, the function storage subunit determines the function implementation corresponding to the reference in the intermediate file, and if the function implementation cannot be determined, an exception is reported and the current iteration is stopped; if the function implementation can be determined, the function implementation is copied to the code storage area, and the iteration is continued until the main function iteration is completed.
[0156] The variable initial value judgment subunit judges whether the variable has an initial value if the type of the reference is a variable.
[0157] The variable with initial value storage subunit stores the variable with an initial value in the first data storage area, and the iteration is continued until the main function iteration is completed.
[0158] The variable without initial value storage subunit stores the variable without an initial value in the second data storage area, and the iteration is continued until the main function iteration is completed.
[0159] In some optional embodiments, the intermediate file merging unit includes:
[0160] The reference storage subunit establishes a reference table in a preset reference storage area; the reference table includes the entry of a function and the entry of a public variable in the variable.
[0161] The storage merging subunit merges the code storage area, the data storage area and the reference storage area by using the self-defined linker to generate a unified self-defined intermediate file.
[0162] Further function descriptions of the above-mentioned modules and units are the same as those of the corresponding embodiments, and will not be repeated here.
[0163] The multi-architecture simultaneous compiling device in the embodiment is in the form of a functional unit, and the unit refers to an ASIC (Application Specific Integrated Circuit) circuit, a processor and a memory executing one or more software or fixed programs, and / or other devices that can provide the above functions.
[0164] The embodiment of the application further provides a computer device having the multi-architecture simultaneous compiling device shown in the above Figure 6 .
[0165] Please refer to Figure 7 , Figure 7 is a structural schematic diagram of a computer device provided by an optional embodiment of the application, as Figure 7As shown, the computer device includes one or more processors 10, memory 20, and interfaces 30 for external devices such as a keyboard and a mouse and a disk drive. One or more of the interfaces 30 enable a user to interact with the computer device. In some embodiments, the interface 30 also includes an input device, such as a microphone, or output device, such as a speaker. Figure 7 The processor 10 is used in the description as an example.
[0166] The processor 10 can be a central processing unit, a network processor, or a combination thereof. The processor 10 can further include a hardware chip. The hardware chip can be an application specific integrated circuit, a programmable logic device, or a combination thereof. The programmable logic device can be a complex programmable logic device, a field programmable logic device, a general array logic, or any combination thereof.
[0167] The memory 20 stores instructions that can be executed by the at least one processor 10 to cause the at least one processor 10 to perform the methods described in the above embodiments.
[0168] The memory 20 can include a program storage area and a data storage area. The program storage area can store an operating system, application programs, and the like for use by the at least one processor 10. The data storage area can store data created by the computer device, as well as data received by the computer device. The memory 20 can include a cache memory (not shown) for the at least one processor 10, as well as a RAM and a ROM. The memory 20 can also include a non-volatile memory, such as a magnetic disk or an optical disk, for example. The memory 20 can include a combination of cache memory, a RAM, a ROM, and the non-volatile memory. In some embodiments, the memory 20 can include a remote-proximate memory, which can be connected to the computer device through a network. Examples of the network include, but are not limited to, the Internet, an intranet, an extranet, a local area network, a wide area network, a metropolitan area network, a personal area network, a campus area network, a space area network, a terrestrial network, a wireless network, a global network such as the Internet, a private network such as an enterprise intranet, a local network such as a LAN, a cellular network, a satellite network, a home network, a personal area network, and the like, or a combination thereof.
[0169] The memory 20 can include a volatile memory, such as a RAM, for example. The memory 20 can also include a non-volatile memory, such as a flash memory, a hard disk, or a solid-state drive, for example. The memory 20 can also include a combination of the above-mentioned types of memories.
[0170] The computer device also includes an input device 30 and an output device 40. The processor 10, the memory 20, the input device 30 and the output device 40 can be connected by a bus or other means, Figure 7 The bus connection is taken as an example.
[0171] The input device 30 can receive inputted digital or character information, and generate key signal input related to user settings and function control of the computer device, such as a touch screen, a keypad, a mouse, a trackpad, a touchpad, a pointing stick, one or more mouse buttons, a trackball, a joystick, etc. The output device 40 can include a display device, an auxiliary lighting device (e.g., an LED), a tactile feedback device (e.g., a vibration motor), etc. The display device includes but is not limited to a liquid crystal display, a light-emitting diode, a display, and a plasma display. In some optional embodiments, the display device can be a touch screen.
[0172] The embodiments of the present application also provide a computer readable storage medium, and the method according to the embodiments of the present application can be implemented in hardware, firmware, or recorded in a storage medium, or stored in a remote storage medium or a non-transitory machine readable storage medium downloaded through a network and stored in a local storage medium, so that the method described herein can be processed by such software on a storage medium using a general purpose computer, a special purpose processor, or programmable or special hardware. Among them, the storage medium can be a magnetic disk, an optical disk, a read-only memory, a random access memory, a flash memory, a hard disk or a solid state disk, etc.; further, the storage medium can also include a combination of the above types of memories. It can be understood that the computer, processor, microprocessor controller or programmable hardware includes a storage component that can store or receive software or computer code, which, when accessed and executed by the computer, processor or hardware, implements the method shown in the above embodiments.
[0173] Part of the present application can be applied as a computer program product, for example, computer program instructions, when executed by a computer, the operation of the computer can invoke or provide the method and / or technical solutions according to the present application. Those skilled in the art should understand that the form of computer program instructions in computer readable medium includes but is not limited to source file, executable file, installation package file, etc., and accordingly, the way of computer program instructions executed by computer includes but is not limited to: the computer directly executes the instructions, or the computer executes the corresponding compiled program after compiling the instructions, or the computer reads and executes the instructions, or the computer reads and installs the instructions and then executes the corresponding installed program. Here, the computer readable medium can be any available computer readable storage medium or communication medium accessible to the computer.
[0174] While embodiments of the application have been described in connection with the preferred embodiments of the various figures, those of ordinary skill in the art will appreciate that various modifications and changes can be made without departing from the spirit and scope of the application, and that such modifications and changes fall within the scope of the appended claims.
Claims
1. A method for simultaneous compilation across multiple architectures, characterized in that, The method includes: Identify one or more code files, and compile each of the code files into a corresponding intermediate file; Load the generated intermediate files into a custom linker, parse the intermediate files using the custom linker, and generate a unified intermediate file based on the parsed main function and references. The unified intermediate file is used to continue compilation on different architectures, generating executable files or library files corresponding to different architectures.
2. The method according to claim 1, characterized in that, The step of using the custom linker to parse each of the intermediate files and generating a unified intermediate file based on the parsed main function and references includes: Based on the variables parsed from the intermediate file, the data type of each variable is obtained; the reference includes variables; In the case where there are different data types among the various variables, a designated area is set in the data storage area for storing the variables of the intermediate file; the different data types are data types with different specifications in different architectures, and the designated area is used to store the variables corresponding to the different data types.
3. The method according to claim 1, characterized in that, The step of using the custom linker to parse each of the intermediate files and generating a unified intermediate file based on the parsed main function and references also includes: The custom linker locates the main function in the intermediate file and stores it in a preset code storage area. The type of each reference is determined by traversing the references in the main function using the custom linker. If the type of the reference is a variable, the reference is stored in the data storage area; if the type of the reference is a function, the reference is stored in the code storage area. After the reference traversal in the main function is completed, the custom linker is used to merge the data storage area and the code storage area to generate a unified intermediate file.
4. The method according to claim 3, characterized in that, The step of finding the main function in the intermediate file using the custom linker includes: If the intermediate file is used to generate a library file, then all external interface functions of the intermediate file are traversed, and each external interface function is regarded as the corresponding main function.
5. The method according to claim 3, characterized in that, The step of traversing the references in the main function using the custom linker to determine the type of each reference includes: The custom linker is used to iterate line by line in the main function; For the current line encountered during iteration, determine whether the content of the current line is a reference. If the content of the current line is a reference, then continue to determine the type of the reference based on the content of the current line.
6. The method according to claim 3, characterized in that, When the type of the reference is a variable, storing the reference in the data storage area; when the type of the reference is a function, storing the reference in the code storage area, includes: If the referenced type is a function, then in the intermediate file, the function implementation corresponding to the reference is determined. If the function implementation cannot be determined, an exception is reported and the current traversal is stopped. If the function implementation can be determined, then the function implementation is copied to the code storage area, and the traversal continues until the main function traversal is completed. If the type of the reference is a variable, then determine whether the variable has an initial value; If the variable has an initial value, then the variable is stored in the first data storage area, and the traversal continues until the main function completes the traversal; If the variable has no initial value, the variable is stored in the second data storage area, and the traversal continues until the main function completes the traversal; wherein the data storage area includes the first data storage area and the second data storage area.
7. The method according to claim 3, characterized in that, The step of merging the data storage area and the code storage area using the custom linker to generate a unified intermediate file includes: A reference table is established in a preset reference storage area; the reference table includes the entry point of the function and the entry point of the public variables in the variables; The custom linker is used to merge the code storage area, the data storage area, and the reference storage area to generate a unified custom intermediate file.
8. An apparatus for simultaneous compilation across multiple architectures, characterized in that, The device includes: The pre-compilation module is used to identify one or more code files and compile each code file into a corresponding intermediate file. The generation module is used to load the generated intermediate files into the custom linker, parse the intermediate files using the custom linker, and generate a unified intermediate file based on the main function and references obtained from the parsing. The compilation module is used to continue compilation on different architectures using a unified intermediate file, generating executable files or library files corresponding to different architectures.
9. A computer device, characterized in that, include: A memory and a processor, the memory and the processor being communicatively connected to each other, the memory storing computer instructions, the processor executing the computer instructions to perform the method of simultaneous compilation of multiple architectures as described in any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions for causing a computer to perform the method of simultaneous compilation of multiple architectures as described in any one of claims 1 to 7.
