Program conversion device, program conversion method, and program
The program conversion device and method address the issue of slow execution speeds in converted programs by using static and dynamic analysis to pre-secure memory areas for variable data elements, resulting in improved performance.
Patent Information
- Application Number
- JP2021106654
- Authority / Receiving Office
- JP · JP
- Patent Type
- Patents
- Current Assignee / Owner
- Filing Date
- 2021-06-28
- Publication Date
- 2025-06-18
- Estimated Expiration
- 2041-06-28
AI Technical Summary
Existing program conversion methods result in slow execution speeds for converted programs due to the need for dynamic memory allocation and deallocation for variable data elements with changing memory area sizes.
A program conversion device and method that includes static analysis to identify variable data elements, syntax addition to calculate the maximum memory area required, and dynamic analysis to determine the assumed maximum value, resulting in a second program with pre-secured memory areas for improved execution speed.
The proposed solution significantly enhances the execution speed of the converted program by eliminating the need for dynamic memory allocation and deallocation, thereby improving program performance.
Smart Images

Figure 0007694199000001 
Figure 0007694199000002 
Figure 0007694199000003
Abstract
Description
Technical Field
[0001] The present invention relates to a program conversion device, a program conversion method, and a program.
Background Art
[0002] Conventionally, a compilation method for converting a program has been known (see, for example, Patent Documents 1 and 2). Patent Document 1 Japanese Patent Laid-Open No. 3-91036 Patent Document 2 Japanese Patent Laid-Open No. 2005-301415
Summary of the Invention
Problems to be Solved by the Invention
[0003] When converting a program, it is preferable that the execution speed of the converted program is fast.
Means for Solving the Problems
[0004] In order to solve the above problems, in one aspect of the present invention, there is provided a program conversion device that converts a first program in a first language into a second program in a second language. The program conversion device may include a static analysis unit that analyzes the first program and extracts variable data elements whose memory area sizes to be secured change. The program conversion device may include a syntax addition unit that adds additional syntax for calculating the maximum value of the memory area to be secured for the variable data elements into the first program. The program conversion device may include a dynamic analysis unit that executes the first program with the additional syntax added and analyzes the assumed maximum value of the memory area assumed for the variable data elements.
[0005] The program conversion device may include a program conversion unit that generates a second program including a pre-securing syntax for securing a memory area of the assumed maximum value for the variable data elements.
[0006] The static analysis unit may extract variable data elements by extracting a syntax including a pre-specified instruction.
[0007] In the first program, the static analysis unit may extract a list structure whose number of list elements changes as a variable data element, and extract an element number change syntax including an instruction to add or delete a list element to / from the list structure. The syntax addition unit may add an additional syntax for counting the number of list elements included in the list structure to the first program corresponding to the element number change syntax.
[0008] In the first program, the static analysis unit may extract a list structure whose number of list elements changes as a variable data element, and extract an element number change syntax including an instruction to add or delete a list element to / from the list structure. The syntax addition unit may add an additional syntax for calculating the total size of the sizes of list elements included in the list structure to the first program corresponding to the element number change syntax.
[0009] When the size of the memory area to be secured for a variable data element exceeds the assumed maximum value, the second program generated by the program conversion unit may include a dynamic allocation syntax for dynamically allocating a memory area having a size exceeding the assumed maximum value for the variable data element.
[0010] The dynamic analysis unit may extract the assumed maximum value when the first program is executed within the range of the operating conditions when the operating conditions for executing the first program are input.
[0011] The dynamic analysis unit may determine the conditions for executing the first program based on the occurrence probability of each condition included in the operating conditions.
[0012] The dynamic analysis unit may determine the assumed maximum value for each variable data element based on the size of the available memory area.
[0013] The second language may be a compiler language.
[0014] In a second aspect of the present invention, there is provided a program conversion method for converting a first program in a first language into a second program in a second language. The program conversion method may include a static analysis stage of analyzing the first program to extract variable data elements whose memory area sizes to be secured change. The program conversion method may include a syntax addition stage of adding additional syntax for calculating the maximum value of the memory area to be secured for the variable data elements into the first program. The program conversion method may include a dynamic analysis stage of executing the first program with the additional syntax added and analyzing the assumed maximum value of the memory area assumed for the variable data elements.
[0015] In a third aspect of the present invention, there is provided a program for causing a computer to execute the program conversion method according to the second aspect.
[0016] Note that the above summary of the invention does not list all the necessary features of the present invention. Also, sub-combinations of these feature groups can also be inventions.
Brief Description of Drawings
[0017]
Figure 1
Figure 2
Figure 3
Figure 4
Figure 5
Figure 6
Figure 7
Figure 8
Figure 9
Figure 10
Figure 11
Figure 12
Figure 13
Figure 14
Figure 15
Figure 16
Figure 17
Figure 18
Mode for Carrying Out the Invention
[0018] Hereinafter, the present invention will be described through embodiments of the invention. However, the following embodiments do not limit the invention according to the claims. Also, not all combinations of features described in the embodiments are essential for the solution means of the invention.
[0019] FIG. 1 is a block diagram showing a configuration example of a program conversion device 100 according to an embodiment of the present invention. The program conversion device 100 converts a first program in a first language into a second program in a second language different from the first language. As an example, the first language is an interpreter-type language that sequentially converts each instruction into machine language and executes it when the program is executed. The first language may be a script language. The first language is, for example, Python, but is not limited thereto. As an example, the second language is a compiler language that converts the entire program into machine language and then executes it. The second language is, for example, the C language, but is not limited thereto.
[0020] The first program and the second program may include variable data elements whose memory area sizes to be secured during program execution change. For example, when a list structure including a plurality of list elements is defined in a program and the number of list elements included in the list structure varies as the program is executed, the size of the memory area to be secured for the list structure varies during program execution.
[0021] When converting each syntax of the first program into the second program, in the second program, along with the syntax for increasing or decreasing the number of list elements of the list structure, a new memory area for the list structure is secured, the list structure is updated in the memory area, and the syntax for releasing the memory area for the old list structure is inserted. Therefore, in the second program, every time the syntax for increasing or decreasing the number of list elements of the list structure is executed, a process of dynamically securing and releasing the memory area is performed. For this reason, the execution speed of the second program becomes slow.
[0022] The program conversion device 100 determines the assumed maximum value of the memory area assumed for the variable data element by analyzing the first program. The program conversion device 100 includes an instruction to pre-reserve the memory area of the assumed maximum value for the variable data element in the second program. As a result, in the second program, the process of dynamically securing and releasing the memory area, which was performed each time an instruction to increase or decrease the number of list elements in the list structure was executed, can be omitted. Therefore, the execution speed of the second program can be improved.
[0023] Note that the assumed maximum value of the memory area of the variable data element does not have to match the maximum value that the data size of the variable data element can take. The assumed maximum value may be the maximum value of the data size of the variable data element when the program is executed under predetermined conditions, or may be a value obtained by performing arithmetic processing such as adding or subtracting a predetermined value from the maximum value.
[0024] The program conversion device 100 in this example efficiently and accurately analyzes the assumed maximum value of the memory area for the variable data element by combining static analysis, syntax addition, and dynamic analysis of the first program. Static analysis refers to analyzing the meaning of each syntax of the program without executing the program. Dynamic analysis refers to executing the program and analyzing the execution result or the intermediate process.
[0025] The program conversion device 100 in this example includes a static analysis unit 10, a syntax addition unit 20, a dynamic analysis unit 30, and a program conversion unit 40. Each element of the program conversion device 100 may be realized by an arithmetic device and a memory of a computer, etc. By executing a program (different from the first program and the second program described above) for realizing the program conversion process, the arithmetic device and the memory of the computer, etc. may function as all of the static analysis unit 10, the syntax addition unit 20, the dynamic analysis unit 30, and the program conversion unit 40, or may function as a part.
[0026] The static analysis unit 10 statically analyzes the first program and extracts variable data elements whose sizes of the memory areas to be secured change. As an example, the variable data element is a list structure in which the number of list elements increases or decreases, but is not limited thereto. For example, even when the number of list elements does not change, a list structure in which the size of each list element changes corresponds to a variable data element. Further, even if it is not a list structure, data whose size changes may correspond to a variable data element.
[0027] The static analysis unit 10 may analyze each syntax included in the first program and extract variable data elements. The static analysis unit 10 may extract variable data elements by extracting a syntax including a specified instruction in advance. For example, the static analysis unit 10 extracts a syntax including an instruction for changing the size of data, and extracts a data element whose data size increases or decreases in the syntax as a variable data element. The instruction is, for example, append, del, etc. for adding or deleting a list element to or from a list structure, but is not limited thereto.
[0028] The syntax addition unit 20 adds an additional syntax for calculating the maximum value of the memory area to be secured for the variable data element to the first program. When the size of each list element is constant, the syntax addition unit 20 may insert an additional syntax for counting the number of list elements after executing the instruction corresponding to the instruction for adding or deleting a list element into the first program. The instruction may be extracted by the static analysis unit 10. For example, the additional syntax is a syntax for increasing an element count value by a predetermined unit number (for example, 1) in the case of an instruction for adding a list element, and decreasing the element count value by the unit number in the case of an instruction for deleting a list element. The element count value is a variable indicating the number of list elements included in the list structure. Further, the additional syntax preferably includes a syntax for saving the maximum value when the maximum value of the element count value is updated.
[0029] The dynamic analysis unit 30 executes the first program with the additional syntax added, and analyzes the assumed maximum value of the memory area assumed for the variable data element. The dynamic analysis unit 30 may receive the operating conditions for executing the first program, and extract the assumed maximum value when the first program is executed within the range of the operating conditions. For example, the dynamic analysis unit 30 analyzes the assumed maximum value of the memory area based on the maximum value of the element count value when the first program is executed under a predetermined operating condition. When the sizes of the respective list elements are uniform, the dynamic analysis unit 30 may use the maximum value of the number of list elements in the list structure as the maximum value of the size of the memory area.
[0030] The operating conditions of the program are, for example, conditions indicating at least one of the number and value of input data input from a user or the like for program execution. The operating conditions may indicate the range of the number of input data or the range of the value of the input data. The first program may be a program in which the number or size of list elements included in the list structure changes according to the input data. The dynamic analysis unit 30 may analyze the maximum value of the element count value when the first program is executed using the input data specified by the operating conditions. When the range of the number of input data or the range of the value of the input data is specified in the operating conditions, the dynamic analysis unit 30 may generate a plurality of types of input data sets within the range and execute the first program using each input data set. In this case, the dynamic analysis unit 30 may extract the maximum value among the maximum values of the respective element count values analyzed for each input data set. The dynamic analysis unit 30 may also execute the first program using the input data set that employs the maximum number within the range of the number of input data specified by the operating conditions or the maximum value within the range of the value of the input data, and analyze the maximum value of the element count value.
[0031] Also, when the size of each list element is not constant, the syntax addition unit 20 may insert additional syntax for calculating the size of the list structure after executing the instruction corresponding to the instruction to add or delete a list element into the first program. The syntax addition unit 20 may insert additional syntax for adding or subtracting the size of the list element to be added or deleted to / from the current size of the list structure into the first program. The additional syntax preferably includes syntax for saving the maximum value when the maximum value of the list structure is updated. The dynamic analysis unit 30 may use the maximum value as the assumed maximum value of the memory area.
[0032] The program conversion unit 40 generates a second program based on the assumed maximum value of the memory area analyzed by the dynamic analysis unit 30. The program conversion unit 40 in this example converts the first program without added additional syntax into the second program and includes pre-allocation syntax for securing a memory area of the assumed maximum value for variable data elements in the second program. The pre-allocation syntax is inserted at a position where it is executed before the syntax for changing the data size of the variable data element in the second program. The pre-allocation syntax may be inserted at the beginning of the second program.
[0033] By such processing, in the second program, it is no longer necessary to dynamically secure and release the memory area for each instruction for changing the data size of the variable data element. Therefore, the execution speed of the second program can be improved.
[0034] FIG. 2 is a diagram for explaining the outline of the first program in the first embodiment. In FIG. 2, the processing when the first program is executed is shown in a flowchart. The first program includes a list structure in which the number of list elements increases or decreases. FIG. 2 shows the syntax for increasing or decreasing the number of list elements in the first program, and other syntax is omitted. As an example, the first program includes syntax 201 for adding list element 1 in the list structure, syntax 202 for deleting list element 1, syntax 203 for adding list element 2, syntax 204 for adding list element n, and syntax 205 for deleting list element 2. In syntax 204, the process of adding list elements is repeated by the number of data input from a user or the like. Syntax 201 to syntax 205 are an example of an element number change syntax including instructions for adding or deleting elements to the list structure. The static analysis unit 10 statically analyzes the first program, extracts the list structure in which list elements 1, 2, ···, n are added or deleted as variable data elements, and extracts syntax 201 to syntax 205 for adding or deleting list elements to the list structure.
[0035] FIG. 3 is a diagram for explaining the outline of the first program with additional syntax added. The syntax addition unit 20 adds additional syntax 301 to additional syntax 305 for counting the number of elements included in the list structure to the first program corresponding to each of syntax 201 to syntax 205 extracted as element number change syntax. The syntax addition unit 20 adds the additional syntax at the position where it is executed concomitantly when the target syntax is executed. The syntax addition unit 20 may add the additional syntax immediately before, immediately after, or in the middle of the target syntax. When the process loops as in syntax 204, the syntax addition unit 20 adds the additional syntax at the position where it is executed every time the process loops.
[0036] Also, for the syntax addition part 20, for the syntaxes 201, 203, and 204 that add list elements, the additional syntaxes 301, 303, and 304 that update the element count value by increasing the element count value indicating the number of current list elements by a unit are added. The additional syntaxes 301, 303, and 304 may include a process of determining whether the updated element count value updates the maximum value of the element count value up to now, and if so, setting the current value of the element count value as the new maximum value.
[0037] For the syntax addition part 20, for the syntaxes 202 and 205 that delete list elements, the additional syntaxes 302 and 305 that update the element count value by decreasing the element count value indicating the number of current list elements by a unit are added. The additional syntaxes 302 and 305 do not necessarily include a process of determining whether the element count value updates the maximum value of the element count value up to now.
[0038] The dynamic analysis part 30 executes the first program to which the additional syntax is added. Thereby, every time the syntaxes 201 to 205 that increase or decrease the number of list elements are executed, the element count value that is the number of list elements can be updated, and the maximum value of the element count value can be updated. The dynamic analysis part 30 obtains the maximum value of the element count value at the stage when the execution of the first program ends. Thereby, the assumed maximum value that is the size of the memory area to be secured in advance for the list structure can be estimated.
[0039] The dynamic analysis part 30 may determine the assumed maximum value for each variable data element based on the size of the memory area available during the execution of the second program. The size of the memory area that can be allocated to the variable data element may be set in advance in the dynamic analysis part 30. The dynamic analysis part 30 may set the assumed maximum value for the variable data element within a range that does not exceed the size of the memory area that can be allocated.
[0040] In addition, when the second program includes a plurality of variable data elements, the dynamic analysis unit 30 may set respective assumed maximum values so that the sum of the assumed maximum values for the plurality of variable data elements does not exceed the size of the allocatable memory area. When the sum of the assumed maximum values exceeds the size of the allocatable memory area, the dynamic analysis unit 30 may set a larger assumed maximum value for a data element with a high frequency of size variation among the plurality of variable data elements. In another example, when the sum of the assumed maximum values exceeds the size of the allocatable memory area, the dynamic analysis unit 30 may reduce the sum of the assumed maximum values by multiplying each assumed maximum value by a constant coefficient less than 1.
[0041] FIG. 4 is a diagram for explaining an outline of a second program generated by the program conversion unit 40. In FIG. 4, a syntax for increasing or decreasing the number of list elements in the second program is shown, and other syntaxes are omitted. The program conversion unit 40 converts the syntaxes 201 to 205 of the first program into the syntaxes 401 to 405 of the second language. The program conversion unit 40 also inserts a pre-allocation syntax 400 at a position to be executed before the syntaxes 401 to 405. The pre-allocation syntax 400 is a syntax for pre-allocating a memory area of an assumed maximum value for variable data elements. Thereby, in each of the syntaxes 401 to 405, addition and deletion processing of data elements can be executed in the pre-allocated memory area. For this reason, in each of the syntaxes 401 to 405, processing for dynamically allocating and releasing a memory area becomes unnecessary. Therefore, a second program with a high execution speed can be generated.
[0042] FIG. 5 is a diagram showing an outline of a second program according to a comparative example. The second program in this example does not pre-allocate a memory area of an assumed maximum value for a list structure in which the number of list elements varies. In the second program of this example, each time the syntaxes 401 to 405 in which the number of list elements varies are executed, a syntax 501 for allocating a memory area for recording a new list structure and a syntax 502 for releasing the memory area in which the old list structure was recorded are executed. For this reason, the execution speed of the second program becomes slow.
[0043] FIG. 6 shows the first program according to the first embodiment. The first program of this example is a program in the Python language. In FIG. 6, the first program is shown divided into a plurality of syntaxes.
[0044] Syntax 610 defines a function used in the first program. Syntax 620 defines the initial state of the list structure (mylist). The processing in Syntax 201 to Syntax 205 is the same as the processing in Syntax 201 to Syntax 205 described in FIG. 2.
[0045] FIG. 7 shows an example of the first program in which additional syntax is inserted by the syntax addition unit 20 in the first embodiment. In FIG. 7, a part including the beginning of the first program is shown. The syntax addition unit 20 of this example inserts an analysis function definition block 615 that defines the functions used in the additional syntaxes 301 to 305 described in FIG. 3 into the first program. The analysis function definition block 615 of this example includes Syntax 701, Syntax 702, and Syntax 703.
[0046] Syntax 701 defines a function for obtaining the initial value of the element count value. Syntax 702 defines a function that, when adding a list element, increases the value of the element count value (tmp_count[0]), and when the value of the element count value becomes larger than the maximum value so far (tmp_count[1]), sets the value of the element count value as the new maximum value. Syntax 703 defines a function that, when deleting a list element, decreases the value of the element count value. The analysis function definition block 615 including these syntaxes is inserted into the first program before the additional syntaxes 301 to 305.
[0047] FIG. 8 shows an example of the first program in which additional syntax is inserted by the syntax addition unit 20 in the first embodiment. In FIG. 8, the continuation of the first program in FIG. 7 is shown. The syntax addition unit 20 adds an additional syntax 630 that defines the initial value of the element count value to the first program. The additional syntax 630 obtains the number of list elements in the initial state of the list structure as the initial value of the element count value.
[0048] Further, the syntax addition unit 20 adds additional syntaxes 301 to 305 corresponding to syntaxes 201 to 205 to the first program. The processing in the additional syntaxes 301 to 305 is the same as the processing in the additional syntaxes 301 to 305 described in FIG. 3.
[0049] The syntax addition unit 20 may add the analysis result acquisition syntax 640 to the first program. The analysis result acquisition syntax 640 outputs the final maximum value of the element count value when the first program is executed. The analysis result acquisition syntax 640 may output the final value of the element count value. The analysis result acquisition syntax 640 may output the final list structure.
[0050] FIG. 9 shows an example of a second program generated by the program conversion unit 40 in the first embodiment. The second program in this example is a C language program. The second program includes a pre-reservation syntax 400 and a main block 910. The main block 910 is a part obtained by converting a first program that does not include additional syntax into a second language.
[0051] The pre-reservation syntax 400 pre-reserves a memory area of an assumed maximum value for variable data elements (in this example, a list structure). In the example of FIG. 9, the pre-reservation syntax 400 pre-reserves an assumed maximum value as the number of list elements that the list structure (mylist) can have. Thereby, in the main block 910, even when increasing or decreasing the number of list elements in the list structure, it is not necessary to secure a new memory area for a new list structure and release the memory area for an old list structure.
[0052] FIG. 10 is a diagram showing an outline of the first program in the second embodiment. The first program of this example differs from the first program shown in FIG. 2 in that it does not have syntax 205. Also, it differs from the first program shown in FIG. 2 in that it has syntax 206 instead of syntax 204. Other syntaxes are the same as in the example of FIG. 2. In syntax 206, list element n is added to or deleted from the list structure. Note that in the first program of this example, the size of each list element is not constant. For this reason, the size of the list structure varies with the addition or deletion of list elements, and the magnitude of the size variation differs depending on the size of the list element to be added or deleted.
[0053] FIG. 11 is a diagram for explaining an outline of the first program with additional syntax added. The syntax addition section 20 adds additional syntaxes 1101 to 1106 for calculating the total size of the list elements included in the list structure to the first program corresponding to each of syntaxes 201 to 206 extracted as the element number change syntaxes.
[0054] Each additional syntax may include a syntax for updating the size count value by adding or subtracting the size of the list element to be added or deleted from the current value of the size count value, which is the total size of the list elements included in the list structure. In other examples, each additional syntax may include a syntax for calculating the size count value by integrating the sizes of the respective list elements after adding or deleting the list element. Each additional syntax may include a process of determining whether the size count value of the list structure after adding the list element has updated the maximum value of the size count value up to now, and if so, setting the size count value as the new maximum value.
[0055] The dynamic analysis unit 30 executes the first program with additional syntax added. As a result, every time the syntaxes 201 to 206 that increase or decrease the number of list elements are executed, the size count value, which is the size of the list structure, can be updated, and the maximum value of the size count value can also be updated. When the execution of the first program ends, the dynamic analysis unit 30 obtains the maximum value of the size count value. Thereby, the assumed maximum value, which is the size of the memory area to be secured in advance for the list structure, can be estimated.
[0056] FIG. 12 shows the first program according to the second embodiment. The first program in this example is a program in the Python language. In FIG. 12, the first program is shown divided into a plurality of syntaxes.
[0057] Syntax 1210 defines the list element (test_data) included in the list structure. Also, syntax 1210 defines the functions used in the first program. Syntax 1220 defines the initial state of the list structure (mylist). The processing in syntaxes 201 to 206 is the same as the processing in syntaxes 201 to 206 described in FIG. 10.
[0058] FIG. 13 shows an example of the first program in which additional syntax is inserted by the syntax addition unit 20 in the second embodiment. In FIG. 13, a part including the beginning of the first program is shown. The syntax addition unit 20 in this example inserts an analysis function definition block 1215 that defines the functions used in the additional syntaxes 1101 to 1106 described in FIG. 11 into the first program. The analysis function definition block 1215 in this example includes syntax 1301, syntax 1302, syntax 1303, and syntax 1304.
[0059] Syntax 1301 defines a function to obtain the initial value of the size count value. Syntax 1302 and Syntax 1303 define functions to update the maximum value of the size of the list structure when adding list elements. Syntax 1302 updates the size count value by accumulating the sizes of each list element included in the list structure after adding a list element. Syntax 1303 defines a new maximum value of the size of the list structure when adding a list element. Syntax 1304 defines a function to maintain the maximum value of the size count value when deleting a list element.
[0060] That is, in this example, when adding a list element, a function is defined to calculate the size count value by accumulating the sizes of each list element included in the list structure and update the maximum value if it exceeds the previous maximum value. On the other hand, when deleting a list element, since it is impossible for the size count value to exceed the maximum value, a function is defined to maintain the maximum value without calculating the size count value of the list structure. The analysis function definition block 1215 including these syntaxes is inserted before the additional syntaxes 1101 to 1106 in the first program. Note that when calculating the size count value by accumulating the sizes of each list element included in the list structure every time a list element is added, the syntax addition unit 20 does not have to add additional syntax to the syntax for deleting a list element.
[0061] Also in this example, similar to the examples of FIGS. 7 and 8, when adding or deleting list elements while retaining the current size count value, a function for updating the size count value may be defined by adding or subtracting the size of the list element from the size count value. Also, in the examples of FIGS. 7 and 8, similar to the example shown in FIG. 13, when adding a list element, a function for counting the number of list elements included in the list structure to calculate an element number count value and updating the maximum value if it exceeds the maximum value so far may be defined. Also, when deleting a list element in the examples of FIGS. 7 and 8, since there is no possibility that the element number count value exceeds the maximum value, a function for maintaining the maximum value without calculating the element number count value of the list structure may be defined. When calculating the element number count value by accumulating the number of each list element included in the list structure every time a list element is added, the syntax addition unit 20 may not add additional syntax to the syntax for deleting the list element.
[0062] FIG. 14 shows an example of a first program in which additional syntax is inserted by the syntax addition unit 20 in the second embodiment. In FIG. 14, it shows the continuation of the first program of FIG. 13. The syntax addition unit 20 adds an additional syntax 1225 that defines the initial value of the size count value to the first program. The additional syntax 1225 may obtain the total size of the list elements in the initial state of the list structure as the initial value of the size count value.
[0063] Also, the syntax addition unit 20 adds additional syntaxes 1101 to 1106 corresponding to syntaxes 201 to 206 to the first program. The processing in the additional syntaxes 1101 to 1106 is the same as the processing in the additional syntaxes 1101 to 1106 described in FIG. 11. In this example, syntax 206 includes a syntax 206-1 for adding a list element and a syntax 206-2 for deleting a list element. The syntax addition unit 20 adds an additional syntax 1106-1 for calculating the size count value when adding a list element corresponding to syntax 206-1. Also, the syntax addition unit 20 adds an additional syntax 1106-2 for maintaining the maximum value of the size count value corresponding to syntax 206-2.
[0064] The syntax addition unit 20 may add the analysis result acquisition syntax 1275 to the first program. The analysis result acquisition syntax 1275 outputs the final maximum value of the size count value when the first program is executed. The analysis result acquisition syntax 1275 may output the final list structure. Also, the analysis result acquisition syntax 1275 may output the final value of the size count value.
[0065] The program conversion unit 40 in this example may generate a second program as shown in FIG. 4. That is, according to the maximum value of the size count value, the pre-securing syntax 400 for pre-securing the assumed maximum value of the memory area may be inserted into the second program.
[0066] FIG. 15 is a diagram showing another example of the second program generated by the program conversion unit 40. The second program in this example may be applied to either the first embodiment or the second embodiment. The program conversion unit 40 in this example generates a second program including the dynamic securing syntax 1501. When the size of the memory area to be secured for the variable data element exceeds the assumed maximum value pre-secured, the dynamic securing syntax 1501 dynamically newly secures a memory area having a size exceeding the assumed maximum value for the variable data element. Dynamically securing means securing during the execution of the second program. The dynamic securing syntax 1501 stores the variable data element in the newly secured memory area and releases the old memory area. Thereby, even when the size of the memory area to be secured for the variable data element exceeds the assumed maximum value, the process for the variable data element can be executed.
[0067] The program conversion unit 40 of this example may insert the dynamic allocation statement 1501 into the second program in response to a syntax in which the size of the memory area of the variable data element varies. The dynamic allocation statement 1501 is inserted at the position where it is executed together with the statement. The dynamic allocation statement 1501 may be inserted immediately before, immediately after, or in the middle of the statement. The dynamic allocation statement 1501 is inserted for a statement (for example, statements 401, 403, 404) in which the size of the memory area of the variable data element may increase, and may not be inserted for a statement (for example, statements 402, 405) in which the size of the memory area of the variable data element decreases. Note that the dynamic allocation statement 1501 does not perform dynamic allocation and release of the memory area when the size of the memory area of the variable data element does not exceed the assumed maximum value secured in advance. Therefore, during normal operation when the size of the memory area of the variable data element does not exceed the assumed maximum value, it is not necessary to perform dynamic allocation and release of the memory area, so the execution speed of the second program can be increased. Also, since it is not necessary to set the exact maximum value of the size of the memory area of the variable data element to the assumed maximum value, it is not necessary to comprehensively set the operating conditions in the dynamic analysis of the first program. For this reason, dynamic analysis can be efficiently executed.
[0068] FIG. 16 is a diagram showing an operation example of the dynamic analysis unit 30. The operation of this example may be applied to either the first embodiment or the second embodiment. A plurality of operating conditions for analyzing the first program are given to the dynamic analysis unit 30 of this example. A range of operating conditions may be given to the dynamic analysis unit 30. In this case, the dynamic analysis unit 30 may extract a plurality of operating conditions included in the range. As described above, the operating conditions are, for example, input data input from a user or the like. Each operating condition may differ in the number of input data, the length of each data, and the like.
[0069] The dynamic analysis unit 30 determines the conditions to be used for dynamically analyzing the first program based on the occurrence probability of each condition included in the operating conditions. The dynamic analysis unit 30 may dynamically analyze the first program using the operating conditions with an occurrence probability equal to or higher than a preset threshold value. Thereby, it is possible to suppress the situation where the assumed maximum value of the memory area size of the variable data element becomes too large due to the operating conditions with a low occurrence probability. The occurrence probability of each operating condition may be given together with the operating condition. The program conversion device 100 may execute a combination of the operation of the dynamic analysis unit 30 described in FIG. 16 and the operation of the program conversion unit 40 described in FIG. 15. Thereby, a realistic assumed maximum value of the memory area size can be set, and when the size of the variable data element exceeds the assumed maximum value, the memory area can be dynamically secured.
[0070] FIG. 17 is a flowchart showing an example of a program conversion method using the program conversion device 100. In FIG. 17, some of the processes in the program conversion method are described. In the program conversion method, the processes of the program conversion device 100 described in FIGS. 1 to 16 may be performed.
[0071] The program conversion method of this example includes a static analysis stage S1701, a syntax addition stage S1702, a dynamic analysis stage S1703, and a program conversion stage S1704. The process of the static analysis stage S1701 is the same as the process of the static analysis unit 10 described in FIGS. 1 to 16. The process of the syntax addition stage S1702 is the same as the process of the syntax addition unit 20 described in FIGS. 1 to 16. The process of the dynamic analysis stage S1703 is the same as the process of the dynamic analysis unit 30 described in FIGS. 1 to 16. The process of the program conversion stage S1704 is the same as the process of the program conversion unit 40 described in FIGS. 1 to 16.
[0072] Various embodiments of the present invention may be described with reference to flowcharts and block diagrams, where the blocks may represent (1) stages of a process in which an operation is performed or (2) sections of an apparatus having a role of performing an operation. Specific stages and sections may be implemented by any of a dedicated circuit, a programmable circuit supplied with computer-readable instructions stored on a computer-readable medium, and a processor supplied with computer-readable instructions stored on a computer-readable medium. The dedicated circuit may include either digital or analog hardware circuits, and may include either an integrated circuit (IC) or discrete circuits. The programmable circuit may include a reconfigurable hardware circuit including memory elements such as logical AND, logical OR, logical XOR, logical NAND, logical NOR, and other logical operations, flip-flops, registers, field programmable gate arrays (FPGA), programmable logic arrays (PLA), etc.
[0073] The computer-readable medium may include any tangible device capable of storing instructions executable by an appropriate device, and as a result, a computer-readable medium having instructions stored therein will comprise a product including instructions executable to create means for performing the operations specified in the flowchart or block diagram. Examples of computer-readable media may include electronic storage media, magnetic storage media, optical storage media, electromagnetic storage media, semiconductor storage media, etc. More specific examples of computer-readable media may include floppy (registered trademark) disks, diskettes, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), electrically erasable programmable read-only memory (EEPROM), static random access memory (SRAM), compact disk read-only memory (CD-ROM), digital versatile disk (DVD), Blu-ray (RTM) disk, memory stick, integrated circuit card, etc.
[0074] Computer-readable instructions may include any combination of one or more programming languages, including assembly instructions, instruction set architecture (ISA) instructions, machine instructions, machine-dependent instructions, microcode, firmware instructions, state-setting data, or source code or object code written in an object-oriented programming language such as Smalltalk, JAVA (registered trademark), C++, and a conventional procedural programming language such as the "C" programming language or a similar programming language.
[0075] Computer-readable instructions may be provided locally or via a wide area network (WAN) such as a local area network (LAN), the Internet, etc., to a processor or programmable circuit of a general-purpose computer, a special-purpose computer, or other programmable data processing device, and the computer-readable instructions may be executed to create means for performing the operations specified in a flowchart or block diagram. Examples of processors include computer processors, processing units, microprocessors, digital signal processors, controllers, microcontrollers, etc.
[0076] FIG. 18 shows an example of a computer 2200 in which multiple aspects of the present invention may be embodied, in whole or in part. Programs installed on the computer 2200 may cause the computer 2200 to function as an operation associated with the device according to an embodiment of the present invention or as one or more sections of the device, or may cause the computer 2200 to execute the operation or the one or more sections. The computer 2200 may also be caused to execute a process according to an embodiment of the present invention or a stage of the process. Such a program may be executed by the CPU 2212 to cause the computer 2200 to perform specific operations associated with some or all of the blocks of the flowcharts and block diagrams described herein.
[0077] The computer 2200 according to this embodiment includes a CPU 2212, a RAM 2214, a graphic controller 2216, and a display device 2218, which are mutually connected by a host controller 2210. The computer 2200 also includes input / output units such as a communication interface 2222, a hard disk drive 2224, a DVD-ROM drive 2226, and an IC card drive, which are connected to the host controller 2210 via an input / output controller 2220. The computer also includes legacy input / output units such as a ROM 2230 and a keyboard 2242, which are connected to the input / output controller 2220 via an input / output chip 2240.
[0078] The CPU 2212 operates according to programs stored in the ROM 2230 and the RAM 2214, thereby controlling each unit. The graphic controller 2216 acquires image data generated by the CPU 2212 in a frame buffer or the like provided in the RAM 2214 or in itself, and causes the image data to be displayed on the display device 2218.
[0079] The communication interface 2222 communicates with other electronic devices via a network. The hard disk drive 2224 stores programs and data used by the CPU 2212 in the computer 2200. The DVD-ROM drive 2226 reads a program or data from the DVD-ROM 2201 and provides the program or data to the hard disk drive 2224 via the RAM 2214. The IC card drive reads programs and data from an IC card and writes programs and data to the IC card.
[0080] The ROM 2230 stores therein either a boot program or the like executed by the computer 2200 upon activation, and a program dependent on the hardware of the computer 2200. The input / output chip 2240 may also be connected to the input / output controller 2220 via various input / output units through a parallel port, a serial port, a keyboard port, a mouse port, or the like.
[0081] The program is provided by a computer-readable medium such as a DVD-ROM 2201 or an IC card. The program is read from the computer-readable medium, installed in the hard disk drive 2224, the RAM 2214, or the ROM 2230, which are also examples of computer-readable media, and executed by the CPU 2212. The information processing described in these programs is read by the computer 2200, resulting in the cooperation between the programs and the various types of hardware resources described above. The apparatus or method may be configured by realizing the operation or processing of information according to the use of the computer 2200.
[0082] For example, when communication is executed between the computer 2200 and an external device, the CPU 2212 may execute a communication program loaded in the RAM 2214 and instruct the communication interface 2222 to perform communication processing based on the processing described in the communication program. The communication interface 2222 reads the transmission data stored in the transmission buffer processing area provided in a recording medium such as the RAM 2214, the hard disk drive 2224, the DVD-ROM 2201, or the IC card under the control of the CPU 2212, transmits the read transmission data to the network, or writes the received data received from the network to the reception buffer processing area provided on the recording medium.
[0083] In addition, the CPU 2212 may cause all or necessary portions of files or databases stored in external recording media such as a hard disk drive 2224, a DVD-ROM drive 2226 (DVD-ROM 2201), an IC card, etc. to be read into the RAM 2214, and may execute various types of processing on the data on the RAM 2214. Next, the CPU 2212 writes back the processed data to the external recording media.
[0084] Various types of information such as various types of programs, data, tables, and databases may be stored in the recording media and may undergo information processing. The CPU 2212 may execute various types of processing on the data read from the RAM 2214, including any of various types of operations, information processing, condition determination, conditional branching, unconditional branching, information search and replacement, etc. described throughout this disclosure and specified by the instruction sequence of the program, and write back the results to the RAM 2214. Also, the CPU 2212 may search for information in files, databases, etc. within the recording media. For example, when a plurality of entries each having an attribute value of a first attribute associated with an attribute value of a second attribute are stored in the recording media, the CPU 2212 searches for an entry that matches the condition where the attribute value of the first attribute is specified from among the plurality of entries, reads the attribute value of the second attribute stored within the entry, and thereby may obtain the attribute value of the second attribute associated with the first attribute that satisfies a predetermined condition.
[0085] The programs or software modules described above may be stored in a computer-readable medium on or near the computer 2200. Also, a recording medium such as a hard disk or RAM provided within a server system connected to a dedicated communication network or the Internet can be used as a computer-readable medium, thereby providing the program to the computer 2200 via the network.
[0086] As described above, the present invention has been described using embodiments, but the technical scope of the present invention is not limited to the scope described in the above embodiments. It is obvious to those skilled in the art that various changes or improvements can be made to the above embodiments. It is clear from the description of the claims that forms with such changes or improvements can also be included in the technical scope of the present invention.
[0087] In the claims, the specification, and the drawings, the execution order of each process such as operations, procedures, steps, and stages in the apparatus, system, program, and method shown is not explicitly stated as "before" or "preceding" etc., and it should be noted that it can be realized in any order as long as the output of the previous process is not used in the subsequent process. Regarding the operation flow in the claims, the specification, and the drawings, even if it is described using "first," "next," etc. for convenience, it does not mean that it is essential to be implemented in this order.
Explanation of Reference Numerals
[0088] 10... Static analysis unit, 20... Syntax addition unit, 30... Dynamic analysis unit, 40... Program conversion unit, 100... Program conversion device, 201, 202, 203, 204, 0205, 206... Syntax, 301, 302, 303, 304, 305... Additional syntax, 400... Pre-guaranteed syntax, 401, 402, 403, 404, 405... Syntax, 501, 502... Syntax, 610, 620... Syntax, 615... Analysis function definition block, 630... Additional syntax, 640... Analysis result acquisition syntax, 701, 702, 703... Syntax, 910... Main block, 1101, 1102, 1103, 1106... Additional syntax, 1210, 1220... Syntax, 1215... Analysis function definition block, 1220... Syntax, 1225... Additional syntax, 1275... Analysis result acquisition syntax, 1301, 1302, 1303, 1304... Syntax, 1501... Dynamic guarantee syntax
Claims
1. A program conversion device that converts a first program in a first language into a second program in a second language, a static analysis unit that analyzes the first program and extracts variable data elements whose memory area sizes to be secured change, a syntax addition unit that adds an additional syntax for calculating the maximum value of the memory area to be secured for the variable data elements into the first program, a dynamic analysis unit that executes the first program with the additional syntax added and analyzes the assumed maximum value of the memory area assumed for the variable data elements A program conversion device comprising:
2. Further comprising a program conversion unit that generates the second program, including a pre-securing syntax for securing a memory area of the assumed maximum value for the variable data elements The program conversion device according to claim 1.
3. The static analysis unit extracts the variable data elements by extracting a syntax including a pre-specified instruction. The program conversion device according to claim 1 or 2.
4. The static analysis unit extracts, as the variable data elements, a list structure whose number of list elements changes in the first program, and extracts an element number change syntax including an instruction to add or delete the list elements to / from the list structure, The syntax addition unit adds, corresponding to the element number change syntax, the additional syntax for counting the number of the list elements included in the list structure into the first program. The program conversion device according to claim 3.
5. The static analysis unit extracts, as the variable data elements, a list structure whose number of list elements changes in the first program, and extracts an element number change syntax including an instruction to add or delete the list elements to / from the list structure, The syntax addition unit adds the additional syntax for calculating the total size of the list elements included in the list structure to the first program in response to the element number change syntax. The program conversion apparatus according to claim 3.
6. When the size of the memory area to be secured for the variable data element exceeds the assumed maximum value in the second program generated by the program conversion unit, the second program includes a dynamic allocation syntax for dynamically allocating a memory area having a size exceeding the assumed maximum value for the variable data element. The program conversion apparatus according to claim 2.
7. When an operation condition for executing the first program is input to the dynamic analysis unit, the assumed maximum value is extracted when the first program is executed within the range of the operation condition. The program conversion apparatus according to any one of claims 1 to 6.
8. The dynamic analysis unit determines the condition for executing the first program based on the occurrence probability of each condition included in the operation condition. The program conversion apparatus according to claim 7.
9. The dynamic analysis unit determines the assumed maximum value for each variable data element based on the size of the available memory area. The program conversion apparatus according to any one of claims 1 to 8.
10. The second language is a compiler language. The program conversion apparatus according to any one of claims 1 to 9.
11. A program conversion method for converting a first program in a first language into a second program in a second language, comprising: a static analysis step in which a computer analyzes the first program and extracts variable data elements whose memory area sizes to be secured change; A syntax addition step of adding, to the first program, additional syntax for calculating a maximum value of the memory area to be secured for the variable data element by the computer; A dynamic analysis step of analyzing an assumed maximum value of the memory area assumed for the variable data element by executing the first program to which the additional syntax has been added by the computer; A program conversion method comprising: Claim 12 A program for causing a computer to execute the program conversion method according to claim 11.
Citation Information
Patent Citations
Dynamic storage area allocation system
JP1997330232A
Program converter
JP2002108628A
System for providing program executing service, method for providing server and program executing service, and its program
JP2002304383A
Starting method for computer system, information processor, and program
JP2008225617A
Program generator
JP2013025403A