JP2005085051A - Software converter - Google Patents

Software converter Download PDF

Info

Publication number
JP2005085051A
JP2005085051A JP2003317600A JP2003317600A JP2005085051A JP 2005085051 A JP2005085051 A JP 2005085051A JP 2003317600 A JP2003317600 A JP 2003317600A JP 2003317600 A JP2003317600 A JP 2003317600A JP 2005085051 A JP2005085051 A JP 2005085051A
Authority
JP
Japan
Prior art keywords
function
label
instruction
source code
branch
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
JP2003317600A
Other languages
Japanese (ja)
Inventor
Takayuki Harada
貴之 原田
Shohei Oishi
昇平 大石
Masanori Kako
正典 加古
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 Holdings Corp
Original Assignee
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 Matsushita Electric Industrial Co Ltd filed Critical Matsushita Electric Industrial Co Ltd
Priority to JP2003317600A priority Critical patent/JP2005085051A/en
Publication of JP2005085051A publication Critical patent/JP2005085051A/en
Pending legal-status Critical Current

Links

Images

Landscapes

  • Devices For Executing Special Programs (AREA)
  • Stored Programmes (AREA)

Abstract

<P>PROBLEM TO BE SOLVED: To provide a software converter capable of generating a source code according to a grammar of a high-level language. <P>SOLUTION: A label detection means 102 detects a head label and a label that is an argument of a call sentence from assembly language source codes 101. A first function division means 105 converts an instruction inside high-level language source codes 104 related to the labels into a format of a function, makes all the instructions inside the high-level language source codes 104 belong to the function, and divides the function by the label that is the argument of the call sentence converted into the function. <P>COPYRIGHT: (C)2005,JPO&NCIPI

Description

本発明は、あるマイクロコンピュータ(以下、マイコンと称す。)のCPUで実行可能なアセンブリ言語で記述されたソースコード(以下、アセンブリ言語ソースコードと称す。)を、別のCPUを搭載したマイコンで実行可能な高級言語(CやC++など)のソースコード(以下、高級言語ソースコードと称す。)に逆変換するソフトウェア変換装置に関する。   The present invention relates to a source code described in an assembly language (hereinafter referred to as assembly language source code) executable by a CPU of a certain microcomputer (hereinafter referred to as a microcomputer) by a microcomputer equipped with another CPU. The present invention relates to a software conversion device that performs reverse conversion into executable high-level language (C, C ++, etc.) source code (hereinafter referred to as high-level language source code).

セット機能の多機能化にともない、組み込みマイコンのソフトウェア開発において、高級言語であるC言語やC++言語などを用いてソフトウェアを開発する機会が増加している。一方で、従来から用いられてきたアセンブリ言語のソフトウェア資産を流用する機会も多く、アセンブリ言語ソースコードを高級言語ソースコードに逆変換(逆コンパイル)し、高級言語ソースコードで一元管理する必要性が高まってきている。このようなソフトウェア変換装置(逆コンパイラ)は、主に組み込みマイコンのソフトウェア開発に用いられている(例えば、特許文献1参照。)。   As the set functions become multi-functional, opportunities for developing software using C language, C ++ language, etc., which are high-level languages, are increasing in software development of embedded microcomputers. On the other hand, there are many opportunities to divert assembly language software assets that have been used in the past, and there is a need to reverse-convert (decompile) assembly language source code into high-level language source code and centrally manage it using high-level language source code. It is increasing. Such a software conversion device (decompiler) is mainly used for software development of an embedded microcomputer (for example, see Patent Document 1).

従来のソフトウェア変換装置は、アセンブリ言語の命令を対応する高級言語の命令に1対1で置き換えることで、逆変換を実施していた。
例えば、
Label equ *
MOV A,ram
ADD A,#2
MOV ram,A
のようなアセンブリ言語ソースコードを、
Label:
D1 = ram;
D1 += 2;
ram = D1;
のように、対応する高級言語ソースコードに変換していた。
A conventional software conversion apparatus performs reverse conversion by replacing assembly language instructions with corresponding high-level language instructions on a one-to-one basis.
For example,
Label equ *
MOV A, ram
ADD A, # 2
MOV ram, A
Assembly language source code, such as
Label:
D1 = ram;
D1 + = 2;
ram = D1;
It was converted into the corresponding high-level language source code.

しかしながら、従来のソフトウェア変換装置は、命令を1対1に置き換えるのみであるため、アセンブリ言語で記述されたcall文などの分岐命令を単に高級言語の関数コールに変換するのみであり、逆コンパイル後の高級言語ソースコードにはその分岐先のラベル(call文の引数となっているラベルなど)が関数に変換されることなくそのまま残っていた。そのため、逆コンパイル後の高級言語ソースコードに対してコンパイルしたとき、関数コールの分岐先の関数が存在しないためにエラーとなり、コンパイルできない場合も多かった。
特表2001−515240号公報(第9−16頁、第一図)
However, since the conventional software conversion device only replaces the instruction one-to-one, it simply converts a branch instruction such as a call statement described in assembly language into a function call in a high-level language, and after decompilation. In the high-level language source code, the branch destination label (such as a label that is an argument of the call statement) remains as it is without being converted into a function. For this reason, when compiling high-level language source code after decompilation, there are many cases in which the function call branch destination function does not exist and an error occurs and compilation is not possible.
JP-T-2001-515240 (pages 9-16, Fig. 1)

本発明は、上記問題点に鑑み、逆コンパイル後の高級言語ソースコード内の先頭ラベルと分岐ラベル(call文の引数となっているラベルなど)に関連する命令を関数の形式に変換し、高級言語ソースコード内の命令をすべて関数に属するものにし、関数化した分岐ラベルでその関数を分割することにより、高級言語の文法に則ったソースコードを生成するソフトウェア変換装置を提供することを目的とする。   In view of the above problems, the present invention converts an instruction related to a head label and a branch label (such as a label that is an argument of a call statement) in a high-level language source code after decompilation into a function format. An object of the present invention is to provide a software conversion device that generates a source code that conforms to the grammar of a high-level language by making all instructions in a language source code belong to a function and dividing the function by a functionalized branch label. To do.

一方、このようにすべての命令が関数に属するようにし、かつ関数化した分岐ラベルでその関数を分割した場合、ラベルに分岐する命令(goto文など)の分岐先のラベルがその分岐命令の関数単位外のラベルとなり、コンパイルできなくなるおそれがある。   On the other hand, when all the instructions belong to the function and the function is divided by the functionalized branch label, the branch destination label of the instruction that branches to the label (such as a goto statement) is the function of the branch instruction. There is a possibility that it will become a label out of the unit and cannot be compiled.

そこで、本発明は、上記問題点に鑑み、関数単位外のラベルに分岐する命令の分岐先のラベルに関連する高級言語ソースコード内の命令を関数の形式に変換し、高級言語ソースコードをその分岐先のラベルでさらに分割することにより、高級言語の文法に則ったソースコードを生成するソフトウェア変換装置を提供することを目的とする。   Therefore, in view of the above problems, the present invention converts an instruction in a high-level language source code related to a branch destination label of an instruction that branches to a label outside a function unit into a function format, and converts the high-level language source code into the function format. It is an object of the present invention to provide a software conversion device that generates source code in accordance with a grammar of a high-level language by further dividing by a branch destination label.

本発明の請求項1記載のソフトウェア変換装置は、アセンブリ言語ソースコードを高級言語ソースコードに逆変換するソフトウェア変換装置において、アセンブリ言語ソースコードの中から先頭のラベルと分岐ラベルを検出するラベル検出手段と、前記ラベル検出手段の検出結果に応じて、検出したラベルに関連する高級言語ソースコード内の命令を関数の形式に変換し、該高級言語ソースコードを分岐ラベルで分割する第1の関数分割手段とを備えることを特徴とする。   The software conversion device according to claim 1 of the present invention is a software conversion device that reversely converts assembly language source code into high-level language source code, and a label detection means for detecting a leading label and a branch label from the assembly language source code. And a first function division for converting an instruction in the high-level language source code related to the detected label into a function format according to the detection result of the label detection means, and dividing the high-level language source code by a branch label. Means.

本発明の請求項2記載のソフトウェア変換装置は、請求項1記載のソフトウェア変換装置であって、前記第1の関数分割手段により関数の形式に変換された高級言語ソースコードの中から、別の関数単位内のラベルへ分岐する分岐命令の分岐先のラベルを検出する分岐先ラベル検出手段と、前記分岐先ラベル検出手段の検出結果に応じて、検出した前記分岐先のラベルに関連する高級言語ソースコード内の命令を関数の形式に変換し、該高級言語ソースコードを前記分岐先のラベルで分割するとともに、前記別の関数単位内のラベルへ分岐する分岐命令を関数へ分岐するための関数コールに置き換える第2の関数分割手段とを備えることを特徴とする。   A software conversion device according to claim 2 of the present invention is the software conversion device according to claim 1, wherein the high-level language source code converted into the function format by the first function dividing means is different from the high-level language source code. Branch destination label detection means for detecting a branch destination label of a branch instruction that branches to a label in a function unit, and a high-level language related to the detected branch destination label according to the detection result of the branch destination label detection means A function for converting an instruction in the source code into a function format, dividing the high-level language source code by the branch destination label, and branching a branch instruction for branching to the label in the other function unit to the function And a second function dividing means for replacing with a call.

本発明の請求項3記載のソフトウェア変換装置は、請求項1もしくは2のいずれかに記載のソフトウェア変換装置であって、前記第1の関数分割手段は、高級言語ソースコードの先頭のラベルを関数化するとともに該高級言語ソースコードの終端に関数終了を表す記号を挿入して該高級言語ソースコードの先頭のラベル以下の命令を関数内の命令とし、前記分岐ラベルを関数化するとともにその直前に関数の分割を表す記号を挿入して該高級言語ソースコードを分割することを特徴とする。   The software conversion device according to claim 3 of the present invention is the software conversion device according to any one of claims 1 and 2, wherein the first function dividing means uses a first label of the high-level language source code as a function. At the end of the high-level language source code, a symbol indicating the end of the function is inserted, and the instruction below the first label of the high-level language source code is used as an instruction in the function. The high-level language source code is divided by inserting a symbol representing the division of the function.

本発明の請求項4記載のソフトウェア変換装置は、請求項2乃至3のいずれかに記載のソフトウェア変換装置であって、前記第2の関数分割手段は、前記分岐先のラベルを関数化するとともにその直前に関数の分割を表す記号を挿入して該高級言語ソースコードを分割することを特徴とする。   The software conversion device according to claim 4 of the present invention is the software conversion device according to any one of claims 2 to 3, wherein the second function dividing means converts the label of the branch destination into a function. The high-level language source code is divided by inserting a symbol representing the division of the function immediately before that.

本発明の請求項5記載のソフトウェア変換装置は、請求項3もしくは4のいずれかに記載のソフトウェア変換装置であって、前記第1の関数分割手段は、前記関数の分割を表す記号に加えて、その直前に関数化された分岐ラベルへ分岐する関数コールを挿入することを特徴とする。   The software conversion device according to claim 5 of the present invention is the software conversion device according to claim 3 or 4, wherein the first function dividing means includes a symbol representing the division of the function. In this case, a function call that branches to a functionalized branch label is inserted immediately before.

本発明の請求項6記載のソフトウェア変換装置は、請求項4もしくは5のいずれかに記載のソフトウェア変換装置であって、前記第2の関数分割手段は、前記関数の分割を表す記号に加えて、その直前に関数化された分岐先のラベルへ分岐する関数コールを挿入することを特徴とする。   A software conversion device according to a sixth aspect of the present invention is the software conversion device according to any one of the fourth or fifth aspects, wherein the second function dividing means includes a symbol representing the division of the function. , A function call for branching to a branch destination label that has been functionalized immediately before is inserted.

本発明の請求項7記載のソフトウェア変換装置は、請求項6記載のソフトウェア変換装置であって、前記分岐ラベルや前記分岐先のラベルの直前に配置されている命令が関数終了命令であることを検出する関数終了命令検出手段と、前記関数終了命令検出手段による関数終了命令の検出に応じて、前記分岐ラベルや前記分岐先のラベルの直前に関数コールが挿入されないようにする不要命令省略手段とを備えることを特徴とする。   The software conversion device according to claim 7 of the present invention is the software conversion device according to claim 6, wherein the instruction arranged immediately before the branch label or the branch destination label is a function end instruction. A function end instruction detecting unit for detecting, and an unnecessary instruction omitting unit for preventing a function call from being inserted immediately before the branch label or the branch destination label in response to detection of the function end instruction by the function end instruction detecting unit; It is characterized by providing.

本発明の請求項8記載のソフトウェア変換装置は、請求項3乃至7のいずれかに記載のソフトウェア変換装置であって、前記分岐ラベルや前記分岐先のラベルの直前に配置されている命令がテーブルデータ命令であることを検出するテーブルデータ命令検出手段と、前記テーブルデータ命令検出手段によるテーブルデータ命令の検出に応じて、前記関数の分割を表す記号の挿入先を前記分岐ラベルや前記分岐先のラベルの直前に代えてテーブルデータ命令の直前にし、テーブルデータ命令が関数単位外に配置されるようにするテーブルデータ配置変更手段とを備えることを特徴とする。   The software conversion device according to claim 8 of the present invention is the software conversion device according to any one of claims 3 to 7, wherein an instruction arranged immediately before the branch label or the branch destination label is a table. A table data instruction detecting means for detecting that the instruction is a data instruction, and in response to detection of the table data instruction by the table data instruction detecting means, an insertion destination of the symbol representing the division of the function is set to the branch label or the branch destination Table data arrangement changing means is provided immediately before the table data instruction instead of immediately before the label so that the table data instruction is arranged outside the function unit.

本発明の請求項9記載のソフトウェア変換装置は、請求項1乃至8のいずれかに記載のソフトウェア変換装置であって、前記分岐ラベルがcall文の引数であることを特徴とする。   A software conversion device according to claim 9 of the present invention is the software conversion device according to any one of claims 1 to 8, wherein the branch label is an argument of a call statement.

本発明の請求項10記載のソフトウェア変換装置は、請求項2乃至9のいずれかに記載のソフトウェア変換装置であって、前記別の関数単位内のラベルへ分岐する分岐命令がgoto文であることを特徴とする。   The software conversion device according to claim 10 of the present invention is the software conversion device according to any one of claims 2 to 9, wherein the branch instruction for branching to the label in the other function unit is a goto statement. It is characterized by.

本発明の請求項11記載のソフトウェア変換装置は、請求項7乃至10のいずれかに記載のソフトウェア変換装置であって、前記関数終了命令がreturn命令またはgoto命令であることを特徴とする。   A software conversion device according to an eleventh aspect of the present invention is the software conversion device according to any one of the seventh to tenth aspects, wherein the function end instruction is a return instruction or a goto instruction.

本発明によれば、アセンブリ言語を高級言語に逆コンパイル(逆変換)するに際し、アセンブリ言語にcall文などのラベルに分岐する命令が記述されている場合であっても、その分岐命令の分岐先のラベル(分岐ラベル)を関数化し、高級言語のソースコード内の命令をすべて関数に属するものにし、関数化した分岐ラベルでこの関数を分割するので、高級言語の文法に則ったソースコードを生成することができる。   According to the present invention, when an assembly language is decompiled into a high-level language (inverse conversion), even when an instruction that branches to a label such as a call statement is described in the assembly language, the branch destination of the branch instruction The label (branch label) is converted into a function, all the instructions in the high-level language source code belong to the function, and this function is divided by the functionalized branch label, so the source code conforming to the high-level language grammar is generated. can do.

また、このようにすべての命令を関数に属するものにし、かつ関数化した分岐ラベルでその関数を分割することにより、goto文などのラベルに分岐する命令の分岐先のラベルがその分岐命令の関数単位外のラベルとなった場合であっても、この分岐命令を関数コールに置き換え、その分岐先のラベルを関数化し、この関数化した分岐先のラベルでさらに高級言語ソースコードを分割するので、高級言語の文法に則ったソースコードを生成することができる。   In addition, when all instructions belong to a function in this way and the function is divided by a functionalized branch label, the branch destination label of an instruction that branches to a label such as a goto statement is the function of the branch instruction. Even when the label is out of the unit, this branch instruction is replaced with a function call, the label of the branch destination is converted into a function, and the high-level language source code is further divided by the functionalized branch destination label. Source code that conforms to the grammar of high-level languages can be generated.

また、関数化した分岐ラベルや分岐先のラベルで関数を分割するに際し、関数を分割する記号の直前にその直後の関数化したラベルへ分岐する関数コールを挿入するので、分岐することなしに高級言語ソースコードの流れの順に処理が行われる場合であっても、論理の整合性を取ることができる。   In addition, when a function is divided by a functionalized branch label or a branch destination label, a function call that branches to the functionalized label immediately after that is inserted immediately before the symbol that divides the function. Even if processing is performed in the order of the flow of the language source code, logic consistency can be achieved.

一方、関数化する分岐ラベルや分岐先のラベルの直前の命令が関数終了命令である場合には関数コールを挿入しないので、ソースコードのコードサイズを圧縮することができる。   On the other hand, since the function call is not inserted when the instruction immediately before the branch label to be functionalized or the branch destination label is a function end instruction, the code size of the source code can be compressed.

また、関数化する分岐ラベルや分岐先のラベルの直前の命令がテーブルデータ命令である場合には、そのテーブルデータ命令の直前で関数が終了するようにするので、高級言語の文法に則ったソースコードを生成することができる。   If the instruction immediately before the branch label to be converted or the label at the branch destination is a table data instruction, the function ends immediately before the table data instruction. Code can be generated.

以下、本発明の実施の形態について、図面を交えて説明する。
図1は、本実施の形態におけるソフトウェア変換装置の構成を示す概略図である。
図1において、ラベル検出手段102はアセンブリ言語ソースコード101の中から先頭のラベルと分岐ラベル(例えば、call文の引数となっているラベル)を検出し、これらのラベルをデータベースに登録する。逆コンパイラ103はアセンブリ言語ソースコード101を逆コンパイルして高級言語ソースコード104に変換する。
Hereinafter, embodiments of the present invention will be described with reference to the drawings.
FIG. 1 is a schematic diagram showing a configuration of a software conversion apparatus according to the present embodiment.
In FIG. 1, a label detection unit 102 detects a leading label and a branch label (for example, a label that is an argument of a call statement) from the assembly language source code 101, and registers these labels in a database. The decompiler 103 decompiles the assembly language source code 101 and converts it into a high-level language source code 104.

第1の関数分割手段105は、データベースに登録されたラベルに関連する高級言語ソースコード104内の命令を関数の形式に変換し、高級言語ソースコード104を分岐ラベルで分割する。ここでは、第1の関数分割手段105は、高級言語ソースコード104の先頭のラベルを関数化するとともに高級言語ソースコード104の終端に関数終了を表す記号“}”を挿入して高級言語ソースコード104の先頭のラベル以下の命令を関数内の命令とし、分岐ラベルを関数化するとともにその直前に関数の分割を表す記号(関数終了を表す記号)“}”を挿入して高級言語ソースコード104を分割する。   The first function dividing unit 105 converts an instruction in the high-level language source code 104 related to the label registered in the database into a function format, and divides the high-level language source code 104 by the branch label. Here, the first function dividing means 105 converts the leading label of the high-level language source code 104 into a function and inserts a symbol “}” indicating the end of the function at the end of the high-level language source code 104 to thereby convert the high-level language source code. The instruction below the first label of 104 is used as an instruction in the function, the branch label is converted into a function, and a symbol (} symbol) indicating the division of the function is inserted immediately before it to display the high-level language source code 104 Split.

さらに、第1の関数分割手段105は、分岐ラベルの直前にその分岐ラベルへ分岐する関数コールを挿入する。
また、第1の関数分割手段105内の関数終了命令検出手段106は、分岐ラベルの直前に配置されているreturn命令やgoto命令などの関数終了命令を検出する。
Further, the first function dividing means 105 inserts a function call that branches to the branch label immediately before the branch label.
The function end instruction detection means 106 in the first function dividing means 105 detects a function end instruction such as a return instruction or a goto instruction arranged immediately before the branch label.

不要命令省略手段107は、関数終了命令検出手段106による関数終了命令の検出に応じて、関数コールが挿入されないようにする。
テーブルデータ命令検出手段108は、分岐ラベルの直前に配置されているテーブルデータ命令を検出する。
The unnecessary instruction omitting unit 107 prevents the function call from being inserted in response to the function end instruction detecting unit 106 detecting the function end instruction.
The table data instruction detecting means 108 detects a table data instruction arranged immediately before the branch label.

テーブルデータ配置変更手段109は、テーブルデータ命令検出手段108によりテーブルデータ命令が検出された場合、関数終了を表す記号“}”の挿入先を分岐ラベルの直前からテーブルデータ命令の直前に変更し、テーブルデータ命令が後述する関数単位外に配置されるようにする。   When the table data instruction is detected by the table data instruction detecting means 108, the table data arrangement changing means 109 changes the insertion destination of the symbol “}” indicating the end of the function from immediately before the branch label to immediately before the table data instruction, The table data instruction is arranged outside the function unit described later.

また、分岐先ラベル検出手段110は、第1の関数分割手段105により関数の形式に変換された高級言語ソースコードの中から、別の関数単位内のラベルへ分岐する分岐命令の分岐先のラベルを検出する。   Further, the branch destination label detection unit 110 is a branch destination label of a branch instruction that branches to a label in another function unit from the high-level language source code converted into the function format by the first function division unit 105. Is detected.

第2の関数分割手段111は、分岐先ラベル検出手段110により検出された分岐先のラベルに関連する高級言語ソースコード内の命令を関数の形式に変換し、この高級言語ソースコードを分岐先のラベルで分割するとともに、分岐命令を関数へ分岐するための関数コールに置き換える。ここでは、第2の関数分割手段111は、分岐先のラベルを関数化するとともにその直前に関数の分割を表す記号(関数終了を表す記号)“}”を挿入して該高級言語ソースコードを分割する。   The second function dividing unit 111 converts an instruction in the high-level language source code related to the branch destination label detected by the branch destination label detecting unit 110 into a function format, and converts the high-level language source code into the branch destination label. Divide by label and replace the branch instruction with a function call to branch to the function. Here, the second function dividing unit 111 converts the label at the branch destination into a function, and inserts a symbol (} indicating a function end) “}” indicating the division of the function immediately before it, and outputs the high-level language source code. To divide.

さらに、第2の関数分割手段111は、分岐先のラベルの直前にこの分岐先のラベルへ分岐する関数コールを挿入する。
また、第2の関数分割手段111内の関数終了命令検出手段106は、分岐先のラベルの直前に配置されているreturn命令やgoto命令などの関数終了命令を検出する。
Further, the second function dividing unit 111 inserts a function call that branches to the branch destination label immediately before the branch destination label.
In addition, the function end instruction detection means 106 in the second function dividing means 111 detects a function end instruction such as a return instruction or a goto instruction arranged immediately before the branch destination label.

不要命令省略手段107は、関数終了命令検出手段106による関数終了命令の検出に応じて、関数コールが挿入されないようにする。
テーブルデータ命令検出手段108は、分岐先のラベルの直前に配置されているテーブルデータ命令を検出する。
The unnecessary instruction omitting unit 107 prevents the function call from being inserted in response to the function end instruction detecting unit 106 detecting the function end instruction.
The table data instruction detecting unit 108 detects a table data instruction arranged immediately before the branch destination label.

テーブルデータ配置変更手段109は、テーブルデータ命令検出手段108によりテーブルデータ命令が検出された場合、関数終了を表す記号“}”の挿入先を分岐先のラベルの直前からテーブルデータ命令の直前に変更し、テーブルデータ命令が後述する関数単位外に配置されるようにする。   When the table data instruction is detected by the table data instruction detecting means 108, the table data arrangement changing means 109 changes the insertion destination of the symbol “}” indicating the end of the function from immediately before the branch destination label to immediately before the table data instruction. The table data instruction is arranged outside the function unit described later.

本実施の形態におけるソフトウェア変換装置は、以上のような構成からなることにより目的とする高級言語ソースコード112を得ることができる。
以下、該ソフトウェア変換装置の動作について、まずラベル検出手段と第1の関数分割手段の動作から詳説する。
The software conversion apparatus according to the present embodiment can obtain the target high-level language source code 112 by being configured as described above.
Hereinafter, the operation of the software conversion apparatus will be described in detail from the operations of the label detecting means and the first function dividing means.

図2(a)は、call文の検索による関数分割を説明するためのフローチャート図である。まず、ステップS201において、アセンブリ言語ソースコードから先頭のラベルと分岐ラベルであるcall文の引数になっているラベルをすべて検索する。次に、ステップS202において、ステップS201で検索したすべてのラベルを関数テーブル(データベース)204に登録する。最後に、ステップS203において、関数テーブル204に登録されたラベルに基づいて、アセンブリ言語ソースコードを逆コンパイルして得た高級言語ソースコード内の先頭のラベルとcall文の引数になっているラベルに関連する命令を関数の形式に変換する。   FIG. 2A is a flowchart for explaining the function division by searching for a call sentence. First, in step S201, all labels that are arguments of the call statement as the head label and branch label are searched from the assembly language source code. Next, in step S202, all the labels searched in step S201 are registered in the function table (database) 204. Finally, in step S203, based on the label registered in the function table 204, the first label in the high-level language source code obtained by decompiling the assembly language source code and the label that is the argument of the call statement are used. Convert related instructions to function form.

この変換処理は、以下のような処理により行う。例えばラベルLabel1がcall文の引数になっており、関数テーブルに登録されている場合、アセンブリ言語ソースコードを逆コンパイルして得た高級言語ソースコードには、
Label1:
と記述されている。そこで、まずこのラベルの直前にgoto文を記述して、
goto Label1;
Label1:
とした後、この“Label1:”の直前に関数終了を表す記号(関数の分割を表す記号)“}”を挿入するとともに、このラベルを関数化して、
Label1( );return;

void Label1(void){
と置き換える。なお、ラベルLabel1が関数化されるので、“goto Label1;”は関数へ分岐するための関数コール“Label1( );return;”に置換される。
This conversion process is performed by the following process. For example, when the label Label1 is an argument of a call statement and is registered in the function table, the high-level language source code obtained by decompiling the assembly language source code includes:
Label1:
It is described. So, first, put a goto statement just before this label,
goto Label1;
Label1:
Then, a symbol indicating the end of the function (a symbol indicating the division of the function) “}” is inserted immediately before “Label1:”, and this label is converted into a function.
Label1 (); return;
}
void Label1 (void) {
Replace with Since the label Label1 is functionalized, “goto Label1;” is replaced with a function call “Label1 (); return;” for branching to the function.

また、一番先頭のラベルも関数テーブル204に登録しておき、この一番先頭のラベルを関数化するとともに、ファイルの終端に関数終了を表す記号“}”を挿入することにより、すべての命令が関数に属するようになる。   The first label is also registered in the function table 204, and the first label is converted into a function, and a symbol “}” indicating the end of the function is inserted at the end of the file, so that all instructions Belongs to a function.

例えば、先頭のラベルがラベルLabel1の場合、アセンブリ言語ソースコードを逆コンパイルして得た高級言語ソースコードには、
Label1:
と記述されており、このラベルを関数化して
void Label1(void){
と置き換えるとともに、ファイルの終端に関数終了を表す記号“}”を挿入する。
For example, when the first label is a label Label1, high-level language source code obtained by decompiling assembly language source code includes:
Label1:
And this label is converted into a function, void Label1 (void) {
And the symbol “}” indicating the end of the function is inserted at the end of the file.

以上のように、ソースコード内の一番先頭のラベルを関数化してファイルの終端に関数終了を表す記号“}”を挿入するとともに、call文の引数となっているラベル(分岐ラベル)の直前に関数終了を表す記号“}”を挿入してこのラベルを関数化することにより、すべての命令が関数に属するようになり、かつcall文の引数となっているラベルで高級言語ソースコードが分割される。   As described above, the first label in the source code is converted into a function, and the symbol “}” indicating the end of the function is inserted at the end of the file, and immediately before the label (branch label) that is the argument of the call statement. By inserting the symbol “}” indicating the end of the function into a function and making this label a function, all instructions belong to the function, and the high-level language source code is divided by the label that is the argument of the call statement Is done.

図3は本実施の形態におけるcall文の検索による関数分割の一実施例である。
まず、アセンブリ言語ソースコード301より、先頭のラベルであるラベルLabel1とcall文の引数であるラベルLabel3を関数テーブルに登録する。
FIG. 3 shows an example of function division by retrieval of a call sentence in the present embodiment.
First, from the assembly language source code 301, the label Label1 as the first label and the label Label3 as the argument of the call statement are registered in the function table.

次に、この関数テーブルに基づいて、アセンブリ言語ソースコード301を逆コンパイルして得たソースコード302を関数分割する。すなわち、ラベルLabel3の直前にgoto文“goto Label3;”を記述してソースコード303とした後、ラベルLabel1を関数化してファイルの終端に関数終了を表す記号“}”を挿入するとともに、ラベルLabel3の直前に関数終了を表す記号“}”を挿入してこのラベルを関数化することにより、ラベルLabel3で関数分割された高級言語ソースコード304を得る。   Next, based on this function table, the source code 302 obtained by decompiling the assembly language source code 301 is divided into functions. That is, after describing the goto statement “goto Label3;” immediately before the label Label3 into the source code 303, the label Label1 is functionalized to insert the symbol “}” indicating the end of the function at the end of the file, and the label Label3 A high-level language source code 304 that is function-divided by the label Label 3 is obtained by inserting the symbol “}” indicating the end of the function immediately before “” to make this label a function.

なお、ソースコード303のgoto文“goto Label4”はラベルLabel4へ分岐するgoto命令であるのでそのまま残され、goto文“goto Label3”は関数“void Label3(void){”へ分岐するgoto命令であるので関数コール“Label3( );return;”に置換される。   Note that the goto statement “goto Label4” in the source code 303 is a goto instruction that branches to the label Label4, and therefore remains as it is, and the goto statement “goto Label3” is a goto instruction that branches to the function “void Label3 (void) {”. Therefore, the function call “Label 3 (); return;” is replaced.

以上のようにcall文の検索による関数分割を行うことで、全命令が関数に属するようになる。しかしながら、この処理のみでは、関数外のラベルへ分岐するgoto文(分岐命令)が残る場合がある。   As described above, by performing function division by searching for a call statement, all instructions belong to functions. However, only this processing may leave a goto statement (branch instruction) that branches to a label outside the function.

例えば、図3に示す例では、ソースコード304に
goto Label4:
が残り、関数“void Label1(void){”から関数“void Label3(void){”へ分岐する構成になり、高級言語の文法に則さずに、コンパイル時に不具合が発生する。
For example, in the example shown in FIG. 3, goto Label4:
Therefore, the function “void Label1 (void) {” branches to the function “void Label3 (void) {”, and a problem occurs at the time of compiling without conforming to the grammar of the high-level language.

そこで、本実施の形態ではこの問題を回避するために、分岐先ラベル検出手段と第2の関数分割手段により、関数外のラベルに分岐するgoto文の検索による関数分割を行う。   Therefore, in this embodiment, in order to avoid this problem, function division is performed by searching for a goto statement that branches to a label outside the function by the branch destination label detection means and the second function division means.

図2(b)は、goto文の検索による関数分割を説明するためのフローチャート図である。
まず、処理開始時におけるステップS211では、関数テーブル214はcall文の検索による関数分割の処理時に得た関数テーブル204と同じものである。
FIG. 2B is a flowchart for explaining function division by searching for a goto sentence.
First, in step S211 at the start of processing, the function table 214 is the same as the function table 204 obtained at the time of function division processing by retrieval of a call statement.

次に、ステップS212において、call文の検索による関数分割後のソースコードの先頭から順に関数化されていないラベル(分岐先のラベル)を検索する。関数化されていないラベルが見つかった場合、そのラベルに分岐するgoto文(分岐命令)をすべて検索する。   Next, in step S212, labels that are not functionalized (branch destination labels) are searched in order from the beginning of the source code after function division by the search of the call statement. If a non-functionalized label is found, all goto statements (branch instructions) that branch to that label are searched.

続いて、ステップS213において、ステップS212にて検索されたラベルで高級言語ソースコードを関数分割するか否かの判定を行う。
この判定処理は以下のようにして行う。すなわち、関数テーブル214に基づいて、関数化されたラベルから次の関数化されたラベルの直前の行までを1つの関数単位とし、関数化されていないラベルとそのラベルに分岐するgoto文が同じ関数単位に属しているか否かを判定する。関数化されていないラベルとそのラベルに分岐するすべてのgoto文が同じ関数単位に属する場合は、そのラベルとgoto文をそのまま残し、ステップS212へ移行して次の関数化されていないラベルの検索に移る。一方、関数化されていないラベルとそのラベルに分岐するgoto文が別の関数単位に属する場合、ステップS214へ移行し、そのラベルに関連する高級言語ソースコード内の命令を関数の形式に変換する。本実施の形態では、このようにして別の関数単位内のラベルへ分岐する分岐命令の分岐先のラベルの検出を行う。
Subsequently, in step S213, it is determined whether or not the high-level language source code is function-divided using the label searched in step S212.
This determination process is performed as follows. That is, based on the function table 214, one functional unit is from the functionalized label to the line immediately before the next functionalized label, and the non-functionalized label and the goto statement branching to the label are the same. Determine whether it belongs to a function unit. If the unfunctionalized label and all the goto statements that branch to the label belong to the same function unit, the label and the goto statement are left as they are, and the process proceeds to step S212 to search for the next unfunctionalized label. Move on. On the other hand, if the label that is not functionalized and the goto statement that branches to the label belong to another function unit, the process proceeds to step S214, and the instruction in the high-level language source code related to the label is converted into the function format. . In this embodiment, the branch destination label of a branch instruction that branches to a label in another function unit is detected in this way.

また、ステップS214における変換処理は、以下のような処理により行う。例えばラベルLabel1が関数化されていないラベルであって、このラベルLabel1に分岐するgoto文が別の関数単位に属する場合、call文の検索による関数分割後のソースコードには、
Label1:
と記述されている。そこで、まずこのラベルの直前にgoto文を記述して、
goto Label1;
Label1:
とした後、この“Label1:”の直前に関数終了を表す記号(関数の分割を表す記号)“}”を挿入するとともに、このラベルを関数化し、
Label1( );return;

void Label1(void){
と置き換え、ラベルLabel1で高級言語ソースコードを関数分割する。
The conversion process in step S214 is performed by the following process. For example, when the label Label1 is a non-functionalized label and the goto statement that branches to the label Label1 belongs to another function unit, the source code after the function division by the search of the call statement includes
Label1:
It is described. So, first, put a goto statement just before this label,
goto Label1;
Label1:
After that, a symbol indicating the end of the function (a symbol indicating the division of the function) “}” is inserted immediately before “Label1:”, and this label is converted into a function.
Label1 (); return;
}
void Label1 (void) {
And the high-level language source code is function-divided by the label Label1.

また、このようにラベルLabel1が関数化されるので、ラベルLabel1へ分岐する命令である“goto Label1;”は関数へ分岐するための関数コール“Label1( );return;”に置換される。   In addition, since the label Label1 is functionalized in this way, “goto Label1;”, which is an instruction for branching to the label Label1, is replaced with a function call “Label1 (); return;” for branching to the function.

このように新たにラベルを関数化した後、ステップS211へ戻ってそのラベルを関数テーブル214に追加登録し(関数一覧作成)、再度、先頭から関数化されていないラベルの検索を開始する。   After the label is newly converted into a function in this way, the process returns to step S211 to additionally register the label in the function table 214 (function list creation), and the search for the label that has not been converted to a function is started again from the beginning.

以上の処理を関数化されていないラベルとそのラベルに分岐するgoto文がすべて同じ関数単位に属するようになるまで繰り返すことにより、高級言語の文法に則したソースコードを得ることができる。   By repeating the above processing until a label that is not functionalized and a goto statement that branches to the label all belong to the same function unit, a source code that conforms to the grammar of a high-level language can be obtained.

このgoto文の検索による関数分割を図4に示す一実施例に則して説明する。図4において、ソースコード304は図3に示すソースコード304と同じものである。
まず、ソースコード304の先頭から順に関数化されていないラベルを検索し、ラベルLabel2を検出する。次に、このラベルLabel2に分岐するgoto文を検索する。図4に示す例ではこのラベルに関数単位の外から分岐してくるgoto文(別の関数単位内のラベルに分岐する分岐命令)は存在しないので、ラベルLabel2では高級言語ソースコードの関数分割を行わない。
The function division by the search of the goto sentence will be described in accordance with an embodiment shown in FIG. In FIG. 4, the source code 304 is the same as the source code 304 shown in FIG.
First, labels that are not functionalized are searched in order from the top of the source code 304, and the label Label2 is detected. Next, a goto statement that branches to this label Label2 is searched. In the example shown in FIG. 4, since there is no goto statement (branch instruction that branches to a label in another function unit) branching from outside the function unit to this label, the label Label2 performs function division of the high-level language source code. Not performed.

続いて、再度ソースコード304の先頭から順に関数化されていないラベルを検索し、ラベルLabel4を検出する。次に、このラベルLabel4に分岐するgoto文を検索する。図4に示す例では、ラベルLabel4は関数“void Label3(void){”の関数単位に属し、ラベルLabel4へ分岐するgoto文はその関数単位とは別の関数“void Label1(void){”に属するので、ラベルLabel4で高級言語ソースコードの関数分割を行う。   Subsequently, the labels that are not functionalized are sequentially searched again from the top of the source code 304, and the label Label4 is detected. Next, a goto statement that branches to this label Label4 is searched. In the example shown in FIG. 4, the label Label4 belongs to the function unit of the function “void Label3 (void) {”, and the goto statement branching to the label Label4 is assigned to a function “void Label1 (void) {” different from the function unit. Therefore, function division of the high-level language source code is performed with the label Label4.

すなわち、ソースコード304内のラベルLabel4の直前にgoto文“goto Label4;”を記述してソースコード305とした後、ラベルLabel4の直前に関数終了を表す記号“}”を挿入してこのラベルを関数化することにより、ラベルLabel4で分割された高級言語ソースコード306を得る。   That is, after describing the goto statement “goto Label4;” immediately before the label Label4 in the source code 304 to form the source code 305, the symbol “}” indicating the end of the function is inserted immediately before the label Label4, and this label is used. By converting it into a function, the high-level language source code 306 divided by the label Label4 is obtained.

続いて、ソースコード306の先頭から順に関数化されていないラベルの検索を行う。図4に示す例では、関数化されていないラベルはこれ以上存在しないので、ここで作業を終了する。   Subsequently, a search for labels that are not functionalized is performed in order from the top of the source code 306. In the example shown in FIG. 4, since there are no more labels that are not functionalized, the operation ends here.

以上のように、call文の検索による関数分割後の高級言語ソースコードから、別の関数単位内のラベルに分岐するgoto文(分岐命令)の分岐先のラベルを検出し、この分岐先のラベルの直前に関数終了を表す記号“}”挿入するとともにこのラベルを関数化し、かつそのgoto文を関数コールに置き換えることにより、高級言語の関数の文法に則したソースコードを得ることができる。   As described above, the branch destination label of a goto statement (branch instruction) that branches to a label in another function unit is detected from the high-level language source code after function division by the search of the call statement, and this branch destination label is detected. By inserting the symbol “}” indicating the end of the function immediately before “”, converting this label into a function, and replacing the goto statement with a function call, a source code conforming to the grammar of the function of the high-level language can be obtained.

なお、別の関数単位内のラベルに分岐するgoto文(分岐命令)の分岐先のラベルを検出するたびに関数分割を行うのではなく、すべての該当ラベルを関数テーブルに追加登録した後、関数分割するようにしてもよい。   In addition, function division is not performed every time a branch destination label of a goto statement (branch instruction) that branches to a label in another function unit is detected, but after all the corresponding labels are additionally registered in the function table, You may make it divide | segment.

このように、call文の検索による関数分割およびgoto文の検索による関数分割によって、全命令が関数に属し、かつ高級言語の関数の文法に則したソースコードを得ることができる。   As described above, the function division by the search of the call sentence and the function division by the search of the goto sentence can obtain a source code in which all instructions belong to the function and comply with the grammar of the function of the high-level language.

しかしながら、これらの処理により本来不要な命令を追加してしまう場合がある。
例えば、図3、4に示す例では、ラベルLabel3(分岐ラベル)とラベルLabel4(分岐先のラベル)を関数化する際に、そのラベルの直前にgoto命令(関数コール)が挿入される。
However, these processes may add unnecessary instructions.
For example, in the example shown in FIGS. 3 and 4, when a label Label3 (branch label) and a label Label4 (branch destination label) are functionalized, a goto instruction (function call) is inserted immediately before the label.

この命令は、分岐することなしにソースコードの流れの順にLabel3、Label4の処理が行われる場合の対策のために配置しているものである。しかし、図3、4に示す例では、これらの命令はreturn命令の直後に配置されることになるため実行されることは無い。   This instruction is arranged as a countermeasure when the processing of Label3 and Label4 is performed in the order of the source code flow without branching. However, in the example shown in FIGS. 3 and 4, since these instructions are arranged immediately after the return instruction, they are not executed.

そこで、本実施の形態では、関数終了命令検出手段と不要命令削除手段により、関数分割する際に、分割する直前の命令(分岐ラベルや分岐先のラベルの直前の命令)がreturn命令やgoto命令のような関数終了命令の場合には、分岐ラベルや分岐先のラベルの直前にgoto命令を挿入しないようにする。   Therefore, in the present embodiment, when the function is divided by the function end instruction detection means and the unnecessary instruction deletion means, the instruction immediately before the division (the instruction immediately before the branch label or branch destination label) is the return instruction or the goto instruction. In the case of such a function end instruction, a goto instruction is not inserted immediately before a branch label or a branch destination label.

図5(a)は、分割する直前の命令がreturn命令もしくはgoto命令の場合の関数分割を説明するためのフローチャート図である。
まず、ステップS501おいて、call文またはgoto文の検索による関数分割を行うに際し、分割する直前の命令がreturn命令もしくはgoto命令であるか否かを判定する。この判定処理は、関数テーブルに基づいて行ってもよいし、関数テーブルにラベルを登録する際に行ってもよい。
FIG. 5A is a flowchart for explaining function division when the instruction immediately before division is a return instruction or a goto instruction.
First, in step S501, when function division is performed by searching for a call statement or a goto statement, it is determined whether the instruction immediately before the division is a return instruction or a goto instruction. This determination process may be performed based on the function table or may be performed when a label is registered in the function table.

分割する直前の命令がreturn命令もしくはgoto命令であった場合には、ステップS502において、新たに挿入したgoto命令を省略して、あるいはgoto命令を挿入することなく関数分割の処理を施し、それ以外の命令の場合にはステップS503において、goto命令をそのまま配置して関数分割の処理を施し論理の整合性を取る。   If the instruction immediately before the division is a return instruction or a goto instruction, in step S502, the newly inserted goto instruction is omitted or a function division process is performed without inserting a goto instruction. In step S503, the goto instruction is arranged as it is, and function division processing is performed to ensure logic consistency.

例えば、図3に示すソースコード302に対してcall文の検索による関数分割およびgoto文の検索による関数分割を行うに際し、上述したgoto命令を省略する処理を施すことにより、図6に示すソースコード601を得ることができる。このソースコード601は、図4に示すソースコード306と比較して、関数“void Label3(void){”と“void Label4(void){”の前に配置されている関数コール“Label3();return;”と“Label4();return;”が省略されている。   For example, when performing function division by retrieval of a call statement and function division by retrieval of a goto statement with respect to the source code 302 shown in FIG. 3, the above-described goto instruction is omitted so that the source code shown in FIG. 601 can be obtained. Compared with the source code 306 shown in FIG. 4, the source code 601 is a function call “Label3 () arranged before the functions“ void Label3 (void) {”and“ void Label4 (void) {”; "return;" and "Label4 (); return;" are omitted.

さらに、ソースコードがテーブルデータ命令を含む場合、上述したcall文またはgoto文の検索による関数分割を行うとテーブルデータ命令が関数に含まれてしまい、高級言語の文法に則さないソースコードに変換されるという問題がある。ここで、テーブルデータ命令とは、プログラム上の例えば関数の中で使用されるデータ列のみをテーブル化したものを指す。   Furthermore, when the source code includes a table data instruction, if the function is divided by searching for the above-described call statement or goto statement, the table data instruction is included in the function and converted into source code that does not conform to the grammar of the high-level language. There is a problem of being. Here, the table data instruction refers to a table in which only a data string used in, for example, a function on a program is tabulated.

例えば、図7(a)に示すソースコード701に対して、上述したcall文の検索による関数分割およびgoto文の検索による関数分割を行うと、ラベルLabel4の関数化にともない、テーブルデータTable1(dc命令によりデータを2バイト分確保している)が関数内部に配置されたソースコード702に変換される。   For example, when the function division by the search of the call statement and the function division by the search of the goto statement are performed on the source code 701 shown in FIG. 7A, the table data Table1 (dc) is generated along with the functionalization of the label Label4. 2 bytes are secured by the instruction) is converted into the source code 702 arranged inside the function.

そこで、本実施の形態では、テーブルデータ命令検索手段とテーブルデータ配置変更手段により、関数分割する際に、分割する直前の命令(分岐ラベルや分岐先のラベルの直前の命令)がテーブルデータ命令の場合には、関数の分割を表す記号(関数の終了を表す記号)“}”の挿入先を分岐ラベルや分岐先のラベルの直前からテーブルデータ命令の直前に変更し、テーブルデータ命令の配置を関数単位外へ変更する。   Therefore, in this embodiment, when the function is divided by the table data instruction search means and the table data arrangement change means, the instruction immediately before the division (the instruction immediately before the branch label or the branch destination label) is the table data instruction. In this case, the insertion destination of the symbol indicating the division of the function (the symbol indicating the end of the function) “}” is changed from immediately before the branch label or branch label to immediately before the table data instruction, and the arrangement of the table data instruction is changed. Change outside function unit.

図5(b)は、分割する直前の命令がテーブルデータ命令の場合の関数分割を説明するためのフローチャート図である。
まず、ステップS511において、call文またはgoto文の検索による関数分割を行うに際し、分割する直前の命令がテーブルデータ命令であるか否かを判定する。この判定処理は、関数テーブルに基づいて行ってもよいし、関数テーブルにラベルを登録する際に行ってもよい。
FIG. 5B is a flowchart for explaining function division when the instruction immediately before division is a table data instruction.
First, in step S511, when performing function division by searching for a call statement or a goto statement, it is determined whether or not the instruction immediately before the division is a table data instruction. This determination process may be performed based on the function table or may be performed when a label is registered in the function table.

分割する直前の命令がテーブルデータ命令であった場合、ステップS512において、関数終了を表す記号“}”の挿入先を分岐ラベルや分岐先のラベルの直前からテーブルデータ命令の直前に変更して関数分割を行う。それ以外の命令の場合は、ステップS513において、そのまま関数分割を行うことにより論理の整合性を取ることが可能となる。   If the instruction immediately before the division is a table data instruction, in step S512, the insertion destination of the symbol “}” indicating the end of the function is changed from immediately before the branch label or branch destination label to immediately before the table data instruction. Split. In the case of other instructions, in step S513, it is possible to obtain logical consistency by performing function division as it is.

例えば、図7(b)に示すソースコード701に対してcall文の検索による関数分割およびgoto文の検索による関数分割を行うに際し、上述したテーブルデータ命令の配置を変更する処理を施すことにより、テーブルデータTable1を関数内部に含まないソースコード703を得ることができる。すなわち、ソースコード701においてラベルLabel4を関数化する際に、関数終了を表す記号“}”の挿入先をラベルLabel4の直前からテーブルデータ命令を示すラベル“Table1:”の直前に変更することにより、関数内部にテーブルデータ命令を含まないソースコード703を得ることが可能となる。   For example, when performing function division by calling a call statement and function division by searching a goto statement on the source code 701 shown in FIG. 7B, by performing the above-described processing for changing the arrangement of table data instructions, The source code 703 that does not include the table data Table1 in the function can be obtained. That is, when the label Label4 is functionalized in the source code 701, the insertion destination of the symbol “}” indicating the end of the function is changed from immediately before the label Label4 to immediately before the label “Table1:” indicating the table data instruction. It is possible to obtain source code 703 that does not include a table data instruction in the function.

なお、分割する直前に配置されているテーブルデータ命令を検出し、さらにその検出したテーブルデータ命令の直前に配置されているreturn命令もしくはgoto命令を検出することで、上述のgoto命令を省略する処理とテーブルデータの配置を更する処理を合わせて行うようにしてもよい。   Processing for omitting the above-mentioned goto instruction by detecting a table data instruction arranged immediately before the division and detecting a return instruction or a goto instruction arranged immediately before the detected table data instruction. And processing for changing the arrangement of the table data may be performed together.

本発明にかかるソフトウェア変換装置は、アセンブリ言語ソースコードから高級言語の文法に則ったソースコードを生成することができるので、あるマイコンのCPUで実行可能なアセンブリ言語ソースコードを、別のCPUを搭載したマイコンで実行可能な高級言語のソースコードに逆変換するソフトウェア変換装置などに適用できる。   Since the software conversion apparatus according to the present invention can generate a source code conforming to a high-level language grammar from an assembly language source code, an assembly language source code that can be executed by a CPU of a certain microcomputer is mounted on another CPU. It can be applied to a software conversion device that performs reverse conversion into high-level language source code that can be executed by a microcomputer.

本発明の実施の形態におけるソフトウェア変換装置の構成を示す概略図Schematic which shows the structure of the software conversion apparatus in embodiment of this invention 本発明の実施の形態におけるソフトウェア変換装置の動作を説明するためのフローチャート図(その1)(a) call文の検索による関数分割を説明するためのフローチャート図(b) goto文の検索による関数分割を説明するためのフローチャート図Flowchart diagram for explaining the operation of the software conversion apparatus according to the embodiment of the present invention (No. 1) (a) Flowchart diagram for explaining function division by retrieval of call statement (b) Function division by retrieval of goto statement Flow chart for explaining 本発明の実施の形態におけるcall文の検索による関数分割の一実施を示す図The figure which shows one implementation of the function division | segmentation by the search of the call sentence in embodiment of this invention 本発明の実施の形態におけるgoto文の検索による関数分割の一実施を示す図The figure which shows one implementation of the function division | segmentation by the search of a goto sentence in embodiment of this invention 本発明の実施の形態におけるソフトウェア変換装置の動作を説明するためのフローチャート図(その2)(a) 分割する直前の命令がreturn命令もしくはgoto命令の場合の関数分割を説明するためのフローチャート図(b) 分割する直前の命令がテーブルデータ命令の場合の関数分割を説明するためのフローチャート図Flowchart diagram for explaining the operation of the software conversion apparatus according to the embodiment of the present invention (No. 2) (a) Flowchart diagram for explaining function division when the instruction immediately before division is a return instruction or a goto instruction ( b) Flowchart diagram for explaining function division when the instruction immediately before division is a table data instruction 本発明の実施の形態におけるgoto命令を省略する処理を施した場合の関数分割の一実施を示す図The figure which shows one implementation of the function division | segmentation at the time of performing the process which omits the goto instruction in embodiment of this invention 本発明の実施の形態におけるテーブルデータ命令の配置を変更する処理を施した場合の関数分割の一実施を示す図The figure which shows one implementation of the function division | segmentation at the time of performing the process which changes arrangement | positioning of the table data instruction in embodiment of this invention

符号の説明Explanation of symbols

101 アセンブリ言語ソースコード
102 ラベル検出手段
103 逆コンパイラ
104 高級言語ソースコード
105 第1の関数分割手段
106 関数終了命令検出手段
107 不要命令省略手段
108 テーブルデータ命令検出手段
109 テーブルデータ配置変更手段
110 分岐先ラベル検出手段
111 第2の関数分割手段
112 目的とする高級言語ソースコード
101 assembly language source code 102 label detection means 103 decompiler 104 high-level language source code 105 first function division means 106 function end instruction detection means 107 unnecessary instruction omission means 108 table data instruction detection means 109 table data arrangement change means 110 branch destination Label detecting means 111 Second function dividing means 112 Target high-level language source code

Claims (11)

アセンブリ言語ソースコードを高級言語ソースコードに逆変換するソフトウェア変換装置において、
アセンブリ言語ソースコードの中から先頭のラベルと分岐ラベルを検出するラベル検出手段と、
前記ラベル検出手段の検出結果に応じて、検出したラベルに関連する高級言語ソースコード内の命令を関数の形式に変換し、該高級言語ソースコードを分岐ラベルで分割する第1の関数分割手段と
を備えることを特徴とするソフトウェア変換装置。
In a software conversion device that converts assembly language source code back to high-level language source code,
Label detection means for detecting the leading label and branch label from assembly language source code;
First function dividing means for converting an instruction in the high-level language source code related to the detected label into a function format according to the detection result of the label detection means, and dividing the high-level language source code by a branch label; A software conversion device comprising:
請求項1記載のソフトウェア変換装置であって、
前記第1の関数分割手段により関数の形式に変換された高級言語ソースコードの中から、別の関数単位内のラベルへ分岐する分岐命令の分岐先のラベルを検出する分岐先ラベル検出手段と、
前記分岐先ラベル検出手段の検出結果に応じて、検出した前記分岐先のラベルに関連する高級言語ソースコード内の命令を関数の形式に変換し、該高級言語ソースコードを前記分岐先のラベルで分割するとともに、前記別の関数単位内のラベルへ分岐する分岐命令を関数へ分岐するための関数コールに置き換える第2の関数分割手段と
を備えることを特徴とするソフトウェア変換装置。
The software conversion device according to claim 1,
Branch destination label detecting means for detecting a branch destination label of a branch instruction that branches to a label in another function unit from the high-level language source code converted into the function format by the first function dividing means;
In accordance with the detection result of the branch destination label detection means, the instruction in the high-level language source code related to the detected branch destination label is converted into a function format, and the high-level language source code is converted into the branch destination label. A software conversion device comprising: a second function dividing unit that divides and replaces a branch instruction that branches to a label in another function unit with a function call for branching to a function.
前記第1の関数分割手段は、高級言語ソースコードの先頭のラベルを関数化するとともに該高級言語ソースコードの終端に関数終了を表す記号を挿入して該高級言語ソースコードの先頭のラベル以下の命令を関数内の命令とし、前記分岐ラベルを関数化するとともにその直前に関数の分割を表す記号を挿入して該高級言語ソースコードを分割することを特徴とする請求項1もしくは2のいずれかに記載のソフトウェア変換装置。   The first function dividing means converts the leading label of the high-level language source code into a function and inserts a symbol indicating the end of the function at the end of the high-level language source code so as to be equal to or lower than the leading label of the high-level language source code. 3. The high-level language source code according to claim 1, wherein an instruction is an instruction in a function, the branch label is converted into a function, and a symbol representing the division of the function is inserted immediately before the high-level language source code. The software converter described in 1. 前記第2の関数分割手段は、前記分岐先のラベルを関数化するとともにその直前に関数の分割を表す記号を挿入して該高級言語ソースコードを分割することを特徴とする請求項2乃至3のいずれかに記載のソフトウェア変換装置。   4. The high-level language source code according to claim 2, wherein the second function dividing means divides the high-level language source code by converting the label at the branch destination into a function and inserting a symbol representing the division of the function immediately before the function. The software conversion apparatus in any one of. 前記第1の関数分割手段は、前記関数の分割を表す記号に加えて、その直前に関数化された分岐ラベルへ分岐する関数コールを挿入することを特徴とする請求項3もしくは4のいずれかに記載のソフトウェア変換装置。   5. The first function dividing means inserts a function call that branches to a branch label that has been functionalized immediately before it, in addition to a symbol that represents the division of the function. The software converter described in 1. 前記第2の関数分割手段は、前記関数の分割を表す記号に加えて、その直前に関数化された分岐先のラベルへ分岐する関数コールを挿入することを特徴とする請求項4もしくは5のいずれかに記載のソフトウェア変換装置。   6. The function dividing unit according to claim 4, wherein the second function dividing unit inserts a function call that branches to a branch destination label that has been functionalized immediately before the symbol that represents the division of the function. The software conversion apparatus in any one. 請求項6記載のソフトウェア変換装置であって、
前記分岐ラベルや前記分岐先のラベルの直前に配置されている命令が関数終了命令であることを検出する関数終了命令検出手段と、
前記関数終了命令検出手段による関数終了命令の検出に応じて、前記分岐ラベルや前記分岐先のラベルの直前に関数コールが挿入されないようにする不要命令省略手段と
を備えることを特徴とするソフトウェア変換装置。
The software conversion device according to claim 6,
Function end instruction detection means for detecting that an instruction arranged immediately before the branch label or the branch destination label is a function end instruction;
Software conversion comprising: unnecessary instruction omission means for preventing a function call from being inserted immediately before the branch label or the branch destination label in response to detection of a function end instruction by the function end instruction detection means apparatus.
請求項3乃至7のいずれかに記載のソフトウェア変換装置であって、
前記分岐ラベルや前記分岐先のラベルの直前に配置されている命令がテーブルデータ命令であることを検出するテーブルデータ命令検出手段と、
前記テーブルデータ命令検出手段によるテーブルデータ命令の検出に応じて、前記関数の分割を表す記号の挿入先を前記分岐ラベルや前記分岐先のラベルの直前に代えてテーブルデータ命令の直前にし、テーブルデータ命令が関数単位外に配置されるようにするテーブルデータ配置変更手段と
を備えることを特徴とするソフトウェア変換装置。
A software conversion device according to any one of claims 3 to 7,
Table data instruction detection means for detecting that an instruction arranged immediately before the branch label or the branch destination label is a table data instruction;
In response to detection of the table data instruction by the table data instruction detection means, the insertion destination of the symbol representing the division of the function is changed to immediately before the table data instruction instead of immediately before the branch label or the branch destination label, and the table data A software conversion apparatus comprising: table data arrangement changing means for arranging an instruction outside a function unit.
前記分岐ラベルがcall文の引数であることを特徴とする請求項1乃至8のいずれかに記載のソフトウェア変換装置。   9. The software conversion apparatus according to claim 1, wherein the branch label is an argument of a call statement. 前記別の関数単位内のラベルへ分岐する分岐命令がgoto文であることを特徴とする請求項2乃至9のいずれかに記載のソフトウェア変換装置。   10. The software conversion apparatus according to claim 2, wherein the branch instruction for branching to a label in another function unit is a goto statement. 前記関数終了命令がreturn命令またはgoto命令であることを特徴とする請求項7乃至10のいずれかに記載のソフトウェア変換装置。
11. The software conversion apparatus according to claim 7, wherein the function end instruction is a return instruction or a goto instruction.
JP2003317600A 2003-09-10 2003-09-10 Software converter Pending JP2005085051A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
JP2003317600A JP2005085051A (en) 2003-09-10 2003-09-10 Software converter

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
JP2003317600A JP2005085051A (en) 2003-09-10 2003-09-10 Software converter

Publications (1)

Publication Number Publication Date
JP2005085051A true JP2005085051A (en) 2005-03-31

Family

ID=34417100

Family Applications (1)

Application Number Title Priority Date Filing Date
JP2003317600A Pending JP2005085051A (en) 2003-09-10 2003-09-10 Software converter

Country Status (1)

Country Link
JP (1) JP2005085051A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2018161283A1 (en) * 2017-03-08 2018-09-13 华为技术有限公司 Packet processing method and apparatus

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2018161283A1 (en) * 2017-03-08 2018-09-13 华为技术有限公司 Packet processing method and apparatus
CN110352400A (en) * 2017-03-08 2019-10-18 华为技术有限公司 Method and apparatus for handling message

Similar Documents

Publication Publication Date Title
Grönniger et al. Monticore: a framework for the development of textual domain specific languages
JP5967618B2 (en) Method for optimizing binary code of a language having access to binary-coded decimal variables, and computer and computer program thereof
CN108139891A (en) Include suggesting for the missing of external file
JP2006243838A (en) Program development device
Zhu et al. BiYacc: Roll your parser and reflective printer into one
JP2008276735A (en) Program code converter and program code conversion method
JP4888790B2 (en) Contract definition function verification apparatus, method and program thereof
Diatchki et al. High-level views on low-level representations
JP2005085051A (en) Software converter
CN115809442A (en) Method, device and equipment for obfuscating reverse code and readable storage medium
JP5109646B2 (en) Program source conversion device
CN114691151A (en) Optimized code decompiling method and system based on deep learning
JP6264179B2 (en) Compiling method, compiling device, and compiling program
KR20090011974A (en) Method for extracting the target files of compilation
CN114816435A (en) Software development method based on reverse technology
JP2018173699A (en) Template generation device, template generation method and program
MacLennan The Synmac syntax macroprocessor: Introduction and manual, version 5
JP5238560B2 (en) Translation apparatus, method, and program
JP2009258796A (en) Program development device and program development method
Kats et al. Interactive disambiguation of meta programs with concrete object syntax
US9792197B2 (en) Apparatus and program
JP7083473B2 (en) Input support device
KR101670726B1 (en) Method for code conversion using debugging information of intermediate language code, apparatus and computer-readable recording medium with program therefor
Okuda et al. Lake symbols for island parsing
CN114327469A (en) Code analysis method, device, equipment and medium