CN114741116A - Program transplanting method and device - Google Patents
Program transplanting method and device Download PDFInfo
- Publication number
- CN114741116A CN114741116A CN202210323623.7A CN202210323623A CN114741116A CN 114741116 A CN114741116 A CN 114741116A CN 202210323623 A CN202210323623 A CN 202210323623A CN 114741116 A CN114741116 A CN 114741116A
- Authority
- CN
- China
- Prior art keywords
- identifier
- source code
- dictionary
- type
- code segment
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
- 238000000034 method Methods 0.000 title claims abstract description 79
- 230000005012 migration Effects 0.000 claims description 50
- 230000006870 function Effects 0.000 claims description 34
- 238000012545 processing Methods 0.000 claims description 10
- 238000004891 communication Methods 0.000 description 17
- 238000010586 diagram Methods 0.000 description 14
- 230000008569 process Effects 0.000 description 10
- 238000013508 migration Methods 0.000 description 4
- 230000008901 benefit Effects 0.000 description 3
- 230000002093 peripheral effect Effects 0.000 description 3
- 230000007723 transport mechanism Effects 0.000 description 2
- 238000004422 calculation algorithm Methods 0.000 description 1
- 230000001413 cellular effect Effects 0.000 description 1
- 238000010276 construction Methods 0.000 description 1
- 238000005516 engineering process Methods 0.000 description 1
- 238000007667 floating Methods 0.000 description 1
- 238000012986 modification Methods 0.000 description 1
- 230000004048 modification Effects 0.000 description 1
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/70—Software maintenance or management
- G06F8/76—Adapting program code to run in a different environment; Porting
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F40/00—Handling natural language data
- G06F40/20—Natural language analysis
- G06F40/237—Lexical tools
- G06F40/242—Dictionaries
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- General Engineering & Computer Science (AREA)
- Software Systems (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Health & Medical Sciences (AREA)
- Artificial Intelligence (AREA)
- Audiology, Speech & Language Pathology (AREA)
- Computational Linguistics (AREA)
- General Health & Medical Sciences (AREA)
- Stored Programmes (AREA)
Abstract
The invention discloses a program transplanting method, which comprises the following steps: sequentially acquiring code segments in a target program to be transplanted; determining a first type and a first identifier of a code segment; judging whether each second identifier of the dictionary corresponding to the first type comprises a first identifier or not, wherein the dictionary stores the corresponding relation between the second identifier and the first source code segment; and if so, writing the first identifier stored in the dictionary and the corresponding first source code segment into a file, wherein the file is used for being transplanted to a target CPU to run. The program transplanting method greatly improves the transplanting efficiency in the program transplanting.
Description
Technical Field
The present invention relates to the field of computer technologies, and in particular, to a program migration method and apparatus, a computing device, and a readable storage medium.
Background
Currently, most open source projects in the technical fields of container and cloud of an operating system are written by the Golang language, but the official version of the Golang does not support sw64 and loongarch64 in domestic CPU architectures, so that a large amount of Golang code implementation needs to be performed on the architectures when container and cloud native related software is transplanted to the architectures. Because the Golay version changes very quickly, the Golay version of each open source item is different, and the Golay library of a specific version is required to be adopted depending on the application of the Golay of the specific version, the source code of the Golay compiler provided by a manufacturer is only a fixed version of source code, and the definition positions and the ranges of functions, structures, constants and variables of different versions of Golay are often very different. Moreover, Golang does not support overloading, and is very prone to problems with undefined or repeatedly defined functions, structures, constants, variables. Therefore, the amount of effort to architecturally support each version on which the open source project depends is difficult to gauge.
To this end, a program migration method is needed to implement the migration of programs that rely on specific Golang version libraries on domestic CPUs such as the sw64 and loonggarch 64 architectures.
Disclosure of Invention
To this end, the present invention provides a program migration method in an attempt to solve, or at least alleviate, the above-identified problems.
According to an aspect of the present invention, there is provided a program migration method including: sequentially acquiring code segments in a target program to be transplanted; determining a first type and a first identifier of a code segment; judging whether each second identifier of the dictionary corresponding to the first type comprises a first identifier or not, wherein the dictionary stores the corresponding relation between the second identifier and the first source code segment; and if so, writing the first identifier stored in the dictionary and the corresponding first source code segment into a file, wherein the file is used for being transplanted to a target CPU for operation.
Optionally, in the program migration method according to the present invention, further comprising: and if the first identifier is not included in the second identifiers of the dictionaries corresponding to the first type, writing the code segment into a file.
Optionally, in the program migration method according to the present invention, further comprising: judging whether other target programs to be transplanted exist or not; if yes, the step of sequentially acquiring the code segments in the target program to be transplanted is continuously executed.
Alternatively, in the program migration method according to the present invention, the dictionary is generated by: sequentially acquiring second source code segments in 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 taking the second identifier of the second source code segment as a key, and storing the first source code segment as a value corresponding to the key in a dictionary corresponding to the second type.
Optionally, in the program migration method according to the present invention, the file includes a file of syscall type, error type, sysnum type, and type, and the step of writing the first identifier stored in the dictionary and the corresponding first source code segment into the file includes: and writing the first identifier in the dictionary and the corresponding first source code segment into any type of file.
Alternatively, in the program migration method according to the present invention, the first type and the second type include a function, a structural body, a constant, and a variable.
Alternatively, in the program migration method according to the present invention, the target CPU includes a sw 64-architecture CPU or a loongarch 64-architecture CPU.
Alternatively, in the program migration method according to the present invention, the target program is a program written in the Golang language.
Alternatively, in the program migration method according to the present invention, the source code library includes source code of a golang compiler provided by the target CPU vendor.
According to another aspect of the present invention, there is provided a program migration apparatus including: the program acquisition module is suitable for sequentially acquiring code segments in the target program to be transplanted; a type and identifier determination module adapted to determine a first type and a first identifier of a code segment; the dictionary query module is suitable for judging whether each second identifier of the dictionary corresponding to the first type comprises a first identifier or not; and the file writing module is suitable for writing the first identifier stored in the dictionary and the corresponding first source code segment into the file when each second identifier of the dictionary corresponding to the first type comprises the first identifier, and is also suitable for writing the code segment into the file when each second identifier of the dictionary corresponding to the first type does not comprise the first identifier.
According to yet another aspect of the present invention, there is provided a computing device comprising: at least one processor; and a memory storing program instructions, wherein the program instructions are configured to be executed by the at least one processor, the program instructions comprising instructions for performing the program migration method as described above.
According to yet another aspect of the present invention, there is provided a readable storage medium storing program instructions which, when read and executed by a computing device, cause the computing device to perform the method as described above.
According to the technical scheme of the invention, after the first type and the first identifier of the code segment in the target program to be transplanted are determined, the first identifier of the code segment is inquired in the dictionary, the content written in the file is determined, if the first identifier is included in the dictionary corresponding to the first type, the content included in the dictionary and corresponding to the code segment is directly written in the file, and the transplanting efficiency is greatly improved in program transplanting.
Further, the program migration method of the present invention realizes reloading of various types of objects by the rewritability of the dictionary. The functions, the structural bodies, the constants and the variables are classified and stored in the dictionary, so that the functions, the structural bodies, the constants and the variables can be conveniently inquired in the dictionary in the program transplanting process, and the program transplanting efficiency is improved.
The foregoing description is only an overview of the technical solutions of the present invention, and the embodiments of the present invention are described below in order to make the technical means of the present invention more clearly understood and to make the above and other objects, features, and advantages of the present invention more clearly understandable.
Drawings
To the accomplishment of the foregoing and related ends, certain illustrative aspects are described herein in connection with the following description and the annexed drawings, which are indicative of various ways in which the principles disclosed herein may be practiced, and all aspects and equivalents thereof are intended to be within the scope of the claimed subject matter. The above and other objects, features and advantages of the present disclosure will become more apparent from the following detailed description read in conjunction with the accompanying drawings. Throughout this disclosure, like reference numerals generally refer to like parts or elements.
FIG. 1 shows a schematic diagram of a computing device 100, according to one embodiment of the invention;
FIG. 2 shows a flow diagram of a program migration method 200 according to one embodiment of the invention;
FIG. 3 illustrates a flow diagram of a method 300 of building a dictionary in accordance with one embodiment of the present invention;
FIG. 4 shows a schematic diagram of an escape-processed source code segment according to one embodiment of the invention;
FIG. 5 illustrates a diagram of files after migration, according to one embodiment of the present invention;
FIG. 6 illustrates a flow diagram of a method 600 of constructing a dictionary in accordance with another embodiment of the present invention;
FIG. 7 shows a flowchart of a program migration method 700 according to another embodiment of the present invention; and
fig. 8 shows a schematic diagram of a program migration apparatus 800 according to an embodiment of the present invention.
Detailed Description
Exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. While exemplary embodiments of the present disclosure are shown in the drawings, it should be understood that the present disclosure may be embodied in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the scope of the disclosure to those skilled in the art.
FIG. 1 is a schematic diagram of an example computing device 100. As shown in FIG. 1, in a basic configuration 102, a computing device 100 typically includes a system memory 106 and one or more processors 104. A memory bus 108 may be used for communication between the processor 104 and the system memory 106.
Depending on the desired configuration, the processor 104 may be any type of processing, including but not limited to: a microprocessor (UP), a microcontroller (UC), a digital information processor (DSP), or any combination thereof. The processor 104 may include one or more levels of cache, such as a level one cache 110 and a level two cache 112, a processor core 114, and registers 116. The example processor core 114 may include an Arithmetic Logic Unit (ALU), a Floating Point Unit (FPU), a digital signal processing core (DSP core), or any combination thereof. The example memory controller 118 may be used with the processor 104, or in some implementations the memory controller 118 may be an internal part of the processor 104.
Depending on the desired configuration, system memory 106 may 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 may include an operating system 120, one or more applications 122, and program data 124. In some implementations, the application 122 can be arranged to execute instructions on an operating system with program data 124 by one or more processors 104.
Computing device 100 also includes a storage device 132, storage device 132 including removable storage 136 and non-removable storage 138.
Computing device 100 may also include a storage interface bus 134. The storage interface bus 134 enables communication from the 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 removable storage 136 and/or non-removable storage 138, and loaded into system memory 106 via storage interface bus 134 and executed by the one or more processors 104 when the computing device 100 is powered on or the applications 122 are to be executed.
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. The example output device 142 includes an image processing unit 148 and an audio processing unit 150. They may 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 may be configured to facilitate communication with external devices such as input devices (e.g., keyboard, mouse, pen, voice input device, touch input device) or other peripherals (e.g., printer, scanner, etc.) via one or more I/O ports 158. An example communication device 146 may include a network controller 160, which may be arranged to facilitate communications with one or more other computing devices 162 over a network communication link via one or more communication ports 164.
A network communication link may be one example of a communication medium. Communication media may typically be embodied by computer readable instructions, data structures, program modules, and may include any information delivery media, such as carrier waves or other transport mechanisms, in a modulated data signal. A "modulated data signal" may be a signal that has one or more of its data set or its changes made in a manner that encodes information in the signal. By way of non-limiting example, communication media may include wired media such as a wired network or private-wired network, and various wireless media such as acoustic, Radio Frequency (RF), microwave, Infrared (IR), or other wireless media. The term computer readable media as used herein may include both storage media and communication media.
Computing device 100 may be implemented as a personal computer including both desktop and notebook computer configurations. Of course, computing device 100 may also be implemented as part of a small-form factor portable (or mobile) electronic device such as a cellular telephone, a digital camera, a Personal Digital Assistant (PDA), a personal media player device, a wireless web-watch device, a personal headset, an application specific device, or a hybrid device that include any of the above functions. And may even be implemented as a server, such as a file server, a database server, an application server, a WEB server, and so forth. The embodiments of the present invention do not limit this.
In one embodiment according to the invention, the computing device 100 is configured to perform a program migration method according to the invention. The program data of the computing device 100 includes a plurality of program instructions for executing the program migration method of the present invention, and the program instructions may instruct the processor to execute the program migration method of the present invention.
According to another embodiment of the present invention, the application disposed on the operating system 120 includes a program migration apparatus 800, and the program migration apparatus 800 includes therein a plurality of program instructions for executing the program migration method of the present invention, so that the program migration method of the present invention can be executed in the program migration apparatus 800.
FIG. 2 shows a flow diagram of a program migration method 200 according to one embodiment of the invention. The program migration method 200 may be performed in a computing device, such as the computing device 100 described above. As shown in fig. 2, the method 200 begins at step S210.
In step S210, the code segments in the target program to be migrated are sequentially acquired.
According to the embodiment of the invention, for the migration of the Golang program, the unix directory of the directly downloaded open source project does not have relevant files of the sw64 or the loonggarch 64 architecture. Thus, the target program to be migrated may be a program missing from the downloaded open source project, and may be, for example, the mips64el library of the open source project. Wherein the unix directory is a directory src/cmd/vector/Golang in Golang source code.
Alternatively, the code segments may be one line of code or multiple lines of code. Specifically, each time a line in the target program to be migrated is read, it is then possible to judge whether the reading is completed by judging whether the line includes a bracket. If a line in the target program is read that includes only one side of a full bracket (e.g., "), it may be determined that the reading is not complete and the reading of the next line may continue until the other side of a full bracket (e.g.,") is read. A function is usually referred to as func abc () { (where abc is taken as an example to represent a function named abc). For example, reading a line of code as func abc () {, it can be determined that the function includes "{" in the line, the function does not end, and it can be determined that the reading is not completed, the next line is continuously read until "}" exists in the read line. Thus, the code segment is a plurality of lines of code, and the subsequent steps require the code segment including the plurality of lines of code to be processed together. As another example, if a line of code is read as func abc () {.
Subsequently, in step S220, a first type and a first identifier of the code segment are determined, wherein the first type comprises a function, a structure, a constant and a variable.
In the Golang language, a function may be specifically defined by func, a structure may be defined by type, a constant may be defined by const, and a variable may be defined by var. The first identifier is a name adopted by the named code segment type, and for the code segment of which the first type is a function, the first identifier is a function name; for code segments with the first type being a structure type, the first identifier is a structure name; for code segments of which the first type is a constant type, the first identifier is a constant name; for code segments whose first type is a variable type, the first identifier is the variable name.
Subsequently, in step S230, it is determined whether the first identifier is included in the second identifiers of the dictionary corresponding to the first type of the code segment. The dictionary stores the corresponding relationship between the second identifier and the first source code segment, that is, the dictionary stores one or more second identifiers, and each second identifier corresponds to one first source code segment.
According to one embodiment of the present invention, if the first type of a code segment is a function, it is looked up in a dictionary corresponding to the function whether there is a first identifier corresponding to the code segment. If the first type of the code segment is a structural body, whether a first identifier corresponding to the code segment exists in a dictionary corresponding to the structural body is searched. If the first type of the code segment is a constant, looking up whether a first identifier corresponding to the code segment exists in a dictionary corresponding to the constant. If the first type of the code segment is a variable, looking up whether a first identifier corresponding to the code segment exists in a dictionary corresponding to the variable.
Turning now to the construction of a dictionary, FIG. 3 shows a flow diagram of a method 300 for constructing a dictionary, according to one embodiment of the present invention. The flowchart of the method 300 begins at step S310.
In step S310, second source code segments in the predetermined source code library are sequentially acquired.
Alternatively, the source code library may include a fixed version of source code of the Golang compiler, and may also include a source code of project mips or a source code of project generic architecture, and if the target program to be migrated is migrated onto the CPU of sw64 architecture, the source code of the fixed version of the Golang compiler is used as a primary reference, the source code of the project mips is used as a secondary reference to the primary reference, and the source code of the project generic architecture is used as a tertiary reference to the secondary reference, for generating the dictionary. Since the manufacturer does not provide each version of the Golang compiler source code, but only provides a fixed version of the Golang compiler source code, i.e., the Golang version on which the open source item depends is not necessarily the fixed version, the source codes of the second reference and/or the third reference are also used as the content in the predetermined source code library.
Alternatively, the source code library may include source codes of a fixed version of the Golang compiler, and may also include source codes of project arm64 or source codes of project generic framework. If the target program to be migrated is migrated to the CPU of the loongarch64 architecture, the source code of the Golang compiler fixed version is used as a main reference, the source code of the item arm64 is used as a second reference next to the main reference, and the source code of the item general architecture is used as a third reference next to the second reference, so as to generate the dictionary.
According to an embodiment of the invention, the dictionary is generated in an overloaded manner, i.e. the contents written in the dictionary later will overwrite the contents written in the dictionary earlier. Therefore, the sequence of sequentially acquiring the source code segments in the predetermined source code library is: the second source code segment in the third reference is first obtained, the second source code segment in the second reference is then obtained, and the second source code segment in the main reference is finally obtained. In this way, if the previously written content and the subsequently written content overlap, the subsequently written content will be the standard.
Here, the second source code segment may be one line of code or a plurality of lines of code. Specifically, each time a line of source codes in a predetermined source code library is read, it is then possible to judge whether the reading is completed by judging whether the line includes parentheses. If a line in the source code is read that includes only one side of a full bracket (e.g., "), it may be determined that the unread is complete and the reading of the next line may continue until the other side of a full bracket (e.g.,") is read. A function is usually referred to as func abc () { (where abc is taken as an example to represent a function named abc). For example, reading a line of code as func abc () {, it can be determined that the function includes "{" in the line, the function does not end, and it can be determined that the reading is not completed, the next line is continuously read until "}" exists in the read line. Thus, the second source code segment is a multi-line code, and the subsequent steps require the second source code segment including the multi-line code to be processed together. For another example, if a line of code is read as func abc () {.
Subsequently, in step S320, a second type of the second source code segment is determined, wherein the second type includes a function, a structure, a constant, and a variable.
According to the embodiment of the present invention, if the second source code segment includes func, the second type of the second source code segment may be determined to be a function, if the second source code segment includes type, the second type of the second source code segment may be determined to be a structural body, if the second source code segment includes const, the second type of the second source code segment may be determined to be a constant, and if the second source code segment includes var, the second type of the second source code segment may be determined to be a variable.
Subsequently, in step S330, the second source code segment is subjected to escape processing.
Subsequently, in step S340, the second identifier of the second source code segment is used as a key (referred to as key), and the escape-processed second source code segment is stored as a value (referred to as value) corresponding to the key in a dictionary corresponding to the second type of the second source code segment.
Specifically, each type of the second source code segment corresponds to one dictionary, and the second type of the second source code segment includes a function, a structure, a constant and a variable, so that four second types of the second source code segment correspond to four dictionaries, including a dictionary for storing source codes of which the second type is the function type, a dictionary for storing source codes of which the second type is the structure type, a dictionary for storing source codes of which the second type is the constant type, and a dictionary for storing source codes of which the second type is the variable type. Taking the second identifier of the second source code segment as a key, and taking the first source code segment obtained after the escape of the second source code segment as a value to be stored in a corresponding dictionary, for example: and if the second type of the second source code segment is a function, taking a second identifier of the second source code segment as a key, and taking the first source code segment obtained after the second source code segment is transferred as a value and storing the value in a dictionary for storing source codes with the second type as the function type.
Fig. 4 shows a schematic diagram of an escape-processed source code segment according to an embodiment of the invention. And storing the source code segment subjected to escape processing as a value in a dictionary together with the corresponding key.
According to the program migration method of the invention, at the time of Golang program migration, the unix directory in the downloaded open source project does not have related files of the domestic Shenwei architecture sw64 and the Loongson architecture loonggarch 64, and different Golang versions of different open source projects depend on different Golang programs. Therefore, the obtained source codes corresponding to the main reference, the second reference and the third reference are reloaded into four types (namely, functions, structural bodies, constants and variables) to generate four dictionaries corresponding to the four types, so that identifiers corresponding to code segments in the target program to be transplanted can be conveniently inquired in the corresponding dictionaries in the program transplanting process, and the program transplanting efficiency can be greatly improved through the generated dictionaries. The Golang language does not support reloading itself, but reloading of various types of Golang codes is achieved through the rewritability of the dictionary.
Subsequently, in step S240, if the first identifier is included in each second identifier of the dictionary corresponding to the first type of the code segment, the first identifier stored in the dictionary and the corresponding first source code segment are written into a file, wherein the file is used for being migrated to the target CPU for running.
Specifically, whether a first identifier of the code segment exists in a key stored in a dictionary corresponding to the first type of the code segment is searched, and if yes, the key and value corresponding to the first identifier stored in the dictionary are used for replacing the content of the code segment and writing the content into a file. The files comprise files of a syscall type, an error type, a sysnum type and a type.
According to the embodiment of the invention, the target program to be transplanted comprises four types, specifically comprising syscall, errors, SYSnums and types. The definition position is not sensitive when the file is written, but there may not be repeated definition, for example, the target program to be migrated is of error type, and when the target program is written into the file, the target program may be written into any type of file, that is, into syscall, errors, sysnum or types type of file, without limitation, but may not be repeatedly present in multiple files, and finally, a migrated function, structure, constant or variable file is formed. FIG. 5 shows a diagram of a file after migration, according to one embodiment of the invention. As shown in FIG. 5, the migrated files include syscall, errors, SYSnums, or typetypes.
Optionally, after writing the first identifier in the dictionary and the first source code segment corresponding to the first identifier into a file, the file is stored in the unix directory, so that the item including the file can run in the target CPU.
Subsequently, in step S250, if the first identifier is not included in the dictionary corresponding to the first type of the code segment, that is, the first identifier is not queried in the dictionary, the code segment is directly written into the file without replacement.
Optionally, after writing the code segment to the file, the file is stored in the unix directory so that the item including the file can be run in the target CPU.
In order to better explain the complete implementation process of the present invention, the method for constructing a dictionary and the program migration method of the present invention are explained in detail below. FIG. 6 illustrates a flow diagram of a method 600 of constructing a dictionary in accordance with another embodiment of the present invention. As shown in fig. 6, the method 600 begins at step S601.
In step S601, source codes in a predetermined source code library are acquired.
Subsequently, in step S602, a row of source codes in the predetermined source code library is read. The specific contents of steps S601-S602 can refer to the description in step S310 above.
Subsequently, in step S603, the type of the line of source code is identified, and the type includes a function, a structure, a constant, and a variable. The details of this step can refer to the description in step S320.
Subsequently, in step S604, it is determined whether the read source code of the line is complete.
Specifically, whether the read source code of the line is complete can be determined by judging whether the bracket is complete. Wherein, the bracket integrity indicates that the line of source codes includes "(" and "also includes") ", or includes" { "and also includes" } ", if the line of source codes does not include brackets or the brackets included in the line of source codes are intact, the line of source codes can be determined to be intact, step S606 is executed, otherwise, the line of source codes is determined to be incomplete, which means that only one side of the line of source codes including a complete bracket is" ("or" { ", and step S605 is executed until a line of source codes read includes" ("or" { "corresponding") "or" } ".
In step S605, the line source code is recorded in the cache. Then, the process returns to step S602.
In step S606, the source code segment in the cache is subjected to escape processing. The details of this step can refer to the description in step S330.
Subsequently, in step S607, the identifier of the source code segment is used as a key, and the source code segment after the escape processing is written into the dictionary corresponding to the type of the source code segment as a value corresponding to the key. The details of this step can refer to the description in step S340.
Subsequently, in step S608, it is determined whether all the source codes in the predetermined source code library have been read. If all the source codes in the predetermined source code library have been read, step S609 is executed, and if the source codes in the predetermined source code library have not been read, step S602 is returned to.
In step S609, it is determined whether there are other predetermined source code libraries, and if there are other predetermined source code libraries that need to be processed, the process returns to step S602, and a new source code in the predetermined source code library is obtained. If there are no other predetermined source code libraries, the method 600 executes to completion.
Fig. 7 shows a flowchart of a program migration method 700 according to another embodiment of the invention. As shown in fig. 7, the method 700 begins at step S701.
In step S701, a target program to be migrated is acquired.
Subsequently, in step S702, the code in one line of the object program is read. The specific contents of steps S701 to S702 can refer to the description in step S210.
Subsequently, in step S703, the type and identifier of the line code are identified, wherein the type includes a function, a structure, a constant, and a variable. The details of this step can refer to the description in step S220. Subsequently, in step S704, it is determined whether the identifier exists in the key of the dictionary. The details of this step can refer to the description in step S230 above. If not, step S705 is performed. If so, step S706 is performed.
In step S705, the read line of codes is written into a file, and the specific content of this step may refer to the description in step S250. After step S705, step S707 is executed.
In step S706, the identifier in the dictionary and its corresponding content are written into a file. The details of this step can refer to the description in step S240 above. After step S706, step S705 is performed.
Subsequently, in step S707, it is determined whether the target program to be migrated is read completely. If the reading is completed, step S708 is performed, and if the reading is not completed, the process returns to step S702.
In step S708, it is determined whether or not there is another target program to be migrated. If yes, the process returns to step S701 to obtain a new target program to be migrated. If not, method 700 execution is complete.
Fig. 8 shows a schematic diagram of a program migration apparatus 800 according to an embodiment of the present invention, where the program migration apparatus 800 resides in a computing device (such as the aforementioned computing device 100) and is adapted to execute the program migration method 200 of the present invention.
As shown in fig. 8, the program migration apparatus 800 includes a program acquisition module 810, a type and identifier determination module 820, a dictionary lookup module 830, and a file writing module 840.
The program obtaining module 810 is adapted to sequentially obtain code segments in the target program to be migrated. A type and identifier determining module 820 adapted to determine a first type and a first identifier of said code segment. The dictionary querying module 830 is adapted to determine whether each second identifier of the dictionary corresponding to the first type includes the first identifier. The file writing module 840 is 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 is 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.
The program migration apparatus 800 may be realized, for example, as a program migration tool that migrates the program migration tool into an unix directory of an item for which program migration is to be performed, and migrates the program by executing a predetermined script. For example, for the sw64 architecture, the mk _ sw64.sh script is executed in the unix directory to realize automatic program migration, and for the loonggarch 64 architecture, the mk _ loonggarch 64.sh script is executed in the unix directory to realize automatic program migration. The program is transplanted through the program transplanting tool, the time required for transplanting a project can be reduced from a day level to a minute level, and the program transplanting efficiency is greatly improved.
It should be noted that the program obtaining module 810 is configured to execute the aforementioned step S210, the type and identifier determining module 820 is configured to execute the aforementioned step S220, the dictionary querying module 830 is configured to execute the aforementioned step S230, and the file writing module 840 is configured to execute the aforementioned step S240.
According to the technical scheme of the invention, after the first type and the first identifier of the code segment in the target program to be transplanted are determined, the first identifier of the code segment is inquired in a dictionary, the content written in the file is determined, if the first identifier is included in the dictionary corresponding to the first type, the content included in the dictionary and corresponding to the code segment is directly written in the file, and the transplanting efficiency is greatly improved in program transplanting.
Further, the program migration method of the present invention realizes reloading of various types of objects by the rewritability of the dictionary. The functions, the structural bodies, the constants and the variables are stored in the dictionary in a classified mode, query in the dictionary in the program transplanting process is facilitated, and the program transplanting efficiency is improved.
The various techniques described herein may be implemented in connection with hardware or software or, alternatively, with a combination of both. Thus, the methods and apparatus of the present invention, or certain aspects or portions thereof, may take the form of program code (i.e., instructions) embodied in tangible media, such as removable hard drives, U.S. disks, floppy disks, CD-ROMs, or any other machine-readable storage medium, wherein, when the program is loaded into and executed by a machine, such as a computer, the machine becomes an apparatus for practicing the invention.
In the case of program code execution on programmable computers, the computing device will generally include 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. Wherein the memory is configured to store program code; the processor is configured to execute the program migration method of the present invention according to instructions in the program code stored in the memory.
By way of example, and not limitation, readable media may comprise 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 embodies 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 includes any information delivery media. Combinations of any of the above are also included within the scope of readable media.
In the description provided herein, algorithms and displays are not inherently related to any particular computer, virtual system, or other apparatus. Various general purpose systems may also be used with examples of this invention. The required structure for constructing such a system is apparent from the description above. Moreover, the present invention is not directed to any particular programming language. It is appreciated that a variety of programming languages may be used to implement the teachings of the present invention as described herein, and any descriptions of specific languages are provided above to disclose the best mode of the invention.
In the description provided herein, numerous specific details are set forth. It is understood, however, that embodiments of the invention may be practiced without these specific details. In some instances, well-known methods, structures and techniques have not been shown in detail in order not to obscure an understanding of this description.
Similarly, it should be appreciated that in the foregoing description of exemplary embodiments of the invention, various features of the invention are sometimes grouped together in a single embodiment, figure, or description thereof for the purpose of streamlining the disclosure and aiding in the understanding of one or more of the various inventive aspects. However, the disclosed method should not be interpreted as reflecting an intention that: that the invention as claimed requires more features than are expressly recited in each claim. Thus, 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 this invention.
Those skilled in the art will appreciate that the modules or units or components of the devices in the examples disclosed herein may be arranged in a device as described in this embodiment, or alternatively may be located in one or more devices different from the device in this example. The modules in the foregoing examples may be combined into one module or may be further divided into multiple sub-modules.
Those skilled in the art will appreciate that the modules in the device in an embodiment may be adaptively changed and disposed in one or more devices different from the embodiment. The modules or units or components in the embodiments may be combined into one module or unit or component, and furthermore, may be divided into a plurality of sub-modules or sub-units or sub-components. All of the features disclosed in this specification (including any accompanying claims, abstract and drawings), and all of the processes or elements of any method or apparatus so disclosed, may be combined in any combination, except combinations where at least some of such features and/or processes or elements are mutually exclusive. Each feature disclosed in this specification (including any accompanying claims, abstract and drawings) may be replaced by alternative features serving the same, equivalent or similar purpose, unless expressly stated otherwise.
Furthermore, those skilled in the art will appreciate that while some embodiments described herein include some features included in other embodiments, rather than other features, combinations of features of different embodiments are meant to be within the scope of the invention and form different embodiments.
Additionally, some of the embodiments are described herein as a method or combination of method elements that can be implemented by a processor of a computer system or by other means of performing the described functions. A processor having the necessary instructions for carrying out the method or method elements thus forms a means for carrying out the method or method elements. Further, the elements of the apparatus embodiments described herein are examples of the following apparatus: the apparatus is used to implement the functions performed by the elements for the purpose of carrying out the invention.
As used herein, unless otherwise specified the use of the ordinal adjectives "first", "second", "third", etc., to describe a common object, merely indicate that different instances of like objects are being referred to, and are not intended to imply that the objects so described must be in a given sequence, either temporally, spatially, in ranking, or in any other manner.
While the invention has been described with respect to a limited number of embodiments, those skilled in the art, having benefit of this description, will appreciate that other embodiments can be devised which do not depart from the scope of the invention as described herein. Furthermore, it should be noted that the language used in the specification has been principally selected for readability and instructional purposes, and may not have been selected to delineate or circumscribe the inventive subject matter. Accordingly, many modifications and variations will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the appended claims. The present invention has been disclosed in an illustrative rather than a restrictive sense, and the scope of the present invention is defined by the appended claims.
Claims (12)
1. A program migration method, the method comprising:
sequentially acquiring code segments in a target program to be transplanted;
determining a first type and a first identifier of the code section;
judging whether each second identifier of the dictionary corresponding to the first type comprises the first identifier or not, wherein the dictionary stores the corresponding relation between the second identifier and the first source code segment;
and if so, writing the first identifier stored in the dictionary and the corresponding first source code segment into a file, wherein the file is used for being transplanted to a target CPU for operation.
2. The method of claim 1, further comprising:
and if the first identifier is not included in the second identifiers of the dictionary corresponding to the first type, writing the code segment into the file.
3. The method of claim 1 or 2, further comprising:
judging whether other target programs to be transplanted exist or not;
if yes, continuing to execute the step of sequentially acquiring the code segments in the target program to be transplanted.
4. The method of claim 1, wherein the dictionary is generated by:
sequentially acquiring second source code segments in a predetermined source code library;
determining a second type of the second source code segment;
conducting escape processing on the second source code segment to obtain a first source code segment;
and taking the second identifier of the second source code segment as a key, and storing the first source code segment as a value corresponding to the key in a dictionary corresponding to the second type.
5. The method of any of claims 1 to 4, the files comprising files of type syscal l, error, syslists and type, wherein the step of writing the first identifiers and their corresponding first source code segments stored in the dictionary into a file comprises:
and writing the first identifier in the dictionary and the corresponding first source code segment into any type of file.
6. The method of any one of claims 1 to 5, wherein the first and second types comprise functions, structures, constants, and variables.
7. The method of any one of claims 1 to 6, wherein the target CPU comprises a CPU of sw64 architecture or a CPU of loonggarch 64 architecture.
8. The method according to any one of claims 1 to 7, wherein the target program is a program written in the Golang language.
9. The method of claim 4, wherein the source code library comprises source code of a golang compiler provided by a target CPU vendor.
10. A program migration apparatus, the apparatus comprising:
the program acquisition module is suitable for sequentially acquiring code segments in the 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;
the dictionary query module is suitable for judging whether each second identifier of the dictionary corresponding to the first type comprises the first identifier or not;
the file writing module is suitable for writing the first identifier stored in the dictionary and the corresponding first source code segment into a file when each second identifier of the dictionary corresponding to the first type comprises the first identifier, and is also suitable for writing the code segment into the file when each second identifier of the dictionary corresponding to the first type does not comprise the first identifier.
11. A computing device, comprising:
one or more processors;
a memory; and
one or more apparatuses comprising instructions for performing any of the methods of claims 1-9.
12. 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 of the methods of claims 1-9.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202210323623.7A CN114741116A (en) | 2022-03-29 | 2022-03-29 | Program transplanting method and device |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202210323623.7A CN114741116A (en) | 2022-03-29 | 2022-03-29 | Program transplanting method and device |
Publications (1)
Publication Number | Publication Date |
---|---|
CN114741116A true CN114741116A (en) | 2022-07-12 |
Family
ID=82278026
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202210323623.7A Pending CN114741116A (en) | 2022-03-29 | 2022-03-29 | Program transplanting method and device |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN114741116A (en) |
-
2022
- 2022-03-29 CN CN202210323623.7A patent/CN114741116A/en active Pending
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN110275864B (en) | Index establishing method, data query method and computing device | |
CN111290952B (en) | Tracking method and device for dynamic link library function | |
CN112988252B (en) | Operating system starting method and computing device | |
US10459727B2 (en) | Loop code processor optimizations | |
WO2018040270A1 (en) | Method and device for loading linux-system elf file in windows system | |
CN112947976B (en) | Operating system upgrading method, computing device and storage medium | |
CN113342563B (en) | Method and device for positioning source code during program running error and computing equipment | |
CN113553010A (en) | Optical disc file checking method, optical disc recording method and computing device | |
CN113885936A (en) | Solution method for software package dependence in customized mirror image | |
US10592252B2 (en) | Efficient instruction processing for sparse data | |
CN113485712B (en) | Kernel clipping method and computing device | |
CN113535650B (en) | File naming method and computing device | |
CN114003289B (en) | Application program running method, computing device and storage medium | |
CN111752620B (en) | Processing method and loading method of kernel module | |
CN114741116A (en) | Program transplanting method and device | |
CN114816772B (en) | Debugging method, debugging system and computing device for application running based on compatible layer | |
US20170192896A1 (en) | Zero cache memory system extension | |
CN114003290B (en) | Application program running method and device related to instruction replacement | |
CN113254888B (en) | Method for acquiring hardware information, authorization control system and computing equipment | |
CN114879978A (en) | Software package dependency processing method, computing device and readable storage medium | |
CN113742140B (en) | File backup method and device and computing equipment | |
CN114510456A (en) | File searching method, downloading device and computing equipment | |
CN114416221A (en) | Application execution method, computing device and storage medium | |
CN114706828A (en) | File loading method, computing device and storage medium | |
CN114595230A (en) | Data synchronous warehousing method, module, computing device and storage medium |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination |