P4C
The P4 Compiler
Loading...
Searching...
No Matches
frontends/p4/frontend.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#ifndef P4_FRONTEND_H_
18#define P4_FRONTEND_H_
19
20#include "../common/options.h"
21#include "ir/ir.h"
22#include "parseAnnotations.h"
23#include "unusedDeclarations.h"
24
25namespace P4 {
26
27class ConstantFoldingPolicy; // forward declare to avoid having to include
28
33 public:
34 virtual ~FrontEndPolicy() = default;
35
39 virtual std::vector<DebugHook> getDebugHooks() const { return {}; }
40
44 virtual ParseAnnotations *getParseAnnotations() const { return nullptr; }
45
48 // TODO: This should probably not be allowed to be skipped at all.
49 virtual bool skipSideEffectOrdering() const { return false; }
50
53 virtual bool enableSubConstToAddTransform() const { return true; }
54
59 virtual bool optimize(const CompilerOptions &options) const {
60 return options.optimizationLevel > 0;
61 }
62
66 virtual ConstantFoldingPolicy *getConstantFoldingPolicy() const { return nullptr; }
67};
68
69class FrontEnd {
70 FrontEndPolicy *policy;
71 std::vector<DebugHook> hooks;
72
73 public:
74 FrontEnd() : FrontEnd(new FrontEndPolicy()) {}
75 explicit FrontEnd(FrontEndPolicy *policy) : policy(policy), hooks(policy->getDebugHooks()) {}
76
77 void addDebugHook(const DebugHook &hook) { hooks.push_back(hook); }
78 // If p4c is run with option '--listFrontendPasses', outStream is used for printing passes names
79 const IR::P4Program *run(const CompilerOptions &options, const IR::P4Program *program,
80 std::ostream *outStream = nullptr);
81};
82
83} // namespace P4
84
85#endif /* P4_FRONTEND_H_ */
Definition frontends/common/options.h:30
Definition constantFolding.h:35
Definition frontends/p4/frontend.h:69
Definition frontends/p4/frontend.h:32
virtual ConstantFoldingPolicy * getConstantFoldingPolicy() const
Definition frontends/p4/frontend.h:66
virtual bool skipSideEffectOrdering() const
Definition frontends/p4/frontend.h:49
virtual std::vector< DebugHook > getDebugHooks() const
Definition frontends/p4/frontend.h:39
virtual ParseAnnotations * getParseAnnotations() const
Definition frontends/p4/frontend.h:44
virtual bool enableSubConstToAddTransform() const
Definition frontends/p4/frontend.h:53
virtual bool optimize(const CompilerOptions &options) const
Definition frontends/p4/frontend.h:59
Definition parseAnnotations.h:138
Definition unusedDeclarations.h:48
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24
std::function< void(const char *manager, unsigned seqNo, const char *pass, const IR::Node *node)> DebugHook
Definition ir/pass_manager.h:38