P4C
The P4 Compiler
Loading...
Searching...
No Matches
p4ctool.h
1
#ifndef BACKENDS_P4TOOLS_COMMON_P4CTOOL_H_
2
#define BACKENDS_P4TOOLS_COMMON_P4CTOOL_H_
3
4
#include <cstdlib>
5
#include <type_traits>
6
#include <vector>
7
8
#include "backends/p4tools/common/compiler/compiler_target.h"
9
#include "backends/p4tools/common/lib/logging.h"
10
#include "backends/p4tools/common/options.h"
11
12
namespace
P4Tools
{
13
16
//
17
// Because of limitations of templates, method implementations must be inlined here.
18
template
<
class
Options,
19
typename
= std::enable_if_t<std::is_base_of_v<AbstractP4cToolOptions, Options>>>
20
class
AbstractP4cTool
{
21
protected
:
25
virtual
int
mainImpl
(
const
CompilerResult
&compilerResult) = 0;
26
27
virtual
void
registerTarget() = 0;
28
29
public
:
33
int
main
(
const
std::vector<const char *> &args) {
34
// Register supported compiler targets.
35
registerTarget();
36
37
// Process command-line options.
38
auto
&toolOptions = Options::get();
39
auto
compileContext = toolOptions.process(args);
40
if
(!compileContext) {
41
return
1;
42
}
43
44
// Set up the compilation context.
45
AutoCompileContext
autoContext(*compileContext);
46
47
// If not explicitly disabled, print basic information to standard output.
48
if
(!toolOptions.disableInformationLogging) {
49
enableInformationLogging
();
50
}
51
52
// Print the seed if it has been set.
53
if
(toolOptions.seed) {
54
printInfo
(
"============ Program seed %1% =============\n"
, *toolOptions.seed);
55
}
56
57
// Run the compiler to get an IR and invoke the tool.
58
const
auto
compilerResult =
P4Tools::CompilerTarget::runCompiler
();
59
if
(!compilerResult.has_value()) {
60
return
EXIT_FAILURE;
61
}
62
return
mainImpl
(compilerResult.value());
63
}
64
};
65
66
}
// namespace P4Tools
67
68
#endif
/* BACKENDS_P4TOOLS_COMMON_P4CTOOL_H_ */
P4Tools::AbstractP4cTool
Definition
p4ctool.h:20
P4Tools::AbstractP4cTool::main
int main(const std::vector< const char * > &args)
Definition
p4ctool.h:33
P4Tools::AbstractP4cTool::mainImpl
virtual int mainImpl(const CompilerResult &compilerResult)=0
P4Tools::CompilerResult
Definition
compiler_target.h:21
P4Tools::CompilerTarget::runCompiler
static CompilerResultOrError runCompiler()
Definition
compiler_target.cpp:31
P4Tools
Definition
compiler_target.cpp:19
P4Tools::printInfo
void printInfo(const std::string &fmt, Arguments &&...args)
Definition
logging.h:15
P4Tools::enableInformationLogging
void enableInformationLogging()
Enable the printing of basic run information.
Definition
logging.cpp:11
AutoCompileContext
Definition
compile_context.h:75
backends
p4tools
common
p4ctool.h
Generated on Tue Mar 26 2024 for