[go: up one dir, main page]

CN116679939A - Method, device and medium for converting PLC instruction into target language - Google Patents

Method, device and medium for converting PLC instruction into target language Download PDF

Info

Publication number
CN116679939A
CN116679939A CN202310698998.6A CN202310698998A CN116679939A CN 116679939 A CN116679939 A CN 116679939A CN 202310698998 A CN202310698998 A CN 202310698998A CN 116679939 A CN116679939 A CN 116679939A
Authority
CN
China
Prior art keywords
instruction
plc
target language
converting
instructions
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202310698998.6A
Other languages
Chinese (zh)
Inventor
苏旭
欧志良
尚波
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shenzhen Invt Electric Co Ltd
Original Assignee
Shenzhen Invt Electric Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Shenzhen Invt Electric Co Ltd filed Critical Shenzhen Invt Electric Co Ltd
Priority to CN202310698998.6A priority Critical patent/CN116679939A/en
Publication of CN116679939A publication Critical patent/CN116679939A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/37Compiler construction; Parser generation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/30Arrangements for executing machine instructions, e.g. instruction decode
    • G06F9/3017Runtime instruction translation, e.g. macros
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02PCLIMATE CHANGE MITIGATION TECHNOLOGIES IN THE PRODUCTION OR PROCESSING OF GOODS
    • Y02P90/00Enabling technologies with a potential contribution to greenhouse gas [GHG] emissions mitigation
    • Y02P90/02Total factory control, e.g. smart factories, flexible manufacturing systems [FMS] or integrated manufacturing systems [IMS]

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Programmable Controllers (AREA)

Abstract

The application discloses a method, a device and a medium for converting a PLC instruction into a target language, which are applied to the technical field of PLC control. The method comprises the steps of firstly obtaining an original instruction table of a compiling type PLC, then scanning the original instruction table to obtain a plurality of instruction sequences of the PLC instruction, and then optimizing the PLC instruction in each instruction sequence by adopting a self-adaptive peeping hole. The self-adaptive peephole optimizes the instruction through some conversion rules capable of improving performance or integral analysis, and finally, the optimized PLC instruction is subjected to program matching to obtain a corresponding target language code. The method is used for converting the instruction of the compiling type PLC, and based on the compiler self-adaptive peeping hole optimization theory, an instruction optimization scheme is provided, so that the conversion from the PLC instruction to the target language can be effectively realized, meanwhile, in the conversion process, the instruction is optimized by adopting the self-adaptive peeping hole, and the target language code with higher execution efficiency and low redundancy is generated.

Description

Method, device and medium for converting PLC instruction into target language
Technical Field
The application relates to the technical field of PLC control, in particular to a method, a device and a medium for converting a PLC instruction into a target language.
Background
The execution mode of the programmable logic controller (Programmable Logic Controller, PLC) is both a compiling type and an interpretation type. The interpretation type execution mode has the advantages of small code length, convenience in breakpoint setting during debugging, low efficiency and the like. The compiling execution mode does not explain the re-execution process, and has the advantages of high execution efficiency and good real-time performance. One solution in the industry for a compiled PLC is to translate the original instruction table of the PLC into target language code, which uses the programming method of a ladder diagram to first convert the ladder diagram into the original instruction table and then convert the instruction table into target language code. Different compilation methods produce different results.
However, when converting compiled PLC instructions into a target language, the final target language code may contain some significant inefficiencies.
It can be seen that how to generate high-efficiency, low-redundancy object language codes is a problem to be solved by those skilled in the art.
Disclosure of Invention
The application aims to provide a method, a device and a medium for converting a PLC instruction into a target language, so as to generate high-efficiency and low-redundancy target language codes.
In order to solve the technical problems, the application provides a method for converting a PLC instruction into a target language, which comprises the following steps:
acquiring an original instruction table of a compiling type PLC;
scanning the original instruction table to obtain a plurality of instruction sequences of the PLC instructions;
optimizing the PLC instructions in each instruction sequence by adopting a self-adaptive peephole;
and performing program matching on the optimized PLC instruction to obtain a corresponding target language code.
Preferably, the optimizing the PLC instructions in each instruction sequence with the adaptive peephole includes:
the adaptive peephole is adopted to respectively carry out the following operations on the PLC instructions in each instruction sequence: forward substitution, algebraic reduction, evaluating constant value expressions, and deleting any one or more of unwanted effects.
Preferably, the scanning the original instruction table to obtain a plurality of instruction sequences of PLC instructions includes:
and scanning the original instruction table to obtain a plurality of instruction sequences of the PLC instructions taking energy flow segments as units.
Preferably, the optimizing the PLC instructions in each instruction sequence with the adaptive peephole includes:
moving the starting end of the self-adaptive peeping hole to the starting position of one energy flow section, and searching the instruction sequences one by one to optimize the PLC instructions in the instruction sequences;
after the PLC instruction optimization of one energy flow segment is completed, the optimization of the next energy flow segment is entered.
Preferably, the scanning the original instruction table to obtain a plurality of instruction sequences of PLC instructions includes:
scanning an operation instruction in the original instruction table, and expanding the operation instruction into a bottom instruction.
Preferably, the obtaining the original instruction table of the compiled PLC includes:
acquiring a ladder diagram of the compiling type PLC;
converting the ladder diagram into the original instruction table.
Preferably, after the program matching is performed on the optimized PLC instruction to obtain a corresponding target language code, the method further includes:
and compiling the target language code by adopting a target language compiler to obtain an executable code.
In order to solve the technical problem, the application also provides a device for converting the PLC instruction into the target language, which comprises:
the acquisition module is used for acquiring an original instruction table of the compiling type PLC;
the scanning module is used for scanning the original instruction table to obtain a plurality of instruction sequences of the PLC instructions;
the optimizing module is used for optimizing the PLC instructions in each instruction sequence by adopting the self-adaptive peepholes;
and the matching module is used for carrying out program matching on the optimized PLC instruction to obtain a corresponding target language code.
Preferably, the device for converting the PLC instruction into the target language further includes: and the compiling module is used for compiling the target language code by adopting a target language compiler after the optimized PLC instruction is subjected to program matching to obtain the corresponding target language code.
In order to solve the technical problem, the application also provides a device for converting the PLC instruction into the target language, which comprises: a memory for storing a computer program;
and the processor is used for realizing the step of the method for converting the PLC instruction into the target language when executing the computer program.
In order to solve the above technical problem, the present application further provides a computer readable storage medium, where a computer program is stored, where the computer program when executed by a processor implements the steps of the method for converting the PLC instruction into the target language.
The method for converting the PLC instruction into the target language is applied to a compiled PLC scene, an original instruction table of the compiled PLC is obtained first, then the original instruction table is scanned to obtain a plurality of instruction sequences of the PLC instruction, namely, the content of the original instruction table is extracted to obtain an instruction sequence capable of carrying out subsequent operation. Then, optimizing PLC instructions in each instruction sequence by adopting the self-adaptive peepholes respectively; the adaptive peephole can be considered as a sliding window of variable size, and the compiler typically only analyzes instructions within this window when performing peephole optimization. The self-adaptive peeping hole can be combined with the characteristics of the PLC instruction, the instruction is optimized through some conversion rules capable of improving performance or integral analysis, and finally, the program matching is carried out on the optimized PLC instruction to obtain a corresponding target language code. The method is used for converting the instruction of the compiling type PLC, and based on the compiler self-adaptive peeping hole optimization theory, an instruction optimization scheme is provided, so that the conversion from the PLC instruction to the target language can be effectively realized, meanwhile, in the conversion process, the instruction is optimized by adopting the self-adaptive peeping hole, and the target language code with higher execution efficiency and low redundancy is generated.
The application also provides a device for converting the PLC instruction into the target language and a computer readable storage medium, which correspond to the method, and have the same beneficial effects as the method.
Drawings
For a clearer description of embodiments of the present application, the drawings that are required to be used in the embodiments will be briefly described, it being apparent that the drawings in the following description are only some embodiments of the present application, and other drawings may be obtained according to the drawings without inventive effort for those skilled in the art.
FIG. 1 is a flowchart of a method for converting a PLC instruction into a target language according to an embodiment of the present application;
FIG. 2 is a flow chart of instruction conversion execution of a compiling PLC according to an embodiment of the present application;
FIG. 3 is a ladder diagram according to an embodiment of the present application;
FIG. 4 is a diagram of instruction representation intent corresponding to a ladder diagram according to an embodiment of the present application;
FIG. 5 is a block diagram of a device for converting a PLC instruction into a target language according to an embodiment of the present application;
fig. 6 is a block diagram of an apparatus for converting PLC instructions into a target language according to another embodiment of the present application.
Detailed Description
The following description of the embodiments of the present application will be made clearly and completely with reference to the accompanying drawings, in which it is apparent that the embodiments described are only some embodiments of the present application, but not all embodiments. Based on the embodiments of the present application, all other embodiments obtained by a person of ordinary skill in the art without making any inventive effort are within the scope of the present application.
The core of the application is to provide a method, a device and a medium for converting a PLC instruction into a target language so as to generate a target language code with high efficiency and low redundancy.
In order to better understand the aspects of the present application, the present application will be described in further detail with reference to the accompanying drawings and detailed description.
FIG. 1 is a flowchart of a method for converting a PLC instruction into a target language according to an embodiment of the present application; as shown in fig. 1, the method comprises the steps of:
s10: and acquiring an original instruction table of the compiling type PLC.
The method for obtaining the original instruction table is not limited, and the original instruction table can be directly obtained, and the original instruction table can be obtained through conversion of a ladder diagram. The ladder diagram based on ladder logic is a widely used PLC programming language, a directed diagram flowing from left to right is adopted to clearly express the logic relationship among graphic units, each graphic unit represents a coil, a contact or a functional block in a switch control system, and the like, and the large ladder diagram can be subdivided into a plurality of sub-networks.
The ladder diagram has two remarkable characteristics, namely, each graphic unit in the ladder diagram is independent and does not affect each other, and a definite logic precedence relationship exists between adjacent graphic units in the ladder diagram, so that a directed acyclic graph can be formed.
Wherein, the partial ladder diagram unit and the instruction correspondence table are as follows:
TABLE 1 partial ladder diagram Unit and instruction correspondence Table
Numbering device Instruction name Function of
1 LD Operation start
2 LDI The inverse operation starts
3 AND Are connected in series
4 ANI Series connection (reverse)
5 OUT Coil output
6 OR Connected in parallel
7 ORI Parallel connection (reverse)
8 ANB Blocks connected in series
9 ORB Parallel connection of blocks
10 MPS Push stack
11 MRD Reading stack
12 MPP Pop-up
13 END Program end
When designing the storage structure of the ladder diagram node, considering that the left and right connection numbers of the primitive nodes are variable, the embodiment designs a single node as a binary tree storage structure basic unit, and the left and right connection is realized by a List chain table. According to the relation among the primitives of the ladder diagram and the instruction corresponding to the primitives, converting the user ladder diagram into an instruction table and an operand, and storing the instruction table and the operand in an instruction chain table CommendNode.
S11: and scanning the original instruction table to obtain a plurality of instruction sequences of the PLC instructions.
S12: and optimizing the PLC instructions in each instruction sequence by adopting the self-adaptive peepholes.
S13: and performing program matching on the optimized PLC instruction to obtain a corresponding target language code.
The processing procedure of the adaptive peephole optimization can be specifically divided into three tasks, namely expansion, simplification and matching, which correspond to the steps S11, S12 and S13 respectively, and the specific type of the target language is not limited and may be C language.
The expansion is that the original instruction table is scanned to obtain a plurality of instruction sequences of the PLC instructions, namely the process of converting operation instructions of the original instruction table into a series of Lower-level instruction (LLIR) operations one by one, so that the subsequent optimization is facilitated. If the energy flow segments are taken as units, the energy flow segments are expanded to form a plurality of energy flow segments, and one energy flow segment comprises a plurality of instruction sequences. The unwind program rewrites the input instructions (Instruction Reference, IR) converting the operation instructions one by one into a series of LLIR operations. The structure of the development program is simple, the operations can be extended one by one without considering the context, and the processing procedure can use a template for each IR operation and replace the register name, constant and label in the template with the proper actual value when overwriting.
The simplification step corresponds to the actual optimization of the adaptive peephole, which would make use of adaptive peephole optimization to process LLIR in one pass, analyze individual operations in LLIR through a small adaptive sliding window, and attempt to improve these operations in a systematic way. The basic mechanisms for simplifying processing are forward substitution (substituting operands of the following instruction with the contents of the preceding instruction), algebraic reduction (e.g., x+0= > x), evaluation of constant value expressions (e.g., 2+17= > 19), and deletion of unwanted effects (e.g., creating unused condition codes). Thus, simplifying the procedure will result in limited local optimization of the operations in the window over LLIR.
After the optimization is completed, matching between the PLC instruction and the target language is performed, namely, the PLC instruction is converted into the target language code. The matching program compares the simplified LLIR against a pattern library to find a pattern that captures all effects in the LLIR in the best way. The final code sequence may produce effects outside the LLIR code sequence, e.g. a new useless condition code value may be created, but those effects that are required to ensure correctness must be preserved. This process cannot remove the active value, whether it is stored in memory, in a register, or at some implicitly set location (e.g., a condition code).
The following presents a procedure for simplifying LLIR by an adaptive peephole optimizer.
Step 1: and moving the starting end of the self-adaptive sliding window to the starting position of one energy flow section, and searching the next instructions one by one.
Step 2: judging whether the node instruction is an output node or not, if not, adding a node to the self-adaptive sliding window, wherein the starting position is fixed, and the tail end moves backwards. The upper operation is repeated until the corresponding output node is found, at which point the adaptive sliding window will record the instruction set and operands of a segment.
Step 3: and analyzing the instructions in the window, simplifying and optimizing, and outputting an optimized segment instruction set and operands.
Step 4: program matching is carried out on the optimized segment instruction set and the operands, and the optimized segment instruction set and the operands are converted into corresponding target language codes.
Step 5: and moving the self-adaptive sliding window to the starting position of the next energy flow section, and repeating the operation until the instruction is ended.
The conversion from the PLC instruction to the target language is completed through the steps.
FIG. 2 is a flow chart of instruction conversion execution of a compiling PLC according to an embodiment of the present application; as shown in fig. 2, the method comprises the following steps:
s20: the user ladder is converted to an IL instruction list (IL is an instruction list language of the PLC).
S21: the next instruction is looked up one by one starting from the instruction segment start position.
S22: judging whether the current instruction is an ending symbol or not; if yes, the process proceeds to step S25, and if no, the process proceeds to step S23.
S23: judging whether the current instruction is a segment ending instruction or not; if yes, go to step S24 and step S27, and if no, go to step S28.
S24: optimizing by adopting a peephole optimizer.
S25: and converting into target language codes.
S26: converted into executable code.
S27: the next instruction is entered.
S28: the peep hole window is added with 1, and the next instruction is identified.
The above is a complete flow of converting the PLC instruction ladder diagram into the target language, and it should be noted that the above solution is only a partial example of the present application and is not limited to other solutions.
FIG. 3 is a ladder diagram according to an embodiment of the present application; taking the conversion of the ladder instruction into the language C as an example, the implementation process of the present example will be described in detail. FIG. 4 is a diagram of instruction representation intent corresponding to a ladder diagram according to an embodiment of the present application; as shown in fig. 3 and 4:
[1] the adaptive peep hole scanning window is moved to the instruction segment start position LD M0.
[2] Judging the command as a normally open contact command, adding 1 to the peep hole window, and scanning the next command.
[3] The instruction content loaded to the tail end of the window is OR M1, which is a parallel normally open contact instruction, the peephole window is added with 1, and the next instruction is continuously scanned.
[4] The instruction LDI M2 is loaded to the tail end of the window and is a serial normally closed contact instruction, 1 is added to the peeping window, and the next instruction is continuously scanned.
[5] ORI M2 instruction is loaded to the end of the window, is a parallel normally closed contact instruction, adds 1 to the peephole window, and continues to scan the next instruction.
[6] The ANB instruction is loaded to the tail end of the window and is a block series connection instruction, namely LD M0 and OR M1 in the window are instruction blocks, LDI M2 and ORI M3 are instruction blocks, the two instruction blocks are in a series connection relation, the peeping hole window is added with 1, and the next instruction is continuously scanned.
[7] The MOV D0D 1 instruction is loaded to the end of the window and is a word data transmission instruction, the value of an operand D0 in the window is assigned to D1, meanwhile, the MOV instruction indicates that the segment is finished, and the whole instruction segment content of the peeping window is the instruction added in the steps after one scanning pass.
[8] Performing lexical and grammatical analysis on instructions and operands in the peeping hole window, wherein the ANB blocks are connected with the instructions in series, namely LD M0 and OR M1 in the window are instruction blocks, LDI M2 and ORI M3 are instruction blocks, the two instruction blocks are in series connection, and when the conditions of the two instruction blocks are true, MOV assignment operation is executed, and D0 is assigned to D1;
[9] the conversion from the instruction to the C language is carried out by [8] step peeping window instruction section lexical and grammatical analysis, and the content of the C language converted by the instruction is as follows:
the method for converting the PLC instruction into the target language is applied to a compiled PLC scene, an original instruction table of the compiled PLC is obtained first, then the original instruction table is scanned to obtain a plurality of instruction sequences of the PLC instruction, namely, the content of the original instruction table is extracted to obtain an instruction sequence capable of carrying out subsequent operation. Then, optimizing PLC instructions in each instruction sequence by adopting the self-adaptive peepholes respectively; the adaptive peephole can be considered as a sliding window of variable size, and the compiler typically only analyzes instructions within this window when performing peephole optimization. The self-adaptive peeping hole can be combined with the characteristics of the PLC instruction, the instruction is optimized through some conversion rules capable of improving performance or integral analysis, and finally, the program matching is carried out on the optimized PLC instruction to obtain a corresponding target language code. The method is used for converting the instruction of the compiling type PLC, and based on the compiler self-adaptive peeping hole optimization theory, an instruction optimization scheme is provided, so that the conversion from the PLC instruction to the target language can be effectively realized, meanwhile, in the conversion process, the instruction is optimized by adopting the self-adaptive peeping hole, and the target language code with higher execution efficiency and low redundancy is generated.
In practical applications, each instruction in the instruction table corresponds to a logic process, taking the target language as the C language as an example, for example: the LD instruction indicates that the device is judged to be in, if the device is 1, the device enters the following energy flow, if the device is 0, the device jumps to the next energy flow block, and the device corresponds to an if statement of the C language. The MOV instruction indicates that the first element value to which it belongs is assigned to the second element, corresponding to the statement "assignment of C" = ". The AND instruction indicates that the condition of judging two adjacent primitives or primitive blocks is true or false, if both are true, entering the following energy flow, if not all true, jumping to the next energy flow block, AND corresponding to the if judging statement AND AND instruction of the C language. Through the analysis, each instruction in the instruction table can be converted into a corresponding C language statement, such as condition judgment, assignment, circulation, function call and the like. The values that the statement needs to process are both element operands in the primitive instruction.
Through the above analysis, it has been possible to translate a single PLC instruction table into a target language. If only a single instruction pair is converted, its generation target language will not be able to satisfy the execution logic of the PLC instruction. Generally, the execution sequence of the ladder program starts with the input energy stream, and determines the logic output according to the result through a series of logic conditions. Logic is typically broken down into small, easily understood pieces, often referred to as "steps" or "segments," which are executed one segment at a time, left to right, top to bottom, and re-executed top to bottom once the CPU executes to the end of the program. Therefore, in the process of converting the PLC instruction into the target language, a complete energy flow section can be taken as a unit, and the complete energy flow section at least comprises one input, one output and a plurality of logic conditions in the middle. The number of instruction units contained in different energy flow sections is different, so that a peeping scanning method can be adopted, and one execution section is taken at a time to convert a PLC instruction into a target language. The core idea of adaptive peephole optimization is to use an adaptive sliding window (or "adaptive peephole") to move over the commands, analyze the short sequences of adjacent commands within the window, and find specific sequences that can be improved. For example, if it is recognized that one instruction sequence is equivalent to another more efficient instruction sequence (that sequence being the particular sequence), the original sequence may be replaced with this equivalent sequence, and the presence of the original sequence may be deleted if it is not significant.
In the above embodiment, it is mentioned that after the original instruction table is expanded to obtain the instruction sequences, the adaptive peeping hole needs to be used to optimize the PLC instructions in each instruction sequence, and when the adaptive peeping hole is used to optimize the PLC instructions in each instruction sequence, the following operations may be specifically adopted: forward substitution, algebraic reduction, evaluating constant value expressions, and deleting any one or more of unwanted effects. Peeping optimization (Peephool Optimization) is a local optimization mode, and a compiler only performs instruction conversion in one basic block or a plurality of basic blocks according to generated codes and combining the characteristics of instructions of a central processing unit (Central Processing Unit, CPU) through conversion rules or overall analysis which are considered to possibly bring about performance improvement, so that the performance of the codes is improved. Although these transcodes are local and small, they may result in a significant performance improvement. The adaptive peephole can be considered as a sliding window of variable size, and the compiler typically only analyzes instructions within this window when performing peephole optimization. After each transition, some optimization opportunities between adjacent windows may also be exposed, so peeping optimization may be invoked multiple times, improving performance as much as possible.
As mentioned above, a complete energy flow segment includes at least one input, one output, and a number of logic conditions in between. The "power flow" is an imaginary concept, assuming that the left and right buses are the positive and negative poles of a dc power supply, the left bus is connected to the positive pole, the right bus is connected to the negative pole, and an imaginary "conceptual current" flows from the left bus to the right bus along the ladder diagram to form a loop, where the "conceptual current" is the "power flow". The energy flow can only flow from left to right, and the energy flow section refers to a loop formed by the fact that 'concept current' flows from a left bus to a right bus along a ladder diagram. The embodiment of the application converts by taking the energy flow section as a unit, namely scans the original instruction table to obtain a plurality of instruction sequences of the PLC instructions by taking the energy flow section as a unit, and then optimizes each energy flow section in turn. Specifically, the starting end of the self-adaptive peeping hole can be moved to the starting position of one energy flow section, the instruction sequences are searched one by one to optimize the PLC instructions in the instruction sequences, and after the PLC instructions of one energy flow section are optimized, the next energy flow section is optimized. Specific optimization steps have been described in the above examples, and are not described here again.
In the above embodiment, after the target language code is obtained, the program cannot be directly executed, so after the optimized PLC instruction is subjected to program matching to obtain the corresponding target language code, the target language code needs to be compiled by a target language compiler to obtain the executable code, and if the target language is the C language, the compiler is specifically the C language compiler.
In the above embodiments, the method for converting the PLC instruction into the target language is described in detail, and the present application also provides a corresponding embodiment of the device for converting the PLC instruction into the target language. It should be noted that the present application describes an embodiment of the device portion from two angles, one based on the angle of the functional module and the other based on the angle of the hardware.
Based on the angle of the functional module, the embodiment provides a device for converting a PLC instruction into a target language, and fig. 5 is a structural diagram of the device for converting a PLC instruction into a target language, as shown in fig. 5, where the device includes:
the acquisition module 10 is used for acquiring an original instruction table of the compiling type PLC;
the scanning module 11 is used for scanning the original instruction table to obtain a plurality of instruction sequences of the PLC instructions;
the optimizing module 12 is used for optimizing the PLC instructions in each instruction sequence by adopting the self-adaptive peepholes respectively;
and the matching module 13 is used for performing program matching on the optimized PLC instruction to obtain a corresponding target language code.
Since the embodiments of the apparatus portion and the embodiments of the method portion correspond to each other, the embodiments of the apparatus portion are referred to the description of the embodiments of the method portion, and are not repeated herein.
As a preferred embodiment, the apparatus for converting PLC instructions into a target language further includes: and the compiling module is used for compiling the target language code by adopting a target language compiler to obtain an executable code after the optimized PLC instruction is subjected to program matching to obtain the corresponding target language code.
The device for converting the PLC instruction into the target language provided in the embodiment corresponds to the above method, and therefore has the same beneficial effects as the above method.
Based on the hardware perspective, the present embodiment provides another device for converting a PLC instruction into a target language, and fig. 6 is a structural diagram of the device for converting a PLC instruction into a target language according to another embodiment of the present application, as shown in fig. 6, the device for converting a PLC instruction into a target language includes: a memory 20 for storing a computer program;
a processor 21 for implementing the steps of the method of converting PLC instructions into a target language as mentioned in the above embodiments when executing a computer program.
Processor 21 may include one or more processing cores, such as a 4-core processor, an 8-core processor, etc. The processor 21 may be implemented in hardware in at least one of a digital signal processor (Digital Signal Processor, DSP), a Field programmable gate array (Field-Programmable Gate Array, FPGA), a programmable logic array (Programmable Logic Array, PLA). The processor 21 may also include a main processor, which is a processor for processing data in an awake state, also called CPU, and a coprocessor; a coprocessor is a low-power processor for processing data in a standby state. In some embodiments, the processor 21 may be integrated with an image processor (Graphics Processing Unit, GPU) for taking care of rendering and rendering of the content that the display screen is required to display. In some embodiments, the processor 21 may also include an artificial intelligence (Artificial Intelligence, AI) processor for processing computing operations related to machine learning.
Memory 20 may include one or more computer-readable storage media, which may be non-transitory. Memory 20 may also include high-speed random access memory, as well as non-volatile memory, such as one or more magnetic disk storage devices, flash memory storage devices. In this embodiment, the memory 20 is at least used for storing a computer program 201, where the computer program, when loaded and executed by the processor 21, can implement the relevant steps of the method for converting PLC instructions into a target language disclosed in any of the foregoing embodiments. In addition, the resources stored in the memory 20 may further include an operating system 202, data 203, and the like, where the storage manner may be transient storage or permanent storage. The operating system 202 may include Windows, unix, linux, among others. The data 203 may include, but is not limited to, data related to the method by which the PLC instruction is converted into the target language, and the like.
In some embodiments, the device for converting PLC instruction into target language may further include a display 22, an input/output interface 23, a communication interface 24, a power supply 25, and a communication bus 26.
Those skilled in the art will appreciate that the structures shown in the figures do not constitute limitations on the means by which the PLC instructions are converted to the target language, and may include more or fewer components than shown.
The device for converting the PLC instruction into the target language provided by the embodiment of the application comprises a memory and a processor, wherein the processor can realize the following method when executing a program stored in the memory: a method for converting PLC instruction into target language.
The device for converting the PLC instruction into the target language provided in the embodiment corresponds to the above method, and therefore has the same beneficial effects as the above method.
Finally, the application also provides a corresponding embodiment of the computer readable storage medium. The computer-readable storage medium has stored thereon a computer program which, when executed by a processor, performs the steps as described in the method embodiments above.
It will be appreciated that the methods of the above embodiments, if implemented in the form of software functional units and sold or used as stand-alone products, may be stored on a computer readable storage medium. Based on such understanding, the technical solution of the present application may be embodied essentially or in part or all of the technical solution contributing to the prior art, or may be embodied in the form of a software product stored in a storage medium, performing all or part of the steps of the method described in the various embodiments of the present application. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a random access Memory (Random Access Memory, RAM), a magnetic disk, or an optical disk, or other various media capable of storing program codes.
The computer readable storage medium provided in the present embodiment corresponds to the above method, and thus has the same advantageous effects as the above method.
The method, the device and the medium for converting the PLC instruction into the target language are described in detail. In the description, each embodiment is described in a progressive manner, and each embodiment is mainly described by the differences from other embodiments, so that the same similar parts among the embodiments are mutually referred. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant points refer to the description of the method section. It should be noted that it will be apparent to those skilled in the art that various modifications and adaptations of the application can be made without departing from the principles of the application and these modifications and adaptations are intended to be within the scope of the application as defined in the following claims.
It should also be noted that in this specification, relational terms such as first and second, and the like are used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Moreover, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element.

Claims (10)

1. A method for converting PLC instructions into a target language, comprising:
acquiring an original instruction table of a compiling type PLC;
scanning the original instruction table to obtain a plurality of instruction sequences of the PLC instructions;
optimizing the PLC instructions in each instruction sequence by adopting a self-adaptive peephole;
and performing program matching on the optimized PLC instruction to obtain a corresponding target language code.
2. The method of converting PLC instructions into a target language according to claim 1, wherein optimizing the PLC instructions in each of the instruction sequences using adaptive peepholes, respectively, comprises:
the adaptive peephole is adopted to respectively carry out the following operations on the PLC instructions in each instruction sequence: forward substitution, algebraic reduction, evaluating constant value expressions, and deleting any one or more of unwanted effects.
3. The method of converting PLC instructions into a target language according to claim 1, wherein scanning the original instruction table for a plurality of instruction sequences of PLC instructions comprises:
and scanning the original instruction table to obtain a plurality of instruction sequences of the PLC instructions taking energy flow segments as units.
4. The method of converting PLC instructions into a target language according to claim 3, wherein optimizing the PLC instructions in each of the instruction sequences using adaptive peepholes, respectively, comprises:
moving the starting end of the self-adaptive peeping hole to the starting position of one energy flow section, and searching the instruction sequences one by one to optimize the PLC instructions in the instruction sequences;
after the PLC instruction optimization of one energy flow segment is completed, the optimization of the next energy flow segment is entered.
5. The method of converting PLC instructions into a target language according to any one of claims 1 to 4, wherein scanning the original instruction table to obtain a plurality of instruction sequences of PLC instructions comprises:
scanning an operation instruction in the original instruction table, and expanding the operation instruction into a bottom instruction.
6. The method of converting PLC instructions into a target language according to claim 1, wherein the obtaining the original instruction table of the compiled PLC includes:
acquiring a ladder diagram of the compiling type PLC;
converting the ladder diagram into the original instruction table.
7. The method for converting a PLC instruction into a target language according to claim 1, wherein after the program matching is performed on the optimized PLC instruction to obtain a corresponding target language code, further comprising:
and compiling the target language code by adopting a target language compiler to obtain an executable code.
8. An apparatus for converting PLC instructions into a target language, comprising:
the acquisition module is used for acquiring an original instruction table of the compiling type PLC;
the scanning module is used for scanning the original instruction table to obtain a plurality of instruction sequences of the PLC instructions;
the optimizing module is used for optimizing the PLC instructions in each instruction sequence by adopting the self-adaptive peepholes;
and the matching module is used for carrying out program matching on the optimized PLC instruction to obtain a corresponding target language code.
9. An apparatus for converting a PLC instruction into a target language, comprising a memory for storing a computer program;
a processor for implementing the steps of the method of converting PLC instructions into a target language according to any one of claims 1 to 7 when executing the computer program.
10. A computer readable storage medium, wherein a computer program is stored on the computer readable storage medium, which when executed by a processor, implements the steps of the method of converting PLC instructions into a target language according to any one of claims 1 to 7.
CN202310698998.6A 2023-06-13 2023-06-13 Method, device and medium for converting PLC instruction into target language Pending CN116679939A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310698998.6A CN116679939A (en) 2023-06-13 2023-06-13 Method, device and medium for converting PLC instruction into target language

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310698998.6A CN116679939A (en) 2023-06-13 2023-06-13 Method, device and medium for converting PLC instruction into target language

Publications (1)

Publication Number Publication Date
CN116679939A true CN116679939A (en) 2023-09-01

Family

ID=87781898

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310698998.6A Pending CN116679939A (en) 2023-06-13 2023-06-13 Method, device and medium for converting PLC instruction into target language

Country Status (1)

Country Link
CN (1) CN116679939A (en)

Similar Documents

Publication Publication Date Title
KR101606622B1 (en) Utilizing special purpose elements to implement a fsm
JPH07234790A (en) Device and method for program conversion processing
Gómez-Rodríguez et al. A transition-based parser for 2-planar dependency structures
CN113722218B (en) Software defect prediction model construction method based on compiler intermediate representation
CN113283613B (en) Deep learning model generation method, optimization method, device, equipment and medium
CN104267654A (en) Method and system for converting ladder diagram program into instruction list program and compiling instruction list program
CN118034660B (en) Graph compiling method and device for large language model fusion operator and storage medium
Blindell Instruction selection
KR102610431B1 (en) Apparatus and method for generating summary of program source code based on ai analysis
CN112764738A (en) Code automatic generation method and system based on multi-view program characteristics
JP7344259B2 (en) Pattern transformation methods, apparatus, electronic devices, computer storage media and computer program products in deep learning frameworks
CN113157917B (en) OpenCL-based optimized classification model establishing and optimized classification method and system
Morton et al. Grammar filtering for syntax-guided synthesis
CN111507070A (en) Natural language generation method and device
CN114816517A (en) A Hierarchical Semantic Aware Code Representation Learning Method
Nymeyer et al. Code generation based on formal BURS theory and heuristic search
CN112527304B (en) Self-adaptive node fusion compiling optimization method based on heterogeneous platform
CN116679939A (en) Method, device and medium for converting PLC instruction into target language
JP2002527816A (en) Program optimization apparatus and method
CN107168298A (en) Ladder diagram dynamic analysis method
JPH07319682A (en) Software discovery system
EP0638862B1 (en) Method and system for processing language
CN115686923A (en) Method and system for automatically repairing software source code defects
CN113031952B (en) Method, device and storage medium for determining execution code of deep learning model
TWI801836B (en) Method for transforming and optimizing codes between different programing languages

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination