The first step in the cloning process is to scan through the code being
copied to search for references to objects that are not visible in the
destination scope. The tree_node_list
, tree_node
,
operand
, instruction
, and block_symtab
classes have
find_exposed_refs
methods to perform this operation. The results
are returned in a replacements
structure by putting the exposed
references in the lists of original objects. The lists of new objects
are left empty.
Besides checking for exposed references in the objects themselves, the
find_exposed_refs
methods also check for references contained in
annotations attached to the objects. Both flat and structured
annotations are checked, but unregistered annotations are ignored since
they are not copied. The find_annote_refs
method is used to
check a suif_object
for exposed references.
Label symbols are a special case. Even if a label symbol is visible in
the destination scope, it must be replaced if the label instruction is
to be cloned. Otherwise, there would be two label instructions sharing
the same label symbol! Thus, the find_exposed_refs
method adds
the symbol in a label instruction to the list of exposed references.
The exception to this is that label symbols that are defined within
cloned symbol tables will automatically be replaced and are not included
in the exposed references.