JP2008276735A - Program code converter and program code conversion method - Google Patents
Program code converter and program code conversion method Download PDFInfo
- Publication number
- JP2008276735A JP2008276735A JP2007333098A JP2007333098A JP2008276735A JP 2008276735 A JP2008276735 A JP 2008276735A JP 2007333098 A JP2007333098 A JP 2007333098A JP 2007333098 A JP2007333098 A JP 2007333098A JP 2008276735 A JP2008276735 A JP 2008276735A
- Authority
- JP
- Japan
- Prior art keywords
- processor
- code
- source code
- program
- predetermined
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
Images
Abstract
Description
本発明は、プログラムコード変換装置及びプログラムコード変換方法に関し、特に、第1のプロセッサにおいて実行可能な第1のバイナリコードを、第2のプロセッサ用のプログラムコードに変換するプログラムコード変換装置及びプログラムコード変換方法に関する。 The present invention relates to a program code conversion device and a program code conversion method, and in particular, a program code conversion device and a program code for converting a first binary code executable in a first processor into a program code for a second processor. Concerning the conversion method.
従来より、あるプロセッサで実行可能なプログラムを、他の別なプロセッサでも実行可能なようにプログラムの変換が行われている。例えば、互いに異なるプロセッサXとYがあったとき、プロセッサX用のバイナリコードからプロセッサY用のバイナリコードを得る方法としては、一般的には、次の2つの方法がある。 Conventionally, a program is converted so that a program that can be executed by one processor can be executed by another processor. For example, when there are different processors X and Y, there are generally the following two methods for obtaining the binary code for the processor Y from the binary code for the processor X.
第1の方法は、トランスレータプログラムを用いて、プロセッサX用のバイナリコードを、プロセッサY用のバイナリコードに直接変換する方法である。
この方法では、変換後もバイナリコードであるため、変換されたバイナリコードは可読性が低く、プログラマのユーザは、変換されたバイナリコードに対して、マニュアルでデバッグしたり、新たな仕様変更に対応させたり、性能のチューニングをしたりすることが困難であった。また、プロセッサX用の命令体系と、プロセッサY用の命令体系が異なるとき、プロセッサX用の命令コードをプロセッサY用の命令コードに、一対一に置き換えられない場合もある。
The first method is a method of directly converting binary code for processor X into binary code for processor Y using a translator program.
In this method, the converted binary code is low in readability after conversion, and the programmer user can manually debug the converted binary code or adapt it to a new specification change. It was difficult to tune performance. Further, when the instruction system for processor X and the instruction system for processor Y are different, the instruction code for processor X may not be replaced with the instruction code for processor Y on a one-to-one basis.
第2の方法は、プロセッサX用のバイナリコードを逆コンパイルして、一旦、いわゆる高級言語コードに変換し、その高級言語コードを、プロセッサY用のコンパイラにより、コンパイルしてプロセッサY用のバイナリコードを得る方法である(例えば、特許文献1参照)。 In the second method, the binary code for the processor X is decompiled, converted into a so-called high-level language code, and then the high-level language code is compiled by a compiler for the processor Y and then the binary code for the processor Y is compiled. (For example, refer to Patent Document 1).
しかし、この方法では、第1の方法の問題は解決されるが、次のような問題がある。
逆コンパイルにより、プロセッサに依存しない高級言語コードが生成されるとき、元々プロセッサX用のバイナリコードにおいて施されていた最適化が、プロセッサY用のバイナリコードでは保証されない、という問題である。例えば、人手によりアセンブリコードにおいて最適化のために工夫されたコード片が、バイナリコードに含まれるような場合、逆コンパルされて得られた高級言語コードには、そのようなコード片の工夫あるいは知恵は、反映されない、という問題である。すなわち、プログラム上の工夫のためのコード片の例として、機械命令関数がバイナリコードに含まれていても、逆コンパイルされて得られた高級言語コードには、そのコード片は含まれず、その結果、プロセッサY用のコンパイラが高級言語コードから生成するプロセッサY用のバイナリコードには、プロセッサX用のバイナリコードと同等の最適化が施されない。
When high-level language code that does not depend on the processor is generated by decompilation, the optimization originally performed in the binary code for the processor X is not guaranteed in the binary code for the processor Y. For example, when a code fragment devised for optimization in assembly code is included in the binary code, the high-level language code obtained by decompiling is not devised or wisdom of such code fragment. Is a problem that is not reflected. In other words, as an example of a code fragment for the purpose of the program, even if a machine instruction function is included in the binary code, the code fragment is not included in the high-level language code obtained by decompilation. The binary code for the processor Y generated by the compiler for the processor Y from the high-level language code is not subjected to optimization equivalent to the binary code for the processor X.
そこで、本発明は、このような問題に鑑みてなされたものであり、異なるプロセッサ間でプログラムコードの変換を行う場合に、変換元のバイナリコードに含まれるプログラム上の工夫を、変換先のバイナリコードに反映することができるプログラムコード変換装置を提供することを目的とする。 Therefore, the present invention has been made in view of such a problem, and when converting a program code between different processors, a device on the program included in the binary code of the conversion source is converted to the binary of the conversion destination. An object of the present invention is to provide a program code conversion device that can be reflected in a code.
本発明の一態様によれば、第1のプロセッサにおいて実行可能な第1のバイナリコードを、第2のプロセッサ用のプログラムコードに変換するプログラムコード変換装置であって、前記第1のバイナリコードを解析するコード解析部と、該コード解析部により解析して得られた前記第1のプロセッサ用の所定の1以上の命令に対応する、前記第2のプロセッサ用の所定の1以上の機械命令関数を抽出する機械命令関数抽出部と、前記第1のプロセッサ用の前記所定の1以上の命令を、前記機械命令関数抽出部により抽出された前記所定の1以上の機械命令関数に書き換えて、前記第1のバイナリコードから前記第2のプロセッサ用のプログラムコードとして、前記第2のプロセッサ用のソースコードを生成するトランスレータ部と、を有するプログラムコード変換装置を提供することができる。 According to an aspect of the present invention, there is provided a program code conversion device for converting a first binary code executable in a first processor into a program code for a second processor, wherein the first binary code is converted into a program code conversion device. A code analysis unit to analyze, and a predetermined one or more machine instruction functions for the second processor corresponding to the predetermined one or more instructions for the first processor obtained by analysis by the code analysis unit Rewriting the predetermined one or more instructions for the first processor with the predetermined one or more machine instruction functions extracted by the machine instruction function extracting unit, A translator unit that generates source code for the second processor as program code for the second processor from the first binary code. It is possible to provide a program code conversion apparatus.
本発明によれば、異なるプロセッサ間でプログラムコードの変換を行う場合に、変換元のバイナリコードに含まれるプログラム上の工夫を、変換先のバイナリコードに反映することができるプログラムコード変換装置を提供することができる。 According to the present invention, there is provided a program code conversion device capable of reflecting a program device included in a conversion source binary code in a conversion destination binary code when the program code is converted between different processors. can do.
以下、図面を参照して本発明の実施の形態を説明する。
まず図1に基づき、本実施の形態に係わるプログラム変換装置の構成を説明する。図1は、本実施の形態に係わるプログラムコード変換装置の構成を示す構成図である。
プログラムコード変換装置(以下、プログラム変換装置という)1は、中央処理装置(以下、CPUという)11a、ROM、RAM等を有する計算機本体11と、キーボード、マウス等の入力装置12と、画面を有する表示装置13と、変換する対象プログラム(変換元プログラム)及び変換されたプログラム(変換先あるいは変換後のプログラム)等を記憶する記憶装置14を含んで構成されている、パーソナルコンピュータ(以下、PCという)等のコンピュータである。記憶装置14には、変換元のオブジェクトコードであるバイナリプログラム(以下、バイナリコードという)15と、変換後のバイナリコード16と、後述するプログラムの変換処理プログラム17と、後述する変換テーブル18とが記憶されている。また、記憶装置14には、デバッグプログラムであるデバッガ19も記憶されており、デバッグを行うときに、CPU11aがデバッガ19を読み出して実行することができる。
Embodiments of the present invention will be described below with reference to the drawings.
First, the configuration of the program conversion apparatus according to the present embodiment will be described with reference to FIG. FIG. 1 is a block diagram showing the configuration of the program code conversion apparatus according to the present embodiment.
A program code conversion device (hereinafter referred to as a program conversion device) 1 includes a central processing unit (hereinafter referred to as a CPU) 11a, a computer
なお、プログラム変換装置1は、このようなコンピュータに限らず、ネットワークを介して接続されたクライアント・サーバシステムのような装置であってもよい。
The
プログラム変換装置1を利用して、プログラム変換を行うユーザは、変換元のバイナリコード15に対して、後述するプログラムの変換処理を施し、変換後のバイナリコード16を得ることができる。ユーザは、入力装置12と表示装置13を含むマンマシンインターフェース(以下、MMIという)を利用して、記憶装置14に記憶された変換元のバイナリコード15を指定し、かつ変換後のバイナリコード16を記憶する記憶装置14の記憶領域を指定する。
また、ユーザは、MMIを利用して、後述するプログラム変換処理を行う変換処理プログラム17、及び後述する変換テーブル18を指定して、変換処理プログラム17を実行させることができる。
A user who performs program conversion using the
Further, the user can execute the
本実施の形態では、ある一つのプロセッサで実行可能なバイナリコードを、他の異なるプロセッサで実行可能なバイナリコードに変換する場合を説明するが、その一つのプロセッサをAプロセッサとし、そのAプロセッサで実行可能なバイナリコードをAバイナリコードとし、Aプロセッサとは異なるプロセッサをBプロセッサとし、そのBプロセッサで実行可能なバイナリコードをBバイナリコードとする。そして、これらに合わせて、Aバイナリコードに対応するソースプログラム(以下、ソースコードという)をAソースコードとし、Bバイナリコードに対応するソースコードをBソースコードとする。さらに、AソースコードをコンパイルしてAバイナリコードを生成するコンパイラを、Aコンパイラとし、BソースコードをコンパイルしてBバイナリコードを生成するコンパイラを、Bコンパイラとする。 In this embodiment, a case will be described in which binary code that can be executed by one processor is converted to binary code that can be executed by another processor. An executable binary code is an A binary code, a processor different from the A processor is a B processor, and a binary code executable by the B processor is a B binary code. In accordance with these, a source program corresponding to the A binary code (hereinafter referred to as source code) is defined as an A source code, and a source code corresponding to the B binary code is defined as a B source code. Further, a compiler that compiles A source code to generate A binary code is an A compiler, and a compiler that compiles B source code to generate B binary code is a B compiler.
図2は、本実施の形態におけるプログラム変換処理の流れの例を説明するための図である。
図2に示すように、Aバイナリコード15aは、Aソースコード21をAコンパイラ22によってコンパイルして生成されたコードである。Aソースコード21は、所定の処理を実行するための命令群から構成される。Aコンパイラ22は、Aソースコード21をコンパイルして、Aプロセッサで実行可能なオブジェクトコード、すなわちAバイナリコード15aを生成する。
FIG. 2 is a diagram for explaining an example of the flow of program conversion processing in the present embodiment.
As shown in FIG. 2, the A binary code 15 a is a code generated by compiling the A source code 21 by the
Aバイナリコード15aは、トランスレータ部としてのトランスレータ17aにより、汎用の高級言語のソースコード、例えば、C言語ソースコード23に逆コンパイルされる。トランスレータ17aは、Aバイナリコード15aを逆コンパイルする逆コンパイラである。
The A binary code 15a is decompiled into a general-purpose high-level language source code, for example, a C
C言語ソースコード23は、Bソースコードであり、Bプロセッサ用のBコンパイラ17bによってコンパイルされることによって、Bバイナリコード16aがC言語ソースコードから生成される。Bコンパイラ17bは、C言語ソースコード23をコンパイルして、Bプロセッサで実行可能なオブジェクトコード、すなわちBバイナリコード16aを生成する。
The C
本実施の形態に係るプログラム変換装置1では、Aバイナリコード15aからBバイナリコード16aを生成する際に、途中で、Bプロセッサ用のプログラムコードとしてのC言語ソースコード23が、トランスレータ17aによって生成される。この高級言語のソースコードを生成するときに、トランスレータ17aは、Aバイナリコード15a中の所定の命令を抽出し、その抽出された命令を、対応するBプロセッサ用の1以上の機械命令関数(Intrinsic Function:組み込み関数ともいう)に置き換える置換処理を行う。従って、C言語ソースコード23は、Bプロセッサ用の機械命令関数を含むものとなる。さらに、トランスレータ17aは、Aソースコード21を参照して、所定の形式で書かれたコメント文等を抽出し、抽出したコメント文等を、生成するC言語ソースコード23中に埋め込む埋込処理を行う。
In the
従来であれば、Aバイナリコード15aを逆コンパイルすると、Aソースコード21のレベルで、あるいはアセンブリコードのレベルで施された最適化は、C言語ソースコード23中からは消失することがある。さらには、逆コンパイルして得られたC言語ソースコード23には、Aソースコード21中のコメント文等も再生されない。
Conventionally, when the A binary code 15 a is decompiled, the optimization applied at the level of the A source code 21 or at the level of the assembly code may be lost from the C
具体的に説明する。プログラマは、Aソースコード21のレベルで、あるいはアセンブリコードレベルで、Aプロセッサ用にプログラムの最適化を行っている場合がある。例えば、Aプロセッサ用の機械命令関数を用いたり、Aプロセッサにおける実行可能な並列度に応じたソースコードを作成して、Aソースコード21の最適化を行う。しかし、ソースコードレベルあるいはアセンブリコードレベルで短いコードに最適化されても、逆コンパイルによりその短いコード部分は、長いコードに変更されてしまうことがある。 This will be specifically described. The programmer may optimize the program for the A processor at the level of the A source code 21 or at the assembly code level. For example, the A source code 21 is optimized by using a machine instruction function for the A processor or creating a source code corresponding to the degree of parallelism executable in the A processor. However, even if a short code is optimized at the source code level or the assembly code level, the short code part may be changed to a long code by decompilation.
また、Aソースコード21中のコメント文等は、通常はAバイナリコード15a中にはデバッグ情報として含まれないため、逆アセンブルされて得られたC言語ソースコード23中には、コメント文等は含まれない。
そこで、本実施の形態によれば、上述したような置換処理と埋込処理を行うことによって、最適化されたプログラム部分の残存、およびコメント文等の生成が可能となる。以下、詳細に説明する。
In addition, since the comment sentence in the A source code 21 is not usually included as debug information in the A binary code 15a, the comment sentence or the like is included in the C
Therefore, according to the present embodiment, by performing the replacement process and the embedding process as described above, it is possible to retain the optimized program part and generate a comment sentence or the like. Details will be described below.
図3と図4は、本実施の形態に係るプログラム変換装置1の変換処理プログラム17の処理の流れの例を示すフローチャートである。
図3の処理は、記憶装置14中の変換処理プログラム17を、プログラム変換装置1の計算機本体11のCPU11aが、読み出して実行することによって行われる。
3 and 4 are flowcharts showing an example of the processing flow of the
The processing of FIG. 3 is performed by the
まず、CPU11aは、変換元のAバイナリコード15aを解析する(ステップS1)。そして、CPU11aは、解析して得られた情報から、内部表現として、Aバイナリコード15aのコントロールデータフローグラフ(CDFG)を生成する(ステップS2)。従って、ステップS1の処理が、コード解析部を構成し、ステップS2が、コントロールデータフローグラフの情報を生成するコントロールデータフローグラフ(CDFG)情報生成部を構成する。
First, the
Aバイナリコード15aについてコントロールデータフローグラフの生成が完了すると、CPU11aは、Aバイナリコード15aの中から機械命令関数(IF)を抽出する(ステップS3)。ステップS3が、Aプロセッサ用の所定の命令に対応するBプロセッサ用の所定の機械命令関数を抽出する機械命令関数抽出部を構成する。
When the generation of the control data flow graph for the A binary code 15a is completed, the
次に、CPU11aは、抽出された機械命令関数を、変換テーブル18を参照することによって、Bプロセッサ用の機械命令関数を抽出して置き換える(ステップS4)。この置き換えは、例えば、コントロールデータフローグラフ(CDFG)の節点上で、行われる。図5は、その変換テーブルの構成例を示す図である。
Next, the
図5は、変換元のバイナリコード中に含まれている所定の命令と、変換後のソースコード中に含まれる機械命令関数との対応付けがされた変換テーブル18の構成を示す。変換テーブル18は、Aプロセッサ用の所定の複数の命令と、それぞれ対応するBプロセッサ用の複数の機械命令関数(IF)との対応が付けられた対応テーブルである。ここでは、変換テーブル18の左側の欄31には、Aプロセッサ用の複数の命令が記述されており、右側の欄32には、Bプロセッサ用の複数の機械命令関数(IF)が記述されている。すなわち、図5では、左側の欄31の複数の命令のそれぞれに対応して、右側の欄32に機械命令関数が記憶されている。
FIG. 5 shows the configuration of the conversion table 18 in which predetermined instructions included in the binary code of the conversion source are associated with machine instruction functions included in the converted source code. The conversion table 18 is a correspondence table in which a plurality of predetermined instructions for the A processor are associated with a plurality of machine instruction functions (IF) for the corresponding B processor. Here, a plurality of instructions for the A processor are described in the
例えば、Aバイナリコード中に、次の最大値検出命令A_MAXが含まれていたとする。
A_MAX a, b, c ・・・ (1)
この命令(A_MAX a, b, c)は、bとcのうち大きい方の値をaに代入する命令であるとする。なお、バイナリコードは、0と1とからなるバイナリコードであるので、上記の表記(A_MAX a, b, c)は、アセンブリコードの表記である。このような機械命令関数は、プロセッサに依存しない高級言語のC言語ソースコードでは、例えば、以下のようになる。
For example, assume that the following maximum value detection instruction A_MAX is included in the A binary code.
A_MAX a, b, c (1)
This instruction (A_MAX a, b, c) is assumed to be an instruction for assigning the larger value of b and c to a. Since the binary code is a binary code composed of 0 and 1, the above notation (A_MAX a, b, c) is an assembly code notation. Such a machine instruction function is, for example, as follows in a high-level C language source code that does not depend on a processor.
if(b > c) a = b;
else a = c; ・・・(2)
Bプロセッサ用の命令として、上記(1)と同等の命令、例えば(B_MAX a, b, c)、がある場合でも、Bコンパイラ17bが、上記(2)の命令群から(B_MAX a, b, c)を生成できる保証は一般的には無い。通常、Bコンパイラ17bは、上記(2)の命令群から、比較、分岐、及び代入の命令を用いた数命令かかるコードを生成してしまうかもしれない。
if (b> c) a = b;
else a = c; (2)
Even when there is an instruction equivalent to (1) above, for example, (B_MAX a, b, c), as an instruction for the B processor, the
そこで、本実施の形態では、命令(A_MAX a, b, c)に対応する機械命令関数として、機械命令関数(B_MAX(a, b, c))が存在することが分かっているとき、命令(A_MAX a, b, c)に対して、高級言語であるC言語コードを次のように生成する。 Therefore, in this embodiment, when it is known that a machine instruction function (B_MAX (a, b, c)) exists as a machine instruction function corresponding to the instruction (A_MAX a, b, c), the instruction ( For A_MAX a, b, c), a high-level C language code is generated as follows.
B_MAX(a, b, c); ・・・(3)
図5は、変換元のAプロセッサ用の命令と、それに対応するBプロセッサ用の機械命令関数とを対応付けている。よって、CPU11aは、ステップS3で抽出されたAプロセッサ用の命令が、図5の変換テーブル18の左側の欄31にあって、その対応する、Bプロセッサ用の機械命令関数が、右側の欄32にある場合は、CPU11aは、ステップS4において、Aバイナリコード15a中の命令(A_MAX a, b, c)を機械命令関数B_MAX(a, b, c)に置き換える。
B_MAX (a, b, c); (3)
FIG. 5 associates the conversion-source instruction for the A processor with the corresponding machine instruction function for the B processor. Therefore, in the
図5には、さらに、Aプロセッサ用に平均化処理の命令(A_AVE a, b, c)に対応して、Bプロセッサ用の対応する命令として、複数の機械命令関数からなる命令群(B_ADD(a, b, c)とB_SHIFR(a, 1))が記憶されている例が示されている。 FIG. 5 further shows an instruction group (B_ADD () including a plurality of machine instruction functions as corresponding instructions for the B processor corresponding to the averaging process instructions (A_AVE a, b, c) for the A processor. An example is shown in which a, b, c) and B_SHIFR (a, 1)) are stored.
図5には、Aプロセッサ用の命令と、それに対応するBプロセッサ用の1以上の機械命令関数とが対応していることを示す例とが示されているが、変換テーブル18において、左側31には、通常のAプロセッサで実行可能な命令あるいは命令群で、右側32には、左側31の命令、あるいは命令群のそれぞれに対応する、Bプロセッサ用の1以上の機械命令関数を含むようにしてもよい。
FIG. 5 shows an example showing that an instruction for the A processor corresponds to one or more machine instruction functions for the B processor corresponding to the instruction for the A processor. Includes one or more machine instruction functions for the B processor corresponding to each of the instructions on the
そして、次に、CPU11aは、Aバイナリコード15aから高級言語のC言語ソースコードを生成する(ステップS5)。C言語ソースコードを生成するときに、変換テーブル18を参照して抽出した、Bプロセッサ用の機械命令関数を含むように、CPU11aは、C言語ソースコードを生成する。従って、Aバイナリコード15aは、プログラマにより最適化され、Aプロセッサ用の命令が使われていたが、結果として、その最適化の知恵をBプロセッサ用のBバイナリコード16aにも反映させることができる。ステップS4とS5は、Aプロセッサ用の所定の命令を、抽出された所定の機械命令関数に書き換えて、Aバイナリコード15aから、Bプロセッサ用のプログラムコードとして、Bプロセッサ用のC言語ソースコード23を生成するトランスレータ部を構成する。
Then, the
以上のように、ステップS5において出力されたC言語ソースコードは、Bプロセッサ用の機械命令関数を含む高級言語のソースコードである。従って、後述するステップS7においてコンパイルされるときには、Bプロセッサ用の機械命令関数を使ったBバイナリコード16aが生成されるので、Aプロセッサ用に最適化されたAバイナリコード15aと同様の最適化されたBバイナリコード16aとなる。上述の例では、Bコンパイラ17bは、確実にB_MAX命令を生成することが可能となる。
As described above, the C language source code output in step S5 is a high-level language source code including a machine instruction function for the B processor. Therefore, when compiling in step S7, which will be described later, the B binary code 16a using the machine instruction function for the B processor is generated, so that the same optimization as the A binary code 15a optimized for the A processor is performed. B binary code 16a. In the above example, the
従って、Bプロセッサ用の機械命令関数を含むC言語ソースコードが生成されるので、C言語ソースコードの可読性が向上し、かつそのC言語ソースコードをBコンパイラ17bでコンパイルすると、Bプロセッサ上での性能が、Aプロセッサと同等に維持することが期待できる。
Therefore, since C language source code including machine instruction functions for the B processor is generated, readability of the C language source code is improved, and when the C language source code is compiled by the
次に、CPU11aは、Aソースコード21を参照して、Aソースコード21中に、所定の形式で書かれたコメント文を抽出し、ステップS5で生成して得られたC言語ソースコード中に、所定のルールに従って、抽出したコメント文を埋め込む、すなわち挿入する(ステップS6)。ステップS6が、コメント文記述形式判定部を構成する。
Next, the
一般に、従来方法による逆コンパイル方法では、Aバイナリコード15aから逆コンパイルして得られた高級言語ソースコード中には、Aプロセッサ向けのAソースコードのコメント文は復元されないため、高級言語ソースコードの可読性は低い。これは、通常のデバッグ情報にはコメント文の情報は含まれないうえに、従来の逆コンパイル技術は、ソースコードの入手ができない状況を想定しているためである。 In general, in the conventional decompile method, the comment text of the A source code for the A processor is not restored in the high level language source code obtained by decompiling from the A binary code 15a. Readability is low. This is because the comment information is not included in the normal debugging information, and the conventional decompilation technique assumes that the source code cannot be obtained.
また、最終的に作成されたAプロセッサ向けに書かれたAソースコード21は、Aプロセッサのアーキテクチャに特化した人手により修正等されたアセンブリコードや、Aコンパイラ22のみが認識可能な指示子を含んでおり、Bコンパイラ17bではそのような修正等に対応したバイナリコードが生成できない。
The A source code 21 written for the A processor that is finally created includes assembly code that has been manually modified for the A processor architecture, and an indicator that only the
しかし、Aソースコード21が入手可能な場合であっても、一旦Aコンパイラ22によりAバイナリコード15aを得てから、高級言語のC言語ソースコード23へ逆コンパイルをする方法は有効であり、かつその場合に、Aソースコード21中のコメント文の復元は望ましい。
However, even when the A source code 21 is available, it is effective to once obtain the A binary code 15a by the
そこで、本実施の形態のプログラム変換装置1においては、Aソースコード21を利用して、C言語ソースコード23中にコメント文が復元されるように構成されている。
Therefore, the
ステップS6における、所定の形式で書かれたコメント文とは、例えば、Doxygenのようなドキュメント自動生成システムで採用されているような記述ルールに基づいて書かれたコメント文である。従って、CPU11aは、ソースコード中のコメント文が、所定の形式で書かれているか否かを判定し、判定の結果、あるコメント文がその所定の形式で書かれている場合は、ステップS5で生成されたC言語ソースコードに、その所定の形式に従って、そのコメント文を埋め込む。
The comment sentence written in the predetermined format in step S6 is a comment sentence written based on a description rule adopted in a document automatic generation system such as Doxygen. Therefore, the
従って、トラスレータ部17aは、Aソースコードを参照して、Aプロセッサ用のソースコード中のコメント文が所定の形式で記述されているか否かを判定するコメント文記述形式判定部を含む。そして、トランスレータ部17aは、Aソースコード21中のコメント文が所定の形式で記述されていると判定した場合は、その所定の形式に従って、所定の形式で記述されていると判定されたコメント文を、Bプロセッサ用のソースコードであるC言語ソースコード23中に埋め込んで、C言語ソースコード23を生成する。
Therefore, the
例を挙げて説明する。
例えば、Aプロセッサ用のソースコードであるAソースコード21に、次のようなコードがあったとする。
An example will be described.
For example, assume that the following code is included in the A source code 21 which is the source code for the A processor.
・・・・
int max(int a,int b){ return (a > b ? a : b); }
/* this function returns max value */
int min(int a,int b){ return (a > b ? b : a); } ・・・(4)
・・・・
上記ソースコード(4)は、2つの関数定義と、その2つの関数定義の間に書かれた1行のコメント文を含むソースコードである。このソースコード(4)をコンパイル後、高級言語のC言語ソースコードに逆変換する際、コメント文の部分を関数maxと共に復元できれば可読性を上げることができる。しかし、一般的には、Aバイナリコード15aにデバッグ情報が含まれていれば、関数名や変数名は復元可能であるが、上記のコメント文は、2つの関数定義、すなわちmaxとminのどちらの関数について書かれたものなのかを自動的に判断することは不可能である。
...
int max (int a, int b) {return (a> b? a: b);}
/ * this function returns max value * /
int min (int a, int b) {return (a> b? b: a);} (4)
...
The source code (4) is a source code including two function definitions and a one-line comment sentence written between the two function definitions. When this source code (4) is compiled and then converted back to a high-level C language source code, the readability can be improved if the comment sentence portion can be restored together with the function max. However, in general, if debug information is included in the A binary code 15a, the function name and variable name can be restored. However, the above comment statement has two function definitions, namely, max and min. It is impossible to automatically determine whether the function is written for.
これに対して、本実施の形態では、Aソースコード21のコメント文が、ドキュメント自動生成システム等のために所定の形式で書かれている場合、その形式に従って、コメント文の位置を判定し、その判定した位置に対応するように、その所定の形式に従って、生成したC言語ソースコード中にコメント文を埋め込むようにした。 On the other hand, in the present embodiment, when the comment sentence of the A source code 21 is written in a predetermined format for an automatic document generation system or the like, the position of the comment sentence is determined according to the format, According to the predetermined format, a comment sentence is embedded in the generated C language source code so as to correspond to the determined position.
例えば、上記ソースコード(4)をDoxygen(例えば、http://www.stack.nl/~dimitri/doxygen/を参照)のドキュメント自動生成システムにおいて予め定められた形式に従って書くと、次のようになる。 For example, when the above source code (4) is written according to a predetermined format in a document automatic generation system of Doxygen (for example, see http://www.stack.nl/~dimitri/doxygen/), the following is given: Become.
・・・・
/** this function returns max value */
int max(int a,int b){ return (a > b ? a : b); }
int min(int a,int b){ return (a > b ? b : a); } ・・・(5)
・・・・
ソースコード(5)において、「/**」 から始まるコメントは、Doxygenのドキュメント自動生成システムにおいて定められた形式に基づいて書かれたコメントであることを示す。言い換えれば、ソースコード(5)中の変数、関数等についてのコメント文は、Doxygenのドキュメント自動生成システムにおいて定められた形式に従って、書かれていることを明示的に表している。
Doxygenのドキュメント自動生成システムには、そのコメント文と対応する変数、関数は、その直後に定義されているものであるという予め決められたルールがあり、そのルールに従った形式で、コメント文が書かれている。
...
/ ** this function returns max value * /
int max (int a, int b) {return (a> b? a: b);}
int min (int a, int b) {return (a> b? b: a);} (5)
...
In the source code (5), a comment starting with “/ **” indicates that the comment is written based on a format defined in the Doxygen automatic document generation system. In other words, comments about variables, functions, etc. in the source code (5) explicitly indicate that they are written according to a format defined in the Doxygen automatic document generation system.
The Doxygen automatic document generation system has a predetermined rule that the variable and function corresponding to the comment text are defined immediately after that, and the comment text is formatted in accordance with the rule. has been written.
従って、本実施の形態のトランスレータ17aは、生成した高級言語のC言語ソースコード中に、その所定の形式の記述に従って、抽出したコメント文を埋め込むようにした。具体的には、「/**」のようなシンボル、すなわち記号等の識別子と、「this function returns max value」のようなコメント文との対応関係を利用することにより、トランスレータ17aは、生成した高級言語のC言語ソースコード中に、関係する関数等に適切に対応付けて、コメントを復元することが可能になる。
Therefore, the
その結果、ユーザは、C言語ソースコード23中に適切にコメント文が復元されているので、可読性が上がり、C言語ソースコード23のデバッグ、仕様変更対応、性能チューニング等を容易にすることができる。
As a result, since the comment sentence is appropriately restored in the C
次に、CPU11aは、Aソースコード21を参照して、Aソースコード21中のマクロ宣言文を抽出し、ステップS5で生成して得られたC言語ソースコード中に、抽出されたマクロ宣言のテキスト表現等がないかマッチングを行う。一致する箇所が見つかった場合は、C言語ソースコード中に、そのマクロ宣言文とマクロ表現を埋め込む(ステップS7)。ステップS7は、Aソースコード21を参照してAソースコード21中のマクロ宣言文を抽出するマクロ宣言抽出部を構成する。例えば、ステップS7では、Aソースコード21中のマクロ宣言文のリストが生成され、その生成されたリストに含まれるマクロの定義を参照して、C言語ソースコード23について、各マクロの定義に該当する、すなわち各マクロと一致する箇所にその定義が埋め込まれる。
Next, the
さらに、CPU11aは、Aソースコード21を参照して、Aソースコード21からinclude宣言文を抽出し、ステップS5で生成して得られたC言語ソースコード中に、抽出されたincludeファイルの内容と等価な箇所がないかマッチングをする。等価な箇所が見つかった場合は、C言語ソースコード中に、該当するinclude宣言文を埋め込む(ステップS8)。ステップS8が、Aバイナリコード21を参照してAソースコード21中のinclude宣言文を抽出するインクルード宣言抽出部を構成する。例えば、ステップS8では、Aソースコード21中のinclude宣言文を含むファイルの内容を参照して、C言語ソースコード23中にそのinclude宣言文を含むファイル中に記述された内容と等価な内容が検出されたときには、そのC言語ソースコード23にinclude宣言文を追加する。
Further, the
ステップS7とS8について、具体的に説明する。
例えば、Aプロセッサ用のソースコードであるAソースコード21が次の2つのファイル”myheader.h”と”main.c”から構成されていたとする。
Steps S7 and S8 will be specifically described.
For example, it is assumed that the A source code 21 which is the source code for the A processor is composed of the following two files “myheader.h” and “main.c”.
・ファイル名 myheader.hの内容
#define THRESHOLD 127
int binary_filter(unsigned char a){return (a>THRESHOLD ? 255:0);}
・ファイル名 main.cの内容
#include “myheader.h”
int main(){
unsigned char x = 120;
return binary_filter(x);
}
マクロ宣言文である「#define THRESHOLD 127」は、「127」がスレッシュホールド値であることを宣言している。
-File name Contents of myheader.h
#define THRESHOLD 127
int binary_filter (unsigned char a) {return (a> THRESHOLD? 255: 0);}
-File name Contents of main.c
#include “myheader.h”
int main () {
unsigned char x = 120;
return binary_filter (x);
}
The macro declaration statement “#define THRESHOLD 127” declares that “127” is a threshold value.
include宣言文である「#include “myheader.h”」は、ファイル名が「myheader.h」は、includeされることを宣言している。 The include declaration statement “#include“ myheader.h ”” declares that the file name “myheader.h” is included.
これらのinclude宣言文やマクロ宣言文は全てAコンパイラ22によって展開されるため、これらのソースコードに対応するバイナリコードに対してステップS1〜S5の処理を適用した結果は、以下のように1つのファイル”main2.c”となる。
Since all of these include declaration statements and macro declaration statements are expanded by the
・ファイル名 main2.cの内容
int binary_filter(unsigned char a){return (a>127 ? 255:0);}
int main(){
unsigned char x = 120;
return binary_filter(x);
}
Aソースコード21で使われているinclude宣言文の数やマクロ宣言文の数が増えるに従い、上記の結果のソースコードの可読性は下がる。
・ Contents of file name main2.c
int binary_filter (unsigned char a) {return (a> 127? 255: 0);}
int main () {
unsigned char x = 120;
return binary_filter (x);
}
As the number of include declaration statements and macro declaration statements used in the A source code 21 increases, the readability of the resulting source code decreases.
そこで、本実施の形態のトランスレータ17aは、生成した高級言語のC言語ソースコードに対してマクロ宣言文とinclude宣言文を復元する。
Therefore, the
ここでは、ステップS7では、ソースコード21を参照し、「#define・・・」のようなマクロ宣言文が抽出され、ファイル名がmyheader.hであるマクロ宣言文が追加される。さらに、ステップS7では、ファイル名 main2.c中において、「127」が、そのマクロ表現である「THRETHHOLD」に置き換えられる。このようにして、マクロ宣言文とマクロ表現が埋め込まれる。 Here, in step S7, the source code 21 is referred to, a macro declaration sentence such as “#define...” Is extracted, and a macro declaration sentence whose file name is myheader.h is added. In step S7, “127” is replaced with “THRETHHOLD” which is the macro expression in the file name main2.c. In this way, macro declaration statements and macro expressions are embedded.
また、ステップS8では、Aソースコード21を参照し、Aソースコード21中からinclude宣言文が抽出される。そして、include宣言文の追加は、ファイル名 main2.c中の「binary filter・・」が、参照したAソースコード21中にあるため、そのinclude宣言された関数myheader.hをincludeするinclude宣言文が生成され追加される。 In step S8, the A source code 21 is referred to, and an include declaration statement is extracted from the A source code 21. The include declaration statement is added because the "binary filter ..." in the file name main2.c is in the referenced A source code 21, so the include declaration statement that includes the function myheader.h in which the include declaration is included. Is created and added.
その結果、上記の1つのファイルであるプログラムmain2.cは、上記2つのファイルmain.cとmyheader.hに置換される。言い換えると、元のAソースコード21で使用されていたマクロ宣言文とinclude宣言文が復元される。よって、C言語ソースコード23の可読性は上がり、デバッグ、仕様変更、性能チューニング等を容易にすることができる。
As a result, the program main2.c, which is the one file, is replaced with the two files main.c and myheader.h. In other words, the macro declaration statement and the include declaration statement used in the original A source code 21 are restored. Therefore, the readability of the C
さらに、CPU11aは、Aソースコード21を参照して、Aソースコード21中の行番号情報とシンボル情報を、ステップS5で生成して得られたC言語ソースコード中に埋め込む(ステップS9)。ステップS9が、C言語ソースコード23に、Aソースコード21のシンボル情報と行番号情報を埋め込む、シンボル及び行番号情報埋め込み部を構成する。
Further, the
例えば、CPU11aは、Aプロセッサ用のソースコードであるAソースコード21に次のようなコードがあったとする。左端の数字は便宜的な行番号であり、実際のソースコードには含まれない。
For example, it is assumed that the
・ファイル名 func.c の内容
1: void function(){
2: if(b > c) a = b;
3: else a = c;
4: }
上記に対してステップS1〜S5を適用した結果、例えば、次のようになったとする。
・ Contents of file name func.c
1: void function () {
2: if (b> c) a = b;
3: else a = c;
Four: }
As a result of applying Steps S1 to S5 to the above, for example, assume the following.
void f(){
B_MAX(a, b, c);
}
ここでは、トランスレータ17aがプロセッサBの最大値命令B_MAXを利用したコードを生成している例である。この例ではB_MAX(a,b,c)が最大値を得る処理をしていることは、そのテキスト表現から容易に類推できるが、一般的に、プロセッサBのために並列化などの高度な最適化を施した機械命令関数が出力された場合、処理内容を把握し、デバッグ・チューニングをすることは困難になる。
void f () {
B_MAX (a, b, c);
}
In this example, the
そこで、ステップS9では、本実施の形態のトランスレータ17aは、生成した高級言語のC言語ソースコードに対して、次のように、行番号情報とシンボル情報を埋め込む。
Therefore, in step S9, the
void f(){ /** func.c, L1 function */
B_MAX(a, b, c); /** func.c, L2,3 */
}
上記のプログラムには、関数f()に対応するAソースコード21の内容が”func.c”の1行目にあり、シンボル情報としてのシンボル名が”function”であること、B_MAX()に対応する内容が”func.c”の2,3行目にあることの情報が含まれている。これらの情報をユーザが直接解釈してAソースコード21を参照することで処理内容を理解することも可能である。
void f () {/ ** func.c, L1 function * /
B_MAX (a, b, c); / ** func.c, L2,3 * /
}
In the above program, the content of the A source code 21 corresponding to the function f () is on the first line of “func.c”, the symbol name as symbol information is “function”, and B_MAX () It contains information that the corresponding contents are in the second and third lines of “func.c”. It is also possible for the user to understand the processing contents by directly interpreting the information and referring to the A source code 21.
さらに、この埋め込まれた情報を、プロセッサBの並列化コンパイラ部が適切に解釈し、所定の形式で、プロセッサBのバイナリコード中に、デバッガ19が利用可能なデバッグ情報として埋め込む。通常、プロセッサBのデバッガ19は、プロセッサBのバイナリコード16aをデバッグする際、プロセッサBのソースコード23を参照可能である。そして、ユーザは、プロセッサBのデバッガ19により、プロセッサAのソースコード21を適宜参照することが可能となる。
Further, the embedded information is appropriately interpreted by the parallelizing compiler unit of the processor B, and is embedded as debug information usable by the debugger 19 in the binary code of the processor B in a predetermined format. Normally, the debugger 19 of the processor B can refer to the
図6は、Bバイナリコードをデバッガ19によりデバッグしているときに、表示装置13の画面上に表示されるデバッグ画面の例を示す図である。画面31上には、Bバイナリコードあるいはアセンブリコードを表示するバイナリコード表示部32と、C言語ソースコード23を表示するBバイナリコードに対応するソースコード表示部33と、Aソースコードを表示するソースコード表示部34とが表示される。
FIG. 6 is a diagram illustrating an example of a debug screen displayed on the screen of the
ユーザは、バイナリコード表示部32に表示されたバイナリコードあるいはアセンブリコードと、ソースコード表示部33に表示されたC言語ソースコードとだけでなく、ソースコード表示部34に表示されたAソースコード21も参照しながら、Bバイナリコードのデバッグ等をすることができる。
The user not only includes the binary code or assembly code displayed on the binary
ユーザは、バイナリコード表示部32に表示されたコード中、所望の行を選択すると、その選択された行に対応するプログラム部分が、ソースコード表示部33と34において例えば、ハイライト表示等が行われる。
When the user selects a desired line in the code displayed on the binary
よって、入力装置12を利用してユーザが指定するBバイナリコード部分に対応するC言語ソースコード部分だけでなく、Bバイナリコード部分に対応するAソースコード部分も、ソースコード表示部34に表示されるので、ユーザは、変換元のソースプログラムを参照しながら、Bバイナリコード16aのデバッグ等を行うことができる。
Therefore, not only the C source code part corresponding to the B binary code part specified by the user using the
なお、シンボル情報と行番号の埋め込みは、トランスレータ17aを介した処理に限定されない。例えば、プロセッサAのソースコードをプロセッサAの並列化コンパイラにより、いったんプロセッサAマルチコア向けのソースコードあるいはマルチスレッド化コードを生成する場合、上記した例と同様に、プロセッサAマルチコア向けのソースコード、あるいはマルチスレッド化コード中に、プロセッサAのソースコードのシンボル情報と行番号情報を埋め込むようにしてもよい。これにより、プロセッサA並列化コードデバッガから元のソースコードの参照が可能となる。
Note that the embedding of symbol information and line numbers is not limited to processing via the
図4に戻り、ステップS5により、C言語ソースコード23が生成され、さらに上述したステップS6からS9の処理が終了すると、次に、Bコンパイラ17bが、C言語ソースコード23をコンパイルして、Bバイナリコード16aを生成する(ステップS10)。
Returning to FIG. 4, the C
ここで、コンパイラ部であるBコンパイラ17bとして、並列化コンパイラが使用される。並列化コンパイラを用いることによって、Aプロセッサが並列処理に対応していないが、Bプロセッサが並列処理に対応している場合、C言語ソースコード23からBバイナリコード16aを生成するときに、バイナリコード16aはBプロセッサ用の並列度に対応した、並列プログラムのコードとすることができる。並列化コンパイラによって、C言語ソースコード23を並列化プログラムにすることができる。
Here, a parallelizing compiler is used as the
例えば、次のようなループ処理を考える。 For example, consider the following loop processing.
for(int i = 0; i < 256; i++) a[i] = b[i] + c[i]; ・・・(6)
そして、Aプロセッサが2並列SIMD(Single Instruction/Multiple Data)加算命令を持たず、一方でBプロセッサが2並列SIMD加算命令、例えばB_ADD_SIMD2、を持つ場合を仮定する。このとき、Aプロセッサでは256回加算命令を繰り返すが、Bプロセッサでは128(=256/2)回のSIMD加算命令で済む。そこで、Bコンパイラ17bとしてVLIW(Very Long Instruction Word)/SIMD並列化コンパイラを使用することにより、AプロセッサとBプロセッサの演算並列度の差異を吸収することができる。
for (int i = 0; i <256; i ++) a [i] = b [i] + c [i]; (6)
Assume that the A processor does not have a 2-parallel SIMD (Single Instruction / Multiple Data) addition instruction, while the B processor has a 2-parallel SIMD addition instruction, for example, B_ADD_SIMD2. At this time, the A processor repeats the addition instruction 256 times, but the B processor only needs 128 (= 256/2) SIMD addition instructions. Therefore, by using a VLIW (Very Long Instruction Word) / SIMD parallelizing compiler as the
以上のようにして、Bコンパイラ17bに、並列化コンパイラを用いることによって、Aプロセッサが並列処理に対応していなくても、Bプロセッサが並列化処理に対応している場合には、バイナリコード16aは、Bプロセッサ用の並列度に対応したコードとすることができる。
As described above, by using a parallelizing compiler for the
言い換えると、BプロセッサがAプロセッサよりも高並列な命令実行が可能な場合、当然Aバイナリコード15aにはそのような高並列命令は含まれないため、Bプロセッサの高並列命令を生かしきれない虞れがある。そこで、Bコンパイラ17bとして、Bプロセッサの高並列度に対応したコンパイラを用いることにより、Aバイナリコード15aから生成されるBバイナリコード16aは、Bプロセッサの高並列度に対応したコードとすることができる。
In other words, if the B processor is capable of executing instructions with higher parallel than the A processor, the A binary code 15a naturally does not include such a highly parallel instruction, so that the highly parallel instruction of the B processor may not be fully utilized. There is. Therefore, by using a compiler corresponding to the high parallelism of the B processor as the
さらに、Bコンパイラの並列化コンパイル機能に、マルチスレッド化あるいはマルチコア化の機能が含まれている場合でも、上記と同様の効果、すなわち高並列度に対応したコードとすることができるという効果が得られる。 Furthermore, even when the parallel compilation function of the B compiler includes a multi-threading or multi-core function, the same effect as described above, that is, an effect that a code corresponding to a high degree of parallelism can be obtained. It is done.
以上のように、本実施の形態によれば、異なるプロセッサ間でプログラムコードの変換を行う場合に、変換元のバイナリコードに含まれるプログラム上の工夫を、変換先のバイナリコードに反映することができるプログラムコード変換装置を実現することができる。 As described above, according to the present embodiment, when the program code is converted between different processors, the program device included in the conversion source binary code can be reflected in the conversion destination binary code. It is possible to realize a program code conversion device that can be used.
さらに、本実施の形態によれば、変換元のオブジェクトコードであるバイナリコードから、高級言語コードを生成するときに、変換元のバイナリコードの元となるソースコードに含まれていたコメント文、マクロ宣言文等が、その高級言語コード中に適切に復元されるので、ユーザは、高級言語コードのデバッグ、仕様変更対応、性能チューニング等を容易にすることができる。 Furthermore, according to the present embodiment, when a high-level language code is generated from a binary code that is a conversion source object code, a comment sentence or a macro included in the source code that is the source of the conversion source binary code. Since the declaration sentence and the like are appropriately restored in the high-level language code, the user can easily debug the high-level language code, cope with specification changes, and perform performance tuning.
なお、本明細書における各「部」は、実施の形態の各機能に対応する概念的なもので、必ずしも特定のハードウエアやソフトウエア・ルーチンに1対1には対応しない。従って、本実施の形態における各手順の各ステップは、その性質に反しない限り、実行順序を変更し、複数同時に実行し、あるいは実行毎に異なった順序で実行してもよい。 Each “unit” in this specification is a conceptual one corresponding to each function of the embodiment, and does not necessarily correspond to specific hardware or software routine on a one-to-one basis. Therefore, each step of each procedure in the present embodiment may be executed in a different order for each execution by changing the execution order and executing a plurality of steps at the same time, as long as it does not contradict its nature.
さらに、以上説明した動作を実行するプログラムコードは、フレキシブルディスク、CD−ROM等の可搬媒体や、ハードディスク等の記憶装置等の記録媒体に、その全体あるいは一部が記録され、あるいは記憶される。そのプログラムコードは、コンピュータにより読み取られて、動作の全部あるいは一部が実行されるコンピュータプログラム製品として提供することができる。あるいは、そのプログラムコードの全体あるいは一部を通信ネットワークを介して流通または提供することができる。利用者は、通信ネットワークを介してそのプログラムコードをダウンロードしてコンピュータにインストールしたり、あるいは記録媒体からコンピュータにインストールすることで、容易に本発明のプログラムコード変換装置を実現することができる。
本発明は、上述した実施の形態に限定されるものではなく、本発明の要旨を変えない範囲において、種々の変更、改変等が可能である。
Furthermore, the program code for executing the operations described above is recorded or stored in whole or in part on a portable medium such as a flexible disk or CD-ROM, or a recording medium such as a storage device such as a hard disk. . The program code is read by a computer and can be provided as a computer program product in which all or part of the operation is executed. Alternatively, all or part of the program code can be distributed or provided via a communication network. The user can easily realize the program code conversion apparatus of the present invention by downloading the program code via a communication network and installing the program code in a computer or installing the program code from a recording medium into the computer.
The present invention is not limited to the above-described embodiments, and various changes and modifications can be made without departing from the scope of the present invention.
1 プログラム変換装置、11 計算機本体、12 入力装置、13 表示装置、14
記憶装置、15 変換元のバイナリコード、16 変換先のバイナリコード、17 変換
処理プログラム、18 変換テーブル、31 画面
1 program conversion device, 11 computer main body, 12 input device, 13 display device, 14
Storage device, 15 conversion source binary code, 16 conversion destination binary code, 17 conversion processing program, 18 conversion table, 31 screens
Claims (5)
前記第1のバイナリコードを解析するコード解析部と、
該コード解析部により解析して得られた前記第1のプロセッサ用の所定の1以上の命令に対応する、前記第2のプロセッサ用の所定の1以上の機械命令関数を抽出する機械命令関数抽出部と、
前記第1のプロセッサ用の前記所定の1以上の命令を、前記機械命令関数抽出部により抽出された前記所定の1以上の機械命令関数に書き換えて、前記第1のバイナリコードから前記第2のプロセッサ用のプログラムコードとして、前記第2のプロセッサ用のソースコードを生成するトランスレータ部と、
を有することを特徴とするプログラムコード変換装置。 A program code conversion device for converting a first binary code executable in a first processor into a program code for a second processor,
A code analysis unit for analyzing the first binary code;
Machine instruction function extraction for extracting one or more predetermined machine instruction functions for the second processor corresponding to one or more predetermined instructions for the first processor obtained by analysis by the code analysis unit And
The predetermined one or more instructions for the first processor are rewritten to the predetermined one or more machine instruction functions extracted by the machine instruction function extraction unit, and the second binary code is converted into the second one from the first binary code. A translator for generating source code for the second processor as program code for the processor;
A program code conversion apparatus comprising:
前記機械命令関数抽出部は、前記対応テーブルを参照することによって、解析して得られた前記第1のプロセッサ用の前記所定の1以上の命令に対応する、前記第2のプロセッサ用の前記所定の1以上の機械命令関数を抽出することを特徴とする請求項1に記載のプログラムコード変換装置。 A correspondence table in which the predetermined one or more instructions for the first processor are associated with the predetermined one or more machine instruction functions for the second processor;
The machine instruction function extraction unit refers to the correspondence table, and corresponds to the predetermined instruction for the second processor corresponding to the predetermined one or more instructions for the first processor obtained by analysis. The program code conversion apparatus according to claim 1, wherein one or more machine instruction functions are extracted.
前記トランスレータ部は、前記コメント文記述形式判定部が前記第1のプロセッサ用のソースコード中の前記コメント文が前記所定の形式で記述されていると判定した場合は、前記所定の形式に従って、前記所定の形式で記述されていると判定された前記コメント文を、前記第2のプロセッサ用のソースコード中に埋め込んで、前記第2のプロセッサ用のソースコードを生成することを特徴とする請求項1または2に記載のプログラムコード変換装置。 Referring to the source code for the first processor corresponding to the first binary code, it is determined whether or not a comment sentence in the source code for the first processor is described in a predetermined format It has a comment statement description format determination unit,
The translator unit, when the comment statement description format determination unit determines that the comment statement in the source code for the first processor is described in the predetermined format, according to the predetermined format, The source code for the second processor is generated by embedding the comment sentence determined to be described in a predetermined format in the source code for the second processor. 3. The program code conversion device according to 1 or 2.
前記コード解析部により、前記第1のバイナリコードを解析し、
前記機械命令関数抽出部により、前記コード解析部により解析して得られた前記第1のプロセッサ用の所定の1以上の命令に対応する、前記第2のプロセッサ用の所定の1以上の機械命令関数を抽出し、
前記トランスレータ部により、前記第1のプロセッサ用の前記所定の1以上の命令を、前記機械命令関数抽出部により抽出された前記所定の1以上の機械命令関数に書き換えて、前記第1のバイナリコードから前記第2のプロセッサ用のプログラムコードとして、前記第2のプロセッサ用のソースコードを生成することを特徴とするプログラムコード変換方法。 Program code conversion method for converting a first binary code executable in a first processor into a program code for a second processor by a computer having a code analysis unit, a machine instruction function extraction unit, and a translator unit Because
The code analysis unit analyzes the first binary code,
The predetermined one or more machine instructions for the second processor corresponding to the predetermined one or more instructions for the first processor obtained by analysis by the code analysis unit by the machine instruction function extraction unit. Extract the function,
The translator unit rewrites the predetermined one or more instructions for the first processor into the predetermined one or more machine instruction functions extracted by the machine instruction function extraction unit, and the first binary code A program code conversion method comprising: generating source code for the second processor as program code for the second processor.
Priority Applications (3)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
JP2007333098A JP2008276735A (en) | 2007-04-03 | 2007-12-25 | Program code converter and program code conversion method |
US12/059,160 US20080250231A1 (en) | 2007-04-03 | 2008-03-31 | Program code conversion apparatus, program code conversion method and recording medium |
GB0805992A GB2448225A (en) | 2007-04-03 | 2008-04-02 | Computer program for converting or translating code executable on a first processor to code executable on a second processor. |
Applications Claiming Priority (2)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
JP2007097845 | 2007-04-03 | ||
JP2007333098A JP2008276735A (en) | 2007-04-03 | 2007-12-25 | Program code converter and program code conversion method |
Publications (1)
Publication Number | Publication Date |
---|---|
JP2008276735A true JP2008276735A (en) | 2008-11-13 |
Family
ID=40054575
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
JP2007333098A Pending JP2008276735A (en) | 2007-04-03 | 2007-12-25 | Program code converter and program code conversion method |
Country Status (1)
Country | Link |
---|---|
JP (1) | JP2008276735A (en) |
Cited By (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
JP2012038231A (en) * | 2010-08-11 | 2012-02-23 | Internatl Business Mach Corp <Ibm> | Compile method for optimizing binary code, compiler system therefor, and computer program |
WO2012032807A1 (en) * | 2010-09-10 | 2012-03-15 | 株式会社フィックスターズマルチコアラボ | Execution module optimization device, execution module optimization method, and program |
JP2013504124A (en) * | 2009-09-02 | 2013-02-04 | アドバンスト・マイクロ・ディバイシズ・インコーポレイテッド | A lightweight service-based dynamic binary rewriter framework |
US9563547B2 (en) | 2014-02-14 | 2017-02-07 | International Business Machines Corporation | Testing optimized binary modules |
US11556317B2 (en) | 2020-05-22 | 2023-01-17 | Fujitsu Limited | Instruction translation support method and information processing apparatus |
US11635947B2 (en) | 2020-05-22 | 2023-04-25 | Fujitsu Limited | Instruction translation support method and information processing apparatus |
Citations (10)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
JPH06202903A (en) * | 1992-12-29 | 1994-07-22 | Nec Corp | Cpu simulation and cpu simulator |
JPH096629A (en) * | 1995-06-21 | 1997-01-10 | Toshiba Microelectron Corp | Program conversion method |
JPH096646A (en) * | 1995-06-14 | 1997-01-10 | Oki Electric Ind Co Ltd | Program simulation device |
JPH1031595A (en) * | 1996-07-15 | 1998-02-03 | Nec Corp | Simulator and its simulating method |
JPH10187494A (en) * | 1996-12-27 | 1998-07-21 | Oki Data:Kk | Simulator |
JP2000132403A (en) * | 1998-10-21 | 2000-05-12 | Matsushita Electric Ind Co Ltd | Program converting device |
JP2004252807A (en) * | 2003-02-21 | 2004-09-09 | Matsushita Electric Ind Co Ltd | Software development support device |
JP2004295398A (en) * | 2003-03-26 | 2004-10-21 | Toshiba Corp | Compiler, method for compiling and program developing tool |
JP2006243839A (en) * | 2005-02-28 | 2006-09-14 | Toshiba Corp | Instruction generation device and instruction generation method |
US20070006178A1 (en) * | 2005-05-12 | 2007-01-04 | Microsoft Corporation | Function-level just-in-time translation engine with multiple pass optimization |
-
2007
- 2007-12-25 JP JP2007333098A patent/JP2008276735A/en active Pending
Patent Citations (10)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
JPH06202903A (en) * | 1992-12-29 | 1994-07-22 | Nec Corp | Cpu simulation and cpu simulator |
JPH096646A (en) * | 1995-06-14 | 1997-01-10 | Oki Electric Ind Co Ltd | Program simulation device |
JPH096629A (en) * | 1995-06-21 | 1997-01-10 | Toshiba Microelectron Corp | Program conversion method |
JPH1031595A (en) * | 1996-07-15 | 1998-02-03 | Nec Corp | Simulator and its simulating method |
JPH10187494A (en) * | 1996-12-27 | 1998-07-21 | Oki Data:Kk | Simulator |
JP2000132403A (en) * | 1998-10-21 | 2000-05-12 | Matsushita Electric Ind Co Ltd | Program converting device |
JP2004252807A (en) * | 2003-02-21 | 2004-09-09 | Matsushita Electric Ind Co Ltd | Software development support device |
JP2004295398A (en) * | 2003-03-26 | 2004-10-21 | Toshiba Corp | Compiler, method for compiling and program developing tool |
JP2006243839A (en) * | 2005-02-28 | 2006-09-14 | Toshiba Corp | Instruction generation device and instruction generation method |
US20070006178A1 (en) * | 2005-05-12 | 2007-01-04 | Microsoft Corporation | Function-level just-in-time translation engine with multiple pass optimization |
Cited By (7)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
JP2013504124A (en) * | 2009-09-02 | 2013-02-04 | アドバンスト・マイクロ・ディバイシズ・インコーポレイテッド | A lightweight service-based dynamic binary rewriter framework |
JP2012038231A (en) * | 2010-08-11 | 2012-02-23 | Internatl Business Mach Corp <Ibm> | Compile method for optimizing binary code, compiler system therefor, and computer program |
WO2012032807A1 (en) * | 2010-09-10 | 2012-03-15 | 株式会社フィックスターズマルチコアラボ | Execution module optimization device, execution module optimization method, and program |
US9563547B2 (en) | 2014-02-14 | 2017-02-07 | International Business Machines Corporation | Testing optimized binary modules |
US9569347B2 (en) | 2014-02-14 | 2017-02-14 | International Business Machines Corporation | Testing optimized binary modules |
US11556317B2 (en) | 2020-05-22 | 2023-01-17 | Fujitsu Limited | Instruction translation support method and information processing apparatus |
US11635947B2 (en) | 2020-05-22 | 2023-04-25 | Fujitsu Limited | Instruction translation support method and information processing apparatus |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US20080250231A1 (en) | Program code conversion apparatus, program code conversion method and recording medium | |
TWI463404B (en) | Compiling systems and methods | |
US9081586B2 (en) | Systems and methods for customizing optimization/transformation/ processing strategies | |
US20090144705A1 (en) | Debugging device and debugging method | |
EP3244306B1 (en) | A computer-implemented method for allowing modification of a region of original code | |
US7917899B2 (en) | Program development apparatus, method for developing a program, and a computer program product for executing an application for a program development apparatus | |
JP2008276735A (en) | Program code converter and program code conversion method | |
JP2005141410A (en) | Compiler apparatus and compile method | |
JP2007304840A (en) | Compilation method, debugging method, compilation program, and debugging program | |
JP2009176064A (en) | Software refactoring support device and method | |
JP2009169864A (en) | Compile method and compile program | |
JP5399601B2 (en) | Implementation code development system and implementation code development program | |
KR101632027B1 (en) | Method for converting program using pseudo code based comment and computer-readable recording media storing the program performing the said mehtod | |
JP6175306B2 (en) | Control program dividing apparatus, control program dividing method and recording medium therefor | |
JP5974444B2 (en) | Information processing system, information processing method, information processing program, and recording medium | |
JP2009258796A (en) | Program development device and program development method | |
JP2007226358A (en) | Application generation device, application generation method, and application generation program | |
JP2014099108A (en) | Execution time calculating device, execution time calculating method, and program | |
JP2008015665A (en) | Program analysis method and program analyzer | |
JP6326838B2 (en) | Program processing apparatus, program processing method, and program processing program | |
JP2014106770A (en) | Type check device, type check method and type check program | |
JP2011090511A (en) | Execution program, compiler, and device and method of correcting execution program operation | |
Bluemke et al. | A tool supporting C code parallelization | |
JP4019361B2 (en) | Parallelization conversion system, parallelization conversion method, program, and compiler | |
JP2006146731A (en) | Program, storage medium, assembler device, compiler device, simulator device and emulator device |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
A621 | Written request for application examination |
Effective date: 20100216 Free format text: JAPANESE INTERMEDIATE CODE: A621 |
|
A977 | Report on retrieval |
Effective date: 20120315 Free format text: JAPANESE INTERMEDIATE CODE: A971007 |
|
A131 | Notification of reasons for refusal |
Free format text: JAPANESE INTERMEDIATE CODE: A131 Effective date: 20120717 |
|
A02 | Decision of refusal |
Free format text: JAPANESE INTERMEDIATE CODE: A02 Effective date: 20121113 |