Code migration method and device, electronic equipment and readable storage medium
Through encapsulation and modification interfaces, the code migration on different architectural platforms is realized, which solves the problem of low code migration efficiency in the existing technology and improves development efficiency.
Patent Information
- Application Number
- CN202311134507.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-09-04
- Publication Date
- 2025-03-04
AI Technical Summary
In the prior art, code migration efficiency is low, and developers need to modify inapplicable interfaces one by one, making the process less efficient.
By obtaining the interface in the source code file to be migrated, encapsulate the second interface to generate the target library file of the third interface, modifying the library file in the source code file to be the target library file, and realizing the migration of code on different architectural platforms.
It improves the efficiency of code migration. You only need to modify the library files in the source code file to achieve migration, without modifying the interface one by one, which significantly improves development efficiency.
Smart Images

Figure CN119556980A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of computer technology, and in particular relates to a code migration method, device, electronic device and readable storage medium. Background Art
[0002] In the field of computer technology, developers often need to consider the platform architecture on which the code will run when writing code so that the code can be adapted to the platform architecture on which it will run.
[0003] However, with the development of computer technology, the architecture is constantly updated and iterated. Some interfaces used by the original code are not applicable to the updated architecture. In order to enable the original code to run on the updated architecture and realize code migration, developers are often required to modify the inapplicable interfaces in the original code one by one, which is inefficient. Summary of the invention
[0004] The present invention provides a code migration method, device, electronic device and readable storage medium to solve the problem of low code migration efficiency.
[0005] In order to solve the above-mentioned technical problems, the present invention is achieved as follows:
[0006] In a first aspect, the present invention provides a code migration method, characterized in that the method comprises:
[0007] Acquire a first source code file to be migrated, and acquire a first interface included in the first source code file; the first interface belongs to a calling interface of a first architecture;
[0008] The second interface is encapsulated to generate a target library file containing a third interface; the third interface implements an operation corresponding to the first interface by calling the second interface; the calling information of the third interface is consistent with the calling information of the first interface; the second interface belongs to the calling interface of the second architecture;
[0009] Modify the first library file in the first source code file into the target library file to obtain a first target code file; the first library file is a library file corresponding to the calling interface of the first architecture;
[0010] The first target code file is output to a target platform so that the target platform compiles and executes the first target code file; the target platform is a platform using the second architecture.
[0011] In a second aspect, the present invention provides a code migration device, characterized in that the device comprises:
[0012] An acquisition module, used to acquire a first source code file to be migrated, and acquire a first interface included in the first source code file; the first interface belongs to a calling interface of a first architecture;
[0013] The encapsulation module is used to encapsulate the second interface and generate a target library file containing a third interface; the third interface implements the operation corresponding to the first interface by calling the second interface; the calling information of the third interface is consistent with the calling information of the first interface; the second interface belongs to the calling interface of the second architecture;
[0014] A first modification module is used to modify the first library file in the first source code file into the target library file to obtain a first target code file; the first library file is a library file corresponding to the calling interface of the first architecture;
[0015] The first output module is used to output the first target code file to a target platform so that the target platform compiles and executes the first target code file; the target platform is a platform using the second architecture.
[0016] In a third aspect, the present invention provides an electronic device comprising: a processor, a memory, and a computer program stored in the memory and executable on the processor, wherein the processor implements the above-mentioned code migration method when executing the program.
[0017] In a fourth aspect, the present invention provides a readable storage medium, which, when instructions in the storage medium are executed by a processor of an electronic device, enables the electronic device to execute the above-mentioned code migration method.
[0018] The code migration method provided by the embodiment of the present invention obtains the first source code file to be migrated, and obtains the first interface contained in the first source code file, the first interface belongs to the calling interface of the first architecture, encapsulates the second interface, generates a target library file containing the third interface, the third interface implements the operation corresponding to the first interface by calling the second interface; the calling information of the third interface is consistent with the calling information of the first interface; the second interface belongs to the calling interface of the second architecture, and the target library file containing the third interface is generated by encapsulating the second interface, and the operation of the first interface can be implemented through the second interface by calling the third interface. At the same time, the first library file in the first source code file is modified to the target library file to obtain the first target code file; the first library file is a library file corresponding to the calling interface of the first architecture; the first target code file is output to the target platform so that the target platform compiles and executes the first target code file; the target platform is a platform using the second architecture. Since the first library file in the first target code file is modified into a target library file, and the third interface in the target library file is consistent with the calling information of the first interface, when the source code in the first target code file calls the first interface, it actually calls the third interface in the target library file. The target library file is equivalent to the middle layer, that is, the first target code file implements the operation of the first interface by calling the second interface by calling the third interface. In this way, code migration can be achieved by modifying the first library file in the first source code file, without modifying the first interfaces in the first source code file one by one, thereby improving the efficiency of code migration. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0020] Figure 1 is a flowchart of a code migration method provided by an embodiment of the present invention;
[0021] Figure 2 is a schematic diagram of an interface call in a first source code file;
[0022] Figure 3 It is a schematic diagram of performing an interface call in a first target code file provided by an embodiment of the present invention;
[0023] Figure 4 is a structural diagram of a code migration device provided by an embodiment of the present invention;
[0024] Figure 5 It is a structural diagram of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0025] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0026] Figure 1 is a flowchart of a code migration method provided by an embodiment of the present invention. Figure 1 As shown, the method may include the following steps:
[0027] Step 101: Obtain a first source code file to be migrated, and obtain a first interface included in the first source code file; the first interface belongs to a calling interface of a first architecture.
[0028] Step 102, encapsulate the second interface and generate a target library file containing the third interface; the third interface implements the operation corresponding to the first interface by calling the second interface; the calling information of the third interface is consistent with the calling information of the first interface; the second interface belongs to the calling interface of the second architecture.
[0029] Step 103: modify the first library file in the first source code file into the target library file to obtain a first target code file; the first library file is a library file corresponding to the calling interface of the first architecture.
[0030] Step 104: output the first target code file to a target platform, so that the target platform compiles and executes the first target code file; the target platform is a platform using the second architecture.
[0031] The embodiments of the present invention can be applied to code migration or code transplantation scenarios. Code migration refers to the process of migrating the source code of one architecture to another architecture. The architecture depends on the type of instruction set (such as X86, ARM, etc.) used by the central processing unit (CPU), and the first architecture and the second architecture are different architectures. For example, the first architecture can be X86, and the second architecture can be Loong Arch architecture.
[0032] Among them, the first interface belongs to the calling interface of the first architecture. It should be noted that the code is compiled before running on the platform, and the compilation operation often depends on the compiler. The compilers used in different architectures may be different. Therefore, the calling interface of the first architecture can be the built-in interface (Intrinsic) of the compiler of the first architecture. The Intrinsic function is a built-in function of the compiler, provided by the compiler, and the compiler is closely related to the hardware architecture, so the compiler knows how to use the hardware capabilities to implement these functions in the best way. Intrinsic is also an actual single instruction multiple data (Single Instruction Multiple Data, SIMD) operation interface, which provides convenience for the vector implementation of the program, so it is widely used in algorithm optimization. The calling interface of the first architecture can also be a functional function applicable to the first architecture. Accordingly, the calling interface of the first architecture is applicable to the first architecture, and may cause the code to fail to compile and execute on other architectures different from the first architecture, or the code has poor performance on other architectures. Among them, the second interface belongs to the calling interface of the second architecture, which can be the built-in interface of the compiler of the second architecture, or it can be a functional function applicable to the second architecture.
[0033] Among them, the first source code file refers to the source code file to be migrated. Specifically, the first source code file can be obtained when receiving a code migration request. The code migration request can be triggered by relevant personnel according to actual migration requirements, can be initiated by triggering a specified control, or can be initiated by inputting a corresponding instruction. The embodiment of the present invention does not limit this. The code migration request can include the first source code file to be migrated and the target migration architecture, that is, the second architecture. The first source code file includes a call interface belonging to the first architecture, and the call interface of the first architecture may have problems when compiled and executed on the second architecture, so the first source code file cannot be directly run on the platform of the second architecture. In the embodiment of the present invention, the second interface can be encapsulated to generate a third interface, and the third interface is used to call the second interface to implement the operation corresponding to the first interface. Specifically, the third interface can use the second interface to implement the same operation logic as the first interface, and the call information of the third interface is consistent with the call information of the first interface. The call information includes a call name, input parameters, and output parameters. The call name refers to the name or identifier of the interface. In the code, the call to the interface is implemented by inputting the call information of the interface.
[0034] Specifically, the above-mentioned first interface can be one or more. In the embodiment of the present invention, for any first interface, the second interface corresponding to the first interface can be determined first, wherein the second interface corresponding to the first interface refers to an interface in the calling interface of the second architecture that implements the same operation as the first interface. Exemplarily, there is an interface _mm256_fmadd_ps() for implementing floating-point vector multiplication and addition operations in the X86 architecture, and the corresponding __lasx_xvfmadd_s() in the LoongArch architecture is also used to implement floating-point vector multiplication and addition operations. Therefore, when the first interface is _mm256_fmadd_ps(), the second interface can be determined to be __lasx_xvfmadd_s(). Further, after the second interface is determined, the second interface can be encapsulated to generate a library file containing a third interface. Among them, the encapsulation operation in the above step 102 can be understood as adding a layer of external encapsulation to the second interface, but the internal implementation logic is still implemented through the second interface. Therefore, the encapsulated third interface can be compiled and executed on the second architecture. Exemplarily, the above encapsulation operation can be:
[0035] _mm256_fmadd_ps()
[0036] {
[0037] __lasx_xvfmadd_s()
[0038] }.
[0039] The library file can also be called a header file, which is usually used to store declarations of predefined functions, types, structures, etc., so that other source codes can call them. It should be noted that the library file only contains declarations and definitions, and does not contain specific implementation codes, so as to avoid repeatedly defining the same function interface or variable in the source code.
[0040] Furthermore, the target library file formed by the embodiment of the present invention includes a third interface, and the calling information of the third interface is consistent with the first interface. Therefore, the target library file is equivalent to a restatement of the first interface, by modifying the first library file in the first source code to the target library file, so that when the first interface is called in the first source code, it is actually executed by calling the second interface through the target library file. Specifically, since a source code file may contain multiple header files, the embodiment of the present invention can use the target library file to only replace the original first library file in the first source code file, thereby avoiding the problem of the code not being able to run normally due to modifications to other header files. Exemplarily, taking the first architecture as X86 and the second architecture as LoongArch as an example, the first library file can be<immintrin.h> In the embodiment of the present invention, the target library file containing the third interface can be named "x86ToLaIntrinsics.h", so that the first library file in the first source code file can be deregistered by the deregistration symbol " / / " " / / #include<immintrin.h> " or delete it directly and add the target library file to the library file of the first source code file to include "x86ToLaIntrinsics.h".
[0041] Wherein, the above-mentioned target platform can be any computer device adopting the second architecture. The above-mentioned output operation can be realized by means of a network, a pre-agreed communication protocol or a hardware connection, etc., and the embodiment of the present invention does not limit this. Accordingly, after receiving the first target code file, the above-mentioned target platform will compile and execute it through a compiler. The target platform is a platform adopting the second architecture, and the compiler it adopts is also a compiler related to the second architecture. Further, when the target platform compiles and executes the first target code file, since the first library file in the first target code file is modified to a target library file, and the third interface in the target library file is consistent with the call information of the first interface, when the source code in the first target code file calls the first interface, it is actually the third interface in the target library file that is called. The target library file is equivalent to the middle layer, that is, the first target code file calls the second interface by calling the third interface to realize the operation of the first interface. In this way, only the first library file in the first source code file needs to be modified to realize code migration, without modifying the implementation source code in the first source code file.
[0042] In summary, the embodiment of the present invention obtains the first source code file to be migrated, and obtains the first interface contained in the first source code file, the first interface belongs to the calling interface of the first architecture, encapsulates the second interface, generates a target library file containing the third interface, the third interface implements the operation corresponding to the first interface by calling the second interface; the calling information of the third interface is consistent with the calling information of the first interface; the second interface belongs to the calling interface of the second architecture, and by encapsulating the second interface, a target library file containing the third interface is generated, and the operation of the first interface can be implemented through the second interface by calling the third interface. At the same time, the first library file in the first source code file is modified to the target library file, and the first target code file is obtained; the first library file is a library file corresponding to the calling interface of the first architecture; the first target code file is output to the target platform, so that the target platform compiles and executes the first target code file; the target platform is a platform using the second architecture. Since the first library file in the first target code file is modified into a target library file, and the third interface in the target library file is consistent with the calling information of the first interface, when the source code in the first target code file calls the first interface, it actually calls the third interface in the target library file. The target library file is equivalent to the middle layer, that is, the first target code file implements the operation of the first interface by calling the second interface by calling the third interface. In this way, code migration can be achieved by modifying the first library file in the first source code file, without modifying the first interfaces in the first source code file one by one, thereby improving the efficiency of code migration.
[0043] Optionally, the embodiment of the present invention may specifically include the following steps:
[0044] Step S21: upon receiving a request to migrate a second source code file to the target platform, if a first interface included in the second source code file belongs to a first interface included in the first source code file, modify a first library file in the second source code file to be the target library file to obtain a second target code file.
[0045] Step S22: output the second target code file to the target platform, so that the target platform compiles and executes the second target code file.
[0046] Among them, the above-mentioned second source code file is a source code file different from the above-mentioned first source code file, and the above-mentioned request can be triggered by relevant personnel according to actual migration needs, can be initiated by triggering a specified control, or can be initiated by inputting a corresponding instruction, and the embodiment of the present invention does not limit this. Accordingly, when a migration request for a second source code file is received, the interface contained in the second source code file can be traversed to determine the first interface contained therein. If the first interface contained in the second source code file belongs to the first interface contained in the first source code file, it indicates that the calling interface of the first architecture used in the source code of the second source code file is exactly the same as or partially overlaps with the calling interface of the first architecture used in the first source code file, that is, the calling interface of the first architecture used in the first source code file contains the calling interface of the first architecture used in the source code of the second source code file.
[0047] At this time, since the encapsulated third interface contained in the target library file generated in the aforementioned step can implement the operation of the calling interface of the first architecture used in the first source code file by calling the second interface, and the first interface contained in the second source code file belongs to the first interface contained in the first source code file, that is, for the first interface contained in the second source code file, it can also be implemented by the third interface contained in the target library file. Therefore, the embodiment of the present invention can directly modify the first library file in the second source code file into the above-mentioned target library file to obtain the second target code file. In this way, by outputting the second target code file to the target platform and making the target platform compile and execute the second target code file, the migration of the second source code file can be realized, so that it can be compiled and executed on the target platform using the second architecture.
[0048] In the embodiment of the present invention, when receiving a request to migrate the second source code file to the target platform, if the first interface included in the second source code file belongs to the first interface included in the first source code file, the first library file in the second source code file is modified to the target library file to obtain the second target code file; the second target code file is output to the target platform so that the target platform compiles and executes the second target code file. In this way, the reuse of the target library file can be achieved, and when the first interface used in other source code files belongs to the first interface in the first source code file, there is no need to perform the encapsulation operation again, which can further improve the efficiency of code migration.
[0049] Optionally, the first source code file includes compilation parameters. Before the operation of outputting the first target code file to the target platform, the embodiment of the present invention may further include the following steps:
[0050] S31. Modify the compilation parameters in the first target code file into target parameters; the target parameters are used to indicate that the first target code file is applicable to the compiler of the second architecture.
[0051] The above-mentioned compilation parameters refer to compilation configuration parameters or macro controls, which are usually used to indicate which architecture compilers a source code file is applicable to, and only compilers of the architecture indicated by the compilation parameters can compile the source code file.
[0052] Accordingly, in the case where the first source code file includes compilation parameters, the compilation parameters in the first target code file are still the compilation parameters in the first source code file. Since the compilation parameters of the first source code file are not set for the compiler applicable to the second architecture, if the first target code file is directly output to the target platform, the compiler of the target platform may not be able to compile the first target code file. Therefore, the embodiment of the present invention can modify the compilation parameters in the first target code file before outputting the first target code file to the target platform, and modify it to be a target parameter that can represent the compiler applicable to the second architecture.
[0053] In the embodiment of the present invention, the first source code file includes compilation parameters, and the compilation parameters in the first target code file are modified into target parameters; the target parameters are used to indicate that the first target code file is suitable for the compiler of the second architecture. In this way, it can be ensured that the compiler of the target platform can compile the first target code file.
[0054] Optionally, the above-mentioned operation of encapsulating the second interface to generate a target library file containing the third interface may specifically include the following steps in this embodiment of the present invention:
[0055] S41. Determine in sequence the second interfaces corresponding to the first interfaces respectively.
[0056] S42: Encapsulate the second interfaces corresponding to the first interfaces respectively, generate the third interfaces corresponding to the first interfaces respectively, and obtain the target library file.
[0057] Since there are often multiple first interfaces included in the first source code file, the embodiment of the present invention can sequentially determine the second interfaces corresponding to each first interface. For any first interface, the corresponding second interface can be one or more, as long as the corresponding second interface can implement the same operation as the first interface. For example, for the _mm256_fmadd_ps interface of the X86 architecture, there is a corresponding second interface __lasx_xvfmadd_s in the LoongArch architecture to implement the same floating-point vector multiplication and addition operation.
[0058] Specifically, the above step S41 may be based on the semantic information of the first interface and the semantic information of different calling interfaces of the second architecture to match, and the calling interface of the second architecture with similar semantic information is used as the second interface corresponding to the first interface. The above matching operation may be implemented based on a similarity algorithm, such as a cosine similarity algorithm. Alternatively, the above step S41 may be to output the first interface to the display interface in sequence, and the relevant personnel may input the corresponding second interface through the displayed first interface, and then determine the second interface corresponding to the first interface by receiving the input information of the relevant personnel. The embodiment of the present invention does not limit this.
[0059] Furthermore, after obtaining the second interfaces corresponding to the first interfaces, the second interfaces corresponding to the first interfaces can be encapsulated to generate the third interfaces corresponding to the first interfaces, thereby obtaining the target library file. Specifically, the target library file includes the encapsulated third interfaces, the call information of each third interface is consistent with the call information of the corresponding first interface, and the internal logic of each third interface is implemented through the corresponding second interface.
[0060] In the embodiment of the present invention, the second interfaces corresponding to the first interfaces are determined in sequence; the second interfaces corresponding to the first interfaces are encapsulated respectively, and the third interfaces corresponding to the first interfaces are generated to obtain the target library file. In this way, for each first interface, the second interface can be encapsulated to obtain the third interface that can run on the second architecture, and the target library file provides the calling method of the third interface to the source code file without modifying the source code file.
[0061] Optionally, the operation of obtaining the first interface included in the first source code file may further include the following steps in this embodiment of the present invention:
[0062] S51. Traverse the interfaces included in the first source code file, and determine an interface belonging to a preset interface set as the first interface; the preset interface set includes a calling interface of the first architecture.
[0063] The preset interface set includes all the calling interfaces of the first architecture. The embodiment of the present invention can traverse the interfaces included in the first source code file, compare each interface with the interfaces in the preset interface set, and confirm whether each interface belongs to the preset interface set. Accordingly, if there is an interface that belongs to the preset interface set, the interface can be used as the first interface.
[0064] In the embodiment of the present invention, by traversing the interfaces included in the first source code file, an interface belonging to a preset interface set is determined as the first interface; the preset interface set includes the calling interface of the first architecture. In this way, the interfaces included in the first source code file can be screened through the preset interface set, and the first interface can be accurately determined therefrom.
[0065] Optionally, the operation of sequentially determining the second interfaces corresponding to the first interfaces may include the following contents in the embodiment of the present invention:
[0066] S61, output each of the first interfaces to the display interface in sequence.
[0067] S62: Receive an interface input by a user for each of the first interfaces based on the display interface, and determine the interface as a second interface corresponding to each of the first interfaces.
[0068] In the embodiment of the present invention, each of the first interfaces is output to the display interface in sequence; the interface input by the user for each of the first interfaces based on the display interface is received, and the interface is determined as the second interface corresponding to each of the first interfaces. In this way, by setting the display interface and receiving the user's input based on the display interface, the second interface corresponding to each of the first interfaces can be determined, without the need to analyze and operate each of the first interfaces separately, thereby improving the efficiency of determining the second interface.
[0069] Optionally, the first source code file is a source code file of the software to be migrated. In this way, by executing the code migration method provided by the embodiment of the present invention on the source code file of the software to be migrated, the software can be migrated conveniently, thereby improving the efficiency of software migration.
[0070] For example, the first architecture is X86 architecture, the first source code file contains a first interface _mm256_fmadd_ps for implementing floating-point vector multiplication and addition operations, and the second architecture is LoongArch. Figure 2 It is a schematic diagram of an interface call in a first source code file, such as Figure 2 As shown, it can be seen that the library file in the first source code file includes the first library file<immintrin.h> , and when _mm256_fmadd_ps() is called in the first source code file, the X86 compiler can compile it into the vector calculation instruction AVX2 in the X86 instruction set. Figure 3 is a schematic diagram of an interface call in a first target code file provided by an embodiment of the present invention, such as Figure 3As shown, the original first library file in the first target code file is cancelled by the cancellation symbol " / / ", and the target library file "x86ToLaIntrinsics.h" is added to the library file. The target library file contains the third interface after the second interface is encapsulated, and the calling information of the third interface is consistent with the calling information of the first interface, both of which are _mm256_fmadd_ps(). At this time, the target library file "x86ToLaIntrinsics.h" is equivalent to the middle layer. When calling _mm256_fmadd_ps(), it actually calls the second interface __lasx_xvfmadd_s. Accordingly, the LoongArch compiler can compile it into the vector calculation instruction LASX in the LoongArch instruction set.
[0071] In summary, the embodiment of the present invention obtains the first source code file to be migrated, and obtains the first interface contained in the first source code file, the first interface belongs to the calling interface of the first architecture, encapsulates the second interface, generates a target library file containing the third interface, the third interface implements the operation corresponding to the first interface by calling the second interface; the calling information of the third interface is consistent with the calling information of the first interface; the second interface belongs to the calling interface of the second architecture, and by encapsulating the second interface, a target library file containing the third interface is generated, and the operation of the first interface can be implemented through the second interface by calling the third interface. At the same time, the first library file in the first source code file is modified to the target library file, and the first target code file is obtained; the first library file is a library file corresponding to the calling interface of the first architecture; the first target code file is output to the target platform, so that the target platform compiles and executes the first target code file; the target platform is a platform using the second architecture. Since the first library file in the first target code file is modified into a target library file, and the third interface in the target library file is consistent with the calling information of the first interface, when the source code in the first target code file calls the first interface, it actually calls the third interface in the target library file. The target library file is equivalent to the middle layer, that is, the first target code file implements the operation of the first interface by calling the second interface by calling the third interface. In this way, code migration can be achieved by modifying the first library file in the first source code file, without modifying and replacing the first interfaces in the first source code file one by one, thereby improving the efficiency of code migration.
[0072] Figure 4 2 is a structural diagram of a code migration device provided by an embodiment of the present invention. The device 20 may include:
[0073] The acquisition module 201 is used to acquire a first source code file to be migrated, and acquire a first interface included in the first source code file; the first interface belongs to a calling interface of a first architecture;
[0074] The encapsulation module 202 is used to encapsulate the second interface and generate a target library file containing a third interface; the third interface implements the operation corresponding to the first interface by calling the second interface; the calling information of the third interface is consistent with the calling information of the first interface; the second interface belongs to the calling interface of the second architecture;
[0075] A first modification module 203 is used to modify the first library file in the first source code file into the target library file to obtain a first target code file; the first library file is a library file corresponding to the calling interface of the first architecture;
[0076] The first output module 204 is used to output the first target code file to a target platform, so that the target platform compiles and executes the first target code file; the target platform is a platform using the second architecture.
[0077] Optionally, the device 20 further includes:
[0078] A second modification module is used for, upon receiving a request to migrate a second source code file to the target platform, modifying a first library file in the second source code file to the target library file to obtain a second target code file if a first interface included in the second source code file belongs to a first interface included in the first source code file;
[0079] The second output module is used to output the second target code file to the target platform, so that the target platform compiles and executes the second target code file.
[0080] Optionally, the first source code file includes compilation parameters, and the device further includes:
[0081] A parameter modification module is used to modify the compilation parameters in the first target code file into target parameters; the target parameters are used to indicate that the first target code file is suitable for the compiler of the second architecture.
[0082] Optionally, the encapsulation module 202 includes:
[0083] A determination submodule, used to sequentially determine the second interfaces corresponding to each of the first interfaces;
[0084] The encapsulation submodule is used to encapsulate the second interfaces corresponding to the first interfaces respectively, generate the third interfaces corresponding to the first interfaces respectively, and obtain the target library file.
[0085] Optionally, the acquisition module is specifically used to:
[0086] The interfaces included in the first source code file are traversed, and an interface belonging to a preset interface set is determined as the first interface; the preset interface set includes a calling interface of the first architecture.
[0087] Optionally, the determining submodule is specifically used for:
[0088] Outputting each of the first interfaces to a display interface in sequence;
[0089] An interface input by a user for each of the first interfaces based on the display interface is received, and the interface is determined as a second interface corresponding to each of the first interfaces.
[0090] Optionally, the first source code file is a source code file of the software to be migrated.
[0091] In summary, the code migration device provided by the embodiment of the present invention obtains the first source code file to be migrated, and obtains the first interface contained in the first source code file, the first interface belongs to the calling interface of the first architecture, encapsulates the second interface, generates a target library file containing the third interface, the third interface implements the operation corresponding to the first interface by calling the second interface; the calling information of the third interface is consistent with the calling information of the first interface; the second interface belongs to the calling interface of the second architecture, and the target library file containing the third interface is generated by encapsulating the second interface, and the operation of the first interface can be implemented through the second interface by calling the third interface. At the same time, the first library file in the first source code file is modified to the target library file, and the first target code file is obtained; the first library file is a library file corresponding to the calling interface of the first architecture; the first target code file is output to the target platform, so that the target platform compiles and executes the first target code file; the target platform is a platform using the second architecture. Since the first library file in the first target code file is modified into a target library file, and the third interface in the target library file is consistent with the calling information of the first interface, when the source code in the first target code file calls the first interface, it actually calls the third interface in the target library file. The target library file is equivalent to the middle layer, that is, the first target code file implements the operation of the first interface by calling the second interface by calling the third interface. In this way, code migration can be achieved by modifying the first library file in the first source code file, without modifying the first interfaces in the first source code file one by one, thereby improving the efficiency of code migration.
[0092] The present invention also provides an electronic device, see Figure 5, including: a processor 301, a memory 302, and a computer program 3021 stored in the memory and executable on the processor, wherein the processor implements the code migration method of the aforementioned embodiment when executing the program.
[0093] The present invention also provides a readable storage medium, when the instructions in the storage medium are executed by a processor of an electronic device, the electronic device can execute the code migration method of the aforementioned embodiment.
[0094] As 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.
[0095] The algorithm and display provided herein are not inherently related to any particular computer, virtual system or other device. Various general purpose systems can also be used together with the teachings based on this. According to the above description, it is obvious that the structure required for constructing such systems. In addition, the present invention is not directed to any specific programming language either. It should be understood that various programming languages can be utilized to realize the content of the present invention described herein, and the description of the above specific languages is for disclosing the best mode of the present invention.
[0096] In the description provided herein, a large number of specific details are described. However, it is understood that embodiments of the present invention can be practiced without these specific details. In some instances, well-known methods, structures and techniques are not shown in detail so as not to obscure the understanding of this description.
[0097] Similarly, it should be understood that in order to streamline the present invention and aid in understanding one or more of the various inventive aspects, in the above description of exemplary embodiments of the present invention, the various features of the present invention are sometimes grouped together into a single embodiment, figure, or description thereof. However, this disclosed method should not be interpreted as reflecting the following intention: that the claimed invention requires more features than the features explicitly recited in each claim. More specifically, as reflected in the claims below, inventive aspects lie in less than all the features of the individual embodiments disclosed above. Therefore, the claims that follow the specific embodiment are hereby expressly incorporated into the specific embodiment, with each claim itself serving as a separate embodiment of the present invention.
[0098] Those skilled in the art will appreciate that the modules in the devices in the embodiments may be adaptively changed and arranged in one or more devices different from the embodiments. The modules or units or components in the embodiments may be combined into one module or unit or component, and in addition they may be divided into a plurality of submodules or subunits or subcomponents. Except that at least some of such features and / or processes or units are mutually exclusive, all features disclosed in this specification (including the accompanying claims, abstracts and drawings) and all processes or units of any method or device disclosed in this manner may be combined in any combination. Unless otherwise expressly stated, each feature disclosed in this specification (including the accompanying claims, abstracts and drawings) may be replaced by an alternative feature providing the same, equivalent or similar purpose.
[0099] The various component embodiments of the present invention may be implemented in hardware, or in software modules running on one or more processors, or in a combination thereof. It should be understood by those skilled in the art that a microprocessor or digital signal processor (DSP) may be used in practice to implement some or all of the functions of some or all of the components in the sorting device according to the present invention. The present invention may also be implemented as a device or apparatus program for executing part or all of the methods described herein. Such a program for implementing the present invention may be stored on a computer-readable medium, or may be in the form of one or more signals. Such a signal may be downloaded from an Internet website, or provided on a carrier signal, or provided in any other form.
[0100] It should be noted that the above embodiments illustrate the present invention rather than limit it, and that those skilled in the art may devise alternative embodiments without departing from the scope of the appended claims. In the claims, any reference symbol between brackets shall not be construed as a limitation on the claims. The word "comprising" does not exclude the presence of elements or steps not listed in the claims. The word "one" or "an" preceding an element does not exclude the presence of a plurality of such elements. The present invention may be implemented by means of hardware comprising a number of different elements and by means of a suitably programmed computer. In a unit claim enumerating a number of devices, several of these devices may be embodied by the same hardware item. The use of the words first, second, and third, etc., does not indicate any order. These words may be interpreted as names.
[0101] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0102] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present invention should be included in the protection scope of the present invention.
[0103] The above is only a specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any person skilled in the art can easily think of changes or substitutions within the technical scope disclosed by the present invention, which should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention should be based on the protection scope of the claims.
Claims
1. A code migration method, characterized in that: The method comprises: Acquire a first source code file to be migrated, and acquire a first interface included in the first source code file; the first interface belongs to a calling interface of a first architecture; The second interface is encapsulated to generate a target library file containing a third interface; the third interface implements an operation corresponding to the first interface by calling the second interface; the calling information of the third interface is consistent with the calling information of the first interface; the second interface belongs to the calling interface of the second architecture; Modify the first library file in the first source code file into the target library file to obtain a first target code file; the first library file is a library file corresponding to the calling interface of the first architecture; The first target code file is output to a target platform so that the target platform compiles and executes the first target code file; the target platform is a platform using the second architecture.
2. The method according to claim 1, characterized in that: The method further comprises: When receiving a request to migrate a second source code file to the target platform, if a first interface included in the second source code file belongs to a first interface included in the first source code file, modifying a first library file in the second source code file into the target library file to obtain a second target code file; The second object code file is output to the target platform, so that the target platform compiles and executes the second object code file.
3. The method according to claim 1, characterized in that: The first source code file includes compilation parameters, and before outputting the first target code file to the target platform, the process includes: The compilation parameters in the first target code file are modified into target parameters; the target parameters are used to indicate that the first target code file is suitable for the compiler of the second architecture.
4. The method according to claim 1, characterized in that: The step of encapsulating the second interface to generate a target library file containing the third interface includes: sequentially determining the second interfaces corresponding to the first interfaces; The second interfaces corresponding to the first interfaces are respectively encapsulated to generate third interfaces corresponding to the first interfaces, thereby obtaining the target library file.
5. The method according to claim 1, characterized in that: The obtaining of the first interface included in the first source code file includes: The interfaces included in the first source code file are traversed, and an interface belonging to a preset interface set is determined as the first interface; the preset interface set includes a calling interface of the first architecture.
6. The method according to claim 4, characterized in that: The sequentially determining the second interfaces corresponding to the first interfaces respectively includes: Outputting each of the first interfaces to a display interface in sequence; An interface input by a user for each of the first interfaces based on the display interface is received, and the interface is determined as a second interface corresponding to each of the first interfaces.
7. The method according to any one of claims 1 to 6, characterized in that: The first source code file is a source code file of the software to be migrated.
8. A code migration device, characterized in that: The device comprises: An acquisition module, used to acquire a first source code file to be migrated, and acquire a first interface included in the first source code file; the first interface belongs to a calling interface of a first architecture; The encapsulation module is used to encapsulate the second interface and generate a target library file containing a third interface; the third interface implements the operation corresponding to the first interface by calling the second interface; the calling information of the third interface is consistent with the calling information of the first interface; the second interface belongs to the calling interface of the second architecture; A first modification module is used to modify the first library file in the first source code file into the target library file to obtain a first target code file; the first library file is a library file corresponding to the calling interface of the first architecture; The first output module is used to output the first target code file to a target platform so that the target platform compiles and executes the first target code file; the target platform is a platform using the second architecture.
9. The device according to claim 8, characterized in that: The device also includes: A second modification module is used for, upon receiving a request to migrate a second source code file to the target platform, modifying a first library file in the second source code file to the target library file to obtain a second target code file if a first interface included in the second source code file belongs to a first interface included in the first source code file; The second output module is used to output the second target code file to the target platform, so that the target platform compiles and executes the second target code file.
10. The device according to claim 8, characterized in that: The first source code file includes compilation parameters, and the device further includes: A parameter modification module is used to modify the compilation parameters in the first target code file into target parameters; the target parameters are used to indicate that the first target code file is suitable for the compiler of the second architecture.
11. The device according to claim 8, characterized in that: The packaging module comprises: A determination submodule, used to sequentially determine the second interfaces corresponding to each of the first interfaces; The encapsulation submodule is used to encapsulate the second interfaces corresponding to the first interfaces respectively, generate the third interfaces corresponding to the first interfaces respectively, and obtain the target library file.
12. The device according to claim 8, characterized in that: The acquisition module is specifically used for: The interfaces included in the first source code file are traversed, and an interface belonging to a preset interface set is determined as the first interface; the preset interface set includes a calling interface of the first architecture.
13. The device according to claim 11, characterized in that: The determination submodule is specifically used for: Outputting each of the first interfaces to a display interface in sequence; An interface input by a user for each of the first interfaces based on the display interface is received, and the interface is determined as a second interface corresponding to each of the first interfaces.
14. The device according to claim 13, characterized in that: The first source code file is a source code file of the software to be migrated.
15. An electronic device, characterized in that: include: A processor, a memory, and a computer program stored in the memory and executable on the processor, wherein the processor implements the method according to any one of claims 1 to 7 when executing the program.
16. A readable storage medium, characterized in that: When the instructions in the storage medium are executed by a processor of an electronic device, the electronic device is enabled to execute the method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Cross-platform application running method and device, computer system and medium
CN111142935A
Application generation method and device and device for generating application
CN113220280A
Code scanning method, code migration method and related devices
CN114647439A