CN102156655B - Senior language code generation method and generator - Google Patents

Senior language code generation method and generator Download PDF

Info

Publication number
CN102156655B
CN102156655B CN201110115605.1A CN201110115605A CN102156655B CN 102156655 B CN102156655 B CN 102156655B CN 201110115605 A CN201110115605 A CN 201110115605A CN 102156655 B CN102156655 B CN 102156655B
Authority
CN
China
Prior art keywords
language code
grammer
level language
tree
code
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Expired - Fee Related
Application number
CN201110115605.1A
Other languages
Chinese (zh)
Other versions
CN102156655A (en
Inventor
谢峥
王新安
曹颖
陈旭
雍珊珊
王腾
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Peking University Shenzhen Graduate School
Original Assignee
Peking University Shenzhen Graduate School
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Peking University Shenzhen Graduate School filed Critical Peking University Shenzhen Graduate School
Priority to CN201110115605.1A priority Critical patent/CN102156655B/en
Publication of CN102156655A publication Critical patent/CN102156655A/en
Application granted granted Critical
Publication of CN102156655B publication Critical patent/CN102156655B/en
Expired - Fee Related legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Abstract

The invention discloses a senior language code generator and a senior language code generation method. Input description information of a grammar support situation of an electronic design automation (EDA) design tool and a check or test strategy are converted into a corresponding grammar configuration table and a corresponding control restraint table respectively; a corresponding grammar base is called to construct a grammar tree according to the grammar configuration table and the control restraint table; and the grammar tree is converted into a corresponding executable senior language code. As the constructed grammar tree is in accordance with the grammar configuration table and the control restraint table, the executability of the generated senior language code is guaranteed and the relevance of the code is enhanced so as to simulate an actual algorithm code naturally; therefore, a good test example is provided for guaranteeing the conversion correctness of various code descriptions by various EDA design tools; moreover, the test example has high executability, so that the pressure of manually writing and testing the code is relieved.

Description

Generation method and the generator thereof of higher-level language code
Technical field
The present invention relates to electric design automation (Electronic Design Automation, EDA) checking of Software tool and automatic code generate field, relate in particular to a kind of higher-level language code generator and higher-level language code generation method in the checking flow process of High Level Synthesis design tool exploitation.
Background technology
The EDA technology of integrated circuit (IC) design starts from 20 century 70s.As far back as circuit design aspect, there is SPICE (Simulation program with integrated circuit emphasis, general-purpose simulation circuit emulator), aspect domain making, by manual drawing, changed computer graphics into; There is logic simulator and automatic placement and routing's instrument in early 1980s; There is RTL (Register Transfer Level, Method at Register Transfer Level) level design and simulation and logic synthesis tool in late 1980s, and formal verification and static timing analysis tool; Present the 4th generation eda tool mainly comprise: the constitutional diagram input of recycling design, figure, algorithm synthesis, software and hardware complementary design etc.
From the development trend of EDA, can find out, present Computer Aided Design is gradually to algorithm level and system-level conversion.This is also for tackling present integrated circuit (IC) design company to fast Development and the inevitable trend of the demand such as listing fast.Along with the raising of arthmetic statement abstraction hierarchy, use the advantage of higher level lanquage design system more obvious, deviser is constructing function function fast and compactly, by java standard library and function call technology, creates the system of more complicated high speed.
At present, the support of EDA design tool directly maps out corresponding circuit structure from the arthmetic statement of higher level lanquage, but from higher level lanquage arthmetic statement, be mapped to corresponding circuit structure process the correct conversion that the various forms of algorithmic codes within the scope of the higher level lanquage grammer that is conventionally difficult to guarantee to support at this EDA design tool are described.
Summary of the invention
The main technical problem to be solved in the present invention is, a kind of higher-level language code generator and higher-level language code generation method are provided, by higher-level language code generator of the present invention, and the higher-level language code that higher-level language code production method generates is simplified, there are good correlativity and randomness, make more naturally to simulate actual algorithm code, thereby provide satisfactory higher-level language code test case required when testing or verifying, and guarantee the direct enforceability of the higher-level language code test case of generation, thereby alleviated the pressure of manual compiling test code.
For solving the problems of the technologies described above, the technical solution used in the present invention is as follows:
A higher-level language code generator, comprising:
Grammer configuration module, supports situation descriptor for receiving the grammer of the electronic design automation tool of input, and supports situation descriptor to be converted to corresponding grammer allocation list described grammer;
Control parameter extraction module, for receiving the checking of input or the strategy level descriptor of Test Strategy, and the strategy level descriptor of described checking or Test Strategy is converted into corresponding control restriction table;
Higher level lanquage syntax library, for storing all grammers of the higher level lanquage of needs and lexical element description;
Syntax tree generation module, be connected with described grammer configuration module, higher level lanquage syntax library and control parameter extraction module, for the grammer allocation list generating according to described grammer configuration module, and the control restriction table of described parameter extraction module generation, call grammer and lexical element in described higher level lanquage syntax library, and generate corresponding syntax tree;
Code generation module, is connected with described syntax tree generation module, for the syntax tree that described syntax tree generation module is generated, is converted to accordingly and can carries out higher-level language code file.
Further, described code generation module, also for according to described syntax tree, generates corresponding to the described higher-level language code characteristic description file of carrying out higher-level language code file, and described code generation module comprises:
Code construction submodule, is connected with described syntax tree generation module, for the syntax tree that described syntax tree generation module is generated, travels through and reads, and generates the corresponding higher-level language code carried out file;
Code feature extraction submodule, be connected with degree of conformity detection module with described code construction submodule, for the characteristic of the higher-level language code carried out that record produces when described code construction submodule traversal reads described syntax tree, and produce corresponding higher-level language code characteristic description file.
Further, when user needs specific mark or annotation information, described code construction submodule also for increasing the interface of other quantity of information marks on standard language basis.
Further, described higher-level language code generator also comprises:
Degree of conformity detection module, be connected with control parameter extraction module with described code feature extraction submodule, be used for according to described higher-level language code characteristic description file, and described control restriction table carries out degree of conformity and checks, if described higher-level language code characteristic description file meets described control restriction table, generate the report of corresponding degree of conformity, and export described degree of conformity report, can carry out higher-level language code file and high-level code characteristic description file; When if described higher-level language code characteristic description file does not meet described control restriction table, according to the iterations of the permission setting in advance, automatically adjust inner setting, regenerate the new higher-level language code carried out file.
Further, described syntax tree generation module comprises:
Subtree set generates submodule, be connected with higher level lanquage syntax library with described grammer configuration module, control parameter extraction module, be used for according to described grammer allocation list and control restriction table, class sign or the example of grammer in higher level lanquage syntax library or lexical element of take is node, generates corresponding subtree set;
Subtree merges submodule, generating submodule with described grammer configuration module, control parameter extraction module with subtree set is connected, be used for according to described grammer allocation list and control restriction table, at random each subtree is merged, obtain new subtree set, the leaf node type that the condition of merging is set with another stalk for the root node of the stalk tree in the two stalk trees that will merge is identical;
Total syntax tree generates submodule, merge submodule, grammer configuration module and control parameter extraction module with described subtree and be connected, for using the maximum subtree of the new subtree set node obtaining as main tree, other subtrees are as attached tree, and according to described grammer allocation list and control restriction table, according to the direction of bottom-up extension, at random described main tree and attached tree are carried out to many wheel merging, obtain corresponding total syntax tree.
Further, it is characterized in that, described grammer allocation list comprises: grammer point support information, way of realization constraint information, special grammar phenomenon constraint information; Described control restriction table comprises: process-oriented layout's information of program, variable uses information.
A kind of higher-level language code generation method, comprising:
According to the grammer of the electronic design automation tool of input, support situation descriptor, generate corresponding grammer allocation list;
Strategy level descriptor according to the checking of input or Test Strategy, generates the corresponding restriction table of controlling;
According to described grammer allocation list and control restriction table, call grammer and lexical element in higher level lanquage syntax library, and build corresponding syntax tree by syntax tree construction method;
Described syntax tree is converted to accordingly and can carries out higher-level language code file.
Further, described syntax tree is converted to and can carries out accordingly higher-level language code file and comprise:
Traversal reads described syntax tree, generates and can carry out higher-level language code file accordingly;
When having set specific mark or annotation information, described, generate the higher-level language code corresponding to described specific mark or annotation information in carrying out higher-level language code file.
Further, described method also comprises:
When traversal reads described syntax tree, the characteristic of the higher-level language code carried out that record generates, and generate corresponding higher-level language code characteristic description file;
Detect described higher-level language code characteristic description file and whether meet described control restriction table, if met, generate and export corresponding degree of conformity report, described in output, can carry out higher-level language code file and higher-level language code characteristic description file simultaneously; Otherwise adjust accordingly, and generate the new higher-level language code carried out file.
Further, described syntax tree construction method comprises:
According to described control restriction table and grammer allocation list, class sign or the example of grammer or lexical element of take is node, generates corresponding basic subtree set at random;
According to described control restriction table and grammer allocation list, at random each subtree is merged, generate new subtree set, the leaf node type that the condition of merging is set with another stalk for the root node of the stalk tree in the two stalk trees that will merge is identical;
Using the maximum subtree of node as main tree, other subtree is as attached tree, according to described control restriction table and grammer allocation list, according to the direction of bottom-up extension, at random described main tree and attached tree carried out to many wheels and merges, and generates corresponding total syntax tree.
The invention has the beneficial effects as follows:
Higher-level language code maker of the present invention, supports situation descriptor to be converted to corresponding grammer allocation list the grammer of input by grammer configuration module; By controlling parameter extraction module, the checking of input or Test Strategy are converted to corresponding control restriction table again; Again by syntax tree generation module according to this grammer allocation list with control restriction table, call grammer and lexical element in higher level lanquage syntax library, build corresponding syntax tree, by code generation module, the syntax tree of generation is converted to corresponding executable code again, generates executable code characteristic description file simultaneously.Syntax tree because syntax tree generation module builds, can meet control constraint condition, can guarantee the feasibility of code.The higher-level language code that higher-level language code maker of the present invention generates, there are good correlativity and randomness, guaranteed the simplification of code, make it possible to more naturally simulate actual algorithm code, thereby for guaranteeing that EDA design tool provides the test case of high-quality to the correctness of the conversion of various code descriptions, thereby alleviated the pressure of manual compiling test code.On the other hand, because higher level lanquage syntax library can be modified according to the difference of different eda tool supporting languages, to support other linguistic forms, thereby improved the extensibility of code generator.
Higher-level language code maker of the present invention also generates corresponding higher-level language code characteristic description file simultaneously, user can directly understand the characteristic of the higher-level language code carried out producing by this higher-level language code characteristic description file, thereby be convenient to check that whether the checking of oneself or Test Strategy be corresponding with the code producing, the strategy that soon checking or tester's focus will be transferred to checking or test from writing of test code comes up, and for take conversion that higher level lanquage is starting point or the synthesis tool needed comprehensive test case of design feature separately that meets when test or checking are provided, can instruct according to the characteristic description of this executable file the enforcement of checking or Test Strategy simultaneously, and then further alleviated the pressure of manual compiling code.Whether the higher-level language code that higher-level language code maker of the present invention also can detect generation by degree of conformity detection module suits the requirements, when the higher-level language code producing has problem, again by this degree of conformity detection module in allowing iterations, automatically adjust inner setting, regenerate new higher-level language code, and this iterations upper limit can arrange, that is to say that higher level lanquage maker of the present invention is by being provided with degree of conformity detection module, thereby make this higher-level language code generator can carry out self check.
Higher-level language code generation method of the present invention, by the grammer of input being supported to the strategy level descriptor of situation descriptor and checking or Test Strategy, be converted to respectively corresponding grammer allocation list and control restriction table, again according to this grammer allocation list and control restriction table, call grammer and lexical element in syntax library, and build corresponding syntax tree by syntax tree construction method, by traversal, read this syntax tree generation again and can carry out accordingly higher-level language code and higher-level language code characteristic description file, thereby the strategy that checking or tester's focus is transferred to checking or test from writing of test code comes up, while having avoided using ready-made algorithmic code, grammatical phenomenon is incomplete, measuring point is indefinite, the problem that debugging location is inconvenient, simultaneously, due to constructed syntax tree, all meet and control restriction table, make the higher-level language code being converted to by this syntax tree, have good correlativity and randomness, and the higher-level language code generating is simplified, reduced independent code, thereby make it possible to more naturally simulate actual algorithm code, guaranteed the direct enforceability of the higher-level language code test case of generation, and then alleviated the pressure of manual compiling code.
On the other hand, in higher-level language code generation method of the present invention, the construction method of syntax tree is by random subtree being merged into the mode of main tree, more at random main tree and attached tree merged according to the direction upwards extending, and generates total syntax tree.Because every stalk tree all meets, control constraint condition, make to be merged into controllability increase in the process of main tree in subtree; And in the process that merges total syntax tree by subtree set, the total number of subtree reduces gradually, finally converge to one tree, thereby make to be issued to corresponding requirements at few size of code of trying one's best, and meeting convergence as early as possible under the prerequisite of controlling constraint condition, and then improved correlativity and the randomness of the code being converted to by this syntax tree, make it possible to more naturally simulate actual algorithm code.
Accompanying drawing explanation
Fig. 1 is the structural representation of an embodiment of higher-level language code maker of the present invention;
Fig. 2 is the structural representation of an embodiment of code generation module of the present invention;
Fig. 3 is the process flow diagram of an embodiment of higher-level language code generation method of the present invention;
Fig. 4 a, Fig. 4 b and Fig. 4 c are respectively the schematic diagram of grammer point support information, way of realization constraint information and the special grammar phenomenon constraint information of grammer allocation list in an embodiment of higher-level language code generation method of the present invention;
Fig. 5 a and Fig. 5 b are respectively the schematic diagram of variable uses information and program circuit layout in an embodiment of higher-level language code generation method of the present invention;
Fig. 6 is the process flow diagram of an embodiment of syntax tree construction method of the present invention;
Fig. 7 a, Fig. 7 b and Fig. 7 c are respectively the schematic diagram that generates subtree set in an embodiment of syntax tree construction method of the present invention, and merge subtree set and generate the schematic diagram of new subtree set, and the schematic diagram that generates total syntax tree.
Embodiment
Below by embodiment, by reference to the accompanying drawings the present invention is described in further detail.
Please refer to Fig. 1, is the structural representation of an embodiment of the higher-level language code generator of present embodiment.The higher-level language code generator of present embodiment, comprising: grammer configuration module 1, and for receiving the grammer of the EDA design tool of input, support situation descriptor, and support situation descriptor to be converted to corresponding grammer allocation list this grammer; Control parameter extraction module 2, for receiving the checking of input or the strategy level descriptor of Test Strategy, and the strategy level descriptor of this checking or Test Strategy is converted into corresponding control restriction table; Higher level lanquage syntax library 3, for describing by all grammers of the higher level lanquage of needs and lexical element the storage of classifying; Syntax tree generation module 4, be connected with grammer configuration module 1, higher level lanquage syntax library 3 and control parameter extraction module 2, for the grammer allocation list generating according to grammer configuration module 1, and the control restriction table of parameter extraction module 2 generations, call grammer and lexical element in higher level lanquage syntax library, to generate corresponding syntax tree; Code generation module 5, is connected with syntax tree generation module 4, for traveling through, reads the syntax tree that this syntax tree generation module 4 generates, and generates and can carry out higher-level language code file accordingly.
Conventionally the grammatical phenomenon that we occur the permission defining in higher level lanquage grammer standard, is called standard language.In current various higher level lanquage grammer standard, because the support difficulty of some grammer is larger, therefore, EDA design tool can select to support some grammer point, and abandon supporting other grammer points, support a small set that is less than standard syntax set, even also have more self-defining unique grammers on this basis.Grammer in present embodiment supports situation descriptor to refer to, the grammer that EDA design tool allows user to use when programming, the scope that this EDA design tool can be supported.
Strategy level descriptor in present embodiment, for code level, is described how producing the strategy of test point with comparatively abstract form, for example false code, or process flow diagram etc., rather than describe with the form of code.
In present embodiment, the grammer allocation list being generated by grammer configuration module 1 comprises grammer point support information, way of realization constraint information, special grammar phenomenon constraint information; By the control restriction table of controlling parameter extraction module 2 generations, comprised: process-oriented layout's information of program, variable uses information.
The higher-level language code maker of present embodiment supports situation descriptor to be converted to corresponding grammer allocation list the grammer of the input of reception by grammer configuration module 1, thereby by the grammer configuration in grammer allocation list, the restriction of implementation form, special grammar phenomenon, mark, realize coarse adjustment, fine tuning and the fine setting of linguistic constraints, by controlling parameter extraction module 2, the checking of input or Test Strategy are converted to corresponding control restriction table again, thereby test or checking personnel's thinking is changed into digital parameters tabular form, form friendly user interface, again by syntax tree generation module 4 according to this grammer allocation list with control restriction table, call grammer and lexical element in higher level lanquage syntax library, build corresponding syntax tree, by code generation module 5, the syntax tree of generation is converted to corresponding executable code again, because meeting, the syntax tree building controls restriction table, grammer allocation list, and meet corresponding higher level lanquage grammer and morphological rule, thereby the higher-level language code correlativity being converted to by syntax tree improves, make it possible to more naturally simulate actual algorithm code, and then guaranteed the enforceability of the higher-level language code that generates, to reduce the pressure of manual compiling code.
On the other hand, because higher level lanquage syntax library can be modified according to the difference of different eda tool supporting languages, to support other linguistic forms, thereby improved the extensibility of higher-level language code generator.
The code generation module 5 of the higher-level language code generator of present embodiment is also for when the generation of traversal syntax tree can be carried out higher-level language code, the characteristic of the higher-level language code carried out that record generates, thus corresponding higher-level language code characteristic description file generated.The higher level lanquage generator of present embodiment also comprises the degree of conformity detection module 6 being connected with control parameter extraction module 2 with code generation module 5, for the higher-level language code characteristic description file that code generation module 5 is generated, carrying out degree of conformity with the control restriction table of controlling parameter extraction module 2 generations checks, if meeting, higher-level language code characteristic description file controls restriction table, generate the report of corresponding degree of conformity, and export degree of conformity report, can carry out higher-level language code file and higher-level language code characteristic description file; Otherwise according to the iterations of the permission setting in advance, automatically adjust inner setting, regenerate the new higher-level language code carried out file.
The higher-level language code generator of present embodiment, generates corresponding higher level lanquage characteristic description file by code generation module, and whether user can, according to this higher level lanquage characteristic description file, be detected the higher-level language code generating and suit the requirements.On the other hand, by by higher level lanquage characteristic description file with by verifying or the strategy level descriptor of Test Strategy transforms the control restriction table obtaining and checks, whether the code that detects generation suits the requirements, thereby by checking or tester's focus writing from test code, the strategy of transferring to checking or test comes up, and for take conversion that corresponding higher-level language code is starting point or the synthesis tool needed comprehensive test case of design feature separately that meets when test or checking are provided, while having avoided using ready-made algorithmic code, grammatical phenomenon is incomplete, measuring point is indefinite, debugging location is inconvenient, and then alleviated the pressure of writing code.Simultaneously, when the higher-level language code producing has problem, can be by allowing in iterations at degree of conformity detection module 6, automatically adjust inner setting, regenerate code, and this iterations upper limit can arrange, that is to say that the code generator of present embodiment can carry out self check by this degree of conformity detection module 6.
Please refer to Fig. 2, is the structural representation of an embodiment of the code generation module 5 of present embodiment.The code generation module 5 of present embodiment comprises the code construction submodule 51 being connected with syntax tree generation module 4, and the code feature extraction submodule 52 being connected with degree of conformity detection module 6 with code construction submodule 51.Wherein, code construction submodule 51 travels through and reads for the syntax tree that syntax tree generation module 4 is built, and generates executable higher-level language code file; Code feature extraction submodule 52 is for the characteristic of the higher-level language code carried out that record produces when code construction submodule 51 traversal reads syntax tree, and produces corresponding higher-level language code characteristic description file.
Simultaneously in present embodiment, when user needs specific mark or annotation information, this code construction submodule 51 provides the interface that increases other quantity of information mark on standard language basis, can export that user needs containing specific mark or code corresponding to annotation information.
Because some eda tool is for its purposes separately, and outside some grammer standard, defined that this eda tool oneself can identify, for the grammatical phenomenon of special-purpose, therefore, need to when producing code, add these uncurrent grammer contents.
Higher-level language code maker based on above-mentioned, present embodiment also provides a kind of higher-level language code generation method, below in conjunction with specific embodiments and the drawings, the higher-level language code generation method of present embodiment is described in detail.
Please refer to Fig. 3, is the process flow diagram of an embodiment of the higher-level language code generation method of present embodiment.Take C language as example, and the higher-level language code generation method of present embodiment comprises:
S101, supports situation descriptor according to the grammer of the EDA design tool of input, generates corresponding grammer allocation list.
In present embodiment, the grammer allocation list of generation comprises: grammer point support information, way of realization constraint information, special grammar phenomenon constraint information etc., and grammer allocation list can be to some information setting DEFAULT constraint values.
In present embodiment, by grammer being supported situation descriptor be converted to corresponding grammer allocation list, thereby by grammer configure, the mechanism of implementation form restriction, special grammar phenomenon mark realizes coarse adjustment, fine tuning and the fine setting of linguistic constraints.
Please refer to Fig. 4 a, Fig. 4 b and Fig. 4 c, be respectively in present embodiment the schematic diagram of grammer point support information, way of realization constraint information and special grammar phenomenon constraint information in grammer allocation list.Wherein, grammer point support information has comprised the support situation to grammer points such as data type, operational symbol types,, on the grammer point support information form of grammer allocation list, corresponding option is beaten to hook (or Y/N); Way of realization constraint information comprises: the restraint condition of the information such as loop nesting number of times, the nested number of times of condition completes the input of restriction on existing way of realization constraint information form; Special grammar phenomenon constraint information refers to fill in having under more special grammer restrictive condition, and fills on the basis of the special grammar phenomenon description rule providing in system, explains rigorous.
Please refer to Fig. 4 c, in one embodiment of present embodiment, in special grammar phenomenon constraint information, article one represents " expression formula forming if there is binary operator, the data type of binary operator the right and left can not be constant simultaneously, and necessary data type is consistent "; Second represents " expression formula forming if there is binary operator,, when binary operator is shift operation, the data type of second operand of shift operation will be immediate "; Article three, represent " if there is declarative statement,, when declarative statement is used comma to complete continuous statement, not allowing to occur some not initialized phenomenons of some initialization ".
S103, the strategy level descriptor according to the checking of input or Test Strategy, generates the corresponding restriction table of controlling.
Strategy level descriptor in present embodiment, for code level, is described how producing the strategy of test point with comparatively abstract form, for example false code, or process flow diagram etc., rather than describe with the form of code.
Present embodiment, by the strategy level descriptor of checking or Test Strategy is converted to corresponding control restriction table, changes into digital parameters tabular form by test or checking personnel's thinking, has formed friendly user interface, is convenient to the interchange between slip-stick artist.
In present embodiment, the control restriction table of generation comprises: process-oriented layout's information of program, variable uses information etc.Please refer to Fig. 5 a, schematic diagram for variable uses information in an embodiment of present embodiment, during due to generation code, can take function as unit, this variable uses information can comprise: the restricted number to function internal variable sum when constructed fuction, preferentially use the information such as variable name, types of variables, variable initial value, action scope of variable.
Please refer to Fig. 5 b, is process-oriented layout's information schematic diagram of an embodiment Program of present embodiment, and process-oriented layout's information of this program can comprise the position arrangement of each grammer point, for example, wherein in while statement, insert if statement; The setting of each grammer point attribute, the quantitative attribute amount for example wherein assignment statement assignStatement being occurred arranges; And insertion appointment codes, for example " i_count+=i_refa wherein; " for inserting appointment codes etc.
S105, according to the grammer allocation list generating and control restriction table, calls grammer and lexical element in corresponding syntax library, and builds corresponding syntax tree by syntax tree construction method.
Please refer to Fig. 6, the syntax tree construction method of present embodiment comprises:
S1051, according to controlling restriction table and grammer allocation list, class sign or the example of grammer or lexical element of take is node, the random raw corresponding basic subtree set that becomes.
In present embodiment, for the grammer point that guarantees must exist user to select in syntax tree, first read in user's request, the basic syntax point that the user of take selects is main framework, upwards or downwards extend, the merged node that makes to produce the subtree comprise this basic syntax point increases, improve between each subtree of generation can compressibility, thereby make each subtree of the basic subtree set that formed by this subtree more easily be accomplished to the merging of syntax tree.
Please refer to Fig. 7 a, in an embodiment of present embodiment, need the code producing to comprise two if structures and two for structures, according to controlling restriction table and grammer allocation list, generate four independently node: ifstat, ifstat, forstat, forstat.Yet these four independently node can not directly merge, therefore, we first extend up or down to these four nodes, make to be increased by extend the merged node of the tree that of these four independent processing units, improve the combinableness between each tree, thereby be more easily accomplished to the merging of the total tree of grammer.In C language production, all ifstat and forstat must be released by stat, the father node of all ifstat and forstat must be all node stat, and the probability that node stat occurs in C language production is higher, when merging can be higher in conjunction with rate, a step so four nodes here all upwards extend, thereby obtain two subtrees that comprise if structure 101 and subtree 102, and two subtrees that comprise for structure 103 and subtree 104, obtain corresponding basic subtree set.
In present embodiment, a syntax tree only has a root node, but can there be a lot of leaf nodes, and when building syntax tree or total syntax tree, to determining the node of node type or node content, and the content of this node or type are again in optional situation in the rule after grammer configuration constraint, then according to random function, in optional scope, select at random.
In present embodiment, random function refers to and in specified scope, produces a random number, and by this random number, decided a number of the issuable subtree of C language production, higher level lanquage all can provide random function conventionally.For example, in C language production, there is block-> stat n, block can release n stat (n>=0), and the concrete numerical value of this n, the random number being produced by random function is determined.
Random function in present embodiment can repeatedly be called, and it is each according to different needs, the random number that the random function calling produces is not reused, each random number producing is all different, but when random function is called at every turn, there is a maximal value in capital, and this maximal value has limited the generation scope of random number.For example maximal value is 7, and the random value that random function produces so can only be just any in 0 to 6.
S1053, according to controlling restriction table and grammer allocation list, carries out subtree at random many wheels and merges, and generates new subtree set, and wherein, the condition of merging is that the root node of the stalk tree in the two stalk trees that will merge is identical with the leaf node type of another stalk tree.
In present embodiment, to walking at each in upwardly extending process, new root node can require according to production random definite, and in extension process, the non-leaf node obtaining, i.e. nonterminal symbol, usings the new node subtree that search can merge as search condition.
Please refer to Fig. 7 b, at random each subtree in Fig. 7 a is merged, generate new subtree set and comprise: first, owing to can releasing the production collection of stat, be { block-> stat nifStat-> if (expr) stat, ..., by random function, obtain second production ifStat-> if (expr) stat, the leaf node ifstat that is subtree 101 can release if (expr) stat, because this leaf node stat after releasing is identical with the root node stat type of subtree 103, therefore merge subtree 101 and 103 and obtain subtree 201, the first round merges end.
Certainly, the subtree 101 in the present embodiment, subtree 102, subtree 103 and subtree 104 can merge mutually.But while carrying out concrete union operation, can add up the merging possibility between each subtree, and according to the possibility merging, the random number being produced by random function determines specifically which two stalk tree is merged.For example between subtree, annexable scheme has M, and random function input value is exactly M so, if be output as 0=< N < M of N, N scheme called in the numeric representation drawing.For example, when the value producing when random function in the present embodiment is 0, subtree 101 and subtree 102 are merged; When the value of random function generation is 1, subtree 101 and subtree 103 are merged.
In present embodiment, expr (expression formula) can not generate with top-down form at random with simple structures such as not containing nested stat (general statement).In order to assist to generate quickly random attached tree, in subtree set, need to produce enough expr (expression formula) and stat (general statement).
In present embodiment, when there is certain grammer nested, if the nested number of plies user who allows does not specify, before achievement, need it to determine, can determine at random or default setting.For example in program at first, (this numeral can directly be set by user by random function, to obtain random number 3, or get a default value), determine that the nested number of plies is 3, do not allow on any paths, to occur in each downward paths of stat 3 above stat; If started in program, obtain random number 0, in the process of backward deriving at stat, just can not there is again stat, and any one by root node the fullpath to leaf node, the nested number of plies of certain grammer can be calculated by adding up the number of this identical syntactic type node occurring on this path.
Secondly, here can select block or forstat etc. as the new root node of this subtree 201, in the present embodiment, select by block as new root node, move random function and obtain production block-> stat stat, and the new stat in two stat that released by this production is nonterminal symbol, the attached tree that this nonterminal symbol stat of take can merge as new node search, searching root node is subtree 104 and the subtree 102 of stat, the random number producing according to random function again determines subtree 201 and subtree 104 to merge, thereby merge subtree 201 and subtree 104, obtain subtree 202, second takes turns merging finishes.
In the present embodiment, subtree 201 can merge with subtree 102 or subtree 104, but determines that by random function this subtree 201 and subtree 102 merge or merge with subtree 104.
Finally, due to the root node/leaf node of subtree 102, can not in subtree 202, search out corresponding annexable leaf node/root node, therefore, can not merge, obtain new subtree set: subtree 202 and subtree 102.
S1055, using the maximum subtree of node as main tree, other subtree, as attached tree, is carried out bottom-up extension to main tree, carries out randomly many wheels and merges, and generates corresponding total syntax tree.
Please refer to Fig. 7 c, for present embodiment main tree and attached tree are merged, generate the schematic diagram of an embodiment of total syntax tree.In one specific embodiment of present embodiment, main tree and attached tree are merged, generating total syntax tree comprises: according to above-mentioned amalgamation result, select the more subtree 202 of nodal point number as main tree, subtree 102 is carried out new round merging as attached tree: make main tree 202 extend upward, by random function, obtain production stat-> block, the root node of main tree 202 becomes stat; Then, by random function, obtain production ifStat-> if (expr) stat, the if Stat in subtree 102 releases if (expr) stat; Because this leaf node stat after these subtree 102 releases is identical with the root node stat type of main tree 202, main tree 202 and subtree 102 are merged, all subtrees merge complete.
Please refer to Fig. 7 c, attached tree and main tree obtain subtree 301 after merging, node expr in this subtree is nonterminal symbol, owing to not existing in attached tree, take the subtree that expr is root node, so take by producing at random one the attached tree that node expr is root node, and then this attached tree merged in the node expr of main tree 301; Root node due to subtree 301 has been the summit of tree simultaneously, so node expr is with regard to need to constantly extending downwards, by himself completion.
Terminal symbol in present embodiment is the most basic element in language, can not further decompose, and in Fig. 7 c, because ifstat can release if (expr) stat, therefore, it is not terminal symbol; And in the if being released by ifstat (expr) stat, because " if ", " (" and ") " can not be released other element again, be terminal symbol.
In present embodiment, when only having a main tree, select shortest path to arrive function root node.In the present embodiment, owing to only having a main tree 202, in the upwardly extending process of this main tree 202, no longer select stochastic production, but survey and be short to the path that reaches function most forward, finally by production block-> stat, function-> type ID (formalParameter) block obtains subtree 301, so far, the subtree that the funtion of take is root node, syntax tree builds complete.
In the present embodiment, a syntax tree only represents a function, and in the production process of complete code, total number of the syntax tree of generation decided by function number.
Certainly, when attached tree not only only has 102 1 of subtrees, after attached tree 102 and main tree 202 are merged, then remaining attached tree is carried out to many wheel merging at random, and with the major way of bottom-up extension, finally obtain total syntax tree.
In present embodiment, each time main tree is made progress in the process extending, new root node can require according to production random definite, and in extension process, obtain non-leaf node, i.e. nonterminal symbol, usings this new nonterminal symbol attached tree that search can merge as search condition, if qualified attached tree does not exist, can produce at random qualified attached tree and merge.
In present embodiment, at random each subtree being carried out to many wheels merges, and upwards extend in the total syntax tree process of generation, the clause meeting on control restriction table of must take is object, take grammer allocation list as restriction, meet C language syntax and morphological rule, use the chance mechanism of rational belt restraining, take bottom-up extension as major way, generation meets the syntax tree of user's request, and before main tree is upwards extended each time, all must guarantee that all leaf nodes are all terminal symbols, otherwise the attached tree that this nonterminal symbol can merge as search condition search of take merges or produces at random qualified attached tree and merges, in conjunction with not producing satisfactory syntax tree containing nested downward completion mode.
In present embodiment, adopt upwards and extend, the mode that completion downwards lacks node builds syntax tree, can control well the enforcement of the constraint conditions such as nested number of times, simultaneously, main tree is adopted to the mode of bottom-up extension, to produce the nodes that need completion more, like this could be according to the situation of the root node of attached tree, attached tree is merged on main tree, finally converge to a total syntax tree, and during due to merging, the root node that must meet attached tree is identical with the type of the leaf node of needs completion on main tree, therefore, while only having node as terminal symbol as leaf node, just do not need to continue completion.If can not use existing attached tree by main tree completion, according to random function, produce the corresponding subtree needing and carry out completion.
Certainly, in present embodiment, main tree and attached tree are carried out to many wheels while merging, also can be according to the direction of downward extension, but finally all need the node lacking to supplement complete, syntax tree that could complete.
In present embodiment, build in language syntax tree process, when the number of the issuable identical subtree of C language production is uncertain, a number for subtree determines by random function, and the maximal value of random number is by a number decision for current attached tree; In addition, if if, the maximum times user that the main statement such as while occurs does not specify, and before building syntax tree, it is determined, can determine at random or default setting.
Present embodiment is by being set up main tree by subtree, and finally merge in the process of total syntax tree, because each stalk tree all must meet and control restriction table, thereby in the process that makes to set up syntax tree by subtree, controllability increases, and Fast Convergent is total syntax tree, and then make the total syntax tree generating meet control restriction table, and make also meeting the demands by the higher-level language code of this total syntax tree conversion, and the size of code producing is less, good relationship, the effective value of the higher-level language code that raising generates.
S107, traversal reads syntax tree, and generation can be carried out higher-level language code file accordingly.
In present embodiment, when if user has set specific mark or annotation information, also at this, can carry out higher-level language code and generate the higher-level language code carried out corresponding to this specific mark or annotation information, so that the interface that increases other quantity of information marks on standard language basis to be provided.
S109, when traversal reads syntax tree, the characteristic of the higher-level language code that record generates, and generate corresponding higher-level language code characteristic description file.
The characteristic of the higher-level language code that present embodiment generates by record, generate corresponding higher-level language code characteristic description file, thereby make user pass through the characteristic that higher-level language code characteristic description file is understood the higher-level language code producing, and then be convenient to check that whether oneself checking or Test Strategy be corresponding with code, simultaneously can be according to the characteristic description of the middle-and-high-ranking language codes of this higher level lanquage characteristic description file, instruct the enforcement of checking or Test Strategy, alleviated the pressure of manual compiling code.
S1011, according to this higher-level language code characteristic description file, detects this higher-level language code characteristic description file and whether meets control restriction table, if met, performs step S1013a; Otherwise execution step S1013b.
S1013a, generates and exports corresponding degree of conformity report, and output simultaneously can be carried out higher-level language code file and higher-level language code characteristic description file.
S1013b, adjusts accordingly, and generates the new higher-level language code carried out file.
Present embodiment, by checking higher-level language code characteristic description file, whether meet control restriction table, whether the higher-level language code carried out that judges generation suits the requirements, when suiting the requirements, output can be carried out higher-level language code, higher-level language code characteristic description file and degree of conformity report accordingly; When not meeting while needing, allowing under iterations prerequisite, automatically adjust corresponding setting, regenerate the new higher-level language code carried out.
The higher-level language code generation method of present embodiment, first, supports the grammer of input the strategy level descriptor of situation descriptor and checking or Test Strategy, is converted to respectively corresponding grammer allocation list and controls restriction table, secondly, according to this grammer allocation list and control restriction table, call grammer and lexical element in syntax library, and build corresponding syntax tree by syntax tree construction method, moreover, by traversal, read this syntax tree, generate and can carry out higher-level language code file accordingly, the characteristic of the higher-level language code file that record generates simultaneously, generate corresponding higher-level language code characteristic description file, simultaneously, present embodiment is by building syntax tree, be converted into again accordingly and can carry out higher-level language code, because this syntax tree meets the requirement of controlling restriction table, making is increased to controllability in the building process of total syntax tree by subtree, and under the prerequisite that meets control constraint condition, restrain as early as possible, thereby make to simplify meeting the code producing under the prerequisite of user's controlled condition, and there are good correlativity and randomness, make more naturally to simulate actual algorithm code, guaranteed the direct enforceability of the higher-level language code test case of generation, and then alleviated the pressure of manual compiling code.
Above content is in conjunction with concrete embodiment further description made for the present invention, can not assert that specific embodiment of the invention is confined to these explanations.For general technical staff of the technical field of the invention, without departing from the inventive concept of the premise, can also make some simple deduction or replace, all should be considered as belonging to protection scope of the present invention.

Claims (8)

1. a higher-level language code generator, is characterized in that, comprising:
Grammer configuration module, supports situation descriptor for receiving the grammer of the electronic design automation tool of input, and supports situation descriptor to be converted to corresponding grammer allocation list described grammer;
Control parameter extraction module, for receiving the checking of input or the strategy level descriptor of Test Strategy, and the strategy level descriptor of described checking or Test Strategy is converted into corresponding control restriction table;
Higher level lanquage syntax library, for storing all grammers of the higher level lanquage of needs and lexical element description;
Syntax tree generation module, be connected with described grammer configuration module, higher level lanquage syntax library and control parameter extraction module, for the grammer allocation list generating according to described grammer configuration module, and the control restriction table of described parameter extraction module generation, call grammer and lexical element in described higher level lanquage syntax library, and generate corresponding syntax tree;
Code generation module, is connected with described syntax tree generation module, for the syntax tree that described syntax tree generation module is generated, is converted to accordingly and can carries out higher-level language code file;
Described syntax tree generation module comprises:
Subtree set generates submodule, be connected with higher level lanquage syntax library with described grammer configuration module, control parameter extraction module, be used for according to described grammer allocation list and control restriction table, class sign or the example of grammer in higher level lanquage syntax library or lexical element of take is node, generates corresponding subtree set;
Subtree merges submodule, generating submodule with described grammer configuration module, control parameter extraction module with subtree set is connected, be used for according to described grammer allocation list and control restriction table, at random each subtree is merged, obtain new subtree set, the leaf node type that the condition of merging is set with another stalk for the root node of the stalk tree in the two stalk trees that will merge is identical;
Total syntax tree generates submodule, merge submodule, grammer configuration module and control parameter extraction module with described subtree and be connected, for using the maximum subtree of the new subtree set node obtaining as main tree, other subtrees are as attached tree, and according to described grammer allocation list and control restriction table, according to the direction of bottom-up extension, at random described main tree and attached tree are carried out to many wheel merging, obtain corresponding total syntax tree.
2. higher-level language code generator as claimed in claim 1, it is characterized in that, described code generation module also, for according to described syntax tree, generates corresponding to the described higher-level language code characteristic description file of carrying out higher-level language code file, and described code generation module comprises:
Code construction submodule, is connected with described syntax tree generation module, for the syntax tree that described syntax tree generation module is generated, travels through and reads, and generates the corresponding higher-level language code carried out file;
Code feature extraction submodule, be connected with degree of conformity detection module with described code construction submodule, for the characteristic of the higher-level language code carried out that record produces when described code construction submodule traversal reads described syntax tree, and produce corresponding higher-level language code characteristic description file.
3. higher-level language code generator as claimed in claim 2, is characterized in that, when the specific mark of needs or annotation information, described code construction submodule also for increasing the interface of other quantity of information marks on standard language basis.
4. higher-level language code generator as claimed in claim 2, is characterized in that, also comprises:
Degree of conformity detection module, be connected with control parameter extraction module with described code feature extraction submodule, be used for according to described higher-level language code characteristic description file, and described control restriction table carries out degree of conformity and checks, if described higher-level language code characteristic description file meets described control restriction table, generate the report of corresponding degree of conformity, and export described degree of conformity report, can carry out higher-level language code file and high-level code characteristic description file; When if described higher-level language code characteristic description file does not meet described control restriction table, according to the iterations of the permission setting in advance, automatically adjust inner setting, regenerate the new higher-level language code carried out file.
5. the higher-level language code generator as described in any one in claim 1 to 4, is characterized in that, described grammer allocation list comprises: grammer point support information, way of realization constraint information, special grammar phenomenon constraint information; Described control restriction table comprises: process-oriented layout's information of program, variable uses information.
6. a higher-level language code generation method, is characterized in that, comprising:
According to the grammer of the electronic design automation tool of input, support situation descriptor, generate corresponding grammer allocation list;
Strategy level descriptor according to the checking of input or Test Strategy, generates the corresponding restriction table of controlling;
According to described grammer allocation list and control restriction table, call grammer and lexical element in higher level lanquage syntax library, and build corresponding syntax tree by syntax tree construction method;
Described syntax tree is converted to accordingly and can carries out higher-level language code file;
Described syntax tree construction method comprises:
According to described control restriction table and grammer allocation list, class sign or the example of grammer or lexical element of take is node, generates corresponding basic subtree set at random;
According to described control restriction table and grammer allocation list, at random each subtree is merged, generate new subtree set, the leaf node type that the condition of merging is set with another stalk for the root node of the stalk tree in the two stalk trees that will merge is identical;
Using the maximum subtree of node as main tree, other subtree is as attached tree, according to described control restriction table and grammer allocation list, according to the direction of bottom-up extension, at random described main tree and attached tree carried out to many wheels and merges, and generates corresponding total syntax tree.
7. method as claimed in claim 6, is characterized in that, described syntax tree is converted to and can carries out accordingly higher-level language code file and comprise:
Traversal reads described syntax tree, generates and can carry out higher-level language code file accordingly;
When having set specific mark or annotation information, described, generate the higher-level language code corresponding to described specific mark or annotation information in carrying out higher-level language code file.
8. method as claimed in claim 7, is characterized in that, also comprises:
When traversal reads described syntax tree, the characteristic of the higher-level language code carried out that record generates, and generate corresponding higher-level language code characteristic description file;
Detect described higher-level language code characteristic description file and whether meet described control restriction table, if met, generate and export corresponding degree of conformity report, described in output, can carry out higher-level language code file and higher-level language code characteristic description file simultaneously; Otherwise adjust accordingly, and generate the new higher-level language code carried out file.
CN201110115605.1A 2011-05-05 2011-05-05 Senior language code generation method and generator Expired - Fee Related CN102156655B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201110115605.1A CN102156655B (en) 2011-05-05 2011-05-05 Senior language code generation method and generator

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201110115605.1A CN102156655B (en) 2011-05-05 2011-05-05 Senior language code generation method and generator

Publications (2)

Publication Number Publication Date
CN102156655A CN102156655A (en) 2011-08-17
CN102156655B true CN102156655B (en) 2014-04-02

Family

ID=44438163

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201110115605.1A Expired - Fee Related CN102156655B (en) 2011-05-05 2011-05-05 Senior language code generation method and generator

Country Status (1)

Country Link
CN (1) CN102156655B (en)

Families Citing this family (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9880842B2 (en) 2013-03-15 2018-01-30 Intel Corporation Using control flow data structures to direct and track instruction execution
CN109739758B (en) * 2018-12-28 2022-02-01 北京云测信息技术有限公司 Test case conversion method and device
KR20200139525A (en) * 2019-06-04 2020-12-14 삼성전자주식회사 System including fpga and method of operation thereof
CN112269566B (en) * 2020-11-03 2022-09-02 支付宝(杭州)信息技术有限公司 Script generation processing method, device, equipment and system

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1368693A (en) * 2001-02-07 2002-09-11 友邦软件技术有限公司 Method and equipment for global software
CN101841515A (en) * 2009-03-19 2010-09-22 北京理工大学 Target variable protocol data unit codec code automatic generation implementation method

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1368693A (en) * 2001-02-07 2002-09-11 友邦软件技术有限公司 Method and equipment for global software
CN101841515A (en) * 2009-03-19 2010-09-22 北京理工大学 Target variable protocol data unit codec code automatic generation implementation method

Also Published As

Publication number Publication date
CN102156655A (en) 2011-08-17

Similar Documents

Publication Publication Date Title
CN1834903B (en) Method and system for fitting text to shapes within a graphic
CN102156655B (en) Senior language code generation method and generator
US8667462B1 (en) Model and subsystem function signatures
CN106155755A (en) Program compiling method and compiler
JP4783658B2 (en) Verification support device, verification support method, verification support program, and recording medium
US20080109780A1 (en) Method of and apparatus for optimal placement and validation of i/o blocks within an asic
Dolgov et al. 2019 cad contest: Lef/def based global routing
JP2011060277A (en) Integration environment generator
WO2014015189A1 (en) Relative timing architecture
CN106648587A (en) Annotation-based Web application code generation method
CN102270137B (en) Method for acquiring ADL (architecture description language) and modeling tool
JP2010198363A (en) Circuit specification description visualization device and circuit specification description visualization method
US9953120B2 (en) Relative timing characterization
CN101901148A (en) Generation method of ECU parameter configuration interface based on AUTOSAR standard
CN110162297A (en) A kind of source code fragment natural language description automatic generation method and system
CN102385505A (en) Software visualization method for object-oriented programming language source code
CN102722601B (en) Implementation method of formal semantic integration framework for model transformation of numerical control system
JP4480737B2 (en) Logic verification support program, recording medium recording the program, logic verification support device, and logic verification support method
Guerra et al. Inter-modelling with patterns
US11487927B2 (en) Peripheral tool
JP4918907B2 (en) Test data generation program, test data generation device, and test data generation method
Lora et al. Hardware synthesis from software-oriented UML descriptions
KR20220003106A (en) Systems and methods of computer-assisted computer programming
CN115455877B (en) Verification platform generation device, method, medium and electronic equipment
Mark et al. Hierarchical benchmark circuit generation for FPGA architecture evaluation

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
C14 Grant of patent or utility model
GR01 Patent grant
CF01 Termination of patent right due to non-payment of annual fee

Granted publication date: 20140402

Termination date: 20200505

CF01 Termination of patent right due to non-payment of annual fee