Multi-program language cross-instruction-set architecture transplantation method
By establishing a multi-grained knowledge base and abstract syntax tree analysis technology, we automatically locate and process software components in cross-instruction set architecture migration, solving the complexity and compatibility problems of multi-programming language migration in the existing technology, and achieving fast and efficient software migrate.
Patent Information
- Application Number
- CN202411009805.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-26
- Publication Date
- 2024-11-15
AI Technical Summary
During the migration of cross-instruction set architectures, it is difficult to effectively deal with version dependencies in multi-program languages and project dependencies in configuration files, which makes it difficult to identify and solve the compatibility problems of software in the new instruction set architecture environment, and the migration is The process is complicated and difficult to complete quickly.
By establishing a knowledge base of software package granularity, file granularity and code granularity, combining abstract syntax tree analysis technology, we automatically locate the software components related to the software package and generate customized migration suggestions to assist developers in completing cross-instruction set architectures Software migration.
It realizes the automated positioning of software components for multiple program languages during the migration process and the generation of migration suggestions, simplifies developers' work in cross-instruction set architecture migration, and improves the efficiency and accuracy of software migration.
Smart Images

Figure CN118963831A_ABST
Abstract
Description
Technical Field
[0001] The invention relates to a method for transplanting a programming language, in particular to a method for transplanting multiple programming languages across instruction set architectures. Background Art
[0002] With the rapid development of computer technology, different instruction set architectures continue to emerge in pursuit of more targeted designs and better performance. However, due to the design differences between these architectures, some open source software related to instruction set architectures may not be able to run successfully in the new instruction set architecture environment, so cross-instruction set architecture software migration is required.
[0003] Due to the complexity of software technology and the diversity of programming languages, cross-architecture migration has become extremely complex. This not only increases the difficulty of migration, but also requires a lot of manpower and must be completed by developers who master core technologies. This situation makes software migration work face many challenges and limitations in actual operations.
[0004] At present, the Chinese patent "CN115794123A Extensible framework for program cross-architecture migration and program cross-architecture migration method" provides a system environment for source code translation, builds a source architecture subsystem, provides a virtual operating environment for the source program, ensures the isolation of the source architecture and the target architecture, and stores multiple binary translators in the data space, selects the translator with higher translation efficiency for translation, thereby completing the cross-architecture migration of the program; the Chinese patent "CN116414447A A cross-architecture migration method and device, electronic device and storage medium" provides a corresponding relationship between the information of the application to be migrated and the migration target architecture and the general template, and determines the general template, preset migration data and preset migration tool that match the migration request according to the language of the application to be migrated; and arranges the preset migration tool according to the general template. Thus, the migration between architectures is completed.
[0005] However, the method adopted by the Chinese patent "CN115794123A Extensible framework for program cross-architecture migration and program cross-architecture migration method" is fundamentally a binary translation method. Although there is no need to modify the source code for the time being, the version dependencies referenced in multiple programming languages may cause migration problems due to API differences between different platforms, and the stability of the software cannot be guaranteed with updates; the Chinese patent "CN116414447A A cross-architecture migration method and device, electronic device and storage medium" proposes a migration method for template correspondence between different architectures, which can solve some problems at the source code level, but it is difficult to give clear analysis opinions on the project dependencies and configuration parameters introduced in the configuration file.
[0006] Currently, due to the large scale of the project, it is difficult for developers to clearly identify the compatibility issues of the software in the new instruction set architecture environment. For the binary packages and source packages of the project, potential problems need to be discovered through compilation and installation. However, the error prompts that appear during the compilation and installation process often cannot accurately locate the problem, making it difficult for developers who lack a deep understanding of the project to identify problems during the software migration process. In addition, the types of software components that may be involved in the migration process are complex, and it is difficult for developers to determine whether these contents are related to the instruction set architecture, which may lead to omissions in the migration process. After identifying the code snippets that need to be migrated, developers may not be able to directly formulate a clear migration strategy to complete the migration. Summary of the invention
[0007] In view of the deficiencies of the prior art, the present invention aims to provide a multi-programming language cross-instruction set architecture transplantation method, which specifically includes the following steps:
[0008] Step 1: Upload the software package to be migrated;
[0009] Step 2: Determine whether the software package to be migrated has completed migration. If the software package to be migrated has completed migration, the migration process ends; if the software package to be migrated has not completed migration, execute step 3;
[0010] Step 3: Determine the type of the software package to be migrated. According to the suffix of the software package to be migrated, determine whether the type of the software package to be migrated is a binary package or a software source code compressed package. If the type of the software package to be migrated is a binary package, execute step 4. If the type of the software package to be migrated is a software source code compressed package, execute step 5.
[0011] Step 4: decompress the software package to be migrated to obtain a file list of the software package to be migrated, and determine whether the file list of the software package to be migrated contains the first executable file. If the file list of the software package to be migrated does not contain the first executable file, it indicates that the software package to be migrated does not need to be migrated, and the migration process ends. If the file list of the software package to be migrated contains the first executable file, obtain the first executable file, and match the names and versions of all the first executable files with the names and versions of the executable files in the pre-built file granularity knowledge base according to the names and versions of the first executable files. If the names and versions of all the first executable files match the names and versions of the executable files in the pre-built file granularity knowledge base, the first executable file is matched. If all the first executable files are matched, it indicates that the software package to be migrated is compatible with the target architecture, and the target architecture is the instruction set architecture to which the software package to be migrated is about to be migrated. The compatibility of the software package to be migrated with the target architecture indicates that the software package to be migrated has completed the migration and the migration process ends. If the names and versions of all the first executable files do not match the names and versions of the executable files in the pre-built file granularity knowledge base, it indicates that the software package to be migrated needs to be migrated, and a file list of the software package to be migrated is output. The file granularity knowledge base includes target information of multiple executable files, and the target information includes the name of the executable file, the version of the executable file, the direct dependent file of the executable file, the transitive dependent file of the executable file, and the instruction set architecture to which the executable file belongs.
[0012] Step 5: decompress the software package to be migrated to obtain the decompressed file, and obtain the project configuration file and engineering file in the software package to be migrated according to the name and version of the second executable file in the decompressed file and the pre-built file granularity knowledge base, wherein the engineering file is a file with a file suffix of a programming language file suffix;
[0013] Step 6: Obtain the name and version of the third-party component library in the project configuration file, and obtain the code snippet corresponding to the first architecture feature, the code snippet corresponding to the first architecture feature includes the code snippet corresponding to the instruction set architecture feature in the project configuration file and the code snippet corresponding to the instruction set architecture feature in the project file, and obtain the variable name corresponding to the target function in the project file and the value corresponding to the variable name, the target function is a function that can load an executable file in a preset programming language, and the value corresponding to the variable name is the name of the executable file;
[0014] Step 7: Generate migration suggestions based on the name and version of the third-party component library in the project configuration file and the code snippet corresponding to the first architectural feature
[0015] Step 7.1: for the name and version of the third-party component library in the project configuration file, search in the software package granularity knowledge base according to the name and version of the third-party component library. If there is a software package with the same name and version as the third-party component library in the software package granularity knowledge base, it indicates that the software package to be migrated can be run in the target architecture, and a prompt message is output, and the prompt message is used to prompt that the migration of the software package to be migrated has been completed and the migration process is ended; if there is a software package with the same name as the third-party component library but a different version in the software package granularity knowledge base, the generated migration suggestion is to replace the version of the third-party component library in the project configuration file with the version with the same name as the third-party component library but a different version in the software package granularity knowledge base; the software information of multiple software packages in the software package granularity knowledge base, the software information includes the name of the project in the software package, the version of the software package, the operating system that the software package can run, and the instruction set architecture that the software package can run;
[0016] Step 7.2: For the code snippet corresponding to the first architectural feature, determine the instruction set architecture feature keyword of the code snippet corresponding to the first architectural feature, and search in the code granularity knowledge base according to the instruction set architecture feature keyword and the mapping relationship between the instruction set architecture feature and the code snippets under different instruction set architectures corresponding to the instruction set architecture feature in the pre-built code granularity knowledge base to obtain the code snippets under multiple instruction set architectures corresponding to the instruction set architecture feature keyword, obtain the code snippet corresponding to the target architecture, and then determine the specific standard architecture feature contained in the code snippet corresponding to the target architecture, judge whether the specific instruction set architecture feature and the standard architecture feature in the code snippet corresponding to the first architectural feature are the same, and determine the specific instruction set architecture feature in the code snippet corresponding to the first architectural feature. When the feature of the architecture is different from the standard architecture feature, the generated migration suggestion is: replace the code snippet corresponding to the specific instruction set architecture feature in the code snippet corresponding to the first architecture feature with the code snippet corresponding to the target architecture in the code granularity knowledge base; the code granularity knowledge base includes the mapping relationship between the instruction set architecture feature and the code snippets under different instruction set architectures corresponding to the instruction set architecture feature; according to the value corresponding to the variable name, search in the file granularity knowledge base; if the value corresponding to the variable name can be found in the file granularity knowledge base, it indicates that the executable file corresponding to the value corresponding to the variable name has completed the migration and the migration process ends; if the value corresponding to the variable name is not found in the file granularity knowledge base, it indicates that the executable file corresponding to the value corresponding to the variable name needs to be migrated.
[0017] Furthermore, the software package granularity knowledge base is constructed by the following steps:
[0018] Step A1: using the type of instruction set architecture as a keyword, searching in an open source community containing software packages, obtaining multiple software packages of each instruction set architecture type, and storing the multiple software packages of each instruction set architecture type;
[0019] Step A2: For each software package, extract the name of the software package to obtain software information, which includes the name of the project in the software package, the version of the software package, the operating system that the software package can run on, and the instruction set architecture that the software package can run on. The software information of all software packages constitutes a software package granularity knowledge base.
[0020] Furthermore, the file granularity knowledge base is constructed by the following steps:
[0021] Step B1: using the type of instruction set architecture as a keyword, searching in an open source community containing software packages, obtaining multiple software packages of each instruction set architecture type, and storing the multiple software packages of each instruction set architecture type;
[0022] Step B2: decompress each software package to obtain all files in each software package. For all files in each software package, determine whether there is an executable file among all files of the software package. If there is an executable file among all files of the software package, obtain the instruction set architecture to which the executable file belongs and the direct dependent file of the executable file according to the attributes of the executable file. The direct dependent file is a file directly called by the executable file at runtime. The direct dependent file is parsed to obtain a transitive dependent file. The transitive dependent file is a file directly called by the direct dependent file at runtime, and the transitive dependent file is a file indirectly called through the direct dependent file when the executable file is running. The name of the executable file, the version of the executable file, the direct dependent file of the executable file, the transitive dependent file of the executable file and the instruction set architecture to which the executable file belongs constitute the target information of the executable file. The target information of all executable files constitutes a knowledge base of file granularity. If there is no executable file among all files of the software package, return to execute step B1 until there is an executable file among all files of the software package.
[0023] Furthermore, the code granularity knowledge base is constructed by the following steps:
[0024] Step C1: using the type of instruction set architecture as a keyword, searching in an open source community containing project source code to obtain a submission record, wherein the submission record at least includes a newly added source code revision record, obtaining a revision file list including the newly added source code revision record, searching for the update status file according to the name of the update status file in the revision file list, extracting the revised code snippet from the update status file, and storing the name of the update status file, all the contents of the update status file, and the revised code snippet;
[0025] Step C2: construct an abstract syntax tree of all codes in the updated state file, and construct an abstract syntax tree of the corrected code fragment, determine a target node of the corrected code fragment in the abstract syntax tree of all codes in the updated state file according to the abstract syntax tree of all codes in the updated state file and the abstract syntax tree of the corrected code fragment, and search for an associated node in the abstract syntax tree of all codes in the updated state file according to the target node, wherein the associated node is a node having the same function as the target node but a different instruction set architecture type, and store the corrected code fragment corresponding to the target node and the code fragment corresponding to the associated node;
[0026] Step C3: Determine whether the modified code snippet corresponding to the target node and the code snippet corresponding to the associated node contain instruction set architecture features. If the modified code snippet corresponding to the target node and the code snippet corresponding to the associated node contain instruction set architecture features, determine the code snippet corresponding to the instruction set architecture features in the modified code snippet corresponding to the target node and the code snippet corresponding to the associated node, and construct a mapping relationship between the instruction set architecture features and the code snippets under different instruction set architectures corresponding to the instruction set architecture features to form a knowledge base of code granularity. If the modified code snippet corresponding to the target node and the code snippet corresponding to the associated node contain instruction set architecture features, return to execute step C1 until the modified code snippet corresponding to the target node and the code snippet corresponding to the associated node contain instruction set architecture features.
[0027] Furthermore, step 2 is specifically implemented in the following manner:
[0028] A search is performed in a pre-built software package granularity knowledge base at least according to the name of the software package to be migrated and the version of the software package to be migrated. If the software package granularity knowledge base contains a software package with the same name and version as the software package to be migrated, it indicates that the migration of the software package to be migrated has been completed. If the software package granularity knowledge base does not contain a software package with the same name and version as the software package to be migrated, it indicates that the migration of the software package to be migrated has not been completed.
[0029] Furthermore, step 5 is specifically implemented by the following steps:
[0030] Step 5.1: decompress the software package to be migrated to obtain a file list of the software package to be migrated, divide the files in the file list of the software package to be migrated according to the file suffixes, store the compressed package type files in a first list, store the second executable file in a second list, and store the other files in the file list of the software package to be migrated except the compressed package type files and the second executable file in a third list, wherein the first list, the second list and the third list are all different;
[0031] Step 5.2: Process the compressed package type files and executable files, perform multiple iterations of decompression on the compressed package type files until all files in the compressed package type files are decompressed, store the second executable file in the decompressed file in the second list, and store the other files in the decompressed file except the second executable file in the third list; for the second executable files in the second list, match the names and versions of all the second executable files with the names and versions of the executable files in the pre-built file granularity knowledge base according to the names and versions of the second executable files; if the names and versions of all the second executable files match the names and versions of the executable files in the pre-built file granularity knowledge base, it indicates that the software package to be migrated is compatible with the target architecture; the compatibility of the software package to be migrated with the target architecture indicates that the migration of the software package to be migrated has been completed, and the migration process ends; if the names and versions of all the second executable files do not match the names and versions of the executable files in the pre-built file granularity knowledge base, it indicates that the software package to be migrated needs to be migrated; if the names and versions of all the second executable files do not match the names and versions of the executable files in the pre-built file granularity knowledge base, execute step 5.3;
[0032] Step 5.3: Process the files in the third list. Specifically, obtain the project configuration files included in the software package to be migrated from the files in the third list, and use the files with the suffix of the programming language file as project files.
[0033] Furthermore, step 6 is specifically implemented by the following steps:
[0034] Step 6.1: Determine whether the project configuration file contains the name and version of the third-party component library. If the project configuration file does not contain the name and version of the third-party component library, the migration process ends. If the project configuration file contains the name and version of the third-party component library, obtain the name and version of the third-party component library contained in the project configuration file, and store the name and version of the third-party component library in the fourth list; determine whether the project configuration file contains code snippets corresponding to the instruction set architecture features. If the project configuration file contains code snippets corresponding to the instruction set architecture features, store the code snippets corresponding to the instruction set architecture features in the fifth list, and the fourth list is different from the fifth list; if the project configuration file does not contain code snippets corresponding to the instruction set architecture features, the migration process ends;
[0035] Step 6.2: Determine whether the code of the project file contains code snippets corresponding to the instruction set architecture feature. If the code of the project file contains code snippets corresponding to the instruction set architecture feature, use the instruction set architecture feature as a keyword to obtain the code snippets corresponding to the instruction set architecture feature in the code of the project file, and store them in the fifth list. The code snippets corresponding to the instruction set architecture feature in the project configuration file and the code snippets corresponding to the instruction set architecture feature in the project file in the fifth list are the code snippets corresponding to the first architecture feature. If the code of the project file does not contain the code snippets corresponding to the instruction set architecture feature, the migration process ends. According to the pre-set target function, obtain the variable name corresponding to the target function in the project file, obtain the value corresponding to the variable name, and store the value corresponding to the variable name in the fifth list.
[0036] The beneficial effects of adopting the above technical solution are:
[0037] Compared with the prior art, the technical solution proposed in the present invention adopts the method of automatically locating architecture-related software components in software packages, and can help locate architecture-related software components that need to be paid attention to during the migration of multiple programming languages. For different categories of components to be migrated, combined with the collected knowledge base information, customized migration suggestions are generated to assist developers in quickly building an open source software ecosystem for the target instruction set architecture. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] Figure 1 A schematic diagram of a flow chart of a multi-programming language cross-instruction set architecture transplantation method in an embodiment of the present invention;
[0039] Figure 2 A schematic diagram of a construction process of a software package granularity knowledge base and a file granularity knowledge base in an embodiment of the present invention;
[0040] Figure 3The figure is a schematic diagram of the construction process of a code granularity knowledge base in an embodiment of the present invention. DETAILED DESCRIPTION
[0041] The specific implementation of the present invention is further described in detail below in conjunction with the accompanying drawings and examples. The following examples are used to illustrate the present invention, but are not intended to limit the scope of the present invention.
[0042] In view of the problems existing in the prior art, the present invention provides a method for porting multiple programming languages across instruction set architectures. The present invention, starting from the perspective of multiple programming languages, establishes a knowledge base mapping relationship between different dimensions and architectures, and uses the abstract syntax tree (AST) analysis technology and the mixed language software component analysis technology to identify the software components related to the architecture in the software package. Combined with the knowledge base, multi-dimensional software migration adaptation suggestions are provided for different categories of software components, thereby achieving the adaptation goal of multiple programming languages in the migration across instruction set architectures.
[0043] After the compressed package of the software project to be migrated is uploaded, the tool can automatically scan the software components related to the architecture in the internal structure of the software, including dependency library information, source code components, and configuration file components, and locate and classify them. At the same time, it combines the constructed knowledge base and the whitelist and source code mapping knowledge base of different architectures to generate different types of migration suggestions, thereby assisting developers to complete software migration work. Specifically, Figure 1 , which may include the following steps:
[0044] Step 1: Upload the software package to be migrated;
[0045] The software package may be a binary software package or a software source code compressed package. The present invention can parse the binary software package and the software source code compressed package with a suffix.
[0046] Step 2: Determine whether the software package to be migrated has completed migration. If the software package to be migrated has completed migration, the migration process ends; if the software package to be migrated has not completed migration, execute step 3;
[0047] The determination of whether the software package to be migrated has completed migration is specifically implemented in the following manner:
[0048] At least based on the name of the package to be migrated and the version of the package to be migrated, a search is performed in a pre-built package granularity knowledge base, that is, Figure 1 If the software package granularity knowledge base in the matching software package is the same as the software package to be migrated, then Figure 1If the matching in is successful, it indicates that the software package to be migrated has been migrated. If the software package granularity knowledge base does not have a software package with the same name and version as the software package to be migrated, that is, Figure 1 If there is no successful match in the to-be-migrated software package, it indicates that the migration of the to-be-migrated software package has not been completed; the present invention mainly searches in a pre-built software package granularity knowledge base according to the name of the to-be-migrated software package and the version of the to-be-migrated software package, and can further search in the pre-built software package granularity knowledge base according to other information of the to-be-migrated software package.
[0049] The software package granularity knowledge base contains software information of multiple software packages, wherein the software information includes the name of the project in the software package, the version of the software package, the operating system on which the software package can run, and the instruction set architecture on which the software package can run. Figure 2 The software package granularity knowledge base can be constructed by the following steps:
[0050] Step A1: using the type of instruction set architecture as a keyword, searching in an open source community containing software packages, obtaining multiple software packages of each instruction set architecture type, and storing the multiple software packages of each instruction set architecture type;
[0051] Among them, the types of instruction set architectures may include X86, ARM64, LoongArch64, etc., and the open source communities containing software packages may be Maven and PyPI open source communities; the present invention utilizes the API interfaces provided by Maven and PyPI open source communities to obtain different versions of software packages distributed in the above communities and containing keywords in their names, that is, to obtain the project name. After obtaining the project name, it is determined whether the project is related to the architecture based on the project name. If the project is not related to the architecture, the process is terminated. If the project is related to the architecture, the different versions of the obtained software packages with keywords are downloaded to a local specified path.
[0052] Step A2: For each software package, parse the project structure, extract the software package name, and obtain the software information, that is, Figure 2 In the step of extracting basic information, the software information includes the name of the project in the software package, the version of the software package, the operating system on which the software package can run, and the instruction set architecture on which the software package can run. The software information of all software packages constitutes a software package granularity knowledge base.
[0053] In specific implementation, the present invention parses the project structure, that is, decompresses each software package and then extracts basic information. Specifically, the software package name under the path is parsed using a regular expression to extract the version number, the adapted operating system (i.e., the operating system on which the software package can run) and the adapted instruction set architecture (i.e., the instruction set architecture on which the software package can run). For Python's Whl package, for example, av-10.0.0-cp38-cp38-linux_loongarch64.whl, the Python project name package_name (av), version version (10.0.0), the corresponding Python version number py_version (cp38-cp38), the adapted operating system target_os (linux) and the adapted instruction set architecture target_arch (loongarch64) and other information are extracted; for Java's Jar package, for example, Javafx-base-22-linux-aarch64.jar, the Java project package_name (Javafx-base), version number version (22), the adapted operating system target_os (linux) or the instruction set architecture information arch_info (aarch64) are extracted, the Python extracted information is stored in a table named py_pkg, and the Java extracted information is stored in a table named java_pkg, and a software package granularity knowledge base is constructed.
[0054] Step 3: Determine the type of the software package to be migrated. According to the suffix of the software package to be migrated, determine whether the type of the software package to be migrated is a binary package or a software source code compressed package. If the type of the software package to be migrated is a binary package, execute step 4. If the type of the software package to be migrated is a software source code compressed package, execute step 5.
[0055] The present invention determines the type of the software package to be migrated by the suffix of the software package to be migrated. If the suffix is .rpm, .jar, .aar and .whl, the software package to be migrated is a binary software package. If the suffix is .tar.gz, .zip, .7z and .gz, the software package to be migrated is a software source code compression package.
[0056] Step 4: decompress the software package to be migrated to obtain a file list of the software package to be migrated, determine whether the file list of the software package to be migrated contains the first executable file, and if the file list of the software package to be migrated does not contain the first executable file, it indicates that the software package to be migrated does not need to be migrated, and the migration process ends; if the file list of the software package to be migrated contains the first executable file, obtain the first executable file, and match the names and versions of all the first executable files with the names and versions of the executable files in the pre-built file granularity knowledge base according to the names and versions of the first executable files. If the names and versions of all the first executable files match the names and versions of the executable files in the pre-built file granularity knowledge base, it indicates that the software package to be migrated is compatible with the target architecture, and the target architecture is the instruction set architecture to which the software package to be migrated is about to be migrated. The compatibility of the software package to be migrated with the target architecture indicates that the migration of the software package to be migrated has been completed, and the migration process ends; if the names and versions of all the first executable files do not match the names and versions of the executable files in the pre-built file granularity knowledge base, it indicates that the software package to be migrated needs to be migrated, and the file list of the software package to be migrated is output;
[0057] Among them, matching the names and versions of all first executable files with the names and versions of executable files in a pre-built file granularity knowledge base may specifically include: for each first executable file, searching in the pre-built file granularity knowledge base according to the name and version of the first executable file; if all first executable files can be found in the file granularity knowledge base, it indicates that the names and versions of all first executable files match the names and versions of executable files in the pre-built file granularity knowledge base.
[0058] The file granularity knowledge base includes target information of multiple executable files, the target information includes the name of the executable file, the version of the executable file, the direct dependent file of the executable file, the transitive dependent file of the executable file and the instruction set architecture to which the executable file belongs, combined with Figure 2 ,The file granularity knowledge base can be constructed through the following steps:
[0059] Step B1: using the type of instruction set architecture as a keyword, searching in an open source community containing software packages, obtaining multiple software packages of each instruction set architecture type, and storing the multiple software packages of each instruction set architecture type;
[0060] Among them, the types of instruction set architectures may include X86, ARM64, LoongArch64, etc., and the open source communities containing software packages may be Maven and PyPI open source communities; the present invention utilizes the API interfaces provided by Maven and PyPI open source communities to obtain different versions of software packages distributed in the above communities and containing keywords in their names, that is, to obtain the project name. After obtaining the project name, it is determined whether the project is related to the architecture based on the project name. If the project is not related to the architecture, the process is terminated. If the project is related to the architecture, the different versions of the obtained software packages with keywords are downloaded to a local specified path.
[0061] Step B2: decompress each software package to obtain all files in each software package. For all files in each software package, determine whether there is an executable file among all files of the software package. If there is an executable file among all files of the software package, obtain the instruction set architecture to which the executable file belongs and the direct dependent file of the executable file according to the attributes of the executable file. The direct dependent file is a file directly called by the executable file at runtime. The direct dependent file is parsed to obtain a transitive dependent file. The transitive dependent file is a file directly called by the direct dependent file at runtime, and the transitive dependent file is a file indirectly called through the direct dependent file when the executable file is running. The name of the executable file, the version of the executable file, the direct dependent file of the executable file, the transitive dependent file of the executable file and the instruction set architecture to which the executable file belongs constitute the target information of the executable file. The target information of all executable files constitutes a knowledge base of file granularity. If there is no executable file among all files of the software package, return to execute step B1 until there is an executable file among all files of the software package.
[0062] In the specific implementation, the present invention parses the project structure, that is, decompresses each software package, and divides it according to the file category, further determines whether the current file is a compressed package, if the current file is a compressed package, then returns to execute the parsed project structure, if the current file is not a compressed package, obtains the ELF header information, and judges whether there is an executable file in all the files of the software package through the readelf command, specifically, if the file TYPE obtained by the readelf-h instruction is EXEC, then the file is considered to be an executable file. If the attribute value of TYPE is not EXEC, it is not an executable file, and the process ends; then according to the way of reading the ELF header information, the instruction set architecture to which it belongs is obtained through the Machine attribute, and the direct dependent file of the executable file is obtained through the Shared library attribute through the readelf-d method; for the direct dependent file, the ldd command is used to analyze the transitive dependent file of the direct dependent file, and the obtained information executable file name (name), executable file version (version), direct dependent file (dir_dep) and transitive dependent file (ind_dep), instruction set architecture (arch_info) and other attributes are stored in the table dy_file to form a file granularity knowledge base.
[0063] Step 5: decompress the software package to be migrated to obtain the decompressed file, and obtain the project configuration file and engineering file in the software package to be migrated according to the name and version of the second executable file in the decompressed file and the pre-built file granularity knowledge base, wherein the engineering file is a file with a file suffix of a programming language file suffix;
[0064] Step 5.1: decompress the software package to be migrated to obtain a file list of the software package to be migrated, divide the files in the file list of the software package to be migrated according to the file suffixes, store the compressed package type files in a first list, store the second executable file in a second list, and store the other files in the file list of the software package to be migrated except the compressed package type files and the second executable file in a third list, wherein the first list, the second list and the third list are all different;
[0065] The first list may be a list named zipFilesList, the second list may be a list named dyFilesList, and the third list may be a list named proFilesList.
[0066] Step 5.2: Process the compressed package type files and executable files, perform multiple iterations of decompression on the compressed package type files until all files in the compressed package type files are decompressed, store the second executable file in the decompressed file in the second list, and store the other files in the decompressed file except the second executable file in the third list; for the second executable files in the second list, match the names and versions of all the second executable files with the names and versions of the executable files in the pre-built file granularity knowledge base according to the names and versions of the second executable files; if the names and versions of all the second executable files match the names and versions of the executable files in the pre-built file granularity knowledge base, it indicates that the software package to be migrated is compatible with the target architecture; the compatibility of the software package to be migrated with the target architecture indicates that the migration of the software package to be migrated has been completed, and the migration process ends; if the names and versions of all the second executable files do not match the names and versions of the executable files in the pre-built file granularity knowledge base, it indicates that the software package to be migrated needs to be migrated; if the names and versions of all the second executable files do not match the names and versions of the executable files in the pre-built file granularity knowledge base, execute step 5.3;
[0067] Among them, matching the names and versions of all second executable files with the names and versions of executable files in a pre-built file granularity knowledge base may specifically include: for each second executable file, searching in the pre-built file granularity knowledge base according to the name and version of the second executable file; if all second executable files can be found in the file granularity knowledge base, it indicates that the names and versions of all second executable files match the names and versions of executable files in the pre-built file granularity knowledge base.
[0068] It should be noted that the first executable file and the second executable file in the present invention are still executable files in essence. The first executable file and the second executable file in the present invention are named only to distinguish whether they are executable files in a binary package or executable files in a software source code compression package.
[0069] Step 5.3: Process the files in the third list. Specifically, obtain the project configuration files included in the software package to be migrated from the files in the third list, and use the files with the suffix of the programming language file as project files.
[0070] In the specific implementation, the proFilesList list is traversed and divided according to the file suffix. For example, files containing keywords such as setup.py, pyproject.toml, Makefile, etc. are used as project configuration files and stored in the project configuration file profileList list; files ending with suffixes such as .c, .java, and .h are used as project files and stored in the project file projectList list.
[0071] Step 6: Obtain the name and version of the third-party component library in the project configuration file, and obtain the code snippet corresponding to the first architecture feature, wherein the code snippet corresponding to the first architecture feature includes the code snippet corresponding to the instruction set architecture feature in the project configuration file and the code snippet corresponding to the instruction set architecture feature in the project file; and obtain the variable name corresponding to the target function in the project file and the value corresponding to the variable name, wherein the target function is a function capable of loading an executable file in a preset programming language, and the value corresponding to the variable name is the name of the executable file;
[0072] Specifically, this can be achieved through the following steps:
[0073] Step 6.1: Determine whether the project configuration file contains the name and version of the third-party component library. If the project configuration file does not contain the name and version of the third-party component library, the migration process ends. If the project configuration file contains the name and version of the third-party component library, obtain the name and version of the third-party component library contained in the project configuration file, and store the name and version of the third-party component library in the fourth list; determine whether the project configuration file contains code snippets corresponding to the instruction set architecture features. If the project configuration file contains code snippets corresponding to the instruction set architecture features, store the code snippets corresponding to the instruction set architecture features in the fifth list, and the fourth list is different from the fifth list; if the project configuration file does not contain code snippets corresponding to the instruction set architecture features, the migration process ends;
[0074] Among them, the project configuration file contains content related to architectural features, such as third-party component libraries introduced by the software project, and instruction set architecture features. This part specifically refers to the compilation option configuration used by the software project during compilation and operation. The compilation options can be -march, -mabi, etc.
[0075] In specific implementation, the present invention needs to analyze third-party component libraries and compilation options in project configuration files in Java and Python files, such as setup.py, pyproject.toml, pom.xml, and build.gradle files. For example, for a software package developed in Java, the configuration files of the present invention are mainly pom.xml files and build.gradle files. For the pom.xml file, the present invention utilizes the extraction technology of XML file tags to extract the name and version of the third-party component library introduced in the pom.xml file through the dependencies and plugins tags, and simultaneously obtains the compilation options of the project introduced in the profile tag in the pom.xml file at the time of compilation. For the build.gradle file, the present invention utilizes the data flow analysis technology and the regular matching technology to extract the name and version of the third-party component library under the dependencies attribute. For the software package developed in Python, the configuration files are mainly requirement.txt files, setup.py files and pyproject.toml files. For the configuration files, the present invention utilizes the data flow analysis technology and the regular matching technology to match the architecture features, obtains the compilation options configured under the binaries.all, toolChains and platforms attributes, extracts the name and version of the third-party component library in the configuration file, and for the compilation option configuration, locates the Extension attribute introduced by the ext_modules attribute of the setup function through data flow analysis, thereby obtaining the compilation options configured therein.
[0076] Among them, the fourth list can be a list named threeDepList, and the fifth list can be a list named archInfoList. The present invention traverses the profileList list, reads the file content, and analyzes the code content by reading the content of the file in the list according to the above-mentioned analysis method. The extracted third-party component library content is stored in the list threeDepList in the form of component library name and component library version, and the code fragments containing architectural features are stored in the architecture component location list archInfoList.
[0077] Step 6.2: Determine whether the code of the project file contains code snippets corresponding to the instruction set architecture feature. If the code of the project file contains code snippets corresponding to the instruction set architecture feature, use the instruction set architecture feature as a keyword to obtain the code snippets corresponding to the instruction set architecture feature in the code of the project file, and store them in the fifth list. The code snippets corresponding to the instruction set architecture feature in the project configuration file and the code snippets corresponding to the instruction set architecture feature in the project file in the fifth list are the code snippets corresponding to the first architecture feature. If the code of the project file does not contain the code snippet corresponding to the instruction set architecture feature, the migration process ends. According to the preset target function, obtain the variable name corresponding to the target function in the project file, obtain the value corresponding to the variable name, and store the value corresponding to the variable name in the fifth list.
[0078] Among them, the content related to the architecture features contained in the project file is the executable files introduced by the API and the content related to the instruction set architecture used when implementing functions, such as embedded assembly (asm), vector functions (_mm_*), architecture keywords (X86, LoongArch), etc.; the target function is a special function related to the architecture, such as System.loadLibrary(), ctypes.cdll.LoadLibrary(), etc. This type of function can load dynamic executable files in Java and Python to complete business functions.
[0079] In the specific implementation, the present invention collects 12 ways of calling executable files by API in advance in the official documents of Java and Python as special functions related to the architecture, and stores them in the loadLibraryList list. For the features related to the instruction set architecture, the present invention uses the instruction set manual, compiler documents and open source software projects to pre-collect 40 embedded assembly features, 368 system call number features, 10348 architecture-related function features, 21 architecture keywords and 205 compilation option features, traverses the projectList list, reads the contents of the files in the list, uses the keywords of the architecture features to retrieve and extract the code containing the above features, for the functions matched to the loadLibraryList list, uses the data flow analysis technology to extract the parameter list used in the function and track the corresponding variable names, and the values corresponding to the extracted variables are stored as architecture features in the archInfoList list, and uses the regular expressions set for different architecture features, that is, the regular matching technology to match the architecture features, and then filter the noise (architecture-independent code, such as Ax86L naming), and store the code fragments containing the architecture features in the architecture component positioning list archInfoList.
[0080] It should be noted that Figure 1 In the above content, the process of retrieving the name and version of the third-party component library, the instruction set architecture characteristics, and the variable name and variable value can be understood as the part of judging whether there are architecture-related software components. For example, if the name and version of the third-party component library cannot be retrieved, it indicates that the name and version of the third-party component library in the architecture-related software components does not exist.
[0081] Step 7: Generate a migration suggestion based on the name and version of the third-party component library in the project configuration file and the code snippet corresponding to the first architecture feature;
[0082] Step 7.1: For the name and version of the third-party component library in the project configuration file, search in the software package granularity knowledge base according to the name and version of the third-party component library. If there is a software package with the same name and version as the third-party component library in the software package granularity knowledge base, it indicates that the software package to be migrated can run in the target architecture, and a prompt message is output, which is used to prompt that the migration of the software package to be migrated has been completed and the migration process is ended; if there is a software package with the same name as the third-party component library but a different version in the software package granularity knowledge base, the generated migration suggestion is to replace the version of the third-party component library in the project configuration file with the version in the software package granularity knowledge base with the same name as the third-party component library but a different version;
[0083] For example, in a Java project, the 1.6 version of the os-maven-plugin third-party library is used in the pom.xml file. However, according to the whitelist library of the collected package granularity, the third-party library only supports the LoongArch architecture after 1.7.1, so the migration strategy given is to upgrade the version to 1.7.1.
[0084] In the specific implementation, this step first determines whether there is an architecture-related third-party component library. If there is an architecture-related third-party component library, the software package granularity knowledge base is matched, that is, according to the name and version of the third-party component library, the software package granularity knowledge base is searched. If there is a software package with the same name and version as the third-party component library in the software package granularity knowledge base, it indicates that the match is successful. If there is a software package with the same name but different version as the third-party component library in the software package granularity knowledge base, it indicates that the match is not successful.
[0085] Step 7.2: for the code snippet corresponding to the first architectural feature, determine the instruction set architecture feature keyword of the code snippet corresponding to the first architectural feature, and search in the code granularity knowledge base according to the instruction set architecture feature keyword and the mapping relationship between the instruction set architecture feature and the code snippets under different instruction set architectures corresponding to the instruction set architecture feature in the pre-built code granularity knowledge base to obtain the code snippets under multiple instruction set architectures corresponding to the instruction set architecture feature keyword, obtain the code snippet corresponding to the target architecture, and then determine the specific standard architecture feature contained in the code snippet corresponding to the target architecture, and judge whether the specific instruction set architecture feature and the standard architecture feature in the code snippet corresponding to the first architectural feature are the same. In the case that the specific instruction set architecture feature and the standard architecture feature in the code snippet corresponding to the first architectural feature are not the same, the migration suggestion generated is: replace the code snippet corresponding to the specific instruction set architecture feature in the code snippet corresponding to the first architectural feature with the code snippet corresponding to the target architecture in the code granularity knowledge base;
[0086] In the specific implementation, it is first determined whether the architecture feature code snippet is included. If the architecture feature code snippet is included, the architecture feature category is determined, that is, the instruction set architecture feature keyword of the code snippet corresponding to the first architecture feature is determined in the previous text, and then the code granularity architecture mapping relationship knowledge base is matched, that is, the search in the code granularity knowledge base is performed in the previous text.
[0087] The migration suggestions generated based on the code granularity library can be explained by the following example: in a section of code lines, the -march=rv64imafdc code is used for configuration, and through the matching of keyword features, it is determined that the compilation option features under the RISCV architecture are used in the section of code, but the target architecture we need to migrate is LoongArch, so according to the knowledge base of the code granularity, the -march keyword is retrieved to obtain the corresponding usage under the LoongArch architecture as -march=loongarch64, so the migration suggestion given by the present invention is that the -march=rv64imafdc configuration is incompatible in the LoongArch architecture environment, and please use -march=loongarch64 to replace it.
[0088] According to the value corresponding to the variable name, a search is performed in the knowledge base at the file granularity. If the value corresponding to the variable name can be found in the knowledge base at the file granularity, it indicates that the executable file corresponding to the value corresponding to the variable name has completed migration and the migration process ends. If the value corresponding to the variable name cannot be found in the knowledge base at the file granularity, it indicates that the executable file corresponding to the value corresponding to the variable name needs to be migrated. In the specific implementation, it is first determined whether there are special functions related to the architecture. In the case that there are special functions related to the architecture, specific function parameters are extracted to obtain the value corresponding to the variable name, and then the file granularity knowledge base is matched. That is, the knowledge base at the file granularity is searched. If the knowledge base at the file granularity can find the value corresponding to the variable name, it indicates that the match is successful. If the knowledge base at the file granularity cannot find the value corresponding to the variable name, it indicates that the match is not successful.
[0089] The code granularity knowledge base includes the mapping relationship between the instruction set architecture features and the code snippets under different instruction set architectures corresponding to the instruction set architecture features. Figure 3 The code granularity knowledge base can be constructed by the following steps:
[0090] Step C1: using the type of instruction set architecture as a keyword, searching in an open source community containing project source code to obtain a submission record, wherein the submission record at least includes a newly added source code revision record, obtaining a revision file list including the newly added source code revision record, searching for the update status file according to the name of the update status file in the revision file list, extracting the revised code snippet from the update status file, and storing the name of the update status file, all the contents of the update status file, and the revised code snippet;
[0091] Among them, the open source community containing the project source code may be the GitHub open source community;
[0092] In the specific implementation, in the GitHub open source community, LoongArch and Riscv commit records (Commits) are searched as keywords, and the source code revision records newly added in the Commits are analyzed and a list of files with revision records is obtained.
[0093] And determine whether the Commits contain architecture keywords. If the Commits do not contain architecture keywords, end the process. If the Commits contain architecture keywords, use the API provided in Github to obtain the file whose file status is set to update modify in the file list. Store the modified code snippets in such files in the modifyCodeList code revision list. At the same time, in order to clarify the exact location of the modified code and the mapping relationship of the multi-instruction set architecture, it is stored in the form of a dictionary. The dictionary format is as follows {"filename": file name of the file in the updated state, "fileContent": file content of the file in the updated state, "modifyCodeList": file content list of the code in the updated state modifyCodeList}. All files in the file list of the revision record that are in the updated state are stored in the contentList file list in the above-mentioned dictionary format.
[0094] Step C2: construct an abstract syntax tree of all codes in the updated state file, and construct an abstract syntax tree of the corrected code fragment, determine a target node of the corrected code fragment in the abstract syntax tree of all codes in the updated state file according to the abstract syntax tree of all codes in the updated state file and the abstract syntax tree of the corrected code fragment, and search for an associated node in the abstract syntax tree of all codes in the updated state file according to the target node, wherein the associated node is a node having the same function as the target node but a different instruction set architecture type, and store the corrected code fragment corresponding to the target node and the code fragment corresponding to the associated node;
[0095] In the specific implementation, the tree-sitter abstract syntax tree extraction technology is used to classify according to the file name, and the corresponding abstract syntax tree analysis process is performed for different programming languages. This process aims to extract the code context containing the architecture keyword, traverse the contentList file list, obtain the file content corresponding to the updated state of the fileContent attribute in its dictionary and establish the abstract syntax tree structure T1, traverse the modified content of the code corresponding to the modifyCodeList attribute, and construct the abstract syntax tree structure of its modified code content as T2. In T1, first identify and locate the code segment position of T2. Subsequently, around the node at this position, a bidirectional recursive traversal strategy is executed. This recursive process takes the encountered functionDef (function definition) node as the natural termination point. The core goal of the recursive traversal is to extract nodes in T1 that match the code node type revised by T2 and contain architectural features, thereby obtaining nodes with the same function but different instruction set architecture types, and storing code segments of other architectures of the same type as the modified code segment in the mappingCodeList collection, and finally storing the dictionary with the content of the modified code segment as the key and mappingCodeList as the value in the archCodeLists list.
[0096] Step C3: Determine whether the modified code snippet corresponding to the target node and the code snippet corresponding to the associated node contain instruction set architecture features. If the modified code snippet corresponding to the target node and the code snippet corresponding to the associated node contain instruction set architecture features, determine the code snippet corresponding to the instruction set architecture feature in the modified code snippet corresponding to the target node and the code snippet corresponding to the associated node, and construct a mapping relationship between the instruction set architecture feature and the code snippets under different instruction set architectures corresponding to the instruction set architecture feature to form a knowledge base of code granularity. If the modified code snippet corresponding to the target node and the code snippet corresponding to the associated node contain instruction set architecture features, return to execute step C1 until the modified code snippet corresponding to the target node and the code snippet corresponding to the associated node contain instruction set architecture features.
[0097] In the specific implementation, the archCodeLists list is traversed, and the architecture type implied in the code content is judged and corrected according to the architecture features, such as compilation option features, vector optimization function features, embedded assembly features, etc. After filtering by regular expressions, only code snippets under multiple different instruction set architectures with architecture features are retained, and the mapping relationship between the instruction set architecture features and the code snippets under different instruction set architectures corresponding to the instruction set architecture features is constructed and stored in the knowledge base mapping relationship table code_map, thereby constructing a code granularity knowledge base.
[0098] Among them, for the migration suggestions obtained above, the tool can provide online visual viewing of the content that needs to be migrated, provide online change forms, and export a complete doc migration report for offline viewing.
[0099] The above description is only a preferred embodiment of the present disclosure and an explanation of the technical principles used. Those skilled in the art should understand that the scope of the invention involved in the embodiments of the present disclosure is not limited to the technical solutions formed by a specific combination of the above-mentioned technical features, but should also cover other technical solutions formed by any combination of the above-mentioned technical features or their equivalent features without departing from the above-mentioned inventive concept. For example, the above-mentioned features are replaced with the technical features with similar functions disclosed in the embodiments of the present disclosure (but not limited to) to form a technical solution.
Claims
1. A method for transplanting multiple programming languages across instruction set architectures, characterized in that: include: Step 1: Upload the software package to be migrated; Step 2: Determine whether the software package to be migrated has completed migration. If the software package to be migrated has completed migration, the migration process ends; If the software package to be migrated has not completed migration, execute step 3; Step 3: Determine the type of the software package to be migrated. According to the suffix of the software package to be migrated, determine whether the type of the software package to be migrated is a binary package or a software source code compressed package. If the type of the software package to be migrated is a binary package, execute step 4. If the type of the software package to be migrated is a software source code compressed package, execute step 5. Step 4: decompress the software package to be migrated to obtain a file list of the software package to be migrated, and determine whether the file list of the software package to be migrated includes the first executable file. If the file list of the software package to be migrated does not include the first executable file, it indicates that the software package to be migrated does not need to be migrated, and the migration process ends. In the case where the first executable file is included in the file list of the software package to be migrated, the first executable file is obtained, and according to the name and version of the first executable file, the names and versions of all the first executable files are matched with the names and versions of the executable files in the pre-built file granularity knowledge base. If the names and versions of all the first executable files match the names and versions of the executable files in the pre-built file granularity knowledge base, it indicates that the software package to be migrated is compatible with the target architecture, and the target architecture is the instruction set architecture to which the software package to be migrated is about to be migrated. The compatibility of the software package to be migrated with the target architecture indicates that the migration of the software package to be migrated has been completed, and the migration process ends; if the names and versions of all the first executable files do not match the names and versions of the executable files in the pre-built file granularity knowledge base, it indicates that the software package to be migrated needs to be migrated, and the file list of the software package to be migrated is output; the file granularity knowledge base includes target information of multiple executable files, and the target information includes the name of the executable file, the version of the executable file, the direct dependent file of the executable file, the transitive dependent file of the executable file, and the instruction set architecture to which the executable file belongs; Step 5: decompress the software package to be migrated to obtain the decompressed file, and obtain the project configuration file and engineering file in the software package to be migrated according to the name and version of the second executable file in the decompressed file and the pre-built file granularity knowledge base, wherein the engineering file is a file with a file suffix of a programming language file suffix; Step 6: Obtain the name and version of the third-party component library in the project configuration file, and obtain the code snippet corresponding to the first architecture feature, the code snippet corresponding to the first architecture feature includes the code snippet corresponding to the instruction set architecture feature in the project configuration file and the code snippet corresponding to the instruction set architecture feature in the project file, and obtain the variable name corresponding to the target function in the project file and the value corresponding to the variable name, the target function is a function that can load an executable file in a preset programming language, and the value corresponding to the variable name is the name of the executable file; Step 7: Generate migration suggestions based on the name and version of the third-party component library in the project configuration file and the code snippet corresponding to the first architectural feature Step 7.1: Search the software package granularity knowledge base for the name and version of the third-party component library in the project configuration file according to the name and version of the third-party component library. If there is a software package with the same name and version as the third-party component library in the software package granularity knowledge base, it indicates that the software package to be migrated can be run in the target architecture, and a prompt message is output, which is used to prompt that the software package to be migrated has completed migration and the migration process is ended; If there is a package in the package granularity repository that has the same name as the third-party component library but a different version, the generated migration suggestion is to replace the version of the third-party component library in the project configuration file with the version in the package granularity repository that has the same name as the third-party component library but a different version; The software package granularity knowledge base includes software information of multiple software packages, wherein the software information includes names of items in the software package, versions of the software package, operating systems that the software package can run on, and instruction set architectures that the software package can run on; Step 7.2: For the code snippet corresponding to the first architectural feature, determine the instruction set architecture feature keyword of the code snippet corresponding to the first architectural feature, and search in the code granularity knowledge base according to the instruction set architecture feature keyword and the mapping relationship between the instruction set architecture feature and the code snippets under different instruction set architectures corresponding to the instruction set architecture feature in the pre-built code granularity knowledge base to obtain the code snippets under multiple instruction set architectures corresponding to the instruction set architecture feature keyword, obtain the code snippet corresponding to the target architecture, and then determine the specific standard architecture feature contained in the code snippet corresponding to the target architecture, judge whether the specific instruction set architecture feature and the standard architecture feature in the code snippet corresponding to the first architectural feature are the same, and determine the specific instruction set architecture feature in the code snippet corresponding to the first architectural feature. When the feature of the architecture is different from the standard architecture feature, the generated migration suggestion is: replace the code snippet corresponding to the specific instruction set architecture feature in the code snippet corresponding to the first architecture feature with the code snippet corresponding to the target architecture in the code granularity knowledge base; the code granularity knowledge base includes the mapping relationship between the instruction set architecture feature and the code snippets under different instruction set architectures corresponding to the instruction set architecture feature; according to the value corresponding to the variable name, search in the file granularity knowledge base; if the value corresponding to the variable name can be found in the file granularity knowledge base, it indicates that the executable file corresponding to the value corresponding to the variable name has completed the migration and the migration process ends; if the value corresponding to the variable name is not found in the file granularity knowledge base, it indicates that the executable file corresponding to the value corresponding to the variable name needs to be migrated.
2. The multi-programming language cross-instruction set architecture transplantation method according to claim 1, characterized in that: The software package granularity knowledge base is constructed by the following steps: Step A1: using the type of instruction set architecture as a keyword, searching in an open source community containing software packages, obtaining multiple software packages of each instruction set architecture type, and storing the multiple software packages of each instruction set architecture type; Step A2: For each software package, extract the name of the software package to obtain software information, which includes the name of the project in the software package, the version of the software package, the operating system that the software package can run on, and the instruction set architecture that the software package can run on. The software information of all software packages constitutes a software package granularity knowledge base.
3. The multi-programming language cross-instruction set architecture transplantation method according to claim 1, characterized in that: The document granularity knowledge base is constructed by the following steps: Step B1: using the type of instruction set architecture as a keyword, searching in an open source community containing software packages, obtaining multiple software packages of each instruction set architecture type, and storing the multiple software packages of each instruction set architecture type; Step B2: decompress each software package to obtain all files in each software package. For all files in each software package, determine whether there is an executable file among all files of the software package. If there is an executable file among all files of the software package, obtain the instruction set architecture to which the executable file belongs and the direct dependent file of the executable file according to the attributes of the executable file. The direct dependent file is a file directly called by the executable file at runtime. The direct dependent file is parsed to obtain a transitive dependent file. The transitive dependent file is a file directly called by the direct dependent file at runtime, and the transitive dependent file is a file indirectly called through the direct dependent file when the executable file is running. The name of the executable file, the version of the executable file, the direct dependent file of the executable file, the transitive dependent file of the executable file and the instruction set architecture to which the executable file belongs constitute the target information of the executable file. The target information of all executable files constitutes a knowledge base of file granularity. If there is no executable file among all files of the software package, return to execute step B1 until there is an executable file among all files of the software package.
4. The multi-programming language cross-instruction set architecture transplantation method according to claim 1, characterized in that: The code granularity knowledge base is constructed by the following steps: Step C1: using the type of instruction set architecture as a keyword, searching in an open source community containing project source code to obtain a submission record, wherein the submission record at least includes a newly added source code revision record, obtaining a revision file list including the newly added source code revision record, searching for the update status file according to the name of the update status file in the revision file list, extracting the revised code snippet from the update status file, and storing the name of the update status file, all the contents of the update status file, and the revised code snippet; Step C2: construct an abstract syntax tree of all codes in the updated state file, and construct an abstract syntax tree of the corrected code fragment, determine a target node of the corrected code fragment in the abstract syntax tree of all codes in the updated state file according to the abstract syntax tree of all codes in the updated state file and the abstract syntax tree of the corrected code fragment, and search for an associated node in the abstract syntax tree of all codes in the updated state file according to the target node, wherein the associated node is a node having the same function as the target node but a different instruction set architecture type, and store the corrected code fragment corresponding to the target node and the code fragment corresponding to the associated node; Step C3: Determine whether the modified code snippet corresponding to the target node and the code snippet corresponding to the associated node contain instruction set architecture features. If the modified code snippet corresponding to the target node and the code snippet corresponding to the associated node contain instruction set architecture features, determine the code snippet corresponding to the instruction set architecture features in the modified code snippet corresponding to the target node and the code snippet corresponding to the associated node, and construct a mapping relationship between the instruction set architecture features and the code snippets under different instruction set architectures corresponding to the instruction set architecture features to form a knowledge base of code granularity. If the modified code snippet corresponding to the target node and the code snippet corresponding to the associated node contain instruction set architecture features, return to execute step C1 until the modified code snippet corresponding to the target node and the code snippet corresponding to the associated node contain instruction set architecture features.
5. The multi-programming language cross-instruction set architecture transplantation method according to claim 1, characterized in that: Step 2 is implemented in the following ways: A search is performed in a pre-built software package granularity knowledge base at least according to the name of the software package to be migrated and the version of the software package to be migrated. If the software package granularity knowledge base contains a software package with the same name and version as the software package to be migrated, it indicates that the migration of the software package to be migrated has been completed. If the software package granularity knowledge base does not contain a software package with the same name and version as the software package to be migrated, it indicates that the migration of the software package to be migrated has not been completed.
6. The multi-programming language cross-instruction set architecture transplantation method according to claim 1, characterized in that: Step 5 is implemented by the following steps: Step 5.1: decompress the software package to be migrated to obtain a file list of the software package to be migrated, divide the files in the file list of the software package to be migrated according to the file suffixes, store the compressed package type files in a first list, store the second executable file in a second list, and store the other files in the file list of the software package to be migrated except the compressed package type files and the second executable file in a third list, wherein the first list, the second list and the third list are all different; Step 5.2: Process the compressed package type files and executable files, perform multiple iterative decompressions on the compressed package type files until all files in the compressed package type files are completely decompressed, store the second executable file in the decompressed files into the second list, and store other files in the decompressed files except the second executable file into the third list; For the second executable files in the second list, according to the names and versions of the second executable files, the names and versions of all the second executable files are matched with the names and versions of the executable files in the pre-built file granularity knowledge base. If the names and versions of all the second executable files match the names and versions of the executable files in the pre-built file granularity knowledge base, it indicates that the software package to be migrated is compatible with the target architecture. The compatibility of the software package to be migrated with the target architecture indicates that the migration of the software package to be migrated has been completed, and the migration process ends. If the names and versions of all the second executable files do not match the names and versions of the executable files in the pre-built file granularity knowledge base, it indicates that the software package to be migrated needs to be migrated. If the names and versions of all the second executable files do not match the names and versions of the executable files in the pre-built file granularity knowledge base, execute step 5.
3. Step 5.3: Process the files in the third list. Specifically, from the files in the third list, obtain the project configuration files included in the software package to be migrated, and use the files with the suffix of the programming language file as project files.
7. The multi-programming language cross-instruction set architecture transplantation method according to claim 1, characterized in that: Step 6 is implemented by the following steps: Step 6.1: Determine whether the project configuration file contains the name and version of the third-party component library. If the project configuration file does not contain the name and version of the third-party component library, the migration process ends. If the project configuration file contains the name and version of the third-party component library, obtain the name and version of the third-party component library contained in the project configuration file, and store the name and version of the third-party component library in the fourth list; determine whether the project configuration file contains code snippets corresponding to the instruction set architecture features. If the project configuration file contains code snippets corresponding to the instruction set architecture features, store the code snippets corresponding to the instruction set architecture features in the fifth list, and the fourth list is different from the fifth list; if the project configuration file does not contain code snippets corresponding to the instruction set architecture features, the migration process ends; Step 6.2: Determine whether the code of the project file contains code snippets corresponding to the instruction set architecture feature. If the code of the project file contains code snippets corresponding to the instruction set architecture feature, use the instruction set architecture feature as a keyword to obtain the code snippets corresponding to the instruction set architecture feature in the code of the project file, and store them in the fifth list. The code snippets corresponding to the instruction set architecture feature in the project configuration file and the code snippets corresponding to the instruction set architecture feature in the project file in the fifth list are the code snippets corresponding to the first architecture feature. If the code of the project file does not contain the code snippets corresponding to the instruction set architecture feature, the migration process ends. According to the pre-set target function, obtain the variable name corresponding to the target function in the project file, obtain the value corresponding to the variable name, and store the value corresponding to the variable name in the fifth list.
Citation Information
Cited By
Software package source code optimization method of cross-instruction-set architecture
CN120371387A
Python dependency library API migration method based on large language model
CN120429008A
RISC-V-oriented software source code transplantation and deployment method and system
CN120723300A
