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