A dynamic library generation method and device
By analyzing and modifying the object code, code that conforms to the dynamic library format is automatically generated, which solves the problem of low efficiency in manual code modification in the existing technology, and realizes efficient and reliable dynamic library generation, which is suitable for complex algorithms and multi-threaded environments.
Patent Information
- Application Number
- CN202111401467.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-19
- Publication Date
- 2024-11-26
- Estimated Expiration
- 2041-11-19
AI Technical Summary
The existing dynamic library generation method requires manual code modification, which is inefficient and error-prone, especially in the development of complex algorithms, especially in the cloud multi-threaded environment, the use of global variables will cause the code to not meet the requirements of the dynamic library, resulting in the generation of dynamic libraries. Inefficient and poor reliability.
By obtaining the object code, analyzing its structure, modifying it according to the set format of the dynamic library, generating code that conforms to the dynamic library format, automating the dynamic library generation process, avoiding manual modification, and improving efficiency.
Automatic dynamic library generation is realized, reducing the steps of manual modification, improving the generation efficiency, ensuring that the code meets the requirements of the dynamic library, reducing the error rate, and is suitable for multi-threaded environments.
Smart Images

Figure CN114064114B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a method and device for generating a dynamic library. Background Art
[0002] In a program, a library represents a pre-compiled, reusable compiled function. The reason for using a library in a program is that functions can be conveniently used when they are used repeatedly, the specific implementation of the function can be hidden when the function is distributed in the form of a library, and the pre-compiled function can be used as needed, thereby facilitating its maintenance.
[0003] Libraries are classified into static libraries and dynamic libraries. Static libraries are included in the target file of the application during the program compilation process, while dynamic libraries are included in the target file during the computer program execution process. The static library is combined with the object of the application during the compilation process to form an executable file. On the contrary, the dynamic library separates the functions required by various programs from the application program, and only loads the function into the memory when it is called during operation. Since the static library is combined with the object of the application program during the compilation process, the size of the executable file increases due to the inclusion of a large number of static libraries in the program. When multiple applications using the same static library are executed simultaneously, the same code will be loaded into the memory, and it is therefore difficult to efficiently utilize the memory. However, when using a dynamic library, since multiple applications share and use a dynamic library, the memory can be efficiently utilized.
[0004] Therefore, a more reliable dynamic library generation solution needs to be provided. Summary of the invention
[0005] The embodiments of the present specification provide a dynamic library generation method and device to solve the problems of the existing dynamic library generation method that the code needs to be manually modified and the dynamic library generation efficiency is low.
[0006] To solve the above technical problems, the embodiments of this specification are implemented as follows:
[0007] A method for generating a dynamic library provided in an embodiment of the present specification is characterized by comprising:
[0008] Obtain the target code as the basic data for generating a dynamic library;
[0009] Parsing the target code to obtain a code structure of the target code;
[0010] Modifying the target code according to the set format of the dynamic library to obtain a modified target code;
[0011] The modified target code is used to generate a dynamic library according to preset rules.
[0012] The embodiment of this specification provides a dynamic library generation device, including:
[0013] The target code acquisition module is used to acquire the target code as the basic data for generating the dynamic library;
[0014] A code structure analysis module, used for analyzing the target code to obtain the code structure of the target code;
[0015] An object code modification module, used to modify the object code according to the set format of the dynamic library to obtain a modified object code;
[0016] The dynamic library generation module is used to generate a dynamic library according to preset rules using the modified target code.
[0017] At least one embodiment of the present specification can achieve the following beneficial effects: by obtaining the target code as the basic data for generating a dynamic library; parsing the target code to obtain the code structure of the target code; modifying the target code according to the set format of the dynamic library to obtain the modified target code; and generating the dynamic library with the modified target code according to the preset rules. The method can automatically modify the target code as the basic data for generating a dynamic library to a code that meets the dynamic library generation format, without the need for the user to manually modify the target code, thereby quickly generating the corresponding dynamic library and improving the generation efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] In order to more clearly illustrate the embodiments of this specification or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in this application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0019] Figure 1 This is a schematic diagram of the overall solution flow of a dynamic library generation method in an embodiment of this specification;
[0020] Figure 2 A schematic diagram of the structure of a dynamic library generation device provided in an embodiment of this specification. DETAILED DESCRIPTION
[0021] In order to make the purpose, technical solutions and advantages of one or more embodiments of this specification clearer, the technical solutions of one or more embodiments of this specification will be clearly and completely described below in combination with the specific embodiments of this specification and the corresponding drawings. Obviously, the described embodiments are only part of the embodiments of this specification, not all of the embodiments. Based on the embodiments in this specification, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of one or more embodiments of this specification.
[0022] The technical solutions provided by the embodiments of this specification are described in detail below in conjunction with the accompanying drawings.
[0023] The existing algorithms are manually written C / C++ projects or C / C++ projects generated by some tool software. In actual applications, some codes do not meet the requirements of dynamic libraries and cannot be directly generated. For example, the main function may be a simulation operation rather than the main algorithm function, and the algorithm input and output variables are all global variables. The state of each calculation is cached through global variables. For example: It is an advantageous way to run the networked autonomous driving algorithm on the cloud platform through dynamic library calls. However, there are many autonomous driving decision and control algorithm development platforms. When the developed algorithm is generated into a dynamic library, its code itself may not meet the requirements of the dynamic library for the code. For example, the cloud needs to be used in multiple threads, and global variables cannot be used in the generated dynamic library code. Generating these algorithms into dynamic libraries usually requires manual code modification, which results in that for complex algorithms, the code volume is large, the function call relationship is complex, manual modification is time-consuming and labor-intensive, and the modification must be repeated every time, and it is extremely easy to make mistakes during the modification process. It is not easy to find errors after the error, which has a great adverse effect on the efficiency of R&D iteration and repeated testing.
[0024] In order to solve the defects in the prior art, this solution provides the following embodiments:
[0025] Figure 1 The following is a schematic diagram of the overall solution flow of a dynamic library generation method in an embodiment of this specification. From a program perspective, the execution subject of the process can be a program or application client installed on an application server. In an embodiment of this specification, the execution subject can be a program installed on an application server for generating a dynamic library.
[0026] like Figure 1 As shown, the process may include the following steps:
[0027] Step 210: Obtain the target code as the basic data for generating the dynamic library.
[0028] A library is essentially a binary form of executable code that can be loaded into memory and executed by the operating system. Libraries can be divided into two types: static libraries (.a, .lib) and dynamic libraries (.so, .dll). The so-called static and dynamic refer to links. When a program needs to run, in addition to the main program itself (EXE file), it also needs to call other files, including some system files of the operating system. DLL is the called file, that is, the dynamic link library file. The dynamic library is not connected to the target code when the program is compiled, but is loaded when the program is running. If different applications call the same library, there is only one instance of the shared library in the memory, avoiding the problem of space waste. The dynamic library is loaded only when the program is running, which also solves the problem that static libraries will cause trouble to the update, deployment and release of the program. Users only need to update the dynamic library. The dynamic library can correspond to a header file, which contains the definition of the data type and the declaration of the function. The source file for making a dynamic library is the implementation of the function, that is, the definition of the function. The name of the dynamic link library is libxxx.so, with the prefix lib and the suffix ".so".
[0029] The target code needs to generate a corresponding dynamic library so that subsequent users can call it at any time.
[0030] Step 220: Parse the target code to obtain the code structure of the target code.
[0031] The parsing process can be understood as the process of identifying each code structure in the code. The program code includes the main custom function name, main file name, custom function, global variables, and global constants. Among them, the main custom function name is the function used when calling the dynamic library, which needs to be exposed to the outside in the form of function declaration. Variables are divided into local and global, and local variables can also be called internal variables. Variables created by an object or a function are usually local variables and can only be referenced internally, but cannot be referenced by other objects or functions. Global variables can be created by an object function or anywhere in this program. Global variables can be referenced by all objects or functions in this program.
[0032] Step 230: modify the target code according to the set format of the dynamic library to obtain a modified target code.
[0033] When generating a dynamic library, there are some set formats, for example: the cloud needs to be used in multiple threads, and global variables cannot be used in the code of the generated dynamic library. Generally speaking, the generated programs are mostly used for simulation, but when actually generating a dynamic library, only the core algorithm needs to be applied. Therefore, some extra functions or other format contents in the code need to be removed.
[0034] Therefore, the target code can be automatically modified according to the set format of the dynamic library, so that the modified target code meets the code format requirements for generating the dynamic library.
[0035] Step 240: Generate a dynamic library based on the modified target code according to preset rules.
[0036] The generating a dynamic library from the modified target code according to a preset rule may specifically include:
[0037] Based on the modified target code, identify the system dynamic library header file statement, add the system dynamic library link command, and compile to generate the dynamic library. Specifically, the generation command is gcc-shared-fPIC all .c files separated by spaces all link library commands separated by spaces -o target .so.
[0038] It should be understood that the order of some steps in the methods described in one or more embodiments of this specification can be interchanged according to actual needs, or some steps can be omitted or deleted.
[0039] Figure 1 The method in the embodiment of the present invention obtains the target code as the basic data for generating a dynamic library; parses the target code to obtain the code structure of the target code; modifies the target code according to the set format of the dynamic library to obtain the modified target code; and generates the dynamic library according to the preset rules. The method can automatically modify the target code as the basic data for generating a dynamic library to a code that meets the dynamic library generation format, without the need for the user to manually modify the target code, thereby quickly generating the corresponding dynamic library and improving the generation efficiency.
[0040] based on Figure 1 The method, the examples of this specification also provide some specific implementation plans of the method, which are described below.
[0041] Optionally, parsing the target code to obtain the code structure of the target code may specifically include:
[0042] Determine the main custom function name and main file name in the target code;
[0043] Based on the main custom function name and the main file name, determine the code file corresponding to the target code;
[0044] For any of the code files, global variables and global constants in the code file are identified, and the global variables and global constants are stored in a database.
[0045] The database may be a list corresponding to the generation of the dynamic library and used to record or store the code structure.
[0046] Identify the main custom function name and main file name in the code. Through the main file name, you can read the header file, identify all referenced project header files, read the code file corresponding to each header file in turn, and further identify all referenced system header files. For system header files, find the corresponding preset command to link its dynamic library during compilation. Specifically, identify the content in include and ignore spaces.
[0047] Read the code files, identify the defined global variables for each file, and store them in a list. The global variable definition is the variable definition outside the function definition after include, and the variable definition can be judged by the format and variable type keywords.
[0048] Optionally, parsing the target code to obtain the code structure of the target code may specifically include:
[0049] Identify function declarations or definitions in the code file;
[0050] The function names used in the function declaration or definition are stored in the database.
[0051] Optionally, parsing the target code to obtain the code structure of the target code may specifically include:
[0052] Identify custom functions in the code file;
[0053] A call to a custom function in the custom function is determined.
[0054] Optionally, after determining the corresponding calling function in the user-defined function, the following method may also be included:
[0055] Determine the calls to custom functions in all corresponding code files;
[0056] Based on the custom function calls of all the code files, a function call relationship graph is generated, and the function call relationship graph is stored in the database.
[0057] The call relationship graph can include the call relationship between each function in the target code, so as to understand the correlation between each function.
[0058] Specifically, the code files are read, and for each file, the function declaration is identified, the function name is stored, and in the function definition, the call to the custom function in the code is identified, the custom function used is found according to the main function definition, the custom function used is found in these custom functions, and so on, to generate a call relationship graph between functions.
[0059] Optionally, the recognition of function declaration can be realized through the format, including the return variable type or the void flag of no return value, the function name, and the input variable type separated by commas in parentheses; the function definition recognition finds the curly braces based on the function declaration to determine the calling relationship; the function call is the function name plus the parentheses and the input parameters therein. Optionally, the target code is modified according to the set format of the dynamic library to obtain the modified target code, which can specifically include:
[0060] The global variables used by the custom function are modified to the function input parameters in the function declaration and definition, and the call statement of the original global variables in the function definition is modified according to the input parameter form;
[0061] Determine the target function that calls the user-defined function according to the call relationship graph;
[0062] Modify the corresponding statement for calling the user-defined function in the target function definition into the function call statement in the new parameter transfer form to obtain the modified code;
[0063] The global constant definition is added to the user-defined function using the global constant in the modified code as a local constant to obtain a modified target code.
[0064] Optionally, if a global variable is used as a function parameter in the modification process, if it is passed in pointer form and the global variable is a structure, then when calling the variable in the original global variable structure in the function definition, the "." should be changed to "->".
[0065] Optionally, the modified target code may include a header file reference of the target code serving as basic data for generating a dynamic library, variable and structure type definitions, a main function declaration of the modified target code, and a calling function declaration.
[0066] Read the code file, for each function, in its function definition, identify the global variables used in it, rewrite them as pointer type function parameters, and rewrite the global variables used in the function definition as pointers. According to the call relationship graph, for other functions that call this function, rewrite the function call statement and add the corresponding pointer type global variable parameter passing.
[0067] Function calls may be nested, that is, the parameter of one function is the return value of another function, so it is necessary to ignore line breaks and use bracket matching to identify them.
[0068] Create a new version file for each code file and header file. The new version text can be determined as the modified target code. The new version code file contains the original code file header file reference, global constant definition, and the declaration and definition of the function in the call relationship diagram after the above modification. The new version header file contains the header file reference, variable and structure type definition of the original header file, the main function declaration that meets the requirements of dynamic library generation, and the original other function declarations. Associate all program files, identify the system dynamic library header file statement, add the system dynamic library link command, and compile to generate the dynamic library.
[0069] Optionally, for C++ projects written in an object-oriented manner, each function may be a member function, so when writing a new version of the code file, retain the class definition and define the selected function in the class to achieve similar automatic adjustment of the structure.
[0070] The above method establishes a call relationship diagram by predetermining the main function and identifying function calls; converts global variables into pointer parameter transfer modifications; extracts useful code and generates a dynamic library for the new version of the file; the code format is standardized, there are no global variables, and it can be used for multi-threading; and it automatically identifies variables, functions, and calls, and has strong adaptability to code formats. Only the main custom function name needs to be entered, and it can be operated with one click. It is easy to use and the dynamic library generation efficiency is high.
[0071] Based on the same idea, the embodiments of this specification also provide a device corresponding to the above method. Figure 2 This is a schematic diagram of the structure of a dynamic library generation device provided in the embodiment of this specification. Figure 2 As shown, the device may include:
[0072] The target code acquisition module 210 is used to acquire the target code as the basic data for generating the dynamic library;
[0073] A code structure analysis module 220 is used to analyze the target code to obtain the code structure of the target code;
[0074] The target code modification module 230 is used to modify the target code according to the set format of the dynamic library to obtain a modified target code;
[0075] The dynamic library generation module 240 is used to generate a dynamic library according to preset rules using the modified target code.
[0076] based on Figure 2 The present specification also provides some specific implementation schemes of the device, which are described below.
[0077] Optionally, the code structure may include at least a main custom function name, a main file name, a calling function, global variables, and global constants.
[0078] Optionally, the code structure parsing module 220 may specifically include:
[0079] A main user-defined function name and main file name determining unit, used to determine the main user-defined function name and main file name in the target code;
[0080] A code file determining unit, used for determining a code file corresponding to the target code based on the user-defined function name and the main file name;
[0081] The global variable and global constant identification unit is used to identify the global variables and global constants in any one of the code files, and store the global variables and global constants in a database.
[0082] Optionally, the code structure parsing module 220 may specifically include:
[0083] A function declaration identification unit, used for identifying a function declaration or definition in the code file;
[0084] The function name storage unit is used to store the function name used in the function declaration or definition in the database.
[0085] Optionally, the code structure parsing module 220 may specifically include:
[0086] A user-defined function identification unit, used for identifying the user-defined function in the code file;
[0087] The calling function determining unit is used to determine the calling of the user-defined function in the user-defined function.
[0088] Optionally, the code structure parsing module 220 may also be used to:
[0089] Determine the calls to custom functions in all corresponding code files;
[0090] Based on the custom function calls of all the code files, a function call relationship graph is generated, and the function call relationship graph is stored in the database.
[0091] Optionally, the target code modification module 230 may specifically include:
[0092] The global variable modification unit is used to modify the global variables used by the custom function to the function input parameters in the function declaration and definition, and to modify the original global variable call statement in the function definition according to the input parameter form;
[0093] A target function determination unit, which determines a target function for calling the user-defined function according to the call relationship graph;
[0094] A calling statement modification unit, used for modifying the corresponding statement for calling the user-defined function in the target function definition into a function calling statement in the new parameter transfer form, to obtain a modified code;
[0095] The target code modification unit is used to add the global constant definition to the user-defined function using the global constant in the modified code as a local constant to obtain the modified target code.
[0096] Optionally, the dynamic library generation module 240 may specifically include:
[0097] The dynamic library generation unit is used to identify the system dynamic library header file statement based on the modified target code, add the system dynamic library link command, and compile and generate the dynamic library.
[0098] Optionally, the modified target code may include a header file reference of the target code serving as basic data for generating a dynamic library, variable and structure type definitions, a main function declaration of the modified target code, and a calling function declaration.
[0099] In this embodiment, the target code as the basic data for generating a dynamic library is obtained; the target code is parsed to obtain the code structure of the target code; the target code is modified according to the set format of the dynamic library to obtain the modified target code; and the modified target code is used to generate a dynamic library according to preset rules. This method can automatically modify the target code as the basic data for generating a dynamic library into a code that meets the dynamic library generation format, without the need for the user to manually modify the target code, thereby quickly generating the corresponding dynamic library and improving generation efficiency.
[0100] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0101] In the 1990s, improvements to a technology could be clearly distinguished as hardware improvements (for example, improvements to the circuit structure of diodes, transistors, switches, etc.) or software improvements (improvements to the method flow). However, with the development of technology, many improvements to the method flow today can be regarded as direct improvements to the hardware circuit structure. Designers almost always obtain the corresponding hardware circuit structure by programming the improved method flow into the hardware circuit. Therefore, it cannot be said that an improvement in a method flow cannot be implemented using a hardware entity module. For example, a programmable logic device (PLD) (such as a field programmable gate array (FPGA)) is such an integrated circuit whose logical function is determined by the user's programming of the device. Designers can "integrate" a digital system on a PLD by programming themselves, without having to ask a chip manufacturer to design and produce a dedicated integrated circuit chip. Moreover, nowadays, instead of manually making integrated circuit chips, this kind of programming is mostly implemented by "logic compiler" software, which is similar to the software compiler used when developing and writing programs, and the original code before compilation must also be written in a specific programming language, which is called hardware description language (HDL). There is not only one HDL, but many kinds, such as ABEL (Advanced Boolean Expression Language), AHDL (Altera Hardware Description Language), Confluence, CUPL (Cornell University Programming Language), HDCal, JHDL (Java Hardware Description Language), Lava, Lola, MyHDL, PALASM, RHDL (Ruby Hardware Description Language), etc. The most commonly used ones are VHDL (Very-High-Speed Integrated Circuit Hardware Description Language) and Verilog. Those skilled in the art should also know that it is only necessary to program the method flow slightly in the above-mentioned hardware description languages and program it into the integrated circuit, and then it is easy to obtain the hardware circuit that implements the logic method flow.
[0102] The controller can be implemented in any appropriate manner, for example, the controller can take the form of a microprocessor or processor and a computer-readable medium storing a computer-readable program code (such as software or firmware) that can be executed by the (micro)processor, a logic gate, a switch, an application-specific integrated circuit (ASIC), a programmable logic controller, and an embedded microcontroller. Examples of controllers include, but are not limited to, the following microcontrollers: ARC625D, AtmelAT91SAM, Microchip PIC18F26K20, and Silicone Labs C8051F320. The memory controller can also be implemented as part of the control logic of the memory. Those skilled in the art also know that in addition to implementing the controller in a purely computer-readable program code manner, the controller can be implemented in the form of a logic gate, a switch, an application-specific integrated circuit, a programmable logic controller, and an embedded microcontroller by logically programming the method steps. Therefore, this controller can be considered as a hardware component, and the devices included therein for implementing various functions can also be regarded as structures within the hardware component. Or even, the devices for implementing various functions can be regarded as both software modules for implementing the method and structures within the hardware component.
[0103] The systems, devices, modules or units described in the above embodiments may be implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a computer. Specifically, the computer may be, for example, a personal computer, a laptop computer, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email device, a game console, a tablet computer, a wearable device, or a combination of any of these devices.
[0104] For the convenience of description, the above device is described in various units according to their functions. Of course, when implementing the present application, the functions of each unit can be implemented in the same or multiple software and / or hardware.
[0105] Those skilled in the art will appreciate that embodiments of the present invention may be provided as methods, systems, or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0106] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0107] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0108] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0109] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0110] The memory may include non-permanent storage in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.
[0111] Computer readable media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. Information can be computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include temporary computer readable media (transitory media), such as modulated data signals and carrier waves.
[0112] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.
[0113] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program code.
[0114] The present application may be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. The present application may also be practiced in distributed computing environments where tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules may be located in local and remote computer storage media, including storage devices.
[0115] The above is only an embodiment of the present application and is not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included in the scope of the claims of the present application.
Claims
1. A method for generating a dynamic library, It is characterized in that include: Obtain the target code as the basic data for generating a dynamic library; Parsing the target code to obtain a code structure of the target code; The method includes: determining the calls of all corresponding code files to the custom function; generating a function call relationship graph based on the custom function calls of all code files, and storing the function call relationship graph in a database; Modifying the target code according to the set format of the dynamic library to obtain a modified target code; Generate a dynamic library based on the modified target code according to preset rules; in: According to the set format of the dynamic library, the target code is modified to obtain the modified target code, including: The global variables used by the custom function are modified to the function input parameters in the function declaration and definition, and the function with the new parameter transfer form is obtained. The call statement of the original global variables in the function definition is modified according to the input parameter form; Determine the target function that calls the user-defined function according to the function call relationship graph; Modify the corresponding statement for calling the user-defined function in the target function definition into a function call statement in the new parameter transfer form to obtain a modified code; Adding the global constant definition to the user-defined function using the global constant in the modified code as a local constant to obtain the modified target code; Generate a dynamic library using the modified target code according to preset rules, specifically including: Based on the modified target code, the system dynamic library header file statement is identified, the system dynamic library link command is added, and the dynamic library is compiled and generated.
2. The method according to claim 1, It is characterized in that The code structure at least includes a main user-defined function name, a main file name, a user-defined function, a global variable, and a global constant.
3. The method according to claim 2, It is characterized in that The parsing of the target code to obtain the code structure of the target code specifically includes: Determine the main custom function name and main file name in the target code; Based on the main custom function name and the main file name, determine the code file corresponding to the target code; For any of the code files, global variables and global constants in the code file are identified, and the global variables and global constants are stored in a database.
4. The method according to claim 3, It is characterized in that The parsing of the target code to obtain the code structure of the target code specifically includes: Identify function declarations or definitions in the code file; The function names used in the function declaration or definition are stored in the database.
5. The method according to claim 1, It is characterized in that The modified target code includes a header file reference of the target code serving as basic data for generating a dynamic library, variable and structure type definitions, and all user-defined function declarations and definitions of the modified target code.
6. A dynamic library generation device, It is characterized in that include: The target code acquisition module is used to acquire the target code as the basic data for generating the dynamic library; A code structure analysis module, used for analyzing the target code to obtain the code structure of the target code; The method includes: determining the calls of all corresponding code files to the custom function; generating a function call relationship graph based on the custom function calls of all code files, and storing the function call relationship graph in a database; An object code modification module, used to modify the object code according to the set format of the dynamic library to obtain a modified object code; A dynamic library generation module, used to generate a dynamic library from the modified target code according to preset rules; in: The target code modification module is specifically used for: modifying the global variables used by the user-defined function to the function input parameters in the function declaration and definition, obtaining the function in the new parameter transfer form, and modifying the original global variable call statement in the function definition according to the input parameter form; determining the target function that calls the user-defined function according to the function call relationship diagram; modifying the corresponding statement that calls the user-defined function in the target function definition to the function call statement in the new parameter transfer form, obtaining the modified code; adding the global constant definition to the user-defined function that uses the global constant in the modified code as a local constant, obtaining the modified target code; The dynamic library generation module is specifically used to: based on the modified target code, identify the system dynamic library header file statement, add the system dynamic library link command, and compile and generate the dynamic library.
