Method and device for eliminating intermediate variables during the conversion of SCADE models to Lustre models
By analyzing and replacing the intermediate variables of the SCADE model, the problem of increasing computational volume during the conversion of the SCADE model into the Lustre model is solved, and more efficient verification and fewer storage requirements are achieved, and the readability of the model is improved.
Patent Information
- Application Number
- CN202210742855.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-06-27
- Publication Date
- 2025-07-22
- Estimated Expiration
- 2042-06-27
AI Technical Summary
During the process of converting the SCADE model into the Lustre model, due to the introduction of a large number of local variables, the calculation volume increases and the redundant data flow increases during the verification process, making it difficult to effectively remove intermediate variables.
By analyzing the node or function name, variable type, and equation structure of the SCADE model, traversing and searching for intermediate variables, replacing them with input variables or simple expressions, reducing the redundant data flow and realizing the elimination of intermediate variables.
It effectively reduces the time and storage overhead of Lustre model verification, improves the readability of the model, reduces the calculation amount of local variables, and reduces the number of data streams.
Smart Images

Figure CN115237754B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of safety-critical systems, and in particular, to a method and device for eliminating intermediate variables during the conversion of an SCADE model into a Lustre model. Background Art
[0002] In safety-critical fields such as rail transit, automotive electronics, aviation, aerospace, and nuclear power, safety is the core element throughout the system and product life cycle. Ensuring system safety is the criterion adhered to during the design and development of products, and improving system safety is the goal that safety-critical products have been pursuing. Therefore, improving the safety of safety-critical systems is crucial for products.
[0003] Formal methods are based on mathematical methods such as mathematical logic and set theory to model safety-critical systems, and generate code from the models through model-driven methods, thereby reducing human participation to avoid problems brought about artificially during the design and development process. This is of great significance for improving the safety of safety-critical systems. Synchronous languages represented by SCADE, Esterel, and Lustre formally define modeling elements such as arithmetic, logic, comparison, time, arrays, and structures, and also define generic functions and higher-order operators to increase the reusability of nodes or functions. These modeling ideas based on synchronous assumptions are closely combined with safety-critical systems having the three characteristics of computation, information transfer, and control, and have become a powerful support for modeling large-scale industrial safety-critical systems and improving system safety based on the models for simulation, testing, and code generation.
[0004] The method of simulation or testing can discover defects, faults, and errors existing in the SCADE model of the system, but it cannot prove that there are no errors in the safety-critical system. Formal verification based on methods such as mathematical reasoning and theorem proving can be used to prove the compliance of the system model with safety requirements, and thus the correctness of the system can be proved.
[0005] Verifiers based on verification engines such as symbolic model checking, BDD, and SAT, such as the commercial tool Prover, take logical formulas of Boolean variables as input and solve the logical formulas through specific algorithms to achieve the purpose of verifying system safety. However, the SCADE model has arithmetic and logical operations, as well as complex operations such as selection, comparison, and equality, and even more complex generic function and higher-order operator operations. Obviously, the SAT verification engine cannot handle them, which also increases the difficulty of formal verification of the SCADE model.
[0006] A verifier based on an SMT verification engine, such as the Jkind verifier, supports the verification of the above complex results. However, since it takes a Lustre model as input, it cannot recognize an SCADE model. The idea of model transformation can be applied to the SCADE model. However, since the SCADE model introduces a large number of local variables to represent the data flow, the generated code has too high redundancy, resulting in a large amount of computation due to these unnecessary data flows during the verification process. At the same time, there are many operations and composite operations in the SCADE model, making it difficult to remove intermediate variables during the transformation process. Therefore, the problem of increased computation caused by a large number of intermediate variables in the SCADE model has become a technical problem to be solved urgently. Summary of the Invention
[0007] The purpose of the present invention is to provide a method and device for eliminating intermediate variables during the transformation of an SCADE model into a Lustre model, in order to overcome the defects existing in the above-mentioned prior art.
[0008] The purpose of the present invention can be achieved through the following technical solutions:
[0009] According to the first aspect of the present invention, a method for eliminating intermediate variables during the transformation of an SCADE model into a Lustre model is provided. The method includes the following steps:
[0010] Step S1, a node or function name parsing process, which is used to parse the names of nodes or functions from the script file corresponding to the SCADE model;
[0011] Step S2, a variable parsing process, which is used to parse the variable names and types of the input, output, and local variables of the node or function;
[0012] Step S3, an equation parsing process, which is used to parse the equations of the node or function according to the operator names to obtain a list of equation structures corresponding to the operators;
[0013] Step S4, an equation assignment variable traversal process, which is used to traverse the assignment variables in the equation structure list in Step S3 and establish a list of the assignment variables at the current index;
[0014] Step S5, an equation intermediate variable search process, which is used to search the operators of the equation structure list and return the equation structure that matches the assignment variable;
[0015] Step S6, an equation output process, which is used to search the equation structure list according to the above-parsed equations, obtain the content that matches the call parameters, replace them, and add them to the output equation list.
[0016] As a preferred technical solution, the node or function name parsing process in Step S1 is specifically:
[0017] Parse the SCADE file and obtain the content corresponding to the name field under the Operator tag from the file. This content will be used as the index for subsequent access to the node or function.
[0018] As a preferred technical solution, in step S2, the variable parsing process is specifically as follows:
[0019] Obtain the list of variables according to the input variables inputs, output variables outputs, and local variables locals tags respectively, and parse the variable names and variable types according to the Variable field.
[0020] As a preferred technical solution, in step S3, the equation parsing process is specifically as follows:
[0021] Step S301, parse the assignment variable and obtain the name of the assignment variable according to the lefts tag;
[0022] Step S302, parse the call parameters and obtain the names of the call parameters according to the callParameters tag;
[0023] Step S303, parse the equation operator, and parse out the equation operator name and its instance parameters;
[0024] Step S304, establish an equation structure list, analyze the equation structure element that requires storing the most elements, and use its length as the length of each array in the list;
[0025] Step S305, parse the equation elements, parse various elements in each equation operator according to the type of the operator, and store the parsed elements;
[0026] Step S306, store the preprocessed equation, preprocess the parsed equation structure, and store it in the equation structure list.
[0027] As a preferred technical solution, the assignment variables in step S301 include two categories: local variables and output variables.
[0028] As a preferred technical solution, in step S303, if it is a generic function operator, it is necessary to parse the generic function and obtain the parsed operator name.
[0029] As a preferred technical solution, in step S4, the process of traversing the equation assignment variables is specifically as follows:
[0030] Step S401, traverse the equation structure list to obtain the index of the equation structure list, and obtain the equation element array through this index;
[0031] Step S402: Obtain the equation operator, which is parsed from the equation element array.
[0032] Step S403: Obtain the call parameter list. Based on the equation operator parsed in Step S402, obtain the call parameter list from the equation element array.
[0033] Step S404: Determine the type of call parameters. Decompose the call parameters in the equation element array and determine whether the type of each component is local traversal. If it is local traversal, call the search equation intermediate variable module; otherwise, skip this component.
[0034] As a preferred technical solution, in Step S5, the specific process of searching for equation intermediate variables is as follows:
[0035] Step S501: Traverse the equation structure list to obtain the index of the equation structure list, and obtain the equation element array according to this index.
[0036] Step S502: Obtain the assignment variable element. Obtain the assignment variable and compare it with the variable to be searched to analyze whether this assignment variable is the intermediate variable to be replaced.
[0037] Step S503: Match the equation operator. Extract the content of the equation operator from the equation structure array, match it according to the type of the operator, and perform different processing for different operators.
[0038] Step S504: Determine the type of call parameters. Construct the call parameters into an array and perform recursive search on the local variables among them.
[0039] Step S505: Return the result to the assignment variable. If there is no intermediate variable in the call parameters, or all intermediate variables have been replaced by input variables or simple expressions of input variables, return to the assignment variable to be searched.
[0040] As a preferred technical solution, in Step S6, the specific process of equation output is as follows:
[0041] Step S601: Traverse the equation structure list and traverse the updated equation structure list in the process of searching for equation intermediate variables.
[0042] Step S602: Obtain the equation assignment variable. Obtain the assignment variable of the equation according to the current index and establish an array for the assignment variable to store each assignment variable.
[0043] Step S603: Determine the type of assignment variable. Traverse the assignment traversal array. If the current assignment variable is a local variable, continue to process it; otherwise, directly add it to the list of output equations.
[0044] Step S604, obtain the equation structure list. If the assigned variable is a local variable, enter the stage of searching for this local variable, and obtain and traverse the equation structure list.
[0045] Step S605, determine the type of the call parameter. If the call parameter is a local variable, further processing is required; otherwise, it is directly added to the output equation list.
[0046] Step S606, search the equation structure list. If the above call parameter is not a local variable, the equation structure list needs to be traversed again.
[0047] Step S607, search for the intermediate variables of the equation. For the call parameter of the current equation, search for its value in the equation list and perform replacement.
[0048] Step S608, add to the output equation list. Replace the searched variables, update the equation, and add the updated equation to the output equation list.
[0049] Step S609, output the equation list. If the above process traversal has not ended, continue to enter the loop; otherwise, output the equation list.
[0050] According to the second aspect of the present invention, there is provided a device for eliminating intermediate variables during the conversion of an SCADE model into a Lustre model. The device includes:
[0051] A parsing node or function name module, configured to parse the name of a node or function from a script file corresponding to the SCADE model;
[0052] A parsing variable module, configured to parse the variable names and types of the input, output, and local variables of a node or function;
[0053] A parsing equation module, configured to parse the equation of a node or function according to the operator name to obtain an equation structure list corresponding to the operator;
[0054] An equation assignment variable traversing module, configured to traverse the assignment variables in the equation structure list and establish a list of the assignment variables at the current index;
[0055] An equation intermediate variable searching module, configured to search the operators of the equation structure list and return an equation structure that matches the assignment variable;
[0056] An output equation module, configured to search the equation structure list according to the above parsed equation, obtain the content that matches the call parameter, perform replacement, and add it to the output equation list.
[0057] According to a third aspect of the present invention, there is provided an application of a method for eliminating intermediate variables during the conversion of the SCADE model into a Lustre model. This method is applied to the Lustre model obtained after the conversion of the SCADE model in which the zone controller obtains the section index number according to the direction. The index number of the next section is obtained by running the direction, where the input variables are the current section index number iCurBlkIdx, the current running direction iCurDir, and the default value iDEFAULT, and the output variables are the index number OUTiNxtBlkIdx of the next section and the valid direction OUTbValidDir.
[0058] According to a fourth aspect of the present invention, there is provided an electronic device including a memory and a processor. A computer program is stored on the memory, and when the processor executes the program, the method described above is implemented.
[0059] According to a fifth aspect of the present invention, there is provided a computer-readable storage medium on which a computer program is stored. When the program is executed by a processor, the method described above is implemented.
[0060] Compared with the prior art, the present invention has the following advantages:
[0061] 1) The present invention solves the problem of increased computational complexity caused by a large number of intermediate variables in the SCADE model;
[0062] 2) The present invention significantly reduces the time for the verification process of the Lustre model and the overhead caused by storing intermediate variables;
[0063] 3) The method and device for eliminating intermediate variables proposed by the present invention reduce the number of occurrences of local variables that have no practical significance, not only reducing the number of data flows in the Lustre model but also increasing the readability of the model. BRIEF DESCRIPTION OF THE DRAWINGS
[0064] Figure 1 is a specific flowchart of the method of the present invention;
[0065] Figure 2 is a schematic diagram for equation analysis of the present invention;
[0066] Figure 3 is a schematic diagram of the equation storage structure of the present invention;
[0067] Figure 4 is a schematic diagram for traversing equation call parameters of the present invention;
[0068] Figure 5 is a schematic diagram of the search equation intermediate variable module of the present invention;
[0069] Figure 6 is a schematic diagram of the output equation of the present invention;
[0070] Figure 7 This is an example diagram of an embodiment for eliminating intermediate variables in the present invention. Detailed implementation manners
[0071] Next, the technical solutions in the embodiments of the present invention will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, rather than all the embodiments. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present invention without creative efforts shall fall within the protection scope of the present invention.
[0072] A method for eliminating intermediate variables in the process of converting an SCADE model into a Lustre model according to the present invention, the method includes the following steps:
[0073] Step S1, a node or function name parsing process, for parsing the names of nodes or functions from the script file corresponding to the SCADE model;
[0074] Step S2, a variable parsing process, for parsing the variable names and types of the input, output, and local variables of the node or function;
[0075] Step S3, an equation parsing process, for parsing the equations of the node or function according to the operator names to obtain a list of equation structures corresponding to the operators;
[0076] Step S4, an equation assignment variable traversing process, for traversing the assignment variables in the equation structure list in Step S3 and establishing a list of the assignment variables at the current index;
[0077] Step S5, an equation intermediate variable searching process, for searching the operators in the equation structure list and returning the equation structure that matches the assignment variable;
[0078] Step S6, an equation output process, for searching the equation structure list according to the above-parsed equations, obtaining the content that matches the call parameters, replacing them, and adding them to the output equation list.
[0079] The present invention discloses an embodiment:
[0080] function GetNxtBlkIdxByDir(iCurBlkIdx:int;iCurDir:int;iDEFAULT:int)
[0081] returns(OUTiNxtBlkIdx:int;OUTbValidDir:bool)
[0082] var
[0083] _L1: arrsBlkDir_t; _L2: siDir_t; _L3: int; _L4: int[2]; _L5: bool;
[0084] _L6: int; _L7: int[2]; _L8: int; _L9: int; _L10: int;
[0085] let
[0086] _L1 = arrsBlock;
[0087] OUTiNxtBlkIdx = _L6;
[0088] _L2 = (_L1.[_l3] default INVALID_SIDIR_IDX);
[0089] _L3 = iCurBlkIdx;
[0090] _L10 = iCurDir;
[0091] _L8, _L9 = (flatten siDir_t)(_L2);
[0092] _L7 = [DIR_UP, DIR_DOWN];
[0093] _L5, _L6 = MAPEnumArr2(_L10, _L7, _L4, iDEFAULT);
[0094] _L4 = [_L8, _L9];
[0095] OUTbValidDir = _L5;
[0096] tel;
[0097] This embodiment is a SCADE model of the area controller in the train control system for implementing the parsing of track sections. This function obtains the index number of the next section through the running direction. The input variables are the current section index number iCurBlkIdx, the current running direction iCurDir, and the default value iDEFAULT. The output variables are the index number of the next section OUTiNxtBlkIdx and the valid direction OUTbValidDir.
[0098] According to the implementation manner of the present application, a device for removing intermediate variables during the process of converting a SCADE model into a Lustre model is proposed. As Figure 1 shown, it includes:
[0099] Parsing Node or Function Name Module S101, which is used to parse the names of nodes or functions from the script file corresponding to the SCADE model;
[0100] Parsing Variable Module S102, which is used to parse the variable names and types of the input, output, and local variables of the node or function;
[0101] Parsing Equation Module S103, which is used to parse the equations of the node or function according to the operator names to obtain a list of equation structures corresponding to the operators;
[0102] Traversing Equation Assignment Variable Module S104, which is used to traverse the assignment variables in the above equation structure list and establish a list of the assignment variables at the current index;
[0103] Searching Equation Intermediate Variable Module S105, which is used to search the operators of the equation structure list and return the equation structure that matches the assignment variable;
[0104] Output Equation Module S106, which is used to search the equation structure list according to the above-parsed equation, obtain the content that matches the call parameters, replace it, and add it to the output equation list.
[0105] The Figure 1 method for parsing the name of the node or function in is as follows: Parse the SCADE file and obtain the content corresponding to the name field under the Operator tag from the file, and this content will be used as the index for subsequent access to the node or function;
[0106] The Figure 1 method for parsing variables in first obtains the list of variables according to the input variable inputs, output variable outputs, and local variable locals tags respectively, and parses the variable name and variable type according to the Variable field;
[0107] The Figure 1 method for parsing equations in is as Figure 2 shown and includes the following steps:
[0108] (1) Parsing Assignment Variables S201, obtaining the names of the assignment variables according to the lefts tag. The assignment variables are generally classified into two categories: local variables and output variables;
[0109] (2) Parsing Call Parameters S202, obtaining the names of the call parameters according to the callParameters tag;
[0110] (3) Parsing Equation Operators S203, parsing out the equation operator name and its instance parameters. If it is a generic function operator, the generic function needs to be parsed, and the parsed operator name is obtained;
[0111] (4) Establish a list of equation structures S204. First, analyze the equation structure element that requires storing the most elements, and use its length as the length of each array in the list;
[0112] (5) Parse equation elements S205. Parse various elements in each equation operator according to the type of operator, and store the parsed elements;
[0113] (6) Store the preprocessed equation S206. Preprocess the above parsed equation structure and store it in the list of equation structures.
[0114] The Figure 2 storage structure of the list of equation structures in Figure 3 is as shown below and includes the following steps:
[0115] (1) The storage format for a constant constant is: operator name constant, assignment variable lefts, and call parameters callParameters;
[0116] (2) The storage format for a unary operator is: operator name Unary, assignment variable lefts, and call parameters callParameters;
[0117] (3) The storage format for a binary operator is: operator name Binary, assignment variable lefts, call parameters callParameters1, and call parameters callParameters2;
[0118] (4) The storage format for a multi-ary operator is: operator name NAry, assignment variable lefts, and call parameters callParameters;
[0119] (5) The storage format for an atomic assignment operator is: operator name IdExpression, assignment variable lefts, and call parameters callParameters;
[0120] (6) The storage format for a conditional expression operator is: operator name IfThenElse, assignment variable lefts, judgment condition if, then branch result, and else branch result;
[0121] (7) The storage format for a Make operator is: operator name Make, assignment variable lefts, and call parameters callParameters;
[0122] (8) The storage format for the Flatten operator is: operator name Flatten, assignment variable lefts, and call parameters callParameters;
[0123] (9) The storage format for the mapping operator is: operator name PrjOp, assignment variable lefts, and call parameters callParameters;
[0124] (10) The storage format for the dynamic mapping operator is: operator name PrjDynOp, array array, index value index, and default value default;
[0125] (11) The storage format for the change value operator is: operator name ChgIthOp, assignment variable lefts, flow folw, component with or replacement value value;
[0126] (12) The storage format for the follow operator is: operator name FbyOp, assignment variable lefts, flows flows, delay delay, and value value;
[0127] (13) The storage format for the scalar-to-vector operator is: operator name ScalarToVectorOp, assignment variable lefts, and call parameters callParameters;
[0128] (14) The storage format for the array operator is: operator name DataArrayOp, assignment variable lefts, and call parameters callParameters;
[0129] (15) The storage format for the transpose operator is: operator name TransposeOp, assignment variable lefts, and call parameters callParameters;
[0130] (16) The storage format for the inversion operator is: operator name Reverse, assignment variable lefts, call parameters callParameters;
[0131] (17) The storage format for the slicing operator is: operator name Slice, assignment variable lefts, array array, starting index fromIndex, and ending index toIndex;
[0132] (18) The storage format for the Map operator is: operator name Map, assignment variable lefts, iteration count iterationValue, and call parameters callParameters;
[0133] (19) The storage format for the MapFold operator is: operator name MapFold, assigned variable lefts, number of iterations iterationValue, and call parameters callParameters;
[0134] (20) The storage format for the Mapwi operator is: operator name Mapwi, assigned variable lefts, number of iterations iterationvalue, and call parameters callParameters;
[0135] (21) The storage format for the Foldwi operator is: operator name Foldwi, assigned variable lefts, number of iterations iterationValue, judgment condition, iterator, and call parameters callParameters;
[0136] For other operators of higher-order operations, such as Mapi, Mapw, Fold, Foldi, Foldw, MapFoldi, MapFoldw, MapFoldwi, the principle of their parsing and storage is similar to the above. The four storage methods given in this embodiment are very representative. Other storage methods similar to the storage structure of the present invention fall within the scope of the present invention.
[0137] The above Figure 1 method for assigning variables in the traversal equation is as Figure 4 shown and includes the following steps:
[0138] (1) Traverse the equation structure list S401 to obtain the index of the equation structure list, and obtain the equation element array through this index;
[0139] (2) Obtain the equation operator S402, and obtain the equation operator according to the equation element array;
[0140] (3) Obtain the call parameter list S403, and obtain the call parameter list from the equation element array according to the equation operator parsed above;
[0141] (4) Judge the call parameter type S404, decompose the call parameters in the equation element array, and judge whether the type of each component is local traversal. If it is local traversal, call the search equation intermediate variable module, otherwise skip this component.
[0142] The above Figure 1 method for searching equation intermediate variables is as Figure 5 shown and includes the following steps:
[0143] (1) Traverse the equation structure list S502 to obtain the index of the equation structure list, and obtain the equation element array according to this index;
[0144] (2) Obtain the assigned variable element S502, obtain the assigned variable, compare the assigned variable with the variable to be searched, and analyze whether the assigned variable is the intermediate variable to be replaced;
[0145] (3) Match the equation operator S503, extract the content of the equation operator from the equation structure array, match according to the type of the operator, and perform different processing for different operators;
[0146] (4) Judge the type of the call parameter S504. First, construct the call parameter into an array, and perform a recursive search on the local variables therein;
[0147] (5) Return the result to the assigned variable S505. If there is no intermediate variable in the above call parameter, or all intermediate variables have been replaced with input variables or simple expressions of input variables, then return to the assigned variable to be searched.
[0148] The above Figure 5 The method for matching operators includes the following steps:
[0149] (1) When there are multiple call parameters in the equation structure list corresponding to the operator, such as function call OpCal, iterator operator IteratorOp, partial iterator operator PartialIteratorOp, dynamic mapping PrjDynOp, scalar-to-vector operator ScalarToVectorOp, selection operator IfThenElseOp, expansion operator FlattenOp, and structure construction operator MakeOp, establish an array for its call parameters, and analyze whether each array element is a local variable. If it is a local variable, call the search equation list function to search and update it;
[0150] (2) When there is only one call parameter in the equation structure list corresponding to the operator, directly add it to the output equation list.
[0151] The above Figure 1 The method of the output equation module in is as Figure 6 shown and includes the following steps:
[0152] (1) Traverse the equation structure list S601, and traverse the updated equation structure list of the above search equation intermediate traversal module;
[0153] (2) Obtain the equation assigned variable S602, obtain the assigned variable of the equation according to the current index, and establish an array for the assigned variable to store each assigned variable;
[0154] (3) Determine the type of the assigned variable S603. Traverse the assignment traversal array. If the current assigned variable is a local variable, continue the processing; otherwise, directly add it to the list of output equations.
[0155] (4) Obtain the equation structure list S604. If the above assigned variable is a local variable, enter the stage of searching for this local variable. First, obtain and traverse this equation structure list.
[0156] (5) Determine the type of the call parameter S605. If the call parameter is a local variable, further processing is required; otherwise, directly add it to the output equation list.
[0157] (6) Search the equation structure list S606. If the above call parameter is not a local variable, the equation structure list needs to be traversed again.
[0158] (7) Search for the intermediate variable of the equation S607. For the call parameter of the current equation, search for its value in the equation list and perform replacement.
[0159] (8) Add to the output equation list S608. Replace the variables after the above search, update the equation, and add the updated equation to the output equation list.
[0160] (9) Output the equation list S609. If the above process traversal has not ended, continue to enter the loop; otherwise, output the equation list.
[0161] The model after transformation by the method proposed in the embodiments of the present invention is as Figure 7 shown:
[0162]
[0163]
[0164] Figure 7It is the Lustre model transformed from the SCADE model in which the area controller obtains the section index number according to the direction. The left side is the model transformed according to the syntax of the Lustre language, that is, the model before removing the intermediate variables, and the right side is the model after removing the intermediate variables. It can be seen from the figure that the intermediate variables _L1, _L3, _L5, _L6, _L10 only play the role of passing values in the middle and occupy a certain amount of code, so they can be deleted. Obviously, it can be seen that the execution results before and after deletion are the same. Since the scale of the SCADE model of the area controller is quite large, and there are a large number of local variables in the input variables, output variables and calculation nodes or functions of the SCADE model, without affecting the calculation results, removing the intermediate local variables can reduce the storage space required for storing the Lustre code. In this embodiment, removing the intermediate variables reduces the equations related to the intermediate variables _L1, _L3, _L5, _L6, _L10 and replaces the input variables. After the entire SCADE model of the area controller is transformed into a Lustre model, the storage space is reduced by about 25%.
[0165] The method in the process of transforming the SCADE to Lustre model of the present invention, by parsing the model and removing the intermediate variables in the model during the transformation process, can be used in the technical route of model design of safety-critical systems based on SCADE and formal verification or code generation of the model. It has great value for ensuring the correctness of the system through formal verification and also has great significance for reducing errors introduced by manual programming through the model-driven development method;
[0166] The type matching used in removing the intermediate variables of the SCADE model in the present invention can also be used in other uses of the SCADE model transformation. When doing theorem proving of the translator for model transformation, type matching is also required and further processing is done according to the matching content.
[0167] A specific embodiment of the present invention has been described in detail above. Since there are many operators involved, although this embodiment does not give the transformation of all operators, it should be understood that the present invention is applicable to high-trust fields such as rail transit, automotive electronics, aerospace, and nuclear power. Those skilled in the art in the above fields can make many modifications and changes according to the concept of the present invention without creative labor. Therefore, all technical solutions that can be obtained by those skilled in the art in the technical field according to the concept of the present invention through model transformation, formal verification or limited experiments on the basis of the existing technology should be within the protection scope determined by the claims.
[0168] The above is the introduction of the method embodiment. The following further illustrates the solution of the present invention through the embodiments of the electronic device and the storage medium.
[0169] The electronic device of the present invention includes a central processing unit (CPU), which can perform various appropriate actions and processes according to computer program instructions stored in a read-only memory (ROM) or computer program instructions loaded from a storage unit into a random access memory (RAM). In the RAM, various programs and data required for device operation can also be stored. The CPU, ROM, and RAM are connected to each other via a bus. An input / output (I / O) interface is also connected to the bus.
[0170] Multiple components in the device are connected to the I / O interface, including: an input unit, such as a keyboard, a mouse, etc.; an output unit, such as various types of displays, speakers, etc.; a storage unit, such as a disk, an optical disc, etc.; and a communication unit, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit allows the device to exchange information / data with other devices via a computer network such as the Internet and / or various telecommunication networks.
[0171] The processing unit executes the various methods and processes described above, such as Method S1 - S6. For example, in some embodiments, Method S1 - S6 can be implemented as a computer software program, which is tangibly contained in a machine-readable medium, such as a storage unit. In some embodiments, part or all of the computer program can be loaded and / or installed onto the device via the ROM and / or the communication unit. When the computer program is loaded into the RAM and executed by the CPU, one or more steps of Method S1 - S6 described above can be executed. Alternatively, in other embodiments, the CPU can be configured to execute Method S1 - S6 by any other suitable means (e.g., by means of firmware).
[0172] The functions described above herein can be performed at least in part by one or more hardware logic components. For example, without limitation, exemplary types of hardware logic components that can be used include: field programmable gate arrays (FPGA), application specific integrated circuits (ASIC), application specific standard products (ASSP), system on a chip (SOC), complex programmable logic devices (CPLD), and so on.
[0173] The program code for implementing the method of the present invention can be written in any combination of one or more programming languages. These program codes can be provided to a processor or controller of a general-purpose computer, a special-purpose computer, or other programmable data processing devices, such that when the program codes are executed by the processor or controller, the functions / operations specified in the flowchart and / or block diagram are implemented. The program code can be executed entirely on the machine, partially on the machine, executed partially on the machine as an independent software package and partially on a remote machine, or executed entirely on a remote machine or server.
[0174] In the context of the present invention, a machine-readable medium can be a tangible medium that can contain or store a program for use by or in connection with an instruction execution system, apparatus, or device. The machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. The machine-readable medium can include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of the machine-readable storage medium would include electrical connections based on 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 fibers, portable compact disc read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.
[0175] As described above, only the specific embodiments of the present invention are provided, but the protection scope of the present invention is not limited thereto. Any person skilled in the art within the technical scope disclosed by the present invention can easily think of various equivalent modifications or substitutions, and these modifications or substitutions should all be covered within the protection scope of the present invention. Therefore, the protection scope of the present invention should be subject to the protection scope of the claims.
Claims
1. A method for eliminating intermediate variables during the conversion of an SCADE model to a Lustre model, characterized in that, The method includes the following steps: Step S1, a node or function name parsing process, which is used to parse the names of nodes or functions from the script file corresponding to the SCADE model; Step S2, a variable parsing process, which is used to parse the variable names and types of the input, output, and local variables of nodes or functions; Step S3, an equation parsing process, which is used to parse the equations of nodes or functions according to the operator names to obtain a list of equation structures corresponding to the operators; Step S4, an equation assignment variable traversal process, which is used to traverse the assignment variables in the equation structure list in Step S3 and establish a list of assignment variables at the current index; Step S5, an equation intermediate variable search process, which is used to search the operators in the equation structure list and return the equation structure that matches the assignment variable; Step S6, an equation output process, which is used to search the equation structure list according to the parsed equation above, obtain the content that matches the call parameter, replace it, and add it to the output equation list; In the said Step S6, the equation output process is specifically as follows: Step S601, traverse the equation structure list and traverse the updated equation structure list by the equation intermediate variable search process; Step S602, obtain the equation assignment variable, obtain the assignment variable of the equation according to the current index, and establish an array for the assignment variable to store each assignment variable; Step S603, judge the assignment variable type, traverse the assignment traversal array, if the current assignment variable is a local variable, continue to process it, otherwise, directly add it to the output equation list; Step S604, obtain the equation structure list, if the assignment variable is a local variable, enter the stage of searching for this local variable, and obtain and traverse this equation structure list; Step S605, judge the call parameter type, if the call parameter is a local variable, further processing is required, otherwise, directly add it to the output equation list; Step S606, search the equation structure list, if the above call parameter is not a local variable, the equation structure list needs to be traversed again; Step S607, search the equation intermediate variable, for the call parameter of the current equation, search its value from the equation list and replace it; Step S608, add the output equation list, replace the searched variable, update the equation, and add the updated equation to the output equation list; Step S609, output the equation list, if the above process traversal has not ended, continue to enter the loop; otherwise, output the equation list.
2. The method for eliminating intermediate variables during the conversion of an SCADE model to a Lustre model according to claim 1, wherein In the said Step S1, the node or function name parsing process is specifically as follows: Parse the SCADE file, and obtain the content corresponding to the name field under the Operator tag from the file, and this content will be used as the index for subsequent access to this node or function.
3. A method for eliminating intermediate variables during the conversion of an SCADE model to a Lustre model according to claim 1, characterized in that In the said Step S2, the variable parsing process is specifically as follows: Respectively obtain the list of variables according to the input variable inputs, output variable outputs, and local variable locals tags, and parse the variable name and variable type according to the Variable field.
4. The method for eliminating intermediate variables during the conversion of an SCADE model into a Lustre model according to claim 1, wherein In the said Step S3, the equation parsing process is specifically as follows: Step S301: Parse the assignment variables and obtain the names of the assignment variables according to the lefts tag; Step S302: Parse the call parameters and obtain the names of the call parameters according to the callParameters tag; Step S303: Parse the equation operators and parse out the equation operator names and their instance parameters; Step S304: Establish an equation structure list, analyze the equation structure element that requires storing the most elements, and use its length as the length of each array in the list; Step S305: Parse the equation elements, parse each element in each equation operator according to the type of the operator, and store the parsed elements; Step S306: Store the preprocessed equation, preprocess the parsed equation structure, and store it in the equation structure list.
5. The method for eliminating intermediate variables during the conversion of an SCADE model into a Lustre model according to claim 4, wherein, The assignment variables in step S301 include two categories: local variables and output variables.
6. The method for eliminating intermediate variables during the conversion of an SCADE model into a Lustre model according to claim 4, characterized in that In step S303, if it is a generic function operator, the generic function needs to be parsed and the parsed operator name is obtained.
7. The method for eliminating intermediate variables during the conversion of an SCADE model to a Lustre model according to claim 1, characterized in that In step S4, the specific process of traversing the equation assignment variables is as follows: Step S401: Traverse the equation structure list to obtain the index of the equation structure list, and obtain the equation element array through this index; Step S402: Obtain the equation operator and parse out the equation operator according to the equation element array; Step S403: Obtain the call parameter list and obtain the call parameter list from the equation element array according to the equation operator parsed in step S402; Step S404: Judge the call parameter type, decompose the call parameters in the equation element array, and judge whether the type of each component is local traversal. If it is local traversal, call the search equation intermediate variable module, otherwise skip this component.
8. A method for eliminating intermediate variables during the conversion of an SCADE model to a Lustre model according to claim 1, characterized in that, In step S5, the specific process of searching for equation intermediate variables is as follows: Step S501: Traverse the equation structure list to obtain the index of the equation structure list, and obtain the equation element array according to this index; Step S502: Obtain the assignment variable element, obtain the assignment variable, and compare this assignment variable with the variable to be searched to analyze whether this assignment variable is the intermediate variable to be replaced; Step S503: Match the equation operator, extract the content of the equation operator from the equation structure array, match according to the type of the operator, and perform different processing for different operators; Step S504: Judge the call parameter type, construct the call parameters into an array, and perform recursive search on the local variables therein; Step S505: Return the result to the assignment variable. If there is no intermediate variable in the call parameter, or all intermediate variables have been replaced with input variables or simple expressions of input variables, return to the assignment variable to be searched.
9. An apparatus for eliminating intermediate variables during the conversion of an SCADE model to a Lustre model, characterized in that, The device includes: A parsing node or function name module, which is used to parse the names of nodes or functions from the script file corresponding to the SCADE model; A parsing variable module, which is used to parse the variable names and types of the input, output, and local variables of nodes or functions; An equation parsing module, which is used to parse the equations of nodes or functions according to the operator names to obtain a list of equation structures corresponding to the operators; An equation assignment variable traversing module, which is used to traverse the assignment variables in the list of equation structures and establish a list of the assignment variables at the current index; An equation intermediate variable searching module, which is used to search the operators in the list of equation structures and return the equation structures that match the assignment variables; An output equation module, which is used to search the list of equation structures according to the parsed equations above, obtain the content that matches the call parameters, replace them, and add them to the output equation list; The specific working process of the output equation module includes: Step S601: Traverse the list of equation structures and traverse the list of equation structures updated during the search process of the equation intermediate variables; Step S602: Obtain the equation assignment variables, obtain the assignment variables of the equation according to the current index, and establish an array for the assignment variables to store each assignment variable; Step S603: Judge the type of the assignment variable. Traverse the assignment traversal array. If the current assignment variable is a local variable, continue to process it. Otherwise, directly add it to the output equation list; Step S604: Obtain the list of equation structures. If the assignment variable is a local variable, enter the stage of searching for the local variable, and obtain and traverse the list of equation structures; Step S605: Judge the type of the call parameter. If the call parameter is a local variable, further processing is required. Otherwise, directly add it to the output equation list; Step S606: Search the list of equation structures. If the above call parameter is not a local variable, the list of equation structures needs to be traversed again; Step S607: Search the equation intermediate variables. For the call parameter of the current equation, search its value from the equation list and replace it; Step S608: Add to the output equation list, replace the searched variables, update the equation, and add the updated equation to the output equation list; Step S609: Output the equation list. If the above process traversal has not ended, continue to enter the loop; otherwise, output the equation list.
10. Application of a method for eliminating intermediate variables during the conversion of the SCADE model according to any one of claims 1-8 into a Lustre model, characterized in that, This method is applied to the Lustre model converted from the SCADE model in which the area controller obtains the section index number according to the direction. The index number of the next section is obtained through the running direction, where the input variables are the current section index number iCurBlkIdx, the current running direction iCurDir, and the default value iDEFAULT, and the output variables are the index number OUTiNxtBlkIdx of the next section and the legal direction OUTbValidDir.
11. An electronic device, comprising a memory and a processor, wherein a computer program is stored on the memory, characterized in that, When the processor executes the program, it implements the method described in any one of claims 1 to 8.
12. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, it implements the method described in any one of claims 1 to 8.
Citation Information
Patent Citations
Visual variable management method, system and equipment based on multi-dimensional data
CN113688134A
A natural language demand-based AADL model combination verification property automatic generation method
CN114035785A