P4C
The P4 Compiler
Loading...
Searching...
No Matches
ir-tree-macros.h
1/*
2 * SPDX-FileCopyrightText: 2013 Barefoot Networks, Inc.
3 * Copyright 2013-present Barefoot Networks, Inc.
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 */
7
8#ifndef IR_IR_TREE_MACROS_H_
9#define IR_IR_TREE_MACROS_H_
10
11/* macro table listing ALL IR subclasses of Node and all their direct and indirect bases
12 * whenever a new IR Node subclass is added, it MUST be added to this table. Target
13 * specific subclasses might be broken out into a separate table and included here
14 * Because we want to be able to forward-declare all these types, the class type MUST
15 * be a simple identifier that will be declared in namespace P4::IR. Aliases can be defined
16 * in other namespaces if desired.
17 * When there's a templated subclass of Node, all of its instantiations need to appear in this
18 * table, and it also needs to be in the IRNODE_ALL_TEMPLATES_AND_DIRECT_AND_INDIRECT_BASES
19 * table below */
20#include "ir/gen-tree-macro.h"
21// clang-format off
22#define IRNODE_ALL_TEMPLATES_AND_DIRECT_AND_INDIRECT_BASES(M, D, B, TDA, ...) \
23 M(Vector, D(Node), template <class T>, <T>, ##__VA_ARGS__) \
24 M(IndexedVector, D(Vector<T>) B(Node), template <class T>, <T>, ##__VA_ARGS__) \
25 M(NameMap, D(Node), \
26 IR_TREE_COPY( \
27 template <class T, template <class, class, class, class> class MAP TDA(= std::map), \
28 class COMP TDA(= std::less<cstring>), \
29 class ALLOC TDA(= std::allocator<std::pair<cstring, const T*>>)>), \
30 IR_TREE_COPY(<T, MAP, COMP, ALLOC>), ##__VA_ARGS__)
31// clang-format on
32
33#define IR_TREE_COPY(...) __VA_ARGS__
34#define IR_TREE_IGNORE(...)
35
36/* all IR classes, including Node */
37#define IRNODE_ALL_CLASSES_AND_BASES(M, B, ...) \
38 M(Node, , ##__VA_ARGS__) \
39 IRNODE_ALL_SUBCLASSES_AND_DIRECT_AND_INDIRECT_BASES(M, M, B, B, ##__VA_ARGS__)
40
41#define IRNODE_ALL_NON_TEMPLATE_CLASSES_AND_BASES(M, B, ...) \
42 M(Node, , ##__VA_ARGS__) \
43 IRNODE_ALL_SUBCLASSES_AND_DIRECT_AND_INDIRECT_BASES(M, IR_TREE_IGNORE, B, B, ##__VA_ARGS__)
44
45/* all the subclasses with just the immediate bases */
46#define IRNODE_ALL_SUBCLASSES(M, ...) \
47 IRNODE_ALL_SUBCLASSES_AND_DIRECT_AND_INDIRECT_BASES(M, M, IR_TREE_COPY, IR_TREE_IGNORE, \
48 ##__VA_ARGS__)
49#define IRNODE_ALL_NON_TEMPLATE_SUBCLASSES(M, ...) \
50 IRNODE_ALL_SUBCLASSES_AND_DIRECT_AND_INDIRECT_BASES(M, IR_TREE_IGNORE, IR_TREE_COPY, \
51 IR_TREE_IGNORE, ##__VA_ARGS__)
52#define IRNODE_ALL_TEMPLATES_AND_BASES(M, ...) \
53 IRNODE_ALL_TEMPLATES_AND_DIRECT_AND_INDIRECT_BASES(M, IR_TREE_COPY, IR_TREE_IGNORE, \
54 IR_TREE_IGNORE, ##__VA_ARGS__)
55
56/* all classes with no bases */
57#define REMOVE_BASES_ARG(CLASS, BASES, M, ...) M(IR_TREE_COPY(CLASS), ##__VA_ARGS__)
58#define IRNODE_ALL_CLASSES(M, ...) \
59 IRNODE_ALL_CLASSES_AND_BASES(REMOVE_BASES_ARG, IR_TREE_IGNORE, M, ##__VA_ARGS__)
60#define IRNODE_ALL_NON_TEMPLATE_CLASSES(M, ...) \
61 IRNODE_ALL_NON_TEMPLATE_CLASSES_AND_BASES(REMOVE_BASES_ARG, IR_TREE_IGNORE, M, ##__VA_ARGS__)
62
63#define REMOVE_TEMPLATE_BASES_ARG(CLASS, BASES, TEMPLATE, TARGS, M, ...) \
64 M(IR_TREE_COPY(CLASS), IR_TREE_COPY(TEMPLATE), IR_TREE_COPY(TARGS), ##__VA_ARGS__)
65#define IRNODE_ALL_TEMPLATES(M, ...) \
66 IRNODE_ALL_TEMPLATES_AND_DIRECT_AND_INDIRECT_BASES(REMOVE_TEMPLATE_BASES_ARG, IR_TREE_IGNORE, \
67 IR_TREE_IGNORE, IR_TREE_IGNORE, M, \
68 ##__VA_ARGS__)
69#define IRNODE_ALL_TEMPLATES_WITH_DEFAULTS(M, ...) \
70 IRNODE_ALL_TEMPLATES_AND_DIRECT_AND_INDIRECT_BASES( \
71 REMOVE_TEMPLATE_BASES_ARG, IR_TREE_IGNORE, IR_TREE_IGNORE, IR_TREE_COPY, M, ##__VA_ARGS__)
72
73#endif /* IR_IR_TREE_MACROS_H_ */