Skip to content

Annotated CAST Part 2: Main Functionality for Each Pass

Ryan Sullivant edited this page May 17, 2022 · 5 revisions

Annotated CAST: Functionality Highlights for Each Pass

Here we highlight the main functionality provided by each Annotated CAST pass.

IdCollapsePass

  1. Collapsing ids of AnnCastName nodes stating with zero. This is mainly necessary for CAST generated on the GCC side, since GCC assigns random ids (read as multiple digit ids) to identifiers.
  2. Determining AnnCastName nodes are global variables. We say that something is global if it is used at the module scope. If a name node is used at the module scope, we add it to PipelineState's module_node.used_vars dict. This dict is used by PipelineState's methods is_global_var() and all_globals_dict().
  3. Determining if a AnnCastCall node has an associated AnnCastFunctionDef, and determining the invocation_index of the Call node.

ContainerScopePass

  1. Store the container scope for each AnnCastName node.
  2. Keep track of accessed variables (read from), modified variables (assigned to), and used variables (accessed or modified) for each container. This included propagating up accessed, modified, and used variables to enclosing container scopes. For locals, the propagation stops at the closest function container scope, but for globals it continues until the module scope.
  3. Determine if an AnnCastCall node should be a GrFN 2.2 type Call, and if so, make a deep copy of its associated AnnCastFunctionDef.
  4. Create GrfnContainerSrcRef for each container. This is used to populate GrFN container metadata.

VariableVersionPass

  1. Determine container scope dependent versions for each AnnCastName node, and create GrFN VariableNodes for modified variables.
  2. Populate container top and bottom interfaces. For If and Loop containers, used variables are propagated through the top interface, and modified variables are propagated through the bottom interface. For Calls and FunctionDefs arguments/parameters and used globals are propagated through the top interface, while modified globals and return value (if existent) is propagated through the bottom interface.
  3. For CAST coming from Python, dummy assignments are added at the top of functions so that variable propagation is in line with CAST coming from GCC.

GrfnVarCreationPass

  1. Creating GrFN variables for If and Loop interfaces.
  2. Creating GrFN variables for any AnnCastName nodes which don't already have a GrFN variable associated with them.
  3. Aliasing versions for variables across container scopes. For example, for an If or Loop container the INIT_VERSION of a variable entering the body is the aliased to the highest version of that variable appearing in the If/Loop conditional expression. This aliasing ensures that linking GrFN variables "locally" within container scopes will produce correct adjacencies.
  4. Creating and setting up If and Loop GrFN Condition node and If GrFN Decision node.

GrfnAssignmentPass

  1. Create GrFN LITERAL or ASSIGN LambdaNodes for all explicit/from source assignments.
  2. Create GrFN LITERAL or ASSIGN LambdaNodes for function arguments and function return values.

LambdaExpressionPass

  1. Populate expr_str attribute of all AnnCast nodes.
  2. Combine node expr_str's to generate lambda expressions for each LambdaNodeincluding interfaces, assignments, conditions, and decisions

ToGrfnPass

  1. Build GroundedFunctionNetwork graph including
  • creating LambdaNode's for each interface, decision, and condition
  • creating HyperEdges between GrFN VariableNode's and LambdaNodes
  • creating subgraphs for each container, and adding nodes to the appropriate subgraph

Note: The stuff about pass prototype below should be moved somewhere else I think.

Prototype for new Annotated Cast pass:

Each pass does a traversal of the annotated CAST, which means that code for the visitor pattern is repeated on any given pass. To facilitate implementing a new pass, we have a prototype of the visitor code that can be used as a starting point for a new pass. This prototype can be found at automates/program_analysis/CAST2GrFN/visitors/ann_cast_prototype.py

Clone this wiki locally