P4C
The P4 Compiler
 
Loading...
Searching...
No Matches
P4::RemoveNestedStructs Class Referencefinal
Inheritance diagram for P4::RemoveNestedStructs:

Public Member Functions

 RemoveNestedStructs (ComplexValues *values)
 
const IR::Node * postorder (IR::Declaration_Variable *decl) override
 rewrite nested structs to non-nested structs
 
const IR::Node * postorder (IR::Member *expression) override
 replace reference to nested structs with the corresponding non-nested version
 
const IR::Node * postorder (IR::MethodCallExpression *expression) override
 
const IR::Node * postorder (IR::PathExpression *expression) override
 replace reference to nested structs with the corresponding non-nested version
 

Detailed Description

Implements a pass that removes nested structs.

Specifically, it converts only local variables, but does not change the arguments of controls, parsers, packages, and methods.

Example: struct T { bit b; } struct S { T t1; T t2; } S v; f(v.t1, v);

is replaced by

T v_t1; T v_t2; f(v_t1, { v_t1, v_t2 });

This does not work if the second argument of f is out or inout, since the list expression is not a l-value. This pass cannot be used in this case. This can arise only if there are extern functions that can have out arguments with types that are structs.

Precondition
: This pass should be run after CopyStructures, EliminateTuples, and MoveInitializers.
Postcondition
: Ensure that
  • all variables whose types are nested structs are flattened.