JP2000339171A - Compile device, its method and recording medium - Google Patents
Compile device, its method and recording mediumInfo
- Publication number
- JP2000339171A JP2000339171A JP11147742A JP14774299A JP2000339171A JP 2000339171 A JP2000339171 A JP 2000339171A JP 11147742 A JP11147742 A JP 11147742A JP 14774299 A JP14774299 A JP 14774299A JP 2000339171 A JP2000339171 A JP 2000339171A
- Authority
- JP
- Japan
- Prior art keywords
- register
- program
- generating
- external variable
- code
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
- 238000000034 method Methods 0.000 title claims description 95
- 238000012545 processing Methods 0.000 claims abstract description 80
- 230000008569 process Effects 0.000 description 74
- 238000013519 translation Methods 0.000 description 33
- 230000006870 function Effects 0.000 description 23
- 230000007704 transition Effects 0.000 description 17
- 238000005457 optimization Methods 0.000 description 16
- 238000010586 diagram Methods 0.000 description 15
- 230000000694 effects Effects 0.000 description 5
- 238000012986 modification Methods 0.000 description 3
- 230000004048 modification Effects 0.000 description 3
- 230000009467 reduction Effects 0.000 description 2
- 101100048436 Caenorhabditis elegans unc-1 gene Proteins 0.000 description 1
- 230000008859 change Effects 0.000 description 1
- 230000010485 coping Effects 0.000 description 1
- 230000003287 optical effect Effects 0.000 description 1
Landscapes
- Devices For Executing Special Programs (AREA)
Abstract
Description
【0001】[0001]
【発明の属する技術分野】本発明は、コンパイル装置、
方法及びコンパイラプログラムを記録したコンピュータ
読み取り可能な記録媒体に関する。[0001] The present invention relates to a compiling device,
The present invention relates to a method and a computer-readable recording medium recording a compiler program.
【0002】[0002]
【従来の技術】従来のコンパイラは、例えば、図18に
示すように、字句解析手段101と、構文解析手段10
2と、最適化手段103と、コード出力手段10401
を有するコード生成手段1041とで構成されている。
このようなコンパイラでは、字句解析、構文解析、最適
化の各フェーズを経て、コード生成手段1041におい
てオブジェクトプログラム(アセンブラまたは機械語)
のコードが生成される。2. Description of the Related Art A conventional compiler includes, for example, a lexical analyzer 101 and a syntax analyzer 10 as shown in FIG.
2, optimization means 103, code output means 10401
And code generation means 1041 having
In such a compiler, an object program (assembler or machine language) is passed through the lexical analysis, syntax analysis, and optimization phases in the code generation unit 1041.
Code is generated.
【0003】このようなコンパイラにおいて、コンパイ
ル対象となるソースプログラムで変数を定義すると、生
成されたオブジェクトプログラムは、定義した変数の領
域をメモリ中に確保するためのコードを含むものとな
る。そして、このオブジェクトプログラムを実行するコ
ンピュータのCPU(Central Processing Unit)は、
当該変数に対する参照があったとき、前記のコードによ
り確保されたメモリ中の領域にアクセスすることとな
る。In such a compiler, when a variable is defined in a source program to be compiled, the generated object program includes a code for securing an area for the defined variable in a memory. Then, the CPU (Central Processing Unit) of the computer that executes the object program,
When a reference is made to the variable, an area in the memory secured by the above code is accessed.
【0004】ところが、メモリへのアクセスは外部バス
を経由して行わなければならないので、時間がかかって
しまう。そこで、参照頻度の高い変数にはCPU内部の
レジスタを割り当て、変数の参照時にレジスタに対する
アクセスを行うようにすることが、プログラムの実行時
間の観点から有効である。このような最適化処理は、一
般に、レジスタ割り当て最適化と呼ばれている。However, since access to the memory must be performed via an external bus, it takes time. Therefore, it is effective from the viewpoint of the execution time of the program to allocate a register inside the CPU to a variable having a high frequency of reference and to access the register when the variable is referenced. Such optimization processing is generally called register allocation optimization.
【0005】従来のコンパイラにおけるレジスタ割り当
て最適化は、一般に、ソースプログラムでの参照回数が
多い変数にレジスタを割り当てるものであった。ところ
が、ソースプログラムで変数の参照命令が出現する回数
と、コンパイルしたオブジェクトプログラムを実行する
ときに変数を参照する回数とは異なっている。例えば、
変数の参照命令の前に条件分岐命令がある場合には、プ
ログラム実行時の条件によって当該変数が参照されたり
参照されなかったりする。[0005] Register allocation optimization in a conventional compiler generally involves allocating registers to variables that are frequently referenced in a source program. However, the number of times a variable reference instruction appears in a source program is different from the number of times a variable is referenced when a compiled object program is executed. For example,
When a conditional branch instruction is preceded by a variable reference instruction, the variable may or may not be referenced depending on the conditions at the time of program execution.
【0006】また、ループ処理には、ループの回数が静
的に判断可能なものもあるが、実行時にしか分からない
ものもある。実行時にしか回数の分からないループ処理
がある場合には、適当な重み付けをしてループの回数と
見なし、変数を参照する回数を判断するのが一般的であ
るが、これは当然誤差を含んだものとなる。ループの回
数は、プログラムによっては実行時にかなり変動するも
のもあり、これが変数の参照回数を判断するために大き
な誤差となって、最適なレジスタ割り当てが行われない
場合がかなりあった。In some loop processing, the number of loops can be statically determined, but in other loop processing, it is only known at the time of execution. If there is a loop process whose number can only be determined at the time of execution, it is general to consider the number of loops with appropriate weighting and determine the number of times to refer to variables, but this naturally includes an error It will be. The number of loops varies considerably at the time of execution depending on a program, and this causes a large error in judging the number of times of reference to a variable, and in many cases, optimal register allocation is not performed.
【0007】そこで、特開昭61−82243号公報に
記載の「オブジェクトプログラム生成方法」では、コン
パイラに2つの出力手段を持たせることで、最適なレジ
スタ割り当てを行っている。すなわち、1つ目の手段で
は、実行時に変数毎の参照回数を記録する参照頻度記憶
領域を生成するコードを含むオブジェクトプログラムを
生成し、2つ目の手段では、1つ目の手段で出力された
オブジェクトプログラムを実行することにより得られた
参照頻度記憶領域内の情報を参照して、参照頻度の高い
変数にレジスタを割り当てるオブジェクトプログラムを
生成するものとしている。Therefore, in the "object program generation method" described in Japanese Patent Application Laid-Open No. 61-82243, the compiler is provided with two output means to perform optimal register allocation. That is, the first means generates an object program including a code for generating a reference frequency storage area for recording the number of times of reference for each variable at the time of execution, and the second means outputs the object program by the first means. By referring to the information in the reference frequency storage area obtained by executing the object program, an object program that allocates registers to variables with high reference frequency is generated.
【0008】[0008]
【発明が解決しようとする課題】しかしながら、上記特
開昭61−82243号公報では、参照頻度に従ってレ
ジスタの割り当てを行うのみで、レジスタの割り当て対
象となる変数の属性に関する記述がなされていない。ま
た、どのような変数にどのようなレジスタを割り当てる
かに関する記述もされていない。このため、例えば、外
部変数の参照回数が多くなり、これに多くのレジスタが
割り当てられてしまうと、関数の整合性を図るために必
要なレジスタを確保することができなくなってしまう。However, in the above-mentioned Japanese Patent Application Laid-Open No. 61-82243, only the assignment of registers is performed in accordance with the reference frequency, but no description is given regarding the attributes of variables to be assigned to the registers. Further, there is no description about what registers are allocated to what variables. For this reason, for example, if the number of references to the external variable increases and a large number of registers are allocated to the external variable, it becomes impossible to secure the registers necessary for ensuring the consistency of the function.
【0009】ところが、上記公報では、このような場合
の対処方法が何ら開示されていなかった。そこで、この
ような事態が発生した場合には、結局のところレジスタ
の退避/復帰を行わなければならなくなってしまうの
で、コード効率が悪くなり、プログラムの実行速度が遅
くなってしまうという問題があった。また、メモリ中に
レジスタの退避領域も用意しておく必要があり、メモリ
の利用効率が悪くなってしまうという問題もあった。[0009] However, the above publication does not disclose any method for coping with such a case. Therefore, when such a situation occurs, it is necessary to save / restore the registers after all, so that the code efficiency is deteriorated and the program execution speed is reduced. Was. In addition, it is necessary to prepare a save area for the register in the memory, and there is a problem that the use efficiency of the memory is deteriorated.
【0010】なお、レジスタ割り当て最適化に関する他
の技術が、例えば、特開平4−326432号公報や特
開平6−214802号公報において開示されている。
しかしながら、これらの公報に記載された技術でも、上
記特開昭61−82243号公報に記載の技術で指摘し
た問題点を何ら解決することができない。[0010] Other techniques related to register allocation optimization are disclosed in, for example, Japanese Patent Application Laid-Open Nos. 4-326432 and 6-214802.
However, even the techniques described in these publications cannot solve the problems pointed out in the technique described in JP-A-61-82243.
【0011】本発明は、メモリの利用効率がよく、しか
も実行速度の速いオブジェクトプログラムを生成するこ
とができるコンパイル装置、方法、及びこのようなコン
パイラプログラムを記録したコンピュータ読み取り可能
な記録媒体を提供することを目的とする。The present invention provides a compiling apparatus and method capable of generating an object program with high memory utilization efficiency and high execution speed, and a computer-readable recording medium on which such a compiler program is recorded. The purpose is to:
【0012】[0012]
【課題を解決するための手段】上記目的を達成するた
め、本発明の第1の観点にかかるコンパイル装置は、互
いに参照される外部変数を含む複数のソースプログラム
を構文解析した複数の中間ファイルに基づいて、オブジ
ェクトプログラムを生成するコンパイル装置であって、
前記複数の中間ファイルに基づいて、前記外部変数を参
照するための領域をメモリに確保する複数の第1のオブ
ジェクトプログラムを生成する第1のオブジェクトプロ
グラム生成手段と、前記オブジェクトプログラム生成手
段が生成した複数の第1のオブジェクトプログラムを結
合した実行形式のプログラムを実行した結果、参照回数
が多い外部変数から順に、他で使用されていないレジス
タを割り当てるレジスタ割り当て手段と、前記レジスタ
割り当て手段によるレジスタの割り当てを参照し、前記
複数の中間ファイルに基づいて、レジスタが割り当てら
れた外部変数の参照を当該割り当てられたレジスタを用
いて行う複数の第2のオブジェクトプログラムを生成す
る第2のオブジェクトプログラム生成手段とを備えるこ
とを特徴とする。In order to achieve the above object, a compiling apparatus according to a first aspect of the present invention provides a compiling apparatus which parses a plurality of source programs including external variables referred to each other into a plurality of intermediate files. A compiling device for generating an object program based on the
A first object program generating unit for generating a plurality of first object programs for securing an area for referring to the external variable in a memory based on the plurality of intermediate files; Register allocating means for allocating a register which is not used elsewhere in the order of external variables having a large number of references as a result of executing a program in an executable form in which a plurality of first object programs are combined, and allocating registers by the register allocating means A second object program generating means for generating, based on the plurality of intermediate files, a plurality of second object programs for referring to an external variable to which a register is assigned by using the assigned register; It is characterized by having.
【0013】上記コンパイル装置では、参照頻度の高い
外部変数は割り当てたレジスタを用いて参照することが
できるため、生成された第2のオブジェクトプログラム
を結合したプログラムを実行した場合の実行速度を早く
することができる。また、レジスタを使用して参照され
る外部変数には、メモリを割り当てなくても済む場合が
生じるため、メモリの利用効率を高いものとすることが
できる。In the above-mentioned compiling apparatus, since the external variable having a high frequency of reference can be referred to using the allocated register, the execution speed when the program combining the generated second object program is executed is increased. be able to. Further, in some cases, it is not necessary to allocate a memory for an external variable referred to by using a register, so that the use efficiency of the memory can be increased.
【0014】上記コンパイル装置において、前記レジス
タ割り当て手段が外部変数に割り当てる他で使用されて
いないレジスタは、前記実行形式のプログラムを実行し
た結果により得られたものであってもよい。In the above-mentioned compiling device, the register which is not used except for assigning to the external variable by the register assigning means may be obtained as a result of executing the program in the executable form.
【0015】この場合において、前記第1のオブジェク
トプログラム生成手段は、前記複数の第1、第2のオブ
ジェクトプログラムを結合した実行形式のプログラムが
実行される装置に含まれるレジスタと、各レジスタに対
応付けてその使用状況に関する情報を管理するレジスタ
使用管理手段を前記複数の第1のオブジェクトプログラ
ムを結合した実行形式のプログラムを実行するときに生
成するためのコードを生成する手段と、前記複数の第1
のオブジェクトプログラムを結合した実行形式のプログ
ラムを実行してレジスタが使用されたときに当該使用さ
れたレジスタに対応する前記レジスタ使用管理手段内の
使用状況を使用状態とするコードを生成する手段とを含
むものとすることができ、前記レジスタ割り当て手段
は、前記複数の第1のオブジェクトプログラムを結合し
た実行形式のプログラムを実行後に得られた前記レジス
タ使用管理手段を参照して、外部変数へレジスタを割り
当てるものとすることができる。In this case, the first object program generating means includes a register included in an apparatus for executing an executable program obtained by combining the plurality of first and second object programs, and a register corresponding to each register. Means for generating a code for generating a register use management means for managing information on the use state when executing an executable program obtained by combining the plurality of first object programs; and 1
Means for executing a program in an executable form in which the object program is combined and generating a code for setting a use state in the register use management means corresponding to the used register when the register is used. Wherein the register allocating means allocates a register to an external variable by referring to the register use managing means obtained after executing an executable program obtained by combining the plurality of first object programs. It can be.
【0016】上記コンパイル装置において、前記レジス
タ割り当て手段が外部変数に割り当てる他で使用されて
いないレジスタは、また、前記複数の第1のオブジェク
トプログラム中で使用されているレジスタ以外のレジス
タであってもよい。In the above-mentioned compiling apparatus, the register which is not used except for assigning to the external variable by the register allocating means may be a register other than the register used in the plurality of first object programs. Good.
【0017】この場合において、前記第1のオブジェク
トプログラム生成手段は、前記複数の第1、第2のオブ
ジェクトプログラムを結合した実行形式のプログラムが
実行される装置に含まれる各レジスタに対応付けてその
使用状況に関する情報を管理するレジスタ使用管理手段
を生成する手段と、前記レジスタのいずれかを使用する
コードを生成したときに当該使用されたレジスタに対応
する前記レジスタ使用管理手段内の使用状況を使用状態
とする手段とを備えるものとすることができる。In this case, the first object program generation means associates the plurality of first and second object programs with each register included in a device that executes an executable program that combines the plurality of first and second object programs. Means for generating register use management means for managing information on the use state, and using the use state in the register use management means corresponding to the used register when generating a code for using any of the registers Means for setting a state.
【0018】上記コンパイル装置において、前記第1の
オブジェクトプログラム生成手段は、各外部変数と対応
付けて参照回数を記憶する参照頻度記憶手段を前記複数
の第1のオブジェクトプログラムを結合した実行形式の
プログラムを実行するときに生成するためのコードを生
成する手段と、前記複数の第1のオブジェクトプログラ
ムを結合した実行形式のプログラムを実行して外部変数
が参照さたときに当該参照された外部変数に対応する前
記参照頻度記憶手段内の参照回数を加算するコードを生
成する手段とを含むものとしてもよい。In the above-mentioned compiling apparatus, the first object program generating means may include a reference frequency storage means for storing the number of times of reference in association with each external variable, and an execution form program combining the plurality of first object programs. Means for generating a code for generating when the external variable is referred to, and when the external variable is referred to by executing an executable program in which the plurality of first object programs are combined, Means for generating a code for adding the number of references in the corresponding reference frequency storage means.
【0019】また、前記参照頻度記憶手段は、さらに前
記外部変数のそれぞれに対応付けてその初期値を記憶す
るものとしてもよく、この場合には、前記第1のオブジ
ェクトプログラム生成手段は、前記外部変数の初期値を
前記参照頻度記憶手段内に設定するコードを生成する手
段を含むものとすることができる。Further, the reference frequency storage means may further store an initial value in association with each of the external variables. In this case, the first object program generating means may store the initial value. It may include means for generating a code for setting an initial value of a variable in the reference frequency storage means.
【0020】さらに、前記参照頻度記憶手段は、前記外
部変数のそれぞれに対応して割り当てたレジスタに関す
る情報を記憶するものとしてもよく、この場合には、前
記レジスタ割り当て手段は、前記複数の第1のオブジェ
クトプログラムを結合した実行形式のプログラムを実行
した後の前記参照頻度記憶手段内の各外部変数の参照回
数に従ってレジスタの割り当てを行って、対応する外部
変数のレジスタに関する情報の欄に記憶させ、前記第2
のオブジェクトプログラム生成手段は、前記参照頻度記
憶手段を参照して、前記複数の第2のオブジェクトプロ
グラムを生成するものとすることができる。Further, the reference frequency storage means may store information on registers assigned to each of the external variables. In this case, the register assignment means may store the plurality of first variables. Assigning registers according to the reference frequency of each external variable in the reference frequency storage means after executing the execution form program in which the object program is combined, and storing the information in the information field regarding the register of the corresponding external variable, The second
The object program generating means may generate the plurality of second object programs with reference to the reference frequency storage means.
【0021】また、上記コンパイル装置において、前記
第2のオブジェクトプログラム生成手段は、前記レジス
タ割り当て手段が外部変数に割り当てたレジスタを、割
り込み処理での退避及び復帰の対象となるレジスタから
除外するためのコードを生成する手段を含むものとして
もよい。In the above-mentioned compiling apparatus, the second object program generating means is for excluding a register allocated to the external variable by the register allocating means from registers to be saved and restored in interrupt processing. It may include means for generating code.
【0022】なお、上記コンパイル装置において、前記
複数の中間ファイルは、前記第1のオブジェクトプログ
ラム生成手段が前記複数の第1のオブジェクトプログラ
ムを生成する前と、前記第2のオブジェクトプログラム
生成手段が前記複数の第2のオブジェクトプログラムを
生成する前とにおいて、それぞれ別々に生成されたもの
であってもよい。In the compiling apparatus, the plurality of intermediate files may be stored before the first object program generating means generates the plurality of first object programs and when the second object program generating means generates the plurality of first object programs. Before the plurality of second object programs are generated, they may be generated separately.
【0023】上記目的を達成するため、本発明の第2の
観点にかかるコンパイル方法は、互いに参照される外部
変数を含む複数のソースプログラムを構文解析した複数
の中間ファイルに基づいて、オブジェクトプログラムを
生成するコンパイル方法であって、前記複数の中間ファ
イルに基づいて、前記外部変数を参照するための領域を
メモリに確保する複数の第1のオブジェクトプログラム
を生成する第1のオブジェクトプログラム生成ステップ
と、前記オブジェクトプログラム生成ステップで生成し
た複数の第1のオブジェクトプログラムを結合した実行
形式のプログラムを実行した結果、参照回数が多い外部
変数から順に、他で使用されていないレジスタを割り当
てるレジスタ割り当てステップと、前記レジスタ割り当
てステップにおけるレジスタの割り当てを参照し、前記
複数の中間ファイルに基づいて、レジスタが割り当てら
れた外部変数の参照を当該割り当てられたレジスタを用
いて行う複数の第2のオブジェクトプログラムを生成す
る第2のオブジェクトプログラム生成ステップとを含む
ことを特徴とする。In order to achieve the above object, a compiling method according to a second aspect of the present invention is a method for compiling an object program based on a plurality of intermediate files obtained by parsing a plurality of source programs including external variables referred to each other. A compiling method for generating, wherein a first object program generating step of generating a plurality of first object programs for securing an area for referencing the external variable in a memory based on the plurality of intermediate files; A register allocating step of allocating registers that are not used elsewhere in order from an external variable having a large number of references, as a result of executing an executable form program in which the plurality of first object programs generated in the object program generating step are combined; In the register allocation step A second object program for generating a plurality of second object programs that refers to register allocation and references external variables to which registers are allocated using the allocated registers based on the plurality of intermediate files And a generating step.
【0024】上記コンパイル方法において、前記レジス
タ割り当てステップで外部変数に割り当てる他で使用さ
れていないレジスタは、前記実行形式のプログラムを実
行した結果により得られたものであってもよい。In the above-mentioned compiling method, the register which is not used except for assigning to an external variable in the register assigning step may be obtained as a result of executing the program in the executable form.
【0025】上記コンパイル方法において、前記レジス
タ割り当てステップで外部変数に割り当てる他で使用さ
れていないレジスタは、また、前記複数の第1のオブジ
ェクトプログラム中で使用されているレジスタ以外のレ
ジスタであってもよい。In the above-mentioned compiling method, the register which is not used except for assigning to an external variable in the register allocating step may be a register other than the register used in the plurality of first object programs. Good.
【0026】上記目的を達成するため、本発明の第3の
観点にかかるコンピュータ読み取り可能な記録媒体は、
互いに参照される外部変数を含む複数のソースプログラ
ムを構文解析した複数の中間ファイルに基づいて、オブ
ジェクトプログラムを生成するためのコンパイラプログ
ラムを記録したコンピュータ読み取り可能な記録媒体で
あって、前記複数の中間ファイルに基づいて、前記外部
変数を参照するための領域をメモリに確保する複数の第
1のオブジェクトプログラムを生成する第1のオブジェ
クトプログラム生成ステップと、前記オブジェクトプロ
グラム生成ステップで生成した複数の第1のオブジェク
トプログラムを結合した実行形式のプログラムを実行し
た結果、参照回数が多い外部変数から順に、他で使用さ
れていないレジスタを割り当てるレジスタ割り当てステ
ップと、前記レジスタ割り当てステップにおけるレジス
タの割り当てを参照し、前記複数の中間ファイルに基づ
いて、レジスタが割り当てられた外部変数の参照を当該
割り当てられたレジスタを用いて行う複数の第2のオブ
ジェクトプログラムを生成する第2のオブジェクトプロ
グラム生成ステップとを実行させるためのプログラムを
記録することを特徴とする。In order to achieve the above object, a computer-readable recording medium according to a third aspect of the present invention comprises:
A computer-readable recording medium on which a compiler program for generating an object program is recorded based on a plurality of intermediate files obtained by parsing a plurality of source programs including external variables which are referred to each other, wherein A first object program generating step for generating a plurality of first object programs for securing an area for referring to the external variable in a memory based on a file; and a plurality of first object programs generated in the object program generating step. As a result of execution of the execution form program in which the object programs are combined with each other, a register allocating step of allocating a register that is not used by another in order from an external variable having a large number of references, and a register allocating in the register allocating step are referred to. And executing a second object program generating step of generating, based on the plurality of intermediate files, a plurality of second object programs for referring to an external variable to which a register is assigned by using the assigned register. The program is characterized by recording a program for causing the program to execute.
【0027】上記記録媒体に記録されているプログラム
において、前記レジスタ割り当てステップで外部変数に
割り当てる他で使用されていないレジスタは、前記実行
形式のプログラムを実行した結果により得られたもので
あってもよい。In the program recorded on the recording medium, the register which is not used except for assigning it to an external variable in the register allocating step may be obtained as a result of executing the program in the executable form. Good.
【0028】上記記録媒体に記録されているプログラム
において、前記レジスタ割り当てステップで外部変数に
割り当てる他で使用されていないレジスタは、また、前
記複数の第1のオブジェクトプログラム中で使用されて
いるレジスタ以外のレジスタであってもよい。In the program recorded on the recording medium, the registers which are not used except for assigning to the external variables in the register allocating step are also registers other than the registers used in the plurality of first object programs. Register.
【0029】[0029]
【発明の実施の形態】以下、添付図面を参照して、本発
明の実施の形態について説明する。Embodiments of the present invention will be described below with reference to the accompanying drawings.
【0030】[第1の実施の形態]図1は、この実施の
形態にかかるコンパイラを示す機能ブロック図である。
この図では、メモリ上に記憶されたコンパイラプログラ
ムを実行するプロセッサが実現する機能として示してい
る。すなわち、コンパイラプログラムが実行されるコン
ピュータシステムが、コンパイル装置として動作する。[First Embodiment] FIG. 1 is a functional block diagram showing a compiler according to the first embodiment.
In this drawing, the functions are shown as functions realized by a processor that executes a compiler program stored in a memory. That is, the computer system on which the compiler program is executed operates as a compiling device.
【0031】図1に示すように、この実施の形態にかか
るコンパイラ10は、字句解析手段101と、構文解析
手段102と、最適化手段103と、コード生成手段1
041とを備えている。コード生成手段1041は、コ
ード生成制御手段10411と、外部変数およびレジス
タ情報出力コード生成手段10412と、未使用レジス
タ外部変数割り当て手段10413と、未使用レジスタ
外部変数割り当てコード生成手段10414と、コード
出力手段10401とを備えている。As shown in FIG. 1, a compiler 10 according to this embodiment includes a lexical analysis unit 101, a syntax analysis unit 102, an optimization unit 103, and a code generation unit 1.
041. The code generation unit 1041 includes a code generation control unit 10411, an external variable and register information output code generation unit 10412, an unused register external variable allocation unit 10413, an unused register external variable allocation code generation unit 10414, and a code output unit. 10401.
【0032】字句解析手段101は、コンパイルの対象
となる、高級言語で記述されたソースプログラムを字句
(トークン)に分解する。構文解析手段102は、分解
された字句を当該プログラム言語の仕様に従って構文解
析し、解析結果として、例えば構文木などを生成する。
最適化手段103は、冗長な命令等を見直すことで、コ
ンパイル後のオブジェクトプログラムの実行効率を向上
させる。これらの手段101〜103の処理結果は、中
間ファイルとしてコード生成手段1041に渡される。The lexical analysis means 101 decomposes a source program described in a high-level language to be compiled into tokens. The parsing means 102 parses the decomposed lexical data according to the specification of the program language, and generates, for example, a parse tree as a result of the parsing.
The optimization unit 103 improves the execution efficiency of the compiled object program by reviewing redundant instructions and the like. The processing results of these units 101 to 103 are passed to the code generation unit 1041 as an intermediate file.
【0033】コード生成制御手段10411は、2回の
処理で行われる翻訳処理(上記の中間ファイルからアセ
ンブラコードを生成するための処理をいう。以下、同
じ)を制御する。すなわち、コード生成手段10411
は、1回目の翻訳処理では、外部変数及びレジスタ情報
出力コード生成手段10412を呼び出し、2回目の翻
訳処理では、未使用レジスタ外部変数割り当て手段10
413及び未使用レジスタ外部変数割り当てコード生成
手段10414を順次呼び出す。The code generation control means 10411 controls a translation process (process for generating assembler code from the above-mentioned intermediate file, which is performed in two processes). That is, the code generation unit 10411
Calls the external variable and register information output code generation means 10412 in the first translation processing, and uses the unused register external variable allocation means 1012 in the second translation processing.
413 and unused register external variable assignment code generation means 10414 are sequentially called.
【0034】外部変数およびレジスタ情報出力コード生
成手段10412は、最適化手段103の出力結果であ
る中間ファイルから従来と同様の外部変数のための領域
をメモリ内に確保するためのコードを生成すると共に、
外部変数の参照回数と変数に割り当てるレジスタに関す
る情報を出力するためのコードを生成する。An external variable and register information output code generating means 10412 generates a code for securing an area for an external variable in a memory from the intermediate file which is the output result of the optimizing means 103, as in the conventional case. ,
Generate code to output information about the number of references to external variables and registers to be assigned to variables.
【0035】未使用レジスタ外部変数割り当て手段10
413は、外部変数およびレジスタ情報出力コード生成
手段10412が生成したコードが実行形式となって実
行されたときの情報を基にして、未使用のレジスタを外
部変数のために割り当てる処理を行う。Unused register external variable allocation means 10
Reference numeral 413 performs a process of allocating unused registers to the external variables based on information when the code generated by the external variable and the register information output code generation unit 10412 is executed in an executable form.
【0036】未使用レジスタ外部変数割り当てコード生
成手段10414は、未使用レジスタ外部変数割り当て
手段10413による外部変数へのレジスタ割り当てを
参照して、最適化手段103の出力結果である中間ファ
イルから、レジスタ割り当ての行われた外部変数のため
の領域をメモリ領域に確保しないコードを生成する。The unused register external variable allocation code generation means 10414 refers to the register allocation to the external variables by the unused register external variable allocation means 10413, and uses the intermediate file which is the output result of the optimizing means 103 to allocate the register. Generates a code that does not secure the area for the external variable for which the
【0037】コード出力手段10401は、外部変数お
よびレジスタ情報出力コード生成手段10412により
生成されたアセンブラプログラムのコード、または未使
用レジスタ外部変数割り当てコード生成手段10414
により生成されたアセンブラプログラムのコードを出力
する。The code output means 10401 is an assembler program code generated by the external variable and register information output code generation means 10412 or an unused register external variable allocation code generation means 10414.
Outputs the code of the assembler program generated by.
【0038】以下、この実施の形態にかかるコンパイラ
10を含むシステムにおいて、高級言語で記述されたソ
ースプログラムから実行可能な形式のロードモジュール
が生成されるまでの動作の概略について、説明する。図
2は、このような動作を行うための、コンパイラ10を
含むシステム全体を示す図である。The operation of the system including the compiler 10 according to this embodiment until a load module in an executable format is generated from a source program described in a high-level language will be described below. FIG. 2 is a diagram showing the entire system including the compiler 10 for performing such an operation.
【0039】まず、高級言語で記述された複数のソース
プログラム(A、B、C)201をコンパイラ10に入
力する。コンパイラ10は、入力されたソースプログラ
ム201のそれぞれに対して1回目の翻訳処理を行う。
この1回目の翻訳処理では、まず、字句解析手段10
1、構文解析手段102及び最適化手段103が、従来
と同様の処理を行い、その結果を中間ファイル(A、
B、C)202として出力する。First, a plurality of source programs (A, B, C) 201 described in a high-level language are input to the compiler 10. The compiler 10 performs a first translation process on each of the input source programs 201.
In the first translation processing, first, the lexical analysis means 10
1. The parsing means 102 and the optimizing means 103 perform the same processing as before, and the result is stored in the intermediate file (A,
B, C) 202.
【0040】次に、コンパイラ10では、コード生成手
段1041が、中間ファイル202を入力として通常の
コード生成を行うと共に、外部変数およびレジスタ情報
出力コード生成手段10412により外部変数の参照回
数と変数に割り当てるレジスタに関する情報を出力する
ためのコードを生成することにより、第1のアセンブラ
プログラム(A、B、C)203を生成する。Next, in the compiler 10, the code generation means 1041 performs normal code generation using the intermediate file 202 as an input, and allocates the external variable and the register information output code generation means 10412 to the external variable reference count and variables. The first assembler program (A, B, C) 203 is generated by generating a code for outputting information about the register.
【0041】次に、アセンブラ20が第1のアセンブラ
プログラム203をそれぞれアセンブルし、これをさら
にリンカ30がリンクして、実行形式のプログラム20
5を生成する。そして、プログラム実行部40が実行形
式のプログラム205を実行することにより、レジスタ
使用管理領域301と、参照頻度記憶領域302とを生
成する。Next, the assembler 20 assembles the first assembler program 203, and the linker 30 further links the first assembler program 203.
5 is generated. Then, the program execution unit 40 executes the executable program 205 to generate the register use management area 301 and the reference frequency storage area 302.
【0042】次に、コンパイラ10では、コード生成手
段1041が、1回目の翻訳処理で生成された中間ファ
イル202、並びにレジスタ使用管理領域301及び参
照頻度記憶領域302を入力として2回目の翻訳処理を
行う。2回目の翻訳処理では、未使用レジスタ外部変数
割り当て手段10413がすべてのプログラムで同一の
レジスタを参照回数の多い変数に割り当てると共に、使
用レジスタ外部変数割り当てコード生成手段10414
がレジスタが割り当てられた外部変数のための領域をメ
モリ領域に確保しないコードを生成することにより、第
2のアセンブラプログラム(A、B、C)204を生成
する。Next, in the compiler 10, the code generation means 1041 performs the second translation processing by using the intermediate file 202 generated in the first translation processing, the register use management area 301 and the reference frequency storage area 302 as inputs. Do. In the second translation process, the unused register external variable allocating unit 10413 allocates the same register to the variable having a high number of references in all programs, and the used register external variable allocation code generating unit 10414.
Generates a second assembler program (A, B, C) 204 by generating a code that does not reserve an area for an external variable to which a register is assigned in a memory area.
【0043】そして、アセンブラ20が第2のアセンブ
ラプログラム204をそれぞれアセンブルし、これをさ
らにリンカ30がリンクして、最終の出力として、実行
形式のプログラム206を生成する。Then, the assembler 20 assembles the second assembler program 204, respectively, and the linker 30 further links the assembler program 204 to generate an executable program 206 as a final output.
【0044】以下、コード生成制御手段10411、外
部変数およびレジスタ情報出力コード生成手段1041
2、未使用レジスタ外部変数割り当て手段10413及
び未使用レジスタ外部変数割り当てコード生成手段10
414の動作の詳細について、それぞれ図3〜図6に示
すフローチャートを参照して説明する。Hereinafter, code generation control means 10411, external variable and register information output code generation means 1041
2. Unused register external variable allocation means 10413 and unused register external variable allocation code generation means 10
Details of the operation of 414 will be described with reference to the flowcharts shown in FIGS.
【0045】図3は、コード生成制御手段10411の
処理を示すフローチャートである。コード生成制御手段
10411は、まず、最初の翻訳処理であるかどうかを
判定する(ステップS101)。最初の翻訳処理である
場合には、コード生成制御手段10411は、外部変数
およびレジスタ情報出力コード生成手段10412を呼
び出し、後述する処理を実行させる(ステップS10
2)。外部変数およびレジスタ情報出力コード生成手段
10412から制御が戻ると、コード生成制御手段10
411は、このフローチャートの処理を終了する。FIG. 3 is a flowchart showing the processing of the code generation control means 10411. First, the code generation control unit 10411 determines whether or not it is the first translation process (step S101). If it is the first translation process, the code generation control unit 10411 calls the external variable and register information output code generation unit 10412 to execute the process described later (step S10).
2). When control is returned from the external variable and register information output code generation means 10412, the code generation control means 10
Step 411 ends the process of this flowchart.
【0046】一方、最初の翻訳処理でない場合、すなわ
ち2回目の翻訳処理である場合には、コード生成制御手
段10411は、未使用レジスタ外部変数割り当て手段
10413を呼び出し、後述する処理を実行させる(ス
テップS103)。外部変数およびレジスタ情報出力コ
ード生成手段10412から制御が戻ると、コード生成
制御手段10411は、今度は未使用レジスタ外部変数
割り当てコード生成手段10414を呼び出し、後述す
る処理を実行させる(ステップS104)。未使用レジ
スタ外部変数割り当てコード生成手段10414から制
御が戻ると、コード生成手段10411は、このフロー
チャートの処理を終了する。On the other hand, if it is not the first translation processing, that is, if it is the second translation processing, the code generation control means 10411 calls the unused register external variable allocation means 10413 and executes the processing described later (step S103). When the control is returned from the external variable and register information output code generation unit 10412, the code generation control unit 10411 calls the unused register external variable allocation code generation unit 10414, and executes the process described later (step S104). When the control is returned from the unused register external variable assignment code generation unit 10414, the code generation unit 10411 ends the processing of this flowchart.
【0047】図4は、外部変数およびレジスタ情報出力
コード生成手段10412の処理を示すフローチャート
である。外部変数およびレジスタ情報出力コード生成手
段10412は、まず、上述した参照頻度記憶領域30
2及びレジスタ使用管理要域301を確保するためのコ
ードがまだ生成されていないかどうかを判定する(ステ
ップS201)。判定結果により、このようなコードが
生成されていればステップS203に、そうでなければ
ステップS202の処理に進む。FIG. 4 is a flowchart showing the processing of the external variable and register information output code generation means 10412. The external variable and register information output code generation means 10412 firstly outputs the reference frequency storage area 30
It is determined whether a code for securing the area 2 and the register use management area 301 has not been generated yet (step S201). As a result of the determination, if such a code has been generated, the process proceeds to step S203; otherwise, the process proceeds to step S202.
【0048】ステップS202では、外部変数およびレ
ジスタ情報出力コード生成手段10412は、プログラ
ム実行部40による実行時において参照頻度記憶領域3
01とレジスタ使用管理領域302とをメモリ内に確保
し、レジスタ使用管理領域302のレジスタ名の欄に特
殊レジスタを除くすべてのレジスタの名称を登録し、且
つレジスタ使用管理領域302の使用フラグの欄を
“0”に初期化するための処理を行うためのコードを生
成する。このコードの生成が終了すると、ステップS2
03の処理に進む。In step S 202, the external variable and register information output code generation means 10412 stores the reference frequency storage area 3
01 and the register use management area 302 are secured in the memory, the names of all registers except special registers are registered in the register name field of the register use management area 302, and the use flag field of the register use management area 302 is used. To generate a code for performing a process for initializing to “0”. When the generation of this code is completed, step S2
Proceed to 03.
【0049】ステップS203では、外部変数およびレ
ジスタ情報出力コード生成手段10412は、最適化手
段103の処理結果である中間ファイル202がすべて
終了したかどうかを判定する。なお、この判定における
中間ファイル202は、コンパイルの対象となるものす
べてのことを意味し、図2の例でいえば、中間ファイル
A、B、Cの3つすべてをいう。In step S203, the external variable and register information output code generating means 10412 determines whether or not all the intermediate files 202 as the processing results of the optimizing means 103 have been completed. The intermediate file 202 in this determination means all files to be compiled, and in the example of FIG. 2, all three of the intermediate files A, B, and C.
【0050】中間ファイル202がまだ終了していない
と判定すれば、外部変数およびレジスタ情報出力コード
生成手段10412は、最適化手段103の処理結果で
ある中間ファイル202から1行分を読み出す(ステッ
プS204)。さらに、外部変数およびレジスタ情報出
力コード生成手段10412は、当該読み出した行が外
部変数定義文であるかどうかを判定する(ステップS2
05)。If it is determined that the intermediate file 202 has not been completed, the external variable and register information output code generating means 10412 reads one line from the intermediate file 202 which is the processing result of the optimizing means 103 (step S204). ). Further, the external variable and register information output code generation unit 10412 determines whether the read line is an external variable definition statement (step S2).
05).
【0051】外部変数定義文であると判定した場合は、
外部変数およびレジスタ情報出力コード生成手段104
12は、プログラム実行部40による実行時において参
照頻度記憶領域302の変数の欄に当該外部変数の名称
を登録し、対応する参照回数の欄を“0”に初期化し、
対応する初期値の欄に当該外部変数の初期値を設定する
ためのコードを生成する(ステップS206)。そし
て、ステップS203に戻る。When it is determined that the statement is an external variable definition statement,
External variable and register information output code generation means 104
12 registers the name of the external variable in the variable column of the reference frequency storage area 302 at the time of execution by the program execution unit 40, initializes the corresponding reference frequency column to “0”,
A code for setting an initial value of the external variable in a corresponding initial value column is generated (step S206). Then, the process returns to step S203.
【0052】一方、ステップS205で外部変数定義文
でないと判定した場合は、外部変数およびレジスタ情報
出力コード生成手段10412は、さらに当該読み出し
た行が外部変数参照文であるかどうかを判定する(ステ
ップS207)。ここで、外部変数参照文でもないと判
定した場合には、ステップS209の処理に進む。On the other hand, if it is determined in step S205 that the statement is not an external variable definition statement, the external variable and register information output code generation means 10412 further determines whether the read line is an external variable reference statement (step S205). S207). If it is determined that the sentence is not an external variable reference statement, the process proceeds to step S209.
【0053】一方、ステップS207で外部変数参照文
であると判定した場合には、外部変数およびレジスタ情
報出力コード生成手段10412は、参照頻度記憶領域
302の当該外部変数に対応する参照回数の欄を“1”
だけ加算するためのコードを生成する(ステップS20
8)。そして、ステップS209の処理に進む。On the other hand, if it is determined in step S 207 that the sentence is an external variable reference sentence, the external variable and register information output code generating means 10412 sets the reference frequency column of the reference frequency storage area 302 for the external variable. “1”
Is generated (step S20).
8). Then, the process proceeds to step S209.
【0054】ステップS209では、外部変数およびレ
ジスタ情報出力コード生成手段10412は、さらに読
み出した当該行がレジスタを使用するコード(変数の参
照以外の場合も含む)を生成するものであるかどうかを
判定する。レジスタを使用するコードを生成するもので
ないと判定したときはステップS203の処理に戻り、
レジスタを使用するコードを生成するものであると判定
したときはステップS210の処理に進む。In step S209, the external variable and register information output code generation means 10412 determines whether or not the read out line generates a code that uses a register (including a case other than the reference to a variable). I do. If it is determined that the code using the register is not generated, the process returns to step S203, and
If it is determined that a code using a register is to be generated, the process proceeds to step S210.
【0055】ステップS210では、外部変数およびレ
ジスタ情報出力コード生成手段10412は、レジスタ
使用管理領域302の当該使用するレジスタに対応する
使用フラグの欄を“1”とするためのコードを生成す
る。そして、ステップS203の処理に戻る。In step S 210, the external variable and register information output code generation means 10412 generates a code for setting the use flag column corresponding to the register to be used in the register use management area 302 to “1”. Then, the process returns to step S203.
【0056】上記したようなステップS204からS2
10の処理を繰り返し、ステップS203において最終
的に中間ファイル202が終了したと判定すれば、この
フローチャートの処理を終了する。Steps S204 to S2 as described above
If the process of step 10 is repeated and it is finally determined in step S203 that the intermediate file 202 has ended, the process of this flowchart ends.
【0057】図5は、未使用レジスタ外部変数割り当て
手段10413の処理を示すフローチャートである。処
理が開始すると、未使用レジスタ外部変数割り当て手段
10413は、1回目の翻訳処理に従って得られた実行
形式のプログラム205の実行結果から、レジスタ使用
管理領域301に管理されるレジスタに未使用レジスタ
があり、且つ外部変数に割り当てられてないかどうかを
判定する(ステップS301)。FIG. 5 is a flowchart showing the processing of the unused register external variable allocation means 10413. When the process starts, the unused register external variable allocating unit 10413 determines that there is an unused register in the register managed in the register use management area 301 based on the execution result of the executable program 205 obtained according to the first translation process. And it is determined whether or not it is assigned to an external variable (step S301).
【0058】未使用レジスタがあり、且つ外部変数に割
り当てられていないと判定した場合には、未使用レジス
タ外部変数割り当て手段10413は、参照頻度記憶領
域302において参照回数の多い変数から順にレジスタ
を割り当て、割り当てレジスタの欄に登録する。このと
き、割り当てを行ったレジスタに関するレジスタ使用管
理領域301の使用フラグをセットする(ステップS3
02)。そして、このフローチャートの処理を終了す
る。If it is determined that there is an unused register and it is not assigned to an external variable, the unused register external variable allocating unit 10413 allocates the register in the reference frequency storage area 302 in order from the variable having the largest number of references. Registered in the column of the allocation register. At this time, the use flag of the register use management area 301 for the assigned register is set (step S3).
02). Then, the process of this flowchart ends.
【0059】一方、未使用レジスタがなく、および/ま
たは外部変数に割り当てられていないと判定した場合に
は、そのままこのフローチャートの処理を終了する。On the other hand, when it is determined that there is no unused register and / or that the unused register is not assigned to an external variable, the processing of this flowchart is terminated.
【0060】図6は、未使用レジスタ外部変数割り当て
コード生成手段10414の処理を示すフローチャート
である。未使用レジスタ外部変数割り当てコード生成手
段10414は、最適化手段103の処理結果である中
間ファイル202がすべて終了したかどうかを判定する
(ステップS401)。FIG. 6 is a flowchart showing the processing of the unused register external variable assignment code generation means 10414. The unused register external variable allocation code generation unit 10414 determines whether or not all the intermediate files 202 as the processing results of the optimization unit 103 have been completed (step S401).
【0061】一方、中間ファイル202がまだ終了して
いないと判定すれば、未使用レジスタ外部変数割り当て
コード生成手段10414は、最適化手段103の処理
結果である中間ファイル202から1行分を読み出す
(ステップS402)。次に、未使用レジスタ外部変数
割り当てコード生成手段10414は、読み出した当該
行がmain関数の先頭のコードを生成するものである
かどうかを判定する(ステップS403)。On the other hand, if it is determined that the intermediate file 202 has not been completed, the unused register external variable assignment code generation means 10414 reads one line from the intermediate file 202 which is the processing result of the optimization means 103 ( Step S402). Next, the unused register external variable assignment code generation unit 10414 determines whether or not the read out line generates the head code of the main function (step S403).
【0062】main関数の先頭のコードを生成するも
のであると判定した場合には、未使用レジスタ外部変数
割り当てコード生成手段10414は、参照頻度記憶領
域302を参照して、外部変数を割り当てたレジスタに
対して初期値をロードするためのコードを生成する(ス
テップS404)。そして、ステップS401の処理に
戻る。If it is determined that the code at the head of the main function is to be generated, the unused register external variable allocation code generation means 10414 refers to the reference frequency storage area 302 to determine the register to which the external variable has been allocated. Then, a code for loading an initial value is generated (step S404). Then, the process returns to step S401.
【0063】一方、ステップS403でmain関数の
先頭のコードを生成するものでないと判定した場合に
は、未使用レジスタ外部変数割り当てコード生成手段1
0414は、ステップS402で読み出した当該行が割
り込み関数の先頭のコードを生成するものであるかどう
かどうかをさらに判定する(ステップS405)。On the other hand, if it is determined in step S403 that the first code of the main function is not to be generated, the unused register external variable allocation code generation means 1
The step 0414 further determines whether or not the line read in the step S402 is for generating the head code of the interrupt function (step S405).
【0064】割り込み関数の先頭のコードを生成するも
のであると判定した場合には、未使用レジスタ外部変数
割り当てコード生成手段10414は、外部変数に割り
当てたレジスタを割り込み処理の際の退避レジスタ群か
ら除くためのコードを生成する(ステップS406)。
そして、ステップS401の処理に戻る。If it is determined that the code at the head of the interrupt function is to be generated, the unused register external variable allocation code generation means 10414 transfers the register allocated to the external variable from the save register group for interrupt processing. A code to be removed is generated (step S406).
Then, the process returns to step S401.
【0065】一方、ステップS405で割り込み関数の
先頭のコードを生成するものでないと判定した場合に
は、未使用レジスタ外部変数割り当てコード生成手段1
0414は、ステップS402で読み出した当該行が割
り込み関数の終わりのコードを生成するものであるかど
うかをさらに判定する(ステップS407)。On the other hand, if it is determined in step S405 that the first code of the interrupt function is not to be generated, the unused register external variable allocation code generation means 1
In step S414, it is further determined whether or not the line read in step S402 is to generate a code at the end of the interrupt function (step S407).
【0066】割り込み関数の終わりのコードを生成する
ものであると判定した場合には、未使用レジスタ外部変
数割り当てコード生成手段10414は、外部変数に割
り当てたレジスタを割り込み処理から復帰する際の退避
レジスタ群から除くためのコードを生成する(ステップ
S408)。そして、ステップS401の処理に戻る。If it is determined that the code at the end of the interrupt function is to be generated, the unused register external variable allocation code generation means 10414 saves the register allocated to the external variable when returning from interrupt processing. A code to be removed from the group is generated (step S408). Then, the process returns to step S401.
【0067】一方、ステップS407で割り込み関数の
終わりのコードを生成するものでないと判定した場合に
は、未使用レジスタ外部変数割り当てコード生成手段1
0414は、ステップS402で読み出した当該行がレ
ジスタを割り当てた外部変数に対して参照を行うもので
あるかどうかを判定する(ステップS409)。レジス
タを割り当てた外部変数に対して参照を行うものでない
と判定したときは、そのままステップS401の処理に
戻る。On the other hand, if it is determined in step S407 that the code at the end of the interrupt function is not to be generated, the unused register external variable allocation code generation means 1
In step S414, it is determined whether the row read in step S402 refers to an external variable to which a register is assigned (step S409). If it is determined that reference is not made to the external variable to which the register is assigned, the process returns to step S401.
【0068】一方、レジスタを割り当てた外部変数に対
して参照を行うものであると判定したときは、未使用レ
ジスタ外部変数割り当てコード生成手段10414は、
参照頻度記憶領域302を参照して、当該レジスタを使
用して外部変数を参照するためのコードを生成する(ス
テップS410)。そして、ステップS401の処理に
戻る。On the other hand, if it is determined that the reference is made to the external variable to which the register is allocated, the unused register external variable allocation code generation means 10414 generates
With reference to the reference frequency storage area 302, a code for referring to an external variable using the register is generated (step S410). Then, the process returns to step S401.
【0069】そして、ステップS402〜S410の処
理を繰り返し、ステップS401で最終的に中間ファイ
ル202が終了したと判定した場合には、このフローチ
ャートの処理を終了する。Then, the processing of steps S402 to S410 is repeated, and when it is determined in step S401 that the intermediate file 202 is finally completed, the processing of this flowchart is completed.
【0070】以下、この実施の形態にかかるコンパイラ
10によって、高級言語で記述されたソースプログラム
201から第2アセンブラプログラム202が生成され
るまでの動作を、具体例に従って説明する。ここでは、
ソースプログラム201として、図7、図8に示すC言
語で記述されたプログラムを例とする。ここで、図9、
図10は、1回目の翻訳処理で得られる第1アセンブラ
プログラム201(従来技術と同じ)、図13、図14
は、2回目の翻訳処理で得られる第2アセンブラプログ
ラム202を示している。また、図11、図12は、そ
れぞれ1回目の翻訳処理で得られた第1アセンブラプロ
グラム203をアセンブル、リンクして実行したときの
レジスタ使用管理領域301と参照頻度記憶領域302
の状態遷移を示している。Hereinafter, the operation of the compiler 10 according to this embodiment until the second assembler program 202 is generated from the source program 201 described in a high-level language will be described with reference to a specific example. here,
As the source program 201, a program described in C language shown in FIGS. 7 and 8 is taken as an example. Here, FIG.
FIG. 10 shows a first assembler program 201 (same as the prior art) obtained in the first translation process, and FIGS.
Indicates a second assembler program 202 obtained in the second translation process. FIGS. 11 and 12 show a register use management area 301 and a reference frequency storage area 302 when the first assembler program 203 obtained in the first translation process is assembled and linked and executed.
3 shows the state transition.
【0071】図7で示されるソースプログラムa.cを
コンパイラ10に入力すると、字句解析手段101、構
文解析手段102、最適化手段103で従来技術と同等
の処理を行ない、その結果を中間ファイル201として
出力する。次に、コード生成制御手段10411に制御
が移り、図3のS101の判定処理の結果によりステッ
プS102の処理が行われ、外部変数およびレジスタ情
報出力コード生成手段10412に制御が移る。Source program a. Shown in FIG. When c is input to the compiler 10, the lexical analysis means 101, the syntax analysis means 102, and the optimization means 103 perform the same processing as in the prior art, and output the result as an intermediate file 201. Next, control is transferred to the code generation control unit 10411, the process of step S102 is performed based on the result of the determination process of S101 in FIG. 3, and control is transferred to the external variable and register information output code generation unit 10412.
【0072】外部変数およびレジスタ情報出力コード生
成手段10412の処理では、mざう、図4のステップ
S201の判定処理の結果により、ステップS202の
処理が行われ、レジスタ使用管理領域301、参照頻度
記憶領域302を確保し、初期化するコードが生成され
る。In the processing of the external variable and register information output code generation means 10412, the processing of step S202 is performed according to the result of the determination processing of step S201 in FIG. 4, and the register use management area 301, the reference frequency storage area A code to secure and initialize 302 is generated.
【0073】図7のソースプログラムの1行目では、ス
テップS203、S204、S205、S206の処理
により、参照頻度記憶領域302に変数の初期値を登録
するためのコードが生成される。図7のソースプログラ
ムの3、5、6、7、8、10、11行目では、それぞ
れステップS203、S204、S205、S207、
S209の処理が行われる。In the first line of the source program in FIG. 7, a code for registering an initial value of a variable in the reference frequency storage area 302 is generated by the processing of steps S203, S204, S205, and S206. In lines 3, 5, 6, 7, 8, 10, and 11 of the source program in FIG. 7, steps S203, S204, S205, S207,
The process of S209 is performed.
【0074】図7のソースプログラムの12、13、1
4行目では、それぞれステップS203、S204、S
205、S207、S208、S209、S210の処
理が行われ、参照頻度記憶領域302の参照回数を加算
するためのコード、及びレジスタ使用管理領域301の
使用フラグを“1”とするためのコードが生成される。
図7のソースプログラムの15、16行目では、それぞ
れステップS203、S204、S205、S207、
S209の処理が行われる。そして、最後にステップS
203の処理で中間ファイル202の終了を認識して終
了し、コード出力手段10401から図9に示す第1ア
センブラプログラム203を出力する。In the source program shown in FIG.
In the fourth line, steps S203, S204, S
205, S207, S208, S209, and S210 are performed, and a code for adding the number of times of reference in the reference frequency storage area 302 and a code for setting the use flag of the register use management area 301 to "1" are generated. Is done.
In lines 15 and 16 of the source program in FIG. 7, steps S203, S204, S205, S207,
The process of S209 is performed. And finally, step S
In the processing of 203, the end of the intermediate file 202 is recognized and the processing is ended, and the code output means 10401 outputs the first assembler program 203 shown in FIG.
【0075】次に、図8で示されるソースプログラム
b.cをコンパイラ10に入力すると、字句解析手段1
01、構文解析手段102、最適化手段103で従来技
術と同等の処理を行ない、その結果を中間ファイル20
2として出力する。次に、コード生成制御手段1041
1に制御が移り、図3のS101の判定処理の結果によ
りステップS102の処理が行われ、外部変数およびレ
ジスタ情報出力コード生成手段10412に制御が移
る。Next, the source program b. When c is input to the compiler 10, the lexical analysis means 1
01, the parsing means 102 and the optimizing means 103 perform the same processing as in the prior art, and
Output as 2. Next, code generation control means 1041
1 and the process of step S102 is performed based on the result of the determination process of S101 in FIG. 3, and the control is shifted to the external variable and register information output code generation unit 10412.
【0076】外部変数およびレジスタ情報出力コード生
成手段10412では、図4のステップS201の判定
処理においてすでにレジスタ使用管理領域301および
参照頻度記憶領域302を確保するコードを生成してい
ると判定されるため、そのままステップS203以降の
処理に進む。The external variable and register information output code generation means 10412 determines that the code for securing the register use management area 301 and the reference frequency storage area 302 has already been generated in the determination processing of step S201 in FIG. Then, the process directly proceeds to the processing after step S203.
【0077】図8のソースプログラムの1、3、6、7
行目では、それぞれステップS203、S204、S2
05、S207、S209の処理が行われる。図8のソ
ースプログラムの8、9行目では、それぞれステップS
203、S204、S205、S207、S208、S
209、S210の処理が行われ、参照頻度記憶領域3
02の参照回数を加算するためのコード、及びレジスタ
使用管理領域301の使用フラグを“1”とするための
コードが生成される。The source programs 1, 3, 6, and 7 in FIG.
In the row, steps S203, S204, S2
05, S207, and S209 are performed. In lines 8 and 9 of the source program in FIG.
203, S204, S205, S207, S208, S
209 and S210 are performed, and the reference frequency storage area 3
A code for adding the reference number 02 and a code for setting the use flag of the register use management area 301 to “1” are generated.
【0078】図8のソースプログラムの10、12、1
3、14、15行目では、それぞれステップS203、
S204、S205、S207、S209の処理が行わ
れる。そして、最後にステップS203の処理で中間フ
ァイル202の終了を認識して終了し、コード出力手段
10401から図10に示す第1アセンブラプログラム
203を出力する。The source program 10, 12, 1
In lines 3, 14, and 15, steps S203,
Steps S204, S205, S207, and S209 are performed. Finally, the process of step S203 recognizes the end of the intermediate file 202, ends the process, and outputs the first assembler program 203 shown in FIG. 10 from the code output unit 10401.
【0079】以上述べた処理で得られた図9に示す第1
アセンブラプログラムa.sと図10に示す第1アセン
ブラプログラムb.sとを、アセンブル、リンクして得
られた実行形式のプログラム205を実行することによ
り、図3におけるレジスタ使用管理領域301、及び参
照頻度記憶領域302が生成される。次に、実行形式の
プログラム205の実行時における各生成領域の状態遷
移について述べる。なお、実行時に割り込みは起こら
ず、割り込み関数wariは実行しないこととする。The first data shown in FIG.
Assembler program a. s and the first assembler program b. By executing the executable program 205 obtained by assembling and linking s with the s, the register use management area 301 and the reference frequency storage area 302 in FIG. 3 are generated. Next, the state transition of each generation area when the executable program 205 is executed will be described. Note that no interruption occurs during execution, and the interruption function wari is not executed.
【0080】プログラムはmain関数から始まり、図
9のオブジェクトプログラムの22行目において、外部
変数およびレジスタ情報出力コード生成手段10412
によって生成されたコードから、レジスタ使用管理領域
301及び参照頻度記憶領域302が確保、初期化され
る。ここで、レジスタ使用管理領域301の状態遷移は
図11(a)に、参照頻度記憶領域302の状態遷移は
図12(a)となる。The program starts with a main function. At line 22 of the object program in FIG. 9, an external variable and register information output code generation means 10412
The register use management area 301 and the reference frequency storage area 302 are secured and initialized from the code generated by the above. Here, the state transition of the register use management area 301 is as shown in FIG. 11A, and the state transition of the reference frequency storage area 302 is as shown in FIG.
【0081】次に、図9のオブジェクトプログラムの2
4行目の関数コールで関数func1に処理が移る。f
unc1では、図9における36行目から39行目の処
理であり、レジスタ$2と$8とを使用し、変数aを2
回、変数bを1回参照している。このため、外部変数お
よびレジスタ情報出力コード生成手段10412により
生成されたコードにより、レジスタ使用管理領域301
の状態遷移は図11(b)に、参照頻度記憶領域302
の状態遷移は図12(b)となる。Next, 2 of the object program shown in FIG.
The processing moves to the function func1 by the function call on the fourth line. f
In unc1, the processing from the 36th line to the 39th line in FIG. 9 is performed, using the registers # 2 and # 8 and setting the variable a to 2
Time, the variable b is referred to once. For this reason, the code generated by the external variable and the register information output code generation unit 10412 is used by the register use management area 301
11 (b) shows the state transition of the reference frequency storage area 302.
FIG. 12B shows the state transition of FIG.
【0082】次に、図9のオブジェクトプログラムの4
1行目から44行目の処理では、レジスタ$9と$10
を使用し、変数cを1回、変数dを1回、変数eを1回
参照している。このため、外部変数およびレジスタ情報
出力コード生成手段10412により生成されたコード
により、レジスタ使用管理領域301の状態遷移は図1
1(c)、参照頻度記憶領域302の状態遷移は図12
(c)となる。Next, 4 of the object program shown in FIG.
In the processing from the first line to the 44th line, the registers $ 9 and $ 10
Are used to refer to the variable c once, the variable d once, and the variable e once. For this reason, the state transition of the register use management area 301 is controlled by the external variable and the code generated by the register information output code generation unit 10412 in FIG.
1 (c), the state transition of the reference frequency storage area 302 is shown in FIG.
(C).
【0083】次に、図9のオブジェクトプログラムの4
6行目から49行目の処理では、レジスタ$11と$1
2を使用し、変数fを1回、変数gを1回、変数hを1
回参照している。このため、外部変数およびレジスタ情
報出力コード生成手段10412により生成されたコー
ドにより、レジスタ使用管理領域301の状態遷移は図
11(d)、参照頻度記憶領域302の状態遷移は図1
2(d)となる。Next, 4 of the object program in FIG.
In the processing from the sixth line to the 49th line, the registers # 11 and # 1
2, variable f once, variable g once, and variable h 1
Times referenced. Therefore, according to the external variable and the code generated by the register information output code generation unit 10412, the state transition of the register use management area 301 is shown in FIG. 11D, and the state transition of the reference frequency storage area 302 is shown in FIG.
2 (d).
【0084】次に、図9のオブジェクトプログラムの5
1行目の関数コールで関数func2に処理が移る。f
unc2の処理において、図10のオブジェクトプログ
ラムの11行目から14行目の処理でレジスタ$2と$
8を使用し、変数aを2回、変数fを1回参照してい
る。このため、外部変数およびレジスタ情報出力コード
生成手段10412により生成されたコードにより、レ
ジスタ使用管理領域301の状態遷移は図11(d)か
ら変わらず、参照頻度記憶領域302の状態遷移は図1
2(e)となる。Next, 5 of the object program in FIG.
The processing shifts to the function func2 by the function call on the first line. f
In the processing of unc2, the registers # 2 and # 2 are executed in the processing of the eleventh to fourteenth lines of the object program in FIG.
8, the variable a is referred to twice and the variable f is referred to once. For this reason, the state transition of the register use management area 301 does not change from FIG. 11D and the state transition of the reference frequency storage area 302 changes according to the code generated by the external variable and the register information output code generation unit 10412 in FIG.
2 (e).
【0085】次に、図10のオブジェクトプログラムの
16行目から21行目の処理でレジスタ$9と$10と
$11を使用し、変数eを2回、変数bを1回、変数g
を1回参照している。このため、外部変数およびレジス
タ情報出力コード生成手段10412により生成された
コードによりレジスタ使用管理領域301の状態遷移は
図11(d)から変わらず、参照頻度記憶領域302の
状態遷移は図12(f)となる。Next, in the processing from the 16th line to the 21st line of the object program in FIG. 10, the registers e9, e10, and e11 are used, the variable e is set twice, the variable b is set once, and the variable g is set.
Is referenced once. For this reason, the state transition of the register use management area 301 is not changed from that of FIG. 11D by the external variable and the code generated by the register information output code generation unit 10412, and the state transition of the reference frequency storage area 302 is the state transition of FIG. ).
【0086】次に、図10のオブジェクトプログラムの
23行目の処理で、関数func2の呼出し側に戻る。
そして、図9のオブジェクトプログラムの55行目の処
理で関数func1から呼出し側に戻る。さらに、図9
のオブジェクトプログラムの28行目の処理で関数ma
inの呼出し側であるスタートアップルーチンに戻り、
処理を終了する。Next, the process returns to the calling side of the function func2 in the processing of the 23rd line of the object program in FIG.
Then, the function func1 returns to the calling side in the processing of the 55th line of the object program in FIG. Further, FIG.
Function ma in the processing of line 28 of the object program
Return to the startup routine that is the caller of in,
The process ends.
【0087】2回目の翻訳処理では、1回目の翻訳処理
で得られた図9、図10のオブジェクトプログラムをア
センブル、リンクすることにより得られた実行形式のプ
ログラムを実行することで得られたレジスタ使用管理領
域301および参照頻度記憶領域302をコンパイラに
入力する。その後、まず、1回目の翻訳処理で得られた
図7に示すソースプログラムa.cに対する中間ファイ
ル202に対し処理を行なう。In the second translation process, a register obtained by executing an executable program obtained by assembling and linking the object programs of FIGS. 9 and 10 obtained in the first translation process. The use management area 301 and the reference frequency storage area 302 are input to the compiler. After that, first, the source program a. Obtained in the first translation process shown in FIG. The process is performed on the intermediate file 202 for c.
【0088】コード生成制御手段10411は、図3の
ステップS101の判定処理の結果によりステップS1
03を行ない、未使用レジスタ外部変数割り当て手段1
0413に制御を移す。未使用レジスタ外部変数割り当
て手段10413は、図5のステップS301の判定処
理にの結果により、ステップS302の処理を実行す
る。The code generation control means 10411 determines in step S1 based on the result of the determination processing in step S101 in FIG.
03, and unused register external variable allocating means 1
The control is transferred to 0413. The unused register external variable assignment unit 10413 executes the process of step S302 based on the result of the determination process of step S301 in FIG.
【0089】この時点でのレジスタ使用管理領域301
は図11(d)の状態であるため、未使用レジスタ外部
変数割り当て手段10413は、レジスタ$13と$1
4と$15を未使用レジスタと認識する。また、この時
点での参照頻度記憶領域302は図12(g)の状態で
あるため、未使用レジスタ外部変数割り当て手段104
13は、参照回数の多い変数をa、e、bに対してレジ
スタ$13と$14と$15をそれぞれ割り当て、参照
頻度記憶領域302を図12(h)の状態とする。変数
bは、変数f、gと参照回数が同じであるが、この場合
には、どの変数にレジスタを割り当てても同じ効果が得
られるので、本例では一例として変数bに割り当てるも
のとする。The register use management area 301 at this point
Is in the state of FIG. 11D, the unused register external variable allocating means 10413 stores the registers # 13 and # 1
4 and $ 15 are recognized as unused registers. Further, since the reference frequency storage area 302 at this point is in the state shown in FIG.
Reference numeral 13 assigns registers # 13, # 14, and # 15 to variables a, e, and b with a large number of references, respectively, and sets the reference frequency storage area 302 to the state shown in FIG. The variable b has the same number of references as the variables f and g. In this case, the same effect can be obtained by allocating a register to any variable. Therefore, in this example, the variable b is allocated to the variable b as an example.
【0090】次に、コード生成制御手段10411に処
理が戻り、図3のステップS104の処理を行って、未
使用レジスタ外部変数割り当てコード生成手段1041
4に制御を移す。Next, the process returns to the code generation control means 10411, and performs the processing of step S104 in FIG.
Control is transferred to 4.
【0091】未使用レジスタ外部変数割り当てコード生
成手段10414では、図7のステップS401の判定
処理の結果により、ステップS402が実行される。次
に、図9のオブジェクトプログラムの20行目でステッ
プS403、S404の処理が行われ、図13のオブジ
ェクトプログラムの18、19、20行目のコードが生
成される。以後、判定処理に適合しない行に関して、未
使用レジスタ外部変数割り当てコード生成手段1041
4は、ステップS403、S405、S407、S40
9、S401、S402の処理が繰り返される。In the unused register external variable assignment code generation means 10414, step S402 is executed based on the result of the determination processing in step S401 in FIG. Next, the processing of steps S403 and S404 is performed on the twentieth line of the object program in FIG. 9, and the codes on lines 18, 19 and 20 of the object program in FIG. 13 are generated. Thereafter, for a row that does not conform to the determination processing, the unused register external variable assignment code generation means 1041
4 corresponds to steps S403, S405, S407, S40
9, the processing of S401 and S402 is repeated.
【0092】次に、図9のオブジェクトプログラムの3
6行目から49行目でステップS409、S410の処
理が行われ、図13のオブジェクトプログラムの33行
目から42行目のコードが生成される。未使用レジスタ
外部変数割り当てコード生成手段10414は、最後に
ステップS401の処理で中間ファイルの終了を認識し
て終了し、コード出力手段10401から図13に示す
アセンブラコードを出力する。Next, 3 of the object program shown in FIG.
The processes of steps S409 and S410 are performed on the sixth to 49th lines, and the codes on the 33rd to 42th lines of the object program in FIG. 13 are generated. The unused register external variable assignment code generation means 10414 recognizes the end of the intermediate file in the process of step S401 and ends the processing, and outputs the assembler code shown in FIG. 13 from the code output means 10401.
【0093】次に、1回目の翻訳処理で得られた図8に
示すソースプログラムb.cに対する中間ファイル20
2に対し処理を行なう。まず、コード生成制御手段10
411は、図3のステップS101の判定処理の結果に
よりステップS103を行ない、未使用レジスタ外部変
数割り当て手段10413に制御を移す。ここでは、既
に未使用レジスタを外部変数に割り当て済みのため、本
手段を終了し、コード生成制御手段10411に処理が
戻り、図3のステップS104の処理を行った結果、未
使用レジスタ外部変数割り当てコード生成手段1041
4に制御が移る。Next, the source program b. Shown in FIG. intermediate file 20 for c
2 is processed. First, the code generation control means 10
Step 411 performs step S103 according to the result of the determination processing in step S101 in FIG. 3, and transfers control to the unused register external variable allocating unit 10413. Here, since the unused registers have already been allocated to the external variables, this unit is terminated, the processing returns to the code generation control unit 10411, and the processing of step S104 in FIG. Code generation means 1041
The control moves to 4.
【0094】未使用レジスタ外部変数割り当てコード生
成手段10414では、図6のステップS401の判定
処理の結果によりステップS402の処理が実行され
る。次に、図9のアセンブラプログラムの20行目でス
テップS403、S404の処理が行われ、図13のア
センブラプログラムの18、19、20行目のコードが
生成される。以後、判定処理に適合しない行に関して
は、ステップS403、S405、S407、S40
9、S401、S402の処理が繰り返される。The unused register external variable assignment code generation means 10414 executes the process of step S402 according to the result of the determination process of step S401 in FIG. Next, the processes of steps S403 and S404 are performed on the twentieth line of the assembler program in FIG. 9, and the codes on lines 18, 19, and 20 of the assembler program in FIG. 13 are generated. Thereafter, steps S403, S405, S407, and S40 are performed for rows that do not conform to the determination processing.
9, the processing of S401 and S402 is repeated.
【0095】次に、図10のアセンブラプログラムの1
1行目から21行目でステップS409、S410の処
理が行われ、図14の8行目から13行目のコードが生
成される。次に、図10のアセンブラプログラムの29
行目から38行目でステップS405、S406の処理
が行われ、レジスタ$13と$14と$15を退避レジ
スタ群から除いて、図14のアセンブラプログラムの2
1行目から27行目のコードが生成される。Next, one of the assembler programs shown in FIG.
The processing of steps S409 and S410 is performed on the first to 21st lines, and the codes on the 8th to 13th lines in FIG. 14 are generated. Next, 29 of the assembler program of FIG.
The processing of steps S405 and S406 is performed from the 38th line to the 38th line, and the registers # 13, # 14, and # 15 are excluded from the save register group, and the processes of the assembler program 2 shown in FIG.
The code from the first line to the 27th line is generated.
【0096】次に、図10のアセンブラプログラムの4
4行目から53行目でステップS407、S408の処
理が行われ、レジスタ$13と$14と$15を復帰レ
ジスタ群から除いて、図14の33行目から39行目の
コードが生成される。次に、図10のアセンブラプログ
ラムの44行目から53行目でステップS407、S4
08の処理が行われ、図14の28行目から32行目の
コードが生成される。次に、図10のアセンブラプログ
ラムの29行目から38行目でステップS405、S4
06の処理が行われ、レジスタ$13と$14と$15
を退避レジスタ群から除いて、図14の21行目から2
7行目のコードが生成される。Next, 4 of the assembler program in FIG.
The processing of steps S407 and S408 is performed on the fourth to 53rd lines, and the registers # 13, # 14, and # 15 are excluded from the return register group, and the codes on the 33rd to 39th lines in FIG. 14 are generated. You. Next, steps S407 and S4 are executed on lines 44 to 53 of the assembler program in FIG.
The process 08 is performed, and the codes on the 28th line to the 32nd line in FIG. 14 are generated. Next, steps S405 and S4 are executed on lines 29 to 38 of the assembler program in FIG.
06, the registers # 13, # 14, and # 15
Are removed from the save register group, and 2 from line 21 in FIG.
The code on the seventh line is generated.
【0097】そして、未使用レジスタ外部変数割り当て
コード生成手段10414は、最後にステップS401
で中間ファイル201の終了を認識して終了し、コード
出力手段10401から図14に示すアセンブラプログ
ラムを出力する。Then, the unused register external variable assignment code generating means 10414 finally returns to step S401.
Then, the end of the intermediate file 201 is recognized, and the process ends. The code output unit 10401 outputs the assembler program shown in FIG.
【0098】以上のように図7、図8のソースプログラ
ムから生成した第1アセンブラプログラム203(図
9、図10:従来技術)に対する第2アセンブラプログ
ラム(図13、図14:本実施形態)でのデータ領域及
びコード領域の削減率を、図15に示す。この図から、
本実施形態では、メモリ領域の大幅な削減ができること
が分かる。また、この例とは異なる大規模のソースプロ
グラムに対しても、定量的に同等な削減効果が得られる
ことは、経験上予測することができる。As described above, the second assembler program (FIGS. 13 and 14: this embodiment) for the first assembler program 203 (FIGS. 9 and 10: prior art) generated from the source programs of FIGS. FIG. 15 shows the reduction rates of the data area and the code area. From this figure,
According to the present embodiment, it can be seen that the memory area can be significantly reduced. It can be empirically predicted that the same reduction effect can be quantitatively obtained even for a large-scale source program different from this example.
【0099】以上説明したように、この実施の形態にか
かるコンパイラ10では、外部変数およびレジスタ情報
出力コード生成手段10412が1回目の翻訳処理で生
成した第1アセンブラプログラム203をアセンブル、
リンクした実行形式のプログラム205を実行して、外
部変数にに割り当てることのできるレジスタを調べてレ
ジスタ使用管理領域301に登録している。As described above, in the compiler 10 according to the present embodiment, the external variable and register information output code generation means 10412 assembles the first assembler program 203 generated in the first translation processing.
By executing the linked executable program 205, a register that can be assigned to an external variable is checked and registered in the register use management area 301.
【0100】そして、未使用レジスタ外部変数割り当て
手段10413は、実行形式のプログラム205を実際
に実行した状態におけるレジスタ使用管理領域301で
使用フラグが“0”のレジスタを、参照頻度の多い外部
変数に割り当てている。こうして、未使用レジスタ外部
変数割り当てコード生成手段10414が参照頻度の高
い外部変数にレジスタを割り当ててコードを生成するこ
とができるため、第2のアセンブラプログラム204を
アセンブル、リンクした実行形式のプログラム206
は、コード効率がよく、その実行速度が速いものとな
る。Then, the unused register external variable allocating means 10413 converts the register whose use flag is “0” in the register use management area 301 in a state where the executable program 205 is actually executed into an external variable with a high frequency of reference. Have assigned. In this manner, the unused register external variable allocation code generation means 10414 can generate a code by allocating registers to external variables having a high reference frequency, so that the second assembler program 204 is assembled and linked to the executable program 206.
Is code efficient and runs faster.
【0101】また、この実施の形態にかかるコンパイラ
10では、外部変数およびレジスタ情報出力コード生成
手段10412による1回目の翻訳処理では外部変数以
外の変数にレジスタの割り当てを行い、外部変数に対す
るレジスタの割り当ては、2回目の翻訳処理で行うこと
にしている。このため、複数のソースプログラム201
のうちで互いに異なるもの同士での外部変数の参照につ
いても、同一のレジスタを割り当てることができるた
め、、第2のアセンブラプログラム204をアセンブ
ル、リンクした実行形式のプログラム206は、コード
効率がよく、その実行速度が速いものとなる。In the compiler 10 according to this embodiment, in the first translation processing by the external variable and register information output code generating means 10412, registers are allocated to variables other than external variables, and the register is allocated to external variables. Is performed in the second translation process. Therefore, a plurality of source programs 201
Since the same register can be assigned to the reference of an external variable between different ones, the executable program 206 in which the second assembler program 204 is assembled and linked has high code efficiency, Its execution speed is fast.
【0102】また、この実施の形態にかかるコンパイラ
10では、レジスタを割り当てる外部変数に初期値があ
る場合に、未使用レジスタ外部変数割り当てコード生成
手段10414が当該レジスタに初期値を設定するため
のコードを生成している。このため、外部変数を最初か
ら最後まで同一のレジスタに割り当てることが可能とな
り、この分だけメモリ領域に確保しなければならない外
部変数の参照のための領域を小さくすることができる。In the compiler 10 according to the present embodiment, when an external variable to be assigned to a register has an initial value, the unused register external variable assignment code generating means 10414 generates a code for setting the initial value to the register. Has been generated. Therefore, the external variables can be allocated to the same register from the beginning to the end, and the area for referencing the external variables, which must be secured in the memory area, can be reduced accordingly.
【0103】さらに、この実施の形態にかかるコンパイ
ラ10では、未使用レジスタ外部変数割り当てコード生
成手段10414は、割り込み関数で退避/復帰するレ
ジスタから外部変数に割り当てたレジスタを除いてい
る。これにより、第2のアセンブラプログラム204を
アセンブル、リンクした実行形式のプログラム206
は、割り込み処理時に退避/復帰しなければならないレ
ジスタの数が従来よりも少なくすることができるので、
コード効率がよく、その実行速度が速いものとなる。ま
た、レジスタの退避/復帰のためのメモリの領域も小さ
くすることができる。Further, in the compiler 10 according to the present embodiment, the unused register external variable assignment code generation means 10414 removes registers assigned to external variables from registers saved / restored by an interrupt function. Thus, the executable program 206 obtained by assembling and linking the second assembler program 204
Since the number of registers that must be saved / restored during interrupt processing can be reduced compared to the past,
The code efficiency is high and the execution speed is fast. Further, the area of a memory for saving / restoring registers can be reduced.
【0104】[第2の実施の形態]この実施の形態にか
かるコンパイラ10は、第1の実施の形態にかかるもの
とほぼ同じである。但し、この実施の形態では、図16
に示すように、レジスタ使用管理領域301が未使用の
レジスタに関する情報を1回目の翻訳処理において得て
レジスタ使用管理領域301を生成する。すなわち、こ
の実施の形態では、外部変数およびレジスタ情報出力コ
ード生成手段10412がレジスタ使用管理領域301
を生成する点において、第1の実施の形態のものと異な
る。[Second Embodiment] The compiler 10 according to this embodiment is almost the same as that according to the first embodiment. However, in this embodiment, FIG.
As shown in (1), the register use management area 301 obtains information on registers not used in the first translation processing to generate the register use management area 301. That is, in this embodiment, the external variable and register information output code generation means 10412
Is different from that of the first embodiment.
【0105】図17は、この実施の形態における外部変
数およびレジスタ情報出力コード生成手段1042の処
理を示すフローチャートである。この実施の形態では、
外部変数およびレジスタ情報出力コード生成手段104
12は、まず、レジスタ使用管理領域301がメモリ中
に確保されていないかどうかを判定する(ステップS5
01)。レジスタ使用管理領域301がメモリ中に確保
されていると判定したときは、ステップS503の処理
に進む。FIG. 17 is a flowchart showing the processing of the external variable and register information output code generating means 1042 in this embodiment. In this embodiment,
External variable and register information output code generation means 104
12 first determines whether or not the register use management area 301 is secured in the memory (step S5).
01). If it is determined that the register use management area 301 is secured in the memory, the process proceeds to step S503.
【0106】一方、レジスタ使用管理領域301がメモ
リ中に確保されていないと判定したときは、外部変数お
よびレジスタ情報出力コード生成手段10412は、レ
ジスタ使用管理領域301をメモリ中に確保し、さらに
レジスタ使用管理領域302のレジスタ名の欄に特殊レ
ジスタを除くすべてのレジスタの名称を登録する(ステ
ップS502)。そして、ステップS503の処理に進
む。On the other hand, when it is determined that the register use management area 301 is not secured in the memory, the external variable and register information output code generation means 10412 secures the register use management area 301 in the memory, The names of all registers other than special registers are registered in the register name column of the use management area 302 (step S502). Then, the process proceeds to step S503.
【0107】ステップS503からステップS509ま
での処理は、図4のステップS203からS209まで
の処理と同じである。The processing from step S503 to step S509 is the same as the processing from step S203 to S209 in FIG.
【0108】ステップS509においてレジスタを使用
するコードを生成するものであると判定したときは、外
部変数およびレジスタ情報出力コード生成手段1041
2は、レジスタ使用管理領域302の当該使用するレジ
スタに対応する使用フラグの欄を“1”とする(ステッ
プS510)。そして、ステップS503の処理に戻
る。If it is determined in step S509 that a code using a register is to be generated, an external variable and register information output code generating means 1041
2 sets “1” in the column of the use flag corresponding to the register to be used in the register use management area 302 (step S510). Then, the process returns to step S503.
【0109】以上説明したように、この実施の形態にか
かるコンパイラ10では、外部変数およびレジスタ情報
出力コード生成手段10412がレジスタ使用管理領域
301を確保し、特殊レジスタを除くすべてのレジスタ
の名称を登録すると共に、レジスタを使用するコードを
生成する場合には、当該使用するレジスタに対応する使
用フラグの欄を“1”に設定している。これにより、こ
の実施の形態にかかるコンパイラ10では、第1の実施
の形態での効果に加えて次のような効果を得ることがで
きる。As described above, in the compiler 10 according to this embodiment, the external variable and register information output code generation means 10412 secures the register use management area 301 and registers the names of all registers except special registers. In addition, when generating a code that uses a register, the use flag column corresponding to the register to be used is set to “1”. Thus, the compiler 10 according to this embodiment can obtain the following effects in addition to the effects of the first embodiment.
【0110】すなわち、ソースプログラム201によっ
ては、外部からの情報の入力や割り込みによって、実行
する度に動作が異なるものとなることがある。このよう
な場合、ある実行結果では未使用であったレジスタを別
の実行結果では使用する場合がある。しかし、この実施
の形態では、実行時に使用される可能性のあるレジスタ
に対応する使用フラグを、1回目の翻訳時にすべて
“1”にセットするため、外部変数に割り当てられたレ
ジスタが、プログラムの実行時に使用されて、不正な動
作が行われることがなくなる。That is, depending on the source program 201, the operation may be different each time the program is executed due to input of information from outside or interruption. In such a case, a register that has not been used in one execution result may be used in another execution result. However, in this embodiment, the use flags corresponding to the registers that may be used at the time of execution are all set to “1” during the first translation, so that the registers assigned to the external variables are Used at runtime to prevent unauthorized operation.
【0111】[実施の形態の変形]本発明は、上記の第
1、第2の実施の形態に限られず、種々の変形、応用が
可能である。以下、本発明に適用可能な上記の実施の形
態の変形態様について、説明する。[Modifications of Embodiment] The present invention is not limited to the above-described first and second embodiments, and various modifications and applications are possible. Hereinafter, modifications of the above-described embodiment applicable to the present invention will be described.
【0112】上記の第1、第2の実施の形態では、未使
用レジスタ外部変数割り当てコード生成手段10414
によって2回目の翻訳処理を行うときに、最初に入力し
たソースプログラム201から生成した中間ファイル2
02を利用していた。すなわち、1回目の翻訳処理と2
回目の翻訳処理とで同じ中間ファイル202を利用して
いた。しかしながら、2回目の翻訳処理を行う前に、コ
ンパイラ10にソースプログラム201を新たに入力し
て、1回目の翻訳処理を行う前と同様に中間ファイルを
生成するものとしてもよい。In the first and second embodiments, the unused register external variable assignment code generating means 10414 is used.
When the second translation processing is performed, the intermediate file 2 generated from the source program 201 input first is used.
02 was used. That is, the first translation processing and 2
The same intermediate file 202 was used in the second translation process. However, before the second translation process is performed, the source program 201 may be newly input to the compiler 10 and the intermediate file may be generated in the same manner as before the first translation process.
【0113】上記の第1、第2の実施の形態では、ソー
スプログラム201をコンパイラ10でコンパイルした
オブジェクトプログラムとしてアセンブラプログラムを
生成するものとし、生成されたアセンブラプログラムを
アセンブラ20を用いて機械語のコードに変換するもの
としていた。しかしながら、ソースプログラムからアセ
ンブラプログラムをコンパイルしたオブジェクトプログ
ラムとして、直接機械語のコードを生成するものとして
もよい。In the first and second embodiments, an assembler program is generated as an object program compiled from the source program 201 by the compiler 10, and the generated assembler program is converted into a machine language using the assembler 20. Was converted to code. However, a machine language code may be directly generated as an object program obtained by compiling an assembler program from a source program.
【0114】上記の第1、第2の実施の形態では、コン
パイラ10は、字句解析手段101、構文解析手段10
2、最適化手段103、及びコード生成手段1041で
構成されるものとしていた。しかしながら、最適化手段
103を有さず、ソースプログラムを字句解析、構文解
析しただけの中間ファイルに基づいてアセンブラコード
を生成する場合でも、コード生成手段1041に含まれ
る各手段が正しく動作することができる。In the first and second embodiments, the compiler 10 includes the lexical analyzer 101 and the syntax analyzer 10.
2, the optimization means 103 and the code generation means 1041. However, even when the assembler code is generated based on an intermediate file obtained by merely lexical analysis and syntax analysis of the source program without the optimization unit 103, each unit included in the code generation unit 1041 may operate correctly. it can.
【0115】上記の第1、第2の実施の形態では、コン
パイラ10は、メモリ上に記憶されたコンパイラプログ
ラムを実行するプロセッサが実現する機能として説明し
ていた。しかし、このようなコンパイラプログラムは、
磁気ディスク或いは光ディスクなどのコンピュータ読み
取り可能な記録媒体に格納して配布してもよい。さらに
は、ネットワーク上のサーバから当該ネットワークを介
して配信するものとしてもよい。In the first and second embodiments, the compiler 10 has been described as a function realized by a processor that executes a compiler program stored in a memory. However, such a compiler program
The program may be stored and distributed on a computer-readable recording medium such as a magnetic disk or an optical disk. Further, the information may be distributed from a server on a network via the network.
【0116】上記の第1、第2の実施の形態では、コン
パイラ10は、字句解析手段101、構文解析手段10
2、最適化手段103及びコード生成手段1041が一
体のものとして構成されるものとしていた。しかしなが
ら、字句解析手段101、構文解析手段102及び最適
化手段103は、従来のものと同じであるので、コード
生成手段1041のみのモジュールとして提供するよう
にしてもよい。In the first and second embodiments, the compiler 10 includes the lexical analyzer 101 and the syntax analyzer 10.
2. The optimization unit 103 and the code generation unit 1041 are configured as a single unit. However, since the lexical analysis means 101, the syntax analysis means 102, and the optimization means 103 are the same as the conventional ones, they may be provided as a module including only the code generation means 1041.
【0117】[0117]
【発明の効果】以上説明したように、本発明によれば、
コード効率のよい、すなわち実行速度が速いオブジェク
トプログラムを生成することができる。また、外部変数
を参照するための領域をメモリ内に確保しなくても済む
ようになるので、メモリの利用効率のよいオブジェクト
プログラムを生成することができる。As described above, according to the present invention,
It is possible to generate an object program with high code efficiency, that is, a high execution speed. Further, since it is not necessary to secure an area for referring to an external variable in the memory, it is possible to generate an object program with high memory use efficiency.
【図1】本発明の第1の実施の形態にかかるコンパイラ
を示す機能ブロック図である。FIG. 1 is a functional block diagram illustrating a compiler according to a first embodiment of the present invention.
【図2】本発明の第1の実施の形態において、ソースプ
ログラムから実行形式のプログラムを生成するまでの処
理を行うシステム全体を示す図である。FIG. 2 is a diagram illustrating an entire system that performs processing up to generation of an executable program from a source program in the first embodiment of the present invention.
【図3】図1のコード生成制御手段の処理を示すフロー
チャートである。FIG. 3 is a flowchart illustrating a process of a code generation control unit in FIG. 1;
【図4】図1の外部変数およびレジスタ情報出力コード
生成手段の処理を示すフローチャートである。FIG. 4 is a flowchart showing a process of an external variable and register information output code generation unit of FIG. 1;
【図5】未使用レジスタ外部変数割り当て手段の処理を
示すフローチャートである。FIG. 5 is a flowchart showing a process of an unused register external variable assignment unit.
【図6】未使用レジスタ外部変数割り当てコード生成手
段の処理を示すフローチャートである。FIG. 6 is a flowchart showing the processing of an unused register external variable assignment code generation means.
【図7】C言語で記述されたソースプログラムの例を示
す図である。FIG. 7 is a diagram showing an example of a source program described in C language.
【図8】C言語で記述されたソースプログラムの例を示
す図である。FIG. 8 is a diagram showing an example of a source program described in C language.
【図9】図7のソースプログラムから1回目の翻訳処理
で生成されたアセンブラコードを示す図である。FIG. 9 is a diagram showing assembler code generated in a first translation process from the source program of FIG. 7;
【図10】図8のソースプログラムから1回目の翻訳処
理で生成されたアセンブラコードを示す図である。FIG. 10 is a diagram showing assembler code generated in a first translation process from the source program of FIG. 8;
【図11】レジスタ使用管理領域の状態遷移を示す図で
ある。FIG. 11 is a diagram showing a state transition of a register use management area.
【図12】参照頻度記憶領域の状態遷移を示す図であ
る。FIG. 12 is a diagram showing a state transition of a reference frequency storage area.
【図13】図7のソースプログラムから2回目の翻訳処
理で生成されたアセンブラコードを示す図である。FIG. 13 is a diagram showing assembler code generated in a second translation process from the source program of FIG. 7;
【図14】図8のソースプログラムから2回目の翻訳処
理で生成されたアセンブラコードを示す図である。FIG. 14 is a diagram showing assembler code generated in a second translation process from the source program of FIG. 8;
【図15】本発明の第1の実施の形態にかかるコンパイ
ラによる効果を説明する図である。FIG. 15 is a diagram illustrating the effect of the compiler according to the first embodiment of the present invention.
【図16】本発明の第1の実施の形態において、ソース
プログラムから実行形式のプログラムを生成するまでの
処理を行うシステム全体を示す図である。FIG. 16 is a diagram illustrating an entire system that performs processing up to generation of an executable program from a source program in the first embodiment of the present invention.
【図17】本発明の第2の実施の形態における外部変数
およびレジスタ情報出力コード生成手段の処理を示すフ
ローチャートである。FIG. 17 is a flowchart illustrating processing of an external variable and register information output code generation unit according to the second embodiment of the present invention.
【図18】従来例にかかるコンパイラを示す機能ブロッ
ク図である。FIG. 18 is a functional block diagram showing a compiler according to a conventional example.
10 コンパイラ 101 字句解析手段 102 構文解析手段 103 最適化手段 1041 コード生成手段 10401 コード出力手段 10411 コード生成制御手段 10412 外部変数およびレジスタ情報出力コード生
成手段 10413 未使用レジスタ外部変数割り当て手段 10414 未使用レジスタ外部変数割り当てコード生
成手段 20 アセンブラ 30 リンカ 40 プログラム実行部 201 ソースプログラム 202 中間ファイル 203 第1アセンブラプログラム 204 第2アセンブラプログラム 205 実行形式のプログラム 206 実行形式のプログラム 301 レジスタ使用管理領域 302 参照頻度記憶領域DESCRIPTION OF SYMBOLS 10 Compiler 101 Lexical analysis means 102 Syntax analysis means 103 Optimization means 1041 Code generation means 10401 Code output means 10411 Code generation control means 10412 External variable and register information output code generation means 10413 Unused register external variable allocation means 10414 Unused register outside Variable assignment code generation means 20 Assembler 30 Linker 40 Program execution unit 201 Source program 202 Intermediate file 203 First assembler program 204 Second assembler program 205 Executable program 206 Executable program 301 Register use management area 302 Reference frequency storage area
Claims (16)
ースプログラムを構文解析した複数の中間ファイルに基
づいて、オブジェクトプログラムを生成するコンパイル
装置であって、 前記複数の中間ファイルに基づいて、前記外部変数を参
照するための領域をメモリに確保する複数の第1のオブ
ジェクトプログラムを生成する第1のオブジェクトプロ
グラム生成手段と、 前記オブジェクトプログラム生成手段が生成した複数の
第1のオブジェクトプログラムを結合した実行形式のプ
ログラムを実行した結果、参照回数が多い外部変数から
順に、他で使用されていないレジスタを割り当てるレジ
スタ割り当て手段と、 前記レジスタ割り当て手段によるレジスタの割り当てを
参照し、前記複数の中間ファイルに基づいて、レジスタ
が割り当てられた外部変数の参照を当該割り当てられた
レジスタを用いて行う複数の第2のオブジェクトプログ
ラムを生成する第2のオブジェクトプログラム生成手段
とを備えることを特徴とするコンパイル装置。1. A compiling device for generating an object program based on a plurality of intermediate files obtained by parsing a plurality of source programs including external variables referred to each other, wherein the compiling device generates the object program based on the plurality of intermediate files. A first object program generating means for generating a plurality of first object programs for securing an area for referring to an external variable in a memory; and a plurality of first object programs generated by the object program generating means. As a result of executing the program in the execution format, in order from the external variable having the largest number of references, register allocating means for allocating a register that is not otherwise used, and referring to the register allocation by the register allocating means, Based on the registers allocated Compiling device, characterized in that it comprises a second object program generating means for generating a plurality of second object program with reference to an external variable performed by using the register assigned the.
り当てる他で使用されていないレジスタは、前記実行形
式のプログラムを実行した結果により得られたものであ
ることを特徴とする請求項1に記載のコンパイル装置。2. The register according to claim 1, wherein the register that is not used except for assigning to an external variable by the register allocating means is obtained as a result of executing the program in the executable format. Compilation device.
段は、前記複数の第1、第2のオブジェクトプログラム
を結合した実行形式のプログラムが実行される装置に含
まれるレジスタと、各レジスタに対応付けてその使用状
況に関する情報を管理するレジスタ使用管理手段を前記
複数の第1のオブジェクトプログラムを結合した実行形
式のプログラムを実行するときに生成するためのコード
を生成する手段と、前記複数の第1のオブジェクトプロ
グラムを結合した実行形式のプログラムを実行してレジ
スタが使用されたときに当該使用されたレジスタに対応
する前記レジスタ使用管理手段内の使用状況を使用状態
とするコードを生成する手段とを含み、 前記レジスタ割り当て手段は、前記複数の第1のオブジ
ェクトプログラムを結合した実行形式のプログラムを実
行後に得られた前記レジスタ使用管理手段を参照して、
外部変数へレジスタを割り当てることを特徴とする請求
項2に記載のコンパイル装置。3. The method according to claim 1, wherein the first object program generating means includes a register included in a device for executing an executable program obtained by combining the plurality of first and second object programs, and a register associated with each register. Means for generating code for generating register use management means for managing information on the use status when executing an executable program in which the plurality of first object programs are combined; and Means for generating, when a register is used by executing a program in an executable form combined with an object program, a code for setting a use state in the register use management means corresponding to the used register to a use state. The register allocating unit executes the plurality of first object programs in combination Referring to the register use management means obtained after executing the program of the form,
3. The compiling device according to claim 2, wherein registers are allocated to external variables.
り当てる他で使用されていないレジスタは、前記複数の
第1のオブジェクトプログラム中で使用されているレジ
スタ以外のレジスタであることを特徴とする請求項1に
記載のコンパイル装置。4. The register that is not used in any other way than that the register allocating means allocates to an external variable is a register other than a register used in the plurality of first object programs. 2. The compiling device according to 1.
段は、前記複数の第1、第2のオブジェクトプログラム
を結合した実行形式のプログラムが実行される装置に含
まれる各レジスタに対応付けてその使用状況に関する情
報を管理するレジスタ使用管理手段を生成する手段と、
前記レジスタのいずれかを使用するコードを生成したと
きに当該使用されたレジスタに対応する前記レジスタ使
用管理手段内の使用状況を使用状態とする手段とを備え
ることを特徴とする請求項4に記載のコンパイル装置。5. A method according to claim 1, wherein said first object program generating means associates each of said plurality of first and second object programs with a register included in an apparatus for executing an executable program which is combined with said plurality of first and second object programs. Means for generating register use management means for managing information about
5. The apparatus according to claim 4, further comprising: a unit that sets a use state in the register use management unit corresponding to the used register when a code that uses any of the registers is generated. 6. Compilation device.
段は、各外部変数と対応付けて参照回数を記憶する参照
頻度記憶手段を前記複数の第1のオブジェクトプログラ
ムを結合した実行形式のプログラムを実行するときに生
成するためのコードを生成する手段と、前記複数の第1
のオブジェクトプログラムを結合した実行形式のプログ
ラムを実行して外部変数が参照さたときに当該参照され
た外部変数に対応する前記参照頻度記憶手段内の参照回
数を加算するコードを生成する手段とを含むことを特徴
とする請求項1乃至5のいずれか1項に記載のコンパイ
ル装置。6. The first object program generating means executes a program in an executable form in which the plurality of first object programs are combined with a reference frequency storing means for storing a reference count in association with each external variable. Means for generating code for generating, when the plurality of first
Means for executing a program in an executable form in which the object programs are combined to generate a code for adding a reference count in the reference frequency storage means corresponding to the external variable referred to when the external variable is referred to. The compiling device according to claim 1, wherein the compiling device includes a compiling device.
変数のそれぞれに対応付けてその初期値を記憶し、 前記第1のオブジェクトプログラム生成手段は、前記外
部変数の初期値を前記参照頻度記憶手段内に設定するコ
ードを生成する手段を含むことを特徴とする請求項6に
記載のコンパイル装置。7. The reference frequency storage means further stores an initial value in association with each of the external variables, and the first object program generating means stores the initial value of the external variable in the reference frequency. 7. The compiling apparatus according to claim 6, further comprising means for generating a code to be set in the means.
変数のそれぞれに対応して割り当てたレジスタに関する
情報を記憶し、 前記レジスタ割り当て手段は、前記複数の第1のオブジ
ェクトプログラムを結合した実行形式のプログラムを実
行した後の前記参照頻度記憶手段内の各外部変数の参照
回数に従ってレジスタの割り当てを行って、対応する外
部変数のレジスタに関する情報の欄に記憶させ、 前記第2のオブジェクトプログラム生成手段は、前記参
照頻度記憶手段を参照して、前記複数の第2のオブジェ
クトプログラムを生成することを特徴とする請求項6ま
たは7に記載のコンパイル装置。8. The reference frequency storage means further stores information on registers allocated corresponding to each of the external variables, and the register allocation means executes an executable form combining the plurality of first object programs. Register allocation is performed according to the reference count of each external variable in the reference frequency storage unit after executing the program, and stored in a column of information on the register of the corresponding external variable, the second object program generation unit 8. The compiling apparatus according to claim 6, wherein the generating unit generates the plurality of second object programs by referring to the reference frequency storage unit.
段は、前記レジスタ割り当て手段が外部変数に割り当て
たレジスタを、割り込み処理での退避及び復帰の対象と
なるレジスタから除外するためのコードを生成する手段
を含むことを特徴とする請求項1乃至8に記載のコンパ
イル装置。9. The second object program generating means generates code for excluding a register assigned to an external variable by the register allocating means from a register to be saved and restored in interrupt processing. 9. The compiling device according to claim 1, further comprising:
オブジェクトプログラム生成手段が前記複数の第1のオ
ブジェクトプログラムを生成する前と、前記第2のオブ
ジェクトプログラム生成手段が前記複数の第2のオブジ
ェクトプログラムを生成する前とにおいて、それぞれ別
々に生成されたものであることを特徴とする請求項1乃
至9のいずれか1項に記載のコンパイル装置。10. The plurality of intermediate files are generated before the first object program generating means generates the plurality of first object programs and when the second object program generating means generates the plurality of second object programs. 10. The compiling device according to claim 1, wherein the compiling device is separately generated before and before the object program is generated.
ソースプログラムを構文解析した複数の中間ファイルに
基づいて、オブジェクトプログラムを生成するコンパイ
ル方法であって、 前記複数の中間ファイルに基づいて、前記外部変数を参
照するための領域をメモリに確保する複数の第1のオブ
ジェクトプログラムを生成する第1のオブジェクトプロ
グラム生成ステップと、 前記オブジェクトプログラム生成ステップで生成した複
数の第1のオブジェクトプログラムを結合した実行形式
のプログラムを実行した結果、参照回数が多い外部変数
から順に、他で使用されていないレジスタを割り当てる
レジスタ割り当てステップと、 前記レジスタ割り当てステップにおけるレジスタの割り
当てを参照し、前記複数の中間ファイルに基づいて、レ
ジスタが割り当てられた外部変数の参照を当該割り当て
られたレジスタを用いて行う複数の第2のオブジェクト
プログラムを生成する第2のオブジェクトプログラム生
成ステップとを含むことを特徴とするコンパイル方法。11. A compiling method for generating an object program based on a plurality of intermediate files obtained by parsing a plurality of source programs including external variables referred to each other, wherein the compiling method includes the steps of: A first object program generating step of generating a plurality of first object programs for securing an area for referring to an external variable in a memory; and a plurality of first object programs generated in the object program generating step are combined. As a result of executing the program in the execution form, in order from the external variable having the largest number of references, a register allocating step of allocating a register that is not otherwise used, and referring to the register allocation in the register allocating step, the plurality of intermediate files are referred to. On the basis of, Compiling method which comprises a second object program generating step of generating a plurality of second object program performed using register is assigned the references assigned external variable register.
数に割り当てる他で使用されていないレジスタは、前記
実行形式のプログラムを実行した結果により得られたも
のであることを特徴とする請求項11に記載のコンパイ
ル方法。12. The method according to claim 11, wherein the registers that are not otherwise used to be allocated to the external variables in the register allocation step are obtained as a result of executing the program in the executable form. Compilation method.
数に割り当てる他で使用されていないレジスタは、前記
複数の第1のオブジェクトプログラム中で使用されてい
るレジスタ以外のレジスタであることを特徴とする請求
項11に記載のコンパイル方法。13. The register used in the register allocation step, which is not used except for assigning to an external variable, is a register other than a register used in the plurality of first object programs. 12. The compiling method according to item 11.
ソースプログラムを構文解析した複数の中間ファイルに
基づいて、オブジェクトプログラムを生成するためのコ
ンパイラプログラムを記録したコンピュータ読み取り可
能な記録媒体であって、 前記複数の中間ファイルに基づいて、前記外部変数を参
照するための領域をメモリに確保する複数の第1のオブ
ジェクトプログラムを生成する第1のオブジェクトプロ
グラム生成ステップと、 前記オブジェクトプログラム生成ステップで生成した複
数の第1のオブジェクトプログラムを結合した実行形式
のプログラムを実行した結果、参照回数が多い外部変数
から順に、他で使用されていないレジスタを割り当てる
レジスタ割り当てステップと、 前記レジスタ割り当てステップにおけるレジスタの割り
当てを参照し、前記複数の中間ファイルに基づいて、レ
ジスタが割り当てられた外部変数の参照を当該割り当て
られたレジスタを用いて行う複数の第2のオブジェクト
プログラムを生成する第2のオブジェクトプログラム生
成ステップとを実行させるためのプログラムを記録する
ことを特徴とするコンピュータ読み取り可能な記録媒
体。14. A computer-readable recording medium on which a compiler program for generating an object program is recorded based on a plurality of intermediate files obtained by parsing a plurality of source programs including external variables referred to each other. A first object program generating step of generating a plurality of first object programs for securing an area for referring to the external variable in a memory based on the plurality of intermediate files; Executing a program in an executable form in which the plurality of first object programs are combined, and as a result, a register allocating step of allocating a register that is not used elsewhere in order from an external variable having a large number of references; A second object program generating a plurality of second object programs that reference external variables to which registers have been allocated using the allocated registers based on the plurality of intermediate files. A computer-readable recording medium for recording a program for executing the steps.
数に割り当てる他で使用されていないレジスタは、前記
実行形式のプログラムを実行した結果により得られたも
のであることを特徴とする請求項14に記載のコンピュ
ータ読み取り可能な記録媒体。15. The register according to claim 14, wherein the register which is not otherwise used to be allocated to an external variable in the register allocating step is obtained as a result of executing the program in the executable form. Computer readable recording medium.
数に割り当てる他で使用されていないレジスタは、前記
複数の第1のオブジェクトプログラム中で使用されてい
るレジスタ以外のレジスタであることを特徴とする請求
項14に記載のコンピュータ読み取り可能な記録媒体。16. The register that is not used except for assigning to an external variable in the register allocating step is a register other than a register used in the plurality of first object programs. 15. The computer-readable recording medium according to 14.
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| JP11147742A JP2000339171A (en) | 1999-05-27 | 1999-05-27 | Compile device, its method and recording medium |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| JP11147742A JP2000339171A (en) | 1999-05-27 | 1999-05-27 | Compile device, its method and recording medium |
Publications (1)
| Publication Number | Publication Date |
|---|---|
| JP2000339171A true JP2000339171A (en) | 2000-12-08 |
Family
ID=15437127
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| JP11147742A Pending JP2000339171A (en) | 1999-05-27 | 1999-05-27 | Compile device, its method and recording medium |
Country Status (1)
| Country | Link |
|---|---|
| JP (1) | JP2000339171A (en) |
Cited By (1)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| JP2012203581A (en) * | 2011-03-24 | 2012-10-22 | Fujitsu Ltd | Method for optimizing register arrangement, program for optimizing register arrangement, and device for optimizing register arrangement |
-
1999
- 1999-05-27 JP JP11147742A patent/JP2000339171A/en active Pending
Cited By (1)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| JP2012203581A (en) * | 2011-03-24 | 2012-10-22 | Fujitsu Ltd | Method for optimizing register arrangement, program for optimizing register arrangement, and device for optimizing register arrangement |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| US8799881B2 (en) | Program parallelization device and program product | |
| EP0428084A2 (en) | Method and apparatus for compiling computer programs with interprocedural register allocation | |
| US20070226720A1 (en) | System and Method for Efficiently Passing Information Between Compiler and Post-Compile-Time Software | |
| JPH08339304A (en) | Method and apparatus for generation of platform standard object file containing machine independence code | |
| US20100229161A1 (en) | Compile method and compiler | |
| US20090328016A1 (en) | Generalized expression trees | |
| US20180052667A1 (en) | Emulation device, emulation method, and recording medium storing emulation program | |
| JP2004220583A (en) | Method and system for executing global processor resource assignment in assembler | |
| JP2017228029A (en) | Parallelization method, parallelization tool, on-vehicle device | |
| US7251594B2 (en) | Execution time modification of instruction emulation parameters | |
| Pellegrini | Distillating knowledge about Scotch | |
| CN115826946A (en) | A program exception vector space optimization system, method, device and medium | |
| US11435989B2 (en) | Thread-local return structure for asynchronous state machine | |
| JP2011141676A (en) | Apparatus and method for processing language, and computer program product | |
| US20010039653A1 (en) | Program conversion method, program conversion apparatus, storage medium for storing program conversion program and program conversion program | |
| US5404531A (en) | Method and apparatus for compiler processing on program related to data transfer and calculation, and method of managing memory | |
| JP5576605B2 (en) | Program conversion apparatus and program conversion method | |
| JP2005129001A (en) | Program execution device, microprocessor, and program execution method | |
| CN118092887B (en) | Wasm instruction set generation method, wasm instruction set generation device, terminal and storage medium | |
| US6134708A (en) | Program compilation execution system | |
| JP2000339171A (en) | Compile device, its method and recording medium | |
| US11429358B2 (en) | Representing asynchronous state machine in intermediate code | |
| JP3241214B2 (en) | Distributed processing apparatus and process execution method | |
| US20200409746A1 (en) | Information processing apparatus and recording medium | |
| US6029003A (en) | Method of assigning external variables to memories when compiling source program |