Translation device, translation method, and program
Patent Information
- Authority / Receiving Office
- JP · JP
- Patent Type
- Patents
- Current Assignee / Owner
- Filing Date
- 2024-04-08
- Publication Date
- 2026-03-17
Smart Images

Figure 00000010_0000 
Figure 00000010_0001 
Figure 00000011_0000
Abstract
Description
[Technical field]
[0001] The present disclosure relates to a translation device, a translation method, and a program. [Background technology]
[0002] There is a known technique for translating source code written in a programming language for sequence control programs, such as ST language, into a high-level language, such as C language. For example, Patent Document 1 discloses an engineering tool that converts source code written in ST language into source code written in C language. [Prior art documents] [Patent documents]
[0003] [Patent Document 1] JP 2007-133622 A Summary of the Invention [Problem to be solved by the invention]
[0004] Generally, programs based on source code written in a high-level language such as C have higher processing performance than programs based on source code written in a programming language for sequence control programs such as ST language. On the other hand, programs based on source code written in a programming language for sequence control programs generally have better debuggability than programs based on source code written in a high-level language because they can easily implement debugging functions such as step execution, setting observation points, and monitoring variables.
[0005] Therefore, there is a demand for a technology that appropriately translates a part of source code written in a programming language for sequence control programs into a high-level language, taking into consideration both high speed and debuggability. However, the engineering tool described in Patent Document 1 simply converts source code written in ST language into source code written in C language, and is unable to meet this demand.
[0006] In view of the above circumstances, an object of the present disclosure is to provide a translation device or the like capable of translating a portion of source code written in a programming language for a sequence control program into a high-level language, taking into consideration both high speed and debuggability. [Means for solving the problem]
[0007] In order to achieve the above object, a translation device according to the present disclosure includes: a block extracting means for extracting a block, which is a part of a source code, from a source code of a sequence control program; a translation object determining means for determining which of the blocks extracted by said block extracting means should be translated into a high-level language; a translation means for translating, into the high-level language, a block determined by the translation object determination means to be translated into the high-level language; a performance estimation means for estimating, for each block extracted by said block extraction means, a processing performance when said block is translated into said high-level language and a processing performance when said block is not translated into said high-level language; a presentation means for presenting to a user, for each of the blocks, the processing performance estimated by the performance estimation means when the block is translated into the high-level language and the processing performance when the block is not translated into the high-level language; Equipped with. Effect of the Invention
[0008] According to the present disclosure, a portion of source code written in a programming language for a sequence control program can be translated into a high-level language, taking into consideration both high speed and debuggability. [Brief description of the drawings]
[0009] [Figure 1] FIG. 1 is a block diagram showing a functional configuration of a translation device according to a first embodiment of the present disclosure. [Diagram 2]FIG. 1 is a diagram illustrating an example of block extraction by a block extractor of a translation device according to a first embodiment of the present disclosure. [Diagram 3] FIG. 1 is a diagram illustrating an example of block extraction by a block extractor of a translation device according to a first embodiment of the present disclosure. [Figure 4] FIG. 1 is a diagram illustrating an example of processing performance presented by a presentation unit of a translation device according to a first embodiment of the present disclosure. [Diagram 5] FIG. 1 is a diagram illustrating an example of a translated source code obtained by a translation unit of a translation device according to a first embodiment of the present disclosure. [Figure 6] FIG. 1 is a diagram illustrating an example of a hardware configuration of a translation device according to a first embodiment of the present disclosure. [Figure 7] A flowchart showing an example of a translation operation performed by the translation device according to the first embodiment of the present disclosure. [Figure 8] FIG. 11 is a block diagram showing a functional configuration of a translation device according to a second embodiment of the present disclosure. [Figure 9] FIG. 13 is a block diagram showing a functional configuration of a translation device according to a third embodiment of the present disclosure. DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENTS
[0010] Hereinafter, a translation device according to an embodiment of the present disclosure will be described with reference to the drawings. In each drawing, the same or equivalent parts are denoted by the same reference numerals.
[0011] (Embodiment 1) A translation device 1 according to the first embodiment will be described with reference to FIG. 1. A display device 2 and an input device 3 are connected to the translation device 1. The translation device 1 is a translation device that translates a part of a source code written in a programming language for a sequence control program, such as ST language or ladder language, into a high-level language, such as C language. Hereinafter, for convenience, the original source code written in the programming language for the sequence control program is referred to as a "pre-translation source code". Also, the source code obtained by translating a part of the pre-translation source code into a high-level language is referred to as a "post-translation source code". The sequence control program is executed, for example, by a programmable logic controller. The translation device 1 is an example of a translation device according to the present disclosure.
[0012] First, a brief description will be given of what is achieved by the translation device 1. As will be described later, the translation device 1 extracts a plurality of blocks from the pre-translation source code based on a control syntax contained in the pre-translation source code. A block is a group of code in a programming language, and is a part of the source code. As will be described later, the blocks extracted based on the control syntax have a size that can be expected to increase the speed when translated into a high-level language, and also have a size that takes debuggability into consideration.
[0013] The translation device 1 estimates the processing performance when each extracted block is translated into a high-level language and the processing performance when the block is not translated into a high-level language, and presents the estimated processing performance to the user. Based on the presented content, the user specifies blocks that are not to be translated into a high-level language.
[0014] The translation device 1 translates blocks other than the block specified by the user into a high-level language. The translated source code generated by the translation device 1 includes both blocks written in a programming language for a sequence control program and blocks written in a high-level language. This allows the translation device 1 to translate a part of the untranslated source code into a high-level language while taking into consideration both high speed and debuggability.
[0015] In the following description, the programming language for sequence control programs is assumed to be ST language, and the high-level language is assumed to be C. However, the following description is also applicable to programming languages for sequence control programs other than ST language, and high-level languages other than C language.
[0016] Next, the display device 2 and the input device 3 will be described. The display device 2 is a device for displaying the contents presented by the translation device 1. The display device 2 is, for example, a liquid crystal display. The input device 3 is a device for accepting input operations by a user to the translation device 1. The input device 3 is, for example, an input device such as a mouse or a keyboard. The display device 2 and the input device 3 may be an integrated touch screen.
[0017] Next, a description will be given of a functional configuration of the translation device 1. The translation device 1 includes a storage unit 10, a block extraction unit 11, a performance estimation unit 12, a presentation unit 13, a translation subject determination unit 14, and a translation unit 15.
[0018] The storage unit 10 stores the untranslated source code and also stores translated source code obtained by the translation unit 15, which will be described later, translating a part of the untranslated source code.
[0019] The block extraction unit 11 extracts a plurality of blocks from the pre-translation source code stored in the storage unit 10 based on a control syntax included in the pre-translation source code. The control syntax is a syntax for controlling the execution order of each step of a program, such as an IF statement, a FOR statement, a function call statement, etc. The block extraction unit 11 is an example of a block extraction means according to the present disclosure.
[0020] An example of block extraction by the block extraction unit 11 will be described with reference to FIG. 2. The source code shown in FIG. 2 is pre-translation source code. This pre-translation source code includes consecutive statements that do not include control syntax, a FOR statement, an IF statement, and a function call statement. The block extraction unit 11 extracts the consecutive statements that do not include control syntax as one block. The block extraction unit 11 extracts each of the FOR statement, the IF statement, and the function call statement as one block. The extracted block is a part of the pre-translation source code. Hereinafter, the source code corresponding to a block may be referred to as a "code fragment."
[0021] Another example of block extraction by the block extraction unit 11 will be described with reference to Fig. 3. The source code shown in Fig. 3 includes a FOR statement including a FOR statement and an IF statement including a FOR statement. In other words, the source code shown in Fig. 3 includes a portion in which control statements are nested. In this case, the block extraction unit 11 extracts the inner control statement as a lower block and the outer control statement as a higher block. In this way, when the control statements are nested, the extracted blocks are also nested.
[0022] The blocks extracted by the block extraction unit 11 based on the control syntax have a size that can be expected to increase the speed when translated into C language, and also have a size that takes debuggability into consideration. The reason for the increase in speed is that when translating into C language, translating a certain number of chunks is more advantageous in increasing the speed than translating each statement. The reason for the debuggability is that loop variables in FOR statements, variables used for conditional branching in IF statements, arguments passed in function call statements, and the like are likely to be targets of monitoring during debugging. In addition, if blocks are extracted in finer detail, the number of targets to be specified in the user specification described later will become enormous, which will increase the burden on the user, so block extraction based on the control syntax also has the effect of reducing the burden on the user.
[0023] Referring again to FIG. 1, the performance estimation unit 12 estimates, for each of the multiple blocks extracted by the block extraction unit 11, the processing performance when the block is translated into C language and the processing performance when the block is not translated into C language. For each block, the performance estimation unit 12 estimates the processing performance when the block is not translated into C language based on the code fragment of the block before translation. The performance estimation unit 12 translates the block into C language to obtain a code fragment, and estimates the processing performance when the block is translated into C language based on the obtained code fragment. The performance estimation unit 12 is an example of a performance estimation means according to the present disclosure.
[0024] The performance estimation unit 12, for example, refers to a database of execution times of each statement in each language and analyzes the statements contained in the block to estimate the processing performance. Alternatively, the performance estimation unit 12 estimates the processing performance for each block by executing both a program based on the untranslated code fragment and a program based on the translated code fragment in a programmable logic controller and measuring the execution times.
[0025] The presentation unit 13 presents to the user via the display device 2 the processing performance estimated by the performance estimation unit 12 for each block when the block is translated into C language and the processing performance when the block is not translated into C language. The presentation unit 13 presents to the user, for example, the result shown in FIG. 4. In FIG. 4, execution time is shown as the processing performance. FIG. 4 relates to the untranslated source code shown in FIG. 2. The presentation unit 13 is an example of a presentation means according to the present disclosure.
[0026] Referring again to FIG. 1, the translation target determination unit 14 identifies blocks that are not to be translated into C language based on the user's input, and identifies blocks other than the identified blocks as blocks to be translated into C language. The user operates the input device 3 to specify blocks to be excluded from the translation target based on, for example, the results presented by the presentation unit 13, how much speedup is desired, and how debugging is desired. The translation target determination unit 14 identifies blocks that are not to be translated into C language in response to the user's designation operation. The translation target determination unit 14 is an example of a translation target determination means according to the present disclosure.
[0027] The translation unit 15 translates all blocks determined as translation targets by the translation target determination unit 14 into C language to obtain translated source code. Note that, as necessary, the translation unit 15 also changes the source code for blocks that have not been translated into C language and remain in ST language so as to call the blocks translated into C language. The translation unit 15 stores the translated source code obtained by the translation in the storage unit 10. The translation unit 15 is an example of a translation means according to the present disclosure.
[0028] An example of the translated source code obtained by the translation unit 15 will be described with reference to FIG. 5. The translated source code shown in FIG. 5 is obtained by translating the pre-translation source code shown in FIG. 2. The shaded portion in FIG. 5 indicates a portion of the ST language part of the translated source code that has been changed from the pre-translation source code. In the translated source code shown in FIG. 5, a block corresponding to the FOR statement in the pre-translation source code shown in FIG. 2 is translated into C language to become the C language part shown in FIG. 5, and the ST language part is changed to call the C_Func_Call function written in C language. The get_label_ptr function written in the C language part is a function for referring to a variable in the ST language part that corresponds to the variable name specified by an argument. This function allows the C language part to refer to the variable used in the ST language part.
[0029] Next, an example of a hardware configuration of translation device 1 will be described with reference to Fig. 6. Translation device 1 shown in Fig. 6 is realized by, for example, a personal computer on which an engineering tool program is installed.
[0030] The translation device 1 includes a processor 1001 , a memory 1002 , an interface 1003 , and a secondary storage device 1004 , which are connected to each other via a bus 1000 .
[0031] The processor 1001 is, for example, a CPU (Central Processing Unit). The processor 1001 loads an engineering tool program stored in the secondary storage device 1004 into the memory 1002 and executes the program, thereby implementing each function of the translation device 1.
[0032] The memory 1002 is a main storage device constituted by, for example, a RAM (Random Access Memory). The memory 1002 stores the program of the engineering tool that the processor 1001 reads from the secondary storage device 1004. The memory 1002 also functions as a working memory when the processor 1001 executes the program of the engineering tool.
[0033] The interface 1003 is an I / O (Input / Output) interface such as a serial port, a USB (Universal Serial Bus) port, or a network interface.
[0034] The secondary storage device 1004 is, for example, a flash memory, a hard disk drive (HDD), or a solid state drive (SSD). The secondary storage device 1004 stores a program of an engineering tool executed by the processor 1001. The secondary storage device 1004 also realizes the function of the storage unit 10.
[0035] Next, an example of the translation operation by the translation device 1 will be described with reference to Fig. 7. The operation shown in Fig. 7 is started when, for example, a user operates the input device 3 to perform an operation to translate the untranslated source code.
[0036] The block extracting unit 11 of the translation apparatus 1 extracts blocks from the pre-translation source code stored in the storage unit 10 based on control statements contained in the pre-translation source code (step S101).
[0037] Performance estimation unit 12 of translation apparatus 1 estimates the processing performance before and after translation for each block (step S102).
[0038] Presentation unit 13 of translation apparatus 1 presents the pre-translation and post-translation processing performances estimated in step S102 for each block (step S103).
[0039] The translation target determining unit 14 of the translation apparatus 1 waits for a designation operation by the user, and identifies the block designated by the user as a block not to be translated (step S104).
[0040] The translation target determination unit 14 determines, from among the blocks extracted in step S101, the blocks other than the blocks identified in step S104 as blocks not to be translated, as targets for translation (step S105).
[0041] Translation unit 15 of translation apparatus 1 translates the block determined as the translation target in step S105 into C language, and stores the translated source code in storage unit 10 (step S106).
[0042] The translation device 1 according to the first embodiment has been described above. The translation device 1 extracts a plurality of blocks from the pre-translation source code based on a control syntax included in the pre-translation source code written in a programming language for a sequence control program. The blocks extracted in this way have a size that can be expected to increase the speed when translated into a high-level language, and a size that takes debuggability into consideration. The translation device 1 determines a block to be translated from the extracted plurality of blocks, and translates the block to be translated into a high-level language. The translation device 1 estimates the processing performance before and after translation for each block, and presents it to the user. The user can specify which block to exclude from the translation target, taking into consideration both speed and debuggability, with reference to the presented result. Thus, the translation device 1 can translate a part of the source code written in a programming language for a sequence control program into a high-level language, taking into consideration both speed and debuggability.
[0043] (Embodiment 2) A translation device 1 according to the second embodiment will be described with reference to Fig. 8. The translation device 1 according to the second embodiment differs from the first embodiment in that it further includes a setting unit 16 and a set identifying unit 17. It also differs from the first embodiment in that the function of the presenting unit 13 is added.
[0044] In the second embodiment, a user can set a target performance of a sequence control program. The translation device 1 identifies and presents a set of blocks that meets the target performance and has a minimum total number of steps to be translated when translated into a high-level language. Based on the presented results, the user can specify blocks that will not be translated. By minimizing the total number of steps to be translated, it is possible to achieve the target performance at high speed while improving debuggability as much as possible. This is because the fewer the number of steps to be translated, the more parts that will not be translated, and the parts that will not be translated have excellent debuggability.
[0045] The setting unit 16 accepts a setting operation of the target performance by the user via the input device 3. The setting unit 16 sets the target performance based on the user's operation. The setting unit 16 is an example of a setting means according to the present disclosure.
[0046] The set identification unit 17 identifies a set of blocks that satisfies the target setting and minimizes the total number of steps to be translated when translated into a high-level language. The set identification unit 17 is an example of a set identification means according to the present disclosure.
[0047] In addition to the first embodiment, the presentation unit 13 presents to the user a set of blocks that meets the target setting and that minimizes the total number of steps to be translated when translated into a high-level language, as identified by the set identification unit 17. The user can specify blocks that are not to be translated by referring to the processing performance of each block as in the first embodiment and the newly presented set of blocks.
[0048] (Modification of the second embodiment) In the second embodiment, the translation target determination unit 14 may automatically determine, as the translation target, a set of blocks that meets the target setting specified by the set specification unit 17 and that will result in the smallest total number of steps in the translation target when translated into a high-level language, without waiting for a user's designation. This allows the user to automatically obtain a translated program that meets the desired target setting and has the most improved debuggability.
[0049] (Embodiment 3) A translation device 1 according to the third embodiment will be described with reference to Fig. 9. The translation device 1 according to the third embodiment differs from the first embodiment in that it further includes a setting unit 18. Also, the function of the translation target determination unit 14 differs from that of the first embodiment. Note that this setting unit 18 differs from the setting unit 16 according to the second embodiment.
[0050] The setting unit 18 sets the observation target in the pre-translation source code based on the input operation of the user. The user can specify variables in the source code, specific statements in the source code, etc. as the observation target. For example, the values of variables specified as observation targets are constantly displayed during debugging. Also, for example, when a program executes a statement specified as an observation target during debugging, the user can pause program execution, display variables related to the statement, etc. The setting unit 18 is an example of a setting means according to the present disclosure.
[0051] Unlike the first embodiment, the translation target determination unit 14 automatically determines blocks that do not include the observation target set by the setting unit 18 as blocks to be translated into a high-level language. This ensures debuggability by not translating blocks that include the observation target into a high-level language, and makes it possible to automatically translate other blocks into a high-level language. This ensures the debuggability required by the user, while automatically speeding up the process without placing a burden on the user to specify blocks.
[0052] (Other variations) In the example of translation shown in FIG. 5, the variables used in the ST language part are referenced by the get_label_ptr function in the C language part. On the other hand, variables used within one block in the pre-translation source code may be converted into local variables in the C language. For example, in the example of the pre-translation source code shown in FIG. 2, if the variable Z is not used except within the FOR statement, the variable Z can be converted into a local variable in the C language. This can further speed up the block. However, when the variable Z is specified as an observation target as in the third embodiment, it should not be converted into a local variable but should be referenced by the get_label_ptr function.
[0053] In the processing performance estimation by the performance estimation unit 12, the processing performance may be estimated using a trained model constructed with code fragments as input and processing performance as output. For example, a trained model may be constructed in advance based on the code fragments and the measurement results by executing a program on a programmable logic controller in advance for a large number of code fragments both before and after translation to measure the processing performance.
[0054] In each embodiment, the user specifies blocks that are not to be translated into a high-level language, but the user may specify blocks that are to be translated. In this case, the same effects as those of each embodiment are achieved.
[0055] 6, translation device 1 includes secondary storage device 1004. However, the present invention is not limited to this, and secondary storage device 1004 may be provided outside translation device 1, and translation device 1 and secondary storage device 1004 may be connected via interface 1003. In this configuration, removable media such as a USB flash drive or a memory card may also be used as secondary storage device 1004.
[0056] 6, translation device 1 may be configured with a dedicated circuit using an ASIC (Application Specific Integrated Circuit), an FPGA (Field Programmable Gate Array), etc. In the hardware configuration shown in FIG. 6, a part of the functions of translation device 1 may be realized by a dedicated circuit connected to interface 1003, for example.
[0057] The programs used in the translation device 1 can be distributed by storing them in computer-readable recording media such as CD-ROMs (Compact Disc Read Only Memory), DVDs (Digital Versatile Discs), USB flash drives, memory cards, HDDs, etc. By installing such programs in a specific or general-purpose computer, the computer can function as the translation device 1.
[0058] Furthermore, the above-mentioned program may be stored in a storage device owned by another server on the Internet, and the above-mentioned program may be downloaded from that server.
[0059] Various embodiments and modifications of the present disclosure are possible without departing from the broad spirit and scope of the present disclosure. The above-described embodiments are for explaining the present disclosure and do not limit the scope of the present disclosure. In other words, the scope of the present disclosure is indicated by the claims, not the embodiments. Various modifications made within the scope of the claims and within the scope of the disclosure equivalent thereto are considered to be within the scope of the present disclosure. [Explanation of symbols]
[0060] 1 translation device, 2 display device, 3 input device, 10 memory unit, 11 block extraction unit, 12 performance estimation unit, 13 presentation unit, 14 translation target determination unit, 15 translation unit, 16 setting unit, 17 set identification unit, 18 setting unit, 1000 bus, 1001 processor, 1002 memory, 1003 interface, 1004 secondary storage device.
Claims
1. A block extraction means for extracting a block that is part of the source code from the source code of a sequence control program, A translation target determination means that determines which of the blocks extracted by the block extraction means will be translated into a high-level language, Translation means for translating blocks that have been determined to be translated into the high-level language by the translation target determination means into the high-level language, For each block extracted by the block extraction means, a performance estimation means estimates the processing performance when the block is translated into the high-level language and the processing performance when the block is not translated into the high-level language. For each of the aforementioned blocks, a presentation means presents to the user the processing performance estimated by the performance estimation means when the block is translated into the high-level language, and the processing performance when the block is not translated into the high-level language. A translation device equipped with the following features.
2. A block extraction means for extracting a block which is a part of the source code from the source code of a sequence control program, A translation target determination means that determines which of the blocks extracted by the block extraction means will be translated into a high-level language, Translation means for translating blocks that have been determined to be translated into the high-level language by the translation target determination means into the high-level language, A setting means for setting target performance based on user input, A set identification means for identifying a set of blocks that satisfies the aforementioned target performance and minimizes the total number of steps to be translated when translated into the aforementioned high-level language, A presentation means for presenting the set identified by the set identification means to the user, A translation device equipped with the following features.
3. The aforementioned block is of a size that is expected to provide a speedup effect when translated into the aforementioned high-level language, and is also of a size that takes debuggability into consideration. The translation device according to claim 1.
4. The block extraction means extracts blocks based on the control structures contained in the source code. A translation device according to any one of claims 1 to 3.
5. The translation target determination means further identifies blocks that will not be translated into the high-level language based on the user's input, and determines that blocks other than the identified blocks will be translated into the high-level language. A translation device according to any one of claims 1 to 3.
6. Further comprising setting means for setting the object to be observed in the source code based on the user's input, The translation target determination means determines that blocks that do not contain the observed object are to be translated into the high-level language. A translation device according to any one of claims 1 to 3.
7. The translation means, in translating a block that has been decided to be translated into the high-level language, translates variables used only in that block as local variables of the high-level language. A translation device according to any one of claims 1 to 3.
8. The performance estimation means estimates processing performance based on a trained model. The translation device according to claim 1.
9. From the source code of the sequence control program, a block which is part of the source code is extracted. We decide which of the extracted blocks to translate into a high-level language. The blocks that have been decided to be translated into the aforementioned high-level language are translated into the aforementioned high-level language. For each extracted block, estimate the processing performance when the block is translated into the high-level language and the processing performance when the block is not translated into the high-level language. For each of the aforementioned blocks, the estimated processing performance when the block is translated into the high-level language and the processing performance when the block is not translated into the high-level language are presented to the user. Translation method.
10. Extract a block which is a part of the source code from the source code of a sequence control program, We decide which of the extracted blocks to translate into a high-level language. The blocks that have been decided to be translated into the aforementioned high-level language are translated into the aforementioned high-level language. Based on user input, set target performance. Identify a set of blocks that satisfies the aforementioned target performance and minimizes the total number of steps to be translated when translated into the aforementioned high-level language. The identified pair is presented to the user. Translation method.
11. Computers, A block extraction means for extracting a block that is part of the source code from the source code of a sequence control program. Translation target determination means that determines which of the blocks extracted by the block extraction means will be translated into a high-level language. Translation means for translating blocks that have been determined to be translated into the high-level language by the translation target determination means into the high-level language, For each block extracted by the block extraction means, a performance estimation means estimates the processing performance when the block is translated into the high-level language and the processing performance when the block is not translated into the high-level language. For each of the aforementioned blocks, a presentation means presents to the user the processing performance estimated by the performance estimation means when the block is translated into the high-level language, and the processing performance when the block is not translated into the high-level language. A program that makes it function as such.
12. A computer, A block extraction means for extracting a block that is part of the source code from the source code of a sequence control program. Translation target determination means that determines which of the blocks extracted by the block extraction means will be translated into a high-level language. Translation means for translating blocks that have been determined to be translated into the high-level language by the translation target determination means into the high-level language, A setting means for setting target performance based on user input. A set identification means for identifying a set of blocks that satisfies the aforementioned target performance and minimizes the total number of steps to be translated when translated into the aforementioned high-level language. Presentation means for presenting the set identified by the set identification means to the user, A program that makes it function as such.