P4C
The P4 Compiler
Loading...
Searching...
No Matches
p4tools/modules/smith/targets/generic/target.h
1/*
2 * SPDX-FileCopyrightText: 2024 The P4 Language Consortium
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#ifndef BACKENDS_P4TOOLS_MODULES_SMITH_TARGETS_GENERIC_TARGET_H_
8#define BACKENDS_P4TOOLS_MODULES_SMITH_TARGETS_GENERIC_TARGET_H_
9
10#include <ostream>
11#include <string>
12
13#include "backends/p4tools/modules/smith/common/declarations.h"
14#include "backends/p4tools/modules/smith/common/expressions.h"
15#include "backends/p4tools/modules/smith/common/parser.h"
16#include "backends/p4tools/modules/smith/common/statements.h"
17#include "backends/p4tools/modules/smith/common/table.h"
18#include "backends/p4tools/modules/smith/core/target.h"
19#include "ir/ir.h"
20
21namespace P4::P4Tools::P4Smith::Generic {
22
23class AbstractGenericSmithTarget : public SmithTarget {
24 protected:
25 explicit AbstractGenericSmithTarget(const std::string &deviceName, const std::string &archName);
26};
27
28class GenericCoreSmithTarget : public AbstractGenericSmithTarget {
29 private:
30 DeclarationGenerator *_declarationGenerator = new DeclarationGenerator(*this);
31 ExpressionGenerator *_expressionGenerator = new ExpressionGenerator(*this);
32 StatementGenerator *_statementGenerator = new StatementGenerator(*this);
33 ParserGenerator *_parserGenerator = new ParserGenerator(*this);
34 TableGenerator *_tableGenerator = new TableGenerator(*this);
35
36 [[nodiscard]] IR::P4Parser *generateParserBlock() const;
37 [[nodiscard]] IR::P4Control *generateIngressBlock() const;
38 [[nodiscard]] static IR::Declaration_Instance *generateMainPackage();
39
40 [[nodiscard]] IR::Type_Parser *generateParserBlockType() const;
41 [[nodiscard]] IR::Type_Control *generateIngressBlockType() const;
42 [[nodiscard]] IR::Type_Package *generatePackageType() const;
43
44 public:
46 static void make();
47
48 // Retrieve the singleton instance for the current target.
49 [[nodiscard]] static GenericCoreSmithTarget *getInstance();
50
51 [[nodiscard]] int writeTargetPreamble(std::ostream *ostream) const override;
52
53 [[nodiscard]] const IR::P4Program *generateP4Program() const override;
54
55 [[nodiscard]] DeclarationGenerator &declarationGenerator() const override {
56 return *_declarationGenerator;
57 }
58
59 [[nodiscard]] ExpressionGenerator &expressionGenerator() const override {
60 return *_expressionGenerator;
61 }
62
63 [[nodiscard]] StatementGenerator &statementGenerator() const override {
64 return *_statementGenerator;
65 }
66
67 [[nodiscard]] ParserGenerator &parserGenerator() const override { return *_parserGenerator; }
68
69 [[nodiscard]] TableGenerator &tableGenerator() const override { return *_tableGenerator; }
70
71 private:
72 GenericCoreSmithTarget();
73};
74
75} // namespace P4::P4Tools::P4Smith::Generic
76
77#endif /* BACKENDS_P4TOOLS_MODULES_SMITH_TARGETS_GENERIC_TARGET_H_ */
Definition declarations.h:19
Definition common/expressions.h:54
int writeTargetPreamble(std::ostream *ostream) const override
Definition p4tools/modules/smith/targets/generic/target.cpp:175
static void make()
Registers this target.
Definition p4tools/modules/smith/targets/generic/target.cpp:44
Definition p4tools/modules/smith/common/parser.h:18