CN106445625A - Preprocessing method and device of to-be-compiled codes - Google Patents
Preprocessing method and device of to-be-compiled codes Download PDFInfo
- Publication number
- CN106445625A CN106445625A CN201610845796.XA CN201610845796A CN106445625A CN 106445625 A CN106445625 A CN 106445625A CN 201610845796 A CN201610845796 A CN 201610845796A CN 106445625 A CN106445625 A CN 106445625A
- Authority
- CN
- China
- Prior art keywords
- keyword
- instruction
- sentence
- code
- destination object
- 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.)
- Pending
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/40—Transformation of program code
- G06F8/41—Compilation
- G06F8/44—Encoding
- G06F8/441—Register allocation; Assignment of physical memory space to logical memory space
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/40—Transformation of program code
- G06F8/41—Compilation
- G06F8/44—Encoding
- G06F8/443—Optimisation
Landscapes
- Engineering & Computer Science (AREA)
- General Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Software Systems (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Devices For Executing Special Programs (AREA)
Abstract
The embodiment of the invention provides a preprocessing method and device of to-be-compiled codes. The method comprises the steps that in the to-be-compiled codes, whether an instruction for rendering a target object is included in the codes for drawing the target object or not is determined; making response to the instruction for rendering the target object, branch structure statements meeting the preset condition in the instruction are replaced with sequential structure statements; the branch structure statements are used for selecting whether rendering is carried out or not, and the sequential structure statements are used for rendering. The branch structure statements meeting the preset condition in the instruction are replaced with the sequential structure statements, the number of Shader variants generated in the compiling process is reduced, therefore, the size of a data package generated after compiling is reduced, and terminal internal storage occupied during operating is reduced. In addition, the embodiment of the invention provides a preprocessing device of the to-be-compiled codes.
Description
Technical field
Embodiments of the present invention are related to compiler pretreatment technical field, more specifically, embodiments of the present invention are related to
A kind of preprocess method of code to be compiled and device.
Background technology
This part is it is intended that the embodiments of the present invention stated in claims provide background or context.Herein
Description is not because include just recognizing to be prior art in this part.
In Unity development of games engine, tinter (Shader) refers to that one group supplies computer graphical resource in execution wash with watercolours
The instruction using during dye task, is mainly used in calculating color or the light and shade of image.
When writing the code of Shader instruction, it is possible to use #pragma multi_compile sentence enters to keyword
Row macrodefinition, namely symbol followed by can be a keyword using #pragma multi_compile sentence mark
(Keyword), keyword is the mark for labelling branch in shader instruction, and keyword is divided into state of activation and un-activation
Whether state two states, when being compiled to Shader instruction, activate this pass of determination according to keyword in Shader instruction
Whether the code representated by key word can be compiled to code segment, specifically, the keyword being active is compiled into generation
In code section, the keyword being compiled in code segment can be divided into two kinds of on off states of opening and closing again, specifically executes in code
When select to determine whether this keyword executes according to the on off state of keyword.
When writing the code of Shader instruction, use cooperatively with keyword is branch's anticipation code, refers in Shader
Some branches anticipation code can be specified in order, comprise keyword in branch's anticipation code, branch's anticipation code can be according to pass
The on off state of key word selects different branches.
When writing the code of Shader instruction, if being carried out to keyword using #pragma multi_compile sentence
Macrodefinition, and using anticipation branch code in Shader instruction, then when being compiled to Shader instruction, can be to branch
The different branches of anticipation code are combined, and generate different Shader variants, namely anticipation code difference branch of multiple branches
Each group of permutation and combination all correspond to a Shader variant, such that it is able to using different Shader variants execution rendering tasks
When, realize different effects, for tool example:
In the examples described above, drafting skin, drafting hair, drafting hair dew are all using #pragma multi_
The keyword of compile sentence definition it is assumed that each keyword is all in state of activation, then, when being compiled, is understood according to three
The different on off states of individual keyword are combined, and compiling generates different Shader variants, specifically it is assumed that each is crucial
Word has two kinds of on off states, represents that keyword is closed with 0, represents that keyword is in opening with 1, then above-mentioned
Shader in example instructs when being compiled, the different switch shapes of three keywords according to included in branch's anticipation sentence
State is combined, and can generate the individual Shader variant of following 8 (2^3), respectively:000th, 001,010,011,100,101,110 with
And 111.
As can be seen that Shader instruction adopts this write method from above-mentioned example, for weight in instructing in Shader
Use again and identical code (namely code of keyword), can only write once, when using by the activation of keyword
State control whether using, it is to avoid repeat to write identical code, thus for writing and safeguarding that offer facilitates.
In application development compilation process, the quantity of Shader variant exponentially can increase with the increase of keyword
Plus, for example:In certain application program Shader instruction, the quantity of keyword is 128, then Shader variant in compilation process
It is up to 2^128 in theory, then after compiling, the packet of this application program will be very big, then running this application program
When also by internal memory larger for occupied terminal, but have in the Shader variant being compiled in compilation process most of may can't
Using arriving, this is accomplished by the Shader variant that will not use is deleted.
The Shader variant not used is deleted generally by the mode deleting Keyword in prior art,
Specifically, Unity supports using #pragma shader_feature sentence, keyword to be deleted in Shader, but
Be this sentence when being used together with #pragma multi_compile sentence, the invalid switch of keyword can only be deleted
State, namely delete certain on off state of not using of keyword, the Shader variant not used can not be deleted completely, lead
Cause in the case that keyword quantity is more, the packet after compiling is still very big, occupied terminal larger internal memory during operation.
Therefore, need a kind of preprocess method of code to be compiled at present badly, to carry out to Shader instruction before compiling
Pretreatment, reduces the quantity generating Shader variant in compilation process, thus generating the size of packet after reducing compiling, fall
The tag memory taking during low operation.
Content of the invention
For in prior art, when being compiled to Shader instruction, the quantity of Shader variant can be with Shader
The increase of keyword in instruction and in exponential increase, and it is impossible to effective delete not by way of deleting to keyword
The Shader variant using, thus the packet of generation is larger after leading to compile, during operation, the larger internal memory of occupied terminal asks
Topic.
For this reason, being highly desirable to a kind of preprocess method of improved code to be compiled, to refer to Shader before compiling
Order carries out pretreatment, reduces the quantity generating Shader variant in compilation process, thus generating packet after reducing compiling
Size, reduces the tag memory taking when running.
In the present context, embodiments of the present invention expectation provides a kind of preprocess method of code to be compiled and dress
Put.
In the first aspect of embodiment of the present invention, there is provided a kind of preprocess method of code to be compiled, including:
In code to be compiled, determine for draw destination object code in whether comprise for carrying out to destination object
The instruction rendering;
In response to determining the instruction comprising for being rendered to destination object, pre-conditioned by meeting in described instruction
Branched structure sentence replaces with sequential organization sentence;
Wherein, described branched structure sentence is used for choosing whether to be rendered, and described sequential organization sentence determines and is used for holding
Row renders.
In the second aspect of embodiment of the present invention, there is provided a kind of pretreatment unit of code to be compiled, including:
Instruction retrieval module, in code to be compiled, determine for draw destination object code in whether comprise
For the instruction that destination object is rendered;
Sentence replacement module, in response to determining the instruction comprising for being rendered to destination object, by described finger
Meet pre-conditioned branched structure sentence in order and replace with sequential organization sentence;
Wherein, described branched structure sentence is used for choosing whether to be rendered, and described sequential organization sentence determines and is used for holding
Row renders.
In the third aspect of embodiment of the present invention, there is provided a kind of pretreatment unit of code to be compiled, for example, can
To include memorizer and processor, wherein, processor can be used for reading the program in memorizer, executes following process:
In code to be compiled, determine for draw destination object code in whether comprise for carrying out to destination object
The instruction rendering;
In response to determining the instruction comprising for being rendered to destination object, pre-conditioned by meeting in described instruction
Branched structure sentence replaces with sequential organization sentence;
Wherein, described branched structure sentence is used for choosing whether to be rendered, and described sequential organization sentence determines and is used for holding
Row renders.
In the fourth aspect of embodiment of the present invention, there is provided a kind of program product, it includes program code, when described
When program product runs, described program code is used for executing procedure below:
In code to be compiled, determine for draw destination object code in whether comprise for carrying out to destination object
The instruction rendering;
In response to determining the instruction comprising for being rendered to destination object, pre-conditioned by meeting in described instruction
Branched structure sentence replaces with sequential organization sentence;
Wherein, described branched structure sentence is used for choosing whether to be rendered, and described sequential organization sentence determines and is used for holding
Row renders.
The preprocess method of the code to be compiled according to embodiment of the present invention and device, are used for drawing target pair in determination
When comprising the instruction for being rendered to destination object in the code of elephant, during this is instructed, meet pre-conditioned branched structure
Sentence replaces with sequential organization sentence, due to when treating compiled code and being compiled, for branched structure sentence, compilation process
Middle can be combined according to the on off state comprising keyword in branched structure sentence, generate Shader variant, and for order
Structured statement, is directly compiled in compilation process, will not generate Shader variant, therefore, meets default bar during this is instructed
The branched structure sentence of part replaces with sequential organization sentence, can reduce the quantity generating Shader variant in compilation process, from
And reduce the size generating packet after compiling, reduce the tag memory taking when running.
Brief description
Detailed description below, above-mentioned and other mesh of exemplary embodiment of the invention are read by reference to accompanying drawing
, feature and advantage will become prone to understand.In the accompanying drawings, if showing the present invention's by way of example, and not by way of limitation
Dry embodiment, wherein:
Fig. 1 schematically shows the application scenarios schematic diagram according to embodiment of the present invention;
The flow process that Fig. 2 schematically shows the preprocess method of code to be compiled according to an embodiment of the invention is illustrated
Figure;
The structure that Fig. 3 schematically shows the pretreatment unit of code to be compiled according to another embodiment of the present invention is shown
It is intended to;
The structure that Fig. 4 schematically shows the pretreatment unit of the code to be compiled according to further embodiment of this invention is shown
It is intended to;
Fig. 5 schematically shows the journey carrying out pretreatment for treating compiled code according to yet another embodiment of the invention
Sequence product schematic diagram.
In the accompanying drawings, identical or corresponding label represents identical or corresponding part.
Specific embodiment
Principle and the spirit of the present invention to be described below with reference to some illustrative embodiments.It should be appreciated that providing this
A little embodiments are used for the purpose of making those skilled in the art better understood when and then realizing the present invention, and not with any
Mode limits the scope of the present invention.On the contrary, these embodiments are provided so that the disclosure is more thorough and complete, and energy
Enough the scope of the present disclosure is intactly conveyed to those skilled in the art.
One skilled in the art will appreciate that embodiments of the present invention can be implemented as a kind of system, device, equipment, method
Or computer program.Therefore, the disclosure can be implemented as following form, that is,:Completely hardware, completely software
(including firmware, resident software, microcode etc.), or the form that hardware and software combines.
According to the embodiment of the present invention it is proposed that a kind of preprocess method of code to be compiled and device.
Herein it is to be understood that any number of elements in accompanying drawing is used to example and unrestricted and any
Name is only used for distinguishing, and does not have any limitation.
Below with reference to some representative embodiments of the present invention, the in detail principle of the explaination present invention and spirit.
Summary of the invention
The inventors discovered that, in prior art, when being compiled to Shader instruction, the quantity of Shader variant can be with
The increase of keyword in Shader instruction and in exponential increase, and it is impossible to have by way of deleting to keyword
Effect deletes the Shader variant not used, thus the packet of generation is larger after leading to compile, during operation, occupied terminal is larger
Internal memory.Lack a kind of preprocess method of improved code to be compiled in prior art, generated with reducing in compilation process
The quantity of Shader variant, thus generating the size of packet after reducing compiling, reduces the tag memory taking when running.
For this reason, the invention provides a kind of preprocess method of code to be compiled and device, the pretreatment of code to be compiled
Method can include:In code to be compiled, determine for draw destination object code in whether comprise for target pair
As the instruction being rendered;In response to determining the instruction comprising for being rendered to destination object, meet pre- during this is instructed
If the branched structure sentence of condition replaces with sequential organization sentence;Wherein, branched structure sentence is used for choosing whether to be rendered,
Sequential organization sentence determine for execution render.
After the ultimate principle describing the present invention, lower mask body introduces the various non-limiting embodiment party of the present invention
Formula.
Application scenarios overview
With reference first to Fig. 1, as shown in figure 1, being answering of the preprocess method of code to be compiled provided in an embodiment of the present invention
With schematic diagram of a scenario, the code to be compiled 103 including code 101 to be compiled with through pretreatment, wherein, code to be compiled is permissible
It is the code of application program, the operation such as code to be compiled can carry out writing in terminal unit, pretreatment and compiling, generate
Packet, packet can realize different functions when application program runs.
When treating compiled code 101 and carrying out pretreatment, determine for draw destination object code in whether comprise to use
In the instruction that destination object is rendered, if comprising the instruction for being rendered to destination object in code to be compiled,
In response to determining the instruction comprising for being rendered to destination object, during this is instructed, meet pre-conditioned branched structure language
Sentence replaces with sequential organization sentence, when being embodied as, can by this instruct in the branch of keyword that comprises to be active
Structured statement replaces with sequential organization sentence;If not comprising the instruction for being rendered to destination object in code to be compiled,
Then do not need to process.After treating compiled code 101 pretreatment, the code to be compiled 103 through pretreatment is compiled.
Wherein, terminal unit can write for program code can be carried out, the various smart machines of pretreatment and compiling,
For example:Mobile phone, computer etc..
Illustrative methods
With reference to the application scenarios of Fig. 1, it is described with reference to Figure 2 the generation to be compiled according to exemplary embodiment of the invention
The preprocess method of code.It should be noted that above-mentioned application scenarios be for only for ease of understand spirit and principles of the present invention and
Illustrate, embodiments of the present invention are unrestricted in this regard.On the contrary, embodiments of the present invention can apply to be suitable for
Any scene.
The schematic flow sheet of one embodiment of the preprocess method of the code a kind of to be compiled that Fig. 2 provides for the present invention, main
Including the flow process treating compiled code and carrying out pretreatment, executive agent can be terminal unit, as shown in Fig. 2 the present invention is real
The preprocess method of the code a kind of to be compiled of example offer is provided, comprises the steps:
Step 201, in code to be compiled, determine for draw destination object code in whether comprise for target
The instruction that object is rendered.
Because Shader instruction can generate Shader variant in compiling, generate Shader change in compilation process to reduce
The quantity of body, namely reduce the generation not using Shader variant, needed Shader instruction is processed before compiling, because
This, in this step, in code to be compiled, determine for draw destination object code in whether comprise for target pair
As the instruction being rendered, namely determine whether comprise Shader instruction in code to be compiled however, it is determined that wrapping in code to be compiled
Containing Shader instruction, then the Shader instruction in this code to be compiled is processed, and if it is determined that not wrapping in code to be compiled
Containing Shader instruction, then do not need to treat compiled code and processed.
In this step, in code to be compiled, determine for draw destination object code in whether comprise for right
The instruction that destination object is rendered can adopt method of the prior art, and here is omitted, and wherein, destination object includes
Object, personage, plant, animal etc., for drawing the code of destination object, including:The material code of destination object, shape code
Deng.
Step 202, in response to determining the instruction comprising for being rendered to destination object, meets default during this is instructed
The branched structure sentence of condition replaces with sequential organization sentence;Wherein, branched structure sentence is used for choosing whether to be rendered, suitable
Sequence structure sentence determine for execution render.
In this step, in response to determining the instruction comprising for being rendered to destination object, namely it is used for painting in determination
When comprising the instruction for being rendered to destination object in the code of destination object processed, meet pre-conditioned during this is instructed
Branched structure sentence replaces with sequential organization sentence, when being embodied as, can be complete by meeting pre-conditioned branched structure sentence
Portion replaces with sequential organization sentence it is also possible to be sequential organization by the partial replacement meeting in pre-conditioned branched structure sentence
Sentence, certainly, more preferably, the branched structure sentence meeting pre-conditioned is all replaced with sequential organization sentence.
The embodiment of the present invention, comprises for rendering to destination object in determining the code being used for drawing destination object
Instruction when, meet pre-conditioned branched structure sentence during this is instructed and replace with sequential organization sentence, due to treating volume
When translating code and being compiled, for branched structure sentence, in compilation process, keyword can be comprised according in branched structure sentence
On off state is combined, and generates Shader variant, and for sequential organization sentence, is directly compiled in compilation process, no
Shader variant can be generated, therefore, meet pre-conditioned branched structure sentence during this is instructed and replace with sequential organization sentence,
The quantity generating Shader variant in compilation process being reduced, thus generating the size of packet after reducing compiling, reducing
The tag memory taking during operation.
What deserves to be explained is, the embodiment of the present invention is being treated before compiled code is compiled, and treats compiled code and carries out
Pretreatment, replaces with sequential organization language by preprocessing process by meeting pre-conditioned branched structure sentence in code to be compiled
Sentence, is written as sequential organization sentence, energy compared to when writing code by meeting pre-conditioned branched structure sentence in code
Enough avoid repeating to write identical code, facilitate written in code and maintenance.
Preferably, replace with sequential organization sentence by meeting pre-conditioned branched structure sentence in instruction, including:Judge
Be used in instruction the macrodefinition of definition of keywords followed by keyword and/or for deleting keyword inactive one state
Macrodefinition followed by keyword whether be active, if so, then will comprise, in instruction, the key that is active
The branched structure sentence of word replaces with sequential organization sentence;Wherein, branched structure sentence is used for swashing according to the keyword comprising
Whether condition selecting of living is rendered.
Due to during to Shader compiling of instruction, if the keyword comprising in Shader instruction to be active
Branched structure sentence, then can be combined generating Shader variant according to the on off state of keyword in compilation process, therefore, be
The Shader variant quantity generating during reducing Shader compiling of instruction, meets pre-conditioned in instructing Shader
When branched structure sentence replaces with sequential organization sentence, the keyword that comprises in needing to instruct Shader to be active
Branched structure sentence replaces with sequential organization sentence.
The keyword comprising in branched structure sentence in Shader instruction is defined by following two modes:Definition of keywords
Sentence and delete keyword sentence, therefore, judge whether the keyword comprising in branched structure sentence is active,
Namely be used in decision instruction the macrodefinition of definition of keywords followed by keyword and/or be used for delete that keyword is invalid to be opened
The macrodefinition of off status followed by keyword whether be active.Wherein, it is used for defining key in Shader instruction
The macrodefinition of word is defined using #pragma multi_compile sentence, for deleting keyword inactive one state
Macrodefinition is defined using #pragma shader_feature sentence.
When being embodied as, judge Shader instruction in for definition of keywords macrodefinition followed by keyword and/
Or for delete the macrodefinition of keyword inactive one state followed by keyword whether be active, if so, then
The branched structure sentence of the keyword comprising to be active in instruction is replaced with sequential organization sentence, if it is not, being then not required to
Be replaced, namely do not need will instruction in comprise to be in unactivated state keyword branched structure sentence replace with suitable
Sequence structure sentence.
When being embodied as, in decision instruction be used for definition of keywords macrodefinition followed by keyword and/or be used for
Delete keyword inactive one state macrodefinition followed by keyword whether be active, including:From being used for painting
The state of activation mark of each keyword is obtained, the state of activation according to each keyword identifies in the code of destination object processed,
Generate the set of keywords of activation comprising all keywords being active;The grand of definition of keywords will be used in instruction
Definition followed by keyword mated with each keyword activating in set of keywords, according to matching result determination
In instruction be used for definition of keywords macrodefinition followed by keyword whether be active;And/or will use in instructing
In delete the macrodefinition of keyword inactive one state followed by keyword and each pass activated in set of keywords
Key word is mated, according to be used in matching result determine instruction deleting the macrodefinition of keyword inactive one state followed by
Keyword whether be active.
In code to be compiled, the code for drawing destination object includes Shader instruction, Shader makes in instructing
The state of activation mark of keyword and each keyword, grand fixed for definition of keywords in judging Shader instruction
Justice followed by keyword and/or for delete the macrodefinition of keyword inactive one state followed by keyword whether
The state of activation mark of each keyword, root when being active, can be obtained from the code for drawing destination object
According to the state of activation mark of each keyword, generate the set of keywords of activation comprising all keywords being active
Close.Wherein, state of activation mark can be identified using any number or symbol, for example:Represent un-activation using numerical value 0
State, represents state of activation using numerical value 1.
After generation activates set of keywords, open Shader instruction in the form of text, use during Shader is instructed
In definition of keywords macrodefinition followed by keyword mated with each keyword activating in set of keywords,
If the match is successful, namely in Shader instruction for definition of keywords macrodefinition followed by keyword with activated key
Arbitrary keyword in word set identical it is determined that for definition of keywords macrodefinition followed by keyword be in activation
State, if coupling unsuccessful, namely Shader instruction in for definition of keywords macrodefinition followed by keyword with
Activation set of keywords in all keywords all differ it is determined that for definition of keywords macrodefinition followed by pass
Key word is in unactivated state.Based on same method it can be determined that being used for deleting keyword inactive one in Shader instruction
The macrodefinition of state followed by keyword whether be active.
Certainly, it will be apparent to a skilled person that in other embodiments of the present invention, other side can also be adopted
Method judge Shader instruction in for definition of keywords macrodefinition followed by keyword and/or be used for deleting keyword no
Effect on off state macrodefinition followed by keyword whether be active, be not used to specifically limit herein.For example,
In other embodiments of the present invention, it is determined as follows:In the code for drawing destination object, crucial according to each
The state of activation mark of word, obtains the keyword that each is active, the keyword being active for each,
Searching for, in Shader instruction, the keyword being active with the presence or absence of this, if existing, searching in Shader instruction
Keyword be active.
It should be noted that the branched structure sentence of keyword comprising to be active in instructing Shader replaces
When being changed to sequential organization sentence, the Shader instruction being merely able to user is write is processed, and system can not be provided
Shader instruction is processed, therefore, in the state of activation obtaining each keyword from the code for drawing destination object
Before mark, further include:Judge the instruction that destination object is rendered comprising for the code drawing destination object
Whether it is located under predetermined directory, if it is determined that result is yes, then executes and obtain each pass from the code for drawing destination object
The step of the state of activation mark of key word.Wherein, predetermined directory can be the storage catalogue of user write Shader instruction, tool
When body is implemented, it is possible to use specific title or mark are marked.
Preferably, the branched structure sentence of the keyword comprising to be active in instruction is replaced with sequential organization language
Sentence, including:Using predefined mode, the keyword being active is predefined;By comprise to be active
The branched structure sentence of keyword replaces with the sequential organization sentence comprising predefined keyword.
When being embodied as, using predefined mode, the keyword being active is predefined, refer to adopt #
Define sentence predefines to keyword.After keyword being carried out predefine using #define sentence, Shader is referred to
The branched structure sentence of keyword comprising in order to be active replaces with the sequential organization comprising predefined keyword
Sentence.
As more specific embodiment it is assumed that comprising " #pragma multi_compile A B " in Shader instruction
Sentence, namely both keyword A and B is defined by macrodefined mode, if A and B is all in state of activation, and this Shader
Instruction belongs to the Shader instruction that user writes, then when carrying out pretreatment to Shader instruction, using predefined mode pair
Keyword A and B is predefined, and realizes " #define A especially by following sentence;#define B”.
Example devices
After the method describing exemplary embodiment of the invention, next, it is exemplary to describe the present invention with reference to Fig. 3
The pretreatment unit of the code to be compiled of embodiment.
Fig. 3 is a kind of one of structural representation of pretreatment unit of code to be compiled provided in an embodiment of the present invention, such as
Shown in Fig. 3, can include as lower module:
Instruction retrieval module 301, in code to be compiled, determine for draw destination object code in whether wrap
Containing the instruction for being rendered to destination object;
Sentence replacement module 302, in response to determining the instruction comprising for being rendered to destination object, instructing
Middle meet pre-conditioned branched structure sentence and replace with sequential organization sentence;
Wherein, branched structure sentence is used for choosing whether to be rendered, sequential organization sentence determine for execution render.
Preferably, the sentence replacement module 302 of the pretreatment unit of code to be compiled, including:
Judging unit 3021, in decision instruction be used for definition of keywords macrodefinition followed by keyword and/
Or for delete the macrodefinition of keyword inactive one state followed by keyword whether be active;
Replacement unit 3022, for when judging unit result of determination is to be, then will comprising to be active in instruction
The branched structure sentence of keyword replace with sequential organization sentence;
Wherein, branched structure sentence is used for choosing whether to be rendered according to the state of activation of the keyword comprising.
Preferably, judging unit 3021, including:
Obtain subelement 30211, for obtaining the activation shape of each keyword from the code for drawing destination object
State identifies, and according to the state of activation mark of each keyword, generates the activation comprising all keywords being active
Set of keywords;
Process subelement 30212, for will be used in instruction the macrodefinition of definition of keywords followed by keyword with
The each keyword having activated in set of keywords mated, according to being used for definition of keywords in matching result determine instruction
Macrodefinition followed by keyword whether be active;And/or
To be used for deleting in instruction the macrodefinition of keyword inactive one state followed by keyword with activated pass
Each keyword in key word set is mated, according to being used in matching result determine instruction deleting keyword inactive one shape
The macrodefinition of state followed by keyword whether be active.
Preferably, the state of activation of each keyword is obtained from the code for drawing destination object in acquisition subelement
Before mark, judging unit 3021 is additionally operable to:
Judge whether the instruction that destination object is rendered comprising for the code drawing destination object is located at default
Under catalogue, if it is determined that result is yes, then acquisition subelement 30211 is notified to obtain each from the code for drawing destination object
The state of activation mark of keyword.
Preferably, replacement unit 3022, specifically for:
Using predefined mode, the keyword being active is predefined;
The branched structure sentence of the keyword comprising to be active is replaced with and comprises the suitable of predefined keyword
Sequence structure sentence.
Example devices
After the method and apparatus describing exemplary embodiment of the invention, next, introducing according to the present invention's
The pretreatment unit of the code to be compiled of another exemplary embodiment.
Person of ordinary skill in the field it is understood that various aspects of the invention can be implemented as system, method or
Program product.Therefore, various aspects of the invention can be implemented as following form, that is,:Completely hardware embodiment, complete
Full Software Implementation (including firmware, microcode etc.), or the embodiment that hardware and software aspect combines, can unite here
Referred to as " circuit ", " module " or " system ".
In some possible embodiments, the pretreatment unit of the code to be compiled according to the present invention can at least include
At least one processing unit and at least one memory element.Wherein, described memory element has program stored therein code, when described
So that described processing unit executes this specification above-mentioned " illustrative methods " part when program code is executed by described processing unit
Described in the preprocess method of the code to be compiled according to the various illustrative embodiments of the present invention in step.For example, institute
State processing unit and can execute step 201 as shown in Figure 2, in code to be compiled, determine for drawing destination object
Whether comprise the instruction for being rendered to destination object, step 202 in code, comprise for target pair in response to determining
As the instruction being rendered, meet pre-conditioned branched structure sentence during this is instructed and replace with sequential organization sentence;Wherein,
Branched structure sentence is used for choosing whether to be rendered, sequential organization sentence determine for execution render.
The pretreatment unit 40 of the code to be compiled according to the embodiment of the invention to be described referring to Fig. 4.
The pretreatment unit 40 of the code to be compiled that Fig. 4 shows is only an example, to the function of the embodiment of the present invention and should not make
Bring any restriction with scope.
As shown in figure 4, the pretreatment unit 40 of code to be compiled is showed in the form of universal computing device.Code to be compiled
The assembly of pretreatment unit 40 can include but is not limited to:At least one processing unit 401 above-mentioned, at least one storage above-mentioned
Unit 402, the bus 403 of connection different system assembly (including processing unit 401 and memory element 402).
Bus 403 represents one or more of a few class bus structures, including memory bus or Memory Controller,
Peripheral bus, processor or using the arbitrarily bus-structured local bus in multiple bus structures.
Memory element 402 can include the computer-readable recording medium of form of volatile memory, such as random access memory (RAM)
4021 and/or cache memory 4022, can further include read only memory (ROM) 4023.
Memory element 402 can also include the program/utility with one group of (at least one) program module 4024
4025, such program module 4024 includes but is not limited to:Operating system, one or more application program, other program mould
The realization of network environment is potentially included in block and routine data, each of these examples or certain combination.
The pretreatment unit 40 of code to be compiled can also (such as keyboard, sensing set with one or more external equipments 404
Standby etc.) communicate, the equipment that also can enable a user to be interacted with the pretreatment unit 40 of code to be compiled with one or more is led to
Letter, and/or communicated with one or more of the other computing device with the pretreatment unit 40 enabling this code to be compiled
Any equipment (such as router, modem etc.) communication.This communication can pass through input/output (I/O) interface 405
Carry out.And, the pretreatment unit 40 of code to be compiled can also be by network adapter 406 and one or more network
(such as LAN (LAN), wide area network (WAN) and/or public network, such as the Internet) communicates.As shown in figure 4, Network adaptation
Device 406 is communicated with other modules of the pretreatment unit 40 of code to be compiled by bus 403.It will be appreciated that though in figure is not
Illustrate, other hardware and/or software module can be used in conjunction with the pretreatment unit 40 of code to be compiled, including but not limited to:
Microcode, device driver, redundant processing unit, external disk drive array, RAID system, tape drive and data are standby
Part storage system etc..
Exemplary process product
In some possible embodiments, the various aspects of the preprocess method of code to be compiled that the present invention provides are also
Can be implemented as a kind of form of program product, it includes program code, when described program product runs on a computing device
When, described program code is used for the root making described computer equipment execute described in this specification above-mentioned " illustrative methods " part
According to the step in the preprocess method of the code to be compiled of the various illustrative embodiments of the present invention, for example, described computer sets
Standby can execute step 201 as shown in Figure 2, in code to be compiled, determine for draw destination object code in be
The no instruction comprising for being rendered to destination object, step 202, comprise for wash with watercolours is carried out to destination object in response to determining
The instruction of dye, meets pre-conditioned branched structure sentence and replaces with sequential organization sentence during this is instructed;Wherein, branched structure
Sentence is used for choosing whether to be rendered, sequential organization sentence determine for execution render.
Described program product can adopt the combination in any of one or more computer-readable recording mediums.Computer-readable recording medium can be readable letter
Number medium or readable storage medium storing program for executing.Readable storage medium storing program for executing for example can be but not limited to electricity, magnetic, optical, electromagnetic, red
The system of outside line or quasiconductor, device or device, or arbitrarily above combination.The more specifically example of readable storage medium storing program for executing
(non exhaustive list) includes:There is the electrical connection of one or more wires, portable disc, hard disk, random access memory
(RAM), read only memory (ROM), erasable programmable read only memory (EPROM or flash memory), optical fiber, portable compact disc
Read memorizer (CD-ROM), light storage device, magnetic memory device or above-mentioned any appropriate combination.
As shown in figure 5, describing the journey carrying out pretreatment for treating compiled code according to the embodiment of the present invention
Sequence product 50, it using portable compact disc read only memory (CD-ROM) and can include program code it is possible in terminal
Run on equipment.However, the program product not limited to this of the present invention, in this document, readable storage medium storing program for executing can be any bag
Containing or storage program tangible medium, this program can be commanded execution system, device or device using or in connection
Use.
Readable signal medium can include the data signal in a base band or as carrier wave part propagation, wherein carries
Readable program code.The data signal of this propagation can take various forms, including but not limited to electromagnetism letter
Number, optical signal or above-mentioned any appropriate combination.Readable signal medium can also be beyond readable storage medium storing program for executing any can
Read medium, this computer-readable recording medium can send, propagate or transmit for by instruction execution system, device or device using or
Program in connection.
The program code comprising on computer-readable recording medium can be with any suitable medium transmission, including but not limited to
Wirelessly, wired, optical cable, RF etc., or above-mentioned any appropriate combination.
The program for executing present invention operation can be write with the combination in any of one or more programming language
Code, described program design language includes object oriented program language Java, C++ etc., also includes routine
Procedural programming language such as " C " language or similar programming language.Program code can be fully in user
Execute in computing device, partly execute on a user device, execute as an independent software kit, partly calculating in user
Its upper side is divided execution on a remote computing or is executed in remote computing device or server completely.It is being related to far
In the situation of journey computing device, remote computing device can include LAN (LAN) or wide by the network of any kind
Domain net (WAN) is connected to user's computing device, or it may be connected to external computing device (for example utilizes Internet service
Provider comes by Internet connection).
Although it should be noted that being referred to some modules or the submodule of the pretreatment of code to be compiled in above-detailed
Block, but this division be merely exemplary not enforceable.In fact, according to the embodiment of the present invention, retouch above
The feature of two or more modules stated and function can embody in a module.Conversely, an above-described module
Feature and function can be to be embodied by multiple modules with Further Division.
Although additionally, describe the operation of the inventive method in the accompanying drawings with particular order, this do not require that or
Hint must according to this particular order execute these operation, or have to carry out all shown operation just enable desired
Result.Additionally or alternatively, it is convenient to omit some steps, multiple steps are merged into a step execution, and/or by one
Step is decomposed into execution of multiple steps.
Although describe spirit and principles of the present invention by reference to some specific embodiments it should be appreciated that, this
Invention is not limited to disclosed specific embodiment, and the division to each side does not mean that the feature in these aspects can not yet
Combination to be benefited, this divide merely to statement convenience.It is contemplated that cover claims spirit and
In the range of included various modifications and equivalent arrangements.
Claims (10)
1. a kind of preprocess method of code to be compiled, including:
In code to be compiled, determine for draw destination object code in whether comprise for rendering to destination object
Instruction;
In response to determining the instruction comprising for being rendered to destination object, pre-conditioned branch will be met in described instruction
Structured statement replaces with sequential organization sentence;
Wherein, described branched structure sentence is used for choosing whether to be rendered, and described sequential organization sentence determines for executing wash with watercolours
Dye.
2. method according to claim 1, wherein, described will described instruction in meet pre-conditioned branched structure sentence
Replace with sequential organization sentence, including:
Judge described instruction in for definition of keywords macrodefinition followed by keyword and/or be used for deleting keyword no
Effect on off state macrodefinition followed by keyword whether be active, if so, then will described instruction in comprise locate
Branched structure sentence in the keyword of state of activation replaces with sequential organization sentence;
Wherein, described branched structure sentence is used for choosing whether to be rendered according to the state of activation of the keyword comprising.
3. method according to claim 2, wherein, described judge described instruction in for definition of keywords macrodefinition after
Keyword that face is closelyed follow and/or for delete the macrodefinition of keyword inactive one state followed by keyword whether be in
State of activation, including:
Obtain the state of activation mark of each keyword from the described code for drawing destination object, according to each pass described
The state of activation mark of key word, generates the set of keywords of activation comprising all keywords being active;
By be used in described instruction the macrodefinition of definition of keywords followed by keyword activated set of keywords with described
In each keyword mated, determined tight after the macrodefinition for definition of keywords in described instruction according to matching result
With keyword whether be active;And/or
By be used for deleting in described instruction the macrodefinition of keyword inactive one state followed by keyword sharp with described
Each keyword in set of keywords of living is mated, and is determined in described instruction according to matching result and is used for deleting keyword no
Effect on off state macrodefinition followed by keyword whether be active.
4. method according to claim 3, is obtaining each keyword from the described code for drawing destination object
State of activation mark before, further include:
Judge whether the instruction that destination object is rendered that the described code for drawing destination object comprises is located at default
Under catalogue, if it is determined that result is yes, then executes and obtain swashing of each keyword from the described code for drawing destination object
The step of status indicator alive.
5. the method according to any one of claim 2-4, wherein, described will described instruction in comprise to be active
The branched structure sentence of keyword replace with sequential organization sentence, including:
Using predefined mode, the described keyword being active is predefined;
The branched structure sentence of the keyword comprising to be active is replaced with the order knot comprising predefined keyword
Structure sentence.
6. a kind of pretreatment unit of code to be compiled, including:
Instruction retrieval module, in code to be compiled, determine for draw destination object code in whether comprise for
The instruction that destination object is rendered;
Sentence replacement module, in response to determining the instruction comprising for being rendered to destination object, by described instruction
Meet pre-conditioned branched structure sentence and replace with sequential organization sentence;
Wherein, described branched structure sentence is used for choosing whether to be rendered, and described sequential organization sentence determines for executing wash with watercolours
Dye.
7. device according to claim 6, wherein, described sentence replacement module, including:
Judging unit, for judge described instruction in for definition of keywords macrodefinition followed by keyword and/or use
In delete keyword inactive one state macrodefinition followed by keyword whether be active;
Replacement unit, for when described judging unit result of determination is to be, then will comprising to be active in described instruction
The branched structure sentence of keyword replace with sequential organization sentence;
Wherein, described branched structure sentence is used for choosing whether to be rendered according to the state of activation of the keyword comprising.
8. device according to claim 7, wherein, described judging unit, including:
Obtain subelement, for obtaining the state of activation mark of each keyword from the described code for drawing destination object
Know, according to the state of activation mark of each keyword described, generate the activation comprising all keywords being active
Set of keywords;
Process subelement, for by be used in described instruction the macrodefinition of definition of keywords followed by keyword with described
Each keyword in activation set of keywords is mated, and is determined in described instruction according to matching result and is used for definition of keywords
Macrodefinition followed by keyword whether be active;And/or
By be used for deleting in described instruction the macrodefinition of keyword inactive one state followed by keyword sharp with described
Each keyword in set of keywords of living is mated, and is determined in described instruction according to matching result and is used for deleting keyword no
Effect on off state macrodefinition followed by keyword whether be active.
9. device according to claim 8, in described acquisition subelement from the described code for drawing destination object
Before obtaining the state of activation mark of each keyword, described judging unit is additionally operable to:
Judge whether the instruction that destination object is rendered that the described code for drawing destination object comprises is located at default
Under catalogue, if it is determined that result is yes, then described acquisition subelement is notified to obtain from the described code for drawing destination object
The state of activation mark of each keyword.
10. the device according to any one of claim 7-9, wherein, described replacement unit, specifically for:
Using predefined mode, the described keyword being active is predefined;
The branched structure sentence of the keyword comprising to be active is replaced with the order knot comprising predefined keyword
Structure sentence.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201610845796.XA CN106445625A (en) | 2016-09-23 | 2016-09-23 | Preprocessing method and device of to-be-compiled codes |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201610845796.XA CN106445625A (en) | 2016-09-23 | 2016-09-23 | Preprocessing method and device of to-be-compiled codes |
Publications (1)
Publication Number | Publication Date |
---|---|
CN106445625A true CN106445625A (en) | 2017-02-22 |
Family
ID=58166075
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201610845796.XA Pending CN106445625A (en) | 2016-09-23 | 2016-09-23 | Preprocessing method and device of to-be-compiled codes |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN106445625A (en) |
Cited By (7)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN109885310A (en) * | 2019-01-14 | 2019-06-14 | 珠海金山网络游戏科技有限公司 | A kind of method and device reducing mobile phone games Shader module EMS memory occupation |
CN110490961A (en) * | 2019-08-15 | 2019-11-22 | 天津优乐互娱科技有限公司 | A kind of hair Brush Tool and the method for drawing hair |
CN111596920A (en) * | 2019-02-21 | 2020-08-28 | 迈普通信技术股份有限公司 | File compiling method and device, compiling equipment and storage medium |
CN112256273A (en) * | 2020-10-20 | 2021-01-22 | 网易(杭州)网络有限公司 | Application program packaging method and device and electronic equipment |
CN113590221A (en) * | 2021-08-02 | 2021-11-02 | 上海米哈游璃月科技有限公司 | Method and device for detecting number of shader variants, electronic equipment and storage medium |
CN113906394A (en) * | 2019-05-24 | 2022-01-07 | 微软技术许可有限责任公司 | Executable code branch annotation for objective branch validation |
CN114077433A (en) * | 2021-11-18 | 2022-02-22 | 大连东软信息学院 | Cross-platform modular shader language general integration method |
Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101063944A (en) * | 2006-12-27 | 2007-10-31 | 北京大学 | Method for recognizing composite conditional branch structure |
US20140258997A1 (en) * | 2013-03-06 | 2014-09-11 | Qualcomm Incorporated | Dynamic reconfigurable compiler |
CN104536797A (en) * | 2015-01-14 | 2015-04-22 | 大唐微电子技术有限公司 | Java program precompiling method and precompiler |
CN105005495A (en) * | 2015-06-23 | 2015-10-28 | 珠海金山网络游戏科技有限公司 | Game engine |
-
2016
- 2016-09-23 CN CN201610845796.XA patent/CN106445625A/en active Pending
Patent Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101063944A (en) * | 2006-12-27 | 2007-10-31 | 北京大学 | Method for recognizing composite conditional branch structure |
US20140258997A1 (en) * | 2013-03-06 | 2014-09-11 | Qualcomm Incorporated | Dynamic reconfigurable compiler |
CN104536797A (en) * | 2015-01-14 | 2015-04-22 | 大唐微电子技术有限公司 | Java program precompiling method and precompiler |
CN105005495A (en) * | 2015-06-23 | 2015-10-28 | 珠海金山网络游戏科技有限公司 | Game engine |
Cited By (10)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN109885310A (en) * | 2019-01-14 | 2019-06-14 | 珠海金山网络游戏科技有限公司 | A kind of method and device reducing mobile phone games Shader module EMS memory occupation |
CN111596920A (en) * | 2019-02-21 | 2020-08-28 | 迈普通信技术股份有限公司 | File compiling method and device, compiling equipment and storage medium |
CN113906394A (en) * | 2019-05-24 | 2022-01-07 | 微软技术许可有限责任公司 | Executable code branch annotation for objective branch validation |
CN110490961A (en) * | 2019-08-15 | 2019-11-22 | 天津优乐互娱科技有限公司 | A kind of hair Brush Tool and the method for drawing hair |
CN112256273A (en) * | 2020-10-20 | 2021-01-22 | 网易(杭州)网络有限公司 | Application program packaging method and device and electronic equipment |
CN112256273B (en) * | 2020-10-20 | 2023-11-24 | 网易(杭州)网络有限公司 | Application program packaging method and device and electronic equipment |
CN113590221A (en) * | 2021-08-02 | 2021-11-02 | 上海米哈游璃月科技有限公司 | Method and device for detecting number of shader variants, electronic equipment and storage medium |
CN113590221B (en) * | 2021-08-02 | 2024-05-03 | 上海米哈游璃月科技有限公司 | Method and device for detecting number of shader variants, electronic equipment and storage medium |
CN114077433A (en) * | 2021-11-18 | 2022-02-22 | 大连东软信息学院 | Cross-platform modular shader language general integration method |
CN114077433B (en) * | 2021-11-18 | 2024-05-03 | 大连东软信息学院 | Cross-platform modularized shader language universal integration method |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN106445625A (en) | Preprocessing method and device of to-be-compiled codes | |
Landin | The mechanical evaluation of expressions | |
Zhang et al. | Interactive program synthesis by augmented examples | |
CN107229848A (en) | A kind of code reinforcement means and device | |
US20220035614A1 (en) | Method and electronic device for deploying operator in deep learning framework | |
CN102200911B (en) | variable closure | |
Morrison | Condensed graphs: Unifying availability-driven, coercion-driven and control-driven computing | |
CN108139891A (en) | Include suggesting for the missing of external file | |
CN109634684A (en) | Method, apparatus, computer equipment and the storage medium of application program load language | |
EP3387525B1 (en) | Learning from input patterns in programing-by-example | |
CN103198240B (en) | A kind of method and apparatus for the protection of code security | |
US9886251B2 (en) | Optimized compiling of a template function | |
EP4363965A1 (en) | Source code synthesis for domain specific languages from natural language text | |
Fowler | A pedagogical framework for domain-specific languages | |
CN101000557B (en) | Virtual machine | |
JP7344259B2 (en) | Pattern transformation methods, apparatus, electronic devices, computer storage media and computer program products in deep learning frameworks | |
CN112632924B (en) | Method, system, electronic equipment and storage medium for regularized execution sequence labeling | |
Kollár | Formal Processing of Informal Meaning by Abstract Interpretation. | |
CN109344385A (en) | Natural language processing method, apparatus, computer equipment and storage medium | |
Takizawa et al. | Xevolver for performance tuning of C programs | |
CN110377337A (en) | Information extracting method, intelligent terminal and storage medium in a kind of application | |
Hamdaoui | Concurrency, references and linear logic | |
Shaughnessy | Ruby Under a Microscope: Learning Ruby Internals Through Experiment | |
Arima et al. | Extension of the Function to Ensure Real-time Traceability between UML Sequence Diagram and Java Source Code on RETUSS | |
US11681545B2 (en) | Reducing complexity of workflow graphs through vertex grouping and contraction |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
C06 | Publication | ||
PB01 | Publication | ||
C10 | Entry into substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
RJ01 | Rejection of invention patent application after publication | ||
RJ01 | Rejection of invention patent application after publication |
Application publication date: 20170222 |