P4C
The P4 Compiler
Loading...
Searching...
No Matches
getV1ModelVersion.h
1#ifndef FRONTENDS_P4_GETV1MODELVERSION_H_
2#define FRONTENDS_P4_GETV1MODELVERSION_H_
3
4#include "absl/strings/numbers.h"
5#include "frontends/p4-14/fromv1.0/v1model.h"
6#include "ir/ir.h"
7#include "ir/visitor.h"
8
9namespace P4::P4V1 {
10
14 bool preorder(const IR::Declaration_Constant *dc) override {
15 if (dc->name == "__v1model_version") {
16 const auto *val = dc->initializer->to<IR::Constant>();
17 if (!val || val->value < 0) {
18 P4::error(ErrorType::ERR_EXPECTED,
19 "%1%: expected v1model version to be a non-negative number",
20 dc->initializer);
21 return false;
22 }
23 version = static_cast<unsigned>(val->value);
24
25 unsigned initialVersion;
26 unsigned currentVersion;
27 BUG_CHECK(absl::SimpleAtoi(V1Model::versionInitial, &initialVersion) &&
28 absl::SimpleAtoi(V1Model::versionCurrent, &currentVersion),
29 "Unable to check v1model version");
30 if (version < initialVersion || version > currentVersion) {
32 ErrorType::ERR_UNKNOWN,
33 "%1%: unknown v1model version; initial supported version is %2%, latest is %3%",
34 dc->initializer, initialVersion, currentVersion);
35 return false;
36 }
37 }
38 return false;
39 }
40 bool preorder(const IR::Declaration *) override { return false; }
41
42 public:
43 unsigned version = 0;
44};
45
46} // namespace P4::P4V1
47
48#endif /* FRONTENDS_P4_GETV1MODELVERSION_H_ */
Definition visitor.h:413
Definition getV1ModelVersion.h:13
Definition converters.cpp:28
void error(const char *format, Args &&...args)
Report an error with the given message.
Definition lib/error.h:58