Translation device, translation method, and program

The translation device addresses the imbalance in speed and debuggability by extracting and selectively translating code blocks, achieving efficient translation that balances processing speed and debuggability.

WO2025215697A1PCT designated stage Publication Date: 2025-10-16MITSUBISHI ELECTRIC CORP
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
PCT/JP2024/014246
Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
Filing Date
2024-04-08
Publication Date
2025-10-16

AI Technical Summary

Technical Problem

Existing translation tools fail to balance processing speed and debuggability when converting source code from sequence control programming languages to high-level languages, as they do not selectively translate portions of the code based on both performance and debuggability considerations.

Method used

A translation device that extracts blocks from source code, estimates processing performance, and allows users to specify which blocks to translate into a high-level language, balancing speed and debuggability by translating only selected blocks.

Benefits of technology

The device effectively translates source code portions into high-level languages while maintaining high speed and ensuring good debuggability by allowing selective translation of blocks, thus optimizing both performance and debugging capabilities.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure JP2024014246_16102025_PF_FP_ABST
    Figure JP2024014246_16102025_PF_FP_ABST
Patent Text Reader

Abstract

A translation device (1) comprises a block extraction unit (11) that extracts blocks that are a portion of source code for a sequence control program from the source code, a translation target determination unit (14) that determines which blocks of the blocks extracted by the block extraction unit (11) are to be translated into a high-level language, and a translation unit (15) that translates the blocks that the translation target determination unit (14) has determined are to be translated into the high-level language into the high-level language.
Need to check novelty before this filing date? Find Prior Art

Description

Translation device, translation method, and program

[0001] The present disclosure relates to a translation device, a translation method, and a program.

[0002] There is known a 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.

[0003] Japanese Patent Application Laid-Open No. 2007-133622

[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. 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 can appropriately translate a portion of source code written in a programming language for a sequence control program into a high-level language, taking into consideration both 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 cannot meet this demand.

[0006] In view of the above circumstances, the object of the present disclosure is to provide a translation device or the like that can translate part of source code written in a programming language for a sequence control program into a high-level language, taking into consideration both speed and debuggability.

[0007] In order to achieve the above-mentioned object, the translation device according to the present disclosure comprises: a block extraction means for extracting blocks that are part of the source code of a sequence control program from the source code; a translation target determination means for determining which of the blocks extracted by the block extraction means should be translated into a high-level language; and a translation means for translating into the high-level language the blocks that have been determined by the translation target determination means to be translated into the high-level language.

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

[0009] 1. A block diagram showing a functional configuration of a translation device according to a first embodiment of the present disclosure. 2. A diagram showing an example of block extraction by a block extraction unit of a translation device according to a first embodiment of the present disclosure. 3. A diagram showing an example of block extraction by a block extraction unit of a translation device according to a first embodiment of the present disclosure. 4. A diagram showing an example of processing performance presented by a presentation unit of a translation device according to a first embodiment of the present disclosure. 5. A diagram showing an example of translated source code obtained by a translation unit of a translation device according to a first embodiment of the present disclosure. 6. A diagram showing an example of a hardware configuration of a translation device according to a first embodiment of the present disclosure. 7. A flowchart showing an example of a translation operation by a translation device according to a first embodiment of the present disclosure. 8. A block diagram showing a functional configuration of a translation device according to a second embodiment of the present disclosure.

[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 designated by the same reference numerals.

[0011] (Embodiment 1) A translation device 1 according to embodiment 1 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 portion of 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. For convenience, the original source code written in the programming language for the sequence control program will be referred to as "pre-translation source code" hereinafter. Furthermore, source code obtained by translating a portion of the pre-translation source code into a high-level language will be referred to as "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, we will briefly explain what is achieved by the translation apparatus 1. As will be described later, the translation apparatus 1 extracts multiple blocks from pre-translation source code based on control syntax included 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 speed when translated into a high-level language, and also has a size that takes debuggability into consideration.

[0013] For each extracted block, the translation device 1 estimates the processing performance when the 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 will not 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 the sequence control program and blocks written in a high-level language. This allows the translation device 1 to translate a portion of the pre-translation 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 the sequence control program is assumed to be ST language, and the high-level language is C. However, the following description can also be applied to programming languages ​​for the sequence control program 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 content 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 to the translation device 1 by the user. 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 the 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 the translated source code obtained by the translation unit 15 (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 control statements included in the pre-translation source code. The control statements are statements for controlling the execution order of each step of a program, such as IF statements, FOR statements, and function call statements. 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 a series of 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 series of statements that do not include control syntax as one block. The block extraction unit 11 extracts the FOR statement, the IF statement, and the function call statement as one block each. 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 Figure 3. The source code shown in Figure 3 includes a FOR statement that includes a FOR statement, and an IF statement that includes a FOR statement. In other words, the source code shown in Figure 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-level block and the outer control statement as a higher-level block. In this way, when 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 are of a size that can be expected to speed up translation into C language, and that also takes debuggability into consideration. The reason for speed is that when translating into C language, translating a certain number of blocks at a time is more advantageous than translating each individual statement. The reason for debuggability is that loop variables in FOR statements, variables used for conditional branching in IF statements, and arguments passed in function call statements are likely to be targets of monitoring during debugging. Furthermore, if blocks were extracted in more detail, the number of targets to be specified by the user (described later) would become enormous, placing a heavy burden on the user. Therefore, 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 for each statement in each language and analyzes the statements included in the block to estimate the processing performance. Alternatively, the performance estimation unit 12 estimates the processing performance for each block by running both a program based on the untranslated code fragment and a program based on the translated code fragment on 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 results shown in FIG. 4. In FIG. 4, execution time is shown as 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 will not be translated into C language based on user 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, the desired degree of speedup, and the desired method of debugging. The translation target determination unit 14 identifies blocks that will not 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. Furthermore, the translation unit 15 also modifies the source code, as necessary, 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 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 portions in FIG. 5 indicate portions of the ST language portion of the translated source code that have been changed from the pre-translation source code. In the translated source code shown in FIG. 5, the block corresponding to the FOR statement in the pre-translation source code shown in FIG. 2 has been translated into C language to become the C language portion shown in FIG. 5. The ST language portion has been modified to call the C_Func_Call function written in C language. The get_label_ptr function written in the C language portion is a function for referencing a variable in the ST language portion that corresponds to the variable name specified by an argument. This function allows variables used in the ST language portion to be referenced in the C language portion as well.

[0029] Next, an example of the hardware configuration of the translation device 1 will be described with reference to Fig. 6. The translation device 1 shown in Fig. 6 is realized by, for example, a personal computer on which an engineering tool program is installed.

[0030] Translation device 1 includes a processor 1001 , a memory 1002 , an interface 1003 , and a secondary storage device 1004 , which are connected to one another 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 realizing each function of the translation device 1.

[0032] The memory 1002 is a main storage device configured, for example, by a RAM (Random Access Memory). The memory 1002 stores the engineering tool program 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 engineering tool program.

[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 the program of the 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, the user operates the input device 3 to translate the pre-translation source code.

[0036] The block extractor 11 of the translation apparatus 1 extracts blocks from the pre-translation source code stored in the storage unit 10 based on control statements included 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] The presenting unit 13 of the translation apparatus 1 presents the processing performance before and after translation 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, as translation targets, the blocks extracted in step S101 other than the blocks identified in step S104 as blocks not to be translated (step S105).

[0041] The translation unit 15 of the translation apparatus 1 translates the block determined as the translation target in step S105 into C language, and stores the translated source code in the storage unit 10 (step S106).

[0042] The translation device 1 according to the first embodiment has been described above. The translation device 1 extracts multiple blocks from pre-translation source code written in a programming language for a sequence control program based on control syntax included in the pre-translation source code. The extracted blocks are of a size that can be expected to increase speed when translated into a high-level language and that takes debuggability into consideration. The translation device 1 determines blocks to be translated from the extracted multiple blocks and translates the blocks to be translated into the high-level language. The translation device 1 estimates the processing performance of each block before and after translation and presents the results to the user. The user can refer to the presented results and specify which blocks to exclude from the translation target, taking into consideration both speed and debuggability. Thus, the translation device 1 can translate a portion of 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 embodiment 2 will be described with reference to Fig. 8. The translation device 1 according to embodiment 2 differs from embodiment 1 in that it further includes a setting unit 16 and a set identification unit 17. It also differs from embodiment 1 in that the presenting unit 13 has additional functions.

[0044] In the second embodiment, the user can set the target performance of the sequence control program. The translation device 1 identifies and presents a set of blocks that meet the target performance and minimize the 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 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 case of embodiment 1, the presentation unit 13 presents to the user a set of blocks that meets the target setting and 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 will not be translated, referring to the processing performance of each block as in embodiment 1 and the newly presented set of blocks.

[0048] In the second embodiment, the translation target determination unit 14 may automatically determine, as the translation target, a set of blocks identified by the set identification unit 17 that satisfies the target setting and minimizes the total number of steps of 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 satisfies the desired target setting and has the greatest possible improvement in debuggability.

[0049] (Third Embodiment) A translation device 1 according to a 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. The function of the translation target determination unit 14 also 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 observation targets in the pre-translation source code based on user input operations. The user can specify variables in the source code, specific statements in the source code, etc. as observation targets. For example, the values ​​of variables specified as observation targets are constantly displayed during debugging. Furthermore, 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, and so on. 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 allows other blocks to be automatically translated into a high-level language. This ensures the debuggability required by the user, while automatically speeding up the translation without placing the burden of block specification on the user.

[0052] (Other Modifications) In the example of translation shown in FIG. 5, the variables used in the ST language section are referenced by the get_label_ptr function in the C language section. Meanwhile, variables used within a single block in the pre-translation source code may be converted into local C variables. For example, in the example of pre-translation source code shown in FIG. 2, if variable Z is used only within the FOR statement, variable Z can be converted into a local C variable. This can further speed up the execution of that block. However, if variable Z is specified as an observation target, as in the third embodiment, it should be referenced by the get_label_ptr function without being converted into a local variable.

[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 can be 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 external to 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 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), FPGA (Field Programmable Gate Array), etc. In the hardware configuration shown in FIG. 6, some of the functions of translation device 1 may be realized by a dedicated circuit connected to interface 1003, for example.

[0057] The program used in translation device 1 can be stored and distributed on a computer-readable recording medium such as a CD-ROM (Compact Disc Read Only Memory), a DVD (Digital Versatile Disc), a USB flash drive, a memory card, or a HDD. By installing such a program on a specific or general-purpose computer, the computer can function as 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 program may be downloaded from that server.

[0059] The present disclosure allows various embodiments and modifications without departing from the broad spirit and scope of the present disclosure. Furthermore, the above-described embodiments are intended to explain the present disclosure and do not limit the scope of the present disclosure. In other words, the scope of the present disclosure is defined by the claims, not the embodiments. Various modifications made within the scope of the claims and the meaning of equivalent disclosures are considered to be within the scope of the present disclosure.

[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 translation device comprising: a block extraction means for extracting blocks that are part of source code from the source code of a sequence control program; a translation target determination means for determining which of the blocks extracted by the block extraction means should be translated into a high-level language; and a translation means for translating into the high-level language the blocks determined by the translation target determination means to be translated into the high-level language.

2. The translation device according to claim 1, wherein the blocks are of a size that can be expected to have a high-speed effect when translated into the high-level language and that takes debuggability into consideration.

3. The translation device according to claim 1 or 2, wherein the block extraction means extracts blocks based on control statements contained in the source code.

4. A translation device as described in any one of claims 1 to 3, further comprising: a performance estimation means for estimating, for each block extracted by the block extraction means, 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; and a presentation means for presenting to a user, for each block, 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, estimated by the performance estimation means.

5. A translation device according to any one of claims 1 to 3, wherein the translation target determination means further identifies blocks that will not be translated into the high-level language based on user input, and determines blocks other than the identified blocks as blocks to be translated into the high-level language.

6. A translation device as claimed in any one of claims 1 to 3, comprising: a setting means for setting a target performance based on user input; a set identification means for identifying a set of blocks that meets the target performance and minimizes the total number of steps to be translated when translated into the high-level language; and a presentation means for presenting the sets identified by the set identification means to the user.

7. A translation device according to any one of claims 1 to 3, further comprising a setting means for setting an observation target in the source code based on a user's input, wherein the translation target determination means determines a block that does not include the observation target as a block to be translated into the high-level language.

8. A translation device according to any one of claims 1 to 7, wherein 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.

9. The translation device according to claim 4, wherein the performance estimation means estimates processing performance based on a trained model.

10. A translation method comprising: extracting blocks that are part of source code from the source code of a sequence control program; determining which of the extracted blocks should be translated into a high-level language; and translating the blocks that have been determined to be translated into the high-level language into the high-level language.

11. A program that causes a computer to function as: a block extraction means that extracts blocks that are part of 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 should be translated into a high-level language; and a translation means that translates into the high-level language the blocks that have been determined by the translation target determination means to be translated into the high-level language.

Citation Information

Patent Citations

  • Instruction simulation method and instruction simulation system of processor

    JP1998177487A

  • Programmable controller and control program development supporting device

    JP2002099312A

  • Tool for converting PLC program

    JP2010176377A

  • Embedded apparatus software generation support device, method and program

    JP2013140513A