Compilation method and device of program organization unit, storage medium and electronic equipment
Through program parsing, legality checking and bit number information processing, the bit number description file and interface call code are generated, which solves the problem of inefficient bit number synchronization maintenance in POU program compilation, and realizes efficient bit number management and configuration process.
Patent Information
- Application Number
- CN202411459620.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-18
- Publication Date
- 2025-01-17
AI Technical Summary
The existing POU program compilation method requires manual synchronization of bit number information in the global variable table, resulting in low efficiency and complexity in program configuration.
Through program analysis, legality check, intermediate code conversion, bit number information identification processing, interface call code generation, bit number description files and executable files are generated, so that bit number management does not require global variable configuration.
It improves the convenience and efficiency of POU program configuration, reduces the complexity of bit number synchronous maintenance, and improves the accuracy of configuration.
Smart Images

Figure CN119322618A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of industrial automation control technology, and in particular to a compiling method and device for a program organization unit, a storage medium and an electronic device. Background Art
[0002] With the development of control technology, control systems have been widely used in various production scenarios to automate production processes. IEC 61131 is one of the main standards for control system programming. In the IEC 61131 standard, the Program Organization Unit (POU) is the basic module in the user program. The control program of the control system is usually composed of multiple POU programs, and each POU program is used to implement a specific control function.
[0003] In the control logic configuration of the control system, many data objects are called bit numbers, such as relevant data of sensors, valves, motors and other equipment, certain signal data or virtual memory data units, etc. The control logic of each POU program often involves interactive reference access to bit number objects, and the compilation of existing POU programs is implemented by static compilation, that is, the source code of the program is converted into corresponding machine instructions, that is, currently, the global variable table is usually configured based on the bit number objects involved in all POU programs. During the program compilation process, memory space is allocated for the bit number objects based on the global variable table, and the reading and writing of the bit number data in the POU program is converted into instructions for specified memory operations.
[0004] Based on the existing compilation method, the bit numbers involved in each POU program need to be globally configured, that is, the bit number configuration is independent of the control logic of each POU program. When the bit number or POU program changes, the global variable data and the content of the POU program need to be manually modified synchronously. When there are many bit number objects, the program configuration process will become very complicated, making the program configuration efficiency low. Summary of the invention
[0005] In view of this, an embodiment of the present invention provides a compilation method for a program organization unit to solve the problem that in the existing compilation method, manual synchronization maintenance of the bit number information in the program and the global variable table is required, the program configuration process is relatively cumbersome and inefficient.
[0006] The embodiment of the present invention also provides a compiling device for a program organization unit to ensure the actual implementation and application of the above method.
[0007] To achieve the above objectives, the embodiments of the present invention provide the following technical solutions:
[0008] A method for compiling a program organization unit, comprising:
[0009] When the target program organization unit needs to be compiled, the target program organization unit is parsed to obtain the original configuration program corresponding to the target program organization unit;
[0010] Performing a validity check on the original configuration program to obtain a validity check result;
[0011] If the validity check result indicates that the original configuration program passes the validity check, performing intermediate code conversion on the original configuration program to obtain an intermediate representation code corresponding to the original configuration program;
[0012] Performing a bit number information identification process on the intermediate representation code to obtain a bit number information set; the bit number information set includes at least one bit number description information;
[0013] Based on the bit number information set, a bit number description file is generated, so that the controller performs bit number management based on the bit number description file when running the program;
[0014] Determine a bit number operation code and a business logic code in the intermediate representation code; the bit number operation code includes at least one data read and write code corresponding to a bit number read and write operation;
[0015] For each of the bit number read and write operations, an operation code conversion is performed based on the data read and write code corresponding to the bit number read and write operation to obtain an interface call code corresponding to the bit number read and write operation, and the interface call code is used to call a preset bit number read and write interface to perform the bit number read and write operation;
[0016] Convert the business logic code into a readable code to obtain a readable logic code corresponding to the business logic code;
[0017] Generate a target code file corresponding to the intermediate representation code based on the readable logic code and the interface calling code corresponding to each of the bit number read and write operations;
[0018] Generate an executable file corresponding to the target code file;
[0019] The executable file and the bit number description file are used as the compilation result of the target program organization unit.
[0020] In the above method, optionally, performing program parsing on the target program organization unit to obtain the original configuration program corresponding to the target program organization unit includes:
[0021] Obtaining the source program of the target program organization unit;
[0022] According to the programming language type of the target program organization unit, determining a target program parsing module corresponding to the target program organization unit from a plurality of pre-configured program parsing modules;
[0023] The target program analysis module is called to analyze the source program to obtain a program analysis result, and the program analysis result is used as the original configuration program corresponding to the target program organization unit.
[0024] In the above method, optionally, performing a validity check on the original configuration program to obtain a validity check result includes:
[0025] Get multiple pre-set check conditions;
[0026] Determining whether the original configuration program meets each of the inspection conditions;
[0027] If the original configuration program meets each of the check conditions, a first preset conclusion is used as the legality check result; the first preset conclusion indicates that the original configuration program passes the legality check.
[0028] In the above method, optionally, the performing intermediate code conversion on the original configuration program to obtain the intermediate representation code corresponding to the original configuration program includes:
[0029] According to the programming language type of the target program organization unit, determining a target code conversion module corresponding to the target program organization unit from a plurality of pre-configured code conversion modules;
[0030] The target code conversion module is called to perform intermediate code conversion on the original configuration program to obtain a code conversion result, and the code conversion result is used as the intermediate representation code corresponding to the original configuration program.
[0031] In the above method, optionally, performing a bit number information identification process on the intermediate representation code to obtain a bit number information set includes:
[0032] Identifying each bit number object associated with the intermediate representation code;
[0033] Determine the basic description information corresponding to each of the bit number objects; the basic description information corresponding to each of the bit number objects includes the bit number name, unique coding identifier, data type and initial value of the bit number object;
[0034] Determine the extended description information corresponding to each of the bit number objects; the extended description information corresponding to each of the bit number objects includes various configuration data for managing and accessing the bit number object;
[0035] For each of the bit number objects, the basic description information and the extended description information corresponding to the bit number object are used as the bit number description information corresponding to the bit number object;
[0036] The bit number information set is composed of the bit number description information corresponding to each bit number object.
[0037] The above method may optionally include performing operation code conversion based on the data read / write code corresponding to the bit number read / write operation to obtain the interface call code corresponding to the bit number read / write operation, including:
[0038] Determine the operation information corresponding to the bit number read / write operation according to the data read / write code corresponding to the bit number read / write operation; the operation information includes the target bit number identifier, data operation type and reference method corresponding to the bit number read / write operation;
[0039] Generate interface parameters according to the operation information;
[0040] Based on the interface parameters, a calling code of the bit number read / write interface is determined, and the calling code of the bit number read / write interface is used as the interface calling code corresponding to the bit number read / write operation.
[0041] In the above method, optionally, generating an executable file corresponding to the target code file includes:
[0042] Determining an operating environment corresponding to the controller;
[0043] Determine the compile and link tool corresponding to the operating environment;
[0044] The compiling and linking tool is used to link the target code file to obtain a program file of an executable program, and the program file of the executable program is used as the executable file corresponding to the target code file.
[0045] A compiling device for a program organization unit, comprising:
[0046] A program parsing unit, used for parsing the target program organization unit when it is necessary to compile the target program organization unit, and obtaining an original configuration program corresponding to the target program organization unit;
[0047] A program checking unit, used for performing a legality check on the original configuration program to obtain a legality check result;
[0048] A first conversion unit is configured to perform intermediate code conversion on the original configuration program to obtain an intermediate representation code corresponding to the original configuration program if the validity check result indicates that the original configuration program passes the validity check;
[0049] A bit number identification unit is used to perform bit number information identification processing on the intermediate representation code to obtain a bit number information set; the bit number information set includes at least one bit number description information;
[0050] A first generating unit, configured to generate a bit number description file based on the bit number information set, so that the controller performs bit number management based on the bit number description file when running a program;
[0051] A code identification unit, used to determine the bit number operation code and the business logic code in the intermediate representation code; the bit number operation code includes at least one data read and write code corresponding to the bit number read and write operation;
[0052] A second conversion unit is used to perform operation code conversion for each of the bit number read and write operations based on the data read and write code corresponding to the bit number read and write operation, and obtain an interface call code corresponding to the bit number read and write operation, wherein the interface call code is used to call a preset bit number read and write interface to perform the bit number read and write operation;
[0053] A third conversion unit, configured to convert the business logic code into a readable code to obtain a readable logic code corresponding to the business logic code;
[0054] A second generating unit, configured to generate a target code file corresponding to the intermediate representation code based on the readable logic code and the interface calling code corresponding to each of the bit number read and write operations;
[0055] A third generating unit, used to generate an executable file corresponding to the target code file;
[0056] The result output unit is used to use the executable file and the bit number description file as the compilation result of the target program organization unit.
[0057] A storage medium includes stored instructions, wherein when the instructions are executed, the device where the storage medium is located is controlled to execute the compilation method of the program organization unit as described above.
[0058] An electronic device includes a memory and one or more instructions, wherein the one or more instructions are stored in the memory and configured to be executed by one or more processors to compile the program organization unit as described above.
[0059] Based on a compilation method of a program organization unit provided by the above-mentioned embodiment of the present invention, when it is necessary to compile a target program organization unit, the target program organization unit is parsed to obtain an original configuration program corresponding to the target program organization unit; a legality check is performed on the original configuration program, and if the original configuration program passes the legality check, the original configuration program is converted into an intermediate code to obtain an intermediate representation code corresponding to the original configuration program; the intermediate representation code is processed for bit number information identification to obtain a bit number information set; the bit number information set includes at least one bit number description information; based on the bit number information set, a bit number description file is generated so that the controller performs bit number management based on the bit number description file when running the program; the bit number operation in the intermediate representation code is determined code and business logic code; the bit number operation code includes at least one data read and write code corresponding to a bit number read and write operation; for each bit number read and write operation, the operation code is converted based on the data read and write code corresponding to the bit number read and write operation, and the interface call code corresponding to the bit number read and write operation is obtained, and the interface call code is used to call a preset bit number read and write interface to perform the bit number read and write operation; the business logic code is converted into a readable code to obtain a readable logic code corresponding to the business logic code; based on the readable logic code and the interface call code corresponding to each bit number read and write operation, a target code file corresponding to the intermediate representation code is generated; an executable file corresponding to the target code file is generated; the executable file and the bit number description file are used as the compilation result of the target program organization unit. By applying the method provided by the embodiment of the present invention, during the program compilation process of the program organization unit (POU), the description information of each bit number involved in the POU program can be extracted, the description information of each bit number can be summarized to generate a bit number description file, and the bit number operation code in the POU program can be converted into a corresponding interface call code, and the final executable file can be generated based on the readable code and interface call code of the business logic code in the POU program. The compilation result of the POU program includes an executable file and a bit number description file. During the compilation process, there is no need to implement bit number management by configuring global variables. When the controller runs the program based on the compilation result, it can use the bit number description file to perform operations such as memory allocation on the bit number, and based on the interface call code corresponding to each bit number read and write operation, call the preset bit number read and write interface to perform the corresponding bit number read and write operation. Therefore, during the configuration process of the POU program, the configuration engineer can configure the bit number operation code according to business needs in the configuration of the POU program. The bit number management can be realized based on its configuration program, and there is no need to realize the bit number management by configuring the global variable table. Therefore, only the configured POU program needs to be maintained, and there is no need to pay attention to the bit number synchronization of the overall control configuration, which is conducive to improving the convenience of program configuration and improving the efficiency and accuracy of configuration. BRIEF DESCRIPTION OF THE DRAWINGS
[0060] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying creative work.
[0061] Figure 1 A method flow chart of a method for compiling a program organization unit provided by an embodiment of the present invention;
[0062] Figure 2 A schematic diagram of a component architecture of a compiler provided by an embodiment of the present invention;
[0063] Figure 3 A schematic diagram of a compilation process provided by an embodiment of the present invention;
[0064] Figure 4 A schematic diagram of the structure of a compiling device for a program organization unit provided by an embodiment of the present invention;
[0065] Figure 5 A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0066] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0067] In this application, the terms "comprises", "comprising" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "comprising a ..." does not exclude the presence of other identical elements in the process, method, article or device comprising the element.
[0068] The embodiment of the present invention provides a method for compiling a program organization unit. The method can be applied to a compiler, and the execution subject can be a processor that deploys the compiler. The method flow chart of the method is as follows: Figure 1 As shown, including:
[0069] S101: When a target program organization unit needs to be compiled, the target program organization unit is parsed to obtain an original configuration program corresponding to the target program organization unit;
[0070] The method provided by the embodiment of the present invention is applied to the compilation scenario of the control system configuration program. In the configuration of the control logic, corresponding programs are usually configured for different objects. For example, when configuring the program logic based on the S88 / S95 standard, for each instrument on site, a control module (CM) program will be configured for each instrument, for example, a valve on site corresponds to a CM program, a pressure transmitter corresponds to a CM program, a level transmitter corresponds to a CM program, and so on. For each device on site, an equipment module (Equipment Module) program will be configured for each device, for example, a reaction tower corresponds to an EM program, a reactor corresponds to an EM program, and so on. In the control logic of the device, it is often necessary to reference the bit number data of multiple instruments to realize business logic processing, so correspondingly, the bit numbers in multiple CM programs are often referenced in the EM program. These module programs are independent program organization units (POUs), respectively. It can be understood that the overall configuration program is composed of various POU programs. S88 and S95 are two existing standards for standardized industrial control system architectures.
[0071] In the method provided by the embodiment of the present invention, when the configuration program of the control system is compiled, each POU program needs to be compiled separately, and the POU program that needs to be compiled currently is called the target program organization unit. When the compiler compiles the target program organization unit, first, it needs to parse the source program of the target program organization unit, specifically, read the program file corresponding to the target program organization unit, deserialize and parse the archive file into structured data in the memory, so as to obtain the original configuration program corresponding to the target program organization unit. The original configuration program includes business logic codes related to specific business, and also includes read and write operation codes for bit numbers involved in the configuration.
[0072] S102: Performing a validity check on the original configuration program to obtain a validity check result;
[0073] In the method provided by the embodiment of the present invention, the compiler can perform a legality check on the original configuration program according to a pre-set legality check strategy to identify whether the configuration content of the target program organization unit meets the program configuration requirements. The legality check result of the original configuration program indicates whether the original configuration program passes the legality check. If the legality check result indicates that the original configuration program fails the legality check, the program compilation process of the target program organization unit can be stopped.
[0074] S103: If the validity check result indicates that the original configuration program passes the validity check, performing intermediate code conversion on the original configuration program to obtain an intermediate representation code corresponding to the original configuration program;
[0075] In the method provided by an embodiment of the present invention, if the result of the legitimacy check of the original configuration program indicates that the original configuration program has passed the legitimacy check, that is, the configuration content of the original configuration program meets the program configuration requirements, the compiler converts the original configuration program into an intermediate code of a corresponding form, that is, an intermediate representation, and uses the converted intermediate code as the intermediate representation code of the original configuration program.
[0076] S104: performing a bit number information identification process on the intermediate representation code to obtain a bit number information set; the bit number information set includes at least one bit number description information;
[0077] In the method provided by the embodiment of the present invention, after obtaining the intermediate representation code of the original configuration program, the compiler can identify the relevant information of the bit number objects involved in the intermediate representation code, and form a bit number information set with the bit number description information of each bit number object obtained by identification. Each bit number description information includes various data required for the corresponding bit number object to be persisted in memory during the program scheduling cycle.
[0078] S105: generating a bit number description file based on the bit number information set, so that the controller performs bit number management based on the bit number description file when running the program;
[0079] In the method provided by the embodiment of the present invention, each bit number description information in the bit number information set is summarized to obtain a bit number description list, and a corresponding program data description file is generated based on the bit number description list, and the program data description file is used as a bit number description file, and the bit number description file can also be called a bit number list description file. The bit number description file will be used as a component of the target program organization unit program compilation result. When the controller is running the program, it can perform operations such as memory allocation on the corresponding bit number based on the bit number description file to realize bit number management.
[0080] S106: Determine a bit number operation code and a business logic code in the intermediate representation code; the bit number operation code includes at least one data read / write code corresponding to a bit number read / write operation;
[0081] In the method provided by the embodiment of the present invention, after obtaining the intermediate representation code of the original configuration program, the compiler can identify the specific content of the intermediate representation code, and distinguish the code related to the bit number operation and the code related to the actual business logic other than the bit number operation. The code related to the bit number operation is called the bit number operation code, and the code related to other actual business logic is called the business logic code. The bit number operation is generally a read and write operation of the bit number, and the bit number operation code is composed of the data read and write code corresponding to the bit number read and write operation involved in the intermediate representation code. The bit number operation code may include data read and write codes corresponding to multiple bit number read and write operations, and the specific number of operations involved is determined by the actual control logic requirements.
[0082] S107: for each of the bit number read and write operations, perform operation code conversion based on the data read and write code corresponding to the bit number read and write operation, and obtain an interface call code corresponding to the bit number read and write operation, wherein the interface call code is used to call a preset bit number read and write interface to perform the bit number read and write operation;
[0083] In the method provided by the embodiment of the present invention, an API interface for performing bit number reading and writing is pre-set, that is, a bit number reading and writing interface, and the bit number reading and writing interface is used to perform corresponding data reading and writing operations on the corresponding bit number according to the bit number reading and writing request. After the compiler identifies and obtains the bit number operation code, it can convert the data reading and writing code of each bit number reading and writing operation, and convert the data reading and writing code into a corresponding interface calling code for calling the preset bit number reading and writing interface. For example, the data reading and writing code of the bit number reading and writing operation A is to perform a write operation on the bit number B, then the data reading and writing code is converted into a code for calling the bit number reading and writing interface, and the interface parameters passed into the interface in the calling code of the interface indicate to perform a write operation on the bit number B, and the code for calling the bit number reading and writing interface and requesting the bit number reading and writing interface to perform a write operation on the bit number B is the interface calling code corresponding to the bit number reading and writing operation A.
[0084] S108: Convert the business logic code into a readable code to obtain a readable logic code corresponding to the business logic code;
[0085] In the method provided by the embodiment of the present invention, the compiler converts the business logic code in the intermediate representation code into a readable code of the corresponding type, and uses the conversion result as the readable logic code. For example, the business logic code can be converted into C code or assembly code, and the specific code type can be configured according to actual needs.
[0086] S109: generating a target code file corresponding to the intermediate representation code based on the readable logic code and the interface calling code corresponding to each of the bit number read and write operations;
[0087] In the method provided by the embodiment of the present invention, the compiler can use the readable logic code and the interface call code corresponding to each bit number read and write operation as the code content, generate a corresponding code file, and use the code file as the target code file corresponding to the intermediate representation code. That is, the compiler can convert the data read and write code of each bit number read and write operation in the intermediate representation code into the corresponding interface call code, replace the original bit number operation code with each interface call code, convert the business logic code in the intermediate representation object into a readable code, and generate a corresponding code file based on the intermediate representation object that has undergone the interface call code conversion and the readable code conversion.
[0088] S110: Generate an executable file corresponding to the target code file;
[0089] In the method provided by the embodiment of the present invention, the compiler can convert the target code file into a corresponding executable file through compiling and linking.
[0090] S111: taking the executable file and the bit number description file as the compilation result of the target program organization unit.
[0091] In the method provided by the embodiment of the present invention, the compiler can use the executable file of the bit number description file and the target code file as the compilation result of the target program organization unit. When the controller runs the program of the target program organization unit, it can perform bit number management operations such as memory allocation on each bit number according to the bit number description file in its compilation result, and when performing logical control based on the executable file, the corresponding bit number read and write operations are implemented by calling the bit number read and write interface.
[0092] Based on the method provided by the embodiment of the present invention, when compiling a target program organization unit, the target program organization unit is parsed to obtain an original configuration program corresponding to the target program organization unit; a legality check is performed on the original configuration program, and if the original configuration program passes the legality check, the original configuration program is converted into an intermediate code to obtain a corresponding intermediate representation code; the bit number information in the intermediate representation code is identified to obtain a bit number information set; based on the bit number information set, a bit number description file is generated; the bit number operation code and the business logic code in the intermediate representation code are determined; the bit number operation code includes at least one data corresponding to a bit number read and write operation Read and write code; for each bit number read and write operation, the operation code is converted based on the data read and write code corresponding to the bit number read and write operation, and the interface call code corresponding to the bit number read and write operation is obtained, and the interface call code is used to call the preset bit number read and write interface to perform the bit number read and write operation; the business logic code is converted into a readable code to obtain a readable logic code corresponding to the business logic code; based on the readable logic code and the interface call code corresponding to each bit number read and write operation, a target code file corresponding to the intermediate representation code is generated; an executable file corresponding to the target code file is generated; the executable file and the bit number description file are used as the compilation result of the target program organization unit. Applying the method provided by the embodiment of the present invention, in the program compilation process of the program organization unit (POU), the description information of each bit number involved in the POU program can be extracted, the description information of each bit number can be summarized to generate a bit number description file, and the bit number operation code in the POU program can be converted into a corresponding interface call code, and the final executable file is generated based on the readable code and interface call code of the business logic code in the POU program, and the compilation result of the POU program includes an executable file and a bit number description file. During the compilation process, there is no need to implement bit number management by configuring global variables. When the controller runs the program based on the compilation results, it can use the bit number description file to perform operations such as memory allocation on the bit number, and based on the interface call code corresponding to each bit number read and write operation, call the preset bit number read and write interface to perform the corresponding bit number read and write operations. Therefore, during the configuration process of the POU program, the configuration engineer can configure the bit number operation code according to business needs in the configuration of the POU program. The management of the bit number can be implemented based on its configuration program, and there is no need to implement bit number management by configuring the global variable table. Therefore, only the configured POU program needs to be maintained, and there is no need to pay attention to the bit number synchronization of the overall control configuration, which is conducive to improving the convenience of program configuration and improving the efficiency and accuracy of configuration.
[0093] exist Figure 1 On the basis of the method shown, in the method provided by the embodiment of the present invention, the process of performing program parsing on the target program organization unit mentioned in step S101 to obtain the original configuration program corresponding to the target program organization unit includes:
[0094] Obtaining the source program of the target program organization unit;
[0095] In the method provided by the embodiment of the present invention, the compiler can obtain the source program of the target program organization unit, that is, the original program code stored in the archive file, by reading the archive file corresponding to the target program organization unit.
[0096] According to the programming language type of the target program organization unit, determining a target program parsing module corresponding to the target program organization unit from a plurality of pre-configured program parsing modules;
[0097] In the method provided by the embodiment of the present invention, multiple program parsing modules can be pre-set, and each program parsing module corresponds to various types of programming languages, and each programming language type corresponds to a program parsing module. For example, a function block diagram language (FBD) / ladder diagram language (LD) corresponds to a program parsing module, a structured text language (ST) / sequential function flow chart language (SFC) corresponds to a program parsing module, and an instruction list language (IL) corresponds to a program parsing module. Each program parsing module is set according to the program parsing mechanism of the programming language type corresponding to it, and it can convert the source program of this type into structured data in the memory. It can be understood that each program organization unit is a program module obtained based on the corresponding programming language type configuration. When the compiler performs program parsing, it can find the program parsing module corresponding to the programming language type in each program parsing module according to the programming language type of the target program organization unit, that is, the programming language type of the configuration program of the program organization unit, and use the program parsing module corresponding to the programming language type as the target program parsing module.
[0098] The target program analysis module is called to analyze the source program to obtain a program analysis result, and the program analysis result is used as the original configuration program corresponding to the target program organization unit.
[0099] In the method provided by the embodiment of the present invention, the compiler can call the target program parsing module to parse the source program of the target program organization unit. Specifically, the source program of the target program organization unit can be loaded into the target program parsing module, and the target program parsing module converts the source program into a unified data structure form based on a program parsing specification that matches its programming language type, and obtains a complete mapping expression of the source program, that is, the program parsing result of the target program organization unit, and uses the result as the original configuration program to facilitate subsequent operations.
[0100] Based on the method provided by the embodiment of the present invention, the corresponding program parsing module can be matched according to the programming language type of the target program organization unit to implement program parsing. In the case of program parsing that can adapt to different types of program organization units, each type of program organization unit can be parsed by a matching program parsing mechanism, which is conducive to improving the program parsing speed and then improving the program compilation efficiency.
[0101] exist Figure 1 On the basis of the method shown, in the method provided by the embodiment of the present invention, the process of performing a validity check on the original configuration program mentioned in step S102 to obtain a validity check result includes:
[0102] Get multiple pre-set check conditions;
[0103] In the method provided by the embodiment of the present invention, multiple check conditions can be pre-configured according to actual needs to detect whether the configuration content of the POU program meets the configuration requirements. For example, each check condition may include: whether the configuration content meets the programming language specification, whether the bit name is legal, whether the program is over-specified, whether the primitive connection is legal, whether there are unused variables in the program, etc. The compiler can obtain each check condition from the configuration data.
[0104] Determining whether the original configuration program meets each of the inspection conditions;
[0105] In the method provided by the embodiment of the present invention, the compiler can check the content of the original configuration program according to the condition content of each check condition. Specifically, when checking the original configuration program based on a certain check condition, the required judgment parameters can be determined according to the condition content of the current check condition, and the original configuration program can be analyzed according to the required judgment parameters to obtain data matching the judgment parameters, and identify whether these data are consistent with the condition requirements of the current check condition. If they are consistent, it is considered that the original configuration program meets the current check condition. For example, if the check condition is whether there are unused variables in the program, the required judgment parameters are determined to be the variables involved in the program, and the original configuration program is analyzed for variables to obtain the various variables existing in the original configuration program, and identify whether these variables are all used variables. If these variables are all used variables, there are no unused variables in the program, and it is considered that the original configuration program meets the check condition.
[0106] If the original configuration program meets each of the check conditions, a first preset conclusion is used as the legality check result; the first preset conclusion indicates that the original configuration program passes the legality check.
[0107] In the method provided by the embodiment of the present invention, if the original configuration program meets each check condition, that is, the content of the original configuration program meets the condition requirements of all check conditions, the compiler will take the passing of the legality check as the legality check result of the original configuration program. If the original configuration program fails to meet all check conditions, that is, there is at least one check condition that the original configuration program does not meet, then the second preset conclusion is taken as the legality check result of the original configuration program, and the second preset conclusion indicates that the original configuration program has not passed the legality check, that is, if the original configuration program does not meet all check conditions, it is considered that it has not passed the legality check.
[0108] exist Figure 1 On the basis of the method shown, in the method provided by the embodiment of the present invention, the process of converting the intermediate code of the original configuration program mentioned in step S103 to obtain the intermediate representation code corresponding to the original configuration program includes:
[0109] According to the programming language type of the target program organization unit, determining a target code conversion module corresponding to the target program organization unit from a plurality of pre-configured code conversion modules;
[0110] In the method provided by the embodiment of the present invention, multiple code conversion modules can be pre-set, each code conversion module corresponds to each programming language type, and each programming language type corresponds to a code conversion module. Each code conversion module is set according to the program intermediate representation conversion mechanism of the programming language type to which it corresponds, and each code conversion module is used to translate the corresponding type of configuration program into the corresponding intermediate representation code. The compiler can find the code conversion module corresponding to the programming language type according to the programming language type of the target program organization unit, and use the code conversion module corresponding to the programming language type as the target code conversion module.
[0111] The target code conversion module is called to perform intermediate code conversion on the original configuration program to obtain a code conversion result, and the code conversion result is used as the intermediate representation code corresponding to the original configuration program.
[0112] In the method provided by the embodiment of the present invention, the compiler can call the target code conversion module to convert the original configuration program of the target program organization unit into an intermediate code. Specifically, the original configuration program can be loaded into the target code conversion module, and the target code conversion module converts the original configuration program into a corresponding code form based on the corresponding intermediate representation conversion mechanism to obtain the conversion result of the original configuration program, that is, the intermediate representation code of the original configuration program.
[0113] Based on the method provided by the embodiment of the present invention, different code conversion modules can be used to adapt to the intermediate representation code conversion of different types of POU programs, which is beneficial to improving the conversion speed of the intermediate representation code and further improving the program compilation efficiency.
[0114] exist Figure 1 On the basis of the method shown, in the method provided by the embodiment of the present invention, the process of performing bit number information identification processing on the intermediate representation code mentioned in step S104 to obtain a bit number information set includes:
[0115] Identifying each bit number object associated with the intermediate representation code;
[0116] In the method provided by the embodiment of the present invention, the compiler can identify each bit number involved in the intermediate representation code, and use the identified bit numbers as each bit number object associated with the intermediate representation code.
[0117] Determine the basic description information corresponding to each of the bit number objects; the basic description information corresponding to each of the bit number objects includes the bit number name, unique coding identifier, data type and initial value of the bit number object;
[0118] In the method provided by an embodiment of the present invention, the compiler can further parse the code content related to each bit number object in the intermediate representation code, and extract the content describing the basic properties of each bit number object, specifically including the bit number name, unique coding identifier, data type and initial value of the bit number, and use the basic description data of the bit number object as the basic description information of the bit number object.
[0119] Determine the extended description information corresponding to each of the bit number objects; the extended description information corresponding to each of the bit number objects includes various configuration data for managing and accessing the bit number object;
[0120] In the method provided by the embodiment of the present invention, when the compiler parses the code content related to each bit number object, it can also extract the description content related to the application of each bit number object, specifically including various configuration data used to manage and access the bit number when the program is running, such as bit number description, whether to multicast, whether to enter the history record, read and write permission level, memory allocation strategy, etc. The various configuration data used to manage and access the bit number object are used as the extended description information of the bit number object.
[0121] For each of the bit number objects, the basic description information and the extended description information corresponding to the bit number object are used as the bit number description information corresponding to the bit number object;
[0122] The bit number information set is composed of the bit number description information corresponding to each bit number object.
[0123] In the method provided by the embodiment of the present invention, the basic description information and extended description information of each bit number object in the intermediate representation code are used as the bit number description information of the bit number object. That is, the bit number description information of a bit number object includes the basic description information corresponding to the bit number object and the extended description information corresponding to the bit number object. The bit number description information of each bit number object is used as a bit number information set.
[0124] exist Figure 1 On the basis of the method shown, in the method provided by the embodiment of the present invention, the process of performing operation code conversion based on the data read and write code corresponding to the bit number read and write operation mentioned in step S107 to obtain the interface call code corresponding to the bit number read and write operation includes:
[0125] Determine the operation information corresponding to the bit number read / write operation according to the data read / write code corresponding to the bit number read / write operation; the operation information includes the target bit number identifier, data operation type and reference method corresponding to the bit number read / write operation;
[0126] In the method provided by the embodiment of the present invention, when the compiler performs operation code conversion on the bit number read and write operation, it can identify the data read and write code corresponding to the bit number read and write operation, and obtain the target bit number identification, data operation type, reference method and other data related to the bit number operation corresponding to the bit number read and write operation. The target bit number identification is the identification of the bit number that needs to be operated, the data operation type refers to the type of operation that needs to be performed, such as a read operation or a write operation, and the reference method refers to the type of reference of the program to the bit number, such as an external reference or a content reference. The various data related to the bit number operation indicated in the data read and write code are used as the operation information of the current bit number read and write operation.
[0127] Generate interface parameters according to the operation information;
[0128] In the method provided by the embodiment of the present invention, the compiler can convert various data in the operation information into corresponding interface parameters according to the pre-configured interface parameter format.
[0129] Based on the interface parameters, a calling code of the bit number read / write interface is determined, and the calling code of the bit number read / write interface is used as the interface calling code corresponding to the bit number read / write operation.
[0130] In the method provided by the embodiment of the present invention, a calling code template of the bit number read / write interface can be pre-set, and the current interface parameters are substituted into the preset calling code template to generate the corresponding code for calling the bit number read / write interface, that is, the calling code of the bit number read / write interface, and the calling code is used as the interface calling code corresponding to the current bit number read / write operation. It can be understood that the interface parameters generated based on the operation information indicate that a specified operation is performed on a specified bit number, so the current calling code of the bit number read / write interface is to request the bit number read / write interface to perform a specified operation on the specified bit number.
[0131] exist Figure 1 On the basis of the method shown, in the method provided by the embodiment of the present invention, the process of generating the executable file corresponding to the target code file mentioned in step S110 includes:
[0132] Determining an operating environment corresponding to the controller;
[0133] In the method provided by the embodiment of the present invention, the compiler can determine the operating environment of the current controller according to the configuration information of the system, that is, the deployment environment of the control system, such as Linux or Windows environment.
[0134] Determine the compile and link tool corresponding to the operating environment;
[0135] In the method provided in the embodiment of the present invention, multiple compiling and linking tools can be pre-configured, and each compiling and linking tool corresponds to each type of system operating environment, that is, each type of system operating environment has a corresponding compiling and linking tool. The compiler can search for the compiling and linking tool corresponding to the current operating environment in the pre-deployed compiling and linking tools according to the operating environment corresponding to the current controller. For example, the Linux environment can correspond to the compiling and linking tool gcc / g++.
[0136] The compiling and linking tool is used to link the target code file to obtain a program file of an executable program, and the program file of the executable program is used as the executable file corresponding to the target code file.
[0137] In the method provided by the embodiment of the present invention, the compiler can use the compile and link tool matched by the current operating environment to link the target code file to obtain the executable program corresponding to the target code file, and use the program file of the executable program as the executable file of the target code file.
[0138] Based on the method provided in the embodiment of the present invention, different compilation and linking tools can be used to link codes in different operating environments, and executable programs in different operating environments can be generated to adapt to the compilation requirements in different environments and improve the flexibility of compilation.
[0139] In order to better illustrate the method provided by the embodiment of the present invention, based on the methods provided by the previous embodiments, the embodiment of the present invention provides another method for compiling a program organization unit in combination with actual application scenarios. The method provided by the embodiment of the present invention is applied to the compiler of the control system. The control system logic processing has the characteristics of "bit number + control logic". The logic processing object in the control system is usually the hard point bit number corresponding to the actual IO card and the corresponding soft point bit number or communication bit number in the software. These bit numbers must not only be able to be directly read and written by the program, but also usually need to be monitored by monitoring programs, that is, the bit numbers need to be sensed by other system components. The control system in the embodiment of the present invention is based on the IEC 61131-3 (the third part of the IEC61131 standard) international standard specification for program configuration, and the configuration program is composed of various program organization unit (POU) programs. The method provided by the embodiment of the present invention is used to compile various POU programs in the configuration program. The component architecture of the compiler provided by the embodiment of the present invention can be as follows Figure 2 As shown, it specifically includes: program parsing module, configuration legality checking module, intermediate representation code generation module, bit number list description file generation module, execution code generation module and compilation and linking module. The functions of each module are briefly described below.
[0140] Program parsing module: A program parsing module based on the IEC6113-3 standard. This module loads the original program of the POU program, parses the original configuration content of the POU program, and checks the legality and validity of the configuration. Specifically, IEC61131-3 contains multiple programming language types. The FBD / LD type POU program corresponds to a program parsing module, the ST / SFC type POU program corresponds to a program parsing module, and the IL type POU program corresponds to a program parsing module. Different types of program parsing modules have the same external interface. During the compilation process, according to the programming language type of the POU program to be compiled, a program parsing module that matches its programming language type can be applied. The program parsing module parses the original program of the POU program to obtain the program parsing result (i.e. Figure 1 The original configuration program in the method shown), and calls the legality check module to perform a legality check on the program parsing result. If the program parsing result passes the legality check, the program parsing result is input into the intermediate representation code generation module for subsequent processing.
[0141] Legality check module: This module performs a legality check on the POU configuration based on the program parsing results of the POU program. For example, it checks whether the configuration content meets the specifications of the IEC61131-3 programming language, checks the legality of the bit number name, whether the single program is over-configured, whether the FBD / LD / SFC graphic element connections are legal, whether there are unused variables in the program, whether there are multiple assignments of the same bit number in the program, ST code syntax check, etc. It can also check whether there are external bit numbers in the current POU program, whether the type of the source bit number definition and the usage at the reference are compatible, etc.
[0142] Intermediate representation code generation module: This module is responsible for converting the program parsing results into a normalized intermediate representation code object. Each programming language corresponds to a specific intermediate representation code generation module. During the compilation process, the intermediate representation code generation module that matches the programming language type of the current POU program can be called. The intermediate representation code generation module converts the program parsing results of the POU program into intermediate codes to obtain the intermediate representation code of the program parsing results. The intermediate representation code is an intermediate layer that reduces the coupling between the final compiled generated code and the original configuration content. The compilation of each code only needs to be converted into the intermediate representation code, and the subsequent compilation and linking only need to be uniformly processed for the intermediate representation code.
[0143] Bit number list description file generation module: This module traverses and extracts the relevant description information of the bits that need to be persisted in the memory during the program scheduling cycle in the controller based on the intermediate representation code generated by the intermediate representation code generation module, and summarizes the description information of each bit number to generate the corresponding bit number list description file (i.e. Figure 1 The bit number description file in the method shown in the figure) is a program data description file. The description information of a single bit number includes basic description information and extended description information. The basic description information includes the bit number name, unique coding identifier, data type, initial value, etc. The extended description information includes the bit number description, whether it is multicast, whether it is recorded in history, read and write permission level, memory allocation strategy, etc. The bit number description information contains relevant data on the allocation and use of the bit number in the controller memory. The controller operating environment can provide the actual allocation and read and write access of the bit number according to the bit number list description file.
[0144] Execution code generation module: This module is responsible for performing corresponding code conversion on the intermediate representation code. Specifically, it is necessary to identify the bit number operation code and business logic code in the intermediate representation code. For the bit number operation code, it is converted into a call code for the preset bit number read and write interface, that is, the bit number operation code records the code for performing data read and write operations on the bit number. Based on the bit number read and write operations indicated in the bit number operation code, an interface call code is generated to request the bit number read and write interface to perform corresponding data read and write operations on the bit number. Specifically, according to different reference types to the bit number in the program, such as external references and internal references, corresponding API interface (bit number read and write interface) calls can be generated. According to the object source or path of the calling bit number parameter, the compiler can generate specific interface parameters to send to the API interface. For the business logic code, it will be converted into a general, readable code, such as C code or assembly code. For the intermediate representation code that has been processed by code conversion (that is, the bit number operation code in the intermediate representation code has been replaced with the interface call code for the bit number read and write interface, and the business logic code has been converted into readable code), a corresponding code file is generated.
[0145] Compile and link module: This module is used to link the code files generated by the execution code generation module. Specifically, the corresponding compile and link tools can be deployed according to the operating environment of various systems. During the compilation process, the corresponding compile and link tool can be selected according to the operating environment of the target controller to compile and link the code files generated by the execution code generation module to obtain the executable file of the business logic. For example, in the Linux environment, gcc / g++ can be used to generate a dynamic library so file from the code file.
[0146] In the embodiment of the present invention, the bit number list description file generated by the bit number list description file generation module and the executable file generated by the compile link module are used as the compilation results of the current POU program.
[0147] In general, the compilation process of the program organization unit provided in the embodiment of the present invention can be as follows: Figure 3 As shown, when compiling the configuration program of a single POU, the various modules in the compiler are processed accordingly, and finally the bit number list description file and executable file corresponding to the current POU program are obtained. With the bit number list description file as a prerequisite for the execution of the executable file, when the controller schedules the execution of the executable file, it is necessary to allocate the bit number memory inside the controller and initialize all the bit numbers in the POU program according to the bit number list description file, and be responsible for the read and write operations of the bit numbers when running externally. The executable file generated in the embodiment of the present invention mainly records the code segment, and does not contain the data segment in the executable file obtained by the traditional compilation method such as ELF. During the program running process, the corresponding bit number parameters are read and written by calling the bit number read and write interface.
[0148] In the method provided by the embodiment of the present invention, the controller is responsible for initializing the corresponding bit numbers in the bit number list description file at runtime during program scheduling, and is responsible for reading and writing these bit numbers at external runtime. Through the bit number description list and bit number read and write interface corresponding to each POU program, the bit number can be perceived and read and written by a third-party program.
[0149] In the method provided by the embodiment of the present invention, the compilation results of the bit number data and the code are separated, the management of the bit number in the compilation results is decoupled from the business logic code, and the compilation result file of the program does not contain the allocation and release code of the bit number, but only the business logic code and the code for bit number reference processing (that is, the calling code of the bit number read and write interface).
[0150] In the method provided by an embodiment of the present invention, the compiler can generate a bit number list description file in a unified format for POU programs in different programming languages. A bit number list description file is generated for each POU, and each bit number list description file contains relevant data that persists in the memory for all bit numbers involved in the corresponding POU program.
[0151] In the method provided by the embodiment of the present invention, according to the different operating environments of the controller, machine codes for direct calls such as x86 / arm can be generated, and intermediate bytecodes of different formats (such as java bytecode or wasm) can be generated to adapt to the compilation requirements of different operating environments. The compilation of the bit number reading and writing only depends on the API interface specification, which can adapt to the software and hardware operating environments of different controllers.
[0152] Based on the method provided in the embodiment of the present invention, the position number reading and writing operations can be directly configured during the configuration process of the POU program. There is no need to configure the global variable configuration for the position number. The user only maintains the POU program configured by the user, which can improve the convenience and accuracy of the user configuration. Different POU programs can realize interactive reading and writing of position numbers. During configuration, any position number or parameter can be directly referenced for reading and writing, without the need for third-party communication to realize cross-POU data forwarding. Reading and writing are realized through a unified interface call without the need for communication configuration, and the read and write operations based on the interface call have a lower operation delay than those of third-party communications, which can improve the read and write performance. In addition, in the method provided in the embodiment of the present invention, the position number data is decoupled from the business logic, and both the internal position numbers and the referenced external position numbers are normalized, which can simplify the controller scheduling logic.
[0153] and Figure 1 Corresponding to the method for compiling the program organization unit shown in FIG. 1 , an embodiment of the present invention further provides a device for compiling the program organization unit, for compiling Figure 1 The specific implementation of the method shown in is shown in the structural diagram Figure 4 As shown, including:
[0154] The program parsing unit 201 is used to parse the target program organization unit when it is necessary to compile the target program organization unit, and obtain the original configuration program corresponding to the target program organization unit;
[0155] A program checking unit 202, used for performing a validity check on the original configuration program to obtain a validity check result;
[0156] A first conversion unit 203 is configured to perform intermediate code conversion on the original configuration program to obtain an intermediate representation code corresponding to the original configuration program if the validity check result indicates that the original configuration program passes the validity check;
[0157] A bit number identification unit 204 is used to perform bit number information identification processing on the intermediate representation code to obtain a bit number information set; the bit number information set includes at least one bit number description information;
[0158] A first generating unit 205 is used to generate a bit number description file based on the bit number information set, so that the controller performs bit number management based on the bit number description file when running a program;
[0159] A code identification unit 206, configured to determine a bit number operation code and a business logic code in the intermediate representation code; the bit number operation code includes a data read / write code corresponding to at least one bit number read / write operation;
[0160] The second conversion unit 207 is used to perform operation code conversion for each of the bit number read and write operations based on the data read and write code corresponding to the bit number read and write operation, and obtain the interface call code corresponding to the bit number read and write operation, and the interface call code is used to call a preset bit number read and write interface to perform the bit number read and write operation;
[0161] The third conversion unit 208 is used to convert the business logic code into a readable code to obtain a readable logic code corresponding to the business logic code;
[0162] A second generating unit 209, configured to generate a target code file corresponding to the intermediate representation code based on the readable logic code and the interface calling code corresponding to each of the bit number read and write operations;
[0163] The third generating unit 210 is used to generate an executable file corresponding to the target code file;
[0164] The result output unit 211 is used to use the executable file and the bit number description file as the compilation result of the target program organization unit.
[0165] By using the device provided by the embodiment of the present invention, during the program compilation process of the program organization unit (POU), the description information of each bit number involved in the POU program can be extracted, the description information of each bit number can be summarized to generate a bit number description file, and the bit number operation code in the POU program can be converted into a corresponding interface call code, and the final executable file can be generated based on the readable code and interface call code of the business logic code in the POU program. The compilation result of the POU program includes an executable file and a bit number description file. During the compilation process, there is no need to implement bit number management by configuring global variables. When the controller runs the program based on the compilation result, it can use the bit number description file to perform operations such as memory allocation on the bit number, and based on the interface call code corresponding to each bit number read and write operation, call the preset bit number read and write interface to perform the corresponding bit number read and write operation. Therefore, during the configuration process of the POU program, the configuration engineer can configure the bit number operation code according to business needs in the configuration of the POU program. The bit number management can be realized based on its configuration program, and there is no need to realize the bit number management by configuring the global variable table. Therefore, only the configured POU program needs to be maintained, and there is no need to pay attention to the bit number synchronization of the overall control configuration, which is conducive to improving the convenience of program configuration and improving the efficiency and accuracy of configuration.
[0166] exist Figure 4 Based on the device shown, the device provided by the embodiment of the present invention can be further expanded into multiple units. The function of each unit can refer to the description of each embodiment provided in the previous text for the compilation method of the program organization unit, and no further examples will be given here.
[0167] An embodiment of the present invention further provides a storage medium, which includes stored instructions, wherein when the instructions are executed, the device where the storage medium is located is controlled to execute the above-mentioned method for compiling the program organization unit.
[0168] The embodiment of the present invention further provides an electronic device, the structural diagram of which is shown in FIG. Figure 5 As shown, it specifically includes a memory 301 and one or more instructions 302, wherein the one or more instructions 302 are stored in the memory 301 and are configured to be executed by one or more processors 303 to perform the following operations:
[0169] When the target program organization unit needs to be compiled, the target program organization unit is parsed to obtain the original configuration program corresponding to the target program organization unit;
[0170] Performing a validity check on the original configuration program to obtain a validity check result;
[0171] If the validity check result indicates that the original configuration program passes the validity check, performing intermediate code conversion on the original configuration program to obtain an intermediate representation code corresponding to the original configuration program;
[0172] Performing a bit number information identification process on the intermediate representation code to obtain a bit number information set; the bit number information set includes at least one bit number description information;
[0173] Based on the bit number information set, a bit number description file is generated, so that the controller performs bit number management based on the bit number description file when running the program;
[0174] Determine a bit number operation code and a business logic code in the intermediate representation code; the bit number operation code includes at least one data read and write code corresponding to a bit number read and write operation;
[0175] For each of the bit number read and write operations, an operation code conversion is performed based on the data read and write code corresponding to the bit number read and write operation to obtain an interface call code corresponding to the bit number read and write operation, and the interface call code is used to call a preset bit number read and write interface to perform the bit number read and write operation;
[0176] Convert the business logic code into a readable code to obtain a readable logic code corresponding to the business logic code;
[0177] Generate a target code file corresponding to the intermediate representation code based on the readable logic code and the interface calling code corresponding to each of the bit number read and write operations;
[0178] Generate an executable file corresponding to the target code file;
[0179] The executable file and the bit number description file are used as the compilation result of the target program organization unit.
[0180] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can refer to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the system or system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can refer to the partial description of the method embodiment. The system and system embodiments described above are merely schematic, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without creative work.
[0181] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.
[0182] The above description of the disclosed embodiments enables those skilled in the art to implement or use the present invention. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but rather to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A method for compiling a program organization unit, characterized in that: include: When the target program organization unit needs to be compiled, the target program organization unit is parsed to obtain the original configuration program corresponding to the target program organization unit; Performing a validity check on the original configuration program to obtain a validity check result; If the validity check result indicates that the original configuration program passes the validity check, performing intermediate code conversion on the original configuration program to obtain an intermediate representation code corresponding to the original configuration program; Performing a bit number information identification process on the intermediate representation code to obtain a bit number information set; the bit number information set includes at least one bit number description information; Based on the bit number information set, a bit number description file is generated, so that the controller performs bit number management based on the bit number description file when running the program; Determine a bit number operation code and a business logic code in the intermediate representation code; the bit number operation code includes at least one data read and write code corresponding to a bit number read and write operation; For each of the bit number read and write operations, an operation code conversion is performed based on the data read and write code corresponding to the bit number read and write operation to obtain an interface call code corresponding to the bit number read and write operation, and the interface call code is used to call a preset bit number read and write interface to perform the bit number read and write operation; Convert the business logic code into a readable code to obtain a readable logic code corresponding to the business logic code; Generate a target code file corresponding to the intermediate representation code based on the readable logic code and the interface calling code corresponding to each of the bit number read and write operations; Generate an executable file corresponding to the target code file; The executable file and the bit number description file are used as the compilation result of the target program organization unit.
2. The compiling method of the program organization unit according to claim 1, characterized in that: The performing program parsing on the target program organization unit to obtain the original configuration program corresponding to the target program organization unit includes: Obtaining the source program of the target program organization unit; According to the programming language type of the target program organization unit, determining a target program parsing module corresponding to the target program organization unit from a plurality of pre-configured program parsing modules; The target program analysis module is called to analyze the source program to obtain a program analysis result, and the program analysis result is used as the original configuration program corresponding to the target program organization unit.
3. The compiling method of the program organization unit according to claim 1, characterized in that: The performing a validity check on the original configuration program to obtain a validity check result includes: Get multiple pre-set check conditions; Determining whether the original configuration program meets each of the inspection conditions; If the original configuration program meets each of the check conditions, a first preset conclusion is used as the legality check result; the first preset conclusion indicates that the original configuration program passes the legality check.
4. The compiling method of the program organization unit according to claim 1, characterized in that: The performing intermediate code conversion on the original configuration program to obtain the intermediate representation code corresponding to the original configuration program includes: According to the programming language type of the target program organization unit, determining a target code conversion module corresponding to the target program organization unit from a plurality of pre-configured code conversion modules; The target code conversion module is called to perform intermediate code conversion on the original configuration program to obtain a code conversion result, and the code conversion result is used as the intermediate representation code corresponding to the original configuration program.
5. The compiling method of the program organization unit according to claim 1, characterized in that: The step of performing a bit number information identification process on the intermediate representation code to obtain a bit number information set includes: Identifying each bit number object associated with the intermediate representation code; Determine the basic description information corresponding to each of the bit number objects; the basic description information corresponding to each of the bit number objects includes the bit number name, unique coding identifier, data type and initial value of the bit number object; Determine the extended description information corresponding to each of the bit number objects; the extended description information corresponding to each of the bit number objects includes various configuration data for managing and accessing the bit number object; For each of the bit number objects, the basic description information and the extended description information corresponding to the bit number object are used as the bit number description information corresponding to the bit number object; The bit number information set is composed of the bit number description information corresponding to each bit number object.
6. The compiling method of the program organization unit according to claim 1, characterized in that: The step of performing operation code conversion based on the data read / write code corresponding to the bit number read / write operation to obtain the interface call code corresponding to the bit number read / write operation includes: Determine the operation information corresponding to the bit number read / write operation according to the data read / write code corresponding to the bit number read / write operation; the operation information includes the target bit number identifier, data operation type and reference method corresponding to the bit number read / write operation; Generate interface parameters according to the operation information; Based on the interface parameters, a calling code of the bit number read / write interface is determined, and the calling code of the bit number read / write interface is used as the interface calling code corresponding to the bit number read / write operation.
7. The compiling method of the program organization unit according to claim 1, characterized in that: The generating of the executable file corresponding to the target code file comprises: Determining an operating environment corresponding to the controller; Determine the compile and link tool corresponding to the operating environment; The compiling and linking tool is used to link the target code file to obtain a program file of an executable program, and the program file of the executable program is used as the executable file corresponding to the target code file.
8. A compiling device for a program organization unit, characterized in that: include: A program parsing unit, used for parsing the target program organization unit when it is necessary to compile the target program organization unit, and obtaining an original configuration program corresponding to the target program organization unit; A program checking unit, used for performing a legality check on the original configuration program to obtain a legality check result; A first conversion unit is configured to perform intermediate code conversion on the original configuration program to obtain an intermediate representation code corresponding to the original configuration program if the validity check result indicates that the original configuration program passes the validity check; A bit number identification unit is used to perform bit number information identification processing on the intermediate representation code to obtain a bit number information set; the bit number information set includes at least one bit number description information; A first generating unit, configured to generate a bit number description file based on the bit number information set, so that the controller performs bit number management based on the bit number description file when running a program; A code identification unit, used to determine the bit number operation code and the business logic code in the intermediate representation code; the bit number operation code includes at least one data read and write code corresponding to the bit number read and write operation; A second conversion unit is used to perform operation code conversion for each of the bit number read and write operations based on the data read and write code corresponding to the bit number read and write operation, and obtain an interface call code corresponding to the bit number read and write operation, wherein the interface call code is used to call a preset bit number read and write interface to perform the bit number read and write operation; A third conversion unit, configured to convert the business logic code into a readable code to obtain a readable logic code corresponding to the business logic code; A second generating unit, configured to generate a target code file corresponding to the intermediate representation code based on the readable logic code and the interface calling code corresponding to each of the bit number read and write operations; A third generating unit, used to generate an executable file corresponding to the target code file; The result output unit is used to use the executable file and the bit number description file as the compilation result of the target program organization unit.
9. A storage medium, characterized in that: The storage medium includes stored instructions, wherein when the instructions are executed, the device where the storage medium is located is controlled to execute the compiling method of the program organization unit according to any one of claims 1 to 7.
10. An electronic device, characterized in that: The system comprises a memory and one or more instructions, wherein the one or more instructions are stored in the memory and configured to be executed by one or more processors to compile the program organization unit according to any one of claims 1 to 7.