Synchronous data flow language translation method supporting model simulation

By modifying the input and output structure of the LustreF program and generating the context structure, the problem that existing tools cannot track local variables and initialize the input and output structure is solved, and the code generation of model simulation is realized, the development process is optimized and the code is improved.

CN120066525APending Publication Date: 2025-05-30BEIJING INST OF COMP TECH & APPL
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202510237283.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-03-02
Publication Date
2025-05-30

AI Technical Summary

Technical Problem

Existing synchronous data streaming language translation tools cannot generate code that can track local variable values ​​and initialize input and output structures in a single cycle of the program, and cannot implement model simulation.

Method used

By modifying the function input and output structure and local variable definition of the LustreF program, the local variable value is output in the form of a return value, and a context structure containing local variables and its initialization function are generated to complete the translation from LustreD to C language.

Benefits of technology

The tracking of local variable values ​​and initialization functions of input and output variables in a single clock cycle of the model are implemented, which optimizes the development process and improves the trustworthiness of the code.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120066525A_ABST
    Figure CN120066525A_ABST
Patent Text Reader

Abstract

The invention relates to a synchronous data stream language translation method supporting model simulation, and belongs to the field of code generation. In the synchronous data flow translation process, an input and output structure of a function is modified, a context structure body containing local variables is generated, and an initialization function is generated for the context structure body. Through the above steps, the generated code can realize tracking of local variable values in a single clock period of the model, and provides an initialization function of input and output variables. Compared with codes generated by a traditional method, the codes generated by the method have higher convenience and reliability during model simulation.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of code generation, and particularly relates to a method for translating synchronous data flow language that supports model simulation. Background Art

[0002] The model-based code generation technology is an advanced programming technology that can automatically generate code through models, significantly improving development efficiency and reducing human errors.

[0003] In the actual software development process, in addition to generating code that can be correctly compiled and run, the code generation tool also needs to generate code that can simulate the model. The model simulation code not only has to implement the functions of the model, but also must be able to track the local variable values of all nodes and initialize the input and output variables.

[0004] Currently, the synchronous data flow language is a commonly used source language in model-driven software development. Model-based software development tools usually convert the graph model into a synchronous data flow language program, and then convert it into other high-level language programs through a synchronous data flow language translation tool. However, existing domestic synchronous data flow language translation tools such as L2C fail to consider the model simulation requirements, and the generated code cannot track the local variables in a single cycle of the program, nor can it initialize the program input and output structure. Summary of the Invention

[0005] (1) Technical Problems to be Solved

[0006] The technical problem to be solved by the present invention is how to provide a method for translating synchronous data flow language that supports model simulation to solve the problem that the generated code cannot track the local variables in a single cycle of the program and cannot initialize the program input and output structure.

[0007] (2) Technical Solutions

[0008] To solve the above technical problems, the present invention proposes a method for translating synchronous data flow language that supports model simulation, which includes the following steps:

[0009] S1. Translate to lustreF

[0010] Use the synchronous data flow language translation tool L2C to generate a LustreF program from the Lustre program source code;

[0011] S2. Modify function output and return function local variables

[0012] Traverse the LustreF program and modify the input and output structure, local variable definition, and function call structure of the functions defined in the program so that the local variable values are output in the form of return values;

[0013] S3. Generate the context structure and its initialization function

[0014] Modify the context structure generation function so that both node and function nodes generate the same context structure; call the context structure initialization function generation tool to add the context structure initialization function to the function list; eliminate the calling method errors caused by modifying the function input and output structures; at this time, the program language is translated to LustreD;

[0015] S4. Complete the translation process

[0016] Call L2C to complete the translation process from LustreD to C language.

[0017] (III) Beneficial effects

[0018] The present invention provides a synchronous data flow language translation method supporting model simulation. The method has at least the following beneficial effects:

[0019] (1) Design a method for generating simulation code for the model, enabling the tool to simulate the model and track node local variables, thereby optimizing the development process.

[0020] (2) Develop based on L2C, with a high degree of modularity, and can quickly switch compilation options.

[0021] (3) Operate at the abstract syntax tree level in the middle translation step. The given translation tool has been formally verified, and the code has a high credibility.

[0022] (4) Add a code simulation function to the OnModel modeling platform, expanding the platform function and development practicality. Description of the drawings

[0023] Figure 1 Four-layer structure of the abstract syntax tree for the translation process;

[0024] Figure 2 Full translation process;

[0025] Figure 3 Main steps of S2 and S3;

[0026] Figure 4 Graphical model of the embodiment in the OnModel modeling tool. Detailed implementation manners

[0027] To make the objectives, contents, and advantages of the present invention clearer, the following further describes the detailed implementation manners of the present invention in conjunction with the drawings and embodiments.

[0028] The technical problem to be solved by the present invention is how to implement a synchronous data flow language code translation method that supports simulating a graph model, so that the translated C language program can be used to simulate the model.

[0029] To solve the above problems, this paper proposes a synchronous data flow language translation method that supports model simulation. Before introducing this method, it is necessary to briefly explain some concepts and terms:

[0030] The main research work of the present invention is based on Coq. Coq is a widely used theorem proving tool, and its core theory is the calculus of inductive constructions. Under this theoretical framework, Coq combines functional programming and higher-order logic, and has strong mathematical theory support. One of the advantages of Coq is that the terms and functions defined in it can be directly extracted into the OCaml language, which makes it possible to construct formally verified programs.

[0031] The present invention adopts the synchronous data flow language translation tool L2C developed based on Coq. During the translation process of L2C, the LustreF abstract syntax tree is mainly involved as an intermediate language. The work of the present invention focuses on the definition and processing of LustreF. LustreF is formally defined in Coq and is divided into four layers: program layer, node layer, statement layer, and expression layer, as Figure 1 shown. In the node layer, nodes include two types: function and node. Among them, function can be regarded as a simplified node, which does not contain temporal operators and node history clock information.

[0032] To implement the feature that a node in the Lustre language can have multiple return values and simulate the clock environment of the Lustre language, a context structure will be defined for the node in the C code translated from the Lustre language. The types of the constituent elements of the context structure are the return variables corresponding to the node in all Lustre source codes, as well as the context structures of the nodes called by the node. The following is an example of the context structure of a node:

[0033]

[0034]

[0035] In the generated C code, the corresponding return variables participate in the operation in the form of pointers to the context structure. To meet the code simulation requirements, it is necessary to generate context structures for all nodes, and all local variables in the function should be defined in the context structure and participate in the function operation in the form of pointers.

[0036] Now, the translation method involved in the present invention will be specifically introduced. The method specifically includes the following steps:

[0037] S1. Translate to lustreF

[0038] Use the existing synchronous data flow language translation tool L2C to generate a LustreF program from the Lustre program source code.

[0039] S2. Modify the function output and return the function local variables

[0040] Traverse the LustreF program and modify the input-output structure, local variable definition, and function call structure of the functions defined in the program so that the local variable values are output in the form of return values.

[0041] S3. Generate the context structure and its initialization function

[0042] Modify the context structure generation function so that both node and function nodes generate the same context structure. Call the context structure initialization function generation tool to add the context structure initialization function to the function list. Eliminate the call method errors caused by modifying the function input-output structure. At this time, the program language is translated to LustreD.

[0043] The key steps in steps S2 and S3 are as Figure 2 shown.

[0044] S4. Complete the translation process

[0045] Call L2C to complete the translation process from LustreD to C language. The complete code generation process is as Figure 3 shown.

[0046] Among them, step S2 specifically includes:

[0047] S21. In the LustreF function definition, merge the nd_vars list into nd_rets. At the same time, design the function fieldlist_of to convert the information in the nd_vars list into the fieldlist type and merge it into nd_fld, so that the required context structure can be generated in the subsequent steps.

[0048] S22. Record the original nd_rets, clear the nd_vars field in the function construction, and pass the recorded nd_vars to the subsequent steps to avoid node call errors caused by S21.

[0049] Among them, step S3 specifically includes:

[0050] S31. The generation method of the context structure is designed to construct the mapping from fieldlist to the structure, traverse the function call relationship, and add function call information to the context structure, enabling the generation of the same context structure for node and function nodes.

[0051] S32. Call the context structure initialization tool to generate an initialization function for the context structure of the node and add it to the node list.

[0052] S33. Translate the call statement, splitting the call statement into two parts: the input context structure pointer and the assignment of variables in the function based on the context structure pointer after calculation. When assigning variables, sequentially use the original nd_rets variable recorded in S22 as the structure element pointer to eliminate the errors introduced by S2.

[0053] Example 1:

[0054] To make the objectives, content, and advantages of the present invention clearer, the following further describes in detail the specific implementation manners of the present invention with reference to the embodiments.

[0055] S1: Translate to lustreF

[0056] Use the existing synchronous data flow language translation tool L2C to generate the LustreF program from the Lustre program source code.

[0057] S2: Modify the function output to return the local variables of the function:

[0058] Compared with C, the input / output and call structure of LustreF are relatively simple. In LustreF, the function is defined as follows

[0059]

[0060]

[0061] Among them, nd_vars and nd_rets record the local variable list and return variable list in the node, and nd_fld records the information required to generate the node context structure. To return the local variables, perform step S21: merge the nd_vars list into nd_rets. At the same time, convert the information in the nd_vars list into the fieldlist type through the fieldlist_of function and merge it into nd_fld, enabling the subsequent steps to generate the required context structure.

[0062] Meanwhile, due to the change in the node input-output structure, there will be a problem of inconsistent variable numbers when the function is called. To solve this problem, perform step S22: Record the original input-output variables to correct this problem in subsequent translations.

[0063] S3: Generate a context structure containing local variables

[0064] Based on step S2, perform step S31: Call OutStructGen to generate a context structure for the nodes in the program. To reflect the difference in the clock environment between node and function nodes, OutStructGen will not be applied to functions in L2C. To ensure that local variables are traced, this method designs a new context structure generation method so that all nodes generate the corresponding context structure according to nd_fld. Meanwhile, traverse the syntax tree function list to obtain the call topology information and add the function node context structure call information to the context structure.

[0065] Call the context structure initialization function generation tool to generate the initialization function of the context structure for the development of simulation work.

[0066] Call the SimplEnv translation step to modify the function body of the node: Modify the variables existing in the output variable list in the function body to the form of pointers to the corresponding elements in the context structure. To ensure the correct reference value of the pointer during function call, S32 of this method modifies the SimplEnv step. When allocating pointer references for function calls, use the information of the original output variables of the called function saved in step S2 to ensure the correctness of the pointer reference and solve the call error introduced in step S2.

[0067] S4: Complete the translation process

[0068] Call the remaining steps of L2C to complete the translation process from the LustreD program to the C language program.

[0069] Embodiment 2:

[0070] The following introduces the specific process of this method in combination with an example:

[0071] The following is an excerpt of the Lustre source code used in the test:

[0072]

[0073]

[0074] First, translate this program into LustreF through step S1 and make corresponding modifications to its input-output structure according to step S2.

[0075] After that, through step S3, a context structure and an initialization function are added to the program, and the input / output structure and call structure of the program are adjusted accordingly.

[0076] The LustreD program obtained after translating steps S2 and S3 can be output as the following code (excerpt):

[0077]

[0078]

[0079] It can be seen that after translating through steps S2 and S3, the program can correctly return local variables through the context structure and generate the corresponding initialization function. Next, it only needs to be translated into a C program through step S4.

[0080] The finally generated C code is shown in the following table (excerpt):

[0081]

[0082]

[0083]

[0084] The C code generated by the original tool (L2C) is as follows (excerpt):

[0085]

[0086]

[0087] It can be seen that compared with the code generated by the original tool, in the model simulation code, local variables participate in function operations in the form of context structure pointers, and the values of local variables can be traced within a single cycle by simply accessing the context structure of the entry function in the loop function. At the same time, a function for initializing the context structure is added, which facilitates the development of testing work.

[0088] Embodiment 3:

[0089] A synchronous data flow language translation method supporting model simulation, the method comprising the following steps:

[0090] S1: Use a synchronous data flow language translation tool to translate a Lustre program into a LustreF program;

[0091] S2: Modify the input / output structure and local variable definitions of the functions in the LustreF program so that the local variable values are output in the form of return values;

[0092] S3: Generate a context structure containing local variables based on the LustreF program and generate its initialization function;

[0093] S4: Finally complete the translation process to C language and generate simulation code.

[0094] Furthermore, in step S2, the local variable list is merged into the return variable list, and at the same time, the local variable information is added to the node structure definition to generate a context structure containing local variables.

[0095] Furthermore, in step S3, context structures are generated for all local variables of the node type, while ensuring the correctness of variable pointer references.

[0096] Furthermore, the generated context structure includes all intermediate variables, input variables, and output variables in the Lustre program, which are used to trace variable values during the model simulation process.

[0097] Furthermore, by adding an initialization function to the context structure, the debugging and testing processes of the simulation code are simplified.

[0098] Furthermore, this method is implemented in the Coq tool, based on the trusted translation tool for synchronous data flow languages.

[0099] Furthermore, in the finally generated C language code, except for global constants and variables, all operations inside the nodes are completed through the context structure pointer, supporting variable tracing and simulation testing.

[0100] Beneficial effects:

[0101] The present invention relates to a method for translating synchronous data flow languages supporting model simulation, belonging to the field of code generation. The method proposed by the present invention is based on the synchronous data flow language translation tool L2C. In the process of synchronous data flow translation, the present invention modifies the input-output structure of functions, generates a context structure containing local variables, and generates an initialization function for the context structure. Through the above steps, the generated code can track the values of local variables within a single clock cycle of the model and provide an initialization function for input-output variables. Compared with the code generated by traditional methods, the code generated by the present invention has higher convenience and reliability during model simulation.

[0102] The present invention proposes a method for translating synchronous data flow languages supporting model simulation. This method has at least the following beneficial effects:

[0103] (1) Designed a method for generating simulation code for the model, enabling the tool to simulate the model and trace node local variables, thereby optimizing the development process.

[0104] (2) Developed based on L2C, it has a high degree of modularity and can quickly switch compilation options.

[0105] (3) Operate at the level of the intermediate translation abstract syntax tree. The translation tool given has been formally verified and the code has a high credibility.

[0106] (4) Added a code simulation function in the OnModel modeling platform, expanding the platform function and development practicality.

[0107] The above are only the preferred embodiments of the present invention. It should be noted that for those of ordinary skill in the art, without departing from the technical principle of the present invention, several improvements and modifications can be made, and these improvements and modifications should also be regarded as the protection scope of the present invention.

Claims

1. A synchronous data flow language translation method supporting model simulation, characterized in that: The method comprises the following steps: S1, translation to lustreF Generate LustreF program from Lustre program source code using L2C, a synchronous data flow language translation tool; S2. Modify function output and return function local variables Traverse the LustreF program and modify the input and output structure, local variable definition, and function call structure of the functions defined in the program so that the local variable values ​​are output as return values; S3. Generate context structure and its initialization function Modify the context structure generation function so that both node and function nodes generate the same context structure; Call the context structure initialization function generation tool to add the context structure initialization function to the function list; eliminate the calling method errors caused by modifying the function input and output structure; At this time, the program language is translated into LustreD; S4. Complete the translation process Call L2C to complete the translation process from LustreD to C language.

2. The synchronous data flow language translation method supporting model simulation as claimed in claim 1, characterized in that: The S2 includes: S21. In the LustreF function definition, merge the nd_vars list into nd_rets. At the same time, design the function fieldlist_of to convert the information in the nd_vars list into the fieldlist type and merge it into nd_fld, so that the subsequent steps can generate the required context structure. S22. Record the original nd_rets, clear the nd_vars field in the function construction, and pass the recorded nd_vars to the subsequent steps to avoid the node call error caused by S21.

3. The synchronous data flow language translation method supporting model simulation as claimed in claim 2, characterized in that: In S21, in the LustreF function definition, nd_vars and nd_rets record the local variable list and return variable list in the node, nd_fld records the information required to generate the node context structure, and the nd_vars list is merged into nd_rets; at the same time, the information in the nd_vars list is converted into the fieldlist type through the fieldlist_of function and merged into nd_fld.

4. The synchronous data flow language translation method supporting model simulation as claimed in claim 2, characterized in that: The S3 includes: S31. Design a method for generating a context structure, construct a mapping from fieldlist to structure, traverse the function call relationship, and add function call information to the context structure; so that it can generate the same context structure for node and function nodes; S32, calling the context structure initialization tool, generating an initialization function for the context structure of the node, and adding it to the node list; S33. Translate the call statement and split the call statement into two parts: input the context structure pointer and assign values ​​to the variables in the function according to the context structure pointer after operation; when assigning values ​​to variables, use the original nd_rets variable recorded in S22 as the structure element pointer in sequence to eliminate the error introduced by S2.

5. The synchronous data flow language translation method supporting model simulation as claimed in claim 4, characterized in that: In S31, OutStructGen is called to generate a context structure for the nodes in the program.

6. The synchronous data flow language translation method supporting model simulation as claimed in claim 4, characterized in that: In the S31, all nodes generate a context structure corresponding to the node according to nd_fld; at the same time, the syntax tree function list is traversed to obtain the call topology information, and the function node context structure call information is added to the context structure.

7. The synchronous data flow language translation method supporting model simulation as claimed in claim 4, characterized in that: In S31, the generated context structure includes all intermediate variables, input variables and output variables in the Lustre program, and is used to track variable values ​​during the model simulation process.

8. The synchronous data flow language translation method supporting model simulation as claimed in claim 4, characterized in that: In the S33, the SimplEnv translation step is called to modify the function body of the node: the variables in the output variable list in the function body are modified to the form of corresponding element pointers in the context structure.

9. The synchronous data flow language translation method supporting model simulation as claimed in claim 4, characterized in that: In S4, in the C language code finally generated, except for global constants and variables, all operations within the nodes are completed through context structure pointers, supporting variable tracking and simulation testing.

10. The synchronous data flow language translation method supporting model simulation as claimed in claim 1, characterized in that: The method is based on L2C, a synchronous dataflow language translation tool developed by Coq.

Citation Information

Patent Citations

  • Model-based visual software development tool implementation method

    CN115964033A

  • Model formalized verification method based on extended Lustre language

    CN116150005A

  • Synchronous data stream language conversion method of extended condition block

    CN117454848A

  • Asynchronous programming model for concurrent workflow scenarios

    US20140282625A1