P4C
The P4 Compiler
Loading...
Searching...
No Matches
checkSize.h
1/*
2 * Copyright 2018 VMware, Inc.
3 * SPDX-FileCopyrightText: 2018 VMware, Inc.
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 */
7
8#ifndef MIDEND_CHECKSIZE_H_
9#define MIDEND_CHECKSIZE_H_
10
11#include "ir/ir.h"
12
13namespace P4 {
14
16class CheckTableSize : public Modifier {
17 public:
18 CheckTableSize() { setName("CheckTableSize"); }
19 bool preorder(IR::P4Table *table) override {
20 auto size = table->getSizeProperty();
21 if (size == nullptr) return false;
22
23 bool deleteSize = false;
24 auto key = table->getKey();
25 if (key == nullptr) {
26 if (size->value != 1) {
27 warn(ErrorType::WARN_MISMATCH, "%1%: size %2% specified for table without keys",
28 table, size);
29 deleteSize = true;
30 }
31 }
32 auto entries = table->properties->getProperty(IR::TableProperties::entriesPropertyName);
33 if (entries != nullptr && entries->isConstant) {
34 warn(ErrorType::WARN_MISMATCH,
35 "%1%: size %2% specified for table with constant entries", table, size);
36 deleteSize = true;
37 }
38 if (deleteSize) {
39 auto props = IR::IndexedVector<IR::Property>(table->properties->properties);
40 props.removeByName(IR::TableProperties::sizePropertyName);
41 table->properties = new IR::TableProperties(table->properties->srcInfo, props);
42 }
43 return false;
44 }
45};
46
47} // namespace P4
48
49#endif /* MIDEND_CHECKSIZE_H_ */
Definition indexed_vector.h:31
Definition visitor.h:385
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:13