1 : // Copyright 2012 Google Inc. All Rights Reserved.
2 : //
3 : // Licensed under the Apache License, Version 2.0 (the "License");
4 : // you may not use this file except in compliance with the License.
5 : // You may obtain a copy of the License at
6 : //
7 : // http://www.apache.org/licenses/LICENSE-2.0
8 : //
9 : // Unless required by applicable law or agreed to in writing, software
10 : // distributed under the License is distributed on an "AS IS" BASIS,
11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 : // See the License for the specific language governing permissions and
13 : // limitations under the License.
14 : //
15 : // Declares a partial BlockGraphTransformInterface implementation that provides
16 : // an implementation for the 'name' member function. Declares a similar
17 : // implementation of a BasicBlockSubGraphTransformInterface. Both
18 : // implementations refer to the same static variable so that a transform need
19 : // only be named once, and be an implementation of both transform types.
20 :
21 : #ifndef SYZYGY_BLOCK_GRAPH_TRANSFORMS_NAMED_TRANSFORM_H_
22 : #define SYZYGY_BLOCK_GRAPH_TRANSFORMS_NAMED_TRANSFORM_H_
23 :
24 : #include "syzygy/block_graph/transform.h"
25 :
26 : namespace block_graph {
27 : namespace transforms {
28 :
29 : // Implements the 'name' member function of BlockGraphTransformInterface.
30 : // The user must define the static variable:
31 : //
32 : // const char DerivedType::kTransformName[];
33 : //
34 : // @tparam DerivedType the type of the derived class.
35 : template<class DerivedType>
36 : class NamedBlockGraphTransformImpl : public BlockGraphTransformInterface {
37 : public:
38 : // Gets the name of this transform.
39 : //
40 : // @returns the name of this transform.
41 E : virtual const char* name() const override {
42 E : return DerivedType::kTransformName;
43 E : }
44 : };
45 :
46 : // Implements the 'name' member function of BasicBlockGraphTransformInterface.
47 : // The user must define the static variable:
48 : //
49 : // const char DerivedType::kTransformName[];
50 : //
51 : // @tparam DerivedType the type of the derived class.
52 : template<class DerivedType>
53 : class NamedBasicBlockSubGraphTransformImpl
54 : : public BasicBlockSubGraphTransformInterface {
55 : public:
56 : // Gets the name of this transform.
57 : //
58 : // @returns the name of this transform.
59 E : virtual const char* name() const override {
60 E : return DerivedType::kTransformName;
61 E : }
62 : };
63 :
64 : } // namespace transforms
65 : } // namespace block_graph
66 :
67 : #endif // SYZYGY_BLOCK_GRAPH_TRANSFORMS_NAMED_TRANSFORM_H_
|