简体   繁体   中英

What does Backpatching mean?

What does backpatching mean ? Please illustrate with a simple example.

返回修补通常是指解析已经在代码中植入的前向分支的过程,例如在“if”语句中,当目标的值变得已知时,例如当遇到右括号或匹配'else'时。

In intermediate code generation stage of a compiler we often need to execute "jump" instructions to places in the code that don't exist yet. To deal with this type of cases a target label is inserted for that instruction. A marker nonterminal in the production rule causes the semantic action to pick up.

Some statements like conditional statements, while, etc. will be represented as a bunch of "if" and "goto" syntax while generating the intermediate code. The problem is that, These "goto" instructions, do not have a valid reference at the beginning(when the compiler starts reading the source code line by line - AKA 1st pass ). But, after reading the whole source code for the first time, the labels and references these "goto"s are pointing to, are determined.

The problem is that can we make the compiler able to fill the X in the "goto X" statements in one single pass or not? The answer is yes.

If we don't use backpatching, this can be achieved by a 2 pass analysis on the source code. But, backpatching lets us to create and hold a separate list which is exclusively designed for "goto" statements. Since it is done in only one pass, the first pass will not fill the X in the "goto X" statements because the comipler doesn't know where the X is at first glance. But, it does stores the X in that exclusive list and after going through the whole code and finding that X , the X is replaced by that address or reference.

Backpaching是为goto指令留下空白条目的过程,其中目标地址在第一遍中的前向传输中是未知的,并且在第二遍中填充这些未知。

Backpatching: The syntax directed definition can be implemented in two or more passes (we have both synthesized attributes and inherited attributes).

Build the tree first.

Walk the tree in the depth-first order.

The main difficulty with code generation in one pass is that we may not know the target of a branch when we generate code for flow of control statements

Backpatching is the technique to get around this problem. Generate branch instructions with empty targets When the target is known, fill in the label of the branch instructions (backpatching).

backpatching is a process in which the operand field of an instruction containing a forward reference is left blank initially. the address of the forward reference symbol is put into this field when its definition is encountered in the program.

Back patching is the activity of filling up the unspecified information of labels by using the appropriate semantic expression in during the code generation process.

It is done by:

  1. boolean expression.
  2. flow of control statement.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM