简体   繁体   English

Backpatching是什么意思?

[英]What does Backpatching mean?

What does backpatching mean ? backpatching是什么意思? 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. 在生成中间代码时,一些语句(如条件语句,等等)将表示为一堆“if”和“goto”语法。 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 ). 问题是,这些“goto”指令在开头没有有效的引用 (当编译器开始逐行读取源代码时 - 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. 但是,在第一次阅读完整的源代码之后,确定了这些“goto”指向的标签引用

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? 问题是我们可以让编译器能够在一次通过中填充“goto X”语句中的X吗? The answer is yes. 答案是肯定的。

If we don't use backpatching, this can be achieved by a 2 pass analysis on the source code. 如果我们不使用反向修补,可以通过对源代码进行2遍分析来实现。 But, backpatching lets us to create and hold a separate list which is exclusively designed for "goto" statements. 但是,回调允许我们创建并保存一个专门为“goto”语句设计的单独列表 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. 因为它只在一次传递中完成,所以第一次传递不会填充“goto X”语句中的X,因为comipler乍一看不知道X的位置 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. 但是,它确实将X存储在该独占列表中,在完成整个代码并找到X之后X被该地址或引用替换。

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

Backpatching: The syntax directed definition can be implemented in two or more passes (we have both synthesized attributes and inherited attributes). Backpatching:语法定向定义可以在两个或多个过程中实现(我们有合成属性和继承属性)。

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. Backpatching是解决这个问题的技巧。 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. backpatching是一个过程,其中包含前向引用的指令的操作数字段最初保持空白。 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. 控制声明流程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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