Skip to content

Annotated CAST Part 2: Main Functionality for Each Pass

Ryan Sullivant edited this page Jun 1, 2022 · 5 revisions

Annotated CAST: Functionality Highlights for Each Pass

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

IdCollapsePass

  1. Collapses 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. Determines which AnnCastName nodes are global variables. We say that an AnnCastName 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. Determines if an AnnCastCall node has an associated AnnCastFunctionDef, and determines the invocation_index of the Call node.

ContainerScopePass

  1. Stores the container scope for each AnnCastName node.
  2. Keeps track of accessed variables (read from variables), modified variables (assigned to variables), and used variables (accessed or modified variables) for each container. This includes 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. Determines if an AnnCastCall node should be a GrFN 2.2 type Call, and if so, makes a deep copy of its associated AnnCastFunctionDef.
  4. Creates GrfnContainerSrcRef for each container. This is used to populate GrFN container metadata.

VariableVersionPass

  1. Determines container scope dependent versions for each AnnCastName node, and creates GrFN VariableNodes for modified variables.
  2. Populates 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. Creates GrFN variables for If and Loop interfaces.
  2. Creates GrFN variables for any AnnCastName nodes which don't already have a GrFN variable associated with them.
  3. Aliases 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. Creates GrFN LITERAL or ASSIGN LambdaNodes for all explicit/from source assignments.
  2. Creates GrFN LITERAL or ASSIGN LambdaNodes for function arguments and function return values.

LambdaExpressionPass

  1. Populates expr_str attribute of all AnnCast nodes.
  2. Combines node's expr_str's to generate lambda expressions for each LambdaNode including interfaces, assignments, conditions, and decisions

ToGrfnPass

  1. Builds GroundedFunctionNetwork graph which includes
  • 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

Clone this wiki locally