P4C
The P4 Compiler
Loading...
Searching...
No Matches
bmv2/common/parser.h
1/*
2Copyright 2013-present Barefoot Networks, Inc.
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17#ifndef BACKENDS_BMV2_COMMON_PARSER_H_
18#define BACKENDS_BMV2_COMMON_PARSER_H_
19
20#include "expression.h"
21#include "frontends/common/resolveReferences/referenceMap.h"
22#include "frontends/p4/typeMap.h"
23#include "helpers.h"
24#include "ir/ir.h"
25#include "lib/json.h"
26
27namespace P4::BMV2 {
28
29class JsonObjects;
30
31class ParserConverter : public Inspector {
33 cstring name;
34 P4::P4CoreLibrary &corelib;
35
36 protected:
37 void convertSimpleKey(const IR::Expression *keySet, big_int &value, big_int &mask) const;
38 unsigned combine(const IR::Expression *keySet, const IR::ListExpression *select, big_int &value,
39 big_int &mask, bool &is_vset, cstring &vset_name) const;
40 Util::IJson *stateName(IR::ID state);
41 Util::IJson *convertParserStatement(const IR::StatOrDecl *stat);
42 Util::IJson *convertSelectKey(const IR::SelectExpression *expr);
43 Util::IJson *convertPathExpression(const IR::PathExpression *expr);
44 Util::IJson *createDefaultTransition();
45 cstring jsonAssignment(const IR::Type *type);
46 std::vector<Util::IJson *> convertSelectExpression(const IR::SelectExpression *expr);
47 void addValueSets(const IR::P4Parser *parser);
48
49 public:
50 bool preorder(const IR::P4Parser *p) override;
51 explicit ParserConverter(ConversionContext *ctxt, cstring name = "parser"_cs)
52 : ctxt(ctxt), name(name), corelib(P4::P4CoreLibrary::instance()) {
53 setName("ParserConverter");
54 }
55};
56
57} // namespace P4::BMV2
58
59#endif /* BACKENDS_BMV2_COMMON_PARSER_H_ */
Definition bmv2/common/parser.h:31
void convertSimpleKey(const IR::Expression *keySet, big_int &value, big_int &mask) const
Operates on a select keyset.
Definition bmv2/common/parser.cpp:334
Definition visitor.h:400
Definition coreLibrary.h:103
Definition json.h:40
Definition cstring.h:85
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition action.cpp:21
Definition helpers.h:297
Definition id.h:28