Chapter 5:Semantic Analysis

Resource requirement

 

If we allocate resources during the compile time using the above information, then the resources will be allocated in the order shown above ( just below the arrow diagram showing the dependencies). Note that where R3 is written it means that R1 and R2 are already in use. Note how we have used the information from the topologically sorted graph to allocate the resources. We could thus evaluate 9 attributes by just allocating 3 resources. For example, after evaluating node 1, we reused the resource held by 1, because 1 is not needed any longer by any other node for its attributes evaluation.

However , we can do even better : Note that, most of the time, the attributes are just copied from one node to another without any modification. For attributes that are just copied, we need not allocate any extra resource ( Register), we can simply use the re-source of the node whose attribute is being copied. Thus, in the previous example, the attribute evaluation can be done using just 2 Resources (Registers), as shown in the lowermost figure.