Abstract:
In an identical function definition generation determining step of a template compilation method, dependency between a function definition code and a template parameter is analyzed, and when there is no dependency, a common function is defined and a plurality of function definitions obtained before defining the common function are deleted in a function definition sharing step. Thereafter, a function call obtained before defining the common function is replaced with a call of the common function in a function call replacing step. Accordingly, among a plurality of function definition codes generated from a template, function definition codes generated as the identical code are shared, so as to reduce the code size that generally increases due to template facilities.

Description:
BACKGROUND OF THE INVENTION  
       [0001]     The present invention relates to a compilation method for converting a program described with a high-level language with template facilities into object codes.  
         [0002]     In recent development of software, the scale of a program has become large, and therefore, an object-oriented language with high maintainability and reusability is regarded useful.  
         [0003]     A typical example of the object-oriented language is the C++ language. The C++ language has template facilities and is usable for generic programming with high maintainability and reusability. Also, a standard template library designated as STL is generally provided to a compiler, and programming using the template facilities is expected to increase in the future.  
         [0004]      FIG. 12  shows examples of codes generated through compilation of a C++ program by using the template facilities.  
         [0005]     As shown in source codes (a) and (b) of  FIG. 12 , templates respectively representing a class group and a function group are defined in the C++ language, and thus, function definitions can be easily generated by giving template parameters. In a source code (c), temperate parameters int and long are given to the template of the source code (a) or (b), so as to generate A&lt;int&gt; type and A&lt;long&gt; type classes and functions A&lt;int&gt;::f and A&lt;long&gt;::f with a return value of a void type and arguments of an int type and a long type and to define an object ‘a’ of the A&lt;int&gt; type and an object ‘b’ of the A&lt;long&gt; type. In a source code (d), generated member functions A&lt;int&gt;::f and A&lt;long&gt;::f are called.  
         [0006]     The generated codes shown in  FIG. 12  result from the compilation performed on the source codes by a conventional compilation method. It is understood that definition codes (f) and (g) of the functions A&lt;int&gt;::f and A&lt;long&gt;::f generated by giving the parameters int and long to the template are generated and that the definition codes (f) and (g) are called by a call statement in a definition code (e) of a function h. At this point, a label corresponding to the operand of the call statement is a label indicating the starting address of the function definition. In this manner, a plurality of classes and functions can be easily generated by defining a template and giving template parameters.  
         [0007]     In the conventional compilation, when different template parameters are given to a template, functions (including a static function, an external function and a virtual or non-virtual member function) corresponding to the respective parameter values are always generated as codes with different definitions. For example, in  FIG. 12 , the definition code (f) is generated correspondingly to the template parameter int and the definition code (g) is generated correspondingly to the template parameter long. Therefore, the whole code size is largely increased in accordance with “the code size of function definitions generated from a template”×“the number of kinds of template parameters”.  
         [0008]     However, with respect to a function generated from a template, a different code is not always generated when a template parameter is different but an identical code may be generated. For example, in  FIG. 12 , although the functions A&lt;int&gt;::f and A&lt;long&gt;::f are given different template parameters, the generated definition codes (f) and (g) are identical to each other.  
         [0009]     As conventional technique to prevent such increase of the code size, for example, Japanese Laid-Open Patent Publication No. 9-231077 describes a program description method in which a common part of a program is separated, as an implementation class with no specified type, from an interface class with a specified type having a template with a dummy argument.  
         [0010]     In this conventional technique, however, a programmer is forced to intentionally describe a common part of a program as an implementation class with no specified type, which increases the burden of the programmer.  
       SUMMARY OF THE INVENTION  
       [0011]     An object of the invention is providing a template compilation method in which the code size increased due to template facilities is reduced without making a programmer conscious of optimum program description.  
         [0012]     In order to achieve the object, according to the present invention, two or more function definition codes generated as an identical code among a plurality of function definition codes generated from a template are automatically determined by a CPU, so as to share the two or more identical function definition codes.  
         [0013]     Specifically, the template compilation method of this invention for converting an input program described with a high-level language with template facilities into object codes, includes an identical function definition generation determining step of determining whether or not identical function definitions are generated, as definitions of a plurality of functions included in the input program, from a template by using different template parameters; a function definition sharing step, performed when it is determined that the identical function definitions are generated in the identical function definition generation determining step, of replacing the definitions of the plurality of functions generated as the identical function definitions with one common function definition; and a function call replacing step, performed when the common function definition is replaced in the function definition sharing step, of replacing calls of the plurality of functions obtained before replacing the common function definition with a call of the common function definition.  
         [0014]     In an aspect of the template compilation method of this invention, it is analyzed in the identical function definition generation determining step whether or not any of the definitions of the plurality of functions uses a function template as the template and includes a portion depending upon a template parameter in a function defining portion thereof.  
         [0015]     In another aspect of the template compilation method of this invention, in the identical function definition generation determining step, when it is determined as a result of analysis that any of the definitions of the plurality of functions using a function template as the template includes no portion depending upon a template parameter in the function defining portion thereof, nondependent function information composed of at least a file name, a template function name and an instantiated function name is generated.  
         [0016]     In another aspect of the template compilation method of this invention, it is analyzed in the identical function definition generation determining step whether or not any of the definitions of the plurality of functions uses a class template as the template and includes a portion depending upon a template parameter in a member function defining portion thereof.  
         [0017]     In another aspect of the template compilation method of this invention, in the identical function definition generation determining step, when it is determined as a result of analysis that any of the definitions of the plurality of functions using a class template as the template includes no portion depending upon the template parameter in the member function defining portion thereof, nondependent function information composed of at least a file name, a template function name and an instantiated function name is generated.  
         [0018]     In another aspect of the template compilation method of this invention, it is analyzed in the identical function definition generation determining step whether or not any of the definitions of the plurality of functions uses a function template as the template and includes type conversion depending upon a template parameter in a function defining portion thereof, whether or not any of the definitions of the plurality of functions includes a function call using an argument depending upon a template parameter, and whether or not there already exists a function definition instantiated with a template parameter with an identical type size.  
         [0019]     In another aspect of the template compilation method of this invention, in the identical function definition generation determining step, when it is determined as a result of analysis that none of the definitions of the plurality of functions includes type conversion depending upon a parameter in a function defining portion thereof, that none of the definitions of the plurality of functions includes a function call using an argument depending upon a template parameter and that there already exists a function definition instantiated with a template parameter with an identical type size, specific parameter identical function information composed of at least a file name, a template function name, a parameter size and an instantiated function name is generated.  
         [0020]     In another aspect of the template compilation method of this invention, it is analyzed in the identical function definition generation determining step whether or not any of the definitions of the plurality of functions uses a class template as the template and includes type conversion depending upon a template parameter in a member function defining portion thereof, whether or not any of the definitions of the plurality of functions includes a function call using an argument depending upon a template parameter and whether or not there already exists a function definition instantiated with a template parameter with an identical type size.  
         [0021]     In another aspect of the template compilation method of this invention, in the identical function definition generation determining step, when it is determined as a result of analysis that none of the definitions of the plurality of functions includes type conversion depending upon a parameter in a member function defining portion thereof, that none of the definitions of the plurality of functions includes a function call using an argument depending upon a template parameter and that there already exists a function definition instantiated with a template parameter with an identical type size, specific parameter identical function information composed of at least a file name, a template function name, a parameter size and an instantiated function name is generated.  
         [0022]     In another aspect of the template compilation method of this invention, the function definition sharing step includes sub-steps of receiving the nondependent function information generated in the identical function definition generation determining step; registering names of instantiated functions generated from an identical template in the nondependent function information with a common function name; and changing function definition codes of the instantiated functions generated from the identical template into a function definition code of the common function definition.  
         [0023]     In another aspect of the template compilation method of this invention, the function definition sharing step includes sub-steps of receiving the specific parameter identical function information generated in the identical function definition generation determining step; registering names of instantiated functions generated from an identical template with an identical parameter size in the specific parameter identical function information with a common function name; and changing function definition codes of the instantiated functions generated from the identical template with the identical parameter size into a function definition code of the common function definition.  
         [0024]     In another aspect of the template compilation method of this invention, in the function call replacing step, a function call statement using a starting address of a function obtained before generating the common function definition is replaced with a function call statement using a starting address of the common function definition obtained in the function definition sharing step.  
         [0025]     In another aspect of the template compilation method of this invention, in the function call replacing step, when the function call is a virtual function call, a starting address of a function obtained before generating the common function definition registered in a virtual function table is replaced with a starting address of the common function definition obtained in the function definition sharing step.  
         [0026]     In another aspect of the template compilation method of this invention, in the function call replacing step, when a plurality of virtual function tables attain identical registration contents as a result of replacing the starting address of the function obtained before generating the common function definition registered in the virtual function table with the starting address of the common function definition, the plurality of virtual function tables are replaced with one common virtual function table.  
         [0027]     As described above, according to the present invention, it is first determined whether or not identical function definitions are generated among a plurality of function definitions of an input program from a template by using different template parameters. In the case where it is determined as a result that the identical definitions are generated, these identical function definitions are replaced with one common function definition, and calls of these function definitions are replaced with a call of the common function definition.  
         [0028]     Accordingly, even when the input program includes a plurality of function definitions generated by giving different parameters to the template, when these plural function definitions are generated as identical definition codes, the identical definition codes corresponding to the plural function definitions are not included in the resultant output codes. As a result, object codes can be generated efficiently with a small code size. 
     
    
     BRIEF DESCRIPTION OF THE DRAWINGS  
       [0029]      FIG. 1  is a diagram of a compilation step in a template compilation method according to an embodiment of the invention;  
         [0030]      FIG. 2  is a process flowchart for an identical function definition generation determining step in the compilation step of  FIG. 1 ;  
         [0031]      FIG. 3  is a process flowchart for a function definition sharing step in the compilation step of  FIG. 1 ;  
         [0032]      FIG. 4  is a process flowchart for a function call replacing step in the compilation step of  FIG. 1 ;  
         [0033]      FIG. 5  is a diagram of a program stored in a program storage;  
         [0034]      FIG. 6A  is a diagram of template information extracted in the identical function definition generation determining step,  FIG. 6B  is a diagram of parameter nondependent function information generated in the identical function definition generation determining step and  FIG. 6C  is a diagram of specific parameter identical function information generated in the identical function definition generation determining step;  
         [0035]      FIG. 7A  is a diagram of name information of function definition that are registered with common function names in the function definition sharing step and  FIG. 7B  is a diagram of function definition code information in which function definition codes obtained before sharing a common code are deleted and common function definition codes are registered in the function definition sharing step;  
         [0036]      FIG. 8A  is a diagram of function call information extracted in the function call replacing step and replacement with common functions and  FIG. 8B  is a diagram of virtual function table information extracted in the function call replacing step and replacement with common functions;  
         [0037]      FIG. 9A  is a diagram of replacement of a virtual function table with a common virtual function table to be referred to in a virtual call in the function call replacing step and  FIG. 9B  is a diagram of replacement of the entity of the virtual function table with the common virtual function table in the function call replacing step;  
         [0038]      FIG. 10  is a diagram of outputs resulting from employment of the template compilation method of the embodiment of the invention;  
         [0039]      FIG. 11  is a diagram of outputs resulting from employment of a conventional compilation method; and  
         [0040]      FIG. 12  is a diagram of an exemplified program using templates and resultant output codes. 
     
    
     DETAILED DESCRIPTION OF THE INVENTION  
       [0041]     A preferred embodiment of the invention will now be described with reference to the accompanying drawings.  
         [0042]      FIG. 1  is a structure chart of a compilation method according to the embodiment of the invention.  
         [0043]     The compilation step of  FIG. 1  includes an inputting step S 102 , a syntactic analyzing step S 103 , an identical function definition generation determining step S 105 , a function definition sharing step S 106 , a function call replacing step S 107 , an intermediate code generating step S 109 , an optimizing step S 110 , a resource allocating step S 111  and an outputting step S 112 . The respective steps of the compilation step are processing executed by a compilation apparatus equipped with a CPU on the basis of a compiler.  
         [0044]     A program storage D 101  stores input programs to be compiled.  
         [0045]     In the input step S 102 , all the programs stored in the program storage D 101  are successively input to be passed to the syntactic analyzing step S 103 .  
         [0046]     In the syntactic analyzing step S 103 , the syntax of each program passed from the input step S 102  is analyzed, so as to generate a symbol table, a syntax tree and the like.  
         [0047]     In the identical function definition generation determining step S 105 , information associated with a template is extracted from information generated in the syntactic analyzing step S 103 , and it is analyzed whether or not identical function definitions are generated from the template by using different template parameters.  
         [0048]     In the function definition sharing step S 106 , information associated with function definition is extracted from the information generated in the syntactic analyzing step S 103 , the analysis result is passed from the identical function definition generation determining step S 105 , and a plurality of function definitions generated as the identical function definitions by using different template parameters are replaced with a single common function definition.  
         [0049]     In the function call replacing step S 107 , information associated with function call is extracted from the information generated in the syntactic analyzing step S 103 , the replacement result is passed from the function definition sharing step S 106 , and function calls obtained before sharing the common definition are replaced with a call of the common function definition on the basis of the resultant common function definition.  
         [0050]     In the intermediate code generating step S 109 , an intermediate code is generated on the basis of the syntax tree generated in the syntactic analyzing step S 103 . In generating an intermediate code associated with a function definition generated from the template or a virtual function table, the replaced information obtained through execution of the identical function definition generation determining step S 105 , the function definition sharing step S 106  and the function call replacing step S 107  is referred to to generate a corresponding intermediate code.  
         [0051]     In the optimizing step S 110 , various optimization is performed on the intermediate code generated in the intermediate code generating step S 1109 .  
         [0052]     In the resource allocating step S 111 , hardware resources such as a register and a memory are allocated to all variables included in the intermediate code having been optimized in the optimizing step S 110 .  
         [0053]     In the outputting step S 112 , the intermediate code having been subjected to the resource allocation in the resource allocating step S 111  is converted into an object code, which is output to a generated code storage D 113 .  
         [0054]     The generated code storage D 113  stores the object code having been converted through the compilation step including the steps S 102  through S 112 .  
         [0055]     The inputting step S 102 , the syntactic analyzing step S 103 , the intermediate code generating step S 109 , the optimizing step S 110 , the resource allocating step S 111  and the outputting step S 112  are not herein described in detail because they are not the principal point of the invention.  
         [0056]     Next, processing of the identical function definition generation determining step S 105  will be described with reference to  FIG. 2  by exemplifying application to a program shown in  FIG. 5 .  
         [0057]     The processing of the identical function definition generation determining step S 105  is performed through steps a 1  through all, which will now be described in this order.  
         [0058]     In the step a 1 , the information associated with a template is extracted from the information generated in the syntactic analyzing step S 103 . Since information of templates of all the input files has been analyzed in the syntactic analyzing step S 103 , merely the information associated with templates is extracted. Referring to the program shown in  FIG. 5 , in all the input files template 1 .cc and template 2 .cc, defined templates are a function template g in the file template 1 .cc and a class template B in the file template 2 .cc. Therefore, an extraction result as shown in  FIG. 6A  is obtained. It is noted that the “#include” statement on the first line of the input file template 1 .cc or template 2 .cc corresponds to a program for expanding the content of a file enclosed in “ ” in this position.  
         [0059]     In the step a 2 , in the whole extracted information of the templates, processing of a loop  1  (including the steps a 2  through a 6 ) is repeatedly performed on respective member functions of each class template. In  FIG. 6A , [ 2 ] and [ 3 ] correspond to the member functions of the class template, and hence, the processing of the loop  1  is repeatedly performed on the member functions [ 2 ] and [ 3 ].  
         [0060]     In the step a 3 , it is determined whether or not the member function has a template code not depending upon the template parameter at all. When NO, the flow proceeds to the step a 4 , and when YES, the flow proceeds to the step a 5 . For example, when the member function [ 2 ] of  FIG. 6A  is subjected to the determination of the step a 3 , the code of the member function [ 2 ] is return b; regardless of the value of the template parameter T and hence does not depend upon the value of the template parameter T at all. Therefore, the determination made in the step a 3  is YES, and hence the flow proceeds to the step as.  
         [0061]     Also, the code of the member function [ 3 ] is return y; regardless of the value of the template parameter T and hence does not depend upon the value of the template parameter T at all. Therefore, the determination made in the step a 3  is YES, and hence the flow proceeds to the step as.  
         [0062]     In the step a 4 , it is determined whether or not there is a function from which identical codes are generated with respect to a specific combination of template parameter values. The process of the step a 4  is the same as that of the step a 9  performed in a loop  2  of the step a 7  described below. Since the member functions [ 2 ] and [ 3 ] of  FIG. 6A  have been determined as YES in the step a 3 , these functions are not subjected to the process of the step a 4 . This process will be described in detail in describing the step a 9 .  
         [0063]     In the step a 5 , parameter nondependent function information of the member function having been determined as YES in the step a 4  is generated. Since the member functions [ 2 ] and [ 3 ] of  FIG. 6A  are parameter nondependent functions, the parameter nondependent function information as shown in  FIG. 6B  composed of at least a file name, a template function name and an instantiated function name made into entity (instantiated) by the template parameter is generated with respect to each of the member functions [ 2 ] and [ 3 ].  
         [0064]     In the step a 6 , the flow returns to the step a 2  so as to repeat the processing of the loop  1 .  
         [0065]     In the step a 7 , processing of the loop  2  is repeatedly performed on function templates included in the whole extracted information of the templates. In  FIG. 6A , [ 1 ] corresponds to a function template. The processing of the loop  2  is executed on the function template [ 1 ].  
         [0066]     In the step a 8 , it is determined whether or not the function has a template code not depending upon the template parameter at all. When NO, the flow proceeds to the step a 9 , and when YES, the flow proceeds to the step a 10 . When the function template [ 1 ]of  FIG. 6A  is subjected to the determination of the step a 8 , the code of the function template [ 1 ] depends upon the template parameter because the types of virtual arguments a and b are different depending upon the value of the template parameter T. Accordingly, the function template [ 1 ] is determined as NO in the step a 8 , and the flow proceeds to the step a 9 .  
         [0067]     In the step a 9 , it is determined whether or not there is a function from which identical codes are generated with respect to a specific combination of template parameter values. The process of the step a 9  is the same as that of the step a 4  performed in the loop  1  of the step a 2 .  
         [0068]     The process of the step a 4  and the step a 9  is performed through steps b 1  through b 4 , which will now be described in this order.  
         [0069]     In the step b 1 , it is determined whether or not there is explicit or implicit type conversion in the function code. When YES, the flow proceeds to the step b 2 , and when NO, the flow goes out of the process of the step a 4  or the step a 9 . When the function template [ 1 ] of  FIG. 6A  is subjected to the determination of the step b 1 , there is no type conversion in the code return a+b; of the function template [ 1 ], and therefore, the function template [ 1 ] is determined as YES in the step b 1 , and the flow proceeds to the step b 2 .  
         [0070]     In the step b 2 , it is determined whether or not there is a function call by using a parameter dependent argument. When YES, the flow proceeds to the step b 3 , and when NO, the flow goes out of the process of the step a 4  or the step a 9 . When the function template [ 1 ] of  FIG. 6A  is subjected to the determination of the step b 2 , there is no function call in the code return a+b; of the function template [ 1 ], and hence, the function template [ 1 ] is determined as YES in the step b 2 , and the flow proceeds to the step b 3 .  
         [0071]     In the step b 3 , it is determined whether or not there are function definitions generated by using parameters with the same type size in the instantiated parameter values. When YES, the flow proceeds to the step b 4 , and when NO, the flow goes out of the process of the step a 4  or the step a 9 . When the function template [ 1 ] of  FIG. 6A  is subjected to the determination of the step b 3 , instantiated template parameters of the function template [ 1 ] are of the int type and the long type. These types have the same size depending upon compilation circumstances. Herein, it is assumed that both of these types have a size of 4 bytes. Since there are function definitions generated by using the parameters with the same type size, the flow proceeds to the step b 4 .  
         [0072]     In the step b 4 , specific parameter identical function information is generated on the basis of the function definitions having been determined as YES in all the determinations of the steps b 1  through b 3 . The function template [ 1 ] of  FIG. 6A  has been determined as YES in all the determinations of the steps b 1  through b 3 , and identical codes are generated when the template parameter value is int and when it is long. Therefore, the specific parameter identical function information as shown in  FIG. 6C  composed of at least a file name, a template function name, a parameter size and an instantiated function name is generated with respect to the function template [ 1 ].  
         [0073]     In the step a 10 , parameter nondependent function information of the function having been determined as YES in the step a 8  is generated. The function template [ 1 ] of  FIG. 6A  has been determined as NO in the step a 8 , the process of the step a 10  is not performed.  
         [0074]     In the step all, the flow returns to the step a 7 , so as to repeatedly perform the processing of the loop  2 .  
         [0075]     In this manner, when the processing of the identical function definition generation determining step S 105  is applied to the program of  FIG. 5 , the parameter nondependent function information of  FIG. 6B  and the specific parameter identical function information of  FIG. 6C  are generated. These resultant information are passed to the function definition sharing step S 106 .  
         [0076]     Next, the processing of the function definition sharing step S 106  will be described with reference to  FIG. 3 .  
         [0077]     The processing of the function definition sharing step S 106  is performed through steps c 1  through c 8 , which will now be described in this order.  
         [0078]     In the step c 1 , in the information passed from the identical function definition generation determining step S 105 , the parameter nondependent function information is subjected to processing of a loop  1  (including the steps c 1  through c 4 ). Specifically, in this embodiment, the processing of the loop  1  is repeatedly performed on the parameter nondependent function information of  FIG. 6B .  
         [0079]     In the step c 2 , a common function name is registered with respect to the instantiated function names generated from the same template, and the flow proceeds to the step c 3 . For example, when the parameter nondependent function information of  FIG. 6B  is subjected to the process of the step c 2 , a part [x] of  FIG. 7A  is registered.  
         [0080]     In the step c 3 , the definitions of the respective instantiated functions are deleted from the syntactic analysis result, definition of a common function is registered in the syntactic analysis result, and the flow proceeds to the step c 4 . When the process of the step c 3  is executed on the function definition name information [x] of  FIG. 7A , the function definition codes of the instantiated functions are deleted and the function definition code of the common function is newly registered as shown in a part [x] of  FIG. 7B .  
         [0081]     In the step c 4 , the flow returns to the step c 1 , so as to repeat the processing of the loop  1 .  
         [0082]     In the step c 5 , in the information passed from the identical function definition generation determining step S 105 , the specific parameter identical function information is repeatedly subjected to processing of a loop  2  (including the steps c 5  through c 8 ). The specific parameter identical function information of  FIG. 6C  is repeatedly subjected to the processing of the loop  2 .  
         [0083]     In the step c 6 , a common function name is registered with respect to instantiated function names generated from the same template by using parameters with the same size, and the flow proceeds to the step c 7 . When the process of the step c 6  is executed on the specific parameter identical function information of  FIG. 6C , a part [y] of  FIG. 7A  is registered.  
         [0084]     In the step c 7 , the definitions of the respective instantiated functions are deleted from the syntactic analysis result, a definition of a common function is registered in a function definition part, and the flow proceeds to the step c 8 . When the process of the step c 7  is executed on the definition name information [y] of the common function shown in  FIG. 7A , the function definition codes of the instantiated functions are deleted and the function definition code of the common function is newly registered in the syntactic analysis result as shown in a part [y] of  FIG. 7B .  
         [0085]     In the step c 8 , the flow returns to the step c 5 , so as to repeatedly perform the processing of the loop  2 .  
         [0086]     In this manner, when the processing of the function definition sharing step S 106  is applied to the parameter nondependent function information of  FIG. 6B  and the specific parameter identical function information of  FIG. 6C , the function definition names of  FIG. 7A  and the function definition codes of  FIG. 7B  are generated, so as to be passed to the function call replacing step S 107 .  
         [0087]     Next, the processing of the function call replacing step S 107  will be described with reference to  FIG. 4 .  
         [0088]     The processing of the function call replacing step S 107  is performed through steps d 1  through d 13 , which will now be described in this order.  
         [0089]     In the step d 1 , information associated with function calls is extracted from the information generated in the syntactic analyzing step S 103 . In the case where there is virtual function table information of each class, this information is also extracted. Since the information associated with the function calls included in all the input files has been analyzed in the syntactic analyzing step S 103 , merely the information associated with function calls and the virtual function table information are extracted. In the program shown in  FIG. 5 , a function func 1  calls the function generated from the template in the file template 1 .cc, and a function func 2  calls the member function of the class generated from the template in the file template 2 .cc. Therefore, extraction result for the function call information as shown in  FIG. 8A  is obtained. Also, in the function func 2 , a virtual function call of a class inherited in the class A is performed, and hence, extraction result for the virtual function table information as shown in  FIG. 8B  is obtained.  
         [0090]     In the step d 2 , processing of a loop  1  is repeatedly performed on the whole function call information for calling functions generated from the templates. In  FIG. 8A , the functions generated from the templates are called in both the functions func 1  and func 2 , and hence, the processing of the loop  1  is repeatedly executed on these functions.  
         [0091]     In the step d 3 , a call of a function whose common function name has been registered is replaced with a common function call. In  FIG. 8A , a function call with a reference mark (# 1 ) is replaced with a common function call with a reference mark (# 2 ), a function call with a reference mark (# 3 ) is replaced with a common function call with a reference mark (# 4 ), and a function call with a reference mark (# 5 ) is replaced with a common function call with a reference mark (# 6 ).  
         [0092]     In the step d 4 , it is determined whether or not the function call is a virtual function call. When YES, the flow proceeds to the step d 5 , and when NO, the flow proceeds to the step d 13 . In  FIG. 8A , the function call with the reference mark (# 4 ) is a virtual function call, and hence the flow proceeds to the step d 5 . Also, since the function calls with the reference marks (# 2 ) and (# 6 ) are ordinary calls, the flow proceeds to the step d 13 .  
         [0093]     In the step d 5 , the processing of the loop  2  is repeatedly executed on all virtual function tables in which functions are registered with a common function name. In  FIG. 8B , the processing of the loop  2  is repeatedly performed on a virtual function table of a class B&lt;int&gt; and a virtual function table of a class B&lt;long&gt;.  
         [0094]     In the step d 6 , the functions registered with the common function name in the virtual function table are replaced with a common function. An address of the function is actually registered, but it is herein described for simplification that the function is registered. In  FIG. 8B , with respect to functions registered with reference marks (# 7 ) and (# 9 ), common function names have been registered in the function definition sharing step S 106 , and therefore, these functions are respectively replaced with common functions as shown with reference marks (# 8 ) and (# 10 ).  
         [0095]     In the step d 7 , the flow returns to the step d 5 , so as to repeat the processing of the loop  2 .  
         [0096]     In the step d 8 , processing of a loop  3  is repeatedly performed on the virtual function tables in which the functions have been replaced. In  FIG. 8B , the processing of the loop  3  is repeatedly performed on virtual function tables vtbl_B&lt;int&gt; and vtbl_B&lt;long&gt;.  
         [0097]     In the step d 9 , it is determined whether or not any virtual function tables have attained the same contents through the replacement performed in the step d 6 . When YES, the flow proceeds to the step d 10 , and when NO, the flow proceeds to the step d 12 . In  FIG. 8B , the virtual function tables vtbl_B&lt;int&gt; and vtbl_B&lt;long&gt; have attained the same registration contents, and hence, the flow proceeds to the step d 10 .  
         [0098]     In the step d 10 , the virtual function tables having the same contents are deleted, and a common virtual function table is generated. The virtual function tables vtbl_B&lt;int&gt; and vtbl_B&lt;long&gt; of  FIG. 8B  are deleted and a common virtual function table vtbl_B is newly generated as shown in  FIG. 9B .  
         [0099]     In the step d 11 , a virtual function table to be referred to in a virtual function call is replaced with a common virtual function table. The virtual function tables vtbl_B&lt;int&gt; and vtbl_B&lt;long&gt; referred to in the virtual calls in  FIG. 8A  are replaced with the common virtual function table vtbl_B as shown in  FIG. 9A .  
         [0100]     In the step d 12 , the flow returns to the step d 8 , so as to repeat the processing of the loop  3 .  
         [0101]     In this manner, when the processing of the identical call replacing step S 107  is applied to the program shown in  FIG. 5 , the function call information of  FIG. 9A  and the virtual function table information of  FIG. 9B  are generated.  
         [0102]     In the intermediate code generating step S 109 , not only the syntax analysis data generated in the syntactic analyzing step S 103  but also data newly generated through the identical function definition determining step S 105 , the function definition sharing step S 106  and the function call replacing step S 107  are all read, so as to generate object codes to be ultimately stored in the generated code storage D 113 .  
         [0103]      FIG. 10  shows output codes obtained as a result of application of the compilation step of this embodiment to the program of  FIG. 5  in the aforementioned manner. Also, for comparison,  FIG. 11  shows output codes obtained as a result of conventional compilation. It is understood from these drawings that overlapped codes, such as codes (c) and (d), (f) and (g), (l) and (m), and (n) and (o) of  FIG. 11 , are changed into common codes (c), (e), (j) and (k) of  FIG. 10  through the application of the compilation step of this embodiment. Thus, by employing the compilation step of this embodiment, object codes can be generated efficiently with small code sizes and with a small number of execution steps when identical codes are generated by giving different parameters to a template.  
         [0104]     As described so far, even in the case where there are a plurality of function definitions resulting from different parameters given to a template in an input program, when identical definition codes are generated as the plural function definitions, resultant output codes include one identical definition code alone according to the present invention. Therefore, the invention is useful as a template compilation method or the like for efficiently generating output codes with a small code size.