P4C
The P4 Compiler
Loading...
Searching...
No Matches
P4::IR Namespace Reference

Classes

struct  has_static_type_name
 
struct  has_static_type_name< T, std::void_t< decltype(T::static_type_name())> >
 
struct  ID
 
class  IDeclaration
 The Declaration interface, representing objects with names. More...
 
class  IndexedVector
 
class  INode
 
class  NameMap
 
class  Node
 
class  NodeMap
 
struct  StateVariableEqual
 Equals for StateVariable pointers. We only compare the label. More...
 
struct  StateVariableLess
 Less for StateVariable pointers. We only compare the label. More...
 
struct  SymbolicVariableEqual
 Equals for SymbolicVariable pointers. We only compare the label. More...
 
struct  SymbolicVariableLess
 Less for SymbolicVariable pointers. We only compare the label. More...
 
class  Vector
 
class  VectorBase
 

Functions

const IR::Constant * convertBoolLiteral (const IR::BoolLiteral *lit)
 
cstring dbp (const INode *node)
 
bool equal (const INode *a, const INode *b)
 
bool equal (const Node *a, const Node *b)
 
bool equiv (const INode *a, const INode *b)
 
bool equiv (const Node *a, const Node *b)
 
std::vector< const Expression * > flattenListExpression (const BaseListExpression *listExpr)
 
std::vector< const Expression * > flattenListOrStructExpression (const Expression *listLikeExpr)
 
std::vector< const Expression * > flattenStructExpression (const StructExpression *structExpr)
 
template<class T, class U>
const T * get (const IR::Vector< T > &vec, U name)
 
template<class T, class U>
const T * get (const IR::Vector< T > *vec, U name)
 
big_int getBigIntFromLiteral (const Literal *l)
 
const Type_Bits * getBitTypeToFit (int value)
 Utility functions for generating IR nodes.
 
const IR::Expression * getDefaultValue (const IR::Type *type, const Util::SourceInfo &srcInfo, bool valueRequired)
 
const IR::Expression * getDefaultValue (const Type *type, const Util::SourceInfo &srcInfo={}, bool valueRequired=false)
 
int getIntFromLiteral (const Literal *l)
 
big_int getMaxBvVal (const Type *t)
 
big_int getMaxBvVal (int bitWidth)
 
const IR::Constant * getMaxValueConstant (const Type *t, const Util::SourceInfo &srcInfo)
 
big_int getMinBvVal (const Type *t)
 
const IR::NodeinlineBlock (const Transform &t, const IR::IndexedVector< IR::StatOrDecl > &stmts)
 
const IR::NodeinlineBlock (const Transform &t, IR::IndexedVector< IR::StatOrDecl > &&stmts)
 
const IR::NodeinlineBlock (const Transform &t, std::initializer_list< const IR::StatOrDecl * > stmts)
 
template<typename Stmts>
const IR::NodeinlineBlockImpl (const Transform &t, Stmts &&stmts)
 

Variables

template<class T>
constexpr bool has_static_type_name_v = has_static_type_name<T>::value
 

Detailed Description

Copyright (C) 2024 Intel Corporation

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

SPDX-License-Identifier: Apache-2.0

Function Documentation

◆ convertBoolLiteral()

const IR::Constant * P4::IR::convertBoolLiteral ( const IR::BoolLiteral * lit)

Converts a bool literal into a constant of type Type_Bits and width 1. The value is 1, if the bool literal is true, 0 otherwise.

◆ flattenListExpression()

std::vector< const Expression * > P4::IR::flattenListExpression ( const BaseListExpression * listExpr)

Given an BaseListExpression, returns a flat vector of the expressions contained in that list.

◆ flattenListOrStructExpression()

std::vector< const Expression * > P4::IR::flattenListOrStructExpression ( const Expression * listLikeExpr)

Given a StructExpression or BaseListExpression, returns a flat vector of the expressions contained in that list. Note that this function will fail if the type of any input struct expression is not a Type_Name.

◆ flattenStructExpression()

std::vector< const Expression * > P4::IR::flattenStructExpression ( const StructExpression * structExpr)

Given an StructExpression, returns a flat vector of the expressions contained in that struct. Unfortunately, list and struct expressions are similar but have no common ancestors. This is why we require two separate methods. Note that this function will fail if the type of

Parameters
structExpris not a Type_Name.

◆ getBigIntFromLiteral()

big_int P4::IR::getBigIntFromLiteral ( const Literal * )
Returns
the big int value stored in a literal.

◆ getBitTypeToFit()

const Type_Bits * P4::IR::getBitTypeToFit ( int value)

Utility functions for generating IR nodes.

Returns
a representation of bit<> that is just wide enough to fit the given value.

◆ getDefaultValue()

const IR::Expression * P4::IR::getDefaultValue ( const Type * type,
const Util::SourceInfo & srcInfo = {},
bool valueRequired = false )
Returns
the "default" value for a given type. The resulting expression will have the specified srcInfo position. The current mapping as defined in the P4 specification is: Type_Bits 0 Type_Boolean false Type_InfInt 0 Type_Enum first member Type_SerEnum first member Type_Error NoError Type_String "" Type_Header InvalidHeader Type_HeaderUnion InvalidHeaderUnion Type_StructLike StructExpression (fields filled with getDefaultValue) Type_Fragment recurses into getDefaultValue Type_BaseList ListExpression (fields filled with getDefaultValue) Type_Array HeaderStackExpression (fields filled with getDefaultValue) Definition: https://p4.org/p4-spec/docs/P4-16-working-spec.html#sec-default-values

◆ getIntFromLiteral()

int P4::IR::getIntFromLiteral ( const Literal * )
Returns
the integer value stored in a literal. We use int here.

◆ getMaxBvVal() [1/2]

big_int P4::IR::getMaxBvVal ( const Type * t)
Returns
the maximum value that can fit into this type. This function assumes a big int value, meaning it only supports bit vectors and booleans.

◆ getMaxBvVal() [2/2]

big_int P4::IR::getMaxBvVal ( int bitWidth)
Returns
the maximum big_int value that can fit into this bit width.

◆ getMaxValueConstant()

const IR::Constant * P4::IR::getMaxValueConstant ( const Type * t,
const Util::SourceInfo & srcInfo = {} )
Returns
a constant with the maximum big_int value that can fit into this bit width. Implicitly converts boolean types to a bit vector of width one with value 1.

◆ getMinBvVal()

big_int P4::IR::getMinBvVal ( const Type * t)
Returns
the minimum value that can fit into this type.

◆ inlineBlock()

const IR::Node * P4::IR::inlineBlock ( const Transform & ,
std::initializer_list< const IR::StatOrDecl * >  )

A helper useful when returning multiple statements out of a Transform's function that should return a statement. While an IR::BlockStatement can accept a vector of statements for each of its child statements, some other places (namely IR::IfStatmenent, IR::SwitchStatement / IR::SwitchCase) only accept a statement. In these case, the visitor will fail with a BUG if the returned value is not IR::StatOrDecl. Passing the arguments through this function (or one of its overloads) works around this by wrapping the statements into a BlockStatement if the parent node cannot accept them directly.

This would be usually used as follows const IR::Node *preorder(IR::SomeStatement *stmt) { ... return IR::inlineBlock(*this, {a, b, c}); }

Returns
IR::IndexedVector<IR::StatOrDecl> * containing the values if the parent is IR::BlockStatement, and IR::BlockStatement * containing the values otherwise. As a special case, returns the sole statement if there is just one passed to the function.