A modelica model-oriented incremental compilation method and system
By identifying and compiling local modifications to the Modelica model using an incremental compilation method, the problems of long compilation times for large models and redundant diagnostic information are solved, thereby improving modeling efficiency and user experience.
Patent Information
- Application Number
- CN202411915284.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-24
- Publication Date
- 2026-02-06
- Estimated Expiration
- 2044-12-24
AI Technical Summary
The existing Modelica model compilation process is time-consuming and contains redundant diagnostic information, which affects modeling efficiency and user experience, especially when the model size is large.
An incremental compilation method is adopted, which generates an abstract syntax tree by matching keywords to local modifications of the Modelica model, identifies the changed parts and instantiates intermediate representations, and integrates the intermediate representations of the changed and unchanged parts, thereby reducing the overall compilation time and diagnostic information.
It improves modeling efficiency, reduces user waiting time, focuses on diagnostic information for modification, facilitates problem localization, and enhances the user experience of the modeling tool.
Smart Images

Figure CN119759362B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the field of industrial internet system modeling simulation, and in particular to a Modelica model-oriented incremental compilation method and system. BACKGROUND
[0002] With the rapid development of the field of industrial internet system modeling simulation, the demand for high-precision and high-efficiency model compilation methods is increasingly urgent. Modelica, as a declarative multi-domain system modeling language, has been widely used in the field of system modeling simulation due to its powerful cross-domain modeling capability and openness. However, in practical applications, the compilation process of Modelica models often faces some challenges.
[0003] Firstly, in reality, large systems such as rockets, cars, and ships have huge equation variable scales of tens of thousands or even hundreds of thousands. Complete compilation of these large-scale models usually takes a long time. In the iterative process of modeling simulation, modifying the model and then verifying it is a common operation in modeling, including adjusting parameters, adding or deleting components, and modifying topological structures. However, traditional Modelica modeling simulation tools require recompilation of the entire model to verify the modification effect, which is particularly time-consuming when the model is large, greatly affecting modeling efficiency and the user experience of modeling simulation tools. In addition, with the continuous in-depth application of Modelica modeling simulation technology, the complexity and size of the model are also increasing, which will undoubtedly further exacerbate the problem.
[0004] Furthermore, the processing of compilation diagnostics and log information is also a problem that cannot be ignored. Each complete compilation generates a large amount of compilation diagnostic information, and users are usually only interested in diagnostic information related to the modified part. In large models, it is undoubtedly a difficult task to filter out useful information for the modified part from the vast amount of complete diagnostic and log information. This not only increases the user's workload, but also reduces modeling efficiency. SUMMARY
[0005] The present application provides a Modelica model-oriented incremental compilation method and system to solve the problem of complete recompilation after local modification of Modelica models. Through incremental compilation, the modified part of the model can be quickly identified and locally compiled, avoiding recompilation of the entire model and significantly improving compilation efficiency. At the same time, incremental compilation can effectively reduce the output of compilation diagnostic information, allowing users to more easily obtain diagnostic information related to the modified part, further improving the modeling experience.
[0006] According to a first aspect of the present application, a Modelica model-oriented incremental compilation method is provided, comprising:
[0007] Step 1, keyword matching is performed on the edited and modified Modelica model text to obtain an abstract syntax tree of the Modelica model; the abstract syntax tree includes definitions and behaviors of each component in the Modelica model;
[0008] Step 2, based on the abstract syntax tree and the changes in the last time, a changed part of the Modelica model editing and modification is determined;
[0009] Step 3, the changed part of the Modelica model is instantiated into an intermediate representation; the intermediate representation includes a component argument tree and a component behavior list;
[0010] Step 4, the intermediate representations of the changed part and the unchanged part of the Modelica model are integrated to obtain a complete representation of the Modelica model.
[0011] On the basis of the above technical solutions, the present application can also be improved as follows.
[0012] Optionally, the process of obtaining the abstract syntax tree of the Modelica model in step 1 includes:
[0013] A Modelica keyword matching list is set;
[0014] The Modelica model text is parsed byte by byte, and when a keyword in the Modelica keyword matching list is matched, the content corresponding to the keyword is extracted to generate the abstract syntax tree.
[0015] Optionally, the keywords in the Modelica keyword matching list include model definition, model name, component definition within the model, component name, model equation, and end symbol.
[0016] The content corresponding to the keyword is extracted to generate the abstract syntax tree, including extracting the description corresponding to the component definition to generate an abstract syntax tree structure representing the definition and behavior of the component, and extracting the description corresponding to the model equation to generate an abstract syntax tree structure representing the meaning of the equation.
[0017] Optionally, the abstract syntax tree further includes the model name; the definition of the component in the Modelica model includes the component type and the component name, and the behavior of the component includes the component behavior statement obtained based on the component equation behavior.
[0018] Optionally, step 3 includes:
[0019] When the Modelica is compiled for the first time, the Modelica model is completely compiled to obtain intermediate representations of all components, and a mapping table of model abstract syntax tree and intermediate representation is constructed;
[0020] After the Modelica model is edited and modified, all components of the Modelica model are traversed, and when the abstract syntax tree of any component has no corresponding intermediate representation in the mapping table, it is determined that the component is modified, and the intermediate representation of each modified component is generated as the intermediate representation of the changed part of the Modelica model, and the mapping table is correspondingly modified.
[0021] Optionally, the step 3 further comprises:
[0022] After it is determined that any component is modified, the component affected by the modified component is generated according to the topological structure and variable behavior equation analysis of the Modelica model, and the intermediate representation of the affected component is generated as the intermediate representation of the changed part of the Modelica model.
[0023] Optionally, the integrating process in the step 4 comprises:
[0024] The mapping table of model component abstract syntax tree and intermediate representation is updated;
[0025] According to the component hierarchical relationship of the Modelica model, the model component argument tree is spliced to obtain a complete argument tree of the Modelica model;
[0026] The behavior list of the component is combined to obtain a complete behavior list of the Modelica model.
[0027] According to a second aspect of the present application, a Modelica model-oriented incremental compilation system is provided, comprising a model parser, a model change detection and dependency analysis module, a model instantiation module and a model integration module;
[0028] The model parser is configured to perform keyword matching on the Modelica model text after editing and modification to obtain an abstract syntax tree of the Modelica model; the abstract syntax tree comprises definitions and behaviors of each component in the Modelica model;
[0029] The model change detection and dependency analysis module is configured to determine a changed part of the Modelica model after editing and modification based on the abstract syntax tree and the last change;
[0030] The model instantiation module is configured to instantiate the changed part of the Modelica model into an intermediate representation; the intermediate representation comprises a variable tree of components and a sequence of component behavior programs;
[0031] The model integration module is configured to integrate the intermediate representations of the changed part and the unchanged part of the Modelica model to obtain a complete representation of the Modelica model.
[0032] According to a third aspect of the present application, an electronic device is provided, comprising a memory and a processor, wherein the processor is configured to implement the steps of the Modelica model-oriented incremental compilation method when executing a computer management program stored in the memory.
[0033] According to a fourth aspect of the present application, a computer readable storage medium is provided, wherein a computer management program is stored on the computer readable storage medium, and the computer management program is configured to implement the steps of the Modelica model-oriented incremental compilation method when executed by a processor.
[0034] The Modelica model-oriented incremental compilation method, system, electronic device and storage medium provided by the present application support compiling only the modified part of a model and the part affected by the modified part when the model is locally modified, and obtain a complete representation of the model by integrating the intermediate representation of the unchanged part, thereby reducing the time consumption of complete model compilation and improving modeling efficiency. Meanwhile, the problem of long waiting time for users to compile after frequently modifying the model is avoided, and the use experience of the modeling tool is improved. When the modified part of the model is incrementally compiled, only the compilation diagnostic information of the modified part is output, the focus is on the part modified by the user, and the large amount of diagnostic information generated by complete model compilation is avoided to interfere with the user, thereby facilitating the user to locate the model problem through the diagnostic information. BRIEF DESCRIPTION OF DRAWINGS
[0035] Figure 1 A flowchart of a Modelica model-oriented incremental compilation method provided by an embodiment of the present application;
[0036] Figure 2 A model change detection flowchart provided by an embodiment of the present application;
[0037] Figure 3 A model dependency analysis flowchart provided by an embodiment of the present application;
[0038] Figure 4 A model integration flowchart provided by an embodiment of the present application;
[0039] Figure 5 A principle flowchart provided by an embodiment of the present application;
[0040] Figure 6 A possible hardware structure schematic diagram of an electronic device provided by the present application is shown in the following figure:
[0041] Figure 7 A possible hardware structure schematic diagram of a computer readable storage medium provided by the present application is shown in the following figure. DETAILED DESCRIPTION
[0042] The principles and features of the present application are described below in conjunction with the accompanying drawings, and the examples are only used to explain the present application and not to limit the scope of the present application.
[0043] Figure 1 A flow chart of a Modelica model-oriented incremental compilation method provided by an embodiment of the present application is shown in the following figure: Figure 1 The compilation method comprises the following steps:
[0044] Step 1: keyword matching is performed on the edited and modified Modelica model text to obtain an abstract syntax tree of the Modelica model; the abstract syntax tree comprises the definition and behavior of each component in the Modelica model.
[0045] Step 2: based on the abstract syntax tree and the changes in the last time, the changed part of the Modelica model editing and modification is determined.
[0046] Step 3: the changed part of the Modelica model is instantiated into an intermediate representation; the intermediate representation comprises a component argument tree and a component behavior list.
[0047] The intermediate representation of the component definition after compilation is the argument tree of the component, and the intermediate representation of the component behavior after compilation is the component behavior list, which represents the variable structure and behavior logic of the model component.
[0048] Step 4: the intermediate representations of the changed part and the unchanged part of the Modelica model are integrated to obtain a complete representation of the Modelica model.
[0049] The present application provides a compilation method suitable for large-scale complex Modelica models, which is based on an incremental Modelica model compilation method. The method can identify and only compile the changed part of the Modelica model and the part affected by the change during the compilation of the Modelica model, thereby significantly reducing the model compilation time and improving the modeling efficiency. At the same time, only the modified model and the part affected by the modification are compiled, and the compilation diagnostic information can be focused on the part modified by the user, which facilitates the user to locate the model problem by checking.
[0050] Embodiment 1
[0051] The embodiment 1 provided by the application is an embodiment of the modelica model-oriented incremental compilation method provided by the application, which is combined with Figure 1 It can be known that the embodiment of the compilation method comprises:
[0052] Step 1, keyword matching is performed on the edited and modified Modelica model text to obtain an abstract syntax tree of the Modelica model; the abstract syntax tree comprises definitions and behaviors of each component in the Modelica model.
[0053] In an embodiment, the process of obtaining the abstract syntax tree of the Modelica model in step 1 comprises:
[0054] A Modelica keyword matching list is set.
[0055] The Modelica model text is parsed byte by byte, and when a keyword in the Modelica keyword matching list is matched, the content corresponding to the keyword is extracted to generate an abstract syntax tree.
[0056] In an embodiment, the keywords in the Modelica keyword matching list comprise model definition, model name, component definition in the model, component name, model equation and end symbol.
[0057] The content corresponding to the keyword is extracted to generate an abstract syntax tree, which comprises: extracting the description corresponding to the component definition to generate an abstract syntax tree structure representing the definition and behavior of the component, and extracting the description corresponding to the model equation to generate an abstract syntax tree structure representing the meaning of the equation.
[0058] In a specific implementation, one embodiment of the abstract syntax tree of the model obtained by performing lexical and syntax analysis on the Modelica model text according to the Modelica specification definition in the Modelica keyword matching list comprises:
[0059] The Modelica model text is as follows:
[0060] Model test
[0061] Real a;
[0062] equation
[0063] a = time;
[0064] end test;
[0065] The model parsing process is as follows:
[0066] Firstly, the Modelcia keyword "Model" is matched, which represents a model definition, and the model name, i.e., test, is obtained, and an abstract syntax tree structure of the model test is obtained (including the model name); the next matched Modelcia keyword is "Real", which represents a real component definition, and the component name, i.e., a, is obtained, and an abstract syntax tree structure of the component a is obtained (including the component name and the component type), and the abstract syntax tree of the component a is added to the abstract syntax tree of the model test; the next matched keyword is "equation", which represents a model equation area, and the content after the keyword is a model equation description; the next keyword is "=", which represents an equal equation, and the expressions on the left and right sides of "=" represent expressions having an equal relationship, where "a" represents a component name, and "time" is a Modelcia keyword, representing time, and an equal equation abstract syntax tree is obtained: the component with the name "a" is equal to time (time), and the equal equation abstract syntax tree is added to the abstract syntax tree of the model test; finally, the Modelcia keyword "end" is matched, which represents the end of a model, and the model name after the keyword should be consistent with the model name obtained by the previous parsing, i.e., test.
[0067] After the parsing is completed, an abstract syntax tree of the model test is obtained, which includes an abstract syntax tree of the real (Real) component a and an abstract syntax tree of the equal equation (a = time), and respectively represents the definition and behavior of the component in the model.
[0068] If the change is not legal, an error prompt is given to help the user locate and modify.
[0069] In a possible embodiment, the abstract syntax tree further includes a model name; the definition of a component in the Modelcia model includes a component type and a component name, and the behavior of the component includes a component behavior statement obtained based on a component equation behavior.
[0070] Step 2: determining a changed part of the Modelcia model based on the abstract syntax tree and the change in the last time.
[0071] Step 3: instantiating the changed part of the Modelcia model into an intermediate representation; the intermediate representation includes a component argument tree and a component behavior list.
[0072] In a possible embodiment, step 3 includes:
[0073] When the Modelcia is compiled for the first time, the Modelcia model is completely compiled to obtain the intermediate representation of all components, and a mapping table of the generated model abstract syntax tree and the intermediate representation is constructed.
[0074] After the Modelica model is edited and modified, all components of the Modelica model are traversed, and if the abstract syntax tree of any component does not have a corresponding intermediate representation in the mapping table, it is determined that the component is modified, and the intermediate representation of each modified component is generated as the intermediate representation of the changed part of the Modelica model, and the mapping table is correspondingly modified.
[0075] As shown in Figure 2 Fig. 1 is a schematic diagram of a model change detection process provided by an embodiment of the present application, and Fig. 2 is a schematic diagram of a model dependency analysis process provided by an embodiment of the present application. Figure 2 As can be seen from
[0076] When the model is edited and modified, the modified part is immediately parsed to obtain the abstract syntax tree of the modified part, and the abstract syntax tree before modification is updated and replaced (invalidated). At this time, the abstract syntax tree of the modified part has not been recompiled, and thus does not have a corresponding intermediate representation, so the intermediate representation cannot be found in the mapping table. When the model is incrementally compiled, the components in the model are traversed, and if the abstract syntax tree of the component does not have a corresponding intermediate representation in the mapping table, it is indicated that the component is modified and needs to be recompiled. After the modified part is recompiled, a new intermediate representation is obtained, and the old data invalidated in the mapping table is replaced by the new abstract syntax tree after modification and the new intermediate representation to determine the modified part of the model.
[0077] In a possible implementation manner, step 3 further includes:
[0078] After it is determined that any component is modified, the component affected by the modified component is generated according to the topological structure of the Modelica model and variable behavior equation analysis, and the intermediate representation of the affected component is generated as the intermediate representation of the changed part of the Modelica model.
[0079] The component affected by the modified component is invalidated and needs to be recompiled.
[0080] In specific implementation, the mapping table can be represented by a C++ map, and based on the mapping table, the corresponding intermediate representation of the component can be found through the abstract syntax tree of the component.
[0081] The identified component that needs to be recompiled is re-instantiated to obtain the latest intermediate representation, and the compilation diagnostic information of the component is output.
[0082] As shown in Figure 3 Fig. 1 is a schematic diagram of a model change detection process provided by an embodiment of the present application, and Fig. 2 is a schematic diagram of a model dependency analysis process provided by an embodiment of the present application. Figure 3As can be seen, this is a schematic diagram of the model dependency analysis process in this invention. As an example, it determines whether a component is affected by the modification by analyzing the relationship between the component and the modified component in the model. First, it checks whether the component type is a derived type of the modified component. If a derivation relationship exists, a dependency relationship must exist, and it is marked as an affected component. Then, it checks whether the component and its nested component variants reference the modified component. If they do, a dependency relationship may exist, and it is marked as an affected component from the perspective of functional correctness. Finally, it checks whether the equation behavior within the component references the modified component. If it does, it is marked as an affected component.
[0083] Step 4: Integrate the intermediate representations of the changed and unchanged parts of the Modelica model to obtain the complete representation of the Modelica model.
[0084] In one possible embodiment, the integration process in step 4 includes:
[0085] Update the abstract syntax tree and intermediate representation mapping table of the model components.
[0086] The complete variable tree of the Modelica model is obtained by splicing the variable trees of the model components according to the component hierarchy of the Modelica model.
[0087] The behavior lists of the components are merged to obtain the complete behavior list of the Modelica model.
[0088] like Figure 4 The diagram shown is a schematic representation of the model integration process provided in an embodiment of the present invention. Figure 4 As can be seen, in one embodiment, the intermediate data representation obtained by instantiating the changed part of the model is integrated with the intermediate representation of the unchanged part to obtain the complete representation of the model. The intermediate representation obtained by recompiling the components includes the component variable tree and the component behavior list. First, the component variables are concatenated to the parent component variable tree, and then concatenated layer by layer according to the model hierarchy to obtain the complete edge variable tree of the model. Then, the component behavior list is merged into the model behavior list to obtain the complete model behavior list. Finally, the mapping table between the model component abstract variable tree and the intermediate representation is updated.
[0089] Example 2
[0090] Embodiment 2 provided by this invention is an embodiment of an incremental compilation system for the Modelica model provided by this invention. Figure 1 This invention provides an incremental compilation system architecture diagram for the Modelica model, combined with... Figure 2 It is known that the implementation of this compilation system includes: a model parser, a model change detection and dependency analysis module, a model instantiation module, and a model integration module.
[0091] a model parser configured to perform keyword matching on the edited Modelica model text to obtain an abstract syntax tree of the Modelica model, wherein the abstract syntax tree comprises definitions and behaviors of components in the Modelica model.
[0092] The main function of the model parser is to parse the Modelica model into an abstract syntax tree (AST), and the subsequent compilation process is based on the abstract syntax tree of the model.
[0093] a model change detection and dependency analysis module configured to determine the changed part of the Modelica model based on the abstract syntax tree and the previous change.
[0094] a model instantiation module configured to instantiate the changed part of the Modelica model into an intermediate representation, wherein the intermediate representation comprises a component argument tree and a component behavior program sequence.
[0095] a model integration module configured to integrate the intermediate representations of the changed part and the unchanged part of the Modelica model to obtain a complete representation of the Modelica model.
[0096] It can be understood that the incremental compilation system for Modelica models provided by the present application corresponds to the incremental compilation method for Modelica models provided by the above-mentioned embodiments, and the related technical features of the incremental compilation system for Modelica models can refer to the related technical features of the incremental compilation method for Modelica models, which will not be repeated here.
[0097] Embodiment 3
[0098] Embodiment 3 provided by the present application is a specific application embodiment of the incremental compilation method for Modelica models provided by the present application. The abstract syntax tree mainly includes: model name, component definition in the model (abstract syntax tree, including: component type, component name), component behavior (abstract syntax tree), and the behavior of all components is the model behavior. The compilation process is to obtain the intermediate representation of the model based on the abstract syntax tree of the model, and the component intermediate representation mainly includes: component argument tree (intermediate representation after component definition compilation), behavior statement (intermediate representation after component behavior compilation), and the compilation process is as follows:
[0099] Step 1, Modelica model is hierarchical, model components can contain other components, according to the hierarchical relationship of model components are compiled layer by layer, component type for Modelica basic type (including: Real, Integer, Boolean, String, Enumeration) components for the most basic components, can not contain other components. When the component is compiled (also known as instantiation), first based on the abstract syntax tree of the component to determine the name, type and dimension of the component itself, get the component argument, if the component is not a Modelica basic type, then also need to handle the internal components of the component, the argument of the internal component is spliced to the parent argument of the upper layer, the internal argument is as a child argument of the upper layer father argument, layer by layer, finally get the complete argument tree of the model.
[0100] Step 2, the compilation process is based on the abstract syntax tree of the equation behavior of the component, and the component behavior statement is instantiated, the instantiation process is mainly to find the specific component variable pointed to by the component name recorded in the equation behavior abstract syntax tree, and finally build the behavior statement between the variables.
[0101] Examples are as follows:
[0102] Model
[0103] Model A
[0104] Model B
[0105] Real b;
[0106] equation
[0107] b = time;
[0108] end B;
[0109] B x;
[0110] Real a;
[0111] equation
[0112] a = x.b;
[0113] end A;
[0114] The compilation process is as follows:
[0115] Step 3, compiling model A, first instantiating components in A, including: component x and component a, wherein component x is not a Modelica basic type, thus when instantiating component x to obtain argument x, its internal component is also instantiated, the internal component b is a Modelica basic type, and is directly instantiated to obtain argument b, and argument b is spliced to argument x; after component x is instantiated, component a is instantiated, and component a is a Modelica basic type, and is directly instantiated to obtain argument a.
[0116] Step 4, after the component instantiation is completed, the component behavior is instantiated, wherein the type B of component x contains the internal component b and the behavior "b = time" of component b, when the "b = time" is instantiated, the component argument b pointed to by the string "b" is found according to the string "b", and the string "time" represents time, and finally the behavior statement "argument b is equal to time" is obtained; the model A contains the behavior "a = x.b" of component a, and when the behavior "a = x.b" is instantiated, the component argument a pointed to by the string "a" is found according to the string "a", and the internal argument b in the argument x is found according to the string "x.b", and finally the behavior statement "argument a is equal to the internal argument b in the argument x" is obtained.
[0117] Step 5, after the instantiation of all components in the model is completed, the complete argument tree and the behavior statement of the model are obtained, that is, the complete intermediate representation of the model.
[0118] As Figure 5 The principle flowchart of the embodiment provided by the application is shown, and Figure 5 It can be known that the implementation principle of the incremental compilation method for the Modelica model provided by the application is specifically as follows:
[0119] S101: The model parser parses the model text into an abstract syntax tree according to the Modelica specification, for subsequent compilation processes.
[0120] S102: The model change detection module checks the abstract syntax tree of the model component and the mapping table of the intermediate representation, and obtains the modified part of the model.
[0121] S103: The model change dependency analysis module analyzes the components affected by the modified components in the model according to the topological structure of the model and the variable behavior equation, and the affected components are also regarded as modified components.
[0122] S104: The modified model component is instantiated to obtain the component intermediate representation.
[0123] S105: The intermediate representation of the modified component and the intermediate representation of the unchanged part are integrated to obtain the complete representation of the model.
[0124] S106: update the model component abstract syntax tree and intermediate representation mapping table.
[0125] Please refer to Figure 6 , Figure 6 The embodiment of the electronic device provided by the embodiment of the present application is shown. As shown in Figure 6 , the embodiment of the present application provides an electronic device, which comprises a memory 1310, a processor 1320, and a computer program 1311 stored in the memory 1310 and executable on the processor 1320. When the processor 1320 executes the computer program 1311, the following steps are implemented: performing keyword matching on the edited and modified Modelica model text to obtain an abstract syntax tree of the Modelica model; the abstract syntax tree comprises definitions and behaviors of each component in the Modelica model; determining a changed part of the Modelica model edited and modified based on the abstract syntax tree and the last change; instantiating the changed part of the Modelica model into an intermediate representation; the intermediate representation comprises: a component argument tree and a component behavior list; and integrating the intermediate representations of the changed part and the unchanged part of the Modelica model to obtain a complete representation of the Modelica model.
[0126] Please refer to Figure 7 , Figure 7 The embodiment of the computer readable storage medium provided by the present application is shown. As shown in Figure 7 , the embodiment provides a computer readable storage medium 1400, which stores a computer program 1411. When the computer program 1411 is executed by a processor, the following steps are implemented: performing keyword matching on the edited and modified Modelica model text to obtain an abstract syntax tree of the Modelica model; the abstract syntax tree comprises definitions and behaviors of each component in the Modelica model; determining a changed part of the Modelica model edited and modified based on the abstract syntax tree and the last change; instantiating the changed part of the Modelica model into an intermediate representation; the intermediate representation comprises: a component argument tree and a component behavior list; and integrating the intermediate representations of the changed part and the unchanged part of the Modelica model to obtain a complete representation of the Modelica model.
[0127] The embodiment of the present application provides a kind of Modelica model-oriented incremental compilation method, system, electronic equipment and storage medium, when model is partially modified, support only the compilation of model modification part and the part affected by it, the complete representation of model is obtained by integrating with the intermediate representation of unchanged part, reduce the time consumption of model complete compilation, improve modeling efficiency.Modeling tool is also avoided after the user is frequently modified model and is compiled to need long time waiting problem, improve the use experience of modeling tool.When the incremental compilation of model modification part is carried out, only the compilation diagnostic information of modification part is output, focus on the part of user modification, avoid the interference caused to user by a large amount of diagnostic information generated by model complete compilation, facilitate user to locate model problem by diagnostic information.
[0128] It should be noted that in the above embodiments, the description of each embodiment has its own emphasis, and the parts not described in detail in a certain embodiment can be referred to the related description of other embodiments.
[0129] Those skilled in the art should understand that the embodiments of the present application can be provided as a method, a system or a computer program product. Therefore, the present application can adopt a completely hardware embodiment, a completely software embodiment or an embodiment combining software and hardware aspects. Moreover, the present application can adopt the form of a computer program product implemented on one or more computer usable storage media containing computer usable program code (including but not limited to disk storage, CD-ROM, optical storage, etc.).
[0130] The present application is described with reference to flowcharts and / or block diagrams according to the method, device (system) and computer program product of the embodiments of the present application. It should be understood that each flow and / or block in the flowcharts and / or block diagrams, and the combination of flows and / or blocks in the flowcharts and / or block diagrams can be realized by computer program instructions. These computer program instructions can be provided to the processor of a general-purpose computer, a special-purpose computer, an embedded computer or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device produce a device for implementing the functions specified in the flowcharts and / or block diagrams. Figure 1 The functions specified in one flow or multiple flows and / or blocks Figure 1 The functions specified in one block or multiple blocks.
[0131] These computer program instructions can also be stored in a computer readable storage medium, which can guide the computer or other programmable data processing device to work in a specific way, so that the instructions stored in the computer readable storage medium produce a product including instruction devices, which implement the functions specified in the flowcharts and / or block diagrams. Figure 1 The functions specified in one flow or multiple flows and / or blocks Figure 1 The functions specified in one block or multiple blocks.
[0132] These computer program instructions can also be loaded into computer or other programmable data processing devices, so that a series of operations steps are performed on the computer or other programmable devices to generate computer-implemented processes, thus the instructions executed on the computer or other programmable devices provide the function of realizing the processes specified in the flowcharts Figure 1 one flowchart or multiple flowcharts and / or blocks Figure 1 one block or multiple blocks to realize the function specified in the flowcharts
[0133] Although the preferred embodiments of the application have been described, those skilled in the art will be able to make additional modifications and variations to these embodiments without departing from the spirit and scope of the application. Accordingly, it is intended that the appended claims be construed to include all such modifications and variations as fall within the scope of the application.
[0134] Obviously, various modifications and changes are possible in the present application without departing from the spirit and scope of the application. It is to be understood that the application includes any such modifications and changes only insofar as they come within the scope of the appended claims and their equivalents.
Claims
1. A method for incremental compilation of a Modelica model, characterized in that, The compiling method comprises: Step 1, keyword matching is performed on the Modelica model text after editing modification to obtain an abstract syntax tree of the Modelica model; the abstract syntax tree comprises definitions and behaviors of each component in the Modelica model; Step 2, based on the abstract syntax tree and the changes in the last time, the changed part of the Modelica model after editing modification is determined; Step 3, the changed part of the Modelica model is instantiated into an intermediate representation; the intermediate representation comprises a component argument tree and a component behavior list; Step 4, the intermediate representations of the changed part and the unchanged part of the Modelica model are integrated to obtain a complete representation of the Modelica model; The step 3 comprises: When the Modelica is compiled for the first time, the Modelica model is completely compiled to obtain intermediate representations of all components, and a mapping table of the generated model abstract syntax tree and the intermediate representation is constructed; After the Modelica model is edited and modified, all components of the Modelica model are traversed, and when the abstract syntax tree of any component does not have a corresponding intermediate representation in the mapping table, it is judged that the component is modified, the intermediate representation of each modified component is generated as the intermediate representation of the changed part of the Modelica model, and the mapping table is correspondingly modified.
2. The method of claim 1, wherein, The process of obtaining the abstract syntax tree of the Modelica model in the step 1 comprises: Setting a Modelica keyword matching list; The Modelica model text is parsed byte by byte, when a keyword in the Modelica keyword matching list is matched, the content corresponding to the keyword is extracted to generate the abstract syntax tree.
3. The compiling method of claim 2, wherein, The keywords in the Modelica keyword matching list comprise model definition, model name, component definition in the model, component name, model equation and end symbol; Extracting the content corresponding to the keyword to generate the abstract syntax tree comprises extracting the description corresponding to the component definition to generate an abstract syntax tree structure representing the definition and behavior of the component, and extracting the description corresponding to the model equation to generate an abstract syntax tree structure representing the meaning of the equation.
4. The compiling method of claim 3, wherein, The abstract syntax tree further comprises a model name; the definition of the component in the Modelica model comprises a component type and a component name, and the behavior of the component comprises a component behavior statement obtained based on a component equation behavior.
5. The method of claim 1, wherein, The step 3 further comprises: After it is judged that any component is modified, the components affected by the modified component are generated according to the topological structure and variable behavior equation of the Modelica model, and the intermediate representation of the affected component is generated as the intermediate representation of the changed part of the Modelica model.
6. The method of claim 1, wherein, The integration process in the step 4 comprises: Updating the mapping table of the model component abstract syntax tree and the intermediate representation; According to the component hierarchical relationship of the Modelica model, the model component argument tree is spliced to obtain a complete argument tree of the Modelica model; The behavior list of the components is combined to obtain a complete behavior list of the Modelica model.
7. A Modelica model oriented incremental compilation system, characterized in that, The compiling system comprises a model parser, a model change detection and dependency analysis module, a model instantiation module and a model integration module. The model parser is configured to perform keyword matching on the Modelica model text after the editing modification to obtain an abstract syntax tree of the Modelica model; the abstract syntax tree comprises definitions and behaviors of each component in the Modelica model. The model change detection and dependency analysis module is configured to determine a changed part of the Modelica model based on the abstract syntax tree and a previous change. The model instantiation module is configured to instantiate the changed part of the Modelica model into an intermediate representation; the intermediate representation comprises a component argument tree and a component behavior flow sequence. The model integration module is configured to integrate the intermediate representations of the changed part and the unchanged part of the Modelica model to obtain a complete representation of the Modelica model. The model instantiation module comprises: When the Modelica is compiled for the first time, the Modelica model is completely compiled to obtain intermediate representations of all components, and a mapping table of model abstract syntax trees and intermediate representations is constructed; After the Modelica model is edited and modified, all components of the Modelica model are traversed, and when an abstract syntax tree of an arbitrary component has no corresponding intermediate representation in the mapping table, it is determined that the component is modified, and the intermediate representation of each modified component is generated as the intermediate representation of the changed part of the Modelica model, and the mapping table is modified correspondingly.
8. An electronic device, comprising: A memory and a processor are included, and the processor is configured to execute a computer management program stored in the memory to implement the steps of the Modelica model-oriented incremental compiling method according to any one of claims 1-6.
9. A computer-readable storage medium, characterized in that, A computer management program is stored on the memory, and the computer management program is executed by the processor to implement the steps of the Modelica model-oriented incremental compiling method according to any one of claims 1-6.
Citation Information
Patent Citations
Verilog syntactic analysis method based on incremental compiling
CN117270863A