Method for compilation of programming languages

Abstract: A language processing method targeted at hardware having a data space greater than the data width of an architecture is improved in that address calculation of an array element is performed efficiently and the size of an object is reduced while the execution performance of the object is enhanced. A command which designates a maximum size of an array is inputted, and it is analyzed whether or not the designated size is equal to or smaller than a fixed size (step 301). When a result of the analysis is equal to or smaller than the fixed size, a subscript of the array is taken out first (step 306). An offset is calculated from contents of the subscript thus taken out and the data width of the array element (step 309), and an address of the array element is calculated from the offset thus calculated and the top address of the array (step 310).

Description: 1. Field of the Invention This invention relates to a language processing method, and particularly to a language processing method used to compile a source program described in a language having an array structure such as the C language into object modules. 2. Description of the Prior Art Files produced by compilation of a source program inputted by a language processing program are called object modules (hereinafter referred to as objects). Generally, for software processed by a language processing program, the speed is required as its execution performance. In order to realize a high speed execution performance, it is necessary that the sizes of the objects which are results of execution of language processing be small and that the execution of the objects is fast. Meanwhile, as the scale of software increases, the data space of hardware tends to expand. In a conventional language processing method, as the expansion of the data space proceeds, the address calculation for calculating the position of an array element in the data space is performed in conformity with the size of the data space. If it is assumed that the data space is 4 gigabytes (= 2 32 bytes), then representation of an address in the data space requires 32 bits = 4 bytes. A method of conventional address calculation of an array element will be described with reference to FIG. 9 based on such assumption. In a process for calculating an offset of an element of an array from the top of the array, a subscript of the array is taken out (step 901). Then, the contents of the subscript are extended to 4 bytes (step 902). Then, the contents (4 bytes) of the subscript after the extension are multiplied by a data width of elements of the array to calculate an offset (step 903). An offset is calculated by the steps described just above. Subsequently, the address of the array element is calculated by taking out a top address of the array (step 904) and adding the array top address thus taken out to the offset calculated as above (step 905). A language program produces an object in accordance with the calculation method described above. The reason why the contents of a subscript are extended to 4 bytes at step 902 is such as follows. Generally in a high level language, external reference of a variable is permitted in order to allow a link of a plurality of modules. However, if external reference of an array is permitted similarly, then the size of the array becomes indefinite. Therefore, taking the possibility into consideration that the maximum value of an offset to be obtained may have an equal size to that of the data space, the processing for extension to 4 bytes is employed. In the conventional method described above, since a subscript is extended to 4 bytes prior to multiplication for calculation of an offset, the size of one of terms in calculation is 4 bytes, resulting in the problem that the load in execution of multiplication increases. This does not matter with language processing which is targeted to an architecture having a multiplication command which can designate 4 byte data as an operand, but where another architecture which includes a command of a bit width centered at 16 bits = 2 bytes or a smaller bit width is targeted, the command size is greater where 4 byte data are handled than where 2 byte data are handled. In short, where the data width of the architecture is smaller than the address width of the data space, where the address calculation method for an array element described above is employed, the size of an object to be produced becomes great and the execution performance of the object is deteriorated. As a countermeasure for the problem described above, the data space temporarily handled with a 16-bit architecture machine is set to a size with which an address can be represented with 16 bits. With the countermeasure, the subscript should be extended to 16 bits = 2 bytes also in calculation of an array. Thus, since an offset is calculated by multiplication between 2-byte data and another data, if the size of the latter data is equal to or smaller than 2 bytes, then the multiplication can be performed by a single command. However, in recent years, there is a tendency that the data space greater than the data width of an architecture is required. In this instance, also in address calculation of an array element, the problem arises that an object which is great in object size and low in execution performance is produced as described above. However, even if the data space is expanded, merely a large number of data are handled, and the size of one array need not necessarily be 4 bytes. It is an object of the present invention to provide a language processing method by which address calculation of an array element in language processing targeted at hardware having a data space greater than the data width of an architecture is performed efficiently to reduce the size of an object and enhance the execution performance of the object. From "Software Practice and Experience", Vol. 20, No. 3, March 1, 1990, pages 301 to 320 a new code generation approach is described, in which the implementation of language level operators and addressing operators is achieved by two independent sub-tasks. Each of these phases is specified using a set of decision trees that encode the set of possible implementation templates or each language feature and the set of constraints under which each can be applied. Code selection in each phase is achieved by interpreting these trees using a single comprehensive selection algorithm. The method easily extends to machine independence across a large class of target computers by abstracting the implementation templates into machine independent implementation strategies. The method disclosed distinguishes between addressing operators and language operators because the range of address values differs from that of an integer arithmetic implying a different machine implementation and because the separation is necessary to allow an efficient recognition of addressing computations that can be implemented as addressing modes of the target machine. EP-A-0180077 describes a data processing machine for compiling computer programs which determines the number of significant bits of a given arithmetic calculation and selects, based on this calculation, the word length of the variables processed in the arithmetic operation in order to improve the efficient use of the available storage capacity. In order to attain the object described above, according to the present invention there is provided a language processing method, as defined in claim 1. The array may be inputted from other than the source program information or alternatively from within the source program information. With the language processing method, since an address calculation algorithm for an array element is selected in accordance with the size of the array designated by a command, the size of an object to be produced can be reduced. Where the size of the array is equal to or smaller than the size of the int of a target machine, the size of the array can be reduced by one byte for address calculation of an array element by a command designation. In a machine which does not involve shift calculation of long data (4 bytes) of the C language, in the calculation method of the prior art, a shift of long data is realized by a library call, which results in increase of the object size and the execution time of a command. However, with the language processing method of the present invention, such increase can be eliminated. In particular, by reducing the size of an object to be produced, the program space can be saved and reduction of the loading time of an object can be achieved. The above and other objects, features and advantages of the present invention will become apparent from the following description and the appended claims, taken in conjunction with the accompanying drawings. FIG. 1 is a system block diagram illustrating an entire language processing method of a first embodiment of the present invention; FIG. 2 is a diagrammatic view illustrating an example of a command input of the language processing method illustrated in FIG. 1: FIG. 3 is a flow chart of array element address calculation algorithm selection processing of the language processing method illustrated in FIG. 1; FIG. 4 is a diagrammatic view showing an example of an input source file employed in the language processing method illustrated in FIG. 1; FIG. 5 is a similar view but showing an example of an output object according to an array element address calculation algorithm employed in the array element address calculation algorithm selection processing illustrated in FIG. 4; FIG. 6 is a similar view showing an example of an output object according to another array element address calculation algorithm employed in the array element address calculation algorithm selection processing illustrated in FIG. 4 and according to the prior art; FIG. 7 is a system block diagram of an entire language processing method of a second embodiment of the present invention; FIG. 8 is a diagrammatic view showing an example of an input source file of the language processing method illustrated in FIG. 7; and FIG. 9 is a flow chart of an array element address calculation algorithm of a conventional language processing method. Referring first to FIG. 1, there is illustrated a language processing method according to a first preferred embodiment of the the present invention. The language processing method of the present embodiment is targeted at a machine architecture which involves a shift calculation of long data (4 bytes) of the C language. A language processing step 103 includes a syntax analysis step 104 for inputting and analyzing an input source file 101 described in the C language, a command analysis step 105 for inputting and analyzing a command inputted at a command input step 102, a code production step 106 for producing a code in accordance with contents obtained by the syntax analysis, and an object output step 108 for outputting the code thus produced to an object file 109. Further, the code production step 106 includes an array element address calculation step 107 for selecting a suitable calculation method in accordance with a result of the analysis at the command analysis step 105. In the present embodiment, when the maximum size of arrays appearing in the input source file is equal to or smaller than the int width of the target machine, this is designated by a command. Here, the int width is 2 bytes, and it is designated that the maximum size of arrays is equal to or smaller than 64 kilobytes. An example of a command inputted at the command input step 102 is illustrated in FIG. 2. "short α rray" is a command designation of the present example. The command analysis step 105 analyzes the designation and stores it as calculation method designation data. When reference to an array element is recognized at the syntax analysis step 104, since an address of the array element must be calculated first, the array element address calculation step 107 of the code production step 106 is called. At the array element address calculation step 107, one of two array element address calculation algorithms is selected in accordance with the calculation method designation data obtained by the analysis at the command analysis step 105. A procedure of the array element address calculation 107 will be described below with reference to FIG. 3. First, it is checked whether or not the calculation method designation data indicate that the array can be accommodated in the size of the int (step 301). If the array can be accommodated in the size of the int, then a first array element address calculation algorithm 304 is selected as an object to be produced, and production of an object is performed (step 302). If the array cannot be accommodated in the size of the int, then a second array element address calculation algorithm 305 which is the same as a conventional algorithm is selected, and production of an object is performed (step 303). The first array element address calculation algorithm 304 first takes out a subscript of the array (step 306). Subsequently, multiplication between the contents (2 bytes) of the subscript thus taken out and the data width of the array element is performed to determine an offset first (step 307). Here, if the data width of the array element exceeds 2 bytes, then multiplication must necessarily be performed divisionally by a plurality of times. However, since the size of the subscription side is 2 bytes, the load is lower than that of multiplication of 4 bytes x 4 bytes. After an offset is obtained, this is expanded to the address width (4 bytes) (step 308). This is because, since addition to an address is performed subsequently, the data widths must necessarily be made equal to each other. An offset from the top of the array is calculated by the processing described above. Subsequently, the top address of the array is taken out (step 309), and the top address of the array thus taken out and the offset calculated at step 308 are added to each other to obtain an address of the array element (step 310). The second array calculation algorithm 305 is the same as the conventional array calculation algorithm described hereinabove with reference to FIG. 9. In particular, steps 311 to 315 in FIG. 3 are the same as the steps 901 to 905 in FIG. 9, respectively. An example of the reference to an array element is illustrated in FIG. 4. Since an array "tab" refers to the outside, the size of the array is indefinite. Meanwhile, address calculation is required for "tab[i]". Results of production of objects in accordance with the procedure described above are illustrated in FIGS. 5 and 6. FIG. 5 illustrates the results when it is designated by a command that the address size of the array is equal to or smaller than the size of the int, and FIG. 6 illustrates the results when it is designated that the address size of the array exceeds the size of the int. In the present embodiment, since the data width of array elements is 4 bytes, a multiplication command is not used but a shift command is used at the multiplication step. As shown in FIGS. 5 and 6, when it is designated that the size of the array is equal to or smaller than the size of the int, the object size is totaling 19 bytes, but when the size of the array exceeds the size of the int, the object size is totaling 20 bytes. Since produced codes shown in FIG. 6 are the same as those which are outputted in accordance with the conventional array calculation algorithm, it can be seen that, when it is designated in the present embodiment that the size of the array is equal to or smaller than the size of the int, the size of the array is decreased by one byte from the conventional object size. Subsequently, a language processing method of a second embodiment of the present invention will be described. While it is designated, in the first embodiment described above, by way of inputting of a command whether or not the size of the array exceeds the size of the int, not all of the arrays are equal to or smaller than the size of the int or larger than the size of the int, but it is sometimes different among different arrays whether or not the size exceeds the size of the int. Therefore, in the present second embodiment, a command which designates whether the size of the array is equal to or small than the size of the int or greater than the size of the int. The language processing method of the second embodiment of the present invention is illustrated in FIG. 7. Referring to FIG. 7, a language processing step 702 includes the same steps as those of the first embodiment except that a command analysis step 704 is included in the syntax analysis step 703 and that no input data other than an input source file 701 is present. In the present embodiment, it is described in the input source file 701 whether or not the size of an array exceeds the size of the int as seen in FIG. 8. Symbols "short array" are described in a declaration portion as a command which indicates that the size of the array "tab1" shown in FIG. 8 is equal to or smaller than the size of the int. After the syntax analysis step 703 recognizes the declaration of the array, whether or not the size of the array exceeds the size of the int is determined from presence or absence of a command designation whether the size of the array exceeds the size of the int at the command analysis step 704. Then, when reference to an array element is recognized in accordance with the determination at the command analysis step 704, an array element address calculation step 706 of a code production step 705 is called. The processing following this is the same processing as in the first embodiment, and accordingly, detailed description thereof is omitted herein. Since, in the present second embodiment, the size of an array can be designated for each array, more delicate selection of an address calculation method than that in the first embodiment can be achieved.

Claims: A computer language compilation method to be executed in a data space with a corresponding required address size which includes the steps of: inputting source program information, analyzing the thus inputted source program information to produce object information, calculating the address of an array element of an array to be processed upon production of the object information, and outputting the object information thus produced, characterized in that the step of calculating the address of an array element comprises the steps of: inputting a command which designates a maximum size of the array and analyzing whether or not the designated size is equal to or smaller than a fixed size so that the array requires a smaller address size than said required address size (step 301); selecting, based on said analysis of the designated array size: if the designated state is equal to or smaller than said fixed size, a first array address calculation operation comprising the steps of: taking out the subscript of said array element of the array (step 306); calculating an offset from contents of the subscript thus taken out and the data width of the array element (step 309) by means of operations of said smaller size; and calculating an address of the array element from the offset thus calculated and the top address of the array (step 310), or if the designated size is larger than said fixed size, a second array address calculation operation comprising the steps of: taking out the subscript of said array element of the array (step 311); extending the contents of the subscript thus taken out to said required address size (step 312); calculating an offset from contents of the subscript thus taken out and the data width of the array element (step 313); and calculating an address of the array element from the offset thus calculated and the top address of the array (step 315). A language processing method as set forth in claim 1, characterized in that the command of designating a maximum size of the array is inputted from other than the source program information. A language processing method as set forth in claim 1, characterized in that the command of designating a maximum size of the array is inputted from within the source program information.

Inventors: ISOZAKI HIROKO, ISOZAKI, HIROKO, ISOZAKI, HIROKO, C/O NEC CORPORATION
Applicants: NIPPON ELECTRIC CO, NEC CORPORATION
Application year: 1994
Main classification: G06F9
IPC codes: G06F9