JP2002157128A - Method for allocating stack area to compiler and compiler - Google Patents

Method for allocating stack area to compiler and compiler

Info

Publication number
JP2002157128A
JP2002157128A JP2000353012A JP2000353012A JP2002157128A JP 2002157128 A JP2002157128 A JP 2002157128A JP 2000353012 A JP2000353012 A JP 2000353012A JP 2000353012 A JP2000353012 A JP 2000353012A JP 2002157128 A JP2002157128 A JP 2002157128A
Authority
JP
Japan
Prior art keywords
symbol table
stack area
compiler
stack
area
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
JP2000353012A
Other languages
Japanese (ja)
Inventor
Hiroshi Nonomura
野々村  洋
Kenichi Tagami
憲一 田神
Yoshinori Hayakawa
義則 早川
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Hitachi Software Engineering Co Ltd
Hitachi Ltd
Original Assignee
Hitachi Software Engineering Co Ltd
Hitachi Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Hitachi Software Engineering Co Ltd, Hitachi Ltd filed Critical Hitachi Software Engineering Co Ltd
Priority to JP2000353012A priority Critical patent/JP2002157128A/en
Publication of JP2002157128A publication Critical patent/JP2002157128A/en
Pending legal-status Critical Current

Links

Landscapes

  • Devices For Executing Special Programs (AREA)

Abstract

PROBLEM TO BE SOLVED: To dispense with securing useless stack area by dispensing with securing any memory area in a stack for members of a structure not referred to when allocating stack area during compilation. SOLUTION: During compilation, when the area of a local variable of the structure is allocated to the stack, a program is scanned to check if there is a portion referring to the relevant member of the structure. Only when the member of the structure is referred to and a memory area for the structure member is not yet secured, the memory area for the structure member is secured on the stack area.

Description

【発明の詳細な説明】DETAILED DESCRIPTION OF THE INVENTION

【0001】[0001]

【発明の属する技術分野】本発明は、コンパイラのスタ
ック領域割り付け方法及びコンパイラに係り、特に、ロ
ーカル変数のメモリ領域をスタック領域に割るつけるコ
ンパイラのスタック領域割り付け方法及びコンパイラに
関する。
The present invention relates to a method for allocating a stack area of a compiler and, more particularly, to a method and a compiler for allocating a stack area of a local variable memory area to a stack area.

【0002】[0002]

【従来の技術】C言語等のコンパイラは、関数が呼び出
されたとき、その変数を格納するメモリ領域を確保し、
その変数(ローカル変数)を必要に応じてスタック領域
割り付けている。この樹のコンパイラに関する従来技術
として、例えば、「エイホ、セシィ、ウルマン著 コン
パイラII」(サイエンス社、1990年)489頁〜4
96頁等に記載された技術が知られている。この従来技
術は、関数毎に、必要となるスタック領域のサイズや、
領域のどの位置を、どのローカル変数に対応付けるか等
のスタック領域の割り付けをコンパイル時に行うという
ものである。
2. Description of the Related Art When a function is called, a compiler such as the C language secures a memory area for storing its variables,
The variable (local variable) is allocated to the stack area as needed. As a prior art relating to the compiler of this tree, for example, "Compiler II by Eiho, Cessie and Ullman" (Science Inc., 1990), p.
The technique described on page 96 is known. In this conventional technique, the size of the stack area required for each function,
At the time of compilation, allocation of a stack area such as which position of the area is to be associated with which local variable is performed.

【0003】そして、前述の従来技術は、ローカル変数
が構造体の場合、構造体が全体で1つの変数とみなされ
るため、構造体の1つのメンバに対する参照しかない場
合でも、構造体全体分のメモリ領域をスタック領域上に
確保していた。
[0003] In the above-mentioned prior art, when a local variable is a structure, the structure is regarded as one variable as a whole. Therefore, even when there is only a reference to one member of the structure, the entire structure is not included. The memory area was secured on the stack area.

【0004】[0004]

【発明が解決しようとする課題】前述した従来技術は、
複数のメンバを持つ構造体がローカル変数の場合、構造
体の中に、プログラム中で参照していないメンバがある
場合にも、構造体全体分の領域をスタックに確保するた
め、参照されないメンバの分のスタック領域が無駄に確
保されることになるという問題点を有している。
The prior art described above is
When a structure with multiple members is a local variable, even if there is a member not referenced in the program, the structure is allocated to the entire structure on the stack. However, there is a problem that a stack area is wastefully secured.

【0005】本発明の目的は、前述した従来技術の問題
点を解決し、参照されない構造体のメンバについて、ス
タックにメモリ領域を確保せずに、無駄なスタック領域
の確保を不要としたコンパイラのスタック領域割り付け
方法及びコンパイラを提供することにある。
SUMMARY OF THE INVENTION An object of the present invention is to solve the above-mentioned problems of the prior art, and to provide a compiler which does not need to secure a useless stack area without securing a memory area on the stack for members of a structure not referred to. An object of the present invention is to provide a stack area allocating method and a compiler.

【0006】[0006]

【課題を解決するための手段】本発明によれば前記目的
は、コンパイラのスタック領域割り付け方法において、
構造体のローカル変数のメモリ領域をスタック領域上に
確保するとき、構造体に含まれる複数のメンバのそれぞ
れについてそのメンバが参照されるメンバであるか否か
を調べ、参照される構造体のメンバについてスタック領
域を確保し、参照されない構造体のメンバについてその
スタック領域を確保しないようにすることにより達成さ
れる。
According to the present invention, there is provided a method for allocating a stack area of a compiler, comprising:
When allocating a memory area for a local variable of a structure on the stack area, it checks whether each of the multiple members included in the structure is a referenced member, and checks the member of the referenced structure This is achieved by allocating a stack area for the non-referenced structure and not reserving the stack area for members of the structure that are not referred to.

【0007】本発明は、構造体のローカル変数の領域を
スタックに割り付ける際に、プログラムを走査して、該
当する構造体のメンバを参照している個所をがあるか否
かを調べ、参照があった場合に、参照されているメンバ
のメモリ領域だけをスタック領域上に確保する。これに
より、参照されない構造体のメンバについて、スタック
にメモリ領域が確保されないため、無駄なスタック領域
の確保を不要とすることができる。
According to the present invention, when allocating an area of a local variable of a structure to a stack, the program is scanned to check whether or not there is a location referring to a member of the relevant structure. If there is, only the memory area of the referenced member is secured on the stack area. As a result, a memory area is not secured in the stack for members of a structure that is not referred to, so that it is not necessary to secure a useless stack area.

【0008】[0008]

【発明の実施の形態】以下、本発明によるコンパイラの
スタック領域割り付け方法及びコンパイラの実施形態を
図面により詳細に説明する。
BRIEF DESCRIPTION OF THE DRAWINGS FIG. 1 is a block diagram showing an embodiment of a method for allocating a stack area of a compiler according to the present invention;

【0009】図1は本発明の一実施形態によるコンパイ
ラが稼動する計算機システムの構成を示すブロック図、
図2はコンパイルの処理動作を説明するフローチャー
ト、図3は構造体参照解析処理の処理動作の詳細を説明
するフローチャート、図4はスタック割り付け処理の処
理動作の詳細を説明するフローチャート、図5はソース
プログラムの例について説明する図、図6は図5のソー
スプログラムから生成される記号表の一部の例について
説明する図、図7は従来技術により構造体にスタック領
域上のメモリを割り付けた例を示す図、図8は本発明の
実施形態により構造体にスタック領域上のメモリを割り
付けた例を示す図である。図1において、101はCP
U、102はディスプレイ装置、103はキーボード、
104は主記憶装置、105はコンパイラ、106は中
間コード、107は外部記憶装置、108はソースプロ
グラム、108はオブジェクトプログラムである。
FIG. 1 is a block diagram showing the configuration of a computer system on which a compiler according to an embodiment of the present invention operates.
FIG. 2 is a flowchart for explaining the processing operation of the compilation, FIG. 3 is a flowchart for explaining the processing operation of the structure reference analysis processing, FIG. 4 is a flowchart for explaining the processing operation of the stack allocation processing, and FIG. FIG. 6 is a diagram illustrating an example of a program, FIG. 6 is a diagram illustrating a partial example of a symbol table generated from the source program of FIG. 5, and FIG. 7 is an example in which a memory on a stack area is allocated to a structure by a conventional technique. FIG. 8 is a diagram showing an example in which a memory on a stack area is allocated to a structure according to the embodiment of the present invention. In FIG. 1, 101 is a CP.
U, 102 is a display device, 103 is a keyboard,
104 is a main storage device, 105 is a compiler, 106 is an intermediate code, 107 is an external storage device, 108 is a source program, and 108 is an object program.

【0010】本発明の実施形態によるコンパイラが動作
する計算機システムは、図1に示すように、CPU10
1、ディスプレイ装置102、キーボード103、主記
憶装置104、外部記憶装置107を備えて構成されて
いる。主記憶装置104には、コンパイラ105とコン
パイル過程で必要となる中間コード106とが保持され
る。また、外部記憶装置107には、ソースプログラム
108、及び、オブジェクトプログラム109が保持さ
れる。コンパイル処理は、CPU101がコンパイラ1
04を実行することにより行われる。ユーザーは、キー
ボード103よりコマンドをコンパイラ104に与え、
ディスプレイ装置102は、ユーザーにコンパイルの終
了やエラーを知らせる。
A computer system on which a compiler according to an embodiment of the present invention operates has, as shown in FIG.
1, a display device 102, a keyboard 103, a main storage device 104, and an external storage device 107. The main storage device 104 holds a compiler 105 and an intermediate code 106 required in the compiling process. The external storage device 107 holds a source program 108 and an object program 109. The compiling process is performed by the CPU 101 using the compiler 1
04 is performed. The user gives a command to the compiler 104 from the keyboard 103,
The display device 102 informs the user of the end of compilation or an error.

【0011】次に、図2に示すフローを参照して、コン
パイルの処理動作を説明する。
Next, the compile processing operation will be described with reference to the flow shown in FIG.

【0012】(1)まず、ソースプログラム108を読
み出して、コンパイラ内部で処理可能な中間コード10
6や、図6により後述する記号表を生成する構文解析の
処理を実行する。構文解析処理の詳細は、例えば、「エ
イホ、セシィ、ウルマン著 コンパイラII」(サイエン
ス社、1990年)30頁〜74頁に記載され、また、
記号表の生成についても、同書521頁〜535頁に記
載されているので、ここでの説明を省略する(ステップ
201)。
(1) First, the source program 108 is read, and the intermediate code 10 that can be processed inside the compiler is read.
6 and a syntax analysis process for generating a symbol table described later with reference to FIG. The details of the parsing process are described in, for example, "Compiler II by Eiho, Seshi and Ullman" (Science Inc., 1990), pp. 30-74.
The generation of the symbol table is also described on pages 521 to 535 of the same book, and the description is omitted here (step 201).

【0013】(2)次に、構造体参照解析の処理を実行
する。この構造体参照解析の処理については、図3に示
すフローを参照してその詳細を後述する(ステップ20
2)。
(2) Next, a structure reference analysis process is executed. Details of the structure reference analysis processing will be described later with reference to the flow shown in FIG.
2).

【0014】(3)次に、スタック割り付け処理を行
う。このスタック割り付け処理の処理については、図4
に示すフローを参照してその詳細を後述する(ステップ
203)。
(3) Next, a stack allocation process is performed. This stack allocation processing is described in FIG.
The details will be described later with reference to the flow shown in FIG.

【0015】(4)次に、オブジェクトコード生成の処
理を実行してオブジェクトコードを生成して処理を終了
する。このオブジェクト生成処理の詳細は、「エイホ、
セシィ、ウルマン著:コンパイラII」(サイエンス社、
1990年)624頁〜707頁に記載されているの
で、ここでの説明を省略する(ステップ204)。
(4) Next, an object code generation process is executed to generate an object code, and the process ends. For more information on this object creation process, see "
Cessy, Ullman: Compiler II "(Science,
(1990), pages 624 to 707, and a description thereof will be omitted (step 204).

【0016】ここで、構造体参照解析の処理及びスタッ
ク割り付け処理の処理の詳細を説明する前に、図5を参
照して本発明の実施形態に使用するソースプログラムの
例について、また、図6を参照して図5に示すソースプ
ログラムから生成される記号表の一部の例について説明
する。
Before describing the details of the structure reference analysis process and the stack allocation process, an example of a source program used in the embodiment of the present invention will be described with reference to FIG. An example of a part of a symbol table generated from the source program shown in FIG. 5 will be described with reference to FIG.

【0017】図5に示すソースプログラムの例は、50
1〜505として示すような構造で定義される構造体
が、関数func( )内で使われるローカル変数aと
して508において宣言されている。すなわち、構造体
を宣言している501〜505は、fooという型がメ
ンバとして、x、y、zを持つ構造体であることを宣言
している。そして、関数を定義する部分である506〜
514において、506として示す関数の変数が、50
8、509として示すようにローカル変数aであると宣
言されており、ローカル変数aと、構造体のメンバx、
y、zとを使用するプログラムの処理を示す文が510
〜514として記述されている。このプログラムの処理
を示す文からプログラムが参照する構造体のメンバは、
構造体を構成する全メンバx、y、zのうちのメンバ
x、yだけであることが判る。
The example of the source program shown in FIG.
A structure defined by a structure shown as 1 to 505 is declared in 508 as a local variable a used in the function func (). That is, 501 to 505 declaring a structure declare that the type foo is a structure having x, y, and z as members. And 506- which is the part that defines the function
At 514, the variable of the function shown as 506 is 50
8, 509, the local variable a and the structure member x,
A sentence indicating processing of a program using y and z is 510
514. The members of the structure referenced by the program from the statement indicating the processing of this program are:
It can be seen that there are only members x and y among all the members x, y and z constituting the structure.

【0018】このようなソースプログラムから生成され
る記号表は、例えば、図6に示すようなものとなる。図
6において、記号表601が図5に示した501〜50
5で宣言される構造体aに対応し、記号表602、60
3、604のそれぞれは、構造体aのメンバx、y、z
の記号表である。記号表は、階層構造を持つリスト構造
になっており、記号表601は、関数内で宣言される記
号のリストに含まれており、その下に構造体メンバの記
号表リストとして、記号表602〜604がリスト構造
になって付加されている。各記号表は、記号の名前と、
型、サイズ、配置される位置、メモリ参照の有無をしめ
すフラグの情報を保持する。位置の情報は、初期値とし
て未定になっており、メモリ参照情報は、初期値として
FALSEになっている。
A symbol table generated from such a source program is, for example, as shown in FIG. In FIG. 6, the symbol table 601 corresponds to 501 to 50 shown in FIG.
5, corresponding to the structure a declared in FIG.
3, 604 are members x, y, z of the structure a
Is a symbol table. The symbol table has a list structure having a hierarchical structure. The symbol table 601 is included in a list of symbols declared in the function, and a symbol table 602 is provided below the symbol table as a symbol table list of structure members. To 604 are added in a list structure. Each symbol table contains the name of the symbol,
Holds information on the type, size, arrangement position, and flag indicating presence / absence of memory reference. The position information is undecided as an initial value, and the memory reference information is FALSE as an initial value.

【0019】前述したような構造体aを従来技術の方法
によりメモリ領域に割り付けたスタック領域は、図7に
示すようなものとなる。すなわち、従来技術の場合、ス
タック領域701上に、構造体aのメンバであるx、
y、zの領域が、それぞれ領域702、703、704
として割り付けられることになる。
FIG. 7 shows a stack area in which the above-mentioned structure a is allocated to the memory area by the conventional method. That is, in the case of the related art, x, which is a member of the structure a, is placed on the stack area 701.
Areas y and z are areas 702, 703, and 704, respectively.
Will be assigned as

【0020】次に、図3に示すフローを参照して、本発
明の特徴的な処理の1つである構造体参照解析の処理の
処理動作について説明する。この処理は、構造体のメン
バに対してメモリ領域を取る必要があるか否かを調べ、
メンバにフラグを立てる処理である。
Next, with reference to the flow shown in FIG. 3, the processing operation of the structure reference analysis processing which is one of the characteristic processing of the present invention will be described. This process checks if it is necessary to take memory space for the members of the structure,
This is a process of setting a flag on a member.

【0021】(1)まず、まだ処理していない文がある
か否かを調べ、全ての文が処理済の場合、そのまま構造
体参照解析処理を終了する。また、未処理の文がある場
合、次の文を取り出す(ステップ301、302)。
(1) First, it is checked whether or not there is a sentence that has not yet been processed. If all the sentences have been processed, the structure reference analysis processing ends as it is. If there is an unprocessed sentence, the next sentence is extracted (steps 301 and 302).

【0022】(2)次に、ステップ302で取り出した
文がローカル変数のメモリ参照文か否かを調べ、ローカ
ル変数のメモリ参照文でなかった場合、ステップ301
からの処理に戻る(ステップ303)。
(2) Next, it is checked whether or not the statement extracted in step 302 is a memory reference statement of a local variable. If the statement is not a memory reference statement of a local variable, step 301
The process returns to (Step 303).

【0023】(3)ステップ303で、文がローカル変
数のメモリ参照文であった場合、その文が構造体への参
照であるか否かを調べ、構造体への参照でなかった場
合、ステップ301からの処理に戻る(ステップ30
4)。
(3) In step 303, if the statement is a memory reference statement of a local variable, it is checked whether or not the statement is a reference to a structure. Return to the processing from step 301 (step 30)
4).

【0024】(4)ステップ304で、文が構造体への
参照であった場合、構造体への参照が構造体のメンバへ
の参照であるか否かを調べ、構造体のメンバへの参照で
あった場合、すでに参照されている構造体のメンバに対
応する記号表のメモリ参照フラグがTRUEになってい
るか否かを調べる。フラグがTRUEになっていた場
合、ステップ301からの処理に戻る(ステップ30
5、306)。
(4) In step 304, if the statement is a reference to a structure, it is checked whether or not the reference to the structure is a reference to a member of the structure. If it is, it is checked whether the memory reference flag of the symbol table corresponding to the member of the structure already referred to is set to TRUE. If the flag has been set to TRUE, the process returns to step 301 (step 30).
5, 306).

【0025】(5)ステップ306で、メモリ参照フラ
グがTRUEになっていなかった場合、参照されている
構造体のメンバに対応する記号表のメモリ参照フラグを
TRUEにした後、ステップ301からの処理に戻る
(ステップ307)。
(5) If the memory reference flag is not set to TRUE in step 306, the memory reference flag of the symbol table corresponding to the member of the structure being referred to is set to TRUE, and then the processing from step 301 is performed. (Step 307).

【0026】(6)ステップ305で、構造体への参照
が構造体のメンバへの参照でなかった場合、構造体全体
への参照であるため、対応する構造体全体に対応する記
号表のメモリ参照フラグがTRUEになっているか否か
を調べ、フラグがTRUEになっていた場合、ステップ
301からの処理に戻る(ステップ308)。
(6) In step 305, if the reference to the structure is not a reference to a member of the structure, it is a reference to the entire structure, so that the memory of the symbol table corresponding to the whole of the corresponding structure is stored. It is determined whether or not the reference flag is set to TRUE. If the flag is set to TRUE, the process returns to step 301 (step 308).

【0027】(7)ステップ308で、フラグがTRU
Eになっていなかった場合、参照されている構造体全体
に対応する記号表のメモリ参照フラグをTRUEにした
後、ステップ301からの処理に戻る(ステップ30
9)。
(7) In step 308, the flag is set to TRU
If it is not E, the memory reference flag of the symbol table corresponding to the entire structure being referred to is set to TRUE, and the process returns to Step 301 (Step 30).
9).

【0028】次に、図4に示すフローを参照して、本発
明の特徴的な処理の1つであるスタック割り付け処理の
処理動作について説明する。この処理は、参照されない
構造体のメンバに対して、スタック領域を確保しないよ
うにするものであり、スタック領域上に変数に対応する
メモリ領域を取るものである。
Next, the processing operation of the stack allocation processing which is one of the characteristic processing of the present invention will be described with reference to the flow shown in FIG. In this processing, a stack area is not reserved for members of a structure that is not referred to, and a memory area corresponding to a variable is allocated on the stack area.

【0029】(1)まず、関数全体の記号表リストにつ
いて処理を行う準備を行い、まだ、処理していない記号
表があるか否かを調べる。この結果、未処理の記号表が
ある場合、未処理の記号表を取り出す(ステップ401
〜403)。
(1) First, preparations are made to process the symbol table list of the entire function, and it is checked whether there is a symbol table that has not been processed yet. As a result, if there is an unprocessed symbol table, the unprocessed symbol table is extracted (step 401).
403).

【0030】(2)次に、ステップ403で取り出した
未処理の記号表が構造体の記号表であるか否かを調べ、
構造体の記号表であった場合、記号表のメモリ参照フラ
グがTRUEであるか否かを調べる(ステップ404、
405)。
(2) Next, it is checked whether or not the unprocessed symbol table extracted in step 403 is a symbol table of a structure.
If it is a symbol table of a structure, it is checked whether or not the memory reference flag of the symbol table is TRUE (step 404,
405).

【0031】(3)ステップ405で、記号表のメモリ
参照フラグがTRUEであった場合、スタック領域上に
構造体全体のサイズのメモリ領域を取った後、ステップ
402からの処理に戻り、記号表のメモリ参照フラグが
TRUEでなくFALSEであった場合、記号表の構造
体のメンバの記号表リストについて再帰的に処理を行う
ために、処理中の構造体メンバの記号表リストの処理を
する準備をした後、ステップ402からの処理に戻る
(ステップ406、409)。
(3) If the memory reference flag of the symbol table is TRUE in step 405, a memory area having the size of the entire structure is taken on the stack area, and the process returns to step 402 to return to the processing from the symbol table. If the memory reference flag is not FALSE but TRUE, the symbol table list of members of the structure of the symbol table is processed recursively to prepare for processing of the symbol table list of the structure member being processed. After that, the process returns to step 402 (steps 406 and 409).

【0032】(4)ステップ404で、記号表が構造体
の記号表でなかった場合、記号表のメモリ参照フラグが
TRUEであるか否かを調べ、メモリ参照フラグがTR
UEでなくFALSEであった場合、ステップ402か
らの処理に戻り、また、記号表のメモリ参照フラグがT
RUEであった場合、スタック領域上にその記号表のサ
イズのメモリ領域を取った後、ステップ402からの処
理に戻る(ステップ407、408)。
(4) If the symbol table is not the symbol table of the structure in step 404, it is checked whether or not the memory reference flag of the symbol table is TRUE.
If it is FALSE instead of the UE, the process returns to step 402, and the memory reference flag in the symbol table is set to T
If it is a RUE, a memory area having the size of the symbol table is set on the stack area, and the process returns to the step 402 (steps 407 and 408).

【0033】(5)ステップ402で、未処理の記号表
がなかった場合、処理中の記号表リストが構造体メンバ
の記号表リストであるか否かを調べ、構造体メンバの記
号表リストではな買った場合、処理を終了し、また、構
造体メンバの記号表であった場合、構造体メンバについ
て再帰的に処理を行うため、親構造体の属する記号表リ
ストの処理を行う準備を行った後、ステップ402から
の処理に戻る(ステップ410、411)。
(5) If there is no unprocessed symbol table in step 402, it is checked whether or not the symbol table list being processed is a symbol table list of structure members. If the purchase is completed, the process is terminated. If the symbol table is a structure member symbol table, preparation is made to process the symbol table list to which the parent structure belongs in order to recursively process the structure member. After that, the process returns to the process from step 402 (steps 410 and 411).

【0034】前述したような本発明の実施形態の処理に
より、図4に示したプログラムで宣言されている構造体
aをメモリ領域に割り付けたスタック領域は、図8に示
すようなものとなる。すなわち、本発明の実施形態の場
合、スタック領域801上に、構造体aのメンバである
x、yの領域が、それぞれ領域802、803として割
り付けられることになる。
By the processing of the embodiment of the present invention described above, the stack area in which the structure a declared in the program shown in FIG. 4 is allocated to the memory area becomes as shown in FIG. That is, in the case of the embodiment of the present invention, the x and y regions that are members of the structure a are allocated as the regions 802 and 803 on the stack region 801.

【0035】次に、図5により説明したソースプログラ
ムにおける構造体のメンバが、図3により説明した構造
体参照解析の処理、及び、図4により説明したのスタッ
ク割り付けの処理に従って、図8に示すようなスタック
の割り付けが行われる流れについて説明する。
Next, the members of the structure in the source program described with reference to FIG. 5 are shown in FIG. 8 according to the structure reference analysis processing described with reference to FIG. 3 and the stack allocation processing described with reference to FIG. A flow in which such stack allocation is performed will be described.

【0036】まず、構造体参照解析の処理開始後、ステ
ップ301において未処理の文があるため、ステップ3
02に進み文510が取り出される。次に、ステップ3
03において、文510がローカル変数のメモリ参照文
ではないためステップ301の処理に戻る。ステップ3
01において、まだ未処理の文があるため、ステップ3
02に進み文511が取り出される。次に、ステップ3
03において、文511がローカル変数のメモリ参照文
であるためステップ304に進む。次に、ステップ30
4において、文511が構造体の参照文であるためステ
ップ305に進む。次に、ステップ305において、文
511が構造体メンバへの参照であるため、ステップ3
06に進む。次に、ステップ306において、文511
において参照される構造体メンバxに対応する記号表6
02のメモリ参照フラグが、初期値のFALSEのまま
のためステップ307に進む。ステップ307におい
て、文511で参照される構造体のメンバxに対応する
記号表602のメモリ参照フラグをTRUEにした後、
ステップ301の処理に戻る。
First, after the structure reference analysis process is started, since there is an unprocessed statement in step 301, step 3
In step 02, the sentence 510 is extracted. Next, step 3
In 03, the statement 510 is not a memory reference statement of a local variable, so that the process returns to step 301. Step 3
In step 01, there are still unprocessed statements, so step 3
In step 02, the sentence 511 is extracted. Next, step 3
In step 03, the process proceeds to step 304 because the statement 511 is a memory reference statement of a local variable. Next, step 30
In step 4, since the sentence 511 is a reference to a structure, the process proceeds to step 305. Next, in step 305, since statement 511 is a reference to a structure member, step 3
Proceed to 06. Next, in step 306, the statement 511
Table 6 corresponding to the structure member x referenced in
Since the memory reference flag of 02 remains the initial value FALSE, the process proceeds to step 307. In step 307, after setting the memory reference flag of the symbol table 602 corresponding to the member x of the structure referred to in the statement 511 to TRUE,
The process returns to step 301.

【0037】前述と同様にして文512についてもステ
ップ307まで進み、文512で参照される構造体のメ
ンバyに対応する記号表603のメモリ参照フラグがT
RUEにされる。
In the same manner as described above, the process proceeds to step 307 for the statement 512, and the memory reference flag of the symbol table 603 corresponding to the member y of the structure referred to by the statement 512 is set to T.
RUE.

【0038】文513も、文511、512の場合と同
様にローカル変数のメモリ参照であり、構造体メンバへ
の参照文であるが、ステップ306において、すでに記
号表602、603ともメモリ参照フラグがTRUEと
されているため、ステップ301の処理へ戻る。
The statement 513 is also a memory reference of a local variable and is a reference to a structure member, as in the case of the statements 511 and 512. In step 306, both the symbol tables 602 and 603 have the memory reference flag already set. Since it is set to TRUE, the process returns to step 301.

【0039】文513の処理が終了すると、ステップ3
01で未処理の文がないと判断されて構造体参照解析の
処理を終了する。
When the processing of statement 513 is completed, step 3
In step 01, it is determined that there is no unprocessed statement, and the structure reference analysis process ends.

【0040】構造体参照解析の処理終了後、図4により
説明した処理手順に従ってスタック割り付け処理が行わ
れる。まず、ステップ401において、処理中の関数で
ある図5に示すfunc( )の記号表リストの処理を
行う準備を行う。この記号表リストには、図6に示す記
号表が含まれる。次に、ステップ402において、未処
理の記号表があるためステップ403に進む。ステップ
403において、未処理の記号表として記号表601が
取り出されてステップ404に進む。ステップ404に
おいて、記号表601が構造体の記号表であるためステ
ップ405に進む。ステップ405において、記号表6
01のメモリ参照フラグがFALSEであるためステッ
プ409に進む。ステップ409において、記号表60
1で示される構造体のメンバの記号表リストである記号
表602〜604の処理を行う準備をした後、ステップ
402に戻る。
After the structure reference analysis process is completed, a stack allocation process is performed according to the processing procedure described with reference to FIG. First, in step 401, preparations are made for processing the symbol table list of func () shown in FIG. 5, which is a function being processed. The symbol table list includes the symbol table shown in FIG. Next, in step 402, since there is an unprocessed symbol table, the process proceeds to step 403. In step 403, the symbol table 601 is extracted as an unprocessed symbol table, and the flow advances to step 404. In step 404, the process proceeds to step 405 because the symbol table 601 is the symbol table of the structure. In step 405, the symbol table 6
Since the memory reference flag of 01 is FALSE, the process proceeds to step 409. In step 409, the symbol table 60
After preparing to process the symbol tables 602 to 604, which are the symbol table lists of the members of the structure indicated by 1, the process returns to step 402.

【0041】ステップ402では、未処理の記号表があ
るため、再びステップ403に進む。ステップ403で
は、未処理の記号表として記号表602が取り出されて
ステップ404に進む。ステップ404において、記号
表602が構造体の記号表ではないため、ステップ40
7に進む。ステップ407では、記号表602のメモリ
参照フラグがTRUEであるためステップ408に進
む。ステップ408では、スタック領域801上にメモ
リ領域802が取る処理が行われ、その後、ステップ4
02に戻る。
In step 402, since there is an unprocessed symbol table, the process proceeds to step 403 again. In step 403, the symbol table 602 is extracted as an unprocessed symbol table, and the flow advances to step 404. In step 404, since the symbol table 602 is not the symbol table of the structure, step 40
Go to 7. In step 407, the process proceeds to step 408 because the memory reference flag of the symbol table 602 is TRUE. In step 408, a process of taking the memory area 802 on the stack area 801 is performed.
Return to 02.

【0042】ステップ402での処理から記号表602
の場合と同様にして、記号表603について、メモリ領
域803を取る処理が行われる。記号表604について
も、同様に処理が進められるが、記号表604は、メモ
リ参照フラグがFALSEのため、ステップ407から
そのままステップ402へ戻る。記号表604の処理が
終わると、ステップ402において、構造体のメンバの
記号表リストには未処理の記号表がないため、ステップ
410に進む。ステップ410において、記号表リスト
が構造体メンバの記号表リストであるためステップ41
1に進む。ステップ411において、構造体メンバの親
構造体である構造体aの記号表601の属する記号表リ
ストについて処理を行う準備をした後、ステップ402
に戻る。関数func( )に属する他の記号表につい
ての全ての処理が終了した後、ステップ402からステ
ップ410に進み、そこから処理を終了する前述した本
発明の実施形態は、単純な構造体を例として説明した
が、構造体の中に構造体が定義されているような入れ子
状の構造体についても、内側の構造体については、内側
の構造体及びそのメンバとすることにより、本発明を適
用することができる。また、外側の構造体についても、
内側の構造体全体を外側構造体の1つのメンバとして扱
うことにより、本発明を適用することができる。
From the processing in step 402, the symbol table 602
In the same manner as in the case of (1), a process for taking the memory area 803 is performed on the symbol table 603. The same process is performed for the symbol table 604, but the symbol table 604 returns from step 407 to step 402 as it is because the memory reference flag is FALSE. When the processing of the symbol table 604 ends, in step 402, there is no unprocessed symbol table in the symbol table list of the members of the structure. In step 410, since the symbol table list is the symbol table list of the structure members, step 41
Proceed to 1. In step 411, after preparing to process the symbol table list to which the symbol table 601 of the structure a that is the parent structure of the structure member belongs, the process proceeds to step 402.
Return to After all the processes for the other symbol tables belonging to the function func () have been completed, the process proceeds from step 402 to step 410, where the process is terminated. The above-described embodiment of the present invention uses a simple structure as an example. As described above, the present invention is also applied to a nested structure in which a structure is defined in a structure, by using the inner structure and its members as the inner structure. be able to. Also, for the outer structure,
The present invention can be applied by treating the entire inner structure as one member of the outer structure.

【0043】前述した本発明の実施形態において、図2
〜図4により説明した処理を実行するプログラムをF
D、MO、CDROM、DVD等の記録媒体に格納し、
コンパイルシステムとして提供することができる。
In the embodiment of the present invention described above, FIG.
4 is a program for executing the processing described with reference to FIG.
D, MO, CDROM, DVD and other storage media,
It can be provided as a compilation system.

【0044】[0044]

【発明の効果】以上説明したように本発明によれば、コ
ンパイル中のスタック領域割り当て時に、参照されない
構造体のメンバについて、スタックにメモリ領域を確保
する必要がなく、無駄なスタック領域の確保を不要とす
ることができるので、スタック領域を有向に使用するこ
とができる。
As described above, according to the present invention, when allocating a stack area during compilation, it is not necessary to secure a memory area on the stack for members of a structure that is not referred to, so that useless stack area can be secured. Since it can be unnecessary, the stack area can be used in a directed manner.

【図面の簡単な説明】[Brief description of the drawings]

【図1】本発明の一実施形態によるコンパイラが稼動す
る計算機システムの構成を示すブロック図である。
FIG. 1 is a block diagram showing a configuration of a computer system on which a compiler according to an embodiment of the present invention operates.

【図2】コンパイルの処理動作を説明するフローチャー
トである。
FIG. 2 is a flowchart illustrating a compile processing operation.

【図3】構造体参照解析処理の処理動作の詳細を説明す
るフローチャートである。
FIG. 3 is a flowchart illustrating details of a processing operation of a structure reference analysis process.

【図4】スタック割り付け処理の処理動作の詳細を説明
するフローチャートである。
FIG. 4 is a flowchart illustrating details of a processing operation of stack allocation processing.

【図5】ソースプログラムの例について説明する図であ
る。
FIG. 5 is a diagram illustrating an example of a source program.

【図6】ソースプログラムから生成される記号表の例に
ついて説明する図である。
FIG. 6 is a diagram illustrating an example of a symbol table generated from a source program.

【図7】従来技術により構造体にスタック領域上のメモ
リを割り付けた例を示す図である。
FIG. 7 is a diagram showing an example in which a memory on a stack area is allocated to a structure according to the related art.

【図8】本発明の実施形態により構造体にスタック領域
上のメモリを割り付けた例を示す図である。
FIG. 8 is a diagram showing an example in which a memory on a stack area is allocated to a structure according to the embodiment of the present invention.

【符号の説明】[Explanation of symbols]

101 CPU 102 ディスプレイ装置 103 キーボード 104 主記憶装置 105 コンパイラ 106 中間コード 107 外部記憶装置 108 ソースプログラム 108 オブジェクトプログラム 101 CPU 102 Display device 103 Keyboard 104 Main storage device 105 Compiler 106 Intermediate code 107 External storage device 108 Source program 108 Object program

フロントページの続き (72)発明者 田神 憲一 東京都小平市上水本町五丁目20番1号 株 式会社日立製作所半導体グループ内 (72)発明者 早川 義則 神奈川県横浜市中区尾上町六丁目81番地 日立ソフトウェアエンジニアリング株式会 社内 Fターム(参考) 5B081 CC27 Continued on the front page (72) Inventor Kenichi Tagami 5-2-1, Kamimizuhoncho, Kodaira-shi, Tokyo Within the Semiconductor Group, Hitachi, Ltd. (72) Inventor Yoshinori Hayakawa 6-81 Onoecho, Naka-ku, Yokohama-shi, Kanagawa Prefecture Address Hitachi Software Engineering Co., Ltd. In-house F-term (reference) 5B081 CC27

Claims (3)

【特許請求の範囲】[Claims] 【請求項1】 コンパイラのスタック領域割り付け方法
において、構造体のローカル変数のメモリ領域をスタッ
ク領域上に確保するとき、構造体に含まれる複数のメン
バのそれぞれについてそのメンバが参照されるメンバで
あるか否かを調べ、参照される構造体のメンバについて
スタック領域を確保し、参照されない構造体のメンバに
ついてそのスタック領域を確保しないことを特徴とする
コンパイラのスタック領域割り付け方法。
In a method of allocating a stack area of a compiler, when a memory area of a local variable of a structure is secured on the stack area, each of a plurality of members included in the structure is a member referred to. A stack area allocation method for a compiler, characterized in that a stack area is reserved for a member of a structure to be referred to and a stack area is not reserved for a member of a structure that is not referred to.
【請求項2】 コンパイラにおいて、構造体のローカル
変数のメモリ領域をスタック領域上に確保するとき、構
造体に含まれる複数のメンバのそれぞれについてそのメ
ンバが参照されるメンバであるか否かを調べる手段と、
参照されない構造体のメンバについてそのスタック領域
を確保せずに、参照される構造体のメンバについてスタ
ック領域を確保する手段とを備えることを特徴とするコ
ンパイラ。
2. When a memory area for a local variable of a structure is secured on a stack area in a compiler, each of a plurality of members included in the structure is checked whether or not the member is a referenced member. Means,
Means for securing a stack area for a member of a referenced structure without securing a stack area for a member of a structure that is not referenced.
【請求項3】 請求項2記載のコンパイラを実現するた
めの構造体に含まれる複数のメンバのそれぞれについて
そのメンバが参照されるメンバであるか否かを調べる処
理プログラムと、参照されない構造体のメンバについて
そのスタック領域を確保せずに、参照される構造体のメ
ンバについてスタック領域を確保する処理プログラムと
が格納されたことを特徴とする記録媒体。
3. A processing program for checking whether or not each of a plurality of members included in a structure for realizing the compiler according to claim 2 is a member to be referred to, A storage medium storing a processing program for securing a stack area for a member of a referenced structure without securing a stack area for the member.
JP2000353012A 2000-11-20 2000-11-20 Method for allocating stack area to compiler and compiler Pending JP2002157128A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
JP2000353012A JP2002157128A (en) 2000-11-20 2000-11-20 Method for allocating stack area to compiler and compiler

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
JP2000353012A JP2002157128A (en) 2000-11-20 2000-11-20 Method for allocating stack area to compiler and compiler

Publications (1)

Publication Number Publication Date
JP2002157128A true JP2002157128A (en) 2002-05-31

Family

ID=18825834

Family Applications (1)

Application Number Title Priority Date Filing Date
JP2000353012A Pending JP2002157128A (en) 2000-11-20 2000-11-20 Method for allocating stack area to compiler and compiler

Country Status (1)

Country Link
JP (1) JP2002157128A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8478970B2 (en) 2009-08-31 2013-07-02 Electronics And Telecommunications Research Institute Accessing value for local variable from function call stack upon offset matching with instruction extracted stack pointer offset or from cache
JP2016136368A (en) * 2015-01-23 2016-07-28 富士電機株式会社 Language conversion device

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8478970B2 (en) 2009-08-31 2013-07-02 Electronics And Telecommunications Research Institute Accessing value for local variable from function call stack upon offset matching with instruction extracted stack pointer offset or from cache
KR101283469B1 (en) 2009-08-31 2013-07-12 한국전자통신연구원 Method and Apparatus for Memory Access of Processor Instruction
JP2016136368A (en) * 2015-01-23 2016-07-28 富士電機株式会社 Language conversion device

Similar Documents

Publication Publication Date Title
JP2609093B2 (en) Apparatus and method for generating software program
KR100270916B1 (en) How to add network management system and class dynamically
US7823139B2 (en) Method and system for translating programming languages
JP2666847B2 (en) Heterogeneous language communication method
US6363522B1 (en) Method and apparatus for handling exceptions as normal control flow
JP2000347874A (en) Method and device for structuring call rule prolog and epilog codes using register allocator
US20070039010A1 (en) Automatic generation of software code to facilitate interoperability
Miecznikowski et al. Decompiling Java using staged encapsulation
US5826088A (en) System for protecting computer software written in interpreted language
JPH1196016A (en) Gdmo translator, gdmo translation method and recording medium recording gdmo translator program
US20010044930A1 (en) Loop optimization method and a compiler
US7080370B1 (en) Method and apparatus for compiling source programs using one or more libraries
JP2002157128A (en) Method for allocating stack area to compiler and compiler
JPH0869381A (en) Compilation system
JP2000353097A (en) Method and device for generating low density interference graph
Oudshoorn A Drop-in Replacement for LR (1) Table-Driven Parsing
JP3566602B2 (en) Compilation method and recording medium recording compilation program
CN113900657A (en) Method for reading data rule, electronic device and storage medium
JPH0438528A (en) In-line developing system for source program
JP3921288B2 (en) Computer-readable storage medium storing language processing apparatus and inline expansion program
JP3192177B2 (en) Object processing device
JP3301394B2 (en) Communication management program startup initial setting method
JP2003036163A (en) Operating system with translating function and system mounting it
JP2626450B2 (en) Backing store usage calculator
JPH06266562A (en) Object code size optimizing system in object-oriented language processing system