P4C
The P4 Compiler
Loading...
Searching...
No Matches
frontends/common/options.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/* -*-C++-*- */
18
19#ifndef FRONTENDS_COMMON_OPTIONS_H_
20#define FRONTENDS_COMMON_OPTIONS_H_
21
22#include <filesystem>
23#include <unordered_set>
24
25#include "parser_options.h"
26// for p4::P4RuntimeFormat definition
27#include "control-plane/p4RuntimeTypes.h"
28
29namespace P4 {
30
31class CompilerOptions : public ParserOptions {
32 protected:
33 bool validateOptions() const override;
34
35 public:
36 explicit CompilerOptions(std::string_view defaultMessage = "Compile a P4 program");
37
38 // If true, skip frontend passes whose names are contained in
39 // passesToExcludeFrontend vector.
40 bool excludeFrontendPasses = false;
41 bool listFrontendPasses = false;
42 // If true, skip midend passes whose names are contained in
43 // passesToExcludeMidend vector.
44 bool excludeMidendPasses = false;
45 bool listMidendPasses = false;
46 // If true, skip backend passes whose names are contained in
47 // passesToExcludeBackend vector.
48 bool excludeBackendPasses = false;
49 // Strings matched against pass names that should be excluded from frontend
50 // passes.
51 std::vector<cstring> passesToExcludeFrontend;
52 // Strings matched against pass names that should be excluded from midend
53 // passes.
54 std::vector<cstring> passesToExcludeMidend;
55 // Strings matched against pass names that should be excluded from backend
56 // passes.
57 std::vector<cstring> passesToExcludeBackend;
58 // Dump a JSON representation of the IR in the file.
59 std::filesystem::path dumpJsonFile;
60 // Dump and undump the IR tree.
61 bool debugJson = false;
62 // if this flag is true, compile program in non-debug mode.
63 bool ndebug = false;
64 // Write a P4Runtime control plane API description to the specified file.
65 cstring p4RuntimeFile = nullptr;
66 // Write static table entries as a P4Runtime WriteRequest message to the
67 // specified file.
68 cstring p4RuntimeEntriesFile = nullptr;
69 // Write P4Runtime control plane API description to the specified files.
70 cstring p4RuntimeFiles = nullptr;
71 // Write static table entries as a P4Runtime WriteRequest message to the
72 // specified files.
73 cstring p4RuntimeEntriesFiles = nullptr;
74 // Choose format for P4Runtime API description.
75 P4::P4RuntimeFormat p4RuntimeFormat = P4::P4RuntimeFormat::BINARY;
76 // Pretty-print the program in the specified file.
77 std::filesystem::path prettyPrintFile;
78 // Target.
79 cstring target = nullptr;
80 // Architecture.
81 cstring arch = nullptr;
82 // If true, unroll all parser loops inside the midend.
83 bool loopsUnrolling = false;
84 // List of code metrics input by user.
85 cstring inputMetrics = nullptr;
86 // Code metrics to be collected.
87 std::set<cstring> selectedMetrics;
88
89 // General optimization options -- can be interpreted by backends in various ways
90 int optimizationLevel = 1;
91 bool optimizeDebug = false; // optimize favoring debuggability
92 bool optimizeSize = false; // optimize favoring size
93
94 virtual bool enable_intrinsic_metadata_fix();
95
99 virtual bool controlPlaneAPIGenEnabled() const {
100 if (p4RuntimeFile.isNullOrEmpty() && p4RuntimeFiles.isNullOrEmpty() &&
101 p4RuntimeEntriesFile.isNullOrEmpty() && p4RuntimeEntriesFiles.isNullOrEmpty()) {
102 return false;
103 }
104 return true;
105 }
106};
107
108} // namespace P4
109
110#endif /* FRONTENDS_COMMON_OPTIONS_H_ */
virtual bool controlPlaneAPIGenEnabled() const
Definition frontends/common/options.h:99
bool validateOptions() const override
Definition frontends/common/options.cpp:214
Definition cstring.h:85
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24
P4RuntimeFormat
P4Runtime serialization formats.
Definition p4RuntimeTypes.h:23