Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /home/zhenxiangba/zhenxiangba.com/public_html/phproxy-improved-master/index.php on line 456
JP3327640B2 - Instruction code selection device - Google Patents
[go: Go Back, main page]

JP3327640B2 - Instruction code selection device - Google Patents

Instruction code selection device

Info

Publication number
JP3327640B2
JP3327640B2 JP22699093A JP22699093A JP3327640B2 JP 3327640 B2 JP3327640 B2 JP 3327640B2 JP 22699093 A JP22699093 A JP 22699093A JP 22699093 A JP22699093 A JP 22699093A JP 3327640 B2 JP3327640 B2 JP 3327640B2
Authority
JP
Japan
Prior art keywords
instruction
pattern
expression tree
instruction code
expression
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Expired - Fee Related
Application number
JP22699093A
Other languages
Japanese (ja)
Other versions
JPH0784796A (en
Inventor
博司 湯川
宣輝 富永
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Panasonic Corp
Panasonic Holdings Corp
Original Assignee
Panasonic Corp
Matsushita Electric Industrial Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Panasonic Corp, Matsushita Electric Industrial Co Ltd filed Critical Panasonic Corp
Priority to JP22699093A priority Critical patent/JP3327640B2/en
Publication of JPH0784796A publication Critical patent/JPH0784796A/en
Application granted granted Critical
Publication of JP3327640B2 publication Critical patent/JP3327640B2/en
Anticipated expiration legal-status Critical
Expired - Fee Related legal-status Critical Current

Links

Landscapes

  • Devices For Executing Special Programs (AREA)

Description

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

【0001】[0001]

【産業上の利用分野】本発明は、高級プログラミング言
語を特定のターゲットマシン向けの機械言語に翻訳する
コンパイラに用いられる命令コード選択装置に関するも
のである。
BACKGROUND OF THE INVENTION 1. Field of the Invention The present invention relates to an instruction code selecting device used in a compiler for translating a high-level programming language into a machine language for a specific target machine.

【0002】[0002]

【従来の技術】コンパイラは、プログラミング言語で書
かれたソースプログラムを入力して機械語あるいはアセ
ンブリ言語で書かれた目的プログラムを作成する装置で
ある。図2は、コンパイラの一般的な構成を概念的に示
したブロック図である。コンパイラ1は、構文解析装置
2と、最適化装置3と、コード生成装置4とを備えてい
る。構文解析装置2は、ソースプログラムを読み込み、
語彙解析を行って単語単位に認識した後、プログラミン
グ言語の文法、規則との整合性をチェックし、中間言語
に変換する。最適化装置3は、目的プログラムのメモリ
効率や実行効率を向上させるために、構文解析装置2で
生成された中間言語の編集を行い最適化する。コード生
成装置4は、最適化された中間言語からターゲットであ
るマシンの命令コードを生成することによって機械語等
の目的プログラムを作成する。このコード生成装置4に
おいては、命令コードを生成するために命令コード選択
装置10が設けられている。
2. Description of the Related Art A compiler is a device that inputs a source program written in a programming language and creates a target program written in a machine language or an assembly language. FIG. 2 is a block diagram conceptually showing a general configuration of the compiler. The compiler 1 includes a syntax analysis device 2, an optimization device 3, and a code generation device 4. The syntax analyzer 2 reads the source program,
After performing vocabulary analysis and recognizing each word, it is checked for consistency with the grammar and rules of the programming language and converted to an intermediate language. The optimization device 3 edits and optimizes the intermediate language generated by the syntax analysis device 2 in order to improve the memory efficiency and execution efficiency of the target program. The code generation device 4 generates a target program such as a machine language by generating an instruction code of a target machine from the optimized intermediate language. In the code generation device 4, an instruction code selection device 10 is provided to generate an instruction code.

【0003】ここで、従来の命令コード選択装置10に
よる命令コードの生成動作について説明する。先ず、命
令コードの生成に先立って、構文解析装置2における構
文解析の結果、ソースプログラムの命令を木構造で示し
た式木のパタンが得られる。図3は、C言語で表記され
たソースプログラムと、構文解析装置2の処理によって
得られたプログラムの各行の実行命令に対応する式木の
パタンの一例を示している。
Here, the operation of generating an instruction code by the conventional instruction code selection device 10 will be described. First, prior to the generation of the instruction code, as a result of the syntax analysis in the syntax analysis device 2, a pattern of an expression tree showing the instructions of the source program in a tree structure is obtained. FIG. 3 shows an example of a source program written in C language and a pattern of an expression tree corresponding to an execution instruction of each line of the program obtained by the processing of the syntax analysis device 2.

【0004】そして、命令コード選択装置10は、この
式木のパタンを受け取り、これを検索キーとしてテンプ
レートを検索する。テンプレートは、式木のパタンと、
これに対応する命令生成規則が予めコンパイラ作成者に
よって記述されている。図9は、従来のテンプレートの
一例を概念的に示したもので、(1)の欄は、ある関数
を呼び出す命令に対応する手続き呼び出し命令の式木パ
タンと、これに対応する命令生成規則51が格納されて
おり、(2)および(3)の欄は、2つの浮動小数点型
変数の加算命令と減算命令に対応する演算実行命令の式
木パタンと、これらに対応する命令生成規則52、5
3、54、55が格納されている。また、演算実行命令
の式木パタン(2)、(3)に対しては、各々2種類の
命令生成規則が記述されている。これは、ターゲットマ
シンには、浮動小数点型の演算を行なう場合に、浮動小
数点型の演算を実行する命令を生成する方法と、浮動小
数点型の演算を実行する手続き呼び出し命令を生成する
方法の二つの方法で命令コードを生成することが可能な
ものが存在することを考慮したためである。
[0004] The instruction code selecting device 10 receives the pattern of the expression tree, and searches for a template using the pattern as a search key. The template is a pattern of Shiki tree,
The instruction generation rule corresponding to this is described in advance by the compiler creator. FIG. 9 conceptually shows an example of a conventional template. A column (1) shows an expression tree pattern of a procedure call instruction corresponding to an instruction for calling a certain function, and an instruction generation rule 51 corresponding to this. Are stored in the columns of (2) and (3), the expression tree pattern of the operation execution instruction corresponding to the addition instruction and the subtraction instruction of the two floating point type variables, and the instruction generation rule 52 corresponding to these. 5
3, 54 and 55 are stored. Two types of instruction generation rules are described for the expression tree patterns (2) and (3) of the operation execution instructions. This is because the target machine, when performing a floating-point operation, generates an instruction for executing the floating-point operation and a method for generating a procedure call instruction for executing the floating-point operation. This is because the fact that an instruction code can be generated by one of the two methods is considered.

【0005】そして、コンパイル時に、オペレータが浮
動小数点の演算を行う場合に、演算実行命令かあるいは
手続き呼び出し命令のいずれを使用するかを指定するこ
とにより、式木のパタンに対応する命令生成規則が一つ
だけ選択され、命令コードが生成される。例えば、図3
に示す加算命令の式木パタンに対して、オペレータの指
定が演算実行命令の生成である場合には、図9中の命令
生成規則52が選択され、命令コードが生成される。
[0005] At the time of compilation, when the operator performs a floating-point operation, by specifying whether to use an operation execution instruction or a procedure call instruction, the instruction generation rule corresponding to the pattern of the expression tree is specified. Only one is selected and an instruction code is generated. For example, FIG.
For the expression tree pattern of the addition instruction shown in (1), if the operator specifies generation of an operation execution instruction, the instruction generation rule 52 in FIG. 9 is selected, and an instruction code is generated.

【0006】[0006]

【発明が解決しようとする課題】しかしながら、図9に
示すように、従来の命令コード選択装置では、ターゲッ
トマシンの命令生成方法の種別を考慮して、一つの式木
のパタンに対して複数の命令生成規則を予めテンプレー
トに記述しておかなければならない。しかも、手続き呼
び出し命令を生成する命令生成規則は、関数呼び出しを
表す式木のパタンに対応する命令生成規則として既にテ
ンプレートに記述されているものがある。例えば、図9
において、式木パタン(2)に対しは、浮動小数点型の
演算実行命令の命令生成規則52と手続き呼び出し命令
の命令生成規則53の2種類の命令生成規則が記述され
ている。この内、命令生成規則53については、テンプ
レート50中に関数呼び出しを示す式木パタン(1)に
対応する命令生成規則51に同じものが記述されてい
る。従って、式木パタン(2)で示される浮動小数点の
演算を行わせる場合には、関数呼び出しのパタン(1)
に記述された命令生成規則51を選択しても所望の演算
を実行することが可能である。しかしながら、命令生成
規則51は、関数呼び出しの式木パタン(1)によって
のみ検索されるため、式木パタン(2)に対しては、命
令生成規則52に加えてさらに命令生成規則53を記述
しておく必要がある。
However, as shown in FIG. 9, in the conventional instruction code selection apparatus, a plurality of patterns are set for one expression tree in consideration of the type of the instruction generation method of the target machine. Instruction generation rules must be described in a template in advance. Moreover, some instruction generation rules for generating a procedure call instruction are already described in a template as instruction generation rules corresponding to the pattern of an expression tree representing a function call. For example, FIG.
In the expression tree pattern (2), two types of instruction generation rules, that is, an instruction generation rule 52 of a floating-point type operation execution instruction and an instruction generation rule 53 of a procedure call instruction are described. Among them, the same instruction generation rule 53 is described in the template 50 in the instruction generation rule 51 corresponding to the expression tree pattern (1) indicating a function call. Therefore, when performing the floating-point operation represented by the expression tree pattern (2), the function call pattern (1)
It is possible to execute a desired operation even if the instruction generation rule 51 described in (1) is selected. However, since the instruction generation rule 51 is searched only by the expression tree pattern (1) of the function call, an instruction generation rule 53 is further described for the expression tree pattern (2) in addition to the instruction generation rule 52. Need to be kept.

【0007】このように、従来の命令コード生成装置
は、式木のパタン毎に、ターゲットマシンの命令生成方
法に対応した複数の浮動小数点型の演算を実行するため
の命令生成規則を記述しなければならないので、コンパ
イラ作成者がテンプレートを作成する手間が増大し、ま
た、テンプレートの格納領域も増大する。さらに、ある
ターゲットマシン用のコンパイラを別のターゲットマシ
ン用のコンパイラに書き換える場合には、いずれの命令
生成規則をも書き換えなければならないため、多大な工
数を要すると共に、コンパイラの保守性、再利用性を低
下させるという問題点があった。
As described above, the conventional instruction code generation device must describe, for each pattern of the expression tree, an instruction generation rule for executing a plurality of floating-point operations corresponding to the instruction generation method of the target machine. Therefore, the effort of the compiler creator to create a template increases, and the storage area of the template also increases. Furthermore, when a compiler for one target machine is rewritten to a compiler for another target machine, all instruction generation rules must be rewritten, which requires a great deal of man-hours, and also requires maintainability and reusability of the compiler. There was a problem that it reduced.

【0008】本発明は、かかる問題点に鑑み、同一内容
に対する冗長な命令生成規則の記述を省略することがで
きるテンプレートを備えた命令コード選択装置を提供す
ることを目的とする。
The present invention has been made in view of the above problems, and has as its object to provide an instruction code selecting apparatus provided with a template which can omit redundant instruction generation rules for the same contents.

【0009】[0009]

【課題を解決するための手段】請求項1の発明に係る命
令コード選択装置は、入力された式木のパタンに対応す
る命令コードを選択する命令コード選択装置であって、
入力された前記式木の中から特定のパタンを持つ式木を
選択する式木パタン選択手段と、前記式木パタン選択手
段により選択された前記式木のパタンを所定の式木のパ
タンに変換する式木パタン変換手段と、種々の式木のパ
タンと、これに対応する命令生成規則を格納する格納手
段と、前記式木パタン変換手段によって変換された式木
パタンを用いて前記格納手段から命令生成規則を選択
て命令コードを生成する命令コード選択手段とを備え
前記格納手段は、前記所定のパタンに対応する命令生成
規則として、前記特定のパタンに対応する命令生成規則
を共通化した命令生成規則を格納するここで、前記特定
のパタンを持つ式木のそれぞれは演算を表し、前記所定
の式木のパタンは、演算を実行する手続きを呼び出す命
令に対応するように構成してもよい。
According to a first aspect of the present invention, there is provided an instruction code selecting apparatus for selecting an instruction code corresponding to a pattern of an input expression tree.
Expression tree pattern selecting means for selecting an expression tree having a specific pattern from the input expression tree, and converting the expression tree pattern selected by the expression tree pattern selection means into a predetermined expression tree pattern and wherein wood pattern converting means for, the pattern of the various formula trees, and store unit that stores instruction generating rules corresponding thereto, before using the formula tree pattern converted by the equation tree pattern converting means Symbol select instruction generating rules from store means
Instruction code selecting means for generating an instruction code by
The storage unit generates an instruction corresponding to the predetermined pattern.
As a rule, an instruction generation rule corresponding to the specific pattern
Where the instruction generation rule that stores
Each of the expression trees having the pattern of
The pattern of the expression tree is a command that calls the procedure that performs the operation.
You may comprise so that it may respond to an order.

【0010】請求項の発明に係る命令コード選択装置
において、前記特定のパタンを持つ式木のそれぞれは演
算を表し、前記格納手段は、特定のパタンと、これに対
応する演算実行命令を生成するための命令生成規則と、
所定の式木のパタンと、これに対応する演算を実行する
手続きを呼び出す命令を生成する1つの命令生成規則と
を格納し、さらに、オペレータが演算実行命令の生成を
所望する場合に、入力された式木を式木パタン選択手段
に出力し、所望しない場合に、入力された式木を命令コ
ード選択手段に出力する変換制御手段を備えている。
An instruction code selecting apparatus according to a third aspect of the present invention.
, Each of the expression trees having the specific pattern
The storage means stores a specific pattern and a corresponding
An instruction generation rule for generating a corresponding operation execution instruction;
Performs a given expression tree pattern and the corresponding operation
One instruction generation rule for generating an instruction that calls a procedure;
Storing the further instruction if the operator <br/> desired generation of execution instruction, and outputs the input expression tree Shikiki pattern selection means, if not desired, the input expression tree Conversion control means for outputting to the code selection means is provided.

【0011】[0011]

【作用】請求項1の発明において、本命令コード選択装
置には、式木のパタンが入力される。式木パタン選択手
段は、入力された式木の中から特定のパタンを持つ式木
を選択する。本発明の実施例では、例えば浮動小数点型
の演算実行命令のパタンを選択する。式木パタンは、式
木パタン選択手段により選択された式木のパタンを所定
の式木のパタンに変換する。格納手段は、種々の式木の
パタンと、これに対応する命令生成規則、特に、前記所
定のパタンに対応する命令生成規則として、前記特定の
パタンに対応する命令生成規則を共通化した命令生成規
則を格納する。そして、命令コード選択手段は、式木パ
タン変換手段によって変換された式木パタンを用いて命
令コード格納手段から式木パタンに該当する命令生成規
を選択して命令コードを生成する。
According to the first aspect of the present invention, a pattern of an expression tree is input to the instruction code selecting device. The expression tree pattern selecting means selects an expression tree having a specific pattern from the input expression trees. In the embodiment of the present invention, for example, a pattern of a floating-point type operation execution instruction is selected. The expression tree pattern converts the expression tree pattern selected by the expression tree pattern selection means into a predetermined expression tree pattern. The storage means is various expression trees
Patterns and the corresponding instruction generation rules, especially
As the instruction generation rule corresponding to a certain pattern,
Instruction generation rules that share the same instruction generation rules for patterns
Stores rules. Then, the instruction code selection means uses the expression tree pattern converted by the expression tree pattern conversion means to store the instruction generation rule corresponding to the expression tree pattern from the instruction code storage means.
Select a rule to generate an instruction code .

【0012】また、請求項2の発明において、変換制御
手段は、オペレータが浮動小数点型の演算を実行する手
続き呼び出し命令の生成を所望する場合に、入力された
式木を式木パタン選択手段に出力し、浮動小数点型の演
算を実行する命令の生成を所望する場合に、入力された
式木を命令コード選択手段に出力する。
Further, in the invention according to claim 2, the conversion control means, when the operator desires to generate a procedure call instruction for executing a floating point type operation, converts the input expression tree to the expression tree pattern selection means. When it is desired to generate an instruction for executing a floating-point type operation, the input expression tree is output to the instruction code selecting means.

【0013】[0013]

【実施例】以下、本発明の実施例について図を用いて説
明する。図1は、本発明の実施例における命令コード選
択装置の構成を示すブロック図である。この命令コード
選択装置10は、従来の装置と同様に、図2に示される
コンパイラ1のコード生成装置4に含まれるものであ
る。
DESCRIPTION OF THE PREFERRED EMBODIMENTS Embodiments of the present invention will be described below with reference to the drawings. FIG. 1 is a block diagram illustrating a configuration of an instruction code selection device according to an embodiment of the present invention. This instruction code selection device 10 is included in the code generation device 4 of the compiler 1 shown in FIG.

【0014】図1を参照して、本実施例による命令コー
ド選択装置10は、変換制御部11と、式木パタン選択
部12と、式木パタン変換部13と、命令コード選択部
14と、テンプレート15とを備える。変換制御部11
は、高級プログラム言語で記述されたソースプログラム
の式木パタンとオペレータが指定した選択情報とを受け
取り、選択情報の種別に従って式木パタン選択部12と
命令コード選択部14のいずれかを選択して受け取った
式木パタンを出力する。
Referring to FIG. 1, an instruction code selection device 10 according to the present embodiment includes a conversion control unit 11, an expression tree pattern selection unit 12, an expression tree pattern conversion unit 13, an instruction code selection unit 14, And a template 15. Conversion control unit 11
Receives an expression tree pattern of a source program described in a high-level programming language and selection information specified by an operator, and selects one of the expression tree pattern selection unit 12 and the instruction code selection unit 14 according to the type of the selection information. Outputs the received expression tree pattern.

【0015】式木パタン選択部12は、特定のパタン、
例えば演算実行命令のパタンを持つ式木を選択する。式
木パタン変換部13は、式木パタン選択部12で選択さ
れた式木のパタンに所定の操作を施して式木のパタンを
変換する。命令コード選択部14は、変換制御部11、
式木パタン選択部12、式木パタン変換部13の各々か
ら与えられた式木のパタンに対応する命令コードをテン
プレート15中から選択する。
The formula tree pattern selection unit 12 is configured to select a specific pattern,
For example, an expression tree having a pattern of an operation execution instruction is selected. The expression tree pattern conversion unit 13 performs a predetermined operation on the expression tree pattern selected by the expression tree pattern selection unit 12 to convert the expression tree pattern. The instruction code selector 14 includes a conversion controller 11,
An instruction code corresponding to the pattern of the expression tree given from each of the expression tree pattern selection unit 12 and the expression tree pattern conversion unit 13 is selected from the template 15.

【0016】テンプレート15は、式木のパタンと、こ
れに対応する命令生成規則との組合せデータを格納す
る。図4は、テンプレートの内容の一例を示している。
本実施例では、テンプレートは、一つの式木のパタンに
対して一つの命令生成規則が記述されている。次に、上
記のように構成された本実施例の命令コード選択装置の
動作を以下に説明する。図5は、命令コード選択装置の
動作を説明したフローチャートであり、図6は、図5に
示す式木パタン変換ステップの動作を示すフローチャー
トである。ここでは、コンパイラを使用するターゲット
マシンとして、浮動小数点型の演算を実行させるため
に、浮動小数点型の演算を実行する命令を生成する方法
と、浮動小数点型の演算を実行する手続き呼び出し命令
を生成する方法の、二種類の方法が適用されるマシンを
対象とする。
The template 15 stores combination data of an expression tree pattern and an instruction generation rule corresponding to the pattern. FIG. 4 shows an example of the contents of the template.
In this embodiment, the template describes one instruction generation rule for one expression tree pattern. Next, the operation of the instruction code selection device of the present embodiment configured as described above will be described below. FIG. 5 is a flowchart illustrating the operation of the instruction code selection device, and FIG. 6 is a flowchart illustrating the operation of the expression tree pattern conversion step shown in FIG. Here, as a target machine using a compiler, a method for generating an instruction for executing a floating-point type operation and a procedure call instruction for executing a floating-point type operation are generated in order to execute a floating-point type operation. Target machines to which the two methods are applied.

【0017】まず、オペレータは、コンパイラ起動時
に、この二種類の方法のうちのいずれを選択するかの選
択情報を入力しておく。そして、コンパイラを起動し、
構文解析装置2及び最適化装置3を通して式木のパタン
が生成される。命令コード選択装置10は、変換制御部
11を起動し、式木のパタンと先に入力された演算実行
命令の選択情報とを受け取る。そして、変換制御部11
は、コンパイラ起動時の指定により式木を式木パタン選
択部12に渡すか、命令コード選択部14に渡すかを決
定する(ステップS100、S102)。
First, the operator inputs selection information for selecting one of these two methods when starting up the compiler. Then invoke the compiler,
A pattern of the expression tree is generated through the syntax analysis device 2 and the optimization device 3. The instruction code selection device 10 activates the conversion control unit 11 and receives the pattern of the expression tree and the selection information of the previously executed operation execution instruction. Then, the conversion control unit 11
Determines whether to pass the expression tree to the expression tree pattern selection unit 12 or the instruction code selection unit 14 according to the specification at the time of starting the compiler (steps S100 and S102).

【0018】選択情報の内容が浮動小数点型の演算を実
行する命令を生成するものである場合には、式木パタン
を命令コード選択部14に出力し(ステップS11
6)、浮動小数点型の演算を実行する手続き命令を生成
するものである場合には、命令コード選択装置10は、
式木パタン選択部12を起動し、式木パタンを式木パタ
ン選択部12に出力する(ステップS104)。
If the content of the selection information is to generate an instruction for executing a floating-point type operation, an expression tree pattern is output to the instruction code selector 14 (step S11).
6) In the case of generating a procedure instruction for executing a floating-point type operation, the instruction code selection device 10
The formula tree pattern selection unit 12 is activated, and outputs the formula tree pattern to the formula tree pattern selection unit 12 (step S104).

【0019】式木パタン選択部12は、変換制御部11
より渡された式木のパタンを解析する(ステップS10
6)。そして、式木が浮動小数点の演算を表すパタンを
持っている場合は、式木のパタンを式木パタン変換部1
3に渡す(ステップS108)。そうでない場合は、式
木を命令コード選択部14に渡す(ステップS108、
S112)。
The expression tree pattern selection unit 12 includes a conversion control unit 11
The pattern of the expression tree passed is analyzed (step S10).
6). If the expression tree has a pattern representing a floating-point operation, the pattern of the expression tree is converted to the expression tree pattern conversion unit 1.
3 (step S108). Otherwise, the expression tree is passed to the instruction code selector 14 (step S108,
S112).

【0020】引き続いて、命令コード選択装置10は、
式木パタン変換部13を起動する。そして、式木パタン
変換部13は、式木パタン選択部12が選択した浮動小
数点の演算を表すパタンを持っている式木のパタンを、
浮動小数点型の演算を実行する手続き呼び出し命令に対
応するパタンに変換する(ステップS110)。この式
木パタン変換動作については後述する。
Subsequently, the instruction code selecting device 10
The expression tree pattern conversion unit 13 is started. Then, the expression tree pattern conversion unit 13 converts the expression tree pattern having the pattern representing the floating-point operation selected by the expression tree pattern selection unit 12 into:
The pattern is converted into a pattern corresponding to a procedure call instruction for executing a floating-point type operation (step S110). This expression tree pattern conversion operation will be described later.

【0021】さらに、命令コード選択装置10は、命令
コード選択部14を起動する。命令コード選択部14
は、変換制御部11または式木パタン選択部12または
式木パタン変換部13から渡された式木のパタンを用い
てテンプレート15を検索し、式木のパタンに対応する
命令生成規則を選択して抽出する(ステップS11
4)。
Further, the instruction code selection device 10 activates the instruction code selection section 14. Instruction code selector 14
Searches the template 15 using the expression tree pattern passed from the conversion control unit 11, the expression tree pattern selection unit 12, or the expression tree pattern conversion unit 13, selects an instruction generation rule corresponding to the expression tree pattern. (Step S11)
4).

【0022】ここで、上記したステップS110におけ
る式木パタンの変換動作について図6を参照して説明す
る。式木パタン変換部13に式木パタンが入力されると
(ステップS200)、式木パタンに含まれる演算子と
データの型とを検索キーとして、例えば図7に示すよう
な変換表20を検索する(ステップS210)。
Here, the conversion operation of the expression tree pattern in step S110 will be described with reference to FIG. When an expression tree pattern is input to the expression tree pattern conversion unit 13 (step S200), a conversion table 20 as shown in FIG. 7, for example, is searched using the operators and data types included in the expression tree pattern as search keys. (Step S210).

【0023】そして、変換表20中に検索キーに該当す
るものが存在しなければ(ステップS220、S23
0)、変換対象外の式木であると判断し、ステップS2
90の処理に移行し、与えられた式木のパタンを命令コ
ード選択部14に出力する。また、変換表20中に該当
する演算子及び型が存在すれば(ステップS220、S
230)、変換表20中から対応する手続き名を抽出す
る(ステップS240)。
If there is no search key in the conversion table 20 (steps S220, S23)
0), it is determined that the expression tree is not a conversion target, and step S2
The process shifts to step 90 to output the pattern of the given expression tree to the instruction code selector 14. If the corresponding operator and type exist in the conversion table 20 (steps S220 and S220).
230), and extracts the corresponding procedure name from the conversion table 20 (step S240).

【0024】そして、引き続いて手続き呼び出しのノー
ドを作成し(ステップS250)、抽出した手続き名の
ノードを作成し(ステップS260)、元の式木の引数
を設定し(ステップS270)、手続き呼び出し命令の
式木パタンが生成される。その後、上記の動作によって
生成された手続き呼び出しの式木パタンを命令コード選
択部14に出力する(ステップS280)。
Then, a procedure call node is created (step S250), a node of the extracted procedure name is created (step S260), and the original expression tree argument is set (step S270). Is generated. After that, the procedure tree pattern of the procedure call generated by the above operation is output to the instruction code selection unit 14 (step S280).

【0025】次に、具体的な例を用いて本実施例の命令
コード選択装置10の動作について説明する。具体例と
しては、従来の技術の章で説明したものと同様に、図3
に示すソースプログラムに対して図4に示すテンプレー
ト15を用いて命令コードを生成する例を参照する。こ
こで、図3は、C言語で記述されたソースプログラムの
一例を示す図であり、図示されたプログラムにおいて、
実行文の最初の行は、実数(浮動小数点)型の変数a、
b、cを定義し、(1)行は、b、cを引数とする何等
かの関数(func)を定義し、(2)行は、bとcの
加算命令を示し、(3)行は、bからcを引く減算命令
を示している。
Next, the operation of the instruction code selection device 10 of the present embodiment will be described using a specific example. As a specific example, as described in the section of the prior art, FIG.
An example in which an instruction code is generated using the template 15 shown in FIG. 4 for the source program shown in FIG. Here, FIG. 3 is a diagram showing an example of a source program described in the C language.
The first line of the executable statement is a real (floating point) type variable a,
b and c are defined, line (1) defines some function (func) with b and c as arguments, line (2) indicates an instruction to add b and c, and line (3) Indicates a subtraction instruction for subtracting c from b.

【0026】先ず、オペレータは、浮動小数点型の演算
実行命令の式木パタンを浮動小数点型の演算を実行する
手続き呼び出し命令の式木パタンに変換する選択指定を
入力し、コンパイラを起動する。そして、図3の左側に
示すソースプログラムは、各行毎に図面右側に示す式木
のパタンが生成され、変換制御部11に入力される。例
えば、(2)行の命令に対し、生成された演算実行命令
の式木パタン30が生成され、変換制御部11に入力さ
れる。
First, the operator inputs a selection specification for converting an expression tree pattern of a floating-point type operation execution instruction into an expression tree pattern of a procedure call instruction for executing a floating-point type operation, and activates the compiler. Then, in the source program shown on the left side of FIG. 3, a pattern of the expression tree shown on the right side of the drawing is generated for each line, and is input to the conversion control unit 11. For example, the expression tree pattern 30 of the generated operation execution instruction is generated for the instruction in the row (2), and is input to the conversion control unit 11.

【0027】変換制御部11は、オペレータの選択指定
にしたがって、式木を変換するか否かを判断する。本例
の場合、オペレータの指定によりパタンの変換が指定さ
れているので、式木パタン30は式木パタン選択部12
に出力される。そして、式木パタン選択部12は、式木
パタン30に実数型変数の加算命令が定義されているこ
とを解析し、この式木パタンを式木パタン変換部13に
出力する。
The conversion control unit 11 determines whether or not to convert the expression tree according to the operator's selection designation. In the case of this example, since the pattern conversion is specified by the operator, the expression tree pattern 30 is
Is output to Then, the expression tree pattern selection unit 12 analyzes that the addition instruction of the real type variable is defined in the expression tree pattern 30, and outputs the expression tree pattern to the expression tree pattern conversion unit 13.

【0028】式木パタン変換部13は、演算実行命令の
式木パタン30を手続き呼び出し命令の式木パタンに変
換する。この変換処理を以下に説明する。まず、式木パ
タン30から演算子「+」と型「実数(float)」
を検索キーとして取り出し、図7に示す変換表20を検
索する。検索の結果、変換表20の先頭のデータが検索
キーに該当する。従って、変換表20から先頭の手続き
名(_fadd)を抽出する。そして、図8を参照し
て、まず、手続き呼び出しのノード40aを作成する。
次に、抽出した手続き名のノード40bを手続き呼び出
しのノード40aの左側に接続する。さらに、式木パタ
ン30の左辺の変数を取り出し、手続き呼び出しのノー
ド40aの第1の引数40cとし、また、演算の式木3
0の右辺の変数を取り出し、手続き呼び出しのノード4
0aの第2の引数40dとする。これによって手続き呼
び出し命令の式木パタン40が生成される。
The expression tree pattern conversion unit 13 converts the expression tree pattern 30 of the execution instruction into the expression tree pattern of the procedure call instruction. This conversion processing will be described below. First, the operator "+" and the type "real number (float)" are obtained from the expression tree pattern 30.
Is retrieved as a search key, and the conversion table 20 shown in FIG. 7 is searched. As a result of the search, the first data in the conversion table 20 corresponds to the search key. Therefore, the first procedure name (_fadd) is extracted from the conversion table 20. Then, referring to FIG. 8, first, a procedure call node 40a is created.
Next, the node 40b of the extracted procedure name is connected to the left side of the node 40a of the procedure call. Further, a variable on the left side of the expression tree pattern 30 is extracted and used as the first argument 40c of the procedure call node 40a.
Take out the variable on the right side of 0, and call node 4 of the procedure call
The second argument 40d is 0a. As a result, the expression tree pattern 40 of the procedure call instruction is generated.

【0029】変換された式木パタン40は、命令コード
選択部14に出力される。命令コード選択部14は、変
換後の式木パタン40を検索キーとして図4に示すテン
プレート15を検索する。検索の結果、(1)の式木パ
タンが検索キーと一致し、この検索により、命令生成規
則15aが抽出される。以上、本発明を実施例に基づき
説明したが、本発明は上記実施例に限定されるものでは
なく、以下に示すような種々の変形が可能である。 (1)上記実施例では、浮動小数点型の演算に対して二
種類の命令コードが選択され得るターゲットマシンを仮
定したが、もともと浮動小数点型の演算命令を持たない
ターゲットマシンの場合には、変換制御部11を設ける
ことなく、常に式木のパタンを変換可能な構成とするこ
とができる。 (2)上記の具体例では、演算実行命令の式木パタンを
手続き呼び出し命令の式木パタンに変換する例について
説明したが、逆に手続き呼び出し命令の式木パタンを演
算実行命令の式木パタンに変更することも可能である。 (3)また、上記実施例では、浮動小数点型の演算を表
すパタンを持つ式木を式木パタン選択部12が選択して
いるが、ターゲットマシンが倍長整数型の演算命令を持
たない場合には、倍長整数型の演算を表すパタンを持つ
式木も式木パタン選択部12が選択するように構成する
ことができる。 (4)さらに、上記実施例では、式木パタン変換部13
が、所望の演算を実行する手続き呼び出し命令に対応す
るパタンに変換するように構成したが、構造体の代入の
ように一回の代入命令で代入操作が完了しない演算を表
すパタンの場合は、式木パタン変換部が、構造体の大き
さに応じた複数回の代入命令を表すパタンに変換するよ
うに構成することができる。
The converted expression tree pattern 40 is output to the instruction code selector 14. The instruction code selection unit 14 searches the template 15 shown in FIG. 4 using the converted expression tree pattern 40 as a search key. As a result of the search, the expression tree pattern of (1) matches the search key, and the instruction generation rule 15a is extracted by this search. As described above, the present invention has been described based on the embodiments. However, the present invention is not limited to the above embodiments, and various modifications as described below are possible. (1) In the above embodiment, a target machine in which two types of instruction codes can be selected for a floating-point type operation is assumed. Without providing the control unit 11, it is possible to adopt a configuration that can always convert the pattern of the expression tree. (2) In the above specific example, an example has been described in which the expression tree pattern of the operation execution instruction is converted into the expression tree pattern of the procedure call instruction. Conversely, the expression tree pattern of the procedure call instruction is converted to the expression tree pattern of the operation execution instruction. It is also possible to change to (3) In the above embodiment, the expression tree pattern selection unit 12 selects an expression tree having a pattern representing a floating-point operation, but the target machine does not have a double-integer operation instruction. Can be configured such that the expression tree pattern selection unit 12 selects an expression tree having a pattern representing a long integer operation. (4) Further, in the above embodiment, the expression tree pattern conversion unit 13
However, it is configured to convert to a pattern corresponding to a procedure call instruction that executes a desired operation, but in the case of a pattern representing an operation in which the assignment operation is not completed by one assignment instruction such as assignment of a structure, The formula tree pattern conversion unit may be configured to convert the pattern into a pattern representing a plurality of assignment instructions according to the size of the structure.

【0030】[0030]

【発明の効果】以上説明したように、本発明に係る命令
コード選択装置は、同じ命令生成規則に対して異なる式
木のパタンが存在する場合に、式木パタン変換手段によ
って式木のパタンを変換することにより、テンプレート
中に記述した所望の命令生成規則を命令コード選択手段
が変換した式木のパタンを用いて選択するように構成し
たので、テンプレートに記述する命令生成規則の重複を
避けることができ、テンプレートをコンパクトにするこ
とができるとともに、あるターゲットマシン用のコンパ
イラを別のターゲットマシン用に書き換えようとする際
の作業工数の低減を図ることができる。
As described above, the instruction code selection device according to the present invention converts the expression tree pattern by the expression tree pattern conversion means when different expression tree patterns exist for the same instruction generation rule. By converting, the desired instruction generation rule described in the template is selected by using the pattern of the expression tree converted by the instruction code selecting means, so that duplication of the instruction generation rule described in the template is avoided. Thus, the template can be made compact, and the number of man-hours required for rewriting a compiler for one target machine to another target machine can be reduced.

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

【図1】本発明の実施例の命令コード選択装置の構成を
示すブロック図である。
FIG. 1 is a block diagram illustrating a configuration of an instruction code selection device according to an embodiment of the present invention.

【図2】コンパイラの一般的な構成を概念的に示した概
念図である。
FIG. 2 is a conceptual diagram conceptually showing a general configuration of a compiler.

【図3】浮動小数点型の加減算を含むC言語プログラム
とその命令に対応する式木パタンの例を示す説明図であ
る。
FIG. 3 is an explanatory diagram showing an example of a C language program including floating-point type addition and subtraction and an expression tree pattern corresponding to the instruction.

【図4】本発明の実施例によるテンプレートの内容の一
例を示す説明図である。
FIG. 4 is an explanatory diagram showing an example of the contents of a template according to the embodiment of the present invention.

【図5】図1に示す実施例の命令コード選択装置の動作
を示すフローチャートである。
FIG. 5 is a flowchart showing an operation of the instruction code selection device of the embodiment shown in FIG. 1;

【図6】本発明の命令コード選択装置の式木パタン変換
部の変換動作を示すフローチャートである。
FIG. 6 is a flowchart showing a conversion operation of an expression tree pattern conversion unit of the instruction code selection device of the present invention.

【図7】式木パタン変換部13で使用される式木の変換
表の一例を示す説明図である。
FIG. 7 is an explanatory diagram showing an example of a conversion table of an expression tree used in the expression tree pattern conversion unit 13;

【図8】式木パタン変換部13によって変換される式木
のパタンの変換前後の状態を示す模式図である。
FIG. 8 is a schematic diagram showing states before and after conversion of a pattern of an expression tree converted by an expression tree pattern conversion unit 13;

【図9】従来の命令コード選択装置のテンプレートの一
例を示す説明図である。
FIG. 9 is an explanatory diagram showing an example of a template of a conventional instruction code selection device.

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

10 命令コード選択装置 11 変換制御部 12 式木パタン選択部 13 式木パタン変換部 14 命令コード選択部 15 テンプレート DESCRIPTION OF SYMBOLS 10 Instruction code selection apparatus 11 Conversion control part 12 Expression tree pattern selection part 13 Expression tree pattern conversion part 14 Instruction code selection part 15 Template

フロントページの続き (56)参考文献 特開 平3−144829(JP,A) 特開 平3−259343(JP,A) 特開 平5−53821(JP,A) 特開 平3−5827(JP,A) 情報処理学会第26回(昭和58年前期) 全国大会講演論文集,p.433−434 (58)調査した分野(Int.Cl.7,DB名) G06F 9/45 Continuation of front page (56) References JP-A-3-144829 (JP, A) JP-A-3-259343 (JP, A) JP-A-5-53821 (JP, A) JP-A-3-5827 (JP) , A) Proceedings of the IPSJ 26th (Early 1983) National Convention, p. 433-434 (58) Field surveyed (Int. Cl. 7 , DB name) G06F 9/45

Claims (3)

(57)【特許請求の範囲】(57) [Claims] 【請求項1】 入力された式木のパタンに対応する命令
コードを選択する命令コード選択装置であって、 入力された前記式木の中から特定のパタンを持つ式木を
選択する式木パタン選択手段と、 前記式木パタン選択手段により選択された前記式木のパ
タンを所定の式木のパタンに変換する式木パタン変換手
段と 種々の式木のパタンと、これに対応する命令生成規則
格納する格納手段と、 前記式木パタン変換手段によって変換された式木パタン
を用いて前記格納手段から命令生成規則を選択して命令
コードを生成する命令コード選択手段とを備え 前記格納手段は、前記所定のパタンに対応する命令生成
規則として、前記特定のパタンに対応する命令生成規則
を共通化した命令生成規則を格納する ことを特徴とす
る、命令コード選択装置。
An instruction code selecting device for selecting an instruction code corresponding to a pattern of an input expression tree, wherein the expression tree pattern selects an expression tree having a specific pattern from the input expression tree. Selection means, expression tree pattern conversion means for converting the expression tree pattern selected by the expression tree pattern selection means into a predetermined expression tree pattern , various expression tree patterns, and instruction generation corresponding thereto a store unit that stores rules, the formula by selecting the instruction generating rule from the previous SL price paid means using the equation tree pattern converted by the tree pattern converting means instruction
Instruction code selecting means for generating a code , wherein the storing means includes an instruction generating means corresponding to the predetermined pattern.
As a rule, an instruction generation rule corresponding to the specific pattern
An instruction code selection device, characterized by storing an instruction generation rule that makes the instruction code common .
【請求項2】 前記特定のパタンを持つ式木のそれぞれ
は演算を表し、 前記所定の式木のパタンは、演算を実行する手続きを呼
び出す命令に対応することを特徴とする、請求項1記載
の命令コード選択装置。
2. Each of the expression trees having the specific pattern
Represents operation pattern of said predetermined equation tree, call a procedure to perform the calculation
2. The method according to claim 1, wherein the instruction corresponds to an instruction to be issued.
Instruction code selection device.
【請求項3】 前記特定のパタンを持つ式木のそれぞれ
は演算を表し、 前記格納手段は、 特定の式木パタンと、これに対応する演算実行命令を生
成するための命令生成規則と、 所定の式木のパタンと、これに対応する演算を実行する
手続きを呼び出す命令を生成する1つの命令生成規則と
を格納し、 オペレータが演算実行命令の生成を所望する場合に、入
力された前記式木を前記式木パタン選択手段に出力し、
演算実行命令の生成を所望しない場合に、入力された前
記式木を前記命令コード選択手段に出力する変換制御手
段を備えたことを特徴とする、請求項1記載の命令コー
ド選択装置。
3. An expression tree having the specific pattern
Represents an operation, and the storage means generates a specific expression tree pattern and an operation execution instruction corresponding thereto.
Instruction generation rules for generating, a predetermined expression tree pattern, and an operation corresponding thereto
One instruction generation rule for generating an instruction that calls a procedure;
And when the operator desires to generate an operation execution instruction, outputs the input expression tree to the expression tree pattern selecting means,
2. The instruction code selection device according to claim 1, further comprising a conversion control unit that outputs the input expression tree to the instruction code selection unit when generation of an operation execution instruction is not desired.
JP22699093A 1993-09-13 1993-09-13 Instruction code selection device Expired - Fee Related JP3327640B2 (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
JP22699093A JP3327640B2 (en) 1993-09-13 1993-09-13 Instruction code selection device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
JP22699093A JP3327640B2 (en) 1993-09-13 1993-09-13 Instruction code selection device

Publications (2)

Publication Number Publication Date
JPH0784796A JPH0784796A (en) 1995-03-31
JP3327640B2 true JP3327640B2 (en) 2002-09-24

Family

ID=16853787

Family Applications (1)

Application Number Title Priority Date Filing Date
JP22699093A Expired - Fee Related JP3327640B2 (en) 1993-09-13 1993-09-13 Instruction code selection device

Country Status (1)

Country Link
JP (1) JP3327640B2 (en)

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
情報処理学会第26回(昭和58年前期)全国大会講演論文集,p.433−434

Also Published As

Publication number Publication date
JPH0784796A (en) 1995-03-31

Similar Documents

Publication Publication Date Title
JP3762867B2 (en) Compiler device, compiling method, and storage medium storing program therefor
CN110673854B (en) SAS language compilation method, device, equipment and readable storage medium
US5142681A (en) APL-to-Fortran translators
US5606697A (en) Compiler system for language processing program
JPWO2000045260A1 (en) Compiler device, compiling method, and storage medium storing a program therefor
JPH08202545A (en) Object-oriented system and method for generation of target language code
JP5147240B2 (en) Method and system for reversible design tree transformation
Fauth et al. Automated generation of DSP program development tools using a machine description formalism
CN114564195B (en) A secondary development method of cloud CAD platform based on B/S architecture
US20010042241A1 (en) Apparatus and method for executing program using just-in time-compiler system
JP3327640B2 (en) Instruction code selection device
GB2420638A (en) Method of substituting code fragments in Internal Representation
CN119917109B (en) Simulation parametric design method, device and system compatible with APDL command stream
JP2003076558A (en) Method and program for controlling program execution
JP3031767B2 (en) Natural language processor
JPH0795275B2 (en) Compile processor
CN120806190A (en) Code processing method, apparatus, electronic device, storage medium, and computer program product
JPH11195011A (en) Language translation processor, language translation processing method and record medium recording language translation processing program
JPH0540780A (en) Vectorizing processing system
CN121560331A (en) Parameterized compiling optimization method and system based on multi-stage intermediate representation
JP2861630B2 (en) Connection structure analyzer
CN119511931A (en) A PLC programming method based on C++ language
JPH0371229A (en) Program controller
JPH06110750A (en) Method for automatically generating makefile of application program that can access relational database
JPH05108372A (en) System for outputting compiler optimization processing content

Legal Events

Date Code Title Description
LAPS Cancellation because of no payment of annual fees