Transcoding method, apparatus, device, storage medium and product

CN122526576BActive Publication Date: 2026-10-20SUZHOU TONGYUAN SOFT CONTROL INFORMATION TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202611001434.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2026-07-07
Publication Date
2026-10-20
Estimated Expiration
2046-07-07

AI Technical Summary

Technical Problem

然而,当模型侧元数据以缩写文本、注解字段或部分字符串形式存在,或类型路径在不同版本间发生变化时,纯规则匹配容易产生未识别块或条件分支解析不完整的问题

Benefits of technology

与相关技术中采用纯规则映射导致语义补全准确性不足,以及未对条件结构进行融合导致多视图语义割裂相比,本申请通过获取源端建模环境下的模型描述信息,基于所述模型描述信息构建表达组件关系与数据依赖的中间表示,对所述中间表示中的不完备描述部分利用预设的大模型进行语义结构补全,并在识别到条件控制类组件与分支子结构之间存在预设关联模式时归并为融合结构并调整执行顺序,最终生成目标代码及可交换中间文件。可理解的是,当所述中间表示中存在不完备描述部分时,利用所述大模型从类型路径、参数键值与注解文本中提取结构化补全信息,以此实现语义补全,因此基于增强的数据依赖可以确定准确的执行顺序;进而当条件控制类组件与分支子结构满足预设关联模式时,通过归并为融合结构并施加合成约束,确定调整后的执行顺序,最终使得所述目标代码与所述可交换中间文件共享同一执行顺序与融合语义,解决了语义补全准确性不足和多视图一致性差的技术问题。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122526576B_ABST
    Figure CN122526576B_ABST
Patent Text Reader

Abstract

The application discloses a code conversion method and device, equipment, storage medium and product, relates to the automatic code generation technical field, and the code conversion method comprises the following steps: acquiring model description information under a source end modeling environment, constructing an intermediate representation expressing component relationship and data dependency based on the model description information; for the incomplete description part in the intermediate representation, the semantic structure is completed by using a large model, and an enhanced intermediate representation is obtained; based on the data dependency in the enhanced intermediate representation, the execution order is determined; when a preset association mode is identified between a conditional control type component and a branch substructure, the conditional control type component and the branch substructure are merged into a fusion structure, and the execution order is adjusted; according to the adjusted execution order and the fusion structure, target code and exchangeable intermediate files facing a target end engineering environment are generated. The application solves the technical problems of insufficient semantic completion accuracy and poor multi-view consistency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of automated code generation technology, and in particular to code conversion methods, apparatus, devices, storage media and products. Background Technology

[0002] In control algorithm development scenarios based on graphical modeling environments, engineers often use a component-based approach to build control models to express signal processing logic and control strategies. In contrast, the target engineering environment typically uses languages ​​and interchangeable formats conforming to programmable logic controller (PLC) programming standards for programming and integration. These two representations differ significantly in abstraction level, execution semantics, data types, and visualization forms. Related technologies often rely on manual rewriting based on the model, which is inefficient and prone to errors.

[0003] Conventional techniques have attempted to convert model structures into target code, with some solutions translating model components into text statements block by block using pre-defined mapping rules. However, when model metadata exists as abbreviated text, annotation fields, or partial strings, or when type paths change between versions, pure rule matching is prone to issues such as unrecognized blocks or incomplete conditional branch parsing. In recent years, large models have demonstrated capabilities in natural language understanding and structured information extraction, but directly generating target code end-to-end suffers from drawbacks such as poor verifiability, inconsistencies with specific project constraints, and difficulty in ensuring consistency with the original model data flow.

[0004] The aforementioned conventional technical solutions suffer from insufficient semantic completion accuracy when dealing with incomplete model description information during the conversion from graphical models to target-side code. Furthermore, when the model contains conditional control components and multiple branch substructures, the code generated by these technologies is prone to inconsistencies in execution order or semantic fragmentation between multi-view representations, leading to multi-view... Figure 1 Poor consistency. Summary of the Invention

[0005] The main objective of this application is to provide a code conversion method, apparatus, device, storage medium, and product, aiming to solve the problems of insufficient semantic completion accuracy and multiple views in conventional technologies when converting code from graphical models to target code. Figure 1 Technical issues related to poor consistency.

[0006] To achieve the above objectives, this application proposes a code conversion method, which includes: Obtain model description information from the source modeling environment, and construct an intermediate representation expressing component relationships and data dependencies based on the model description information; For the incomplete description in the intermediate representation, semantic structure completion is performed using a preset large model to obtain an enhanced intermediate representation; The execution order is determined based on the data dependencies in the enhanced intermediate representation; When a preset association pattern is detected between a condition control class component and a branch substructure, the condition control class component and the branch substructure are merged into a fusion structure, and the execution order is adjusted. Based on the adjusted execution order and the fusion structure, target code and interchangeable intermediate files are generated for the target engineering environment.

[0007] In one embodiment, the step of constructing an intermediate representation of the relationships and data dependencies of the expressed components based on the model description information includes: Based on the component port attributes in the model description information, identify input ports and output ports; Direct the connection from the output port to the input port as a directed data dependency edge; For a subsystem class composite block, obtain the inner graph class, recursively extract the inner graph class to obtain the inner components and inner connections, so as to construct a subsystem graph set indexed by instance name; An intermediate representation is constructed by combining the top-level component set, the directed data dependency edges, and the subsystem graph set indexed by instance name.

[0008] In one embodiment, the step of performing semantic structure completion using a preset large model includes: Extract the type path, parameter key values, and annotation text from the intermediate representation and use them as input to the large model; Obtain the structured completion information output by the large model, wherein the template format of the structured completion information is consistent with the template format of the intermediate representation fields; Perform syntax validation and confidence filtering on the structured completion information; The filtered structured completion information is written into the intermediate representation to obtain the enhanced intermediate representation, thereby completing the semantic structure completion.

[0009] In one embodiment, the step of merging the condition control class component and the branch substructure into a fusion structure includes: When the condition control class component is a condition branch block, condition expression fragments are extracted from the annotations or parameters of the condition branch block, and the condition expression fragments are normalized to obtain the completed branch conditions. When the condition control component is a multi-branch selection block, extract the selection expression; Replace the variable references in the completed branch conditions or the selection expressions with the actual variable paths on the data flow; Based on the replaced and completed branch conditions or selection expressions, a structured statement for calling inline subsystem function blocks is generated. Based on the structured statement, the original condition control components and branch substructures are replaced to form the fusion structure.

[0010] In one embodiment, the step of adjusting the execution order includes: Based on the data dependencies in the enhanced intermediate representation, a component dependency graph is constructed; Based on the component dependency graph, identify the missing data dependencies between the condition control component and its preceding data preparation component; Based on the missing data dependency, a composite edge is added to the component dependency graph, pointing from the pre-data preparation component to the condition control class component. The execution order is adjusted based on the component dependency graph after adding composite edges.

[0011] In one embodiment, the step of generating target code and interchangeable intermediate files for the target engineering environment includes: Based on the adjusted execution order and the fusion structure, a structured text program body is generated, and the structured text program body is set as the target code; Based on the structured text program, a ladder diagram extensible markup language file is generated, and a structured text fragment consistent with the target code is embedded in the fusion network position of the ladder diagram extensible markup language file; Based on the structured text program, a scalable vector graphics file of a trapezoidal diagram is generated. According to the type of the fusion structure, the ladder layout parameters corresponding to the scalable vector graphics file of the trapezoidal diagram are adjusted to accommodate the embedded structured text preview area. An interchangeable intermediate file is generated based on the ladder diagram extensible markup language file after the embedding operation and the ladder diagram scalable vector graphics file after the adjustment operation. The target code and the interchangeable intermediate file share the adjusted execution order and fusion structure semantics.

[0012] Furthermore, to achieve the above objectives, this application also proposes a code conversion apparatus, the code conversion apparatus comprising: The acquisition module is used to acquire model description information from the source modeling environment and construct an intermediate representation expressing component relationships and data dependencies based on the model description information. The completion module is used to complete the semantic structure of the incomplete description parts in the intermediate representation using a preset large model to obtain an enhanced intermediate representation; A determination module is used to determine the execution order based on the data dependencies in the enhanced intermediate representation; The adjustment module is used to merge the condition control component and the branch substructure into a fusion structure and adjust the execution order when a preset association pattern is detected between the condition control component and the branch substructure. The conversion module is used to generate target code and interchangeable intermediate files for the target engineering environment based on the adjusted execution order and the fusion structure.

[0013] In addition, to achieve the above objectives, this application also proposes a code conversion device, the device comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor, the computer program being configured to implement the steps of the code conversion method as described above.

[0014] In addition, to achieve the above objectives, this application also proposes a storage medium, which is a computer-readable storage medium, on which a computer program is stored, and which, when executed by a processor, implements the steps of the code conversion method described above.

[0015] In addition, to achieve the above objectives, this application also provides a computer program product, which includes a computer program that, when executed by a processor, implements the steps of the code conversion method described above.

[0016] One or more technical solutions proposed in this application have at least the following technical effects: Compared to related technologies that rely on pure rule mapping leading to insufficient semantic completion accuracy and fail to fuse conditional structures resulting in fragmented semantics across multiple views, this application obtains model description information from the source-side modeling environment. Based on this information, it constructs an intermediate representation expressing component relationships and data dependencies. For incomplete descriptions in this intermediate representation, it uses a pre-defined large model to complete the semantic structure. When a pre-defined association pattern is identified between conditional control components and branch substructures, these are merged into a fusion structure, and the execution order is adjusted. Finally, target code and exchangeable intermediate files are generated. It is understood that when incomplete descriptions exist in the intermediate representation, the large model extracts structured completion information from type paths, parameter keys, and annotation text to achieve semantic completion. Therefore, based on enhanced data dependencies, an accurate execution order can be determined. Furthermore, when conditional control components and branch substructures satisfy a pre-defined association pattern, the adjusted execution order is determined by merging them into a fusion structure and applying composition constraints. Ultimately, the target code and the exchangeable intermediate files share the same execution order and fusion semantics, solving the problems of insufficient semantic completion accuracy and fragmented semantics across multiple views. Figure 1 Technical issues related to poor consistency. Attached Figure Description

[0017] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.

[0018] To more clearly illustrate the technical solutions in the embodiments of this application or related technologies, the accompanying drawings used in the description of the embodiments or related technologies will be briefly introduced below. Obviously, for those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0019] Figure 1 This is a flowchart illustrating an embodiment of the code conversion method of this application. Figure 2 This is a flowchart illustrating Embodiment 2 of the code conversion method of this application; Figure 3 This is a flowchart illustrating Embodiment 3 of the code conversion method of this application; Figure 4 This is a schematic diagram of the module structure of the code conversion device according to an embodiment of this application; Figure 5 This is a schematic diagram of the device structure of the hardware operating environment involved in the code conversion method in this application embodiment.

[0020] The purpose, features, and advantages of this application will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. Detailed Implementation

[0021] It should be understood that the specific embodiments described herein are merely illustrative of the technical solutions of this application and are not intended to limit this application.

[0022] To better understand the technical solution of this application, a detailed description will be provided below in conjunction with the accompanying drawings and specific implementation methods.

[0023] The main solution in this application embodiment is: Obtain model description information from the source modeling environment, and construct an intermediate representation expressing component relationships and data dependencies based on the model description information; For the incomplete description in the intermediate representation, semantic structure completion is performed using a preset large model to obtain an enhanced intermediate representation; The execution order is determined based on the data dependencies in the enhanced intermediate representation; When a preset association pattern is detected between a condition control class component and a branch substructure, the condition control class component and the branch substructure are merged into a fusion structure, and the execution order is adjusted. Based on the adjusted execution order and the fusion structure, target code and interchangeable intermediate files are generated for the target engineering environment.

[0024] In this embodiment, the application uses a code conversion device as the execution subject. For ease of description, it will be referred to as "device" in detail below.

[0025] In related technologies, when converting graphical models to target code, incomplete model description information makes it difficult for pure rule mapping to accurately restore missing semantics, leading to conversion interruption or incorrect code generation. At the same time, when there are conditional control components and multiple branch substructures in the model, related technologies usually generate independent conditional statements and branch function blocks, resulting in deviations in control flow and data flow between the target code and the exchangeable intermediate file, making it difficult to maintain consistency in multi-view semantics.

[0026] This application provides a solution that unifies the model structure into a traceable directed dependency form by constructing an intermediate representation that carries data dependencies. A pre-defined large model is introduced to semantically complete incomplete descriptions in the intermediate representation, standardizing and filling in ambiguous or missing key information. Based on this, the execution order is determined according to the completed data dependencies, and conditional control components and branch substructures that satisfy a pre-defined association pattern are merged, consolidating scattered conditions and branches into unified structured statements. Simultaneously, composition constraints are applied to the execution order to eliminate the risk of unassigned variables being referenced. Finally, based on the same execution order and fused structure, target code and exchangeable intermediate files are generated synchronously, ensuring that the target code and exchangeable intermediate files are strictly homologous in control logic and data flow semantics. This improves the semantic completion accuracy of the conversion from the graphical model to the target code and enhances multi-view processing. Figure 1 To the point of being responsive.

[0027] Based on this, embodiments of this application provide a code conversion method, referring to... Figure 1 , Figure 1 This is a flowchart illustrating the first embodiment of the code conversion method of this application.

[0028] In this embodiment, the code conversion method includes steps S10 to S50: Step S10: Obtain model description information from the source modeling environment, and construct an intermediate representation expressing component relationships and data dependencies based on the model description information; It should be noted that the source-side modeling environment includes, but is not limited to, a simulation modeling platform that supports graphical component drag-and-drop and connection operations. The model description information includes, but is not limited to, a list of component instances, component port attributes, connection relationships between components, and inner graph class references of subsystem class composite blocks. The component relationship refers to the directed data transfer association formed between components through port connections, and the data dependency refers to the unidirectional dependency relationship where the output of the production-side component serves as the input of the consumer-side component. The intermediate representation includes, but is not limited to, a top-level component set organized in a tree structure, a set of directed data dependency edges, and a set of subsystem graphs indexed by instance name.

[0029] Understandably, this step extracts the scattered components and connection information in the graphical model into a structured intermediate representation, making the data dependencies that were originally implicit in the graphical layout explicit, and providing a unified data foundation for subsequent semantic completion, execution order determination and fusion processing.

[0030] Step S20: For the incomplete description part in the intermediate representation, semantic structure completion is performed using a preset large model to obtain an enhanced intermediate representation; It should be noted that the incomplete description includes, but is not limited to, abbreviated text, non-key-value annotation fields, unrecognized type paths due to version changes, or missing conditional expression fragments. The pre-set large model includes, but is not limited to, pre-trained or pre-configured large language models, as well as composite models formed by combining the large language model with the retrieval enhancement generation module. Semantic structure completion refers to extracting standardized structured information from unstructured or semi-structured text and mapping it to the corresponding fields of the intermediate representation. The enhanced intermediate representation refers to the intermediate representation where, after semantic completion, the incomplete fields have been standardized and corrected.

[0031] Understandably, this step leverages the semantic understanding capabilities of large models to intelligently fill in ambiguous or missing parts of the model description information, overcoming the limitations of pure rule mapping in dealing with variable or incomplete inputs, and improving the completeness of intermediate representations and the reliability of subsequent processing.

[0032] Step S30: Determine the execution order based on the data dependencies in the enhanced intermediate representation; It should be noted that the data dependencies are recorded in the enhanced intermediate representation as directed edges, with each directed edge pointing from the producer component to the consumer component. The execution order refers to the order in which the code blocks or function blocks corresponding to each component are called in the target program. This order must ensure that the prerequisite data that any component depends on is ready when it is executed.

[0033] Understandably, this step transforms the data dependencies between components into a deterministic execution order through topological sorting, ensuring that unassigned variables are not referenced during runtime in the subsequently generated target code, thus guaranteeing the correctness of the code logic.

[0034] Step S40: When a preset association pattern is detected between the condition control class component and the branch substructure, the condition control class component and the branch substructure are merged into a fusion structure, and the execution order is adjusted. It should be noted that the condition control components include, but are not limited to, conditional branch blocks and multi-branch selection blocks. The branch substructure refers to a set of subsystem function blocks selected for execution under different conditions. The preset association mode includes, but is not limited to, a connection mode where the enable output of each branch of the condition control component is uniquely connected to the corresponding subsystem action port. The fusion structure refers to merging the originally scattered condition judgment statements and branch subsystem calls into a single inline structured control statement, such as an inline conditional selection statement or a multi-branch selection statement. Adjusting the execution order refers to adding composite edges to the dependency graph so that the condition control components are executed after the preceding data preparation components they depend on.

[0035] Understandably, this step merges scattered conditions and branches into a unified fusion structure, reducing the introduction of intermediate flags and multiple independent conditional statements. At the same time, the synthesis edge constraint ensures that the fusion structure is executed at the correct time, avoiding data reference errors caused by improper execution order.

[0036] Step S50: Based on the adjusted execution order and the fusion structure, generate target code and interchangeable intermediate files for the target end engineering environment.

[0037] It should be noted that the target-side engineering environment includes, but is not limited to, a development and runtime environment supporting the programmable logic controller (PLC) programming standard, and the target code includes, but is not limited to, a structured text program body conforming to the PLC programming standard. The exchangeable intermediate files include, but are not limited to, ladder diagram extensible markup language (TLD) files and ladder diagram scalable vector graphics (LSD) files. These exchangeable intermediate files are used to transfer the program's structure and logic information between different toolchains. The exchangeable intermediate files embed a structured text fragment consistent with the target code at the fusion network location, and both share the adjusted execution order and fusion structural semantics.

[0038] Understandably, this step generates multiple types of artifacts simultaneously based on a single execution order and fusion structure, ensuring that the target code and the interchangeable intermediate files are strictly homologous in terms of control logic and data flow semantics. This avoids semantic fragmentation of the same model across different views, facilitating direct deployment or secondary processing in the target-side engineering chain.

[0039] This embodiment provides a code conversion method. When incomplete descriptions exist in the intermediate representation, structured completion information is extracted from type paths, parameter keys, and annotation text using the large model to achieve semantic completion. Therefore, based on enhanced data dependencies, an accurate execution order can be determined. Furthermore, when conditional control components and branch substructures satisfy a preset association pattern, the adjusted execution order is determined by merging them into a fusion structure and applying composition constraints. Ultimately, the target code and the interchangeable intermediate file share the same execution order and fusion semantics, solving the problems of insufficient accuracy in semantic completion and multiple views. Figure 1 Technical issues related to poor consistency.

[0040] In one feasible implementation, the step of constructing an intermediate representation of the relationships and data dependencies of the expressed components based on the model description information includes: Based on the component port attributes in the model description information, identify input ports and output ports; Direct the connection from the output port to the input port as a directed data dependency edge; For a subsystem class composite block, obtain the inner graph class, recursively extract the inner graph class to obtain the inner components and inner connections, so as to construct a subsystem graph set indexed by instance name; An intermediate representation is constructed by combining the top-level component set, the directed data dependency edges, and the subsystem graph set indexed by instance name.

[0041] It should be noted that the component port attributes include, but are not limited to, port type identifiers, direction identifiers, or name characteristics, used to distinguish whether a port is an input port for receiving data or an output port for sending data. The directed data dependency edge refers to a unidirectional connection from an output port to an input port, used to express the dependency relationship of data flowing from the production end to the consumption end. The subsystem class composite block includes, but is not limited to, user-defined subsystem encapsulation blocks, which appear as a whole in the graphical model but contain nested components and connections. The inner graph class refers to the subgraph type definition referenced within the subsystem class composite block. The recursive extraction refers to expanding the nested multi-layered subsystem layer by layer, obtaining the component instances and connection relationships within each layer, until no more subsystem class composite blocks are contained. The subsystem graph set indexed by instance name refers to a set storing the corresponding inner subgraph structure using the name of each subsystem instance as the index key, facilitating quick location when referenced at the top level.

[0042] Understandably, this implementation method clarifies the direction of data flow by identifying port attributes, thus avoiding the ambiguity caused by undirected connections. At the same time, by recursively extracting the internal structure of subsystems, the information of originally nested and closed subsystems is flattened into a unified intermediate representation, making the full-level structure of the model transparent and visible to subsequent processing, and ensuring the integrity of data dependencies.

[0043] For example, refer to Figure 2 This process corresponds to the structured extraction of scattered component and connection information from the graphical modeling environment into a unified intermediate representation. First, based on the component port attributes in the model description information, input and output ports are distinguished. Next, the connections are normalized into directed data dependency edges pointing from output ports to input ports. Simultaneously, subsystem class composite blocks are recursively expanded, extracting nested components and connections layer by layer. Finally, all extraction results—the top-level component set, the directed data dependency edge set, and the inner graph set indexed by subsystem instance name—are uniformly organized into a tree-structured intermediate representation for subsequent semantic completion and execution order analysis.

[0044] In one feasible implementation, the step of using a preset large model for semantic structure completion includes: Extract the type path, parameter key values, and annotation text from the intermediate representation and use them as input to the large model; Obtain the structured completion information output by the large model, wherein the template format of the structured completion information is consistent with the template format of the intermediate representation fields; Perform syntax validation and confidence filtering on the structured completion information; The filtered structured completion information is written into the intermediate representation to obtain the enhanced intermediate representation, thereby completing the semantic structure completion.

[0045] It should be noted that the type path includes, but is not limited to, the complete namespace path or type identifier of the component in the model library, used to indicate the category to which the component belongs. The parameter key-value pairs include, but are not limited to, the name and corresponding value pairs of component configuration parameters. The annotation text includes, but is not limited to, comment strings, abbreviations, or conditional expression fragments embedded in annotation fields added by engineers for the component. The structured completion information refers to the set of standardized fields output by the large model after analyzing the input information, which follows a preset template, and whose field names and data types are consistent with the corresponding fields in the intermediate representation. The preset template format consistent with the intermediate representation fields refers to a predefined template structure, which specifies the naming, hierarchy, and value constraints of each field in the output result of the large model, to ensure that the output can be directly interfaced with the intermediate representation. The syntax validation includes, but is not limited to, checking the field type, value range, and completeness of required fields of the structured completion information. The confidence filtering refers to comparing the confidence score output by the large model with a preset threshold, retaining the structured completion information with a confidence score not lower than the preset threshold, and discarding the part lower than the preset threshold.

[0046] Understandably, this implementation extracts multi-source textual information from the intermediate representation as input to the large model, enabling the large model to perform semantic reasoning by integrating component types, parameter configurations, and human annotations, thus improving the accuracy of completion. Simultaneously, through triple safeguards of template constraints, syntax validation, and confidence filtering, the output of the large model is limited to a controllable range, avoiding the risks associated with unverified information directly entering the intermediate representation, thus balancing the flexibility of completion with engineering reliability.

[0047] In one feasible implementation, the step of merging the condition control class component and the branch substructure into a fusion structure includes: When the condition control class component is a condition branch block, condition expression fragments are extracted from the annotations or parameters of the condition branch block, and the condition expression fragments are normalized to obtain the completed branch conditions. When the condition control component is a multi-branch selection block, extract the selection expression; Replace the variable references in the completed branch conditions or the selection expressions with the actual variable paths on the data flow; Based on the replaced and completed branch conditions or selection expressions, a structured statement for calling inline subsystem function blocks is generated. Based on the structured statement, the original condition control components and branch substructures are replaced to form the fusion structure.

[0048] It should be noted that the conditional branch block includes, but is not limited to, two- or multi-branch conditional components representing if-or-other logic in the model, whose annotations or parameters may contain embedded expression text defining the branch judgment logic. The conditional expression fragment refers to a text segment describing the branch triggering condition separated from the annotation fields or parameter values ​​of the conditional branch block, and may exist in abbreviated or non-standard forms. The normalization process includes, but is not limited to, expanding abbreviated operator names, correcting non-standard syntax, and supplementing missing comparison operators. The completed branch condition refers to a standard conditional expression obtained after the normalization process that can be directly used for code generation. The multi-branch selection block includes, but is not limited to, switches or selector components representing multi-way selection logic in the model, whose selection expression is used to determine which branch to execute. The branch enable output refers to the output port of the multi-branch selection block corresponding to each branch, whose output signal is used to trigger the corresponding branch's subsystem. The subsystem action port refers to the input port in the branch subsystem that receives the enable or trigger signal. Binding the selection expression to each branch action port means establishing a mapping relationship between the selection expression value and the corresponding branch port, so that different values ​​correspond to the triggering of different branch subsystems. The actual variable path refers to the complete access path of the output variable or intermediate variable of the preceding component determined on the data flow, used to replace placeholders or abbreviated variable names in the expression. The inline subsystem function block call refers to embedding a subsystem function block that was originally called independently outside the branch into the execution body of the condition or selection statement for direct call.

[0049] Understandably, this implementation provides a complete processing chain for two common control modes: conditional branch blocks and multi-branch selection blocks. This chain involves extracting semantics from annotations or parameters, standardizing expressions, binding branch ports, replacing variable paths, and finally generating the fused statement. By consolidating the control logic, originally scattered across multiple independent paragraphs, into a single structured statement, the redundancy of intermediate flags and logical jumps caused by segmented generation is eliminated. Simultaneously, variable references are mapped to actual data paths, ensuring that the fused structure is semantically strictly consistent with the data flow of the original model.

[0050] For example, refer to Figure 3 , Figure 3This paper illustrates a process for merging conditional control components and branch substructures according to a feasible embodiment of this application. This process targets two common control structures in graphical models: conditional branch blocks and multi-branch selection blocks. It consolidates the conditional judgments and branch call logic, originally scattered across multiple independent sections, into a unified structured statement. When a conditional control component is identified as a conditional branch block, conditional expression fragments are extracted from its annotations or parameters and normalized to obtain the completed branch conditions. When identified as a multi-branch selection block, selection expressions are extracted, and the unique correspondence between each branch enable output and the subsystem action port is verified, completing the binding of selection expressions and branch ports. Subsequently, variable references in the branch conditions or selection expressions are replaced to point to the actual variable paths in the data flow. Finally, based on the replaced and completed branch conditions or selection expressions, a structured statement for inline subsystem function block calls is generated. Based on this structured statement, the original conditional control components and branch substructures are replaced to form a merged structure. This merged structure eliminates the intermediate flag bits and logical jump redundancy introduced by segmented generation, ensuring strict consistency between the control logic and the original model data flow.

[0051] In one feasible implementation, the step of adjusting the execution order includes: Based on the data dependencies in the enhanced intermediate representation, a component dependency graph is constructed; Based on the component dependency graph, identify the missing data dependencies between the condition control component and its preceding data preparation component; Based on the missing data dependency, a composite edge is added to the component dependency graph, pointing from the pre-data preparation component to the condition control class component. The execution order is adjusted based on the component dependency graph after adding composite edges.

[0052] It should be noted that the component dependency graph refers to a directed acyclic graph constructed with components as nodes and directed data dependency edges as edges, used to express the data production and consumption relationships between components. The pre-processing data components include, but are not limited to, computational components or data source components that provide the necessary variable values ​​for the condition control components before their execution. The missing data dependency refers to a situation where a data usage relationship exists between the condition control components and the pre-processing data components, but the corresponding directed edge is missing in the component dependency graph, causing the condition control components to be ranked before their data source components when sorted according to the original topology. The composite edge refers to a directed dependency edge that is not derived from the original model connection relationship, but is added by this implementation to ensure execution correctness. The dependency graph after adding composite edges refers to the complete constraint graph obtained by adding composite edges to the original data dependency relationship. The re-determining of the execution order refers to performing a topological sort again on the dependency graph after adding composite edges to generate an execution order that conforms to all original dependencies and composite dependencies.

[0053] Understandably, this implementation method, by constructing a component dependency graph and explicitly representing implicit execution order constraints as composite edges, corrects the order errors that might occur due to incomplete coverage of execution dependencies by the original model's connections. Especially after merging condition control components with branch substructures, composite edges ensure that the merged structure is executed only after all its dependent data is ready, eliminating the risk of unassigned variables being prematurely referenced and guaranteeing the logical correctness of the generated code at runtime.

[0054] In one feasible implementation, the step of generating target code and interchangeable intermediate files for the target engineering environment includes: Based on the adjusted execution order and the fusion structure, a structured text program body is generated, and the structured text program body is set as the target code; Based on the structured text program, a ladder diagram extensible markup language file is generated, and a structured text fragment consistent with the target code is embedded in the fusion network position of the ladder diagram extensible markup language file; Based on the structured text program, a scalable vector graphics file of a trapezoidal diagram is generated. According to the type of the fusion structure, the ladder layout parameters corresponding to the scalable vector graphics file of the trapezoidal diagram are adjusted to accommodate the embedded structured text preview area. An interchangeable intermediate file is generated based on the ladder diagram extensible markup language file after the embedding operation and the ladder diagram scalable vector graphics file after the adjustment operation. The target code and the interchangeable intermediate file share the adjusted execution order and fusion structure semantics.

[0055] It should be noted that the structured text program body refers to the complete program code conforming to the structured text language specification in the programmable logic controller (PLC) programming standard, including the variable declaration area and the statement body arranged according to the adjusted execution order. The ladder diagram extensible markup language file refers to a ladder diagram description file conforming to the PLC interchangeable format specification, which records the network structure, component instances, and connection relationships of the ladder diagram in extensible markup language format. The fused network position refers to the location of the network or ladder step corresponding to the fused structure in the ladder diagram extensible markup language file. This position originally needs to be expanded into multiple independent networks, which are then merged into a single network node carrying structured semantics after fusion processing. The structured text fragment consistent with the target code refers to a structured text statement segment extracted from or synchronously generated from the target code that corresponds to the fused structure. This fragment is bound to the ladder diagram network as a comment or embedded text. The ladder diagram scalable vector graphics file refers to a ladder diagram vector graphics file used for graphical preview or document output, whose ladder step layout dynamically adapts to the scale of the fused structure. The ladder step layout parameters include, but are not limited to, ladder step height, branch spacing, and embedded text display area size. The embedded structured text preview area refers to the text display area reserved within the corresponding rung of the ladder diagram vector image, used to directly present structured text fragments logically equivalent to the ladder diagram. The exchangeable intermediate files include, but are not limited to, the ladder diagram extensible markup language file and the ladder diagram scalable vector graphics file, both of which can be imported, parsed, or displayed by the target-side engineering toolchain. Sharing the adjusted execution order and fusion structure semantics means that the statement order in the target code, the network order in the ladder diagram extensible markup language file, and the rung order in the ladder diagram scalable vector graphics file all originate from the same execution order, and the logical expression of all three at the fusion network position originates from the same fusion structure, with no semantic deviation.

[0056] It is understood that this implementation method, when generating multiple types of artifacts, always uses the same adjusted execution order and fusion structure as the sole data source, ensuring strict consistency in control flow and data flow semantics between the target code, the extensible markup language description file, and the vector graphics preview file from the source. By embedding the structured text fragments corresponding to the fusion structure into the ladder diagram description file and the graphics preview, the presentation of the same control logic in different views corroborates each other, eliminating the semantic fragmentation of multiple views caused by separate conversions or manual splicing, and facilitating direct deployment, verification, and secondary processing in the target-side engineering chain.

[0057] For example, the code conversion method of this application embodiment generally includes an intermediate representation construction stage, a semantic enhancement stage, an execution order determination stage, a fusion processing stage, and a multi-format generation stage.

[0058] During the intermediate representation construction phase, model description information from the source modeling environment is obtained. The source modeling environment includes, but is not limited to, simulation modeling platforms that support graphical component drag-and-drop and connection operations, such as the Modelica (Modelica, a multi-domain unified modeling language) environment or the Sysblock (Sysplorer Embedded Coder, a system embedded encoder) component library environment. Model description information includes a list of component instances and connection relationships under the current model class. For references at both ends of connections, resolution and orientation are performed, identifying the attributes of input and output ports. Connections from output ports to input ports are oriented as directed data dependency edges, forming a data flow expression with a producer-to-consumer standard. For user subsystem class composite blocks, their inner graph classes are located through type lookup. Inner components and connections of nested subsystems are recursively extracted, and each layer of subgraphs is organized into a tree structure as a unified intermediate representation. This intermediate representation includes a top-level block set, a connection set, and a subsystem graph set indexed by instance name. As a result, the data dependencies that were originally implicit in the graphical layout are made explicit as structured data, providing a unified foundation for subsequent processing.

[0059] During the semantic enhancement phase, incomplete descriptions in the intermediate representation are completed. These incomplete descriptions may include metadata in the form of abbreviated text, annotation fields, or partial strings returned by the software development kit (SDK), such as unrecognized or missing information when type paths change between versions or when block parameters are embedded in annotations in non-key-value form. One or more of the following information are submitted to the pre-defined large model: the block's type path, parameter keys and abbreviations or full-text annotations; fragments of conditional expressions extracted from annotations; user-defined control intentions or naming conventions in natural language; and explanatory text for the target programmable controller dialect or vendor-extended constraints. The pre-defined large model produces structured results in a controlled output mode, such as completing or normalizing conditional expressions, mapping non-standard abbreviations to internal standard operator names, generating placeholder mapping templates or parameter lists for unrecognized blocks, or generating mapping candidates for subsequent rule engine merging. The structured output results, using a pre-defined template format consistent with the intermediate representation fields, are written back to the intermediate representation after syntax validation and confidence filtering to obtain the enhanced intermediate representation. Syntax validation can include field type checking, value range checking, and required field completeness checking; confidence filtering compares the confidence score of the large model output with a preset threshold, retaining only the portion with a confidence score not lower than the preset threshold. Thus, the semantic understanding capability of the large model is combined with formal extraction oriented towards the model graph, which not only handles fuzzy and incomplete information, but also limits the output of the large model to a controllable range.

[0060] During the execution order determination phase, a component dependency graph is constructed based on the directed data dependency edges in the enhanced intermediate representation. The component dependency graph forms a directed acyclic graph (DAG) with components as nodes and directed data dependency edges as edges. A topological sorting algorithm is used to process the component dependency graph to obtain an execution order that satisfies all data dependencies, ensuring that the prerequisite data for any component is ready before it is executed. Topological sorting can be performed using an algorithm based on decreasing in-degree.

[0061] During the fusion processing phase, condition control components and branch substructures are identified and merged. Condition control components include conditional branch blocks and multi-branch selection blocks. When a preset association pattern is detected between a conditional control component and each branch subsystem, a fused view is constructed. A typical scenario of a preset association pattern is that each branch's enable output is uniquely connected to the corresponding subsystem's action port. For conditional branch blocks, conditional expression fragments are extracted from their annotations or parameters, including ifExpr(if Expression, conditional expression, abbreviated as ifExpr) and elseifExpr(else if Expression, otherwise if expression, abbreviated as elseifExpr), etc., and the extracted fragments are normalized to obtain the completed branch conditions. For multi-branch selection blocks, the selection expression caseExpr(case Expression, selection expression, abbreviated as caseExpr) is extracted. When it is determined that each branch's enable output is uniquely connected to the corresponding subsystem's action port, the selection expression is bound to each branch's action port. The variable references in the completed branch conditions or selection expressions are replaced with actual variable paths in the data flow. Based on the replaced and completed branch conditions or selection expressions, a structured statement for inline subsystem function block calls is generated. This structured statement, in the form of a single structured conditional statement or a multi-branch selection statement, replaces the original conditional control components and branch substructures, forming a fused structure. Simultaneously, a composition constraint is applied to the component dependency graph. This involves identifying missing data dependencies between conditional control components and their preceding data preparation components, and adding composition edges from the preceding data preparation components to the conditional control components in the dependency graph. This ensures that conditional or selection blocks are placed after the relevant data preparation steps, preventing unassigned variables from being referenced. The execution order is then re-determined based on the dependency graph with added composition edges, resulting in an adjusted execution order. For cases that fail verification using the criteria, a rollback to non-fused multi-step generation is initiated, and an alarm is issued.

[0062] During the multi-format generation stage, multiple products are generated simultaneously based on the adjusted execution order and fusion structure. A structured text (ST) program body conforming to IEC 61131-3 (International Electrotechnical Commission 61131-3, Programmable Controller Programming Language Standard, abbreviated as IEC 61131-3) is generated as the target code, including a variable declaration area and statement bodies arranged in the adjusted execution order. Simultaneously, a ladder diagram extensible markup language file (LD XML) in an exchangeable format for the programmable controller is generated, embedding structured text fragments consistent with the target code at the fusion network location, ensuring consistency between the compilable core and the embedded ladder diagram annotation fragments. Simultaneously, based on the structured text program, a scalable vector graphics (SVG) file is generated, with its ladder order consistent with the fusion fragment display. The ladder layout parameters are adjusted according to the fusion structure type to accommodate the embedded structured text preview area. Multiple types of artifacts share the same execution order and fusion fragment generation function to ensure consistency based on origin.

[0063] In one optional implementation, the preset large model is a composite model formed by combining a Large Language Model (LLM) and a Retrieval-Augmented Generation (RAG) module. The RAG module can introduce reference texts from an external knowledge base related to the target programmable controller's dialect or vendor extension constraints to assist the large language model in producing structured completion information that better matches the actual deployment environment.

[0064] In one alternative implementation, during the construction of the intermediate representation, in addition to directional identification through component port attributes, the preset signal flow information in the component type metadata can also be used to assist in the determination. For example, the producer and consumer can be directly determined based on the input and output attributes declared in the component type definition.

[0065] In one alternative implementation, for the fusion processing of multi-branch selection blocks, if the selection expression involves value mapping of enumeration types, a mapping table of enumeration values ​​to branch ports can be pre-built, and binding can be completed by looking up the table, so as to reduce the dependence on large model completion and improve processing speed.

[0066] In one alternative implementation, the interchangeable intermediate file also includes a Structured Text XML (ST XML) file conforming to the Programmable Controller Interchangeable Format specification. The compilable kernel embedded in this file is consistent with the target code, making it easy to import directly into an integrated development environment that supports the Programmable Controller Interchangeable Format.

[0067] It should be noted that the above examples are only for understanding this application and do not constitute a limitation on the code conversion method of this application. Any simple transformations based on this technical concept are all within the protection scope of this application.

[0068] This application also provides a code conversion device, please refer to... Figure 4 The code conversion device includes: The acquisition module 10 is used to acquire model description information in the source modeling environment and construct an intermediate representation expressing component relationships and data dependencies based on the model description information; The completion module 20 is used to complete the semantic structure of the incomplete description part in the intermediate representation using a preset large model to obtain an enhanced intermediate representation; The determination module 30 is used to determine the execution order based on the data dependencies in the enhanced intermediate representation; The adjustment module 40 is used to merge the condition control class component and the branch substructure into a fusion structure and adjust the execution order when a preset association pattern is detected between the condition control class component and the branch substructure. The conversion module 50 is used to generate target code and interchangeable intermediate files for the target end engineering environment based on the adjusted execution order and the fusion structure.

[0069] And / or, the code conversion device includes: The first identification module is used to identify input ports and output ports based on the component port attributes in the model description information; The first orientation module is used to orient the connection from the output port to the input port as a directed data dependency edge. The first extraction module is used to obtain the inner graph class of the subsystem class composite block, and recursively extract the inner graph class to obtain the inner component and the inner connection, so as to construct a subsystem graph set indexed by instance name; The first organization module is used to construct an intermediate representation from the top-level component set, the directed data dependency edges, and the subsystem graph set indexed by instance name.

[0070] And / or, the code conversion device includes: The second extraction module is used to extract type path, parameter key value and annotation text from the intermediate representation as input to the large model; The first acquisition module is used to acquire the structured completion information output by the large model, wherein the template format of the structured completion information is consistent with the template format of the intermediate representation field; The first verification module is used to perform syntax verification and confidence filtering on the structured completion information; The first writing module is used to write the filtered structured completion information into the intermediate representation to obtain the enhanced intermediate representation, thereby completing the semantic structure completion.

[0071] And / or, the code conversion device includes: The first condition processing module is used to extract condition expression fragments from the annotations or parameters of the condition branch block when the condition control class component is a condition branch block, and to perform normalization processing on the condition expression fragments to obtain the completed branch conditions. The second condition processing module is used to extract the selection expression when the condition control class component is a multi-branch selection block; The first replacement module is used to replace the variable references in the completed branch conditions or the selection expressions with the actual variable paths on the data flow. The second generation module is used to generate a structured statement for calling inline subsystem function blocks based on the replaced and completed branch conditions or selection expressions, and to replace the original condition control components and branch substructures based on the structured statement to form the fusion structure.

[0072] And / or, the code conversion device includes: A first construction module is used to construct a component dependency graph based on the data dependencies in the enhanced intermediate representation; The second identification module is used to identify the missing data dependencies between the condition control component and its preceding data preparation component based on the component dependency graph. The first adding module is used to add a composite edge from the pre-data preparation component to the condition control class component in the component dependency graph based on the missing data dependency. The first determination module is used to adjust the execution order based on the component dependency graph after adding composite edges.

[0073] And / or, the code conversion device includes: The third generation module is used to generate a structured text program body based on the adjusted execution order and the fusion structure, and set the structured text program body as the target code; The fourth generation module is used to generate a ladder diagram extensible markup language file based on the structured text program, and embed a structured text fragment consistent with the target code at the fusion network position of the ladder diagram extensible markup language file; The fifth generation module is used to generate a scalable vector graphics file of a trapezoidal diagram based on the structured text program, and adjust the ladder layout parameters corresponding to the scalable vector graphics file of the trapezoidal diagram according to the type of the fusion structure to accommodate the embedded structured text preview area. The first output module is used to generate an interchangeable intermediate file based on the ladder diagram extensible markup language file after the embedding operation and the ladder diagram scalable vector graphics file after the adjustment operation. The target code and the interchangeable intermediate file share the adjusted execution order and fusion structure semantics.

[0074] The code conversion apparatus provided in this application, employing the code conversion method described in the above embodiments, can solve the problems of insufficient semantic completion accuracy and multiple views in conventional technologies when converting code from graphical models to target code. Figure 1 The technical problem of poor consistency. Compared with related technologies, the beneficial effects of the code conversion device provided in this application are the same as those of the code conversion method provided in the above embodiments, and other technical features in the code conversion device are the same as those disclosed in the methods of the above embodiments, and will not be repeated here.

[0075] This application provides a code conversion device, which includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the code conversion method in Embodiment 1 above.

[0076] The following is for reference. Figure 5 The diagram illustrates a structural schematic of a code conversion device suitable for implementing embodiments of this application. The code conversion device in the embodiments of this application may include, but is not limited to, mobile terminals such as mobile phones, tablets, laptops, digital broadcast receivers, PDAs (Personal Digital Assistants), PMPs (Portable Media Players), in-vehicle terminals (e.g., in-vehicle navigation terminals), and fixed terminals such as digital televisions and desktop computers. Figure 5 The code conversion device shown is merely an example and should not impose any limitation on the functionality and scope of use of the embodiments of this application.

[0077] like Figure 5As shown, the code conversion device may include a processing unit 1001 (e.g., a central processing unit, a graphics processing unit, etc.) that can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 1002 or a program loaded from a storage device 1003 into a random access memory (RAM) 1004. The RAM 1004 also stores various programs and data required for the operation of the code conversion device. The processing unit 1001, ROM 1002, and RAM 1004 are interconnected via a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Typically, the following systems can be connected to the I / O interface 1006: input devices 1007 including, for example, a touchscreen, touchpad, keyboard, mouse, image sensor, microphone, accelerometer, gyroscope, etc.; output devices 1008 including, for example, a liquid crystal display (LCD), speaker, vibrator, etc.; storage devices 1003 including, for example, magnetic tape, hard disk, etc.; and communication devices 1009. Communication device 1009 allows the code conversion device to communicate wirelessly or wiredly with other devices to exchange data. Although the figure shows code conversion devices with various systems, it should be understood that implementation or possession of all the systems shown is not required. More or fewer systems may be implemented alternatively.

[0078] Specifically, according to the embodiments disclosed in this application, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments disclosed in this application include a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via a communication device, or installed from storage device 1003, or installed from ROM 1002. When the computer program is executed by processing device 1001, it performs the functions defined in the methods of the embodiments disclosed in this application.

[0079] The code conversion device provided in this application, employing the code conversion method described in the above embodiments, can solve the problems of insufficient semantic completion accuracy and multiple views in conventional technologies when converting code from graphical models to target code. Figure 1 The technical problem of poor consistency. Compared with related technologies, the beneficial effects of the code conversion device provided in this application are the same as those of the code conversion method provided in the above embodiments, and other technical features in the code conversion device are the same as those disclosed in the method of the previous embodiment, and will not be repeated here.

[0080] It should be understood that the various parts disclosed in this application can be implemented using hardware, software, firmware, or a combination thereof. In the description of the above embodiments, specific features, structures, materials, or characteristics can be combined in any suitable manner in one or more embodiments or examples.

[0081] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.

[0082] This application provides a computer-readable storage medium having computer-readable program instructions (i.e., a computer program) stored thereon, the computer-readable program instructions being used to execute the code conversion method described in the above embodiments.

[0083] The computer-readable storage medium provided in this application may be, for example, a USB flash drive, but is not limited to, electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices, or any combination thereof. More specific examples of computer-readable storage media may include, but are not limited to: electrical connections having one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof. In this embodiment, the computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, system, or device. The program code contained on the computer-readable storage medium may be transmitted using any suitable medium, including but not limited to: wires, optical cables, RF (Radio Frequency), etc., or any suitable combination thereof.

[0084] The aforementioned computer-readable storage medium may be included in the code conversion device; or it may exist independently and not be assembled into the code conversion device.

[0085] The aforementioned computer-readable storage medium carries one or more programs, which, when executed by the code conversion device, cause the code conversion device to: acquire model description information from the source modeling environment, and construct an intermediate representation expressing component relationships and data dependencies based on the model description information; For the incomplete description in the intermediate representation, semantic structure completion is performed using a preset large model to obtain an enhanced intermediate representation; The execution order is determined based on the data dependencies in the enhanced intermediate representation; When a preset association pattern is detected between a condition control class component and a branch substructure, the condition control class component and the branch substructure are merged into a fusion structure, and the execution order is adjusted. Based on the adjusted execution order and the fusion structure, target code and interchangeable intermediate files are generated for the target engineering environment.

[0086] Computer program code for performing the operations of this application can be written in one or more programming languages ​​or a combination thereof, including object-oriented programming languages ​​such as Java, Smalltalk, and C++, and conventional procedural programming languages ​​such as the "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network—including a Local Area Network (LAN) or a Wide Area Network (WAN)—or can be connected to an external computer (e.g., via the Internet using an Internet service provider).

[0087] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of this application. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.

[0088] The modules described in the embodiments of this application can be implemented in software or hardware. The names of the modules do not necessarily limit the functionality of the unit itself.

[0089] The readable storage medium provided in this application is a computer-readable storage medium, which stores computer-readable program instructions (i.e., a computer program) for executing the above-described code conversion method. This addresses the shortcomings of conventional techniques in semantic completion accuracy and multi-view issues during the conversion from graphical models to target-side code. Figure 1 The technical problem of poor consistency. Compared with related technologies, the beneficial effects of the computer-readable storage medium provided in this application are the same as the beneficial effects of the code conversion method provided in the above embodiments, and will not be repeated here.

[0090] This application also provides a computer program product, including a computer program that, when executed by a processor, implements the steps of the code conversion method described above.

[0091] The computer program product provided in this application can solve the problems of insufficient semantic completion accuracy and multiple views in conventional technologies when converting from graphical models to target code. Figure 1 The technical problem of poor consistency. Compared with related technologies, the beneficial effects of the computer program product provided in this application are the same as the beneficial effects of the code conversion method provided in the above embodiments, and will not be repeated here.

[0092] All acquisition of signals, information, or actions in this application are carried out in compliance with the relevant data protection laws and policies of the country where the application is located, and with the authorization of the relevant device owner.

[0093] The above description is only a part of the embodiments of this application and does not limit the scope of protection of this application. All equivalent structural transformations made under the technical concept of this application and using the content of this application specification and drawings, or direct / indirect applications in other related technical fields, are included in the scope of protection of this application.

Claims

1. A code conversion method, characterized in that, The method includes: Obtain model description information from the source modeling environment, and construct an intermediate representation expressing component relationships and data dependencies based on the model description information; For the incomplete description in the intermediate representation, semantic structure completion is performed using a preset large model to obtain an enhanced intermediate representation; The execution order is determined based on the data dependencies in the enhanced intermediate representation; When a preset association pattern is detected between a condition control class component and a branch substructure, the condition control class component and the branch substructure are merged into a fusion structure, and the execution order is adjusted. Based on the adjusted execution order and the fusion structure, target code and interchangeable intermediate files are generated for the target end engineering environment; The steps for generating target code and exchangeable intermediate files for the target engineering environment include: Based on the adjusted execution order and the fusion structure, a structured text program body is generated, and the structured text program body is set as the target code; Based on the structured text program, a ladder diagram extensible markup language file is generated, and a structured text fragment consistent with the target code is embedded in the fusion network position of the ladder diagram extensible markup language file; Based on the structured text program, a scalable vector graphics file of a trapezoidal diagram is generated. According to the type of the fusion structure, the ladder layout parameters corresponding to the scalable vector graphics file of the trapezoidal diagram are adjusted to accommodate the embedded structured text preview area. An interchangeable intermediate file is generated based on the ladder diagram extensible markup language file after the embedding operation and the ladder diagram scalable vector graphics file after the adjustment operation. The target code and the interchangeable intermediate file share the adjusted execution order and fusion structure semantics.

2. The method according to claim 1, characterized in that, The step of constructing an intermediate representation of the relationships and data dependencies of the components based on the model description information includes: Based on the component port attributes in the model description information, identify input ports and output ports; Direct the connection from the output port to the input port as a directed data dependency edge; For a subsystem class composite block, obtain the inner graph class, recursively extract the inner graph class to obtain the inner components and inner connections, so as to construct a subsystem graph set indexed by instance name; An intermediate representation is constructed by combining the top-level component set, the directed data dependency edges, and the subsystem graph set indexed by instance name.

3. The method according to claim 1, characterized in that, The steps for semantic structure completion using a pre-defined large model include: Extract the type path, parameter key values, and annotation text from the intermediate representation and use them as input to the large model; Obtain the structured completion information output by the large model, wherein the template format of the structured completion information is consistent with the template format of the intermediate representation fields; Perform syntax validation and confidence filtering on the structured completion information; The filtered structured completion information is written into the intermediate representation to obtain the enhanced intermediate representation, thereby completing the semantic structure completion.

4. The method according to claim 1, characterized in that, The step of merging the condition control class component and the branch substructure into a fusion structure includes: When the condition control class component is a condition branch block, condition expression fragments are extracted from the annotations or parameters of the condition branch block, and the condition expression fragments are normalized to obtain the completed branch conditions. When the condition control component is a multi-branch selection block, extract the selection expression; Replace the variable references in the completed branch conditions or the selection expressions with the actual variable paths on the data flow; Based on the replaced and completed branch conditions or selection expressions, a structured statement for calling inline subsystem function blocks is generated. Based on the structured statement, the original condition control components and branch substructures are replaced to form the fusion structure.

5. The method according to claim 1, characterized in that, The step of adjusting the execution order includes: Based on the data dependencies in the enhanced intermediate representation, a component dependency graph is constructed; Based on the component dependency graph, identify the missing data dependencies between the condition control component and its preceding data preparation component; Based on the missing data dependency, a composite edge is added to the component dependency graph, pointing from the pre-data preparation component to the condition control class component. The execution order is adjusted based on the component dependency graph after adding composite edges.

6. A code conversion device, characterized in that, The device includes: The acquisition module is used to acquire model description information from the source modeling environment and construct an intermediate representation expressing component relationships and data dependencies based on the model description information. The completion module is used to complete the semantic structure of the incomplete description parts in the intermediate representation using a preset large model to obtain an enhanced intermediate representation. A determination module is used to determine the execution order based on the data dependencies in the enhanced intermediate representation; The adjustment module is used to merge the condition control component and the branch substructure into a fusion structure and adjust the execution order when a preset association pattern is detected between the condition control component and the branch substructure. The conversion module is used to generate target code and interchangeable intermediate files for the target end engineering environment based on the adjusted execution order and the fusion structure. The conversion module is also used to achieve: Based on the adjusted execution order and the fusion structure, a structured text program body is generated, and the structured text program body is set as the target code; Based on the structured text program, a ladder diagram extensible markup language file is generated, and a structured text fragment consistent with the target code is embedded in the fusion network position of the ladder diagram extensible markup language file; Based on the structured text program, a scalable vector graphics file of a trapezoidal diagram is generated. According to the type of the fusion structure, the ladder layout parameters corresponding to the scalable vector graphics file of the trapezoidal diagram are adjusted to accommodate the embedded structured text preview area. An interchangeable intermediate file is generated based on the ladder diagram extensible markup language file after the embedding operation and the ladder diagram scalable vector graphics file after the adjustment operation. The target code and the interchangeable intermediate file share the adjusted execution order and fusion structure semantics.

7. A code conversion device, characterized in that, The device includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, the computer program being configured to implement the steps of the code conversion method as described in any one of claims 1 to 5.

8. A storage medium, characterized in that, The storage medium is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, it implements the steps of the code conversion method as described in any one of claims 1 to 5.

9. A computer program product, characterized in that, The computer program product includes a computer program that, when executed by a processor, implements the steps of the code conversion method as described in any one of claims 1 to 5.

Citation Information

Patent Citations

  • Graphical code generation method, server, storage medium and program product

    CN121560307A

  • Workflow generation method and device, electronic equipment and computer program product

    CN121597255A