17#ifndef MIDEND_CONVERTENUMS_H_
18#define MIDEND_CONVERTENUMS_H_
20#include "frontends/p4/typeChecking/typeChecker.h"
33 virtual bool convert(
const IR::Type_Enum *type)
const = 0;
36 virtual unsigned encoding(
const IR::Type_Enum *,
unsigned n)
const {
return n; }
41 virtual unsigned enumSize(
unsigned enumCount)
const = 0;
48 const IR::Type_Bits *type;
51 type = IR::Type_Bits::get(srcInfo, width,
false);
53 void add(
cstring decl) { repr.emplace(decl, repr.size()); }
54 unsigned get(
cstring decl)
const { return ::P4::get(repr, decl); }
56 auto begin() {
return repr.begin(); }
57 auto begin()
const {
return repr.begin(); }
58 auto end() {
return repr.end(); }
59 auto end()
const {
return repr.end(); }
102 : policy(policy), typeMap(typeMap) {
105 setName(
"DoConvertEnums");
107 const IR::Node *preorder(IR::Type_Enum *type)
override;
108 const IR::Node *postorder(IR::Type_Name *type)
override;
109 const IR::Node *postorder(IR::Member *expression)
override;
116 using EnumMapping =
decltype(DoConvertEnums::repr);
120 if (!typeChecking) typeChecking =
new TypeChecking(
nullptr, typeMap);
121 passes.push_back(typeChecking);
122 passes.push_back(convertEnums);
124 setName(
"ConvertEnums");
127 EnumMapping getEnumMapping()
const {
return convertEnums->repr; }
136 bool convert(
const IR::Type_Enum *type)
const override {
137 if (type->srcInfo.isValid()) {
142 unsigned enumSize(
unsigned)
const override {
return 32; }
Definition convertEnums.h:29
Definition typeChecker.h:32
Definition convertEnums.h:112
Definition convertEnums.h:93
Definition convertEnums.h:135
Definition convertEnums.h:44
Definition ir/pass_manager.h:40
Definition typeChecker.h:55
Definition source_file.h:131
Definition ordered_map.h:32
Definition string_map.h:41
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24