A kind of analysis and method for supervising of C Language Simulation model
Technical field
The present invention relates to the computer simulation technique field, relate in particular to a kind of analysis and method for supervising of C Language Simulation model.
Background technology
The core of computer simulation technique comprises realistic model and emulation platform.Realistic model is to by the abstractdesription of artificial physical plant characteristic, has mathematics similar with entity and physical attribute, the characteristic and the rule of reflection entity.The description of realistic model can be through various computereses such as formula translation, C language, M language etc.; According to the realization of encoding of corresponding codes rule, also can carry out building of basic mathematical computing module such as addition subtraction multiplication and division through modeling tool such as MATLAB/Simulink with the mode that plays with building blocks and realize.The realistic model of no matter with which kind of mode describing finally all need be compiled into executable application program, downloads to carry out emulation on the emulation platform and resolve.
Emulation platform is the carrier that realistic model resolves, and is made up of software and hardware, and is corresponding, and real-time simulation platform is made up of the real-time oss simulation computer of unifying.In order to realize real-time simulation, promptly the realistic model real-time resolving is carried out data interaction with peripherals in real time, then need the realistic model compiling be downloaded to and implement to move on the emulation platform.Therefore, complete real-time simulation platform generally includes emulation host computer and emulation slave computer.Emulation management software of emulation host computer operation; Be responsible for carrying out the model compiling the model of describing through computerese or through the model that modeling tool is built; Generate executable application program, and download to the emulation slave computer through network communications such as Ethernets.The emulation slave computer is responsible for real-time resolving and has been compiled the realistic model that generates executable application programs.When model when the emulation slave computer carries out emulation and resolves; Whether the emulation host computer need extract the variable data in the realistic model, and online instant playback, correct so that the clear understanding of emulation personnel realistic model resolves the result; Simultaneously; The emulation personnel can carry out manual intervention, and the parameter in the online modification realistic model makes realistic model resolve according to the result of emulation personnel budget.In order to realize to realistic model built-in variable Parameter Extraction and modification; Carry out before real-time simulation resolves at realistic model; Need analyze realistic model; Promptly, comprise that function name and parametric variable name thereof and variable number, module parameter, global variable etc. extract, and are kept in the message file to the information in the realistic model.
At present; For the model that uses modeling tool MATLAB/Simulink to build, can realize analysis through the TLC template file of revising MATLAB/Simulink and providing to realistic model, and for the analysis of the realistic model that uses C speech encoding rule to write; Domestic also do not have a suitable method; Can only it be built into the MATLAB/Simulink model again at present, just can realize parsing process through the TLC template file again, unnecessary, much repeated work that this method will cause.In addition, in practical engineering application, most of realistic models are to adopt the C language, if can not analyze the C language, will limit C Language Simulation application of model scope.
Summary of the invention
In view of this, the invention provides a kind of analysis and method for supervising of C Language Simulation model, be used to solve existing analysis and method for supervising can cause unnecessary, repeat the problem of work in a large number.
A kind of method for decomposing of C Language Simulation model; Generate C code method for decomposing class by grammatical file in advance; Said grammatical file under speech recognition too development environment by developer's hand-coding; Wherein, generate after said C code method for decomposing class compiles grammatical file by the speech recognition instrument, it comprises syntax Analysis Module, Lexical Analysis Module and syntax tree generation module;
This method comprises:
The Lexical Analysis Module of calling in the C code method for decomposing class is analyzed the morphology content of the C Language Simulation model of importing, forms mark stream;
Call the syntax Analysis Module in the C code method for decomposing class,, the syntactic structure of the C Language Simulation model that imports is analyzed according to said mark stream;
Call the syntactic structure that the syntax tree generation module in the C code method for decomposing class obtains according to said analysis and generate corresponding syntax tree;
From said syntax tree, extract variable information and function information, and the variable information and the function information of said extraction is saved in the model information file.
Preferably, said speech recognition instrument is the speech recognition instrument ANTLR that increases income.
The compiling procedure of said grammatical file comprises:
Confirm the integral frame of grammatical file; The content of said grammatical file is divided into: head module, option mod, syntax analyzer generic module and lexical analyzer generic module, said head module and said option mod are used to define the essential information of grammatical file; Said syntax analyzer generic module; Be used to define the grammatical analysis content that grammatical file comprises, said lexical analyzer generic module is used for the lexical analysis content that comprises due to grammatical file;
Define the grammatical analysis content that grammatical file comprises;
Define the lexical analysis content that grammatical file comprises;
Add distinctive Jave class methods, said distinctive Jave class methods are that said ANTLR has generated not but carries out the C code and analyze needed distinctive java class method.
Said grammatical analysis content comprises: data type sign, structure or community's sign, data structure variable list sign, enumeration type sign, variable number group id, pointer mark, parameter list sign, identifier list sign.
Said lexical analysis content comprises: character type variable sign, special character sign, 16 systems sign, 10 systems sign, 8 systems sign, floating number sign, piece note form sign, row note sign.
Said C code method for decomposing class is C code method for decomposing java class, C code method for decomposing C++ class or C code method for decomposing C# class.
A kind of method for supervising of C Language Simulation model comprises:
Host computer emulation management software calls the C CompilerTools C Language Simulation model that imports is compiled, and compiling generates executable application program;
Host computer emulation management software adopts the method for decomposing of above-mentioned C Language Simulation model that the C Language Simulation model that imports is analyzed;
Host computer emulation management software downloads to the emulation slave computer with said executable application programs, carries out the real-time resolving of model;
Host computer emulation management software is given the variable information in the model information file and is extracted the model variable that will monitor in emulation personnel and the variable information from said model information file through showing interface; And the said model parameter that will monitor sent to the emulation slave computer; The emulation slave computer is according to variable name; From internal memory, extract the data of corresponding said variable name; Returning to host computer emulation management software shows; If variable is made amendment, the variable name that then directly will revise and corresponding data thereof send to the emulation slave computer, and the emulation slave computer is write the corresponding data of the said variable name that will revise in the corresponding internal memory of the said variable name that will revise.
The invention provides a kind of analysis and method for supervising of C Language Simulation model, this method is write grammatical file in advance and is generated C code method for decomposing class, through using C code method for decomposing class C Language Simulation model is analyzed and is monitored, and implementation procedure is simple.Method provided by the invention has been filled up the blank of present domestic C Language Simulation model analysis and monitoring technique, and the grammatical file content of writing is complete, goes for the analysis and the monitoring requirement of most of C Language Simulation model.
Description of drawings
In order to be illustrated more clearly in the embodiment of the invention or technical scheme of the prior art; To do to introduce simply to the accompanying drawing of required use in embodiment or the description of the Prior Art below; Obviously, the accompanying drawing in describing below only is embodiments of the invention, for those of ordinary skills; Under the prerequisite of not paying creative work, can also obtain other accompanying drawing according to the accompanying drawing that provides.
The process flow diagram of the method for decomposing of the C Language Simulation model that Fig. 1 provides for the embodiment of the invention one;
The compiling procedure figure of the grammatical file that Fig. 2 provides for the embodiment of the invention one;
The process flow diagram of the method for supervising of the C Language Simulation model that Fig. 3 provides for the embodiment of the invention two.
Embodiment
To combine the accompanying drawing in the embodiment of the invention below, the technical scheme in the embodiment of the invention is carried out clear, intactly description, obviously, described embodiment only is the present invention's part embodiment, rather than whole embodiment.Based on the embodiment among the present invention, those of ordinary skills are not making the every other embodiment that is obtained under the creative work prerequisite, all belong to the scope of the present invention's protection.
Embodiment one
The embodiment of the invention one provides a kind of method for decomposing of C Language Simulation model; Before this method of execution; Generate C code method for decomposing class by grammatical file in advance; C code method for decomposing class comprises syntax Analysis Module, Lexical Analysis Module and syntax tree generation module, the process flow diagram of the method for decomposing that Fig. 1 provides for the embodiment of the invention, and this method comprises:
S11: the Lexical Analysis Module of calling in the C code method for decomposing class is analyzed the morphology content of the C Language Simulation model of importing, forms mark stream;
S12: call the syntax Analysis Module in the C code method for decomposing class,, the syntactic structure of the C Language Simulation model that imports is analyzed according to mark stream;
S13: call the syntactic structure that the syntax tree generation module in the C code method for decomposing class obtains according to analysis and generate corresponding syntax tree;
S14: from syntax tree, extract variable information and function information, and variable information and the function information extracted are saved in the model information file.
Wherein, by developer's hand-coding, C code method for decomposing class generates after compiling grammatical file by the speech recognition instrument grammatical file under speech recognition too development environment.In the present embodiment, the speech recognition instrument is the speech recognition instrument ANTLR that increases income.
In the present embodiment, compiling procedure such as Fig. 2 of grammatical file are said, comprising:
S21: the integral frame of confirming grammatical file; The content of grammatical file is divided into: head module header, option mod options, syntax analyzer generic module parser and lexical analyzer generic module lexer; Wherein, head module header and option mod options are used to define the essential information of grammatical file; Syntax analyzer generic module parser; Be used to define the grammatical analysis content that grammatical file comprises, lexical analyzer generic module lexer is used for the lexical analysis content that comprises due to grammatical file;
S22: define the grammatical analysis content that grammatical file comprises, comprise data type sign (like void type, char type, float type etc.), structure or community's sign, data structure variable list sign, enumeration type sign, variable data sign, pointer mark, parameter list sign, identifier list sign.Wherein, the type that in data type sign, comprises also that simulink is distinctive, do not have in the standard C; Like int8_T, cuint16_T etc., after identifying, be programmed in the type_specifier position of grammatical file according to the ANTLR grammar rule; For example, the literary style during the definition of data type is: key word (type_specifier), put in a colon (:) of entering a new line; After add data type identification (sign adds single quotation marks); If a plurality of data types of link definition, then line feed adds " | " and connects the data type sign after again, and is as follows:
type_specifier
:′void′
|′char′
|′short′
|′int′
|′long′
|′float′
|′double′
……
S23: define the lexical analysis content that grammatical file should comprise; Comprise: character type variable sign, n etc. special character sign, 16 systems sign, 10 systems sign, 8 systems sign, floating number sign, piece note form sign, row note sign; After sign is come out; Be programmed in the relevant position of grammatical file by the ANTLR grammar rule, for example, the definition of 16 systems sign is following:
HEX_LITERAL:′0′(′x′|′X′)HexDigit+IntegerTypeSuffix?
S24: add distinctive Jave class methods; Promptly add ANTLR and generated not, analyze needed distinctive Java method, like the method for decomposing of constructed fuction part but carry out the C code; Addition manner is to add self-defining special member function code through key word member; Through key word lexer::header, add self-defining java class, as:
lexer::header{
package?com.hirain.hisim.redundancy.parse.antlr;
}
In the present embodiment, the grammatical file after having write is compiled, generate C code method for decomposing java class, also can generate C code method for decomposing C++ class, C# class certainly.Wherein, C code method for decomposing java class comprises Lexer class (morphology class) and two class files of Parser class (syntactic class).This C code method for decomposing java class is copied under the emulation host computer respective path; Supply host computer emulation management software to call; The corresponding module that the sequence call C code method for decomposing class that host computer emulation management software is set according to lexical analysis, grammatical analysis and generative grammar provides; From the comprehensive syntax tree tree structure of content, extract needed content then, and the content of extracting is saved among the model information file .hisim, wherein; Comprise all information such as function name, parametric variable name, variable number, global variable in the tree structure, cover all information of grammatical file defined.
When on the emulation host computer, importing a C Language Simulation model; Host computer emulation management software can call C code method for decomposing java class automatically; C Language Simulation model to importing is analyzed, the generation model message file, thus realize analysis purpose to C Language Simulation model.
The method for decomposing of the C Language Simulation model that provides through the embodiment of the invention when C Language Simulation model is analyzed, will it not be built into the MATLAB/Simulink model and analyze again, and therefore, implementation procedure is simple.
Embodiment two
The embodiment of the invention two provides a kind of method for supervising of C Language Simulation model, the process flow diagram of the method for supervising that Fig. 3 provides for the embodiment of the invention, and this method comprises:
S31: host computer emulation management software calls the C CompilerTools C Language Simulation model that imports is compiled, and compiling generates executable application program;
S32: host computer emulation management software adopts the method for decomposing of the C Language Simulation model among the embodiment one that the C Language Simulation model that imports is analyzed;
S33: host computer emulation management software downloads to the emulation slave computer with executable application program, carries out the real-time resolving of model;
S34: the variable information in the model information file that host computer emulation management software will obtain through the method for decomposing of embodiment one is given the emulation personnel through showing interface; And the model variable that extraction will be monitored in the variable information from the model information file; The model parameter that will monitor sends to the emulation slave computer; The emulation slave computer is according to variable name; From internal memory, extract the data of corresponding variable name, return to host computer emulation management software and show, if variable is made amendment; The variable name that then directly will revise and corresponding data thereof send to the emulation slave computer, and the data that the variable name that the emulation slave computer will be revised is corresponding are write in the internal memory of the variable name correspondence that will revise.
The method for supervising of the C Language Simulation model that the embodiment of the invention provides has been filled up the blank of domestic C code analysis and monitoring technique; Make C Language Simulation model realize that in real-time emulation system on-line monitoring becomes possibility; Simultaneously; The use speech recognition instrument ANTLE that increases income realizes the analysis to C Language Simulation model, and implementation procedure is simple, reliable.In addition, the grammatical file content that the embodiment of the invention is write is complete, goes for the requirement that most of C Language Simulation model analysis is used.
To the above-mentioned explanation of the disclosed embodiments, make this area professional and technical personnel can realize or use the present invention.Multiple modification to these embodiment will be conspicuous concerning those skilled in the art, and defined General Principle can realize under the situation that does not break away from the spirit or scope of the present invention in other embodiments among this paper.Therefore, the present invention will can not be restricted to these embodiment shown in this paper, but will meet and principle disclosed herein and features of novelty the wideest corresponding to scope.