JP2013210920A - Compilation device, compilation method, and compiler - Google Patents

Compilation device, compilation method, and compiler Download PDF

Info

Publication number
JP2013210920A
JP2013210920A JP2012081715A JP2012081715A JP2013210920A JP 2013210920 A JP2013210920 A JP 2013210920A JP 2012081715 A JP2012081715 A JP 2012081715A JP 2012081715 A JP2012081715 A JP 2012081715A JP 2013210920 A JP2013210920 A JP 2013210920A
Authority
JP
Japan
Prior art keywords
code
sentence
operand
similar
instruction
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
Application number
JP2012081715A
Other languages
Japanese (ja)
Inventor
Shinya Watanabe
真也 渡辺
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
NEC Corp
Original Assignee
NEC Corp
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by NEC Corp filed Critical NEC Corp
Priority to JP2012081715A priority Critical patent/JP2013210920A/en
Publication of JP2013210920A publication Critical patent/JP2013210920A/en
Pending legal-status Critical Current

Links

Images

Landscapes

  • Devices For Executing Special Programs (AREA)

Abstract

PROBLEM TO BE SOLVED: To provide a compilation device in which a time spent for optimization is reduced.SOLUTION: A compilation device according to the present invention is a compilation device 9 for performing compilation by converting a first source code including a plurality of sentences each including a command and an operand written therein into an intermediate code, and further converting it into a second source code, which is a language lower than the first source code. The compilation device includes: a similar sentence detection part 91 which detects similar sentences, which are sentences that become the same as each other in command and operand in intermediate codes thereof; and a code conversion part 92 which, in the intermediate code, converts, when the intermediate code is converted to the second source code, a code corresponding to the similar sentence detected by the similar sentence detection part 91 as a code for calling a common function that executes a command in the similar sentence with an operand of the similar sentence employed as an argument.

Description

本発明は、コンパイル装置、コンパイル方法及びコンパイラに関し、特に、ソースコードを、それよりも低級な言語のソースコードに変換することでコンパイルする技術に関する。   The present invention relates to a compiling device, a compiling method, and a compiler, and more particularly to a technique for compiling by converting source code into source code in a language lower than that.

ソースコードを翻訳して機械語コードを生成するときには、最終的に生成する機械語コードを実行する際における実行時間やメモリ使用量等を最小化するために、最適化が行われている(例えば、特許文献1)。   When generating machine language code by translating source code, optimization is performed in order to minimize execution time, memory usage, and the like when executing the machine language code to be finally generated (for example, Patent Document 1).

ここで、ユーザーが記述したソースコード中に類似したコードが複数ある場合には、その分、ソースコードのコードサイズが大きくなってしまうことになる。コードサイズが大きいと、最適化の処理対象となるデータ量も大きくなることになるため、最適化にかかる時間が増大してしまうという問題がある。   Here, if there are a plurality of similar codes in the source code written by the user, the code size of the source code will increase accordingly. When the code size is large, the amount of data to be optimized becomes large, and there is a problem that the time required for optimization increases.

特開2010−49315号公報JP 2010-49315 A

上述したように、ソースコードに類似したコードが複数存在し、そのコードサイズが大きい場合には、最適化にかかる時間が増大してしまうという課題がある。   As described above, when there are a plurality of codes similar to the source code and the code size is large, there is a problem that the time required for optimization increases.

本発明の目的は、上述したような課題を解決するために、最適化にかかる時間を低減することができるコンパイル装置、コンパイル方法、及び、コンパイラを提供することである。   An object of the present invention is to provide a compiling device, a compiling method, and a compiler that can reduce the time required for optimization in order to solve the above-described problems.

本発明の第1の態様にかかるコンパイル装置は、それぞれに命令とオペランドとが記述された複数の文を含む第1のソースコードを、中間コードに変換し、さらに前記第1のソースコードよりも低級な言語の第2のソースコードに変換することでコンパイルするコンパイル装置であって、前記中間コードにおいて、前記命令及び前記オペランドの形式が相互に同一となる文である類似文を検出する類似文検出部と、前記中間コードを前記第2のソースコードに変換するときに、前記中間コードにおいて、前記類似文検出部が検出した類似文に対応するコードを、当該類似文のオペランドを引数として、当該類似文の命令を実行する共通関数を呼び出すコードとして変換するコード変換部と、を備えたものである。   The compiling device according to the first aspect of the present invention converts a first source code including a plurality of sentences each including an instruction and an operand into intermediate code, and further converts the first source code from the first source code. A compiling device that compiles by converting to a second source code in a low-level language, and detects a similar sentence that is a sentence in which the instructions and the operands have the same format in the intermediate code When the detection unit converts the intermediate code into the second source code, the code corresponding to the similar sentence detected by the similar sentence detection unit in the intermediate code, with the operand of the similar sentence as an argument, A code conversion unit that converts the code to call a common function that executes the instruction of the similar sentence.

本発明の第2の態様にかかるコンパイル方法は、それぞれに命令とオペランドとが記述された複数の文を含む第1のソースコードを、中間コードに変換し、さらに前記第1のソースコードよりも低級な言語の第2のソースコードに変換することでコンパイルするコンパイル方法であって、前記中間コードにおいて、前記命令及び前記オペランドの形式が相互に同一となる文である類似文を検出するステップと、前記中間コードを前記第2のソースコードに変換するときに、前記中間コードにおいて、前記検出した類似文に対応するコードを、当該類似文のオペランドを引数として、当該類似文の命令を実行する共通関数を呼び出すコードとして変換するステップと、を備えたものである。
The compiling method according to the second aspect of the present invention includes converting a first source code including a plurality of sentences each including an instruction and an operand into intermediate code, and further converting the first source code from the first source code. A compiling method for compiling by converting to a second source code of a low-level language, the step of detecting a similar sentence in the intermediate code, which is a sentence having the same format of the instruction and the operand; When the intermediate code is converted into the second source code, the code corresponding to the detected similar sentence is executed in the intermediate code with the operand of the similar sentence as an argument, and the instruction of the similar sentence is executed. And a step of converting the code to call a common function.

本発明の第3の態様にかかるコンパイラは、それぞれに命令とオペランドとが記述された複数の文を含む第1のソースコードを、中間コードに変換し、さらに前記第1のソースコードよりも低級な言語の第2のソースコードに変換することでコンパイルするためのコンパイラであって、前記中間コードにおいて、前記命令及び前記オペランドの形式が相互に同一となる文である類似文を検出する処理と、前記中間コードを前記第2のソースコードに変換するときに、前記中間コードにおいて、前記検出した類似文に対応するコードを、当該類似文のオペランドを引数として、当該類似文の命令を実行する共通関数を呼び出すコードとして変換する処理と、をコンピュータに実行させるものである。   A compiler according to a third aspect of the present invention converts a first source code including a plurality of statements each including an instruction and an operand into intermediate code and further lower-order than the first source code. A compiler for compiling by converting to a second source code in a different language, wherein the intermediate code detects a similar sentence that is a sentence having the same format of the instruction and the operand; When the intermediate code is converted into the second source code, the code corresponding to the detected similar sentence is executed in the intermediate code with the operand of the similar sentence as an argument, and the instruction of the similar sentence is executed. The process of converting the code to call the common function is executed by a computer.

上述した各態様によれば、上述したような課題を解決するために、最適化にかかる時間を低減することができるコンパイル装置、コンパイル方法、及び、コンパイラを提供することができる。   According to each aspect described above, in order to solve the above-described problems, it is possible to provide a compiling device, a compiling method, and a compiler that can reduce the time required for optimization.

発明の実施の形態にかかるコンパイル装置の構成を示すブロック図である。It is a block diagram which shows the structure of the compilation apparatus concerning embodiment of invention. 発明の実施の形態にかかるCPUの処理構成図であるである。It is a processing block diagram of CPU concerning embodiment of invention. 発明の実施の形態にかかる最適化部によるコード共通化単位を説明する図である。It is a figure explaining the code sharing unit by the optimization part concerning embodiment of invention. 発明の実施の形態にかかる中間コード情報テーブル、類似コードテーブル、及び、最適化済中間コードのフォーマットを示す図である。It is a figure which shows the format of the intermediate code information table concerning an embodiment of an invention, a similar code table, and the optimized intermediate code. 発明の実施の形態にかかる最適化部の処理を示すフローチャートである。It is a flowchart which shows the process of the optimization part concerning embodiment of invention. 発明の実施の形態にかかる中間コード情報テーブルの一例を示す図である。It is a figure which shows an example of the intermediate code information table concerning embodiment of invention. 発明の実施の形態にかかる類似コードテーブルの一例を示す図である。It is a figure which shows an example of the similar code table concerning embodiment of invention. 発明の実施の形態にかかる最適化済中間コードの一例を示す図である。It is a figure which shows an example of the optimized intermediate code concerning embodiment of invention. 発明の実施の形態にかかる効果を説明するための図である。It is a figure for demonstrating the effect concerning embodiment of invention. 発明の実施の形態にかかるコンパイル装置の概要構成を示すブロック図である。It is a block diagram which shows schematic structure of the compilation apparatus concerning embodiment of invention.

<発明の実施の形態>
まず、図1を参照して、発明の実施の形態にかかるコンパイル装置1の構成について説明する。図1は、発明の実施の形態にかかるコンパイル装置1の構成を示すブロック図である。
<Embodiment of the Invention>
First, the configuration of a compiling device 1 according to an embodiment of the invention will be described with reference to FIG. FIG. 1 is a block diagram showing a configuration of a compiling device 1 according to an embodiment of the invention.

コンパイル装置1は、CPU(Central Processing Unit)10、メモリ11、及び、記憶部12を有する。   The compiling device 1 includes a CPU (Central Processing Unit) 10, a memory 11, and a storage unit 12.

CPU10は、記憶部12に格納されたソースコード(ソースプログラム)123を機械語コード(機械語プログラム)に翻訳する処理を実行する。具体的には、CPU10は、記憶部12に格納されたコンパイラ120をメモリ11にロードして実行することによって、ソースプログラム123をコンパイルしてアセンブラコードを生成する。CPU10は、アセンブラ121をメモリ11にロードして実行することによって、アセンブラコードをアセンブルしてオブジェクトコードを生成する。CPU10は、記憶部12に格納されたリンカ122をメモリ11にロードして実行することによって、オブジェクトコードをリンクして機械語コードを生成する。CPU10によって生成されたアセンブラコード、オブジェクトコード、及び、機械語コードは、メモリ11又は記憶部12に格納される。   The CPU 10 executes a process of translating the source code (source program) 123 stored in the storage unit 12 into a machine language code (machine language program). Specifically, the CPU 10 loads the compiler 120 stored in the storage unit 12 into the memory 11 and executes it, thereby compiling the source program 123 and generating assembler code. The CPU 10 assembles the assembler code and generates an object code by loading the assembler 121 into the memory 11 and executing it. The CPU 10 loads the linker 122 stored in the storage unit 12 into the memory 11 and executes it, thereby linking the object code and generating a machine language code. The assembler code, object code, and machine language code generated by the CPU 10 are stored in the memory 11 or the storage unit 12.

また、CPU10は、コンパイラ120を実行することによって、後述するように、展開部100、コード生成部101、最適化部102、及び、アドレッシング部103として機能する。   In addition, the CPU 10 functions as an expansion unit 100, a code generation unit 101, an optimization unit 102, and an addressing unit 103, as will be described later, by executing the compiler 120.

メモリ11は、CPU10によってロードされたプログラム(120〜122)、及び、CPU10がソースコード122の翻訳時に生成する各種データ等が格納される。メモリ11は、例えば、RAM(Random Access Memory)である。   The memory 11 stores a program (120 to 122) loaded by the CPU 10 and various data generated by the CPU 10 when the source code 122 is translated. The memory 11 is, for example, a RAM (Random Access Memory).

記憶部12は、コンパイラ120、アセンブラ121、リンカ122、及び、ソースコード123が格納される。記憶部12は、これらのデータ120〜123を格納するための少なくとも1つの任意の記憶装置を含む。記憶装置は、例えば、メモリ及びハードディスク等である。ここで、本実施の形態では、ソースコード123がCOBOLのソースコードである場合について例示する。   The storage unit 12 stores a compiler 120, an assembler 121, a linker 122, and source code 123. The storage unit 12 includes at least one arbitrary storage device for storing these data 120 to 123. The storage device is, for example, a memory and a hard disk. Here, in the present embodiment, a case where the source code 123 is a COBOL source code is illustrated.

続いて、図2を参照して、発明の実施の形態にかかるCPU10の処理構成について説明する。図2は、発明の実施の形態にかかるCPU10の処理構成図である。   Next, the processing configuration of the CPU 10 according to the embodiment of the invention will be described with reference to FIG. FIG. 2 is a processing configuration diagram of the CPU 10 according to the embodiment of the invention.

CPU10は、コンパイラ120を実行することによって、フロントエンドの処理(字句解析、構文解析、及び、意味解析等)を行って、ソースコード123から構文解析済中間コードを生成する。   The CPU 10 executes the compiler 120 to perform front-end processing (lexical analysis, syntax analysis, semantic analysis, etc.) and generate a parsed intermediate code from the source code 123.

CPU10は、コンパイラ120を実行することによって、バックエンドを処理するときに、展開部100、コード生成部101、最適化部102、及び、アドレッシング部103として機能する。各部100〜103における処理は、バックエンドにおける各フェーズに対応した処理となる。   The CPU 10 executes the compiler 120 to function as the expansion unit 100, the code generation unit 101, the optimization unit 102, and the addressing unit 103 when processing the back end. The processing in each unit 100 to 103 is processing corresponding to each phase in the back end.

展開部100は、コンパイルにおける最適化の一部を実行する。ここでの最適化として、例えば、デッドコードの削除、及び、ループの最適化(複数ループの結合)等が行われる。展開部100は、構文解析済中間コードを最適化したオブジェクト生成用中間コード1を生成する。コード生成部101は、オブジェクト生成用中間コード1をプラットフォームに依存した形式に変換したオブジェクト生成用中間コード2を生成する。   The expansion unit 100 executes a part of optimization in compilation. As optimization here, for example, deletion of dead code, optimization of loops (combination of a plurality of loops), and the like are performed. The expansion unit 100 generates the object generation intermediate code 1 in which the parsed intermediate code is optimized. The code generation unit 101 generates an object generation intermediate code 2 obtained by converting the object generation intermediate code 1 into a platform-dependent format.

最適化部102は、オブジェクト生成用中間コード2において、文単位で比較を行うことによって、他の文と類似する文を検出する。最適化部102は、各文の命令及びパラメータの形式を比較することによって、他の文と類似する文を検出する。最適化部102は、他の文と類似する文を、その文における処理を実行する共通関数を呼び出す処理への置き換え対象として検出する。そして、最適化部102は、オブジェクト生成用中間コード2において文に対応するように呼び出す共通関数を特定する情報を埋め込んだ最適化済中間コードを生成する。   The optimization unit 102 detects a sentence similar to another sentence by comparing the object generation intermediate code 2 in units of sentences. The optimization unit 102 detects sentences similar to other sentences by comparing the instruction and parameter format of each sentence. The optimization unit 102 detects a sentence similar to another sentence as a target to be replaced with a process for calling a common function that executes a process in the sentence. Then, the optimization unit 102 generates an optimized intermediate code in which information specifying a common function to be called so as to correspond to a sentence in the object generation intermediate code 2 is embedded.

アドレッシング部103は、最適化済中間コードをアセンブラコードに変換する。このときに、アドレッシング部103は、最適化部102によって最適化済中間コードに埋め込まれた情報に基づいて、他の文と類似する文に対応するコードを、それぞれの文における処理を実行する共通関数を呼び出すコードとなるように変換する。このように、本実施の形態では、文単位で相互に類似するコードを抽出し、抽出したコードを、共通関数を呼び出すコードに置き換えることで、過剰なオブジェクトコードを生成しないようにする。   The addressing unit 103 converts the optimized intermediate code into an assembler code. At this time, based on the information embedded in the optimized intermediate code by the optimization unit 102, the addressing unit 103 executes a process corresponding to a sentence similar to another sentence in each sentence. Convert the code to call the function. As described above, in the present embodiment, codes that are similar to each other are extracted in units of sentences, and the extracted codes are replaced with codes that call common functions, so that excessive object code is not generated.

続いて、図3を参照して、本発明の実施の形態にかかる最適化部102によるコード共通化単位について説明する。図3は、本発明の実施の形態にかかる最適化部102によるコード共通化単位を説明する図である。   Next, with reference to FIG. 3, a code sharing unit by the optimization unit 102 according to the embodiment of the present invention will be described. FIG. 3 is a diagram for explaining a code sharing unit by the optimization unit 102 according to the embodiment of the present invention.

図3に示すように、ソースコード123において、「COMPUTE A=A*B+C」と記述されている場合であっても、乗算(MULTIPLY)、加算(ADD)、及び、代入(MOVE)のそれぞれを実行する文に分解して、それぞれの文について共通化を行う。すなわち、分解可能な単位まで文を分解してから共通化を行う。なお、この分解は、通常、フロントエンドのフェーズで行われる。   As shown in FIG. 3, even in the case where “COMPUTE A = A * B + C” is described in the source code 123, each of multiplication (MULTIPLY), addition (ADD), and substitution (MOVE) is performed. Decompose it into statements to be executed and share each statement. That is, the sentence is disassembled up to a decomposable unit and then shared. This disassembly is normally performed in the front end phase.

このように、MULTIPLY文、ADD文、MOVE文、DEVIDE文、及び、SUBSTRACT文等のように、ソースコード123の言語(COBOL)における命令文の単位での共通化を行う。   In this way, commonization is performed in units of command statements in the language (COBOL) of the source code 123, such as a MULTIPLY statement, an ADD statement, a MOVE statement, a DEVICE statement, and a SUBSTRACT statement.

ここで、上述したように、COBOLのような高級言語では、1文のコードで表現される処理であっても、コンパイルの過程で生成されるアセンブリコードのような低級言語では、複数文のコードで表現される。そこで、本実施の形態では、ソースコード123及びその中間コードで1文で表現される処理であっても、アセンブリコードでは、その1文に対応する複数文のコードにおける処理を実行する共通関数を呼び出す処理に置き換えることで、過剰なオブジェクトコードを生成しないようにする。   Here, as described above, even in a high-level language such as COBOL, even in a low-level language such as an assembly code generated in the process of compilation, a multi-state code It is expressed by Therefore, in the present embodiment, even in the process expressed by one sentence in the source code 123 and its intermediate code, the assembly code has a common function for executing the process in a plurality of sentences corresponding to the one sentence. By replacing it with a call process, it avoids generating excessive object code.

なお、本実施の形態では、高級言語がCOBOLであり、それよりも低級(低水準)の言語がアセンブリコードである場合について例示したが、この関係を満たす言語であれば、他の言語の組み合わせを適用するようにしてもよい。   In this embodiment, the case where the high-level language is COBOL and the lower-level (low-level) language is assembly code is exemplified. However, any combination of other languages is possible as long as the language satisfies this relationship. May be applied.

続いて、図4を参照して、図4を参照して、本発明の実施の形態にかかる中間コード情報テーブル、類似コードテーブル、及び、最適化済中間コードのフォーマットについて説明する。図4は、本発明の実施の形態にかかる中間コード情報テーブル、類似コードテーブル、及び、最適化済中間コードのフォーマットを示す図である。   Next, with reference to FIG. 4, the format of the intermediate code information table, the similar code table, and the optimized intermediate code according to the embodiment of the present invention will be described with reference to FIG. FIG. 4 is a diagram showing a format of the intermediate code information table, the similar code table, and the optimized intermediate code according to the embodiment of the present invention.

図4は、中間コード情報テーブルと、類似コードテーブルと、最適化部102によって生成される最適化済中間コードのそれぞれのフォーマットを示す。   FIG. 4 shows the respective formats of the intermediate code information table, the similar code table, and the optimized intermediate code generated by the optimization unit 102.

中間コード情報テーブルは、コード生成部101によって生成されるオブジェクト生成用中間コード2に含まれる文のそれぞれに対応する複数のレコードを含む。1つのレコードには、文コードと、パラメータ属性情報とが含まれる。パラメータ属性情報は、パラメータのそれぞれについて含まれる。中間コード情報テーブルは、コード生成部101によって、オブジェクト生成用中間コード2に基づいて生成されて、メモリ11又は記憶部12に格納される。   The intermediate code information table includes a plurality of records corresponding to the sentences included in the object generation intermediate code 2 generated by the code generation unit 101. One record includes a sentence code and parameter attribute information. Parameter attribute information is included for each parameter. The intermediate code information table is generated by the code generation unit 101 based on the object generation intermediate code 2 and stored in the memory 11 or the storage unit 12.

文コードは、文における命令(上述したMULTIPLY、ADD等)を一意に特定する情報である。コード生成部101は、例えば、命令を一意に特定する値を文コードとして生成してもよく、オブジェクト生成用中間コード2に含まれる命令に対して一意に割り当てられたコードをそのまま文コードとして使用するようにしてもよい。   The sentence code is information that uniquely identifies an instruction (such as MULTIPLY or ADD described above) in the sentence. For example, the code generation unit 101 may generate a value that uniquely identifies an instruction as a statement code, and uses the code uniquely assigned to the instruction included in the object generation intermediate code 2 as the statement code. You may make it do.

パラメータ属性情報は、パラメータの属性(型、長さ等)を示す情報である。パラメータ属性情報は、各文が関数として共通化できる程度に、パラメータの形式が一致しているか否かを判定するために使用される。一般的に、中間コード(オブジェクト生成用中間コード2)からは、各文におけるパラメータの値、型、長さ等の情報を抽出することができる。そのため、コード生成部101は、オブジェクト生成用中間コード2からパラメータ属性情報を抽出してレコードに格納する。ここで、アセンブリコードで関数を共通化する場合には、その引数となるパラメータの型及び長さが一致することが好ましい。そのため、本実施の形態では、パラメータの属性として、パラメータの型及び長さを抽出して比較する場合について例示する。したがって、パラメータ属性情報は、各文が関数として共通化できる程度に、パラメータの形式が一致しているか否かを判定することができる情報であれば、扱う言語に応じてパラメータの型及び長さに限られず、その内容を変更してよい。   The parameter attribute information is information indicating parameter attributes (type, length, etc.). The parameter attribute information is used to determine whether or not the parameter formats match so that each sentence can be shared as a function. In general, information such as parameter values, types, and lengths in each sentence can be extracted from the intermediate code (object generation intermediate code 2). Therefore, the code generation unit 101 extracts the parameter attribute information from the object generation intermediate code 2 and stores it in the record. Here, when the functions are shared in the assembly code, it is preferable that the types and lengths of the parameters as the arguments match. Therefore, in the present embodiment, a case where a parameter type and length are extracted and compared as parameter attributes is illustrated. Therefore, if the parameter attribute information is information that can be used to determine whether or not the parameter formats match to the extent that each sentence can be shared as a function, the parameter type and length depending on the language to be handled. However, the content may be changed.

類似コードテーブルは、オブジェクト生成用中間コード2において、相互に類似する文の種類毎のレコードが含められる。具体的には、命令及びパラメータの形式が同じ文は、同一の種類の文として扱われる。1つのレコードには、類似コード番号と、文コードと、パラメータ属性情報とが含まれる。類似コードテーブルは、最適化部102によって生成されて、メモリ11又は記憶部12に格納される。   The similar code table includes a record for each kind of sentence similar to each other in the object generation intermediate code 2. Specifically, sentences having the same command and parameter format are treated as the same type of sentence. One record includes a similar code number, a sentence code, and parameter attribute information. The similar code table is generated by the optimization unit 102 and stored in the memory 11 or the storage unit 12.

類似コード番号は、相互に類似する文の種類を一意に特定する情報である。文コード及びパラメータ属性情報については、上述した通りである。最適化部102は、中間コード情報テーブルに基づいて、文コード及びパラメータ属性情報が相互に一致する文を、相互に類似する文として検出する。最適化部102は、他の文と類似する文を検出したときに、その文の種類についてのレコードが類似コードテーブルに存在しない場合、検出した文に関するレコードを類似コードテーブルに追加する。このとき、追加するレコードには、検出した文の種類を示す類似コード番号と、検出した文の文コードと、検出した文のパラメータ属性情報とが含められる。最適化部102は、レコードに含める類似コード番号として、類似コードテーブルに含まれる他の類似コード番号と重複しない番号を生成する。また、最適化部102は、レコードに含める文コード及びパラメータ属性情報として、他の文と類似する文を検出ときに、中間コード情報テーブルからその文の文コード及びパラメータ属性情報を取得する。   The similar code number is information for uniquely specifying the types of sentences similar to each other. The sentence code and the parameter attribute information are as described above. Based on the intermediate code information table, the optimization unit 102 detects sentences having sentence codes and parameter attribute information that match each other as sentences similar to each other. When the optimization unit 102 detects a sentence similar to another sentence and there is no record regarding the type of the sentence in the similar code table, the optimization unit 102 adds a record related to the detected sentence to the similar code table. At this time, the record to be added includes a similar code number indicating the type of the detected sentence, the sentence code of the detected sentence, and parameter attribute information of the detected sentence. The optimization unit 102 generates a number that does not overlap with other similar code numbers included in the similar code table as the similar code numbers included in the record. When the optimization unit 102 detects a sentence similar to another sentence as the sentence code and parameter attribute information included in the record, the optimization unit 102 acquires the sentence code and parameter attribute information of the sentence from the intermediate code information table.

最適化済中間コードは、1文に、類似コード番号、及び、パラメータの情報が含まれる。最適化部102は、他の文に類似する文を検出した場合、検出した文の文コードを、検出した文の種類に対応する類似コード番号に置き換えて、最適化済中間コードを生成する。なお、最適化部102は、他の文に類似する文を検出しなかった場合には、元の文コードをそのまま残して、最適化済中間コードを生成する。また、文において、文コードを置き換えずに、類似コード番号を追加するようにしてもよい。最適化済中間コードは、最適化部102によって生成されて、メモリ11又は記憶部12に格納される。   The optimized intermediate code includes a similar code number and parameter information in one sentence. When the optimization unit 102 detects a sentence similar to another sentence, the optimization unit 102 generates an optimized intermediate code by replacing the sentence code of the detected sentence with a similar code number corresponding to the type of the detected sentence. When the optimization unit 102 does not detect a sentence similar to another sentence, the optimization unit 102 generates an optimized intermediate code while leaving the original sentence code as it is. In the sentence, a similar code number may be added without replacing the sentence code. The optimized intermediate code is generated by the optimization unit 102 and stored in the memory 11 or the storage unit 12.

類似コード番号については、上述した通りである。パラメータは、文におけるパラメータの情報を示している。この情報には、上述したように、パラメータの値、型、長さ等の情報が含まれる。このようにして、文コードが類似コード番号に置き換えられた文は、アドレッシング部103において、文のコードを、最適化済中間コードからアセンブラコードに変換するときに、類似コード番号に対応する文の処理を実行する共通関数を呼び出すコードとして変換される。   The similar code number is as described above. The parameter indicates parameter information in the sentence. As described above, this information includes information such as parameter values, types, and lengths. In this way, the sentence in which the sentence code is replaced with the similar code number is stored in the sentence corresponding to the similar code number when the addressing unit 103 converts the sentence code from the optimized intermediate code to the assembler code. It is converted as a code that calls a common function that executes processing.

続いて、図5〜図8を参照して、本発明の実施の形態にかかる共通化処理について説明する。図5は、本発明の実施の形態にかかる最適化部102の処理を示すフローチャートである。図6は、本発明の実施の形態にかかる中間コード情報テーブルの一例を示す図である。図7は、本発明の実施の形態にかかる類似コードテーブルの一例を示す図である。図8は、本発明の実施の形態にかかる最適化済中間コードの一例を示す図である。   Next, the common processing according to the embodiment of the present invention will be described with reference to FIGS. FIG. 5 is a flowchart showing processing of the optimization unit 102 according to the embodiment of the present invention. FIG. 6 is a diagram showing an example of the intermediate code information table according to the embodiment of the present invention. FIG. 7 is a diagram showing an example of a similar code table according to the embodiment of the present invention. FIG. 8 is a diagram illustrating an example of the optimized intermediate code according to the embodiment of the present invention.

なお、ここでは、図3に、分解後として示す6つの文のコードを含む、オブジェクト生成用中間コード2を処理対象とする場合について例示する。よって、コード生成部101によって、図6に示すように、オブジェクト生成用中間コード2の各文についての中間コード情報テーブルが生成される。   Here, FIG. 3 exemplifies a case where the object generation intermediate code 2 including the code of six sentences shown as being decomposed is a processing target. Therefore, the code generation unit 101 generates an intermediate code information table for each sentence of the object generation intermediate code 2 as shown in FIG.

具体的には、中間コード情報テーブルとして、1文目のレコードには、MULTIPLY命令を示す文コードと、パラメータAの型及び長さのそれぞれを示すパラメータ属性情報、パラメータBの型及び長さを示すパラメータ属性情報、及び、パラメータXの型及び長さを示すパラメータ属性情報が含まれる。2文目のレコードには、ADD命令を示す文コードと、パラメータCの型及び長さのそれぞれを示すパラメータ属性情報、パラメータXの型及び長さを示すパラメータ属性情報、及び、パラメータYの型及び長さを示すパラメータ属性情報が含まれる。3文目のレコードには、MOV命令を示す文コードと、パラメータYの型及び長さのそれぞれを示すパラメータ属性情報、及び、パラメータAの型及び長さを示すパラメータ属性情報が含まれる。   Specifically, as an intermediate code information table, the first sentence record includes a statement code indicating a MULTIPLY instruction, parameter attribute information indicating the type and length of parameter A, and the type and length of parameter B, respectively. Parameter attribute information indicating parameter X information indicating parameter X type and length. The record of the second sentence includes a statement code indicating an ADD instruction, parameter attribute information indicating the type and length of the parameter C, parameter attribute information indicating the type and length of the parameter X, and a type of the parameter Y. And parameter attribute information indicating the length. The record of the third sentence includes a sentence code indicating the MOV instruction, parameter attribute information indicating the type and length of the parameter Y, and parameter attribute information indicating the type and length of the parameter A.

3文目のレコードには、MULTIPLY命令を示す文コードと、パラメータEの型及び長さのそれぞれを示すパラメータ属性情報、パラメータFの型及び長さを示すパラメータ属性情報、及び、パラメータVの型及び長さを示すパラメータ属性情報が含まれる。2文目のレコードには、ADD命令を示す文コードと、パラメータDの型及び長さのそれぞれを示すパラメータ属性情報、パラメータVの型及び長さを示すパラメータ属性情報、及び、パラメータWの型及び長さを示すパラメータ属性情報が含まれる。3文目のレコードには、MOVE命令を示す文コードと、パラメータWの型及び長さのそれぞれを示すパラメータ属性情報、及び、パラメータDの型及び長さを示すパラメータ属性情報が含まれる。   The record of the third sentence includes a statement code indicating a MULTIPLY instruction, parameter attribute information indicating the type and length of the parameter E, parameter attribute information indicating the type and length of the parameter F, and a type of the parameter V And parameter attribute information indicating the length. The record of the second sentence includes a statement code indicating an ADD instruction, parameter attribute information indicating the type and length of the parameter D, parameter attribute information indicating the type and length of the parameter V, and a type of the parameter W. And parameter attribute information indicating the length. The record of the third sentence includes a statement code indicating the MOVE instruction, parameter attribute information indicating the type and length of the parameter W, and parameter attribute information indicating the type and length of the parameter D.

また、ここでは、1文目と4文目、2文目と5文目、3文目と6文目がそれぞれ類似する文であるものとする。すなわち、1文目のパラメータAの型及び長さは、4文目のパラメータEの型及び長さと一致し、1文目のパラメータBの型及び長さは、4文目のパラメータFの型及び長さと一致し、1文目のパラメータXの型及び長さは、4文目のパラメータVの型及び長さと一致するものとする。なお、1文目の命令と4文目の命令は、共にMULTIPLYであり、一致する。また、2文目のパラメータCの型及び長さは、5文目のパラメータDの型及び長さと一致し、2文目のパラメータXの型及び長さは、5文目のパラメータVの型及び長さと一致し、2文目のパラメータYの型及び長さは、5文目のパラメータWの型及び長さと一致するものとする。なお、2文目の命令と5文目の命令は、共にADDであり、一致する。また、3文目のパラメータYの型及び長さは、6文目のパラメータWの型及び長さと一致し、3文目のパラメータAの型及び長さは、6文目のパラメータDの型及び長さと一致するものとする。なお、3文目の命令と6文目の命令は、共にMOVEであり、一致する。   Here, the first sentence, the fourth sentence, the second sentence, the fifth sentence, the third sentence, and the sixth sentence are respectively similar sentences. That is, the type and length of the parameter A in the first sentence is the same as the type and length of the parameter E in the fourth sentence, and the type and length of the parameter B in the first sentence is the type of the parameter F in the fourth sentence. It is assumed that the type and length of the parameter X in the first sentence match the type and length of the parameter V in the fourth sentence. Note that the first sentence instruction and the fourth sentence instruction are both MULTIPLY and match. The type and length of the parameter C in the second sentence are the same as the type and length of the parameter D in the fifth sentence, and the type and length of the parameter X in the second sentence are the type of the parameter V in the fifth sentence. And the type and length of the parameter Y in the second sentence are the same as the type and length of the parameter W in the fifth sentence. Note that the second sentence instruction and the fifth sentence instruction are both ADD and match. The type and length of the parameter Y in the third sentence are the same as the type and length of the parameter W in the sixth sentence, and the type and length of the parameter A in the third sentence are the same as the type of the parameter D in the sixth sentence. And match the length. Note that the third sentence instruction and the sixth sentence instruction are both MOVE and match.

続いて、図5を参照して、上述した条件における最適化部102の処理について説明する。最適化部102は、中間コード情報テーブルから、1文目のレコードを読み込む(S1)。最適化部102は、類似コードテーブルを検索して、1文目と類似する文があるか否かを判定する(S2)。   Next, the processing of the optimization unit 102 under the above-described conditions will be described with reference to FIG. The optimization unit 102 reads the record of the first sentence from the intermediate code information table (S1). The optimization unit 102 searches the similar code table and determines whether there is a sentence similar to the first sentence (S2).

ここでは、まだ、類似コードテーブルに、1文目と類似する文についてのレコードが存在しないため(S3:No)、最適化部102は、中間コード情報テーブルを検索して、1文目と類似する文があるか否かを判定する(S5)。   Here, since there is still no record for a sentence similar to the first sentence in the similar code table (S3: No), the optimization unit 102 searches the intermediate code information table and is similar to the first sentence. It is determined whether there is a sentence to be performed (S5).

中間コード情報テーブルには、1文目と類似する文が4文目に存在する(S6:Yes)。すなわち、中間コード情報テーブルの1文目のレコードが示す命令、パラメータの型及び長さが、中間コード情報テーブルの4文目のレコードが示す命令、パラメータの型及び長さと一致する。   In the intermediate code information table, a sentence similar to the first sentence exists in the fourth sentence (S6: Yes). In other words, the instruction and parameter type and length indicated by the first record in the intermediate code information table match the instruction and parameter type and length indicated by the fourth sentence record in the intermediate code information table.

そのため、最適化部102は、類似コードテーブルに、その文についてのレコードを追加する(S7)。具体的には、図7に示すように、追加するレコードにおいて、1文目(4文目)の文の種類(命令、型及び長さ)を一意に特定する類似コード番号SIM1、1文目(4文目)のMULTIPLY命令を示す文コード、パラメータA(E)の型及び長さを示す情報、パラメータB(F)の型及び長さを示す情報、及び、パラメータX(V)の型及び長さを示す情報を設定する。   Therefore, the optimization unit 102 adds a record for the sentence to the similar code table (S7). Specifically, as shown in FIG. 7, in the record to be added, the similar code number SIM1, which uniquely identifies the type (command, type and length) of the first sentence (fourth sentence), the first sentence (Fourth sentence) MULTIPLY statement code, parameter A (E) type and length information, parameter B (F) type and length information, and parameter X (V) type And information indicating the length is set.

そして、最適化部102は、図8に示すように、オブジェクト生成用中間コード2の1文目の文の文コードを、類似コードテーブルに追加したレコードの類似コード番号SIM1に置き換えた最適化済中間コードを生成する(S4)。   Then, as shown in FIG. 8, the optimization unit 102 has optimized the sentence code of the first sentence of the object generation intermediate code 2 with the similar code number SIM1 of the record added to the similar code table. An intermediate code is generated (S4).

最適化部102は、中間コード情報テーブルのレコードの終端になったか否かを判定する(S9)。ここでは、レコードの終端にはなっていないため(S9:No)、ステップS1に戻る。   The optimization unit 102 determines whether the end of the record of the intermediate code information table has been reached (S9). Here, since it is not the end of the record (S9: No), the process returns to step S1.

続いて、2文目、3文目についても、上述したように、5文目、6文目と類似するため、同様にして、類似コードテーブルへのレコードの追加(S1、S2、S3:No、S5、S6;Yes、S7)と、文コードを類似コード番号(SIM2又はSIM3)に置き換えた最適化済中間コードの生成(S4)が行われる。   Subsequently, since the second sentence and the third sentence are similar to the fifth sentence and the sixth sentence as described above, similarly, records are added to the similar code table (S1, S2, S3: No). , S5, S6; Yes, S7) and generation of optimized intermediate code (S4) in which the sentence code is replaced with the similar code number (SIM2 or SIM3).

これによって、図7に示すように、2文目(5文目)の文の種類(命令、型及び長さ)を一意に特定する類似コード番号SIM2、2文目(5文目)のADD命令を示す文コード、パラメータC(D)の型及び長さを示す情報、パラメータX(V)の型及び長さを示す情報、及び、パラメータY(W)の型及び長さを示す情報が設定されたレコードと、3文目(6文目)の文の種類(命令、型及び長さ)を一意に特定する類似コード番号SIM3、3文目(6文目)のMOVE命令を示す文コード、パラメータY(W)の型及び長さを示す情報、及び、パラメータA(D)の型及び長さを示す情報が設定されたレコードが追加される。   As a result, as shown in FIG. 7, the similar code number SIM2 that uniquely identifies the type (command, type, and length) of the second sentence (fifth sentence), and the second sentence (fifth sentence) ADD A statement code indicating an instruction, information indicating the type and length of the parameter C (D), information indicating the type and length of the parameter X (V), and information indicating the type and length of the parameter Y (W) Sentence code number SIM3 that uniquely identifies the set record and the type (command, type and length) of the third sentence (sixth sentence), and a sentence indicating the third sentence (sixth sentence) MOVE instruction A record in which information indicating a code, information indicating the type and length of parameter Y (W), and information indicating a type and length of parameter A (D) is added.

また、図8に示すように、オブジェクト生成用中間コード2の2文目の文の文コードを、類似コードテーブルに追加したレコードの類似コード番号SIM2に置き換えた最適化済中間コードと、オブジェクト生成用中間コード2の3文目の文の文コードを、類似コードテーブルに追加したレコードの類似コード番号SIM3に置き換えた最適化済中間コードとが生成される。   Further, as shown in FIG. 8, the optimized intermediate code in which the sentence code of the second sentence of the object generation intermediate code 2 is replaced with the similar code number SIM2 of the record added to the similar code table, and the object generation The optimized intermediate code is generated by replacing the sentence code of the third sentence of the intermediate code 2 for use with the similar code number SIM3 of the record added to the similar code table.

続いて、最適化部102は、中間コード情報テーブルから、3文目のレコードを読み込む(S1)。最適化部102は、類似コードテーブルを検索して、3文目と類似する文があるか否かを判定する(S2)。   Subsequently, the optimization unit 102 reads the record of the third sentence from the intermediate code information table (S1). The optimization unit 102 searches the similar code table to determine whether there is a sentence similar to the third sentence (S2).

類似コードテーブルには、図7に示すように、3文目と類似する文についてのレコード(類似コード番号SIM1)が存在する(S3:Yes)。すなわち、中間コード情報テーブルの3文目のレコードが示す命令、パラメータの型及び長さが、類似コードテーブルの1つ目のレコードが示す命令、パラメータの型及び長さと一致する。   As shown in FIG. 7, the similar code table includes a record (similar code number SIM1) for a sentence similar to the third sentence (S3: Yes). That is, the instruction and parameter type and length indicated by the third record in the intermediate code information table match the instruction and parameter type and length indicated by the first record in the similar code table.

そのため、最適化部102は、最適化部102は、オブジェクト生成用中間コード2において、3文目の文の文コードを、類似コードテーブルの1つ目のレコードの類似コード番号SIM1に置き換えた最適化済中間コードを生成する(S4)。   Therefore, the optimization unit 102 optimizes by replacing the sentence code of the third sentence with the similar code number SIM1 of the first record of the similar code table in the object generation intermediate code 2. Generated intermediate code is generated (S4).

最適化部102は、中間コード情報テーブルのレコードの終端になったか否かを判定する(S9)。ここでは、レコードの終端にはなっていないため(S9:No)、ステップS1に戻る。   The optimization unit 102 determines whether the end of the record of the intermediate code information table has been reached (S9). Here, since it is not the end of the record (S9: No), the process returns to step S1.

続いて、5文目、6文目についても、上述したように、類似コードテーブルに対応するレコードが追加された2文目、3文目と類似するため、同様にして、文コードを類似コード番号(SIM2又はSIM3)に置き換えた最適化済中間コードの生成(S1、S2、S3:Yes、S4)が行われる。   Subsequently, since the fifth sentence and the sixth sentence are similar to the second sentence and the third sentence to which the record corresponding to the similar code table is added as described above, the sentence codes are similarly changed. Generation (S1, S2, S3: Yes, S4) of the optimized intermediate code replaced with the number (SIM2 or SIM3) is performed.

これによって、図8に示すように、オブジェクト生成用中間コード2の5文目の文の文コードを、類似コードテーブルに追加したレコードの類似コード番号SIM2に置き換えた最適化済中間コードと、オブジェクト生成用中間コード2の6文目の文の文コードを、類似コードテーブルに追加したレコードの類似コード番号SIM3に置き換えた最適化済中間コードとが生成される。   Thus, as shown in FIG. 8, the optimized intermediate code in which the sentence code of the fifth sentence of the object generation intermediate code 2 is replaced with the similar code number SIM2 of the record added to the similar code table, and the object An optimized intermediate code is generated by replacing the sentence code of the sixth sentence of the generation intermediate code 2 with the similar code number SIM3 of the record added to the similar code table.

そして、レコードの終端に達するため(S9:Yes)、最適化部102は、処理を終了する。   Then, since the end of the record is reached (S9: Yes), the optimization unit 102 ends the process.

なお、ここでは、ステップS6でNoとなるケースが存在しなかったが、そのようなケースとなった場合は、上述したように、文コードを類似コード番号に置き換えずに、最適化済中間コードが生成される(S8)。   Here, there is no case of No in step S6. However, in such a case, as described above, the optimized intermediate code is not replaced without replacing the sentence code with the similar code number. Is generated (S8).

続いて、図9を参照して、発明の実施の形態にかかる効果について説明する。図9は、発明の実施の形態にかかる効果を説明するための図である。   Next, effects according to the embodiment of the invention will be described with reference to FIG. FIG. 9 is a diagram for explaining the effect according to the embodiment of the invention.

最適化済中間コードの各文におけるコードは、アドレッシング部103によって、文に含まれる類似コード番号で特定される文の処理を実行する共通関数を呼び出すコードに変換される。また、共通関数のコードは、アドレッシング部103によって、元の文のコードに基づいて、そのコードの処理を実行するように生成される。また、共通関数のコードは、アドレッシング部103によって、元の文のコードのパラメータの形式で、パラメータを引数とするように生成される。したがって、共通関数には、型及び長さが必ず同一となるパラメータ(値)が引数として指定されるため、関数内の処理で齟齬が生じることはない。   The code in each sentence of the optimized intermediate code is converted by the addressing unit 103 into a code that calls a common function that executes processing of the sentence specified by the similar code number included in the sentence. Further, the code of the common function is generated by the addressing unit 103 so as to execute processing of the code based on the code of the original sentence. Further, the code of the common function is generated by the addressing unit 103 in the form of the parameter of the code of the original sentence so that the parameter is an argument. Therefore, since a parameter (value) having the same type and the same length is specified as an argument in the common function, no wrinkles occur in processing within the function.

例えば、図8の1文目で示すコードは、類似コード番号SIM1に対応するMULTIPLYの処理を実行する共通関数の呼び出しに置き換えられる。この共通関数は、パラメータA及びEで共通する型及び長さのパラメータと、パラメータB及びFで共通する型及び長さのパラメータと、パラメータX及びVで共通する型及び長さのパラメータとを引数とする共通関数として生成される。   For example, the code shown in the first sentence of FIG. 8 is replaced with a call to a common function that executes a MULTIPLY process corresponding to the similar code number SIM1. This common function includes a type and length parameter common to parameters A and E, a type and length parameter common to parameters B and F, and a type and length parameter common to parameters X and V. Generated as a common function as an argument.

ここで、コンパイラは、元々、類似しないコード毎に、中間コードからアセンブラコードのテンプレートを内在している。例えば、中間コードにおいて、ADD命令の文が存在する場合、そのテンプレートに中間コードにおけるパラメータを設定することで、元の中間コードの文のパラメータに対してADD命令の処理を実行するアセンブラコードを生成することができる。このように、中間コードにおける各文を対応するテンプレートに置き換えることで、アセンブラコードへの変換が可能である。   Here, the compiler originally includes an assembler code template from the intermediate code for each dissimilar code. For example, if an ADD instruction statement exists in the intermediate code, an assembler code for executing the ADD instruction processing on the original intermediate code statement parameter is generated by setting the intermediate code parameter in the template. can do. In this way, conversion into assembler code is possible by replacing each sentence in the intermediate code with the corresponding template.

そのため、共通関数を生成する場合には、このテンプレートを利用して生成するようにしてもよい。すなわち、コンパイラ120に、文の種類毎(類似コード番号毎)のアセンブラコードのテンプレートを含めるようにして、共通関数内の処理としてテンプレートのコードを配置することで、簡易に、アセンブラコードを生成することができる。   Therefore, when generating a common function, it may be generated using this template. That is, the compiler 120 includes an assembler code template for each sentence type (for each similar code number) and arranges the template code as a process in the common function, so that an assembler code can be easily generated. be able to.

このように、類似する文を共通関数の呼び出しに置き換えることで、図9の右図に示すように、アセンブラコードにおいて、文単位でコードをまとめて、コード量を小さくすることができる。そのため、この後のフェーズとして、アセンブラ及びリンカによってコードを最適化するときに、最適化対象とするコードサイズを低減することができるため、最適化にかかる時間を低減することができる。   In this way, by replacing similar sentences with calls to common functions, as shown in the right diagram of FIG. 9, in the assembler code, the codes can be gathered in units of sentences and the amount of code can be reduced. Therefore, as a subsequent phase, when the code is optimized by the assembler and linker, the code size to be optimized can be reduced, so that the time required for the optimization can be reduced.

それに対して、図9の左図に示すように、本発明を適用しない場合には、アセンブラコードにおいて、文単位でコードをまとめることをしていないため、その文が記述されていた関数全体のコード量が大きくなってしまう。そのため、アセンブラ及びリンカによってコードを最適化するときに、最適化対象とするコードサイズが大きくなってしまい、最適化にかかる時間が増大してしまう。   On the other hand, as shown in the left diagram of FIG. 9, in the case where the present invention is not applied, since the code is not grouped in the assembler code, the entire function in which the sentence is described is not collected. The amount of code becomes large. Therefore, when the code is optimized by the assembler and the linker, the code size to be optimized becomes large, and the time required for the optimization increases.

<本発明の実施の形態の概要>
続いて、図10を参照して、発明の実施の形態にかかるコンパイル装置1の概要構成について説明する。図10は、発明の実施の形態にかかるコンパイル装置1の概要構成となるコンパイル装置9の構成を示すブロック図である。
<Outline of Embodiment of the Present Invention>
Next, a schematic configuration of the compiling device 1 according to the embodiment of the invention will be described with reference to FIG. FIG. 10 is a block diagram showing a configuration of the compiling device 9 which is a schematic configuration of the compiling device 1 according to the embodiment of the invention.

コンパイル装置9は、類似文検出部90及びコード変換部91を有する。コンパイル装置9は、それぞれに命令とオペランドとが記述された複数の文を含む第1のソースコードを、中間コードに変換し、さらに第1のソースコードよりも低級な言語の第2のソースコードに変換することでコンパイルする。   The compiling device 9 includes a similar sentence detection unit 90 and a code conversion unit 91. The compiling device 9 converts the first source code including a plurality of statements each including an instruction and an operand into intermediate code, and further converts the second source code in a language lower than the first source code. Compile by converting to.

類似文検出部90は、中間コードにおいて、命令及びオペランドの形式が相互に同一となる文である類似文を検出する。コード変換部91は、中間コードを第2のソースコードに変換するときに、中間コードにおいて、類似文検出部90が検出した類似文に対応するコードを、類似文のオペランドを引数として、類似文の命令を実行する共通関数を呼び出すコードとして変換する。   The similar sentence detection unit 90 detects a similar sentence that is a sentence having the same instruction and operand format in the intermediate code. When the code conversion unit 91 converts the intermediate code into the second source code, the code corresponding to the similar sentence detected by the similar sentence detection unit 90 in the intermediate code is used with the operand of the similar sentence as an argument. It is converted as a code that calls a common function that executes these instructions.

以上に説明したように、本実施の形態によれば、中間コードをアセンブラコードに変換するときに、類似文に対応するコードを、類似文のオペランドを引数として、類似文の命令を実行する共通関数を呼び出すコードとして変換するようにしている。これによれば、その後のフェーズで、最適化対象とするコードサイズを低減することができるため、最適化にかかる時間を低減することができる。   As described above, according to the present embodiment, when an intermediate code is converted into an assembler code, a code corresponding to a similar sentence is executed using a similar sentence operand as an argument, and a common sentence instruction is executed. It is converted as code that calls the function. According to this, since the code size to be optimized can be reduced in the subsequent phase, the time required for optimization can be reduced.

なお、本発明は上記実施の形態に限られたものではなく、趣旨を逸脱しない範囲で適宜変更することが可能である。   Note that the present invention is not limited to the above-described embodiment, and can be changed as appropriate without departing from the spirit of the present invention.

また、上述の実施の形態の機能を実現するコンパイラ(プログラム)は、様々なタイプの非一時的なコンピュータ可読媒体(non-transitory computer readable medium)を用いて格納され、コンピュータ(コンパイラ装置)に供給することができる。非一時的なコンピュータ可読媒体は、様々なタイプの実体のある記録媒体(tangible storage medium)を含む。非一時的なコンピュータ可読媒体の例は、磁気記録媒体(例えばフレキシブルディスク、磁気テープ、ハードディスクドライブ)、光磁気記録媒体(例えば光磁気ディスク)、CD−ROM(Read Only Memory)、CD−R、CD−R/W、半導体メモリ(例えば、マスクROM、PROM(Programmable ROM)、EPROM(Erasable PROM)、フラッシュROM、RAM(Random Access Memory))を含む。また、プログラムは、様々なタイプの一時的なコンピュータ可読媒体(transitory computer readable medium)によってコンピュータに供給されてもよい。一時的なコンピュータ可読媒体の例は、電気信号、光信号、及び電磁波を含む。一時的なコンピュータ可読媒体は、電線及び光ファイバ等の有線通信路、又は無線通信路を介して、プログラムをコンピュータに供給できる。   A compiler (program) that realizes the functions of the above-described embodiments is stored using various types of non-transitory computer readable media and supplied to the computer (compiler device). can do. Non-transitory computer readable media include various types of tangible storage media. Examples of non-transitory computer-readable media include magnetic recording media (for example, flexible disks, magnetic tapes, hard disk drives), magneto-optical recording media (for example, magneto-optical disks), CD-ROMs (Read Only Memory), CD-Rs, CD-R / W, semiconductor memory (for example, mask ROM, PROM (Programmable ROM), EPROM (Erasable PROM), flash ROM, RAM (Random Access Memory)) are included. The program may also be supplied to the computer by various types of transitory computer readable media. Examples of transitory computer readable media include electrical signals, optical signals, and electromagnetic waves. The temporary computer-readable medium can supply the program to the computer via a wired communication path such as an electric wire and an optical fiber, or a wireless communication path.

また、コンピュータが上述の実施の形態の機能を実現するプログラムを実行することにより、上述の実施の形態の機能が実現される場合だけでなく、このプログラムが、コンピュータ上で稼動しているOS(Operating System)もしくはアプリケーションソフトウェアと共同して、上述の実施の形態の機能を実現する場合も、本発明の実施の形態に含まれる。さらに、このプログラムの処理の全てもしくは一部がコンピュータに挿入された機能拡張ボードやコンピュータに接続された機能拡張ユニットによって行われて、上述の実施の形態の機能が実現される場合も、本発明の実施の形態に含まれる。   In addition to the case where the function of the above-described embodiment is realized by the computer executing the program that realizes the function of the above-described embodiment, this program is not limited to the OS ( A case where the functions of the above-described embodiment are realized in cooperation with an operating system or application software is also included in the embodiment of the present invention. Furthermore, the present invention is also applicable to the case where the functions of the above-described embodiment are realized by performing all or part of the processing of the program by a function expansion board inserted into the computer or a function expansion unit connected to the computer. It is included in the embodiment.

1、9 コンパイル装置
10 CPU
11 メモリ
12 記憶部
90 類似文検出部
91 コード変換部
100 展開部
101 コード生成部
102 最適化部
103 アドレッシング部
120 コンパイラ
121 アセンブラ
122 リンカ
123 ソースコード
1, 9 Compile device 10 CPU
11 Memory 12 Storage unit 90 Similar sentence detection unit 91 Code conversion unit 100 Expansion unit 101 Code generation unit 102 Optimization unit 103 Addressing unit 120 Compiler 121 Assembler 122 Linker 123 Source code

Claims (8)

それぞれに命令とオペランドとが記述された複数の文を含む第1のソースコードを、中間コードに変換し、さらに前記第1のソースコードよりも低級な言語の第2のソースコードに変換することでコンパイルするコンパイル装置であって、
前記中間コードにおいて、前記命令及び前記オペランドの形式が相互に同一となる文である類似文を検出する類似文検出部と、
前記中間コードを前記第2のソースコードに変換するときに、前記中間コードにおいて、前記類似文検出部が検出した類似文に対応するコードを、当該類似文のオペランドを引数として、当該類似文の命令を実行する共通関数を呼び出すコードとして変換するコード変換部と、
を備えたコンパイル装置。
Converting a first source code including a plurality of sentences each including an instruction and an operand into an intermediate code, and further converting into a second source code in a language lower than the first source code Compiling device for compiling with
In the intermediate code, a similar sentence detection unit that detects a similar sentence that is a sentence having the same format of the instruction and the operand;
When the intermediate code is converted into the second source code, the code corresponding to the similar sentence detected by the similar sentence detection unit in the intermediate code is set with the operand of the similar sentence as an argument. A code conversion unit that converts the code to call a common function that executes instructions;
Compile device with
前記類似文検出部は、前記類似文に、当該類似文の命令及びオペランドの形式を一意に特定する類似特定情報を含め、
前記コード変換部は、前記類似文に対応するコードを、当該類似文に含まれる類似特定情報で特定されるオペランドの形式で当該類似文のオペランドを引数として、当該類似特定情報で特定される命令を実行する共通関数を呼び出すコードとして変換する、
請求項1に記載のコンパイル装置。
The similar sentence detection unit includes similarity specifying information for uniquely specifying the format of the instruction and operand of the similar sentence in the similar sentence,
The code conversion unit is configured to specify a code corresponding to the similar sentence in the form of an operand specified by the similarity specifying information included in the similar sentence, using the operand of the similar sentence as an argument, and an instruction specified by the similarity specifying information As a code that calls a common function that executes
The compiling device according to claim 1.
前記コンパイル装置は、さらに、任意の情報が格納される記憶部を有し、
前記類似文検出部は、前記中間コードにおける文に基づいて、当該文の命令を示す命令情報と、当該文のオペランドの形式を示すオペランド形式情報とを含む中間コード情報を、前記中間コードに含まれる文のそれぞれについて生成して、前記記憶部に格納し、
前記類似文検出部は、前記記憶部に格納された中間コード情報のうち、前記命令情報及び前記オペランド形式情報のそれぞれが示す命令及びオペランドの形式が相互に一致する中間コード情報を検出し、検出した中間コード情報に対応する文を類似文と判定する、
請求項2に記載のコンパイル装置。
The compiling device further includes a storage unit for storing arbitrary information,
The similar sentence detection unit includes, in the intermediate code, intermediate code information including instruction information indicating an instruction of the sentence and operand format information indicating an operand format of the sentence based on the sentence in the intermediate code. Generated for each sentence to be stored in the storage unit,
The similar sentence detection unit detects and detects intermediate code information in which the instruction and operand formats indicated by the instruction information and the operand format information respectively match among the intermediate code information stored in the storage unit. The sentence corresponding to the intermediate code information is determined as a similar sentence,
The compiling device according to claim 2.
前記類似文検出部は、前記類似文を検出したときに、当該類似文の命令及びオペランドの形式を一意に特定する類似特定情報と、当該類似文の命令及びオペランドの形式のそれぞれを示す命令情報及びオペランド情報とを含む類似文情報を生成して、前記記憶部に格納し、
前記類似文検出部は、前記類似文情報が示す命令及びオペランドの形式と、前記中間コード情報が示す命令及びオペランドの形式とが一致する場合、当該類似文情報に含まれる類似特定情報を、当該中間コード情報に対応する文に含める、
請求項3に記載のコンパイル装置。
The similar sentence detection unit, when detecting the similar sentence, similar identification information for uniquely identifying the format of the instruction and operand of the similar sentence, and instruction information indicating each of the format of the instruction and operand of the similar sentence And similar sentence information including the operand information and storing in the storage unit,
When the instruction and operand format indicated by the similar sentence information matches the instruction and operand format indicated by the intermediate code information, the similar sentence detection unit determines the similarity specifying information included in the similar sentence information, Included in the sentence corresponding to the intermediate code information,
The compiling apparatus according to claim 3.
前記オペランドの形式は、オペランドの型及び長さである、
請求項1乃至4のいずれか1項に記載のコンパイル装置。
The form of the operand is the type and length of the operand.
The compiling device according to any one of claims 1 to 4.
前記第1のソースコードは、COBOL言語で記述されたソースコードであり、
前記第2のソースコードは、アセンブラコードである、
請求項1乃至5のいずれか1項に記載のコンパイル装置。
The first source code is a source code written in a COBOL language,
The second source code is an assembler code.
The compiling device according to any one of claims 1 to 5.
それぞれに命令とオペランドとが記述された複数の文を含む第1のソースコードを、中間コードに変換し、さらに前記第1のソースコードよりも低級な言語の第2のソースコードに変換することでコンパイルするコンパイル方法であって、
前記中間コードにおいて、前記命令及び前記オペランドの形式が相互に同一となる文である類似文を検出するステップと、
前記中間コードを前記第2のソースコードに変換するときに、前記中間コードにおいて、前記検出した類似文に対応するコードを、当該類似文のオペランドを引数として、当該類似文の命令を実行する共通関数を呼び出すコードとして変換するステップと、
を備えたコンパイル方法。
Converting a first source code including a plurality of sentences each including an instruction and an operand into an intermediate code, and further converting into a second source code in a language lower than the first source code Compile method to compile with
Detecting a similar sentence in the intermediate code, which is a sentence having the same format of the instruction and the operand;
When the intermediate code is converted to the second source code, a code corresponding to the detected similar sentence is executed in the intermediate code, with the operand of the similar sentence as an argument, and a common sentence instruction is executed Converting it as code that calls a function;
Compile method with
それぞれに命令とオペランドとが記述された複数の文を含む第1のソースコードを、中間コードに変換し、さらに前記第1のソースコードよりも低級な言語の第2のソースコードに変換することでコンパイルするためのコンパイラであって、
前記中間コードにおいて、前記命令及び前記オペランドの形式が相互に同一となる文である類似文を検出する処理と、
前記中間コードを前記第2のソースコードに変換するときに、前記中間コードにおいて、前記検出した類似文に対応するコードを、当該類似文のオペランドを引数として、当該類似文の命令を実行する共通関数を呼び出すコードとして変換する処理と、
をコンピュータに実行させるコンパイラ。
Converting a first source code including a plurality of sentences each including an instruction and an operand into an intermediate code, and further converting into a second source code in a language lower than the first source code A compiler for compiling with
In the intermediate code, a process of detecting a similar sentence that is a sentence having the same format of the instruction and the operand;
When the intermediate code is converted to the second source code, a code corresponding to the detected similar sentence is executed in the intermediate code, with the operand of the similar sentence as an argument, and a common sentence instruction is executed A process to convert the code to call a function,
Is a compiler that allows a computer to execute.
JP2012081715A 2012-03-30 2012-03-30 Compilation device, compilation method, and compiler Pending JP2013210920A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
JP2012081715A JP2013210920A (en) 2012-03-30 2012-03-30 Compilation device, compilation method, and compiler

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
JP2012081715A JP2013210920A (en) 2012-03-30 2012-03-30 Compilation device, compilation method, and compiler

Publications (1)

Publication Number Publication Date
JP2013210920A true JP2013210920A (en) 2013-10-10

Family

ID=49528667

Family Applications (1)

Application Number Title Priority Date Filing Date
JP2012081715A Pending JP2013210920A (en) 2012-03-30 2012-03-30 Compilation device, compilation method, and compiler

Country Status (1)

Country Link
JP (1) JP2013210920A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2015210740A (en) * 2014-04-28 2015-11-24 富士通株式会社 Compilation method, compilation device, and compilation program

Citations (12)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JPH01260548A (en) * 1988-04-12 1989-10-17 Fujitsu Ltd System for processing output of source list for debugging
JPH04367946A (en) * 1991-06-17 1992-12-21 Nec Corp Debug information output system
JPH056278A (en) * 1991-06-28 1993-01-14 Fujitsu Ltd Fortran compile processing device
JPH08263299A (en) * 1995-03-27 1996-10-11 Sanyo Electric Co Ltd Method for converting program
JPH11327887A (en) * 1998-05-13 1999-11-30 Nec Corp Compiler system with automatic parts converting function and recording medium
JP2000347878A (en) * 1999-06-07 2000-12-15 Nec Software Okinawa Ltd Method and device for memory reduction
US6263429B1 (en) * 1998-09-30 2001-07-17 Conexant Systems, Inc. Dynamic microcode for embedded processors
JP2001265605A (en) * 2000-01-12 2001-09-28 Fujitsu Ltd Instruction string optimization method for compiler, compiler device, recording medium and program
JP2003162416A (en) * 2001-11-27 2003-06-06 Matsushita Electric Ind Co Ltd Program conversion apparatus, program conversion method and computer program for realizing the apparatus
US20050235268A1 (en) * 2002-04-15 2005-10-20 Michael Baldischweiler Optimisation of a compiler generated program code
US20060242631A1 (en) * 2005-04-22 2006-10-26 Andersen Jakob R Process and system for sharing program fragments
JP2010108213A (en) * 2008-10-30 2010-05-13 Nec Electronics Corp Program conversion method and program conversion device

Patent Citations (12)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JPH01260548A (en) * 1988-04-12 1989-10-17 Fujitsu Ltd System for processing output of source list for debugging
JPH04367946A (en) * 1991-06-17 1992-12-21 Nec Corp Debug information output system
JPH056278A (en) * 1991-06-28 1993-01-14 Fujitsu Ltd Fortran compile processing device
JPH08263299A (en) * 1995-03-27 1996-10-11 Sanyo Electric Co Ltd Method for converting program
JPH11327887A (en) * 1998-05-13 1999-11-30 Nec Corp Compiler system with automatic parts converting function and recording medium
US6263429B1 (en) * 1998-09-30 2001-07-17 Conexant Systems, Inc. Dynamic microcode for embedded processors
JP2000347878A (en) * 1999-06-07 2000-12-15 Nec Software Okinawa Ltd Method and device for memory reduction
JP2001265605A (en) * 2000-01-12 2001-09-28 Fujitsu Ltd Instruction string optimization method for compiler, compiler device, recording medium and program
JP2003162416A (en) * 2001-11-27 2003-06-06 Matsushita Electric Ind Co Ltd Program conversion apparatus, program conversion method and computer program for realizing the apparatus
US20050235268A1 (en) * 2002-04-15 2005-10-20 Michael Baldischweiler Optimisation of a compiler generated program code
US20060242631A1 (en) * 2005-04-22 2006-10-26 Andersen Jakob R Process and system for sharing program fragments
JP2010108213A (en) * 2008-10-30 2010-05-13 Nec Electronics Corp Program conversion method and program conversion device

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2015210740A (en) * 2014-04-28 2015-11-24 富士通株式会社 Compilation method, compilation device, and compilation program

Similar Documents

Publication Publication Date Title
TWI463404B (en) Compiling systems and methods
CN105335137A (en) Method and device used for processing source file
US7917899B2 (en) Program development apparatus, method for developing a program, and a computer program product for executing an application for a program development apparatus
US20130139137A1 (en) Systems and Methods for Customizing Optimization/Transformation/ Processing Strategies
JP2004295398A (en) Compiler, method for compiling and program developing tool
CN108139891A (en) Include suggesting for the missing of external file
US20090328016A1 (en) Generalized expression trees
CN110058861B (en) Source code processing method and device, storage medium and electronic equipment
JP2010515955A (en) Migration apparatus and method for converting mainframe system application program into application program suitable for open system
US10521203B2 (en) Apparatus and method to facilitate extraction of unused symbols in a program source code
JP2013206291A (en) Program, code generation method and information processing apparatus
JP2009169864A (en) Compile method and compile program
JP2008276735A (en) Program code converter and program code conversion method
US10545741B2 (en) Information processing apparatus, method of compiling, and storage medium
US20110202906A1 (en) Compiling method and compiling program
US9335990B2 (en) Method, a system, and a non-transitory computer-readable medium for supporting application development
JP5038760B2 (en) Source code conversion apparatus and source code conversion method
JP2013210920A (en) Compilation device, compilation method, and compiler
CN115390846A (en) Compiling construction method and device, electronic equipment and storage medium
KR101632027B1 (en) Method for converting program using pseudo code based comment and computer-readable recording media storing the program performing the said mehtod
JP2017091070A (en) Executable code generation program and executable code generation device
JP2009258796A (en) Program development device and program development method
US9720660B2 (en) Binary interface instrumentation
JP5891976B2 (en) Compile execution / management method, apparatus, and program
JP2011180814A (en) Compiler apparatus, compiling method and program

Legal Events

Date Code Title Description
A621 Written request for application examination

Free format text: JAPANESE INTERMEDIATE CODE: A621

Effective date: 20150212

A977 Report on retrieval

Free format text: JAPANESE INTERMEDIATE CODE: A971007

Effective date: 20151014

A131 Notification of reasons for refusal

Free format text: JAPANESE INTERMEDIATE CODE: A131

Effective date: 20151117

A521 Written amendment

Free format text: JAPANESE INTERMEDIATE CODE: A523

Effective date: 20160113

A02 Decision of refusal

Free format text: JAPANESE INTERMEDIATE CODE: A02

Effective date: 20160628