P4C
The P4 Compiler
Loading...
Searching...
No Matches
backends/p4tools/common/options.h
1/*
2 * SPDX-FileCopyrightText: 2022 The P4 Language Consortium
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#ifndef BACKENDS_P4TOOLS_COMMON_OPTIONS_H_
8#define BACKENDS_P4TOOLS_COMMON_OPTIONS_H_
9
10#include <cstdint>
11#include <optional>
12#include <tuple>
13#include <vector>
14
15#include "frontends/common/options.h"
16#include "lib/compile_context.h"
17
18namespace P4::P4Tools {
19
23class AbstractP4cToolOptions : public CompilerOptions {
24 private:
26 std::string _toolName;
27
28 // Keep argument buffers alive while option fields and compilerArgs borrow them.
29 std::vector<std::shared_ptr<std::string>> argumentStorage;
30
31 public:
32 virtual ~AbstractP4cToolOptions() = default;
34 std::optional<uint32_t> seed = std::nullopt;
35
38
42 int process(const std::vector<const char *> &args);
43
45 std::vector<const char *> compilerArgs;
46
48 std::vector<const char *> *process(int argc, char *const argv[]) override;
49
50 protected:
51 // Self-assignments and copy constructor can only be used by other options.
52 AbstractP4cToolOptions &operator=(const AbstractP4cToolOptions &) = default;
53 AbstractP4cToolOptions(const AbstractP4cToolOptions &) = default;
54 AbstractP4cToolOptions(AbstractP4cToolOptions &&) = default;
55
56 [[nodiscard]] bool validateOptions() const override;
57
59 [[nodiscard]] const std::string &getToolName() const;
60
62 std::vector<char *> convertArgs(const std::vector<const char *> &args);
63
64 explicit AbstractP4cToolOptions(std::string_view toolName, std::string_view message);
65};
66
67} // namespace P4::P4Tools
68
69#endif /* BACKENDS_P4TOOLS_COMMON_OPTIONS_H_ */
const std::string & getToolName() const
The name of the tool associated with these options.
Definition backends/p4tools/common/options.cpp:97
bool validateOptions() const override
Definition backends/p4tools/common/options.cpp:95
std::optional< uint32_t > seed
A seed for the PRNG.
Definition backends/p4tools/common/options.h:34
std::vector< const char * > compilerArgs
Command-line arguments to be sent to the compiler. Populated by @process.
Definition backends/p4tools/common/options.h:45
std::vector< char * > convertArgs(const std::vector< const char * > &args)
Converts a vector of command-line arguments into the traditional (argc, argv) format.
Definition backends/p4tools/common/options.cpp:26
int process(const std::vector< const char * > &args)
Definition backends/p4tools/common/options.cpp:36
bool disableInformationLogging
Disable information logging.
Definition backends/p4tools/common/options.h:37
Definition common/compiler/compiler_result.cpp:7