summaryrefslogtreecommitdiffstats
path: root/src/usr/diag/prdf/common/framework/rule/prdfPluginDef.H
blob: 54d4a91bae396e19c6fb97d15edc8861241ce36e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/diag/prdf/common/framework/rule/prdfPluginDef.H $     */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 2004,2014              */
/*                                                                        */
/* Licensed under the Apache License, Version 2.0 (the "License");        */
/* you may not use this file except in compliance with the License.       */
/* You may obtain a copy of the License at                                */
/*                                                                        */
/*     http://www.apache.org/licenses/LICENSE-2.0                         */
/*                                                                        */
/* Unless required by applicable law or agreed to in writing, software    */
/* distributed under the License is distributed on an "AS IS" BASIS,      */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or        */
/* implied. See the License for the specific language governing           */
/* permissions and limitations under the License.                         */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */

#ifndef __PRDFPLUGINDEF_H
#define __PRDFPLUGINDEF_H

#include <stdint.h>

#ifdef __HOSTBOOT_MODULE
  #include <stdlib.h>
#else
  #include <cstdlib>
#endif

namespace PRDF
{

namespace PluginDef
{
    class ParameterList
    {
    };

    template <typename _A>
        class SingleParameter : public ParameterList
        {
            private:
                _A cv_value;

            public:
                SingleParameter(_A v) : cv_value(v) {};
                operator _A() { return cv_value; };
        };

    template <typename _A>
    inline SingleParameter<_A> *
        bindParm(_A v) { return new SingleParameter<_A>(v); };

    template <typename _A, typename _B>
        class TwoParameter : public ParameterList
        {
            private:
                _A cv_valueA;
                _B cv_valueB;

            public:
                TwoParameter(_A vA, _B vB) : cv_valueA(vA), cv_valueB(vB) {};
                _A getA() { return cv_valueA; };
                _B getB() { return cv_valueB; };
        };

    template <typename _A, typename _B>
    inline TwoParameter<_A, _B> *
        bindParm(_A vA, _B vB) { return new TwoParameter<_A,_B>(vA,vB); };

    template <typename _A, typename _B, typename _C>
        class ThreeParameter : public ParameterList
        {
            private:
                _A cv_valueA;
                _B cv_valueB;
                _C cv_valueC;

            public:
                ThreeParameter(_A vA, _B vB, _C vC)
                    : cv_valueA(vA), cv_valueB(vB), cv_valueC(vC) {};
                _A getA() { return cv_valueA; };
                _B getB() { return cv_valueB; };
                _C getC() { return cv_valueC; };
        };

    template <typename _A, typename _B, typename _C>
    inline ThreeParameter<_A, _B, _C> *
        bindParm(_A vA, _B vB, _C vC)
            { return new ThreeParameter<_A,_B,_C>(vA,vB,vC); };

    template <typename _A, typename _B, typename _C, typename _D>
        class FourParameter : public ParameterList
        {
            private:
                _A cv_valueA;
                _B cv_valueB;
                _C cv_valueC;
                _D cv_valueD;

            public:
                FourParameter(_A vA, _B vB, _C vC, _D vD)
                    : cv_valueA(vA), cv_valueB(vB), cv_valueC(vC),
                      cv_valueD(vD)
                    {};
                _A getA() { return cv_valueA; };
                _B getB() { return cv_valueB; };
                _C getC() { return cv_valueC; };
                _D getD() { return cv_valueD; };
        };

    template <typename _A, typename _B, typename _C, typename _D>
    inline FourParameter<_A, _B, _C, _D> *
        bindParm(_A vA, _B vB, _C vC, _D vD)
            { return new FourParameter<_A,_B,_C,_D>(vA,vB,vC,vD); };


};

class ExtensibleFunctionType
{
    public:
        virtual ~ExtensibleFunctionType() {};
};

template <typename _ExtensibleObject>
class ExtensibleFunction : public ExtensibleFunctionType
{
    public:
        virtual ~ExtensibleFunction() { }  // zs01
        virtual int32_t operator()(_ExtensibleObject * A,
                                   PluginDef::ParameterList * B) = 0;
};

class ExtensibleChip;
class ExtensibleDomain;
typedef ExtensibleFunction<ExtensibleChip> ExtensibleChipFunction;
typedef ExtensibleFunction<ExtensibleDomain>
                                        ExtensibleDomainFunction;

template <typename _ExtensibleObject>
class Plugin : public ExtensibleFunction<_ExtensibleObject>
{
    protected:
        int32_t (*_func)(_ExtensibleObject *, PluginDef::ParameterList *);
    public:
        explicit Plugin(int32_t (*func)(_ExtensibleObject *,
                                            PluginDef::ParameterList *))
            : _func(func) {};

        int32_t operator()(_ExtensibleObject * A,
                           PluginDef::ParameterList * B)
        {
            int32_t i = 0;
            if (NULL != _func)
            {
                i = _func(A,B);
            }
            delete B;
            return i;
        };
};

template <typename _ExtensibleObject>
class Plugin_0arg : public ExtensibleFunction<_ExtensibleObject>
{
    protected:
        int32_t (*_func)(_ExtensibleObject *);
    public:
        explicit Plugin_0arg(int32_t (*func)(_ExtensibleObject *))
            : _func(func) {};

        int32_t operator()(_ExtensibleObject * A,
                           PluginDef::ParameterList * B)
        {
            int32_t i = _func(A);
            delete B;
            return i;
        };
};

template <typename _ExtensibleObject>
inline Plugin_0arg<_ExtensibleObject>
    bind_plugin(int32_t (*func)(_ExtensibleObject *))
        { return Plugin_0arg<_ExtensibleObject>(func); };

template <typename _ExtensibleObject>
inline Plugin_0arg<_ExtensibleObject> *
    bind_plugin_ptr(int32_t (*func)(_ExtensibleObject *), void * ptr)
        { return new (ptr) Plugin_0arg<_ExtensibleObject>(func); };

template <typename _A, typename _ExtensibleObject>
class Plugin_1arg : public ExtensibleFunction<_ExtensibleObject>
{
    protected:
        int32_t (*_func)(_ExtensibleObject *, _A);
    public:
        explicit Plugin_1arg(int32_t (*func)(_ExtensibleObject *, _A))
            : _func(func) {};

        int32_t operator()(_ExtensibleObject * A,
                           PluginDef::ParameterList * B)
        {
            int32_t i = _func(A,
                (_A)static_cast<PluginDef::SingleParameter<_A> &>(*B));
            delete B;
            return i;
        };
};

template <typename _A, typename _ExtensibleObject>
inline Plugin_1arg<_A, _ExtensibleObject>
    bind_plugin(int32_t (*func)(_ExtensibleObject *, _A))
        { return Plugin_1arg<_A, _ExtensibleObject>(func); };

template <typename _A, typename _ExtensibleObject>
inline Plugin_1arg<_A, _ExtensibleObject> *
    bind_plugin_ptr(int32_t (*func)(_ExtensibleObject *, _A), void * ptr)
        { return new (ptr) Plugin_1arg<_A, _ExtensibleObject>(func); };


template <typename _A, typename _B, typename _ExtensibleObject>
class Plugin_2arg : public ExtensibleFunction<_ExtensibleObject>
{
    protected:
        int32_t (*_func)(_ExtensibleObject *, _A, _B);
    public:
        explicit Plugin_2arg(int32_t (*func)(_ExtensibleObject *, _A, _B))
            : _func(func) {};

        int32_t operator()(_ExtensibleObject * A,
                           PluginDef::ParameterList * B)
        {
            int32_t i = _func(A,
                static_cast<PluginDef::TwoParameter<_A,_B> *>(B)->getA(),
                static_cast<PluginDef::TwoParameter<_A,_B> *>(B)->getB());
            delete B;
            return i;
        };
};

template <typename _A, typename _B, typename _ExtensibleObject>
inline Plugin_2arg<_A, _B, _ExtensibleObject>
    bind_plugin(int32_t (*func)(_ExtensibleObject *, _A, _B))
        { return Plugin_2arg<_A, _B, _ExtensibleObject>(func); };

template <typename _A, typename _B, typename _ExtensibleObject>
inline Plugin_2arg<_A, _B, _ExtensibleObject> *
    bind_plugin_ptr(int32_t (*func)(_ExtensibleObject *, _A, _B), void * ptr)
        { return new (ptr) Plugin_2arg<_A, _B, _ExtensibleObject>(func); };


template <typename _A, typename _B, typename _C, typename _ExtensibleObject>
class Plugin_3arg : public ExtensibleFunction<_ExtensibleObject>
{
    protected:
        int32_t (*_func)(_ExtensibleObject *, _A, _B, _C);
    public:
        explicit Plugin_3arg(int32_t (*func)
                    (_ExtensibleObject *, _A, _B, _C))
            : _func(func) {};

        int32_t operator()(_ExtensibleObject * A,
                           PluginDef::ParameterList * B)
        {
            int32_t i = _func(A,
                static_cast<PluginDef::ThreeParameter<_A,_B,_C> *>
                        (B)->getA(),
                static_cast<PluginDef::ThreeParameter<_A,_B,_C> *>
                        (B)->getB(),
                static_cast<PluginDef::ThreeParameter<_A,_B,_C> *>
                        (B)->getC()
                    );
            delete B;
            return i;
        };
};

template <typename _A, typename _B, typename _C, typename _ExtensibleObject>
inline Plugin_3arg<_A, _B, _C, _ExtensibleObject>
    bind_plugin(int32_t (*func)(_ExtensibleObject *, _A, _B, _C))
        { return Plugin_3arg<_A, _B, _C, _ExtensibleObject>(func); };

template <typename _A, typename _B, typename _C, typename _ExtensibleObject>
inline Plugin_3arg<_A, _B, _C, _ExtensibleObject> *
    bind_plugin_ptr(int32_t (*func)(_ExtensibleObject *, _A, _B, _C),
                    void * ptr)
        { return new (ptr)
                Plugin_3arg<_A, _B, _C, _ExtensibleObject>(func); };

template <typename _A, typename _B, typename _C, typename _D,
          typename _ExtensibleObject>
class Plugin_4arg : public ExtensibleFunction<_ExtensibleObject>
{
    protected:
        int32_t (*_func)(_ExtensibleObject *, _A, _B, _C, _D);
    public:
        explicit Plugin_4arg(int32_t (*func)
                    (_ExtensibleObject *, _A, _B, _C, _D))
            : _func(func) {};

        int32_t operator()(_ExtensibleObject * A,
                           PluginDef::ParameterList * B)
        {
            int32_t i = _func(A,
                static_cast<PluginDef::FourParameter<_A,_B,_C,_D> *>
                        (B)->getA(),
                static_cast<PluginDef::FourParameter<_A,_B,_C,_D> *>
                        (B)->getB(),
                static_cast<PluginDef::FourParameter<_A,_B,_C,_D> *>
                        (B)->getC(),
                static_cast<PluginDef::FourParameter<_A,_B,_C,_D> *>
                        (B)->getD()
                    );
            delete B;
            return i;
        };
};

template <typename _A, typename _B, typename _C, typename _D,
          typename _ExtensibleObject>
inline Plugin_4arg<_A, _B, _C, _D, _ExtensibleObject>
    bind_plugin(int32_t (*func)(_ExtensibleObject *, _A, _B, _C, _D))
        { return Plugin_4arg<_A, _B, _C, _D, _ExtensibleObject>(func); };

template <typename _A, typename _B, typename _C, typename _D,
          typename _ExtensibleObject>
inline Plugin_4arg<_A, _B, _C, _D, _ExtensibleObject> *
    bind_plugin_ptr(int32_t (*func)(_ExtensibleObject *, _A, _B, _C, _D),
                    void * ptr)
        { return new (ptr)
                Plugin_4arg<_A, _B, _C, _D, _ExtensibleObject>(func); };

} // end namespace PRDF

#define __PRDF_PLUGIN_XYZ(X,Y,Z) X##Y##Z
#define __PRDF_PLUGIN_MAKENAME(X,Y,Z) __PRDF_PLUGIN_XYZ(X,Y,Z)

#define PRDF_PLUGIN_DEFINE(CHIP,PLUGIN_NAME) \
    class __PRDF_PLUGIN_MAKENAME(Plugin_Registration_,CHIP,PLUGIN_NAME) \
    { \
      private: \
        ExtensibleFunctionType * cv_plugin; \
        PluginRegisterClass cv_registerClass; \
        char cv_plugin_space[sizeof(Plugin<ExtensibleChip>)]; \
      public: \
        __PRDF_PLUGIN_MAKENAME(Plugin_Registration_,CHIP,PLUGIN_NAME)() : \
            cv_plugin( bind_plugin_ptr(&CHIP::PLUGIN_NAME, \
                                       &cv_plugin_space) ), \
            cv_registerClass(#CHIP,#PLUGIN_NAME,cv_plugin) \
        {} \
    }; \
    __PRDF_PLUGIN_MAKENAME(Plugin_Registration_,CHIP,PLUGIN_NAME) \
        __PRDF_PLUGIN_MAKENAME(g_PluginRegistration_,CHIP,PLUGIN_NAME)
#endif

#include <prdfPluginMap.H>

OpenPOWER on IntegriCloud