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;
44class EnumRepresentation {
45 std::map<cstring, unsigned> repr;
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 using iterator =
decltype(repr)::iterator;
57 using const_iterator =
decltype(repr)::const_iterator;
58 iterator begin() {
return repr.begin(); }
59 const_iterator begin()
const {
return repr.begin(); }
60 iterator end() {
return repr.end(); }
61 const_iterator end()
const {
return repr.end(); }
96 friend class ConvertEnums;
104 : policy(policy), typeMap(typeMap) {
107 setName(
"DoConvertEnums");
109 const IR::Node *preorder(IR::Type_Enum *type)
override;
110 const IR::Node *postorder(IR::Type_Name *type)
override;
111 const IR::Node *postorder(IR::Member *expression)
override;
114class ConvertEnums :
public PassManager {
118 using EnumMapping =
decltype(DoConvertEnums::repr);
122 if (!typeChecking) typeChecking =
new TypeChecking(refMap, typeMap);
123 passes.push_back(typeChecking);
124 passes.push_back(convertEnums);
126 setName(
"ConvertEnums");
129 EnumMapping getEnumMapping()
const {
return convertEnums->repr; }
138 bool convert(
const IR::Type_Enum *type)
const override {
139 if (type->srcInfo.isValid()) {
144 unsigned enumSize(
unsigned)
const override {
return 32; }
Definition convertEnums.h:29
Definition typeChecker.h:32
Definition convertEnums.h:95
Definition convertEnums.h:137
Class used to encode maps from paths to declarations.
Definition referenceMap.h:66
Definition typeChecker.h:55
Definition source_file.h:124
Definition ordered_map.h:32
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24