BackPatching
. way to implement boolean expressions and flow of control statements in one pass
. code is generated as quadruples into an array
. labels are indices into this array
. makelist(i): create a newlist containing only i, return a pointer to the list.
. merge(p1,p2): merge lists pointed to by p1 and p2 and return a pointer to the concatenated list
. backpatch(p,i): insert i as the target label for the statements in the list pointed to by p
Backpatching is a technique to solve the problem of replacing symbolic names in goto statements by the actual target addresses. This problem comes up because of some languages do not allow symbolic names in the branches.
Idea: Maintain a list of branches that have the same target label ( the function backpatch(p,i) does this only) and replace them once they are defined.
Backpatching can be summarized as this:
. Two-pass implementation: (1) syntax tree (2) depth-first walk
. back-patching (one-pass)
. construct the syntax tree
. depth-first order tree walk computing translations
. generate jumps with unspecified targets (labels)
. keep a list of such statements
. subsequently fill in the labels (back-patching)
. implementation + operations
. table of quadruples; labels as indexes into this table
. makelist(i) create a new list containing only i
. merge(p1, p2) concatenate lists and return pointer
. backpatch(p, i) insert i as a target label for each of statements on list with pointer p
|