P4C
The P4 Compiler
 
Loading...
Searching...
No Matches
P4::Specialize Class Reference

Specializes each Parser and Control with constant constructor arguments by substituting type arguments and constructor parameters. More...

Inheritance diagram for P4::Specialize:

Public Member Functions

 Specialize (SpecializationMap *specMap)
 
const IR::Node * postorder (IR::ConstructorCallExpression *expression) override
 
const IR::Node * postorder (IR::Declaration_Instance *) override
 
const IR::Node * postorder (IR::P4Control *control) override
 
const IR::Node * postorder (IR::P4Parser *parser) override
 
const IR::Node * preorder (IR::Type_Package *package) override
 

Detailed Description

Specializes each Parser and Control with constant constructor arguments by substituting type arguments and constructor parameters.

Specifically, each instantiation of each Parser (or Control) with constructor parameters will cause

  • the creation of a new Parser (or Control) with the actual arguments substituted for the constructor parameters, and
  • the replacement of the instantiation with a new instantiation using the newly-specialized Parser (or Control).

Instantiations with constructor arguments that are not constant values are ignored—see SpecializeAll for details.

Note that this pass handles type substitution for instantiating generic Parser or Control types, which is an experimental feature.

For example:

control c<T>(in T data)(bit<32> size) { ... }
c<bit<32>>(16) c_inst;

is converted to

control cspec(in bit<32> data) { ... }
cspec() c_inst;

with 16 substituted for size in the body of cspec.

A different specialization is made for each constructor invocation and Declaration_Instance.