P4C
The P4 Compiler
Loading...
Searching...
No Matches
removeOpAssign.h
1/*
2 * Copyright 2025 Nvidia, Inc.
3 * SPDX-FileCopyrightText: 2025 Nvidia, Inc.
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 */
7
8#ifndef FRONTENDS_P4_REMOVEOPASSIGN_H_
9#define FRONTENDS_P4_REMOVEOPASSIGN_H_
10
11#include "cloner.h"
12#include "ir/ir.h"
13#include "sideEffects.h"
14
15namespace P4 {
16
17class RemoveOpAssign : public Transform {
18 template <class T>
19 const IR::Node *doit(T *as) {
20 prune();
21 BUG_CHECK(!SideEffects::check(as->left, this), "side effects in LHS of %s", as);
22 return new IR::AssignmentStatement(as->srcInfo, as->left->apply(CloneExpressions()),
23 new typename T::BinOp(as->left, as->right));
24 }
25
26#define PREORDER(OP) \
27 const IR::Node *preorder(IR::OP *as) override { return doit(as); }
28 PREORDER(MulAssign)
29 PREORDER(DivAssign)
30 PREORDER(ModAssign)
31 PREORDER(AddAssign)
32 PREORDER(SubAssign)
33 PREORDER(AddSatAssign)
34 PREORDER(SubSatAssign)
35 PREORDER(ShlAssign)
36 PREORDER(ShrAssign)
37 PREORDER(BAndAssign)
38 PREORDER(BOrAssign)
39 PREORDER(BXorAssign)
40#undef PREORDER
41
42 const IR::Node *preorder(IR::AssignmentStatement *s) override {
43 prune();
44 return s;
45 }
46 const IR::Node *preorder(IR::Expression *e) override {
47 prune();
48 return e;
49 }
50 const IR::Node *preorder(IR::Annotation *a) override {
51 prune();
52 return a;
53 }
54};
55
56} // namespace P4
57
58#endif /* FRONTENDS_P4_REMOVEOPASSIGN_H_ */
Definition cloner.h:26
Definition node.h:53
Definition removeOpAssign.h:17
static bool check(const IR::Expression *expression, const Visitor *calledBy, TypeMap *typeMap=nullptr, const Visitor::Context *ctxt=nullptr)
Definition sideEffects.h:81
Definition visitor.h:442
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:13