JP3915208B2 - Compilation device - Google Patents

Compilation device Download PDF

Info

Publication number
JP3915208B2
JP3915208B2 JP32896497A JP32896497A JP3915208B2 JP 3915208 B2 JP3915208 B2 JP 3915208B2 JP 32896497 A JP32896497 A JP 32896497A JP 32896497 A JP32896497 A JP 32896497A JP 3915208 B2 JP3915208 B2 JP 3915208B2
Authority
JP
Japan
Prior art keywords
initial value
program
variable
area
dynamic
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.)
Expired - Fee Related
Application number
JP32896497A
Other languages
Japanese (ja)
Other versions
JPH11161501A (en
Inventor
誘二 辻森
斉 大脇
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.)
Fujitsu Ltd
Original Assignee
Fujitsu 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 Fujitsu Ltd filed Critical Fujitsu Ltd
Priority to JP32896497A priority Critical patent/JP3915208B2/en
Publication of JPH11161501A publication Critical patent/JPH11161501A/en
Application granted granted Critical
Publication of JP3915208B2 publication Critical patent/JP3915208B2/en
Anticipated expiration legal-status Critical
Expired - Fee Related legal-status Critical Current

Links

Images

Landscapes

  • Devices For Executing Special Programs (AREA)

Description

【0001】
【発明の属する技術分野】
本発明は、入力されたソースプログラムをコンパイルしてオブジェクトプログラムを生成するコンパイラに関し、特に動的な構造体変数の初期化に関する。
【0002】
【従来の技術】
コンピュータプログラムは、通常何らかのプログラミング言語で記述したソースプログラム(ソースコード)を作成し、それをコンパイラでオブジェクトコードに変換し、一つまたは複数のオブジェクトコードをリンクすることで実行形式のプログラムとなる。
【0003】
多くのプログラミング言語はその文法規約として構造体変数をサーポートしている。また、変数は実行形式のプログラムを作成した時点でその変数のための記憶領域が獲得される静的変数と、プログラムを実行する際に動的に記憶領域が獲得される動的変数とがある。
従来のコンパイラでは静的変数に対しては初期値の設定(変数の宣言の際に初期値を指定すること)が可能であったが、動的な構造体変数への初期値の設定は不可能であった。これは、静的変数はコンパイルの際にデータ領域が獲得されるので、コンパイルの際に値を設定することが可能であるのに対し、動的変数はコンパイルの際にはデータ領域が存在していないので、コンパイルの際に値を設定することができないためである。
【0004】
【発明が解決しようとする問題点】
このため、プログラム開発者はソースプログラム作成時に変数の宣言とは別に変数に対する値の設定を記述する必要があった。また、値の設定は構造体変数を構成する個々の要素に対する値の設定として記述されるため、実行形式プログラムのサイズが肥大してしまっていた。
【0005】
また、構造体の各要素毎に要素の参照の際に値が設定済みかどうかをチェックすることはできなかった。
本発明は、動的構造体変数に対して初期値が設定できないという問題点および、この問題点から関連して発生するその他の問題点を解決するものである。
【0006】
【問題を解決するための手段】
そこで、本願発明では、ソースプログラムを入力し、オブジェクトプログラムを出力するコンパイル装置であって、動的変数に設定する初期値を記憶するための初期値設定領域を出力されるオブジェクトプログラム内に静的に獲得する初期値設定領域獲得手段と、獲得した前記初期値設定領域に対して初期値を設定する初期値設定領域初期化手段と、プログラムの実行時に動的変数の領域を動的に獲得した際に、前記初期値設定領域の内容を前記動的に獲得した領域に複写するコードを生成する変数初期化用オブジェクトコード生成手段とを有するコンパイル装置によって上記問題を解決する。
【0007】
【発明の実施の形態】
図1は、プログラムがコンピュータ上でどのように実行されるかを模式的に示す図である。コンピュータ4は図示しないCPU、主記憶装置(メモリ)、外部記憶装置、表示装置、キーボード等で構成される。外部記憶装置にはプログラムやデータがファイルとして格納される。外部記憶装置のファイルに格納されている実行形式プログラム1はメモリ上にロードされ、CPUによって、実行される。OS3はコンピュータのハードウェア資源と実行形式プログラムを制御するものである。ライブラリ2は一種の実行形式プログラムであって、複数の実行形式プログラムから共通に呼び出されるものである。
【0008】
実行形式プログラム1を作成するには、図2に示すエディタ5やコンパイラ6やリンカ7を利用する。エディタ5、コンパイラ6、リンカ7はいずれも実行形式のプログラムである。エディタ5は実行形式プログラムのもととなるソースプログラム8を作成するために利用される。作成したソースプログラムはソースファイルとしてファイルに格納される。
【0009】
コンパイラ6はソースプログラム8をオブジェクトプログラム12に変換するプログラムであって、図3に示すように、構文解析部9、最適化処理部10、コード生成部11によって構成される。
構文解析部9はファイルに格納されているソースプログラム8を読み込んで、所定の文法規則に応じた構文解析を行い、対応する中間言語を生成する。最適化処理部10は構文解析部9によって生成された中間言語を、より実行効率がよくなるように変換する。コード生成部11は最適化処理部10によって変換して得られた中間言語をプログラムが実行されるコンピュータに適したオブジェクトプログラム12に変換する。
【0010】
図4に示すとおり、コンパイラ6によって生成された複数のオブジェクトプログラム(12−1、12−2、12−3等)はリンカ7によって結合され、実行形式プログラム1が生成される。
コンパイラ6はコンパイラ6を実行するためのコマンドをキーボードから入力する等して起動される。コンパイラ6を起動する際には、コマンドと共に、ソースプログラムを格納したソースファイル名やコンパイラに対する各種の指示をオプションとして指示する。オプションの一例として実行時の未定義値検出指示オプションがある。
【0011】
未定義値検出指示オプションはプログラムの実行中に、プログラム中で利用される変数を参照する際に、その変数に対してすでに値が代入されているか否かをチェックし、もしも値が代入されていなかった場合にはその旨のエラー表示を行なうような実行形式のプログラムを作成するためのオプションである。このオプションが指示された場合には変数の参照に先立って何らかの特定の処理を行なう必要があるため、プログラムの実行効率は低下するが、プログラムのデバッグには非常に有用である。
【0012】
構文解析部9はソースプログラムの構文解析中に動的構造体変数の定義を認識すると、図5に示す処理を行なう。
まず、ステップS21において、未定義値検出オプションが指示されているか否かをチェックする。オプションが指示されている場合にはステップS22にすすみ、指示されていない場合にはステップS27に進む。
【0013】
オプションが指示されていた場合、ステップS22において動的構造対変数を初期化するために利用するテンプレート領域を確保する。ここで、同じ型の動的構造体変数のためのテンプレートが既に確保されている場合には、新たにテンプレート領域を確保することはしない。また、テンプレート領域は最終的には実行形式プログラム1に含まれる静的データ領域に確保される。
【0014】
次にステップS23、S24、S25、S26において、確保したテンプレート領域に値を設定する。ソースプログラム中で動的構造体変数の要素に初期値が指定されている場合には、ステップS25で指定されている初期値をその要素に対応するテンプレート中の領域に設定する。初期値が指定されていない場合は、同じ領域に16進数の8b8b8b8bを設定する。この値は生成された実行形式プログラム1を実行中にプログラム中の動的構造体変数の要素をアクセスする際に、その要素に対して既に値が設定されているか否かをチェックするために利用される。
【0015】
即ち、動的構造体変数の要素をアクセスする際に、8b8b8b8bが設定されていれば、その要素には値が設定されていなかった(未定義であって)と判定し、そうでなければ値が設定されていた( 定義済みであった)と判定すればよい。なお、定義済みであるか否かを判定するための値として、ここでは8b8b8b8bを使用したが、プログラム中で使用されない値または、非常に低い確率でしか使用されず、実用上問題の無い値であればどのような値であってもよい。
【0016】
また、ステップS21の判定において、未定義値検出オプションが指定されていない場合には、ステップS27において、動的構造体変数の複数の要素の内の1/5以上の要素に対してソースプログラム8中で初期値が指定されているか否かをチェックする。1/5以上の要素に対して初期値が指定されていればステップS28に進み、1/5未満であれば処理を終了する。なお、ここで判定の基準とする値は必ずしも1/5である必要はなく、生成されるプログラムの実行効率が最善となる値を選択すればよい。
【0017】
ステップS28においては、ステップS22と同様に動的構造体変数を初期化するために利用するテンプレート領域を確保する。同じ型の動的構造体変数のためのテンプレートが既に確保されている場合には、新たにテンプレート領域を確保することはしない。また、テンプレート領域は実行形式プログラム1の静的データ領域に確保される。
【0018】
テンプレート領域を確保した後に、ステップS29、S30、S31において、確保したテンプレート領域の、初期値が指定されている要素に対応する箇所に指定されている初期値を設定する。初期値が指定されていない要素に対しては何も値を設定しない。従って、そのような要素は値が不定値となる。
図7及び図8はソースプログラムの一部を示す例である。ともに、サブルーチンの定義部分の先頭を示していて、要素に初期値が設定されているか否かが部分的に相違する以外は同じである。
【0019】
図7において、第1行目はサブルーチンの定義の開始を示す行である。文字列subroutineが定義の開始を意味し、subはサブルーチンの名前がsubであることを示す。括弧で括られたvarはサブルーチンsubにはパラメータが一つあって、その名前がvarであることを示している。
サブルーチン内で定義される変数は全て動的変数である。即ちサブルーチン内で定義される構造体変数は動的構造体変数である。動的構造体変数を含む動的変数は実行形式プログラム1を実行中にプログラムの動的データ領域内に動的に確保される。サブルーチンのパラメタも同様である。
【0020】
2行目から9行目は動的構造体変数の型を定義している。2行目のtypeが型の定義の開始を示し、9行目のend typeが動的構造体変数の型の定義の終了を示す。また、2行目のaは定義する型の型名がaであることを示す。
3行目から8行目はそれぞれ動的構造体変数を構成する要素を定義している。各行のintegerは要素が整数型であることを意味し、二つのコロン(::)に続く文字列(a1、a2、a3、a4、a5、a6)はそれぞれ要素名を示し、要素名に続く等号(=)に続く数値(1、2、3、4、5、6)はそれそれの要素に対する初期値を示している。
【0021】
10行目は1行目のvarが型aの構造体変数を要素とする3要素の配列変数であることを示している。
図8に示したソースプログラムも基本的には図7に示したものと同様の定義をするものである。ただし、図8に示したソースプログラムは要素a5のみに対して初期値を指定している。
【0022】
構文解析部9のにおいて動的構造体変数を検出した場合には、図7に示したソースプログラムでは図5中のステップS27においてYの判定となり、図8に示したソースプログラムでは図5中のステップS27においてNの判定となる。
構文解析部9で中間言語を作成する際には、図6に示すフローチャートに従って中間言語が生成される。
【0023】
まず、ステップS41において、未定義値検出オプションが指示されているか否かをチェックする。オプションが指示されている場合にはステップS42にすすみ、指示されていない場合にはステップS43に進む。ステップS43に進んだ場合、さらに、初期値が指定されている要素が動的構造体変数を構成する要素の1/5以上であるかどうか判定し、1/5以上の場合にはステップS42に進み、1/5未満の場合にはステップS44に進む。
【0024】
なお、判定の基準は必ずしも1/5である必要はなく、図5のステップS27の判定と一致していればよい。
ステップS42では、図5のステップS22またはS28において領域を確保したテンプレートを用いて動的構造対変数を初期化するための中間言語を生成する。ここでは、テンプレート領域のデータを変数領域に一括して転送するための中間言語を生成する。
【0025】
図9にステップS42で生成される中間言語の一例を示す。図9に示した中間言語は、図7に示したソースプログラムをコンパイルする場合や、図8に示したソースプログラムを未定義値検出オプションを指示してコンパイルする場合に生成される。
1行目と3行目は、変数iを1から3まで変化させながら2行目を繰り返し実行することを意味している。2行目のCMOVEは指定された二つの領域の間で指定されたバイト数のデータ転送を一括して行なうことを意味している。CMOVEの第一パラメータはデータの転送先を、第二パラメータは転送元を、第三パラメータは転送データのバイト数を示している。
【0026】
一般にコンピュータのCPUは連続するデータをある領域から別の領域に一括して転送する命令を備えており、CMOVE中間言語はコード生成部11においてそのような命令に変換される。
図10にステップS44で生成される中間言語の一例を示す。図10に示した中間言語は、図8に示したソースコードを未定義値検出オプションを指定せずにコンパイルする場合に生成される。
【0027】
1行目と4行目は、変数iを1から3まで変化させながら、2行目から3行目を繰り返し実行することを意味している。2行目はレジスタrに数値5をロードすることを意味している。3行目はレジスタrに格納されている値(この場合は5)を動的構造体変数の配列であるvarのi番目の配列要素の構造体要素a5にストアすることを意味している。
【0028】
一般にコンピュータのCPUはレジスタに値を設定するためのロード命令およびメモリに値を格納するためのストア命令、またはこれらの命令に相当する命令を備えており、図10に示した中間言語はコード生成部11において、これらの命令に変換される。
また、一般にCPUの一括データ転送命令によるデータ転送と、ロード/ストア命令によるデータ転送とを比較した場合、転送対象のデータ量が少量の場合はロード/ストア命令による転送の方がより高速に実行されるが、連続する多量のデータを転送する場合には一括データ転送命令の方が高速に実行される。
【0029】
以上説明したようなコンパイラ6の仕組み、特に構文解析部9の仕組みによって、動的構造体変数の高速な初期化の設定、未定義値の検出が可能となる。
また、プログラムの動的データ領域はプログラムの実行時にライブラリ2を呼び出すことで実現される場合、ライブラリの領域確保ルーチンの中で、領域確保とともに動的構造体変数の領域にテンプレート領域の内容をコピーするようにしてもよい。実行形式プログラム1がライブラリを呼び出す際には、獲得すべき領域のサイズを決定するために必要な情報(サイズそのものまたは構造体のサイズと構造体を要素とする配列の配列要素数)とテンプレートのアドレスとをライブラリにパラメタとして渡す。これらのパラメタを受け取ったライブラリは領域を獲得するとともに、指定されたアドレスに存在するテンプレートの内容を獲得した領域に繰り返し複写することで初期化を行なう。こうすると、実行形式プログラム1のサイズを小さくすることが可能となる。
【0030】
【発明の効果】
本願発明によれば、動的構造体変数の型定義と共に初期値を設定することがかのうとなり、ソースプログラムの作成者は構造体変数を獲得する度に値を設定するように記述する必要がなくなる。
また、テンプレートは一つの型に対して一つしか作成しないので、実行形式プログラムのサイズを小さくすることが可能となる。
【0031】
また、動的変数領域へのテンプレートの内容の複写は一括データ転送命令で実行されるようなコードが生成されるので、効率の良い動的構造体変数の初期化が可能となる。
また、常にテンプレートを使用するのではなく、動的構造体変数を構成する要素の中で初期値が指定されている要素が少ない場合には、テンプレートを使わずに初期値を設定するようなコードを生成するので、実行効率のよい実行形式プログラムを作成することが可能となる。
【0032】
また、テンプレートの内容を獲得した領域にコピーする処理を、複数の実行形式プログラムで共用されるライブラリの動的領域獲得ルーチン内で、動的領域の獲得と共に行なうことで、実行形式プログラムのサイズを小さくすることが可能となる。
さらに、動的構造体変数のいずれの要素についても、初期値が設定されているか否かのチェックが可能となり、未定義値の検出をもれなく行なうことが可能となる。
【図面の簡単な説明】
【図1】 コンピュータ上でのプログラムの実行を示す図。
【図2】 コンピュータ上でのプログラム開発環境を示す図。
【図3】 コンパイラの構造及び作用を示す図。
【図4】 リンカの作用を示す図。
【図5】 構造解析部における処理の一部を示す第一の図。
【図6】 構造解析部における処理の一部を示す第二の図。
【図7】 ソースプログラムの一例を示す第一の図。
【図8】 ソースプログラムの一例を示す第二の図。
【図9】 中間言語の一例を示す第一の図。
【図10】 中間言語の一例を示す第二の図。
【符号の説明】
1...実行形式プログラム
2...ライブラリ
3...OS(オペレーティングシステム)
4...コンピュータ
5...エディタ
6...コンパイラ
7...リンカ
8...ソースプログラム
12...オブジェクトプログラム
[0001]
BACKGROUND OF THE INVENTION
The present invention relates to a compiler that compiles an input source program to generate an object program, and particularly relates to initialization of a dynamic structure variable.
[0002]
[Prior art]
A computer program is usually an executable program by creating a source program (source code) described in some programming language, converting it into object code by a compiler, and linking one or more object codes.
[0003]
Many programming languages support structure variables as their grammar conventions. In addition, there are two types of variables: static variables whose storage area is acquired when an executable program is created, and dynamic variables whose storage area is dynamically acquired when the program is executed. .
Conventional compilers can set initial values for static variables (specify initial values when declaring variables), but cannot set initial values for dynamic structure variables. It was possible. This is because a static variable acquires a data area at the time of compilation, so it is possible to set a value at the time of compilation, whereas a dynamic variable has a data area at the time of compilation. This is because the value cannot be set during compilation.
[0004]
[Problems to be solved by the invention]
For this reason, the program developer had to describe setting of values for the variables separately from the declaration of the variables when creating the source program. In addition, since the value setting is described as a value setting for each element constituting the structure variable, the size of the executable program has been enlarged.
[0005]
Also, it was not possible to check whether or not a value has been set for each element of the structure when referring to the element.
The present invention solves the problem that an initial value cannot be set for a dynamic structure variable and other problems that occur in relation to this problem.
[0006]
[Means for solving problems]
Therefore, in the present invention, a compile apparatus that inputs a source program and outputs an object program, and an initial value setting area for storing an initial value to be set in a dynamic variable is static in the output object program. Initial value setting area acquisition means for acquiring, initial value setting area initialization means for setting an initial value for the acquired initial value setting area, and dynamic variable area dynamically acquired at the time of program execution In this case, the above problem is solved by a compiling device having variable initialization object code generation means for generating code for copying the contents of the initial value setting area to the dynamically acquired area.
[0007]
DETAILED DESCRIPTION OF THE INVENTION
FIG. 1 is a diagram schematically showing how a program is executed on a computer. The computer 4 includes a CPU (not shown), a main storage device (memory), an external storage device, a display device, a keyboard, and the like. Programs and data are stored as files in the external storage device. The execution format program 1 stored in the file of the external storage device is loaded onto the memory and executed by the CPU. The OS 3 controls computer hardware resources and executable programs. The library 2 is a kind of executable program, and is commonly called from a plurality of executable programs.
[0008]
In order to create the executable program 1, an editor 5, a compiler 6 and a linker 7 shown in FIG. 2 are used. The editor 5, the compiler 6, and the linker 7 are all executable programs. The editor 5 is used to create a source program 8 that is the basis of the executable program. The created source program is stored in the file as a source file.
[0009]
The compiler 6 is a program for converting the source program 8 into the object program 12, and includes a syntax analysis unit 9, an optimization processing unit 10, and a code generation unit 11, as shown in FIG.
The syntax analysis unit 9 reads the source program 8 stored in the file, performs syntax analysis according to a predetermined grammar rule, and generates a corresponding intermediate language. The optimization processing unit 10 converts the intermediate language generated by the syntax analysis unit 9 so that the execution efficiency is improved. The code generation unit 11 converts the intermediate language obtained by conversion by the optimization processing unit 10 into an object program 12 suitable for a computer on which the program is executed.
[0010]
As shown in FIG. 4, a plurality of object programs (12-1, 12-2, 12-3, etc.) generated by the compiler 6 are combined by a linker 7 to generate an executable program 1.
The compiler 6 is activated by inputting a command for executing the compiler 6 from the keyboard. When the compiler 6 is started, a command is used together with commands to specify the name of the source file storing the source program and various instructions to the compiler. An example of the option is an undefined value detection instruction option at the time of execution.
[0011]
The undefined value detection instruction option checks whether or not a value has already been assigned to a variable that is used in the program during program execution. This is an option for creating an executable program that displays an error message if there is not. When this option is instructed, it is necessary to perform some specific processing prior to referring to the variable. Therefore, the execution efficiency of the program is lowered, but it is very useful for debugging the program.
[0012]
When the syntax analysis unit 9 recognizes the definition of the dynamic structure variable during the syntax analysis of the source program, the processing shown in FIG. 5 is performed.
First, in step S21, it is checked whether an undefined value detection option is instructed. If an option is instructed, the process proceeds to step S22. If not, the process proceeds to step S27.
[0013]
When the option is instructed, a template area used for initializing the dynamic structure pair variable is secured in step S22. Here, when a template for a dynamic structure variable of the same type is already secured, a new template area is not secured. The template area is finally secured in a static data area included in the execution format program 1.
[0014]
Next, in steps S23, S24, S25, and S26, a value is set in the secured template area. If an initial value is specified for an element of a dynamic structure variable in the source program, the initial value specified in step S25 is set in an area in the template corresponding to that element. If the initial value is not specified, hexadecimal 8b8b8b8b is set in the same area. This value is used to check whether a value has already been set for an element of a dynamic structure variable in the program while the generated executable program 1 is being executed. Is done.
[0015]
That is, when accessing an element of a dynamic structure variable, if 8b8b8b8b is set, it is determined that a value has not been set for that element (undefined), otherwise a value is set. It can be determined that is set (defined). Although 8b8b8b8b is used here as a value for determining whether or not it is already defined, it is a value that is not used in the program or is used only with a very low probability and has no practical problem. Any value may be used.
[0016]
If the undefined value detection option is not specified in the determination in step S21, the source program 8 is applied to 1/5 or more of the plurality of elements of the dynamic structure variable in step S27. Check whether or not the initial value is specified. If an initial value is specified for an element of 1/5 or more, the process proceeds to step S28, and if it is less than 1/5, the process ends. Note that the value used as the criterion for determination here is not necessarily 1/5, and a value that provides the best execution efficiency of the generated program may be selected.
[0017]
In step S28, a template area used for initializing the dynamic structure variable is secured as in step S22. If a template for a dynamic structure variable of the same type has already been secured, a new template area is not secured. Further, the template area is secured in the static data area of the executable program 1.
[0018]
After securing the template area, in steps S29, S30, and S31, an initial value designated at a location corresponding to an element for which an initial value is designated in the secured template area is set. No value is set for an element whose initial value is not specified. Accordingly, such elements have indefinite values.
7 and 8 show examples of part of the source program. Both are the same except that the beginning of the definition part of the subroutine is shown, and whether or not an initial value is set for the element is partially different.
[0019]
In FIG. 7, the first line is a line indicating the start of subroutine definition. The character string subroutine means the start of the definition, and sub indicates that the name of the subroutine is sub. The var enclosed in parentheses indicates that the subroutine sub has one parameter and its name is var.
All variables defined within a subroutine are dynamic variables. That is, the structure variable defined in the subroutine is a dynamic structure variable. Dynamic variables including dynamic structure variables are dynamically secured in the dynamic data area of the program during execution of the executable program 1. The same applies to the parameters of the subroutine.
[0020]
The second to ninth lines define the dynamic structure variable type. The type on the second line indicates the start of the type definition, and the end type on the ninth line indicates the end of the type definition of the dynamic structure variable. Further, a in the second line indicates that the type name of the type to be defined is a.
The third to eighth lines define the elements constituting the dynamic structure variable. The integer in each line means that the element is an integer type, and the character strings (a1, a2, a3, a4, a5, a6) following the two colons (: :) indicate the element name and follow the element name. The numerical value (1, 2, 3, 4, 5, 6) following the equal sign (=) indicates the initial value for each element.
[0021]
The 10th line indicates that var in the 1st line is a three-element array variable having a structure variable of type a as an element.
The source program shown in FIG. 8 basically has the same definition as that shown in FIG. However, the source program shown in FIG. 8 designates an initial value only for the element a5.
[0022]
When the dynamic analysis unit 9 detects a dynamic structure variable in the syntax analysis unit 9, the source program shown in FIG. 7 determines Y in step S27 in FIG. 5, and the source program shown in FIG. In step S27, N is determined.
When the intermediate language is created by the syntax analysis unit 9, the intermediate language is generated according to the flowchart shown in FIG.
[0023]
First, in step S41, it is checked whether an undefined value detection option is instructed. If an option is instructed, the process proceeds to step S42. If not, the process proceeds to step S43. When the process proceeds to step S43, it is further determined whether or not the element for which the initial value is specified is 1/5 or more of the elements constituting the dynamic structure variable. If the element is 1/5 or more, the process proceeds to step S42. If it is less than 1/5, the process proceeds to step S44.
[0024]
Note that the criterion for determination does not necessarily have to be 1/5 as long as it matches the determination in step S27 of FIG.
In step S42, an intermediate language for initializing the dynamic structure pair variable is generated using the template in which the area is secured in step S22 or S28 of FIG. Here, an intermediate language for transferring the data in the template area collectively to the variable area is generated.
[0025]
FIG. 9 shows an example of the intermediate language generated in step S42. The intermediate language shown in FIG. 9 is generated when the source program shown in FIG. 7 is compiled, or when the source program shown in FIG. 8 is compiled by specifying an undefined value detection option.
The first and third lines mean that the second line is repeatedly executed while changing the variable i from 1 to 3. CMOVE in the second line means that data transfer of a specified number of bytes is performed at a time between two specified areas. The first parameter of CMOVE indicates the data transfer destination, the second parameter indicates the transfer source, and the third parameter indicates the number of bytes of transfer data.
[0026]
In general, a CPU of a computer is provided with an instruction for transferring continuous data at once from one area to another area, and the CMOVE intermediate language is converted into such an instruction by the code generator 11.
FIG. 10 shows an example of the intermediate language generated in step S44. The intermediate language shown in FIG. 10 is generated when the source code shown in FIG. 8 is compiled without specifying the undefined value detection option.
[0027]
The first and fourth lines mean that the second to third lines are repeatedly executed while changing the variable i from 1 to 3. The second line means that the numerical value 5 is loaded into the register r. The third line means that the value stored in the register r (5 in this case) is stored in the structure element a5 of the i-th array element of var, which is an array of dynamic structure variables.
[0028]
In general, the CPU of a computer has a load instruction for setting a value in a register and a store instruction for storing a value in a memory, or an instruction corresponding to these instructions. The intermediate language shown in FIG. The unit 11 converts these instructions.
In general, when comparing the data transfer by the CPU batch data transfer instruction and the data transfer by the load / store instruction, if the amount of data to be transferred is small, the transfer by the load / store instruction is executed faster. However, when transferring a large amount of continuous data, the batch data transfer instruction is executed at a higher speed.
[0029]
With the mechanism of the compiler 6 described above, particularly the mechanism of the syntax analysis unit 9, it is possible to set initialization of dynamic structure variables at high speed and detect undefined values.
If the dynamic data area of the program is realized by calling the library 2 when the program is executed, the contents of the template area are copied to the area of the dynamic structure variable in the library area allocation routine. You may make it do. When the executable program 1 calls the library, information necessary for determining the size of the area to be acquired (the size itself or the size of the structure and the number of array elements of the array including the structure) and the template Pass the address to the library as a parameter. The library that receives these parameters acquires an area and initializes it by repeatedly copying the contents of the template existing at the designated address to the acquired area. This makes it possible to reduce the size of the executable program 1.
[0030]
【The invention's effect】
According to the present invention, the initial value can be set together with the type definition of the dynamic structure variable, and the creator of the source program does not need to write the value every time the structure variable is acquired. .
Since only one template is created for one type, the size of the executable program can be reduced.
[0031]
Further, since the code that is executed by the batch data transfer instruction is generated for copying the contents of the template to the dynamic variable area, the dynamic structure variable can be efficiently initialized.
Also, instead of using a template all the time, code that sets an initial value without using a template when there are only a few elements that specify an initial value among the elements that make up a dynamic structure variable. Therefore, it is possible to create an executable program with high execution efficiency.
[0032]
In addition, the process of copying the contents of the template to the acquired area is performed together with the acquisition of the dynamic area in the dynamic area acquisition routine of the library shared by a plurality of executable programs, thereby reducing the size of the executable program. It can be made smaller.
Furthermore, it is possible to check whether or not an initial value is set for any element of the dynamic structure variable, and it is possible to detect all undefined values.
[Brief description of the drawings]
FIG. 1 is a diagram showing execution of a program on a computer.
FIG. 2 is a diagram showing a program development environment on a computer.
FIG. 3 is a diagram showing the structure and operation of a compiler.
FIG. 4 is a diagram showing the action of a linker.
FIG. 5 is a first diagram showing a part of processing in a structure analysis unit.
FIG. 6 is a second diagram showing a part of processing in the structure analysis unit.
FIG. 7 is a first diagram showing an example of a source program.
FIG. 8 is a second diagram showing an example of a source program.
FIG. 9 is a first diagram illustrating an example of an intermediate language.
FIG. 10 is a second diagram showing an example of an intermediate language.
[Explanation of symbols]
1. . . 1. Executable program . . Library 3. . . OS (Operating System)
4). . . Computer 5. . . Editor 6. . . Compiler 7. . . Linker8. . . Source program 12. . . Object program

Claims (4)

ソースプログラムを記憶装置から入力し、オブジェクトプログラムを記憶装置に出力するコンパイル装置であって、
動的構造体変数を構成する要素のなかで、初期値が指定されている要素の割合が所定値以上である場合に、動的変数に設定する初期値を記憶するための初期値設定領域を出力されるオブジェクトプログラム内に静的に獲得する初期値設定領域獲得手段と、
獲得した前記初期値設定領域に対して初期値を設定する初期値設定領域初期化手段と、
プログラムの実行時に動的変数の領域を動的に獲得した際に、動的構造体変数を構成する要素のなかで、初期値が指定されている要素の割合が所定値以上である場合に、前記初期値設定領域の内容を前記動的に獲得した領域に複写するコードを前記オブジェクトプログラム内に生成し、そうでない場合には、初期値が指定されている要素に対してのみ値を設定するコードを前記オブジェクトプログラム内に生成する変数初期化用オブジェクトコード生成手段と
を有するコンパイル装置。
A compiling device that inputs a source program from a storage device and outputs an object program to the storage device ,
An initial value setting area for storing the initial value to be set in the dynamic variable when the ratio of the elements for which the initial value is specified among the elements constituting the dynamic structure variable is greater than or equal to the predetermined value. Initial value setting area acquisition means for statically acquiring in the output object program;
Initial value setting area initializing means for setting an initial value for the acquired initial value setting area;
When the dynamic variable area is dynamically acquired at the time of program execution , among the elements that make up the dynamic structure variable, the ratio of the elements for which the initial value is specified is greater than or equal to the predetermined value. A code for copying the contents of the initial value setting area to the dynamically acquired area is generated in the object program. Otherwise, a value is set only for an element for which an initial value is specified. A compiling device comprising: variable initialization object code generation means for generating code in the object program .
前記初期値設定領域獲得手段は動的構造体変数の一つの型に対して初期値設定領域を一つだけ獲得する、請求項1記載のコンパイル装置。  2. The compiling apparatus according to claim 1, wherein said initial value setting area acquisition means acquires only one initial value setting area for one type of dynamic structure variable. 未定義値を検出するための所定の値を動的構造体変数の各要素に初期値として設定する手段を有する請求項1又は記載のコンパイル装置。 3. The compiling apparatus according to claim 1, further comprising means for setting a predetermined value for detecting an undefined value as an initial value in each element of the dynamic structure variable. コンピュータに、On the computer,
ソースプログラムを記憶装置から読み込ませ、  Read the source program from the storage device,
動的構造体変数を構成する要素のなかで、初期値が指定されている要素の割合が所定値以上である場合に、動的変数に設定する初期値を記憶するための初期値設定領域を出力するオブジェクトプログラム内に静的に獲得させ、  An initial value setting area for storing the initial value to be set in the dynamic variable when the ratio of the elements for which the initial value is specified among the elements constituting the dynamic structure variable is equal to or greater than the predetermined value. Statically acquired in the object program to be output,
獲得した前記初期値設定領域に対して初期値を設定させ、  Set an initial value for the acquired initial value setting area,
プログラムの実行時に動的変数の領域を動的に獲得した際に、動的構造体変数を構成する要素のなかで、初期値が指定されている要素の割合が所定値以上である場合に、前記初期値設定領域の内容を前記動的に獲得した領域に複写するコードを前記オブジェクトプログラム内に生成させ、そうでない場合には、初期値が指定されている要素に対してのみ値を設定するコードを前記オブジェクトプログラム内に生成させ、  When the dynamic variable area is dynamically acquired at the time of program execution, among the elements that make up the dynamic structure variable, the ratio of the elements for which the initial value is specified is greater than or equal to the predetermined value. A code for copying the contents of the initial value setting area to the dynamically acquired area is generated in the object program. Otherwise, a value is set only for an element for which an initial value is specified. Generate code in the object program,
生成されたオブジェクトプログラムを記憶装置に出力させる  Output the generated object program to the storage device
プログラムを記録したコンピュータ読取可能な記録媒体。  A computer-readable recording medium on which a program is recorded.
JP32896497A 1997-11-28 1997-11-28 Compilation device Expired - Fee Related JP3915208B2 (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
JP32896497A JP3915208B2 (en) 1997-11-28 1997-11-28 Compilation device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
JP32896497A JP3915208B2 (en) 1997-11-28 1997-11-28 Compilation device

Publications (2)

Publication Number Publication Date
JPH11161501A JPH11161501A (en) 1999-06-18
JP3915208B2 true JP3915208B2 (en) 2007-05-16

Family

ID=18216093

Family Applications (1)

Application Number Title Priority Date Filing Date
JP32896497A Expired - Fee Related JP3915208B2 (en) 1997-11-28 1997-11-28 Compilation device

Country Status (1)

Country Link
JP (1) JP3915208B2 (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2011036768A1 (en) * 2009-09-25 2011-03-31 株式会社 東芝 Simulation device

Also Published As

Publication number Publication date
JPH11161501A (en) 1999-06-18

Similar Documents

Publication Publication Date Title
US5586328A (en) Module dependency based incremental compiler and method
US8458678B2 (en) Compiler supporting programs as data objects
US6931627B2 (en) System and method for combinatorial test generation in a compatibility testing environment
US7707566B2 (en) Software development infrastructure
US6078744A (en) Method and apparatus for improving compiler performance during subsequent compilations of a source program
US6233733B1 (en) Method for generating a Java bytecode data flow graph
JP2013533533A (en) Workload distribution and parallelization within a computing platform
US8843920B2 (en) Systems and methods for deferring software implementation decisions until load time
JP4041248B2 (en) COMPILER DEVICE, COMPUTER-READABLE RECORDING MEDIUM CONTAINING COMPILING PROGRAM, AND COMPILING METHOD
US20090187896A1 (en) Compiler device, program, and recording medium
US9134973B2 (en) Dynamic compiling and loading at runtime
US8387020B1 (en) Verifying that a method has been implemented for a program written in a dynamic programming language
US8930925B2 (en) Method for enabling compilation of a Cobol source program utilizing a two-stage compilation process, the Cobol source program including a mix of Cobol, C++ or JAVA statements, and optional OpenMP directives
Doolin et al. JLAPACK–compiling LAPACK Fortran to Java
JP4652680B2 (en) Compiling method and apparatus, and compiler
WO2022172025A1 (en) Optimising computer program code
US20060107258A1 (en) Program, program code optimization method, program code compile method, program code, and information processing system
JP2022522880A (en) How to generate representations of program logic, decompilers, recompile systems and computer program products
JP3915208B2 (en) Compilation device
Katel et al. High performance gpu code generation for matrix-matrix multiplication using mlir: some early results
Sah et al. An introduction to the Rush language
JP7295469B2 (en) Function generation program, function generation method, and information processing device
Walker et al. An optimizing compiler for the Icon programming language
JP2006338190A (en) Mounting code developing system, and mounting code developing program
JP7295466B2 (en) Class generation program and class generation method

Legal Events

Date Code Title Description
A977 Report on retrieval

Free format text: JAPANESE INTERMEDIATE CODE: A971007

Effective date: 20060908

A131 Notification of reasons for refusal

Free format text: JAPANESE INTERMEDIATE CODE: A131

Effective date: 20060919

A521 Written amendment

Free format text: JAPANESE INTERMEDIATE CODE: A523

Effective date: 20061117

TRDD Decision of grant or rejection written
A01 Written decision to grant a patent or to grant a registration (utility model)

Free format text: JAPANESE INTERMEDIATE CODE: A01

Effective date: 20070116

A61 First payment of annual fees (during grant procedure)

Free format text: JAPANESE INTERMEDIATE CODE: A61

Effective date: 20070129

R150 Certificate of patent or registration of utility model

Free format text: JAPANESE INTERMEDIATE CODE: R150

FPAY Renewal fee payment (event date is renewal date of database)

Free format text: PAYMENT UNTIL: 20110216

Year of fee payment: 4

FPAY Renewal fee payment (event date is renewal date of database)

Free format text: PAYMENT UNTIL: 20110216

Year of fee payment: 4

FPAY Renewal fee payment (event date is renewal date of database)

Free format text: PAYMENT UNTIL: 20120216

Year of fee payment: 5

FPAY Renewal fee payment (event date is renewal date of database)

Free format text: PAYMENT UNTIL: 20130216

Year of fee payment: 6

FPAY Renewal fee payment (event date is renewal date of database)

Free format text: PAYMENT UNTIL: 20130216

Year of fee payment: 6

FPAY Renewal fee payment (event date is renewal date of database)

Free format text: PAYMENT UNTIL: 20140216

Year of fee payment: 7

LAPS Cancellation because of no payment of annual fees