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

Public Member Functions

 DoReplaceTuples (ReferenceMap *refMap, TypeMap *typeMap)
 
const IR::Node * insertReplacements (const IR::Node *before)
 
const IR::Node * postorder (IR::ArrayIndex *expression) override
 
const IR::Node * postorder (IR::Declaration_Instance *decl) override
 
const IR::Node * postorder (IR::Method *method) override
 
const IR::Node * postorder (IR::P4Control *control) override
 
const IR::Node * postorder (IR::P4Parser *parser) override
 
const IR::Node * postorder (IR::Type_BaseList *type) override
 
const IR::Node * postorder (IR::Type_Extern *ext) override
 
const IR::Node * postorder (IR::Type_Newtype *type) override
 
const IR::Node * postorder (IR::Type_Struct *type) override
 
const IR::Node * postorder (IR::Type_Typedef *type) override
 
const IR::Node * preorder (IR::P4ListExpression *expression) override
 
const IR::Node * preorder (IR::P4ValueSet *set) override
 
const IR::Node * preorder (IR::Type_P4List *list) override
 
const IR::Node * skip (const IR::Node *node)
 

Detailed Description

Implement a pass that convert each Tuple type into a Struct.

The struct is inserted in the program replacing the tuple. We make up field names for the struct fields. Note that the replacement has to be recursive, since the tuple could contain types that contain other tuples.

Example: tuple<bit<32>, bit<32>> t;

is replaced by

struct tuple_0 { bit<32> f0; bit<32> f1; } tuple_0 t;

If some of the tuple type arguments are type variables the tuple is left unchanged, as below: struct S<T> { tuple<T> x; } This decision may need to be revisited in the future. Do not replace types within P4Lists either.

Precondition
none
Postcondition
ensure all tuples are replaced with struct. Notice that ListExpressions are not converted to StructExpressions; a subsequent type checking is needed for that.