P4C
The P4 Compiler
Loading...
Searching...
No Matches
irutils.h
1#ifndef IR_IRUTILS_H_
2#define IR_IRUTILS_H_
3
4#include <initializer_list>
5#include <vector>
6
7#include "lib/source_file.h"
8
9namespace P4 {
10
11class Transform;
12
13namespace IR {
14
15// Forward-declare some IR classes that are used in function declarations.
16class BoolLiteral;
17class StringLiteral;
18class Constant;
19class Expression;
20class BaseListExpression;
21class Literal;
22class Node;
23class StatOrDecl;
24class StructExpression;
25class Type;
26class Type_Bits;
27template <typename T>
28class IndexedVector;
29
31//
32// Some of these are just thin wrappers around functions in the IR, but it's nice having everything
33// in one place.
34
35/* =========================================================================================
36 * Types
37 * ========================================================================================= */
38
40const Type_Bits *getBitTypeToFit(int value);
41
42/* =========================================================================================
43 * Expressions
44 * ========================================================================================= */
45
48const IR::Constant *getMaxValueConstant(const Type *t, const Util::SourceInfo &srcInfo = {});
49
67const IR::Expression *getDefaultValue(const Type *type, const Util::SourceInfo &srcInfo = {},
68 bool valueRequired = false);
69
72const IR::Constant *convertBoolLiteral(const IR::BoolLiteral *lit);
73
78std::vector<const Expression *> flattenStructExpression(const StructExpression *structExpr);
79
82std::vector<const Expression *> flattenListExpression(const BaseListExpression *listExpr);
83
87std::vector<const Expression *> flattenListOrStructExpression(const Expression *listLikeExpr);
88
89/* =========================================================================================
90 * Other helper functions
91 * ========================================================================================= */
92
94big_int getBigIntFromLiteral(const Literal *);
95
97int getIntFromLiteral(const Literal *);
98
101// This is 2^(t->size) - 1 for unsigned and 2^(t->size - 1) - 1 for signed.
102big_int getMaxBvVal(const Type *t);
103
105big_int getMaxBvVal(int bitWidth);
106
108// This is 0 for unsigned and -(2^(t->size - 1)) for signed.
109big_int getMinBvVal(const Type *t);
110
128const IR::Node *inlineBlock(const Transform &, std::initializer_list<const IR::StatOrDecl *>);
129const IR::Node *inlineBlock(const Transform &, const IR::IndexedVector<IR::StatOrDecl> &);
130const IR::Node *inlineBlock(const Transform &, IR::IndexedVector<IR::StatOrDecl> &&);
131
132} // namespace IR
133
134} // namespace P4
135
136#endif /* IR_IRUTILS_H_ */
Definition indexed_vector.h:40
Definition node.h:94
Definition visitor.h:437
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24