P4C
The P4 Compiler
 
Loading...
Searching...
No Matches
P4Tools::MidEnd Class Reference
Inheritance diagram for P4Tools::MidEnd:

Public Member Functions

 MidEnd (const CompilerOptions &)
 
void addDefaultPasses ()
 
P4::ReferenceMapgetRefMap ()
 Retrieve the reference map used in the mid end.
 
P4::TypeMapgetTypeMap ()
 Retrieve the type map used in the mid end.
 

Protected Member Functions

virtual bool localCopyPropPolicy (const Visitor::Context *ctx, const IR::Expression *expr)
 
virtual Visitor * mkConvertEnums ()
 
virtual P4::ChooseEnumRepresentationmkConvertEnumsPolicy ()
 
virtual P4::ChooseErrorRepresentationmkConvertErrorPolicy ()
 
virtual Visitor * mkConvertErrors ()
 
virtual Visitor * mkConvertKeys ()
 Provides a target-specific pass that simplifies keys in table calls under a custom policy.
 

Protected Attributes

P4::ReferenceMap refMap
 
P4::TypeMap typeMap
 

Detailed Description

Implements a generic mid end for all targets. If needed, targets can customize this to implement things like targets-specific conversion of P4 enums to bit<n>.

Mid-end implementations must establish certain invariants in the IR.

TODO: Document these invariants. So far, we have:

  • controls and parsers are inlined
  • function arguments are propagated into function bodies where possible
  • fully type-checked

Member Function Documentation

◆ addDefaultPasses()

void P4Tools::MidEnd::addDefaultPasses ( )

Add the list of default passes to the mid end. This is not part of the initializer because some targets may add their own passes to the beginning of the pass list.

◆ localCopyPropPolicy()

bool P4Tools::MidEnd::localCopyPropPolicy ( const Visitor::Context * ctx,
const IR::Expression * expr )
protectedvirtual

Provides a target-specific policy for determining when to do local copy propagation. Implementations should return @false if local copy propagation should not be performed on the given expression. The default implementation enables local copy propagation everywhere by always returning @true.

◆ mkConvertEnums()

Visitor * P4Tools::MidEnd::mkConvertEnums ( )
protectedvirtual

Provides a target-specific pass that converts P4 enums to bit<n>. The default implementation returns P4::ConvertEnums, instantiated with the policy provided by @mkChooseEnumRepresentation.

◆ mkConvertEnumsPolicy()

P4::ChooseEnumRepresentation * P4Tools::MidEnd::mkConvertEnumsPolicy ( )
protectedvirtual

Provides a target-specific policy for converting P4 enums to bit<n>. The default implementation converts all enums to bit<32>.

Implements the default enum-conversion policy, which converts all enums to bit<32>.

◆ mkConvertErrorPolicy()

P4::ChooseErrorRepresentation * P4Tools::MidEnd::mkConvertErrorPolicy ( )
protectedvirtual

Provides a target-specific policy for converting P4 error to bit<n>. The default implementation converts all errors to bit<32>.

Implements the default enum-conversion policy, which converts all enums to bit<32>.

◆ mkConvertErrors()

Visitor * P4Tools::MidEnd::mkConvertErrors ( )
protectedvirtual

Provides a target-specific pass that converts P4 errors to bit<n>. The default implementation returns P4Tools::ConvertErrors, instantiated with the policy provided by @mkChooseEnumRepresentation.