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

Public Member Functions

void postorder (const IR::Annotations *annotations) override
 Structured annotations cannot reuse names.
 
void postorder (const IR::Constant *c) override
 Check that the type of a constant is either bit<>, int<> or int.
 
void postorder (const IR::ConstructorCallExpression *expression) override
 Cannot invoke constructors in actions.
 
void postorder (const IR::Declaration_Constant *decl) override
 Constant names cannot be underscore.
 
void postorder (const IR::Declaration_Instance *inst) override
 
void postorder (const IR::Declaration_Variable *decl) override
 Variable names cannot be underscore.
 
void postorder (const IR::Dots *dots) override
 
void postorder (const IR::EntriesList *l) override
 
void postorder (const IR::ExitStatement *statement) override
 Exit statements are not allowed in parsers or functions.
 
void postorder (const IR::Method *t) override
 
void postorder (const IR::P4Control *control) override
 
void postorder (const IR::P4Parser *parser) override
 
void postorder (const IR::P4Program *program) override
 
void postorder (const IR::P4Table *t) override
 Tables must have an 'actions' property.
 
void postorder (const IR::ParserState *s) override
 The accept and reject states cannot be implemented.
 
void postorder (const IR::ReturnStatement *statement) override
 Return statements are not allowed in parsers.
 
void postorder (const IR::StructField *f) override
 Struct field names cannot be underscore.
 
void postorder (const IR::SwitchStatement *statement) override
 Default label in switch statement is always the last one.
 
void postorder (const IR::Type_Bits *type) override
 Width of a bit<> or int<> type is greater than 0.
 
void postorder (const IR::Type_Package *package) override
 
void postorder (const IR::Type_Varbits *type) override
 

Detailed Description

This pass performs some simple semantic checks on the program; since the grammar accepts many programs that are actually illegal, this pass does some additional validation.

This pass is run immediately after parsing. There is no type information at this point, so it only does simple checks.

  • integer constants have valid types
  • don't care _ is not used as a name for methods, fields, variables, instances
  • width of bit<> types is positive
  • width of int<> types is larger than 1
  • no parser state is named 'accept' or 'reject'
  • constructor parameters are direction-less
  • tables have an actions property
  • instantiations appear at the top-level only
  • the default label of a switch statement appears last
  • instantiations do not occur in actions
  • constructors are not invoked in actions
  • returns and exits do not appear in parsers
  • exits do not appear in functions
  • extern constructors have the same name as the enclosing extern
  • names of all parameters are distinct
  • no duplicate declarations in toplevel program
  • Dots are the last field

Member Function Documentation

◆ postorder() [1/2]

void P4::ValidateParsedProgram::postorder ( const IR::Declaration_Instance * decl)
override

Instance names cannot be don't care Do not declare instances in apply {} blocks, parser states or actions

◆ postorder() [2/2]

void P4::ValidateParsedProgram::postorder ( const IR::Method * m)
override

Check that underscore is not a method name Check that constructors do not have a return type Check that extern constructor names match the enclosing extern