P4C
The P4 Compiler
Loading...
Searching...
No Matches
checkSize.h
1/*
2Copyright 2018 VMware, 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 MIDEND_CHECKSIZE_H_
18#define MIDEND_CHECKSIZE_H_
19
20#include "ir/ir.h"
21
22namespace P4 {
23
25class CheckTableSize : public Modifier {
26 public:
27 CheckTableSize() { setName("CheckTableSize"); }
28 bool preorder(IR::P4Table *table) override {
29 auto size = table->getSizeProperty();
30 if (size == nullptr) return false;
31
32 bool deleteSize = false;
33 auto key = table->getKey();
34 if (key == nullptr) {
35 if (size->value != 1) {
36 warn(ErrorType::WARN_MISMATCH, "%1%: size %2% specified for table without keys",
37 table, size);
38 deleteSize = true;
39 }
40 }
41 auto entries = table->properties->getProperty(IR::TableProperties::entriesPropertyName);
42 if (entries != nullptr && entries->isConstant) {
43 warn(ErrorType::WARN_MISMATCH,
44 "%1%: size %2% specified for table with constant entries", table, size);
45 deleteSize = true;
46 }
47 if (deleteSize) {
48 auto props = IR::IndexedVector<IR::Property>(table->properties->properties);
49 props.removeByName(IR::TableProperties::sizePropertyName);
50 table->properties = new IR::TableProperties(table->properties->srcInfo, props);
51 }
52 return false;
53 }
54};
55
56} // namespace P4
57
58#endif /* MIDEND_CHECKSIZE_H_ */
Checks some possible misuses of the table size property.
Definition checkSize.h:25
Definition node.h:52
Definition visitor.h:372
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24