Program transplantation method and device

By generating a dictionary to map the identifiers of Golang code segments to the relationship between the source code segments, the compatibility problem of Golang when porting to domestic CPU architecture is solved, an efficient program porting method is implemented, and the porting efficiency is improved.

CN114741116BActive Publication Date: 2025-09-23UNIONTECH SOFTWARE TECH CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202210323623.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-03-29
Publication Date
2025-09-23
Estimated Expiration
2042-03-29

AI Technical Summary

Technical Problem

In the existing technology, the official version of the Golang language does not support the domestic CPU architectures sw64 and loongarch64, resulting in a large amount of manual adjustment of the Golang code when porting containers and cloud-native related software on these architectures. In addition, the definition locations and scopes of functions, structures, constants, and variables between different versions of Golang vary greatly, making it easy for undefined or duplicate definitions to occur.

Method used

This paper provides a program porting method that maps the identifiers of Golang code segments to the corresponding relationships between source code segments by generating a dictionary. The code segments are written directly into files using the dictionary query and overloading mechanism, realizing the classified storage and query of functions, structures, constants, and variables, thus improving porting efficiency.

Benefits of technology

During the program porting process, the rewritability of dictionaries enabled overloading of various types of objects, which improved the efficiency of program porting, reduced the porting time from days to minutes, and solved the compatibility issues between different Golang versions.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114741116B_ABST
    Figure CN114741116B_ABST
Patent Text Reader

Abstract

The present invention discloses a program transplantation method, comprising: sequentially obtaining code segments from a target program to be transplanted; determining a first type and a first identifier of the code segment; determining whether the first identifier is included in each second identifier in a dictionary corresponding to the first type, the dictionary storing a correspondence between the second identifier and the first source code segment; and if so, writing the first identifier and the corresponding first source code segment stored in the dictionary into a file, which is then transplanted to a target CPU for execution. The program transplantation method of the present invention significantly improves transplantation efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a program transplantation method, apparatus, computing device and readable storage medium. Background Art

[0002] Currently, most open source projects in the container and cloud-native operating system technology fields are written in Golang. However, the official version of Golang does not support the domestic CPU architectures sw64 and loongarch64. Therefore, porting container and cloud-native software to these architectures requires extensive Golang code implementation. Due to the rapid evolution of Golang versions, each open source project depends on a different version of Golang. Applications that rely on a specific version of Golang must use that specific Golang library. The Golang compiler source code provided by the vendor is a fixed version, and the definition location and scope of functions, structures, constants, and variables often differ significantly between different versions of Golang. Furthermore, Golang does not support overloading, making it very easy for functions, structures, constants, and variables to be undefined or duplicated. Therefore, the workload of implementing architecture support for each version that each open source project depends on is difficult to estimate.

[0003] To this end, there is an urgent need for a program porting method to enable the porting of programs that rely on specific Golang version libraries on domestic CPUs such as sw64 and loongarch64 architectures. Summary of the Invention

[0004] To this end, the present invention provides a program transplantation method in an effort to solve or at least alleviate the above problems.

[0005] According to one aspect of the present invention, a program transplantation method is provided, the method comprising: sequentially obtaining code segments in a target program to be transplanted; determining a first type and a first identifier of the code segment; judging whether each second identifier of a dictionary corresponding to the first type includes the first identifier, the dictionary storing a correspondence between the second identifier and the first source code segment; and if so, writing the first identifier stored in the dictionary and its corresponding first source code segment into a file, the file being used to transplant to a target CPU for execution.

[0006] Optionally, the program transplantation method according to the present invention further includes: writing the code segment into a file if the second identifiers in the dictionary corresponding to the first type do not include the first identifier.

[0007] Optionally, the program transplantation method according to the present invention further includes: determining whether there are other target programs to be transplanted; if so, continuing to execute the step of sequentially obtaining code segments in the target program to be transplanted.

[0008] Optionally, in the program transplantation method according to the present invention, the dictionary is generated in the following manner: obtaining the second source code segments in the predetermined source code library in sequence; determining the second type of the second source code segment; escaping the second source code segment to obtain the first source code segment; using the second identifier of the second source code segment as a key and the first source code segment as the value corresponding to the key in the dictionary corresponding to the second type.

[0009] Optionally, in the program transplantation method according to the present invention, the files include files of syscall type, error type, sysnums type, and type type, wherein the step of writing the first identifier stored in the dictionary and its corresponding first source code segment into the file includes: writing the first identifier in the dictionary and its corresponding first source code segment into any type of file.

[0010] Optionally, in the program transplantation method according to the present invention, the first type and the second type include functions, structures, constants and variables.

[0011] Optionally, in the program transplantation method according to the present invention, the target CPU includes a CPU of sw64 architecture or a CPU of loongarch64 architecture.

[0012] Optionally, in the program transplantation method according to the present invention, the target program is a program written in Golang language.

[0013] Optionally, in the program transplantation method according to the present invention, the source code library includes the source code of the golang compiler provided by the target CPU manufacturer.

[0014] According to another aspect of the present invention, a program transplantation device is provided, which includes: a program acquisition module, suitable for sequentially acquiring code segments in a target program to be transplanted; a type and identifier determination module, suitable for determining a first type and a first identifier of the code segment; a dictionary query module, suitable for judging whether the first identifier is included in each second identifier of a dictionary corresponding to the first type; and a file writing module, suitable for writing the first identifier stored in the dictionary and its corresponding first source code segment into a file when the first identifier is included in each second identifier of the dictionary corresponding to the first type, and also suitable for writing the code segment into a file when the first identifier is not included in each second identifier of the dictionary corresponding to the first type.

[0015] According to another aspect of the present invention, a computing device is provided, comprising: at least one processor; and a memory storing program instructions, wherein the program instructions are configured to be suitable for execution by the at least one processor, and the program instructions include instructions for executing the program transplantation method described above.

[0016] According to another aspect of the present invention, a readable storage medium storing program instructions is provided. When the program instructions are read and executed by a computing device, the computing device executes the method described above.

[0017] According to the technical solution of the present invention, a program transplantation method is provided. After determining the first type and first identifier of the code segment in the target program to be transplanted, the first identifier of the code segment is queried in a dictionary to determine the content to be written into the file. If the dictionary corresponding to the first type includes the first identifier, the content corresponding to the code segment included in the dictionary is directly written into the file, which greatly improves the transplantation efficiency in program transplantation.

[0018] Furthermore, the program migration method of the present invention achieves overloading of various types of objects through the rewritability of the dictionary. Functions, structures, constants, and variables are classified and stored in the dictionary, which facilitates querying in the dictionary during the program migration process, thereby improving the efficiency of program migration.

[0019] The above description is only an overview of the technical solution of the present invention. In order to more clearly understand the technical means of the present invention, it can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of the present invention more obvious and easy to understand, the specific implementation methods of the present invention are specifically listed below. BRIEF DESCRIPTION OF THE DRAWINGS

[0020] To achieve the above and related purposes, certain illustrative aspects are described herein in conjunction with the following description and accompanying drawings, which indicate various ways in which the principles disclosed herein may be practiced, and all aspects and their equivalents are intended to fall within the scope of the claimed subject matter. The above and other objects, features, and advantages of the present disclosure will become more apparent by reading the following detailed description in conjunction with the accompanying drawings. Throughout this disclosure, the same reference numerals generally refer to the same parts or elements.

[0021] Figure 1 A schematic diagram of a computing device 100 according to one embodiment of the present invention is shown;

[0022] Figure 2 A flowchart of a program transplantation method 200 according to an embodiment of the present invention is shown;

[0023] Figure 3 A flowchart of a method 300 for building a dictionary according to an embodiment of the present invention is shown;

[0024] Figure 4 A schematic diagram of a source code segment after escape processing according to an embodiment of the present invention is shown;

[0025] Figure 5 A schematic diagram of a file after transplantation according to an embodiment of the present invention is shown;

[0026] Figure 6 FIG. 6 is a flow chart showing a method 600 for constructing a dictionary according to another embodiment of the present invention;

[0027] Figure 7 A schematic flow chart showing a program transplantation method 700 according to another embodiment of the present invention; and

[0028] Figure 8 FIG. 8 is a schematic diagram showing a program transplantation apparatus 800 according to an embodiment of the present invention. DETAILED DESCRIPTION

[0029] Exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although exemplary embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be limited by the embodiments set forth herein. Rather, these embodiments are provided to enable a more thorough understanding of the present disclosure and to fully convey the scope of the present disclosure to those skilled in the art.

[0030] Figure 1 is a schematic diagram of an example computing device 100. Figure 1 As shown, in a basic configuration 102, computing device 100 typically includes system memory 106 and one or more processors 104. A memory bus 108 may be used for communication between processor 104 and system memory 106.

[0031] Depending on the desired configuration, the processor 104 can be any type of processor, including but not limited to: a microprocessor (UP), a microcontroller (UC), a digital signal processing unit (DSP), or any combination thereof. The processor 104 can include one or more levels of cache, such as a level 1 cache 110 and a level 2 cache 112, a processor core 114, and registers 116. An example processor core 114 can include an arithmetic logic unit (ALU), a floating point unit (FPU), a digital signal processing core (DSP core), or any combination thereof. An example memory controller 118 can be used with the processor 104, or in some implementations, the memory controller 118 can be an internal part of the processor 104.

[0032] Depending on the desired configuration, system memory 106 can be any type of memory, including but not limited to volatile memory (such as RAM), non-volatile memory (such as ROM, flash memory, etc.), or any combination thereof. System memory 106 can include an operating system 120, one or more applications 122, and program data 124. In some embodiments, application 122 can be arranged to execute instructions on the operating system by one or more processors 104 using program data 124.

[0033] Computing device 100 also includes storage 132 , which includes removable storage 136 and non-removable storage 138 .

[0034] The computing device 100 may also include a storage interface bus 134. The storage interface bus 134 enables communication from storage devices 132 (e.g., removable storage 136 and non-removable storage 138) to the basic configuration 102 via the bus / interface controller 130. At least a portion of the operating system 120, applications 122, and data 124 may be stored on the removable storage 136 and / or the non-removable storage 138 and loaded into the system memory 106 via the storage interface bus 134 when the computing device 100 is powered on or when an application 122 is to be executed, and executed by the one or more processors 104.

[0035] The computing device 100 may also include an interface bus 140 that facilitates communication from various interface devices (e.g., output devices 142, peripheral interfaces 144, and communication devices 146) to the basic configuration 102 via the bus / interface controller 130. Example output devices 142 include an image processing unit 148 and an audio processing unit 150. These can be configured to facilitate communication with various external devices such as a display or speakers via one or more A / V ports 152. Example peripheral interfaces 144 may include a serial interface controller 154 and a parallel interface controller 156, which can be configured to facilitate communication with external devices such as input devices (e.g., a keyboard, mouse, pen, voice input device, touch input device) or other peripherals (e.g., a printer, scanner, etc.) via one or more I / O ports 158. Example communication devices 146 may include a network controller 160, which can be arranged to facilitate communication with one or more other computing devices 162 via a network communication link via one or more communication ports 164.

[0036] A network communication link can be an example of a communication medium. Communication media can generally be embodied as computer-readable instructions, data structures, program modules in a modulated data signal such as a carrier wave or other transmission mechanism, and can include any information delivery medium. A "modulated data signal" can be a signal in which one or more of a data set or a change therein can be carried out in a manner that encodes information in the signal. As non-limiting examples, communication media can include wired media such as a wired network or a dedicated line network, and various wireless media such as sound, radio frequency (RF), microwave, infrared (IR) or other wireless media. The term computer-readable medium as used herein can include both storage media and communication media.

[0037] The computing device 100 can be implemented as a personal computer including desktop and notebook computer configurations. Of course, the computing device 100 can also be implemented as part of a small-sized portable (or mobile) electronic device, such as a cellular phone, a digital camera, a personal digital assistant (PDA), a personal media player device, a wireless network browsing device, a personal head-mounted device, an application-specific device, or a hybrid device that can include any of the above functions. It can even be implemented as a server, such as a file server, a database server, an application server, and a web server. The embodiments of the present invention are not limited to this.

[0038] In one embodiment according to the present invention, a computing device 100 is configured to execute the program transplantation method according to the present invention. The program data of the computing device 100 includes a plurality of program instructions for executing the program transplantation method according to the present invention, and these program instructions can instruct a processor to execute the program transplantation method according to the present invention.

[0039] According to another embodiment of the present invention, the application arranged on the operating system 120 includes a program transplantation device 800, which contains multiple program instructions for executing the program transplantation method of the present invention, so that the program transplantation method of the present invention can be executed in the program transplantation device 800.

[0040] Figure 2 FIG. 2 shows a flow chart of a program transplantation method 200 according to an embodiment of the present invention. The program transplantation method 200 may be executed in a computing device (eg, the aforementioned computing device 100). Figure 2 As shown, the method 200 begins at step S210 .

[0041] In step S210, code segments in the target program to be transplanted are obtained in sequence.

[0042] According to an embodiment of the present invention, when porting a Golang program, the Unix directory of the directly downloaded open source project does not contain files related to the sw64 or loongarch64 architecture. Therefore, the target program to be ported can be the program missing from the downloaded open source project. For example, the target program to be ported can be the mips64el library of the open source project. The Unix directory is the directory src / cmd / vendor / golang.org / x / sys / unix / in the Golang source code.

[0043] Optionally, a code segment can be a line of code or multiple lines of code. Specifically, a line in the target program to be transplanted is read each time, and then it can be determined whether the reading is complete by judging whether the line includes a bracket. If a line in the target program is read that only includes one side of a complete bracket (such as "(", "{"), it can be determined that the reading is not complete, and the next line is read until the other side of a complete bracket (such as ")", "}"). The usual starting method of a function is func abc(){, where abc is taken as an example to represent a function named abc. For example, if a line of code is read as func abc(){, it can be determined that the function includes "{" in this line, and the function has not ended. It can be determined that the reading is not complete, and the next line is read until there is "}" in the line read. In this way, the code segment is multiple lines of code, and the subsequent steps need to process the code segment including multiple lines of code together. For another example, if a line of code is read as func abc(){...}, the function is a single-line function, that is, the complete function is included in the line of code, then the code segment is a line of code.

[0044] Then, in step S220 , a first type and a first identifier of the code segment are determined, wherein the first type includes functions, structures, constants, and variables.

[0045] In Golang, you can define functions with func, structures with type, constants with const, and variables with var. The first identifier is the name used to name the code segment type. For a code segment whose first type is a function, the first identifier is the function name; for a code segment whose first type is a structure, the first identifier is the structure name; for a code segment whose first type is a constant, the first identifier is the constant name; and for a code segment whose first type is a variable, the first identifier is the variable name.

[0046] Then, in step S230, it is determined whether each second identifier in the dictionary corresponding to the first type of code segment includes the first identifier. The dictionary stores a correspondence between the second identifier and the first source code segment, that is, the dictionary stores one or more second identifiers, each corresponding to a first source code segment.

[0047] According to one embodiment of the present invention, if the first type of a code segment is a function, a search is performed in the dictionary corresponding to the function to determine whether the first identifier corresponding to the code segment exists. If the first type of a code segment is a structure, a search is performed in the dictionary corresponding to the structure to determine whether the first identifier corresponding to the code segment exists. If the first type of a code segment is a constant, a search is performed in the dictionary corresponding to the constant to determine whether the first identifier corresponding to the code segment exists. If the first type of a code segment is a variable, a search is performed in the dictionary corresponding to the variable to determine whether the first identifier corresponding to the code segment exists.

[0048] The following describes how to construct the dictionary. Figure 3 The flowchart of the method 300 for constructing a dictionary according to an embodiment of the present invention is shown. The flowchart of the method 300 begins with step S310.

[0049] In step S310, second source code segments in a predetermined source code library are sequentially obtained.

[0050] Optionally, the source code library may include the source code of a fixed version of the Golang compiler, and may also include the source code of the project mips or the source code of the project's general architecture. If the target program to be ported is ported to a CPU of the sw64 architecture, the source code of the fixed version of the Golang compiler is used as the primary reference, the source code of the project mips is used as the secondary reference after the primary reference, and the source code of the project's general architecture is used as the tertiary reference after the second reference to generate the dictionary. Since the manufacturer does not provide the source code of each version of the Golang compiler, but only provides the source code of a fixed version of the Golang compiler, that is, the Golang version that the open source project depends on is not necessarily the fixed version, therefore, the source code of the second reference and / or the third reference is also used as the content in the predetermined source code library.

[0051] Optionally, the source code library can include the source code of a fixed version of the Golang compiler, or the source code of the project arm64 or the source code of the project's general architecture. If the target program to be ported is ported to a CPU of the loongarch64 architecture, the source code of the fixed version of the Golang compiler is used as the primary reference, the source code of the project arm64 as the secondary reference, and the source code of the project's general architecture as the tertiary reference to generate the dictionary.

[0052] According to an embodiment of the present invention, a dictionary is generated using an overloading approach, meaning that content written later in the dictionary will overwrite content written earlier. Therefore, the order for obtaining source code segments from the predetermined source code library is as follows: first, obtain the second source code segment from the third reference, then the second source code segment from the second reference, and finally, obtain the second source code segment from the primary reference. Thus, if content written earlier overlaps with content written later, the later content will prevail.

[0053] Here, the second source code segment can be a line of code or multiple lines of code. Specifically, a line of source code in a predetermined source code library is read each time, and then it can be determined whether the reading is complete by judging whether the line includes brackets. If a line in the source code is read that only includes one side of a complete bracket (such as "(", "{"), it can be determined that the reading is not complete, and the next line is read until the other side of a complete bracket (such as ")", "}"). The usual starting method of a function is func abc(){, where abc is taken as an example to represent a function named abc. For example, a line of code is read as func abc(){, it can be judged that the function includes "{" in this line, and the function has not ended. It can be determined that the reading is not complete, and the next line is read until there is "}" in the line read. In this way, the second source code segment is multiple lines of code, and the subsequent steps need to process the second source code segment including multiple lines of code together. For another example, if a line of code read is func abc(){...}, the function is a single-line function, that is, the line of code includes a complete function, then the second source code segment is a line of code.

[0054] Then, in step S320 , a second type of the second source code segment is determined, where the second type includes functions, structures, constants, and variables.

[0055] According to an embodiment of the present invention, if the second source code segment includes func, it can be determined that the second type of the second source code segment is a function; if the second source code segment includes type, it can be determined that the second type of the second source code segment is a structure; if the second source code segment includes const, it can be determined that the second type of the second source code segment is a constant; if the second source code segment includes var, it can be determined that the second type of the second source code segment is a variable.

[0056] Then, in step S330, the second source code segment is escaped.

[0057] Subsequently, in step S340, the second identifier of the second source code segment is used as a key (called key), and the escaped second source code segment is stored as a value corresponding to the key (called value) in a dictionary corresponding to the second type of the second source code segment.

[0058] Specifically, each type of the second source code segment corresponds to a dictionary, and the second type of the second source code segment includes functions, structures, constants, and variables. Therefore, the four second types of the second source code segment correspond to four dictionaries, including a dictionary for storing source codes of the second type being function type, a dictionary for storing source codes of the second type being structure type, a dictionary for storing source codes of the second type being constant type, and a dictionary for storing source codes of the second type being variable type. The second identifier of the second source code segment is used as a key, and the first source code segment obtained after escaping the second source code segment is stored as a value in the corresponding dictionary. For example, if the second type of the second source code segment is a function, the second identifier of the second source code segment is used as a key, and the first source code segment obtained after escaping the second source code segment is stored as a value in the dictionary for storing source codes of the second type being function type.

[0059] Figure 4 A schematic diagram of a source code segment after escape processing according to an embodiment of the present invention is shown. The source code segment after escape processing is stored in the dictionary as a value together with its corresponding key.

[0060] According to the program transplantation method of the present invention, since when the Golang program is transplanted, the unix directory in the downloaded open source project does not have the relevant files of the domestic Shenwei architecture sw64 and the Longxin architecture loongarch64, and the Golang versions relied on by different open source projects are different. Therefore, the source code corresponding to the main reference, the second reference and the third reference obtained are divided into four types (i.e., functions, structures, constants and variables) and overloaded to generate four dictionaries corresponding to the four types. In this way, it is convenient to query the identifier corresponding to the code segment in the target program to be transplanted in the corresponding dictionary during the program transplantation process, and the efficiency of program transplantation can be greatly improved by generating a good dictionary. The Golang language itself does not support overloading, and the overloading of various types of Golang codes is achieved through the rewritability of the dictionary.

[0061] Then, in step S240, if each second identifier in the dictionary corresponding to the first type of code segment includes the first identifier, the first identifier stored in the dictionary and its corresponding first source code segment are written into a file, wherein the file is used to be transplanted to the target CPU for execution.

[0062] Specifically, the first identifier of the code segment is found in the key stored in the dictionary corresponding to the first type of the code segment. If it is found, the key and value corresponding to the first identifier stored in the dictionary are used to replace the content of the code segment and write it into the file. The files include files of the syscall type, error type, sysnums type, and type type.

[0063] According to an embodiment of the present invention, the target program to be transplanted includes four types, specifically including syscall, errors, SYSnums, and types. When writing to a file, the definition position is not sensitive, but duplicate definitions cannot exist. For example, if the target program to be transplanted is of type error, when writing to a file, it can be written to any type of file, that is, to a file of type syscall, errors, SYSnums, or types, without restriction. However, it cannot appear repeatedly in multiple files, ultimately forming the transplanted function, structure, constant, and variable files. Figure 5 FIG. 1 shows a schematic diagram of files after transplantation according to an embodiment of the present invention. Figure 5 As shown, the transplanted files include syscall, errors, SYSnums, or types.

[0064] Optionally, after writing the first identifier in the dictionary and the corresponding first source code segment into a file, the file is stored in a Unix directory so that a project including the file can be run in a target CPU.

[0065] Then, in step S250 , if the dictionary corresponding to the first type of the code segment does not include the first identifier, that is, the first identifier is not found in the dictionary, no replacement is performed and the code segment is directly written into the file.

[0066] Optionally, after writing the code segment into a file, the file is stored in a unix directory so that a project including the file can be run in a target CPU.

[0067] In order to better illustrate the complete implementation process of the present invention, the dictionary construction method and program transplantation method of the present invention are described in detail below. Figure 6 FIG. 6 is a flow chart showing a method 600 for constructing a dictionary according to another embodiment of the present invention. Figure 6 As shown, the method 600 starts at step S601 .

[0068] In step S601, source code in a predetermined source code library is obtained.

[0069] Then, in step S602, a line of source code in the predetermined source code library is read. The specific contents of steps S601-S602 can refer to the description of step S310 above.

[0070] Then, in step S603, the type of the source code line is identified, and the types include function, structure, constant and variable. The specific content of this step can refer to the description of the above step S320.

[0071] Then, in step S604, it is determined whether the read source code line is complete.

[0072] Specifically, whether the line of source code read is complete can be determined by judging whether the brackets are complete. Wherein, complete brackets mean that the line of source code includes "(" and ")" at the same time, or includes "{" and "}" at the same time. If the line of source code does not include brackets or the brackets included in the line of source code are complete, it can be determined that the line of source code is complete, and step S606 is executed. Otherwise, the line of source code is determined to be incomplete, indicating that the line of source code only includes one side of a complete bracket, i.e., "(" or "{", and step S605 is executed until the line of source code read includes the ")" or "}" corresponding to the "(" or "{".

[0073] In step S605, the source code line is recorded in the cache. Then, the process returns to step S602.

[0074] In step S606, the source code segment in the cache is escaped. The specific content of this step can be referred to the description of the above step S330.

[0075] Then, in step S607, the identifier of the source code segment is used as a key, and the escaped source code segment is written as the value corresponding to the key into the dictionary corresponding to the source code segment type. For details of this step, please refer to the description of step S340 above.

[0076] Then, in step S608, it is determined whether all source codes in the predetermined source code library have been read. If all source codes in the predetermined source code library have been read, step S609 is executed. If there are source codes in the predetermined source code library that have not been read, the process returns to step S602.

[0077] In step S609, it is determined whether there are other predetermined source code libraries. If there are other predetermined source code libraries that need to be processed, the method returns to step S602 and obtains the source code in the new predetermined source code library. If there are no other predetermined source code libraries, the method 600 is completed.

[0078] Figure 7 FIG. 7 is a flow chart showing a program transplantation method 700 according to another embodiment of the present invention. Figure 7 As shown, the method 700 starts at step S701 .

[0079] In step S701, the target program to be transplanted is obtained.

[0080] Then, in step S702, a line of code in the target program is read. The specific contents of steps S701-S702 can refer to the description of step S210 above.

[0081] Then, in step S703, the type and identifier of the line of code are identified, where types include functions, structures, constants, and variables. For details about this step, refer to the description of step S220 above. Then, in step S704, it is determined whether the identifier exists in the dictionary key. For details about this step, refer to the description of step S230 above. If not, step S705 is executed. If so, step S706 is executed.

[0082] In step S705, the read line of code is written into a file. For details of this step, please refer to the description of step S250. After step S705, step S707 is executed.

[0083] In step S706, the identifier and its corresponding content in the dictionary are written into the file. The specific content of this step can be referred to the description in the above step S240. After step S706, step S705 is executed.

[0084] Then, in step S707, it is determined whether the target program to be transplanted has been read. If the reading is completed, the process proceeds to step S708; if not, the process returns to step S702.

[0085] In step S708, it is determined whether there are other target programs to be transplanted. If so, the process returns to step S701 to obtain a new target program to be transplanted. If not, the process of method 700 is completed.

[0086] Figure 8 A schematic diagram of a program transplantation apparatus 800 according to an embodiment of the present invention is shown. The program transplantation apparatus 800 resides in a computing device (eg, the aforementioned computing device 100 ) and is suitable for executing the program transplantation method 200 of the present invention.

[0087] like Figure 8 As shown, the program transplantation device 800 includes a program acquisition module 810 , a type and identifier determination module 820 , a dictionary query module 830 , and a file writing module 840 .

[0088] Among them, the program acquisition module 810 is suitable for sequentially acquiring code segments in the target program to be ported. The type and identifier determination module 820 is suitable for determining the first type and the first identifier of the code segment. The dictionary query module 830 is suitable for judging whether the first identifier is included in each second identifier of the dictionary corresponding to the first type. The file writing module 840 is suitable for writing the first identifier stored in the dictionary and its corresponding first source code segment into a file when the first identifier is included in each second identifier of the dictionary corresponding to the first type, and is also suitable for writing the code segment into the file when the first identifier is not included in each second identifier of the dictionary corresponding to the first type.

[0089] The program transplantation device 800 can be implemented as a program transplantation tool, for example. The program transplantation tool is moved to the Unix directory of the project to be transplanted, and the program transplantation is performed by executing a predetermined script. For example, for the sw64 architecture, the mk_sw64.sh script is executed in the Unix directory to perform automated program transplantation. For the loongarch64 architecture, the mk_loongarch64.sh script is executed in the Unix directory to perform automated program transplantation. Using the program transplantation tool to transplant a program can reduce the time required to transplant a project from days to minutes, significantly improving the efficiency of program transplantation.

[0090] It should be noted that the program acquisition module 810 is used to execute the aforementioned step S210, the type and identifier determination module 820 is used to execute the aforementioned step S220, the dictionary query module 830 is used to execute the aforementioned step S230, and the file writing module 840 is used to execute the aforementioned step S240.

[0091] According to the technical solution of the present invention, a program transplantation method is provided. After determining the first type and first identifier of the code segment in the target program to be transplanted, the first identifier of the code segment is queried in a dictionary to determine the content to be written into the file. If the dictionary corresponding to the first type includes the first identifier, the content corresponding to the code segment included in the dictionary is directly written into the file, which greatly improves the transplantation efficiency in program transplantation.

[0092] Furthermore, the program migration method of the present invention achieves overloading of various types of objects through the rewritability of the dictionary. Functions, structures, constants, and variables are classified and stored in the dictionary, which facilitates querying in the dictionary during the program migration process, thereby improving the efficiency of program migration.

[0093] The various techniques described herein may be implemented in conjunction with hardware or software, or a combination thereof. Thus, the methods and apparatus of the present invention, or certain aspects or portions of the methods and apparatus of the present invention, may be implemented in the form of program codes (i.e., instructions) embedded in a tangible medium, such as a removable hard disk, a USB flash drive, a floppy disk, a CD-ROM, or any other machine-readable storage medium, wherein when the program is loaded into a machine such as a computer and executed by the machine, the machine becomes an apparatus for practicing the present invention.

[0094] When program code is executed on a programmable computer, the computing device generally includes a processor, a storage medium readable by the processor (including volatile and non-volatile memory and / or storage elements), at least one input device, and at least one output device. The memory is configured to store the program code, and the processor is configured to execute the program porting method of the present invention according to the instructions in the program code stored in the memory.

[0095] By way of example and not limitation, readable media include readable storage media and communication media. Readable storage media store information such as computer-readable instructions, data structures, program modules, or other data. Communication media typically embody computer-readable instructions, data structures, program modules, or other data in a modulated data signal such as a carrier wave or other transport mechanism, and include any information delivery medium. Combinations of any of the above are also included within the scope of readable media.

[0096] In the description provided herein, the algorithms and displays are not inherently related to any particular computer, virtual system, or other device. Various general-purpose systems may also be used in conjunction with the examples of the present invention. Based on the above description, it is apparent that the structure required for constructing such systems is well understood. In addition, the present invention is not directed to any specific programming language. It should be understood that various programming languages ​​may be utilized to implement the present invention described herein, and the description of specific languages ​​above is provided for the purpose of disclosing the preferred embodiment of the present invention.

[0097] 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.

[0098] Similarly, it should be understood that in order to streamline the present disclosure and aid understanding of one or more of the various inventive aspects, in the above description of exemplary embodiments of the present invention, various features of the present invention are sometimes grouped together into a single embodiment, figure, or description thereof. However, this method of disclosure should not be interpreted as reflecting an intention that the claimed invention requires more features than are expressly recited in each claim. Accordingly, the claims following the detailed description are hereby expressly incorporated into this detailed description, with each claim standing on its own as a separate embodiment of the present invention.

[0099] Those skilled in the art will appreciate that the modules, units, or components of the devices in the examples disclosed herein may be arranged in the device described in the embodiment, or alternatively may be located in one or more devices different from the devices in the examples. The modules in the foregoing examples may be combined into one module or further divided into multiple submodules.

[0100] 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 may be divided into multiple submodules or subunits or subcomponents. All features disclosed in this specification (including the accompanying claims, abstracts and drawings) and all processes or units of any method or device disclosed herein may be combined in any combination, except that at least some of such features and / or processes or units are mutually exclusive. Unless expressly stated otherwise, 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.

[0101] Furthermore, those skilled in the art will appreciate that although some embodiments described herein include certain features and not other features included in other embodiments, the combination of features from different embodiments is intended to be within the scope of the invention and to form different embodiments.

[0102] In addition, some of the embodiments are described herein as methods or combinations of method elements that can be implemented by a processor of a computer system or by other devices that perform the functions described. Thus, a processor having the necessary instructions for implementing the method or method element forms a device for implementing the method or method element. Furthermore, the elements described herein of the device embodiments are examples of devices for implementing the functions performed by the elements for the purpose of implementing the invention.

[0103] As used herein, unless otherwise specified, the use of ordinal numbers "first," "second," "third," etc. to describe common objects merely indicates that different instances of similar objects are involved and are not intended to imply that the objects so described must have a given order in time, space, ranking, or in any other manner.

[0104] Although the present invention has been described with respect to a limited number of embodiments, it will be apparent to those skilled in the art, having benefit of the foregoing description, that other embodiments are contemplated within the scope of the invention thus described. Furthermore, it should be noted that the language used in this specification has been selected primarily for readability and didactic purposes, rather than for the purpose of explaining or limiting the subject matter of the present invention. Consequently, many modifications and variations will be apparent to those skilled in the art without departing from the scope and spirit of the appended claims. The disclosure of the present invention is intended to be illustrative rather than restrictive of the scope of the invention, which is defined by the appended claims.

Claims

1. A program transplantation method, the method comprising: Obtain the code segments in the target program to be transplanted in sequence; determining a first type and a first identifier of the code segment; determining whether each second identifier in a dictionary corresponding to the first type includes the first identifier, the dictionary storing a correspondence between the second identifier and the first source code segment; If yes, writing the first identifier stored in the dictionary and the first source code segment corresponding thereto into a file, wherein the file is used for transplanting to the target CPU for execution; The dictionary is generated in the following manner: sequentially obtaining second source code segments from a predetermined source code library; determining a second type of the second source code segment; performing escape processing on the second source code segment to obtain a first source code segment; and using a second identifier of the second source code segment as a key and the first source code segment as a value corresponding to the key in a dictionary corresponding to the second type.

2. The method according to claim 1, further comprising: If the first identifier is not included in each second identifier of the dictionary corresponding to the first type, the code segment is written into the file.

3. The method according to claim 1 or 2, further comprising: Determine whether there are other target programs to be transplanted; If so, continue to execute the step of sequentially acquiring the code segments in the target program to be transplanted.

4. The method according to claim 1 or 2, wherein the files include files of syscall type, error type, sysnums type, and type type, wherein: The step of writing the first identifier stored in the dictionary and the corresponding first source code segment into a file includes: The first identifier in the dictionary and the corresponding first source code segment are written into a file of any type.

5. The method according to claim 1 or 2, wherein: The first type and the second type include functions, structures, constants and variables.

6. The method according to claim 1 or 2, wherein: The target CPU includes a CPU of sw64 architecture or a CPU of loongarch64 architecture.

7. The method according to claim 1 or 2, wherein: The target program is a program written in Golang language.

8. The method according to claim 1, wherein The source code library includes the source code of the golang compiler provided by the target CPU manufacturer.

9. A program transplantation device, comprising: A program acquisition module, adapted to sequentially acquire code segments from a target program to be transplanted; a type and identifier determination module adapted to determine a first type and a first identifier of the code segment; a dictionary query module, adapted to determine whether each second identifier of a dictionary corresponding to the first type includes the first identifier, the dictionary storing a correspondence between the second identifier and the first source code segment; a file writing module, adapted to write the first identifier stored in the dictionary and the corresponding first source code segment into a file when the first identifier is included in each second identifier of the dictionary corresponding to the first type, and further adapted to write the code segment into the file when the first identifier is not included in each second identifier of the dictionary corresponding to the first type, wherein the file is used to be ported to a target CPU for execution; The dictionary is generated in the following manner: sequentially obtaining second source code segments from a predetermined source code library; determining a second type of the second source code segment; performing escape processing on the second source code segment to obtain a first source code segment; and using a second identifier of the second source code segment as a key and the first source code segment as a value corresponding to the key in a dictionary corresponding to the second type.

10. A computing device comprising: one or more processors; Memory; as well as One or more devices comprising instructions for performing any of the methods according to claims 1 to 8.

11. A computer-readable storage medium storing one or more programs, the one or more programs comprising instructions which, when executed by a computing device, cause the computing device to perform any one of the methods according to claims 1 to 8.

Citation Information

Patent Citations

  • Kernel and BSP transplantation methodof openEuler open source system

    CN112860316A