JP3672207B2 - Program converter - Google Patents

Program converter Download PDF

Info

Publication number
JP3672207B2
JP3672207B2 JP12560797A JP12560797A JP3672207B2 JP 3672207 B2 JP3672207 B2 JP 3672207B2 JP 12560797 A JP12560797 A JP 12560797A JP 12560797 A JP12560797 A JP 12560797A JP 3672207 B2 JP3672207 B2 JP 3672207B2
Authority
JP
Japan
Prior art keywords
override
class
instruction
instruction sequence
information
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
JP12560797A
Other languages
Japanese (ja)
Other versions
JPH10320204A (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.)
Panasonic Corp
Panasonic Holdings Corp
Original Assignee
Panasonic Corp
Matsushita Electric Industrial Co 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 Panasonic Corp, Matsushita Electric Industrial Co Ltd filed Critical Panasonic Corp
Priority to JP12560797A priority Critical patent/JP3672207B2/en
Publication of JPH10320204A publication Critical patent/JPH10320204A/en
Application granted granted Critical
Publication of JP3672207B2 publication Critical patent/JP3672207B2/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】
【従来の技術】
オブジェクト指向言語には、多様性を構築する特別なメソッドとしてオーバーライドメソッドがある。オーバーライドメソッドとは、例えば、クラスAとクラスAを継承するクラスBがそれぞれ同じ型のメソッドfを持ちクラスBのオブジェクトに対してメソッドfを呼び出すと、その呼び出しがクラスAへのポインタやリファレンスを経由していてもクラスBのメソッドfが呼び出されるような機能を持つメソッドを言う。また、このような機能をオーバーライド機能と言う。
【0003】
オブジェクト指向言語C++(以下「C++言語」と言う)ではオーバーライドメソッドは仮想関数と呼ばれ、関数の先頭にvirtual指定子を付加することにより指定できる。また、C++言語ではメソッドは関数であり、関数fをクラスAで仮想関数に指定すればそのクラスAを継承するクラスBでもその関数fは自動的に仮想関数となる。
【0004】
また、オブジェクト指向言語Java(以下「Java言語」と言う)ではメソッドはデフォルトでオーバーライドメソッドとなる。
従来のオブジェクト指向言語のオーバーライドメソッド呼び出しの実現方法について、「注釈C++リファレンスマニュアル」(B.ストラウストラップ著トッパンISBN4−8101−8027−110.7c)の例を用いて説明する。
【0005】
図12はC++言語の仮想関数を含むクラス定義を示す図である。図中のvirtual指定子が先頭についている関数及びそれを継承した関数が仮想関数である。したがって、クラスAの関数f,g及びh、クラスBの関数f、g及びh並びにクラスCの関数f,g及びhが仮想関数である。
図13は、図12に示したクラスの継承関係を表す図である。クラスAはクラスBに継承され、さらにクラスBはクラスCに継承されている。
【0006】
図14は、図12に示したクラスで作成したオブジェクトのメモリ配置をクラス別に示す図である。クラスAを例にとると、一般に、メソッドアドレステーブル「A_vtbl」をオブジェクト外に配置し、このメソッドアドレステーブルのアドレス「A_vptr」のみをオブジェクト内に配置する。オブジェクト毎にメソッドアドレステーブルを配置しないので、同じクラスのオブジェクトを複数作成した場合にメモリのサイズがそれらの重複分だけ節約できる。ここで、「&A::f」はクラスAで定義された仮想関数fのアドレスを表す。仮想関数fを呼び出す場合は、まずオブジェクト内のメソッドアドレステーブル「A_vtbl」のアドレス「A_vptr」に基づいてこのメソッドアドレステーブル内の仮想関数のアドレス「&A::f」を読み出し、その後にこのアドレスを呼び出す事になる。
【0007】
図15はクラスCの仮想関数hの呼び出しを含む関数iをC++言語で記述した例を示す図である。ここで、iの引数はクラスCのオブジェクトへのポインタである。
図16は、図15の関数iを従来のプログラム変換装置で機械語命令列に 変換した例を示す図である。関数iは引数であるオブジェクトへのポインタをレジスタr0上に保持した状態で呼び出される。
【0008】
まず、クラスCのオブジェクトの中の仮想関数hへのポインタを命令「mov(r0+4),r1」でr1レジスタに転送する。次にこれを用いてメソッドアドレステーブル内のオフセット8を加算したところにある仮想関数hの実アドレス「&C::h」を命令「mov(r1+8),r1」でr1レジスタに転送し、命令「jsr r1」でr1のアドレスへ分岐している。ここで、命令「mov(r0+d),r1」はr0のアドレスにdを加算したアドレスで示されるメモリの内容をr1に読み出す命令を表し、命令「jsr r1」はr1のアドレスに分岐するサブルーチンコール命令を表し、命令「rts」は関数iからの復帰命令を表す。
【0009】
図17は、上記の関数hが仮想関数でない関数(以下「非仮想関数」と言う)として定義されていたと仮定した場合に、関数hの呼び出しを含む関数iを機械語命令列に変換した例を示す図である。
図16と図17を比較すると、仮想関数の呼び出しは4命令、非仮想関数の呼び出しは2命令である。
【0010】
【発明が解決しようとする課題】
しかしながら、上記のような従来のオブジェクト指向言語のオーバーライドメソッド呼び出しの実現方法は、オーバーライドメソッドに指定されたものは全て同様に処理するので、オーバーライド機能を使わないメソッドをオーバーライドメソッドに指定すると機械語命令列のコードサイズが大きくなり実行速度が遅くなるという問題点がある。
【0011】
また、プログラマがオーバーライド機能を使わないメソッドの全てをオーバーライドメソッドでないメソッド(以下「非オーバーライドメソッド」と言う)に指定するのは、いちいちオーバーライド機能を使うかどうかを考慮したり、設計段階でオーバーライド機能を使うかどうかを確定できないメソッドを後で非オーバーライドメソッドに指定したりしなければならず、プログラマの負担が大きくなる。
【0012】
さらに、java言語ではメソッドがオーバーライドメソッドでないことを表すfinal指定子が用意されているが、C++言語ではオーバーライドメソッドでないことを表す指定子が無いので、あるメソッドをクラスAでオーバーライドメソッドに指定すると、そのクラスAを継承するクラスBでそのメソッドを非オーバーライドメソッドに指定することができない。
【0013】
そこで、本発明はかかる問題点に鑑み、オブジェクト指向言語のオーバーライドメソッド呼び出し命令のコードサイズを縮小し、実行速度を向上させるプログラム変換装置を提供することを目的とする。
【0014】
【課題を解決するための手段】
本発明に係るプログラム変換装置は、オーバーライドメソッドを含むクラスの定義とオーバーライドメソッド呼び出し命令が含まれるオブジェクト指向言語のプログラムを機械語命令列に翻訳して実行ファイルを生成するプログラム変換装置であって、前記クラスの定義に基づいて全てのクラスの継承関係を継承関係情報として抽出する抽出手段と、全ての前記継承関係情報に基づいて前記オーバーライドメソッド呼び出し命令によって呼び出されるメソッドが属するクラスが継承されるか否かを判断する判断手段と、前記判断手段で継承されないと判断された場合に前記オーバーライドメソッド呼び出し命令をオーバーライドメソッドでない場合の機械語命令列に翻訳するメソッド翻訳手段を備えることを特徴とする。
【0015】
本発明は,1つの入力ファイルにプログラムの実行に必要な全てのクラス定義が含まれている場合に、全てのクラスの継承関係に基づいてオーバーライドメソッド呼び出し命令をオーバーライドメソッドでない場合もしくはオーバーライドメソッドである場合のどちらかに翻訳するという方法をとる。
これによって、あるクラスが他のクラスに全く継承されない場合にそのクラスで定義されるオーバーライドメソッドがオーバーライド機能を使うことができないという性質を利用して、オーバーライドメソッド呼び出し命令をオーバーライドメソッドでない場合の命令列に翻訳することができる。即ち、間接呼び出しを直接呼び出しにすることができる。
【0016】
また、本発明に係るプログラム変換装置は、オーバーライドメソッドを含むクラスの定義とオーバーライドメソッド呼び出し命令が含まれるオブジェクト指向言語のプログラムをファイル単位で機械語命令列に翻訳し出力ファイルとして出力する翻訳装置と、前記翻訳装置で翻訳された出力ファイルを連結して実行ファイルを生成する連結装置とを備えるプログラム変換装置であって、前記オブジェクト指向言語のプログラムにはオーバーライドメソッドを含むクラスの定義とオーバーライドメソッド呼び出し命令が含まれ、前記翻訳装置は、前記クラスの定義に基づいてファイル単位のクラスの継承関係を継承関係情報に翻訳する継承関係翻訳手段と、前記オーバーライドメソッド呼び出し命令をこの命令によって呼び出されるメソッドが属するクラスを表すメソッドクラス情報とこの命令によって呼び出されるメソッドがオーバーライドメソッドでない場合の機械語命令列を表す非オーバーライド情報とオーバーライドメソッドである場合の機械語命令列を表すオーバーライド情報とを含むメソッド命令列に翻訳するメソッド翻訳手段とを備え、前記連結装置は、前記翻訳装置で翻訳された全ての出力ファイルの中の全ての前記継承関係情報に基づいて前記オーバーライドメソッド呼び出し命令によって呼び出されるメソッドが属するクラスが継承されるか否かを判断する判断手段と、前記メソッド命令列を前記判断手段で継承されないと判断された場合にはオーバーライドメソッドでない場合の機械語命令列だけに置換し、一方、継承されると判断された場合にはオーバーライドメソッドである場合の機械語命令列だけに置換する置換手段とを備えることを特徴とする。
【0017】
入力ファイルが複数の場合、翻訳装置ではファイル単位のクラスの継承関係が判るだけで全てのクラスの継承関係は判らない。また、従来の連結装置ではクラスの継承関係は全く判らない。
本発明は、翻訳装置でファイル単位のクラスの継承関係を継承関係情報に翻訳し、連結装置で全ての前記継承関係情報を参照するので、連結装置において全てのクラスの継承関係が判る。さらに、翻訳装置でオーバーライドメソッド呼び出し命令を、オーバーライドメソッドでない場合とオーバーライドメソッドである場合の両方の命令列に翻訳し、連結装置でどちらかを選択するという方法をとる。
【0018】
これによって、あるクラスが他のクラスに全く継承されない場合にそのクラスで定義されるオーバーライドメソッドがオーバーライド機能を使うことができないという性質を利用して、オーバーライドメソッド呼び出し命令をオーバーライドメソッドでない場合の命令列に翻訳することができる。即ち、間接呼び出しを直接呼び出しにすることができる。
【0019】
【発明の実施の形態】
以下、本発明の実施の形態について、図面を用いて説明する。
図1は本発明のプログラム変換装置の構成を示す図である。便宜上、図1には入力ファイルA101、B102、出力ファイルA108、B109及び実行ファイル115も併せて記載している。ここで、この入力ファイルA101及びB102は高級言語で書かれたソースプログラムである。また、この出力ファイルA108及びB109は各入力ファイルを翻訳した機械語命令列である。さらに、この実行ファイル115はこの2つの出力ファイルを連結し、生成した機械語命令列である。なお、ここで言うファイルとは、入出力の単位となるソースプログラムや機械語命令列の集まりを指す。
【0020】
本装置は大別すると、翻訳部103及び連結部110で構成されている。
翻訳部103はファイル単位で実施され、クラス定義毎にクラスの継承関係を継承関係疑似命令に翻訳し、オーバーライドメソッド呼び出し命令を、この命令によって呼び出されるメソッドが属するクラスを表すメソッドクラス疑似命令、この命令によって呼び出されるメソッドがオーバーライドメソッドでない場合の機械語命令列及びオーバーライドメソッドである場合の機械語命令列に翻訳し、その他の翻訳しなかった命令を機械語命令列に翻訳し、出力ファイルとして出力する。
【0021】
ここでは、入力ファイルA101の入力により出力ファイルA108を、入力ファイルB102の入力により出力ファイルB109を出力する。
翻訳部103は、継承関係翻訳部104、メソッド呼び出し検出部105、メソッド翻訳部106及び命令翻訳部107を備えている。
継承関係翻訳部104はクラス定義毎に、クラスの継承関係を継承関係疑似命令に翻訳する。
【0022】
メソッド呼び出し検出部105は入力ファイル内のオーバーライドメソッド呼び出し命令を検出する。
メソッド翻訳部106は、メソッド呼び出し検出部105で検出されたオーバーライドメソッド呼び出し命令をメソッド命令列に翻訳する。ここでメソッド命令列は、この命令によって呼び出されるメソッドが属するクラスを表すメソッドクラス疑似命令、この命令によって呼び出されるメソッドがオーバーライドメソッドでない場合の機械語命令列、オーバーライドメソッドである場合の機械語命令列及びこれらを識別する疑似命令の総称とする。
【0023】
命令翻訳部107は、前記メソッド翻訳部106で翻訳しなかった命令を機械語命令列に翻訳する。
連結部110は翻訳部103で翻訳された出力ファイルの全てを、置換し連結して実行ファイルを生成する。ここでは、出力ファイルA108及びB109の入力により実行ファイル115を出力する。
【0024】
連結部110は、メソッド命令列検出部111、継承クラス判定部112、メソッド置換部113及びファイル連結部114を備えている。
メソッド命令列検出部111は入力された全ての出力ファイルの中から、メソッド翻訳部106により翻訳されたメソッド命令列を検出する。
継承クラス判定部112は、メソッド命令列検出部111で検出されたメソッド命令列中のメソッドクラス疑似命令からそのメソッドの属するクラスを認識し、そのクラスが他のクラスに継承されるかどうかを、全ての出力ファイル中の全ての継承関係疑似命令に基づいて判定する。
【0025】
メソッド置換部113は、メソッド命令列検出部111で検出されたメソッド命令列を、継承クラス判定部112によってメソッド命令列の属するクラスが継承されないクラスであると判定された場合にはオーバーライドメソッドでない場合の機械語命令列だけに置換し、逆に、継承されるクラスと判定された場合にはオーバーライドメソッドである場合の機械語命令列だけに置換し、全ての置換後全ての継承関係疑似命令を消去する。
【0026】
ファイル連結部114は、メソッド置換部113で置換されたファイルの全てを連結して実行ファイルを生成する。
図1のように構成したプログラム作成装置の動作をC++言語のプログラムを用いて説明する。
図2はC++言語の仮想関数を含むクラスXの定義、クラスXを継承するクラスYの定義、クラスXを継承するクラスZの定義、関数void i(Y*)の定義及び関数void j(Z*)の定義を示す図である。ここでは、図1中の入力ファイルA101に納められる。
【0027】
図3は、図2に示したクラスの継承関係を表す図である。クラスXはクラスY及びクラスZに継承されている。
図4はC++言語の仮想関数を含むクラスXの定義、クラスXを継承するクラスYの定義、クラスXを継承するクラスZの定義、クラスZを継承するクラスWの定義及び関数void k(W*)の定義を示す図である。ここでは、図1中の入力ファイルB102に納められる。なお、簡単のために説明に関係しないメソッドの定義、プログラム及び以後の処理内容の表記は省略する。ただし、プログラムの実行に必要なクラスの定義はすべて表記されているものとする。
【0028】
図5は、図4に示したクラスの継承関係を表す図である。クラスXはクラスY及びクラスZに、クラスZはクラスWに継承されている。
入力ファイルA101には図2に示したC++言語のソースプログラムが、入力ファイルB102には図4に示したC++言語のソースプログラムが納められている。
【0029】
翻訳部103は図2に示した入力ファイルA101の入力により、図6で示した出力ファイルA108を出力する。
同様にして、翻訳部103は図4に示した入力ファイルB102の入力により、図7で示した出力ファイルB109を出力する。
連結部110は、図6に示した出力ファイルA108及び図7に示した出力ファイルB109の入力により、図8で示した実行ファイル115を出力する。
【0030】
また、ここで用いられている機械語命令列等の意味は以下のとうりである。
.BASE name : nameで表されるクラスが、別のクラスから継承されていることを表す継承関係疑似命令である。
_i_FP1Y : 関数void i(Y*)のアドレスを表すラベルである。
【0031】
.METHOD S : メソッド命令列の先頭を表す疑似命令である。
.CLASS name : メソッドの属するクラスを表すメソッドクラス疑似命令である。
jsr Label : Labelで表されるアドレスに分岐するサブルーチンコール命令である。
【0032】
_h_1Y : クラスYの仮想関数void h(void)のアドレスを表すラベルである。
.METHOD M : オーバーライドメソッドでない場合の命令列とオーバーライドメソッドである場合の命令列を区切る疑似命令である。
mov(r0+4),r1: r0+4をアドレスとするメモリの内容をr1にロードする転送命令である。
【0033】
mov(r1+0),r1: r1をアドレスとするメモリの内容をr1にロードする転送命令である。
jsr r1 : レジスタr1に格納されたアドレスに分岐するサブルーチンコール命令である。
.METHOD E : メソッド命令列の終端を表す疑似命令である。
【0034】
rts : 関数からの復帰命令である。
_j_FP1Z : 関数void j(Z*)のアドレスを表すラベルである。
_h_1Z : クラスZの仮想関数void h(void)のアドレスを表すラベルである。
【0035】
_k_FP1W : 関数void k(W*)のアドレスを表すラベルである。
_h_1W : クラスWの仮想関数void h(void)のアドレスを表すラベルである。
ここから、翻訳部103の詳細な動作について説明する。
【0036】
図9は翻訳部103の動作フローチャートを示す図である。
まず、入力ファイルA101が入力される。ここでは、図2に示したC++言語のプログラムが入力された場合を考える(ステップ901)。
次に、継承関係翻訳部104の処理が終了したかどうかを判定する。終了してなければクラス情報を取得しに行き、終了していたらメソッド呼び出し検出部105の処理へ行く。ここでは、クラスX、クラスY及びクラスZの定義毎に順次クラス情報を取得しに行き、その後メソッド呼び出し検出部105の処理へ行く(ステップ902)。
【0037】
未処理のクラス定義がある場合は、クラス定義毎にクラス情報を取得する。ここでは、クラスX、クラスY及びクラスZの定義毎に順次クラス情報を取得する(ステップ903)。
次に、取得したクラス定義毎のクラス情報からこのクラスが他のクラスを継承しているかどうかを判定する。Yesなら継承関係を翻訳しに行き、Noなら終了判定へ戻る。ここでは、クラスXの場合は他のクラスを継承していないので終了判定へ戻り、クラスY及びクラスZの場合はクラスXを継承しているので順次継承関係を翻訳しに行く(ステップ904)。
【0038】
このクラスが他のクラスを継承している場合は、クラスの継承関係を継承関係疑似命令に翻訳する。ここでは、クラスY及びクラスZがクラスXを継承しているので継承しているクラス名を継承関係疑似命令「.BASE 1X」に翻訳し、終了判定へ戻る(ステップ905)。なお、継承関係疑似命令は、継承されるクラスのクラス名と継承するクラスのクラス名とをペアで表すものであってもよい。この様にすると、全てのクラスの継承関係を連結装置で完全に再現できるので、全てのクラスの継承関係はもとより、オーバーライドメソッド呼び出し命令をオーバーライドメソッドでない場合の命令列に翻訳した場合にその根拠となった情報等を参照用に出力することもできる。
【0039】
継承関係翻訳部104の処理が終了すると、次に、メソッド呼び出し検出部105の処理が終了したかどうかを判定する。終了してなければオーバーライドメソッド呼び出し命令を検出しに行き、終了していたら従来の翻訳処理へ行く。ここでは、関数「void i(Y*)」の仮想関数呼び出し命令及び関数「void j(Z*)」の仮想関数呼び出し命令について順次命令を検出しに行き、その後従来の翻訳処理へ行く(ステップ906)。
【0040】
未処理のオーバーライドメソッド呼び出し命令がある場合は、これを検出する。ここでは、関数「void i(Y*)」及び関数「void j(Z*)」の仮想関数呼び出し命令を順次検出し、メソッド命令列に翻訳しに行く(ステップ907)。
次に、検出されたオーバーライドメソッド呼び出し命令をメソッド翻訳部106がメソッド命令列に翻訳する。ここでは、関数「void i(Y*)」及び関数「void j(Z*)」の仮想関数呼び出し命令をメソッド命令列に順次翻訳し、終了判定へ戻る(ステップ908)。ここで、関数「void i(Y*)」のメソッド命令列は、図6で示される出力ファイルA108前半の「.METHOD S」で始まり「.METHOD E」で終了する部分である。このメソッド命令列に含まれている「.CLASS 1Y」はこの命令によって呼び出されるメソッドがクラスYに属することを表すメソッドクラス疑似命令であり、「.CLASS 1Y」と「.METHOD M」の間にある機械語命令列はこの命令によって呼び出されるメソッドがオーバーライドメソッドでない場合の機械語命令列であり、「.METHOD M」と「.METHOD E」の間にある機械語命令列はオーバーライドメソッドである場合の機械語命令列である。なお、機械語命令列を生成する方法は従来と同様なので説明を省略する。また、関数「void j(Z*)」のメソッド命令列は関数「void i(Y*)」と同様なので説明を省略する。
【0041】
図10はメソッド命令列を示す図である。
なお、メソッド命令列は常に同じ形式となるので図10(a)に示すメソッド命令列を、図10(b)に示すようにメソッドクラス疑似命令及び1つのマクロ命令で表してもよいし、図10(c)に示すようにメソッドクラス疑似命令の情報も含め1つのマクロ命令で表してもよい。ここで、図10(b)でマクロ名「jsrv」の後ろに順に出力しているのは、オーバーライドメソッド呼び出し命令によって呼び出されるメソッドがオーバーライドメソッドでない場合に呼び出すラベル名、オーバーライドメソッドである場合に使用するオブジェクトの先頭からのオフセット値、オーバーライドメソッドである場合に使用するメソッドアドレス格納テーブルの先頭からのオフセット値及びオーバーライドメソッドである場合に使用するレジスタ名であり、図10(c)でマクロ名「jsrw」の後ろに順に出力しているのは、オーバーライドメソッド呼び出し命令によって呼び出されるメソッドの属するクラス名、このオーバーライドメソッド呼び出し命令によって呼び出されるメソッドがオーバーライドメソッドでない場合に呼び出すラベル名、オーバーライドメソッドである場合に使用するオブジェクトの先頭からのオフセット値、オーバーライドメソッドである場合に使用するメソッドアドレス格納テーブルの先頭からのオフセット値及びオーバーライドメソッドである場合に使用するレジスタ名である。なお、オーバーライドメソッドである場合に使用するレジスタ名は固定しておけば必ずしも必要ではない。
【0042】
メソッド呼び出し検出部105の処理が終了すると、次に、メソッド翻訳部106で翻訳しなかった命令を命令翻訳部107が機械語命令列に翻訳する。なお、この処理は従来の翻訳装置が行なう処理と異ならないので詳しい説明を省略する(ステップ909)。
次に、出力ファイルA108を出力する。ここでは、図6に示した出力ファイルを出力する(ステップ910)。
【0043】
続いて、入力ファイルB102が入力される。ここでは、図4に示したC++言語のプログラムが入力された場合を考える(ステップ901)。
次に、クラスX、クラスY、クラスZ及びクラスWの定義毎に順次クラス情報を取得しに行き、その後メソッド呼び出し検出部105の処理へ行く(ステップ902)。
【0044】
未処理のクラス定義がある場合は、クラスX、クラスY、クラスZ及びクラスWの定義毎に順次クラス情報を取得する(ステップ903)。
次に、クラスXの場合は他のクラスを継承していないので終了判定へ戻り、クラスY及びクラスZの場合はクラスXを継承し、クラスWの場合はクラスZを継承しているので順次継承関係を翻訳しに行く(ステップ904)。
【0045】
クラスY及びクラスZがクラスXを継承しているので継承しているクラス名を継承関係疑似命令「.BASE 1X」に翻訳し、クラスWがクラスZを継承しているので継承しているクラス名を継承関係疑似命令「.BASE 1Z」に翻訳し、順次終了判定へ戻る(ステップ905)。
継承関係翻訳部104の処理が終了すると、次に、関数「void k(W*)」の仮想関数呼び出し命令について命令を検出しに行き、その後従来の翻訳処理へ行く(ステップ906)。
【0046】
未処理のオーバーライドメソッド呼び出し命令がある場合は、関数「voidk(W*)」の仮想関数呼び出し命令を検出し、メソッド命令列に翻訳しに行く(ステップ907)。
次に、関数「void k(W*)」の仮想関数呼び出し命令をメソッド命令列に翻訳し、終了判定へ戻る(ステップ908)。関数「void k(Z*)」のメソッド命令列は関数「void i(Y*)」と同様なので説明を省略する。
【0047】
メソッド呼び出し検出部105の処理が終了すると、次に、メソッド翻訳部106で翻訳しなかった命令を命令翻訳部107が機械語命令列に翻訳する。なお、この処理は従来の翻訳装置が行なう処理と異ならないので詳しい説明を省略する(ステップ909)。
次に、出力ファイルB109を出力する。ここでは、図7に示した出力ファイルを出力する(ステップ910)。
【0048】
続いて、連結部110の詳細な動作について説明する。
図11は連結部110の動作フローチャートを示す図である。
まず、出力ファイルA108及び出力ファイルB109が入力される。ここでは、図6に示した出力ファイル及び図4に示した出力ファイルが入力された場合を考える(ステップ1101)。
【0049】
次に、メソッド命令列検出部111の処理が終了したかどうかを判定する。終了してなければ命令列を検出しに行き、終了していたら承継関係疑似命令を消去しに行く。ここでは、関数「void i(Y*)」のメソッド命令列、関数「void j(Z*)」のメソッド命令列及び関数「void k(W*)」のメソッド命令列について順次命令列を検出しに行き、その後承継関係疑似命令を消去しに行く(ステップ1102)。
【0050】
未処理のメソッド命令列がある場合は、入力された全ての出力ファイルの中からメソッド命令列を検出する。ここでは、関数「void i(Y*)」、関数「void j(Z*)」及び関数「void k(W*)」のメソッド命令列を順次検出し、そのクラスが継承されるかを判定に行く(ステップ1103)。次に、検出されたメソッド命令列中のメソッドクラス疑似命令からそのメソッドの属するクラスを認識し、そのクラスが他のクラスに継承されるかどうかを、全ての出力ファイル中の全ての継承関係疑似命令に基づいて判定する。ここでは、まず、関数「void i(Y*)」のメソッド命令列中のメソッドクラス疑似命令「.CLASS 1Y」からクラスYを認識し、全ての出力ファイル中の全ての継承関係疑似命令「.BASE 1X」及び「.BASE 1Z」に基づいてクラスYが他のクラスに継承されないことを判定し、オーバーライドメソッドでない場合の命令列に置換しに行き、次に、関数「void j(Z*)」のメソッドクラス疑似命令「.CLASS 1Z」からクラスZを認識し、出力ファイルB109中の継承関係疑似命令「.BASE 1Z」に基づいてクラスZが他のクラスに継承されることを判定し、オーバーライドメソッドである場合の命令列に置換しに行き、次に、関数「void k(W*)」のメソッド命令列中のメソッドクラス疑似命令「.CLASS 1W」からクラスWを認識し、全ての出力ファイル中の全ての継承関係疑似命令「.BASE 1X」及び「.BASE 1Z」に基づいてクラスWが他のクラスに継承されないことを判定し、オーバーライドメソッドでない場合の命令列に置換しに行く(ステップ1104)。
【0051】
そのメソッドの属するクラスが他のクラスに継承されないと判定された場合には、メソッド命令列検出部111で検出されたメソッド命令列をメソッド置換部113が、オーバーライドメソッドでない場合の機械語命令列だけに置換する。ここでは、関数「void i(Y*)」のメソッド命令列を命令「jsr _h_1Y」に、関数「void j(W*)」のメソッド命令列を命令「jsr _h_1W」に順次置換し終了判定へ戻る(ステップ1105)。
【0052】
そのメソッドの属するクラスが他のクラスに継承されると判定された場合には、メソッド命令列検出部111で検出されたメソッド命令列をメソッド置換部113が、オーバーライドメソッドである場合の機械語命令列だけに置換する。ここでは、関数「void j(Z*)」のメソッド命令列を命令「mov (r0+4),r1」、「mov (r1+0),r1」及び「jsr r1」に置換し終了判定へ戻る(ステップ1106)。
【0053】
メソッド命令列検出部111の処理が終了すると、次に、全ての継承関係疑似命令を、メソッド置換部113が消去する。ここでは、継承関係疑似命令「.BASE 1X」及び「.BASE 1Z」を消去する(ステップ1107)。
次に、メソッド置換部113で置換されたファイルの全てを、ファイル連結部114が連結して実行ファイルを生成する。なお、上記のファイルを連結する処理は従来の連結装置が行なう処理と異ならないので詳しい説明を省略する(ステップ1108)。
【0054】
次に、実行ファイル115を出力する。ここでは、図8に示した実行ファイルを出力する(ステップ1109)。
なお、本実施例でメソッド置換部113が行う処理は、図10(a)に示すようにメソッド命令列がオーバーライドメソッドでない場合の命令列とオーバーライドメソッドである場合の命令列の両方をそのままの形で含んでいる場合にはこのメソッド命令列から不必要な部分を除くだけの処理となり、メソッド命令列が図10(b)(c)に示すようなマクロ命令の場合にはこのマクロ命令に基づいて必要な命令列を生成する処理となる。
【0055】
また、本実施例では翻訳装置と連結装置とを備えるとしたが、連結装置は必ずしも必要ではない。1つの入力ファイルにプログラムの実行に必要な全てのクラス定義が含まれている場合には、この入力ファイルを翻訳するだけのプログラム変換装置であってもよく、この入力ファイルは複数の入力ファイルからあらかじめ連結されて生成されたものであってもよい。この場合には、プログラム変換装置は、クラス定義で継承しているクラス名を疑似命令に翻訳したり、オーバーライドメソッド呼び出し命令をメソッド命令列に翻訳したり、メソッド命令列を置換したりする必要がなく、クラスの定義に基づいて全てのクラスの継承関係を抽出し、オーバーライドメソッド呼び出し命令をオーバーライドメソッドでない場合もしくはオーバーライドメソッドである場合のどちらかに翻訳するものであればよい。
【0056】
また、本実施例のプログラム変換装置は本実施例を実現するプログラムを汎用のコンピュータに読み取らせることで実現可能である。従って、このプログラムを記録したコンピュータ読み取り可能な記憶媒体のみの移動により容易に譲渡される。
【0057】
【発明の効果】
(イ)以上の説明から明かなように、本発明に係るプログラム変換装置は、オブジェクト指向言語のプログラムを機械語命令列に翻訳して実行ファイルを生成するプログラム変換装置であって、前記オブジェクト指向言語のプログラムにはオーバーライドメソッドを含むクラスの定義とオーバーライドメソッド呼び出し命令が含まれ、前記クラスの定義に基づいて全てのクラスの継承関係を継承関係情報として抽出する抽出手段と、全ての前記継承関係情報に基づいて前記オーバーライドメソッド呼び出し命令によって呼び出されるメソッドが属するクラスが継承されるか否かを判断する判断手段と、前記判断手段で継承されないと判断された場合に前記オーバーライドメソッド呼び出し命令をオーバーライドメソッドでない場合の機械語命令列に翻訳するメソッド翻訳手段を備えることを特徴とする。
【0058】
本発明は,1つの入力ファイルにプログラムの実行に必要な全てのクラス定義が含まれている場合に、全てのクラスの継承関係に基づいてオーバーライドメソッド呼び出し命令をオーバーライドメソッドでない場合もしくはオーバーライドメソッドである場合のどちらかに翻訳するという方法をとる。
これによって、あるクラスが他のクラスに全く継承されない場合にそのクラスで定義されるオーバーライドメソッドがオーバーライド機能を使うことができないという性質を利用して、オーバーライドメソッド呼び出し命令をオーバーライドメソッドでない場合の命令列に翻訳することができる。即ち、間接呼び出しを直接呼び出しにすることができる。
【0059】
従って、この分だけオーバーライドメソッド呼び出し命令のコードサイズが縮小でき、実行速度が向上する。
(ロ)また、本発明に係るプログラム変換装置は、オブジェクト指向言語のプログラムをファイル単位で機械語命令列に翻訳し出力ファイルとして出力する翻訳装置と、前記翻訳装置で翻訳された出力ファイルを連結して実行ファイルを生成する連結装置とを備えるプログラム変換装置であって、前記オブジェクト指向言語のプログラムにはオーバーライドメソッドを含むクラスの定義とオーバーライドメソッド呼び出し命令が含まれ、前記翻訳装置は、前記クラスの定義に基づいてファイル単位のクラスの継承関係を継承関係情報に翻訳する継承関係翻訳手段と、前記オーバーライドメソッド呼び出し命令をこの命令によって呼び出されるメソッドが属するクラスを表すメソッドクラス情報とこの命令によって呼び出されるメソッドがオーバーライドメソッドでない場合の機械語命令列を表す非オーバーライド情報とオーバーライドメソッドである場合の機械語命令列を表すオーバーライド情報とを含むメソッド命令列に翻訳するメソッド翻訳手段とを備え、前記連結装置は、前記翻訳装置で翻訳された全ての出力ファイルの中の全ての前記継承関係情報に基づいて前記オーバーライドメソッド呼び出し命令によって呼び出されるメソッドが属するクラスが継承されるか否かを判断する判断手段と、前記メソッド命令列を前記判断手段で継承されないと判断された場合にはオーバーライドメソッドでない場合の機械語命令列だけに置換し、一方、継承されると判断された場合にはオーバーライドメソッドである場合の機械語命令列だけに置換する置換手段とを備えることを特徴とする。
【0060】
入力ファイルが複数の場合、翻訳装置ではファイル単位のクラスの継承関係が判るだけで全てのクラスの継承関係は判らない。また、従来の連結装置ではクラスの継承関係は全く判らない。
本発明は、翻訳装置でファイル単位のクラスの継承関係を継承関係情報に翻訳し、連結装置で全ての前記継承関係情報を参照するので、連結装置において全てのクラスの継承関係が判る。さらに、翻訳装置でオーバーライドメソッド呼び出し命令を、オーバーライドメソッドでない場合とオーバーライドメソッドである場合の両方の命令列に翻訳し、連結装置でどちらかを選択するという方法をとる。
【0061】
これによって、あるクラスが他のクラスに全く継承されない場合にそのクラスで定義されるオーバーライドメソッドがオーバーライド機能を使うことができないという性質を利用して、オーバーライドメソッド呼び出し命令をオーバーライドメソッドでない場合の命令列に翻訳することができる。即ち、間接呼び出しを直接呼び出しにすることができる。
【0062】
従って、この分だけオーバーライドメソッド呼び出し命令のコードサイズが縮小でき、実行速度が向上する。
(ハ)また、本発明に係るプログラム変換装置は前記(ロ)のプログラム変換装置において、前記メソッド翻訳手段は、前記非オーバーライド命令と、前記オーバーライド命令とを1つのマクロ命令で表すことを特徴とする。
【0063】
これによって、命令数が減少する。
従って、翻訳装置から出力される出力ファイルのファイルサイズが縮小でき、前記連結装置の実行速度が向上する。
(ニ)また、本発明に係るプログラム変換装置は前記(ロ)のプログラム変換装置において、前記メソッド翻訳手段は、前記メソッドクラス情報と、前記非オーバーライド命令と、前記オーバーライド命令とを1つのマクロ命令で表すことを特徴とする。
【0064】
これによって、前記メソッドクラス情報の命令も不要となり、命令数が減少する。また、マクロ命令が1行なので従来の連結装置が行う命令の書式と類似している。
従って、翻訳装置から出力される出力ファイルのファイルサイズが縮小でき、前記連結装置の実行速度が向上し、また、前記連結装置の追加変更を少なくすることができる。
【0065】
(ホ)また、本発明に係るプログラム変換装置は前記(ニ)のプログラム変換装置において、前記マクロ命令は、マクロ名と、前記メソッドクラス情報と、オーバーライドメソッドでない場合に呼び出すラベル名と、オーバーライドメソッドである場合に使用するオブジェクトの先頭からのオフセット値と、オーバーライドメソッドである場合に使用するメソッドアドレス格納テーブルの先頭からのオフセット値で構成されることを特徴とする。
【0066】
これによって、このマクロ命令の書式は従来の連結装置が行う命令の書式と類似する。
従って、前記連結装置の追加変更を少なくすることができる。
(ヘ)また、本発明に係るプログラム変換装置は前記(イ)、(ロ)、(ハ)、(ニ)又は(ホ)のプログラム変換装置において、前記継承関係情報は、クラスの定義において他のクラスに継承されているクラス名を表す情報であることを特徴とする。
【0067】
これによって、複数のクラスが同じクラスを継承している場合に、前記継承関係情報は複数必要なく、1つを共用することができる。
従って、翻訳装置から出力される出力ファイルのファイルサイズが縮小でき、前記連結装置の実行速度が向上する。
(ト)また、本発明に係るプログラムを記録したコンピュータ読み取り可能な記憶媒体は、オブジェクト指向言語のプログラムを機械語命令列に翻訳して実行ファイルを生成するプログラムを記録したコンピュータ読み取り可能な記憶媒体であって、前記オブジェクト指向言語のプログラムにはオーバーライドメソッドを含むクラスの定義とオーバーライドメソッド呼び出し命令が含まれ、前記クラスの定義に基づいて全てのクラスの継承関係を継承関係情報として抽出する抽出手順と、全ての前記継承関係情報に基づいて前記オーバーライドメソッド呼び出し命令によって呼び出されるメソッドが属するクラスが継承されるか否かを判断する判断手順と、前記判断手順で継承されないと判断された場合に前記オーバーライドメソッド呼び出し命令をオーバーライドメソッドでない場合の機械語命令列に翻訳するメソッド翻訳手順を備えることを特徴とする。
【0068】
本発明は,1つの入力ファイルにプログラムの実行に必要な全てのクラス定義が含まれている場合に、全てのクラスの継承関係に基づいてオーバーライドメソッド呼び出し命令をオーバーライドメソッドでない場合もしくはオーバーライドメソッドである場合のどちらかに翻訳するという方法をとる。
これによって、あるクラスが他のクラスに全く継承されない場合にそのクラスで定義されるオーバーライドメソッドがオーバーライド機能を使うことができないという性質を利用して、オーバーライドメソッド呼び出し命令をオーバーライドメソッドでない場合の命令列に翻訳することができる。即ち、間接呼び出しを直接呼び出しにすることができる。
【0069】
従って、この分だけオーバーライドメソッド呼び出し命令のコードサイズが縮小でき、実行速度が向上する。
(チ)また、本発明に係るプログラムを記録したコンピュータ読み取り可能な記憶媒体は、オブジェクト指向言語のプログラムをファイル単位で機械語命令列に翻訳し出力ファイルとして出力する翻訳手順と前記翻訳手順で翻訳された出力ファイルを連結して実行ファイルを生成する連結手順とを備えるプログラムを記録したコンピュータ読み取り可能な記憶媒体であって、前記オブジェクト指向言語のプログラムにはオーバーライドメソッドを含むクラスの定義とオーバーライドメソッド呼び出し命令が含まれ、前記翻訳手順は、前記クラスの定義に基づいてファイル単位のクラスの継承関係を継承関係情報に翻訳する継承関係翻訳手順と、前記オーバーライドメソッド呼び出し命令をこの命令によって呼び出されるメソッドが属するクラスを表すメソッドクラス情報とこの命令によって呼び出されるメソッドがオーバーライドメソッドでない場合の機械語命令列を表す非オーバーライド情報とオーバーライドメソッドである場合の機械語命令列を表すオーバーライド情報とを含むメソッド命令列に翻訳するメソッド翻訳手順とを備え、前記連結手順は、前記翻訳手順で翻訳された全ての出力ファイルの中の全ての前記継承関係情報に基づいて前記オーバーライドメソッド呼び出し命令によって呼び出されるメソッドが属するクラスが継承されるか否かを判断する判断手順と、前記メソッド命令列を前記判断手順で継承されないと判断された場合にはオーバーライドメソッドでない場合の機械語命令列だけに置換し、一方、継承されると判断された場合にはオーバーライドメソッドである場合の機械語命令列だけに置換する置換手順とを備えることを特徴とする。
【0070】
入力ファイルが複数の場合、翻訳手順ではファイル単位のクラスの継承関係が判るだけで全てのクラスの継承関係は判らない。また、従来の連結手順ではクラスの継承関係は全く判らない。
本発明は、翻訳手順でファイル単位のクラスの継承関係を継承関係情報に翻訳し、連結手順で全ての前記継承関係情報を参照するので、連結手順において全てのクラスの継承関係が判る。さらに、翻訳手順でオーバーライドメソッド呼び出し命令を、オーバーライドメソッドでない場合とオーバーライドメソッドである場合の両方の命令列に翻訳し、連結手順でどちらかを選択するという方法をとる。
【0071】
これによって、あるクラスが他のクラスに全く継承されない場合にそのクラスで定義されるオーバーライドメソッドがオーバーライド機能を使うことができないという性質を利用して、オーバーライドメソッド呼び出し命令をオーバーライドメソッドでない場合の命令列に翻訳することができる。即ち、間接呼び出しを直接呼び出しにすることができる。
【0072】
従って、この分だけオーバーライドメソッド呼び出し命令のコードサイズが縮小でき、実行速度が向上する。
【図面の簡単な説明】
【図1】本発明のプログラム変換装置の構成を示す図である
【図2】入力ファイルA101に納められる、C++言語の仮想関数を含むクラスXの定義、クラスXを継承するクラスYの定義、クラスXを継承するクラスZの定義、関数void i(Y*)の定義及び関数void j(Z*)の定義を示す図である。
【図3】図2に示したクラスの継承関係を表す図である。
【図4】入力ファイルB102に納められる、C++言語の仮想関数を含むクラスXの定義、クラスXを継承するクラスYの定義、クラスXを継承するクラスZの定義、クラスZを継承するクラスWの定義及び関数void k(W*)の定義を示す図である。
【図5】図4に示したクラスの継承関係を表す図である。
【図6】図2に示した入力ファイルA101の入力により、翻訳部103が出力する出力ファイルA108を示す図である。
【図7】図4に示した入力ファイルB102の入力により、翻訳部103が出力する出力ファイルB109を示す図である。
【図8】図6に示した出力ファイルA108及び図7に示した出力ファイルB109の入力により、連結部110が出力する実行ファイル115を示す図である。
【図9】翻訳部103の動作フローチャートを示す図である。
【図10】図10(a)はメソッド命令列を示す図である。図10(b)はメソッド命令列をメソッドクラス疑似命令及び1つのマクロ命令で表した図である。図10(c)はメソッド命令列をメソッドクラス疑似命令の情報も含め1つのマクロ命令で表した図である。
【図11】連結部110の動作フローチャートを示す図である。
【図12】C++言語の仮想関数を含むクラス定義を示す図である。
【図13】図12に示したクラスの継承関係を表す図である。
【図14】図12に示したクラスで作成したオブジェクトのメモリ配置をクラス別に示す図である。
【図15】クラスCの仮想関数hの呼び出しを含む関数iをC++言語で記述した例を示す図である。
【図16】図15の関数iを従来のプログラム変換装置で機械語命令列に 変換した例を示す図である。
【図17】上記の関数hが非仮想関数として定義されていたと仮定した場合に、関数hの呼び出しを含む関数iを機械語命令列に変換した例を示す図である。
【符号の説明】
101 入力ファイルA
102 入力ファイルB
103 翻訳部
104 継承関係翻訳部
105 メソッド呼び出し検出部
106 メソッド翻訳部
107 命令翻訳部
108 出力ファイルA
109 出力ファイルB
110 連結部
111 メソッド命令列検出部
112 継承クラス判定部
113 メソッド置換部
114 ファイル連結部
115 実行ファイル
[0001]
BACKGROUND OF THE INVENTION
The present invention relates to a program conversion apparatus that translates a program, and more particularly to a program conversion apparatus that reduces the code size of an override method call instruction of an object-oriented language and improves the execution speed.
[0002]
[Prior art]
Object oriented languages have override methods as special methods for building diversity. An override method is, for example, when class A and class B that inherits class A each have method f of the same type and call method f on an object of class B, the call returns a pointer or reference to class A. A method having a function that allows the method f of the class B to be called even though it is via. Such a function is called an override function.
[0003]
In the object-oriented language C ++ (hereinafter referred to as “C ++ language”), the override method is called a virtual function and can be specified by adding a virtual specifier to the head of the function. In the C ++ language, a method is a function. If the function f is designated as a virtual function in class A, the function f automatically becomes a virtual function in class B that inherits the class A.
[0004]
In the object-oriented language Java (hereinafter referred to as “Java language”), the method is an override method by default.
A conventional method for realizing an object-oriented language override method call will be described with reference to an example of “Annotation C ++ Reference Manual” (B. Straustrap Toppan ISBN 4-8101-8027-110.7c).
[0005]
FIG. 12 is a diagram showing a class definition including a virtual function of C ++ language. A function having a virtual specifier at the head and a function inheriting it are virtual functions in the figure. Therefore, the functions f, g and h of class A, the functions f, g and h of class B and the functions f, g and h of class C are virtual functions.
FIG. 13 is a diagram showing the inheritance relationship of the classes shown in FIG. Class A is inherited by class B, and class B is inherited by class C.
[0006]
FIG. 14 is a diagram showing the memory allocation of objects created by the class shown in FIG. 12 for each class. Taking class A as an example, generally, the method address table “A_vtbl” is arranged outside the object, and only the address “A_vptr” of this method address table is arranged in the object. Since the method address table is not arranged for each object, when multiple objects of the same class are created, the size of the memory can be saved by the overlap. Here, “& A :: f” represents the address of the virtual function f defined in the class A. When calling the virtual function f, first, the address “& A :: f” of the virtual function in the method address table is read based on the address “A_vptr” of the method address table “A_vtbl” in the object, and then this address is read. I will call it.
[0007]
FIG. 15 is a diagram illustrating an example in which a function i including a call to a virtual function h of class C is described in the C ++ language. Here, the argument of i is a pointer to an object of class C.
FIG. 16 is a diagram showing an example in which the function i in FIG. 15 is converted into a machine language instruction sequence by a conventional program conversion apparatus. The function i is called in a state where the pointer to the object as an argument is held in the register r0.
[0008]
First, the pointer to the virtual function h in the class C object is transferred to the r1 register by the instruction “mov (r0 + 4), r1”. Next, using this, the real address “& C :: h” of the virtual function h in the position where the offset 8 in the method address table is added is transferred to the r1 register by the instruction “mov (r1 + 8), r1”, and the instruction “ jsr r1 "branches to the address of r1. Here, the instruction “mov (r0 + d), r1” represents an instruction for reading the contents of the memory indicated by the address obtained by adding d to the address of r0 to r1, and the instruction “jsr r1” is a subroutine call that branches to the address of r1. The instruction “rts” represents a return instruction from the function i.
[0009]
FIG. 17 shows an example in which the function i including the call to the function h is converted into a machine language instruction sequence when the function h is defined as a function that is not a virtual function (hereinafter referred to as “non-virtual function”). FIG.
When FIG. 16 is compared with FIG. 17, the call of the virtual function is 4 instructions, and the call of the non-virtual function is 2 instructions.
[0010]
[Problems to be solved by the invention]
However, since the method for realizing the override method call of the conventional object-oriented language as described above handles all the items specified in the override method in the same way, if a method that does not use the override function is specified in the override method, the machine language instruction There is a problem that the code size of the column becomes large and the execution speed becomes slow.
[0011]
In addition, the programmer specifies all the methods that do not use the override function as methods that are not override methods (hereinafter referred to as “non-override methods”). Methods that cannot be determined whether or not to use must be specified later as non-override methods, which increases the burden on the programmer.
[0012]
Furthermore, although a final specifier indicating that a method is not an override method is prepared in the Java language, but there is no specifier indicating that the method is not an override method in the C ++ language, when a certain method is designated as an override method in the class A, The method cannot be designated as a non-override method in the class B that inherits the class A.
[0013]
Accordingly, an object of the present invention is to provide a program conversion apparatus that reduces the code size of an override method call instruction of an object-oriented language and improves the execution speed.
[0014]
[Means for Solving the Problems]
A program conversion apparatus according to the present invention is a program conversion apparatus that translates an object-oriented language program including a definition of a class including an override method and an override method calling instruction into a machine language instruction sequence to generate an execution file, Extraction means for extracting inheritance relationships of all classes as inheritance relationship information based on the definition of the class, and whether a class to which a method called by the override method call instruction belongs is inherited based on all the inheritance relationship information A judging means for judging whether or not, and a method translating means for translating the override method calling instruction into a machine language instruction string when it is determined not to be inherited by the judging means.
[0015]
In the present invention, when all class definitions necessary for program execution are included in one input file, the override method call instruction is not an override method or an override method based on the inheritance relationship of all classes. Take the method of translating into either case.
This takes advantage of the fact that if a class is not inherited at all by another class, the override method defined in that class cannot use the override function, the override method call instruction is not an override method. Can be translated into That is, an indirect call can be made a direct call.
[0016]
Further, the program conversion apparatus according to the present invention includes a translation apparatus that translates an object-oriented language program including a definition of a class including an override method and an override method calling instruction into a machine language instruction sequence on a file basis and outputs the machine language instruction sequence. And a concatenation device that concatenates output files translated by the translation device to generate an execution file, wherein the object-oriented language program defines a class including an override method and calls an override method. An instruction is included, and the translation device includes inheritance relationship translation means for translating the inheritance relationship of a file unit class into inheritance relationship information based on the definition of the class, and a method called by the instruction for the override method call command. A method instruction sequence that includes method class information that represents a class to be executed, non-override information that represents a machine language instruction sequence when the method called by this instruction is not an override method, and override information that represents a machine language instruction sequence when the method is an override method A method translation means for translating into a class to which the method called by the override method call instruction belongs based on all the inheritance relation information in all output files translated by the translation device. A determination means for determining whether the method instruction sequence is inherited, and if the determination means determines that the method instruction sequence is not inherited, the method instruction sequence is replaced only with a machine language instruction sequence for a case where the method is not an override method. If it is determined that Characterized in that it comprises a replacement means for replacing only machine language instruction sequence when it is de-method.
[0017]
When there are a plurality of input files, the translation device only knows the inheritance relationship of the class for each file, but not the inheritance relationship of all the classes. Moreover, the conventional inheritance device does not know the inheritance relationship of classes.
According to the present invention, the inheritance relationship of the file unit class is translated into the inheritance relationship information by the translation device, and all the inheritance relationship information is referred to by the connection device, so that the inheritance relationship of all the classes can be known in the connection device. Further, the method of translating the override method call instruction in the translation apparatus into an instruction sequence for both the case where it is not the override method and the case where it is the override method, and selecting either one in the concatenation apparatus.
[0018]
This takes advantage of the fact that if a class is not inherited at all by another class, the override method defined in that class cannot use the override function, and the override method call instruction is not an override method. Can be translated into That is, an indirect call can be made a direct call.
[0019]
DETAILED DESCRIPTION OF THE INVENTION
Hereinafter, embodiments of the present invention will be described with reference to the drawings.
FIG. 1 is a diagram showing the configuration of a program conversion apparatus according to the present invention. For convenience, FIG. 1 also shows input files A101 and B102, output files A108 and B109, and an execution file 115. Here, the input files A101 and B102 are source programs written in a high-level language. The output files A108 and B109 are machine language instruction sequences obtained by translating each input file. Further, the execution file 115 is a machine language instruction sequence generated by linking the two output files. The file mentioned here refers to a collection of source programs and machine language instruction sequences as input / output units.
[0020]
This apparatus is roughly composed of a translation unit 103 and a connection unit 110.
The translation unit 103 is implemented on a file-by-file basis, translates the class inheritance relationship into the inheritance relationship pseudo-instruction for each class definition, and converts the override method invocation instruction into a method class pseudo-instruction representing the class to which the method called by this instruction belongs, When the method called by the instruction is not an override method, it is translated into a machine language instruction string and when it is an override method, other untranslated instructions are translated into a machine language instruction string and output as an output file. To do.
[0021]
Here, the output file A108 is output by inputting the input file A101, and the output file B109 is output by inputting the input file B102.
The translation unit 103 includes an inheritance relationship translation unit 104, a method call detection unit 105, a method translation unit 106, and an instruction translation unit 107.
For each class definition, the inheritance relationship translation unit 104 translates the inheritance relationship of the class into an inheritance relationship pseudo-instruction.
[0022]
The method call detection unit 105 detects an override method call instruction in the input file.
The method translation unit 106 translates the override method call instruction detected by the method call detection unit 105 into a method instruction sequence. Here, the method instruction sequence is a method class pseudo-instruction representing the class to which the method called by this instruction belongs, a machine language instruction sequence when the method called by this instruction is not an override method, and a machine language instruction sequence when it is an override method And pseudo-instructions for identifying them.
[0023]
The instruction translation unit 107 translates an instruction that has not been translated by the method translation unit 106 into a machine language instruction sequence.
The concatenating unit 110 replaces and concatenates all the output files translated by the translating unit 103 to generate an execution file. Here, the execution file 115 is output by inputting the output files A 108 and B 109.
[0024]
The concatenation unit 110 includes a method instruction sequence detection unit 111, an inheritance class determination unit 112, a method replacement unit 113, and a file connection unit 114.
The method instruction sequence detection unit 111 detects the method instruction sequence translated by the method translation unit 106 from all input output files.
The inherited class determining unit 112 recognizes the class to which the method belongs from the method class pseudo instruction in the method instruction sequence detected by the method instruction sequence detecting unit 111, and determines whether or not the class is inherited by another class. Judgment is made based on all inheritance relation pseudo-instructions in all output files.
[0025]
The method replacement unit 113 is not an override method when the method instruction sequence detected by the method instruction sequence detection unit 111 is determined not to be inherited by the inheritance class determination unit 112. If it is determined that the class is inherited, it is replaced only by the machine language instruction sequence in the case of the override method. to erase.
[0026]
The file concatenation unit 114 concatenates all the files replaced by the method replacement unit 113 to generate an execution file.
The operation of the program creation apparatus configured as shown in FIG. 1 will be described using a C ++ language program.
FIG. 2 shows a definition of a class X including a virtual function of the C ++ language, a definition of a class Y that inherits the class X, a definition of a class Z that inherits the class X, a definition of the function void i (Y *), and a function void j (Z It is a figure which shows the definition of *). Here, it is stored in the input file A101 in FIG.
[0027]
FIG. 3 is a diagram showing the inheritance relationship of the classes shown in FIG. Class X is inherited by class Y and class Z.
FIG. 4 shows a definition of a class X including a virtual function in the C ++ language, a definition of a class Y that inherits the class X, a definition of a class Z that inherits the class X, a definition of a class W that inherits the class Z, and a function void k (W It is a figure which shows the definition of *). Here, it is stored in the input file B102 in FIG. For simplicity, method definitions, programs, and subsequent processing contents not related to the description are omitted. However, all class definitions necessary for program execution are described.
[0028]
FIG. 5 is a diagram showing the inheritance relationship of the classes shown in FIG. Class X is inherited by class Y and class Z, and class Z is inherited by class W.
The input file A101 contains the C ++ language source program shown in FIG. 2, and the input file B102 contains the C ++ language source program shown in FIG.
[0029]
The translation unit 103 outputs the output file A108 shown in FIG. 6 in response to the input of the input file A101 shown in FIG.
Similarly, the translation unit 103 outputs the output file B109 shown in FIG. 7 in response to the input of the input file B102 shown in FIG.
The linking unit 110 outputs the execution file 115 shown in FIG. 8 in response to the input of the output file A 108 shown in FIG. 6 and the output file B 109 shown in FIG.
[0030]
The meanings of the machine language instruction sequence used here are as follows.
. BASE name: an inheritance relationship pseudo-instruction indicating that a class represented by name is inherited from another class.
_I_FP1Y: A label representing the address of the function void i (Y *).
[0031]
. METHODS: a pseudo-instruction that represents the beginning of a method instruction sequence.
. CLASS name: A method class pseudo instruction representing a class to which a method belongs.
jsr Label: A subroutine call instruction that branches to an address represented by Label.
[0032]
_H — 1Y: a label representing the address of the virtual function void h (void) of class Y
. METHODM M: A pseudo instruction that separates an instruction sequence when the method is not an override method and an instruction sequence when the method is an override method.
mov (r0 + 4), r1: a transfer instruction for loading the contents of the memory having r0 + 4 as an address into r1.
[0033]
mov (r1 + 0), r1: This is a transfer instruction for loading the contents of the memory having r1 as an address into r1.
jsr r1: A subroutine call instruction that branches to the address stored in the register r1.
. METHOD E: A pseudo instruction indicating the end of a method instruction sequence.
[0034]
rts: a return instruction from the function.
_J_FP1Z: A label representing the address of the function void j (Z *).
_H — 1Z: A label indicating the address of the virtual function void h (void) of class Z.
[0035]
_K_FP1W: A label representing the address of the function void k (W *).
_H — 1W: A label representing the address of the virtual function void h (void) of class W.
From here, the detailed operation of the translation unit 103 will be described.
[0036]
FIG. 9 is a flowchart illustrating the operation of the translation unit 103.
First, the input file A101 is input. Here, consider the case where the C ++ language program shown in FIG. 2 is input (step 901).
Next, it is determined whether or not the process of the inheritance relationship translation unit 104 is finished. If it has not been completed, the class information is acquired. Here, the class information is sequentially acquired for each definition of class X, class Y, and class Z, and then the process of the method call detecting unit 105 is performed (step 902).
[0037]
If there is an unprocessed class definition, class information is acquired for each class definition. Here, class information is acquired sequentially for each definition of class X, class Y, and class Z (step 903).
Next, it is determined whether or not this class inherits another class from the obtained class information for each class definition. If yes, go to translate the inheritance relationship, if no, return to end determination. Here, in the case of class X, since the other class is not inherited, the process returns to the end determination, and in the case of class Y and class Z, since class X is inherited, the inheritance relationship is sequentially translated (step 904). .
[0038]
If this class inherits another class, the inheritance relationship of the class is translated into an inheritance relationship pseudo-instruction. Here, since class Y and class Z inherit class X, the inherited class name is translated into inheritance relation pseudo-instruction “.BASE 1X”, and the process returns to the end determination (step 905). Note that the inheritance relationship pseudo-instruction may represent the class name of the inherited class and the class name of the inheriting class as a pair. In this way, the inheritance relationship of all classes can be completely reproduced by the concatenation device. It is also possible to output the information etc. for reference.
[0039]
When the process of the inheritance relationship translation unit 104 ends, it is next determined whether or not the process of the method call detection unit 105 has ended. If not finished, go to detect override method call instruction, and if finished, go to conventional translation processing. Here, instructions are sequentially detected for the virtual function call instruction of the function “void i (Y *)” and the virtual function call instruction of the function “void j (Z *)”, and then the conventional translation processing is performed (step 906).
[0040]
If there is an unprocessed override method call instruction, this is detected. Here, the virtual function calling instructions of the function “void i (Y *)” and the function “void j (Z *)” are sequentially detected and translated into a method instruction sequence (step 907).
Next, the method translation unit 106 translates the detected override method call instruction into a method instruction sequence. Here, the virtual function calling instructions of the function “void i (Y *)” and the function “void j (Z *)” are sequentially translated into a method instruction sequence, and the process returns to the end determination (step 908). Here, the method instruction string of the function “void i (Y *)” is a portion that starts with “.METHODS S” in the first half of the output file A 108 shown in FIG. 6 and ends with “.METHODE E”. “.CLASS 1Y” included in this method instruction sequence is a method class pseudo-instruction indicating that a method called by this instruction belongs to class Y. Between “.CLASS 1Y” and “.METHOD M”, A machine language instruction sequence is a machine language instruction sequence when a method called by this instruction is not an override method, and a machine language instruction sequence between “.METHOD M” and “.METHODE E” is an override method. Machine language instruction sequence. The method for generating the machine language instruction sequence is the same as the conventional method, and thus the description thereof is omitted. Further, the method instruction sequence of the function “void j (Z *)” is the same as that of the function “void i (Y *)”, and thus the description thereof is omitted.
[0041]
FIG. 10 shows a method instruction sequence.
Since the method instruction sequence always has the same format, the method instruction sequence shown in FIG. 10A may be represented by a method class pseudo instruction and one macro instruction as shown in FIG. As shown in FIG. 10 (c), it may be represented by one macro instruction including information on the method class pseudo instruction. Here, in FIG. 10B, the macro name “jsrv” is sequentially output after the label name to be called when the method called by the override method call instruction is not an override method, and is used when the method is an override method. The offset value from the head of the object to be performed, the offset value from the head of the method address storage table used when the method is an override method, and the register name used when the method is an override method. In FIG. "srw" is sequentially output after the class name to which the method called by the override method call instruction belongs, and the method called by this override method call instruction is not an override method The label name to be called, the offset value from the top of the object to be used if it is an override method, the offset value from the top of the method address storage table to be used if it is an override method, and the register to be used if it is an override method Name. Note that it is not always necessary to use a fixed register name for the override method.
[0042]
When the process of the method call detection unit 105 is completed, the instruction translation unit 107 translates the instruction that has not been translated by the method translation unit 106 into a machine language instruction sequence. Since this process is not different from the process performed by the conventional translation apparatus, detailed description thereof is omitted (step 909).
Next, the output file A108 is output. Here, the output file shown in FIG. 6 is output (step 910).
[0043]
Subsequently, the input file B102 is input. Here, consider the case where the C ++ language program shown in FIG. 4 is input (step 901).
Next, class information is sequentially acquired for each definition of class X, class Y, class Z, and class W, and then the process of the method call detection unit 105 is performed (step 902).
[0044]
If there is an unprocessed class definition, class information is sequentially acquired for each definition of class X, class Y, class Z, and class W (step 903).
Next, in the case of class X, since the other class is not inherited, the process returns to the end determination. In the case of class Y and class Z, class X is inherited, and in the case of class W, class Z is inherited. Go to translate inheritance relationship (step 904).
[0045]
Since class Y and class Z inherit class X, the inherited class name is translated into inheritance relation pseudo-instruction ".BASE 1X", and class W inherits class Z because class W inherits class Z. The name is translated into an inheritance relationship pseudo-instruction “.BASE 1Z”, and the process returns to the end determination in sequence (step 905).
When the process of the inheritance relationship translation unit 104 is finished, next, an instruction is detected for the virtual function call instruction of the function “void k (W *)”, and then the conventional translation process is performed (step 906).
[0046]
If there is an unprocessed override method call instruction, a virtual function call instruction of the function “voidk (W *)” is detected and translated into a method instruction sequence (step 907).
Next, the virtual function call instruction of the function “void k (W *)” is translated into a method instruction sequence, and the process returns to the end determination (step 908). Since the method instruction string of the function “void k (Z *)” is the same as that of the function “void i (Y *)”, the description thereof is omitted.
[0047]
When the process of the method call detection unit 105 is completed, the instruction translation unit 107 translates the instruction that has not been translated by the method translation unit 106 into a machine language instruction sequence. Since this process is not different from the process performed by the conventional translation apparatus, detailed description thereof is omitted (step 909).
Next, the output file B109 is output. Here, the output file shown in FIG. 7 is output (step 910).
[0048]
Subsequently, a detailed operation of the connecting unit 110 will be described.
FIG. 11 is a diagram illustrating an operation flowchart of the connecting unit 110.
First, an output file A 108 and an output file B 109 are input. Here, a case is considered where the output file shown in FIG. 6 and the output file shown in FIG. 4 are input (step 1101).
[0049]
Next, it is determined whether or not the process of the method instruction sequence detection unit 111 is completed. If it has not been completed, the instruction sequence is detected. If it has been completed, the succession related pseudo-instruction is deleted. Here, the instruction sequence of the function “void i (Y *)”, the method instruction sequence of the function “void j (Z *)”, and the method instruction sequence of the function “void k (W *)” are sequentially detected. Then, the succession relation pseudo-instruction is deleted (step 1102).
[0050]
If there is an unprocessed method instruction sequence, the method instruction sequence is detected from all input output files. Here, the method instruction sequence of the function “void i (Y *)”, the function “void j (Z *)” and the function “void k (W *)” is sequentially detected to determine whether the class is inherited. (Step 1103). Next, the class to which the method belongs is recognized from the method class pseudo instruction in the detected method instruction sequence, and whether or not the class is inherited by other classes is determined by all the inheritance relation pseudo tests in all output files. Judgment based on instructions. Here, first, the class Y is recognized from the method class pseudo instruction “.CLASS 1Y” in the method instruction sequence of the function “void i (Y *)”, and all the inheritance relation pseudo instructions “. Based on “BASE 1X” and “.BASE 1Z”, it is determined that the class Y is not inherited by other classes, and is replaced with an instruction sequence when it is not an override method, and then the function “void j (Z *)” Class Z is recognized from the method class pseudo-instruction ".CLASS 1Z" of the "." Class Z is determined to be inherited by other classes based on the inheritance relation pseudo-instruction ".BASE 1Z" in the output file B109, If it is an override method, go to replace with the instruction sequence, and then suspect the method class in the method instruction sequence of the function “void k (W *)” Class W is recognized from instruction “.CLASS 1W”, and class W is not inherited by other classes based on all inheritance relation pseudo-instructions “.BASE 1X” and “.BASE 1Z” in all output files. Judgment is made and the instruction sequence for the case where the method is not an override method is replaced (step 1104).
[0051]
If it is determined that the class to which the method belongs is not inherited by another class, the method instruction sequence detected by the method instruction sequence detection unit 111 is only the machine language instruction sequence when the method replacement unit 113 is not an override method. Replace with. Here, the method instruction sequence of the function “void i (Y *)” is sequentially replaced with the instruction “jsr_h_1Y”, and the method instruction sequence of the function “void j (W *)” is sequentially replaced with the instruction “jsr_h_1W”, and the end determination is made. Return (step 1105).
[0052]
If it is determined that the class to which the method belongs is inherited by another class, the method instruction sequence detected by the method instruction sequence detection unit 111 is a machine language instruction when the method replacement unit 113 is an override method. Replace with column only. Here, the method instruction string of the function “void j (Z *)” is replaced with the instructions “mov (r0 + 4), r1”, “mov (r1 + 0), r1”, and “jsr r1”, and the process returns to the end determination (step 1106). ).
[0053]
When the process of the method instruction sequence detection unit 111 is completed, the method replacement unit 113 deletes all the inheritance relation pseudo instructions. Here, the inheritance relationship pseudo-instructions “.BASE 1X” and “.BASE 1Z” are deleted (step 1107).
Next, the file concatenation unit 114 concatenates all of the files replaced by the method replacement unit 113 to generate an execution file. Note that the processing for connecting the above files is not different from the processing performed by the conventional connecting device, and therefore detailed description thereof is omitted (step 1108).
[0054]
Next, the execution file 115 is output. Here, the execution file shown in FIG. 8 is output (step 1109).
Note that the processing performed by the method replacement unit 113 in this embodiment is a form in which both the instruction sequence when the method instruction sequence is not an override method and the instruction sequence when the method instruction sequence is an override method are used as shown in FIG. If the method instruction string is a macro instruction as shown in FIGS. 10 (b) and 10 (c), it is based on this macro instruction. Thus, the necessary instruction sequence is generated.
[0055]
In this embodiment, the translation device and the connection device are provided. However, the connection device is not always necessary. When all the class definitions necessary for program execution are included in one input file, it may be a program conversion device that only translates this input file. It may be generated by being connected in advance. In this case, the program conversion device needs to translate the class name inherited in the class definition into a pseudo instruction, translate the override method call instruction into a method instruction string, or replace the method instruction string. Instead, it is only necessary to extract the inheritance relationship of all classes based on the class definition and translate the override method call instruction into either the case where the override method is not an override method or the case where it is an override method.
[0056]
Further, the program conversion apparatus of the present embodiment can be realized by causing a general-purpose computer to read a program that realizes the present embodiment. Therefore, it is easily transferred by moving only the computer-readable storage medium that records this program.
[0057]
【The invention's effect】
(A) As is clear from the above description, the program conversion apparatus according to the present invention is a program conversion apparatus that translates an object-oriented language program into a machine language instruction sequence to generate an execution file, and the object-oriented The language program includes a definition of a class including an override method and an override method call instruction, an extraction means for extracting inheritance relationships of all classes as inheritance relationship information based on the definition of the class, and all the inheritance relationships Determining means for determining whether or not a class to which a method called by the override method calling instruction belongs is inherited based on information, and overriding the override method calling instruction when the determining means determines that the class is not inherited Machine language life when not Characterized in that it comprises a method translation means for translating the column.
[0058]
In the present invention, when all class definitions necessary for program execution are included in one input file, the override method call instruction is not an override method or an override method based on the inheritance relationship of all classes. Take the method of translating into either case.
This takes advantage of the fact that if a class is not inherited at all by another class, the override method defined in that class cannot use the override function, the override method call instruction is not an override method. Can be translated into That is, an indirect call can be made a direct call.
[0059]
Therefore, the code size of the override method call instruction can be reduced by this amount, and the execution speed is improved.
(B) Further, the program conversion apparatus according to the present invention connects a translation apparatus that translates an object-oriented language program into a machine language instruction sequence for each file and outputs it as an output file, and an output file translated by the translation apparatus And a concatenation device for generating an executable file, wherein the object-oriented language program includes a class definition including an override method and an override method call instruction, and the translation device includes the class Inheritance relationship translation means for translating the inheritance relationship of a file unit class into inheritance relationship information based on the definition of the method, method class information indicating a class to which a method called by this instruction belongs, and method class information that is called by this instruction Method A method translating means for translating into a method instruction sequence including non-override information representing a machine language instruction sequence when not a ride method and override information representing a machine language instruction sequence when being an override method; Determining means for determining whether a class to which a method called by the override method call instruction belongs is inherited based on all the inheritance relationship information in all output files translated by the translation device; When it is determined that the method instruction sequence is not inherited by the determining means, only the machine language instruction sequence when it is not an override method is replaced. On the other hand, when it is determined that the method instruction sequence is inherited, it is an override method. And a replacement means for replacing only with a machine language instruction sequence. That.
[0060]
When there are a plurality of input files, the translation device only knows the inheritance relationship of the class for each file, but not the inheritance relationship of all the classes. Moreover, the conventional inheritance device does not know the inheritance relationship of classes.
According to the present invention, the inheritance relationship of the file unit class is translated into the inheritance relationship information by the translation device, and all the inheritance relationship information is referred to by the connection device, so that the inheritance relationship of all the classes can be known in the connection device. Further, the method of translating the override method call instruction in the translation apparatus into an instruction sequence for both the case where it is not the override method and the case where it is the override method, and selecting either one in the concatenation apparatus.
[0061]
This takes advantage of the fact that if a class is not inherited at all by another class, the override method defined in that class cannot use the override function, the override method call instruction is not an override method. Can be translated into That is, an indirect call can be made a direct call.
[0062]
Therefore, the code size of the override method call instruction can be reduced by this amount, and the execution speed is improved.
(C) The program conversion apparatus according to the present invention is the program conversion apparatus according to (b), wherein the method translation means represents the non-override instruction and the override instruction by one macro instruction. To do.
[0063]
This reduces the number of instructions.
Therefore, the file size of the output file output from the translation device can be reduced, and the execution speed of the connecting device is improved.
(D) The program conversion apparatus according to the present invention is the program conversion apparatus according to (b), wherein the method translating means converts the method class information, the non-override instruction, and the override instruction into one macro instruction. It is characterized by expressing by.
[0064]
As a result, the instructions for the method class information are not necessary, and the number of instructions is reduced. Further, since the macro instruction is one line, it is similar to the instruction format performed by the conventional connecting apparatus.
Therefore, the file size of the output file output from the translation device can be reduced, the execution speed of the connecting device can be improved, and the additional change of the connecting device can be reduced.
[0065]
(E) The program conversion apparatus according to the present invention is the program conversion apparatus according to (d), wherein the macro instruction includes a macro name, the method class information, a label name to be called when it is not an override method, and an override method. It is characterized by comprising an offset value from the top of the object used in the case of and an offset value from the top of the method address storage table used in the case of the override method.
[0066]
As a result, the format of the macro instruction is similar to the format of the instruction performed by the conventional coupling device.
Therefore, the additional change of the connecting device can be reduced.
(F) The program conversion apparatus according to the present invention is the program conversion apparatus according to (a), (b), (c), (d), or (e), wherein the inheritance relationship information is other than the class definition. This is information representing a class name inherited by the class.
[0067]
Thus, when a plurality of classes inherit the same class, a plurality of the inheritance relationship information is not necessary, and one can be shared.
Therefore, the file size of the output file output from the translation device can be reduced, and the execution speed of the connecting device is improved.
(G) A computer-readable storage medium storing a program according to the present invention is a computer-readable storage medium recording a program for translating an object-oriented language program into a machine language instruction sequence to generate an execution file. The object-oriented language program includes a class definition including an override method and an override method call instruction, and an extraction procedure for extracting inheritance relationships of all classes as inheritance relationship information based on the class definition And a determination procedure for determining whether or not a class to which a method called by the override method call instruction belongs is inherited based on all the inheritance relationship information, and when the determination procedure determines that the class is not inherited Override method call Characterized in that it comprises a method translation procedure to be translated into machine language instruction sequence If the instruction is not the overriding method.
[0068]
In the present invention, when all class definitions necessary for program execution are included in one input file, the override method call instruction is not an override method or an override method based on the inheritance relationship of all classes. Take the method of translating into either case.
This takes advantage of the fact that if a class is not inherited at all by another class, the override method defined in that class cannot use the override function, the override method call instruction is not an override method. Can be translated into That is, an indirect call can be made a direct call.
[0069]
Therefore, the code size of the override method call instruction can be reduced by this amount, and the execution speed is improved.
(H) A computer-readable storage medium storing the program according to the present invention includes a translation procedure for translating an object-oriented language program into a machine language instruction sequence for each file, and outputting the output file as an output file. A computer-readable storage medium storing a program comprising a concatenation procedure for concatenating output files generated to generate an execution file, wherein the object-oriented language program includes a class definition including an override method and an override method A call instruction, and the translation procedure includes an inheritance relationship translation procedure for translating the inheritance relationship of a file unit class into inheritance relationship information based on the definition of the class, and a method called by the instruction for the override method call instruction. Class to which the Is translated into a method instruction sequence that contains non-override information that represents the machine language instruction sequence when the method called by this instruction is not an override method and override information that represents the machine language instruction sequence when it is an override method And the concatenation procedure is inherited by the class to which the method called by the override method call instruction belongs based on all the inheritance relationship information in all the output files translated by the translation procedure. A determination procedure for determining whether the method instruction sequence is not inherited in the determination procedure, and when it is determined that the method instruction sequence is not inherited, only the machine language instruction sequence for the case where the method is not an override method is replaced; If so, the override method Characterized in that it comprises a replacement procedure for replacing only the machine language instruction sequence when it is.
[0070]
When there are multiple input files, the translation procedure only knows the inheritance relationship of the class for each file, not the inheritance relationship of all the classes. Moreover, the inheritance relationship of classes is not known at all in the conventional connection procedure.
In the present invention, the inheritance relationship of the file unit class is translated into the inheritance relationship information in the translation procedure, and all the inheritance relationship information is referred to in the connection procedure, so that the inheritance relationship of all the classes can be determined in the connection procedure. Further, the method of translating the override method call instruction in the translation procedure into both the instruction sequence for the case where it is not the override method and the case of the override method, and selecting either in the concatenation procedure is adopted.
[0071]
This takes advantage of the fact that if a class is not inherited at all by another class, the override method defined in that class cannot use the override function, the override method call instruction is not an override method. Can be translated into That is, an indirect call can be made a direct call.
[0072]
Therefore, the code size of the override method call instruction can be reduced by this amount, and the execution speed is improved.
[Brief description of the drawings]
FIG. 1 is a diagram showing a configuration of a program conversion apparatus according to the present invention.
FIG. 2 is a definition of a class X including a virtual function in the C ++ language, a definition of a class Y that inherits the class X, a definition of a class Z that inherits the class X, and a function void i (Y *). And the definition of the function void j (Z *).
FIG. 3 is a diagram illustrating an inheritance relationship of classes illustrated in FIG. 2;
FIG. 4 shows a definition of a class X including a virtual function in the C ++ language, a definition of a class Y that inherits the class X, a definition of a class Z that inherits the class X, and a class W that inherits the class Z. And the definition of the function void k (W *).
FIG. 5 is a diagram illustrating the inheritance relationship of the classes illustrated in FIG. 4;
6 is a diagram showing an output file A108 output by a translation unit 103 in response to input of the input file A101 shown in FIG.
7 is a diagram showing an output file B109 output by the translation unit 103 in response to the input of the input file B102 shown in FIG.
8 is a diagram showing an execution file 115 output by the concatenation unit 110 in response to the input of the output file A 108 shown in FIG. 6 and the output file B 109 shown in FIG.
FIG. 9 is a diagram showing an operation flowchart of the translation unit 103;
FIG. 10A shows a method instruction sequence. FIG. 10B is a diagram showing a method instruction sequence by a method class pseudo instruction and one macro instruction. FIG. 10C is a diagram showing a method instruction sequence including one macro instruction including information on a method class pseudo instruction.
FIG. 11 is a diagram illustrating an operation flowchart of a connecting unit 110;
FIG. 12 is a diagram illustrating a class definition including a virtual function of C ++ language.
13 is a diagram showing the inheritance relationship of the classes shown in FIG.
FIG. 14 is a diagram showing the memory allocation of objects created with the class shown in FIG. 12 by class.
FIG. 15 is a diagram illustrating an example in which a function i including a call to a virtual function h of a class C is described in the C ++ language.
FIG. 16 is a diagram showing an example in which the function i in FIG. 15 is converted into a machine language instruction sequence by a conventional program conversion apparatus.
FIG. 17 is a diagram illustrating an example in which a function i including a call to the function h is converted into a machine language instruction sequence when it is assumed that the function h is defined as a non-virtual function.
[Explanation of symbols]
101 Input file A
102 Input file B
103 Translation Department
104 Inheritance Translation Department
105 Method call detector
106 Method Translation Department
107 Instruction Translation Department
108 Output file A
109 Output file B
110 connecting part
111 Method instruction sequence detector
112 Inheritance class determination part
113 Method replacement part
114 File connection
115 Executable file

Claims (5)

オブジェクト指向言語のプログラムをファイル単位で機械語命令列に翻訳し出力ファイルとして出力する翻訳装置と、前記翻訳装置で翻訳された出力ファイルを連結して実行ファイルを生成する連結装置とを備えるプログラム変換装置であって、
前記オブジェクト指向言語のプログラムには、オーバーライドメソッドを含むクラスの定義とオーバーライドメソッド呼び出し命令が含まれ、
前記翻訳装置は、
前記クラスの定義に基づいてファイル単位のクラスの継承関係を、継承関係情報に翻訳する継承関係翻訳手段と、
前記オーバーライドメソッド呼び出し命令を、この命令によって呼び出されるメソッドが属するクラスを表すメソッドクラス情報と、この命令によって呼び出されるメソッドがオーバーライドメソッドでない場合の機械語命令列を表す非オーバーライド情報と、オーバーライドメソッドである場合の機械語命令列を表すオーバーライド情報とを含むメソッド命令列に翻訳するメソッド翻訳手段とを備え、
前記連結装置は、
前記翻訳装置で翻訳された全ての出力ファイルの中の全ての前記継承関係情報に基づいて、前記オーバーライドメソッド呼び出し命令によって呼び出されるメソッドが属するクラスが、継承されるか否かを判断する判断手段と、
記判断手段で継承されないと判断された場合には、前記メソッド命令列に含まれる前記オーバーライド情報は用いず、当該メソッド命令列に含まれる前記非オーバーライド情報を用いることにより、オーバーライドメソッドでない場合の機械語命令列を生成し、一方、前記判断手段で継承されると判断された場合には、当該メソッド命令列に含まれる前記非オーバーライド情報は用いず、当該メソッド命令列に含まれる前記オーバーライド情報を用いることにより、オーバーライドメソッドである場合の機械語命令列を生成し、前記メソッド命令列を、生成した機械語命令列に置換する置換手段と
を備えることを特徴とするプログラム変換装置。
Program conversion comprising: a translation device that translates an object-oriented language program into a machine language instruction sequence in units of files and outputs an output file; and a concatenation device that concatenates the output files translated by the translation device to generate an execution file A device,
The object-oriented language program includes a class definition including an override method and an override method call instruction.
The translation device includes:
Inheritance relationship translation means for translating the inheritance relationship of the file unit class into the inheritance relationship information based on the definition of the class;
The override method call instruction includes method class information representing a class to which a method called by this instruction belongs, non-override information representing a machine language instruction string when a method called by this instruction is not an override method, and an override method. A method translation means for translating into a method instruction sequence including override information representing a machine language instruction sequence in the case,
The connecting device is
Determining means for determining whether a class to which a method called by the override method calling instruction belongs is inherited based on all the inheritance relationship information in all output files translated by the translation device; ,
If it is determined not to be inherited in the previous Symbol judging means, wherein the override information contained in the method instruction sequence is not used, and by using the non-override information contained in the method instruction sequence, if not override method When it is determined that the machine language instruction sequence is generated and inherited by the determination means, the non-override information included in the method instruction sequence is not used, and the override information included in the method instruction sequence is not used. A program conversion apparatus , comprising: a replacement unit that generates a machine language instruction sequence in the case of an override method by using and replaces the method instruction sequence with the generated machine language instruction sequence .
前記メソッド翻訳手段は、
前記オーバーライドメソッド呼び出し命令を翻訳するにあたり、前記非オーバーライド情報と、前記オーバーライド情報の両方を含む1つのマクロ命令と、前記メソッドクラス情報を含む1つの疑似命令とで表されるメソッド命令列に翻訳すること
を特徴とする請求項1に記載のプログラム変換装置。
The method translation means includes:
Upon translating the override method call instruction, the translation said a non-override information, and one macro instruction containing both the override information in the method instruction sequence is table at one and directive including the method class information program conversion apparatus according to claim 1, characterized in that.
前記メソッド翻訳手段は、
前記オーバーライドメソッド呼び出し命令を翻訳するにあたり、前記メソッドクラス情報と、前記非オーバーライド情報と、前記オーバーライド情報の全てを含む1つのマクロ命令で表されるメソッド命令列に翻訳すること
を特徴とする請求項1に記載のプログラム変換装置。
The method translation means includes:
Upon translating the override method call instruction, according to the above methods class information, wherein the non-overriding information, characterized in that translating the method instruction sequence is table at one macroinstruction that includes all of the override information Item 2. The program conversion device according to Item 1 .
前記マクロ命令は、
マクロ名と、前記メソッドクラス情報と、非オーバーライド情報としてオーバーライドメソッドでない場合に呼び出すラベル名と、オーバーライド情報の一部としてオーバーライドメソッドである場合に使用するオブジェクトの先頭からのオフセット値と、オーバーライド情報の一部としてオーバーライドメソッドである場合に使用するメソッドアドレス格納テーブルの先頭からのオフセット値で構成されること
を特徴とする請求項3に記載のプログラム変換装置。
The macro instruction is
Macro name, method class information, label name to call when non-override method is not an override method, offset value from the beginning of the object to be used when it is an override method as part of override information , and override information 4. The program conversion apparatus according to claim 3, wherein the program conversion apparatus comprises an offset value from the head of a method address storage table used when the method is an override method as a part .
前記メソッド翻訳手段は、  The method translation means includes:
前記オーバーライドメソッド呼び出し命令を翻訳するにあたり、前記非オーバーライド  In translating the override method call instruction, the non-override 情報の代わりにオーバーライドメソッドでない場合の機械語命令列である非オーバーライド命令を含み、前記オーバーライド情報の代わりにオーバーライドメソッドである場合の機械語命令列であるオーバーライド命令を含むメソッド命令列に翻訳し、A non-override instruction that is a machine language instruction sequence when not an override method instead of information, and a method instruction sequence that includes an override instruction that is a machine language instruction sequence when it is an override method instead of the override information;
前記置換手段は、  The replacement means includes
前記メソッド命令列をオーバーライドメソッドでない場合の機械語命令列に置換する際には、メソッド命令列から非オーバーライド命令以外の不必要な部分を除くだけの処理をおこない、前記メソッド命令列をオーバーライドメソッドである場合の機械語命令列に置換する際には、メソッド命令列からオーバーライド命令以外の不必要な部分を除くだけの処理をおこなうこと  When replacing the method instruction sequence with a machine language instruction sequence when it is not an override method, only the unnecessary part other than the non-override instruction is removed from the method instruction sequence, and the method instruction sequence is replaced with the override method. When replacing with the machine language instruction sequence in a certain case, the processing should only be performed by removing unnecessary parts other than the override instruction from the method instruction sequence.
を特徴とする請求項1に記載のプログラム変換装置。  The program conversion apparatus according to claim 1.
JP12560797A 1997-05-15 1997-05-15 Program converter Expired - Fee Related JP3672207B2 (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
JP12560797A JP3672207B2 (en) 1997-05-15 1997-05-15 Program converter

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
JP12560797A JP3672207B2 (en) 1997-05-15 1997-05-15 Program converter

Publications (2)

Publication Number Publication Date
JPH10320204A JPH10320204A (en) 1998-12-04
JP3672207B2 true JP3672207B2 (en) 2005-07-20

Family

ID=14914307

Family Applications (1)

Application Number Title Priority Date Filing Date
JP12560797A Expired - Fee Related JP3672207B2 (en) 1997-05-15 1997-05-15 Program converter

Country Status (1)

Country Link
JP (1) JP3672207B2 (en)

Families Citing this family (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6526571B1 (en) * 1999-03-16 2003-02-25 International Business Machines Corporation Method for identifying calls in java packages whose targets are guaranteed to belong to the same package
US6675377B1 (en) 1999-09-13 2004-01-06 Matsushita Electric Industrial Co., Ltd. Program conversion apparatus
JP2006146613A (en) 2004-11-19 2006-06-08 Matsushita Electric Ind Co Ltd Program conversion method

Also Published As

Publication number Publication date
JPH10320204A (en) 1998-12-04

Similar Documents

Publication Publication Date Title
JP4130713B2 (en) Program converter
DK1174791T3 (en) Total data type system and method
CN105723341B (en) Realization method and system for layout engine and the memory model of script engine
JPH05508503A (en) Branching analysis using backward symbolic execution
JPH05508504A (en) Program translation method
JPH0762827B2 (en) How to refer to the cross image of the program code
JP4638484B2 (en) Data integrity in data processing equipment
JP2001526421A (en) Apparatus and method for allowing object oriented programs written in different framework versions to communicate
JP4026940B2 (en) Program converter
Maksimović et al. Gillian, part II: real-world verification for javascript and C
JP2005018425A (en) Program conversion method, program and storage medium
JP3672207B2 (en) Program converter
JP2006146613A (en) Program conversion method
US11635947B2 (en) Instruction translation support method and information processing apparatus
US6763516B2 (en) Convention checking apparatus, convention checking system, convention checking method, and storage medium on which is recorded a convention checking program
JP2000122876A (en) Information processor
TWI253561B (en) Methods for abstracting and outputting dynamical output messages
KR100846203B1 (en) Method for generating mobile application and record media recorded program for realizing the same
Kicinski et al. Xdp hardware offload: Current work, debugging and edge cases
JP2000305790A (en) Label address converting device and its method and computer readable medium
JPH06266562A (en) Object code size optimizing system in object-oriented language processing system
KR100546672B1 (en) A method for recording and translation contents of a printable character stream using a format character stream in program
JP2000259427A (en) Program converter
CN115185585A (en) Instruction customization method and system
JP4670724B2 (en) Source code generation apparatus, source code generation method, and source code generation program

Legal Events

Date Code Title Description
A621 Written request for application examination

Free format text: JAPANESE INTERMEDIATE CODE: A621

Effective date: 20040513

A131 Notification of reasons for refusal

Free format text: JAPANESE INTERMEDIATE CODE: A131

Effective date: 20050104

A521 Written amendment

Free format text: JAPANESE INTERMEDIATE CODE: A523

Effective date: 20050303

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: 20050412

A61 First payment of annual fees (during grant procedure)

Free format text: JAPANESE INTERMEDIATE CODE: A61

Effective date: 20050415

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: 20080428

Year of fee payment: 3

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

Free format text: PAYMENT UNTIL: 20090428

Year of fee payment: 4

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

Free format text: PAYMENT UNTIL: 20100428

Year of fee payment: 5

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

Free format text: PAYMENT UNTIL: 20110428

Year of fee payment: 6

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

Free format text: PAYMENT UNTIL: 20120428

Year of fee payment: 7

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

Free format text: PAYMENT UNTIL: 20130428

Year of fee payment: 8

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

Free format text: PAYMENT UNTIL: 20130428

Year of fee payment: 8

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

Free format text: PAYMENT UNTIL: 20140428

Year of fee payment: 9

LAPS Cancellation because of no payment of annual fees