]> git.cworth.org Git - apitrace/blob - trace_model.hpp
Add a state tab that list uniforms.
[apitrace] / trace_model.hpp
1 /**************************************************************************
2  *
3  * Copyright 2010 VMware, Inc.
4  * All Rights Reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  *
24  **************************************************************************/
25
26 /*
27  * Object hierarchy for describing the traces in memory.
28  */
29
30 #ifndef _TRACE_MODEL_HPP_
31 #define _TRACE_MODEL_HPP_
32
33
34 #include <assert.h>
35
36 #include <map>
37 #include <vector>
38 #include <iostream>
39
40
41 namespace Trace {
42
43
44 typedef unsigned Id;
45
46
47 struct FunctionSig {
48     Id id;
49     const char *name;
50     unsigned num_args;
51     const char **arg_names;
52 };
53
54
55 struct StructSig {
56     Id id;
57     const char *name;
58     unsigned num_members;
59     const char **member_names;
60 };
61
62
63 struct EnumSig {
64     Id id;
65     const char *name;
66     signed long long value;
67 };
68
69
70 struct BitmaskFlag {
71     const char *name;
72     unsigned long long value;
73 };
74
75
76 struct BitmaskSig {
77     Id id;
78     unsigned num_flags;
79     const BitmaskFlag *flags;
80 };
81
82
83 class Visitor;
84
85
86 class Value
87 {
88 public:
89     virtual ~Value() {}
90     virtual void visit(Visitor &visitor) = 0;
91
92     virtual bool toBool(void) const = 0;
93     virtual signed long long toSInt(void) const;
94     virtual unsigned long long toUInt(void) const;
95     virtual float toFloat(void) const;
96     virtual double toDouble(void) const;
97
98     virtual void *toPointer(void) const;
99     virtual unsigned long long toUIntPtr(void) const;
100     virtual const char *toString(void) const;
101
102     const Value & operator[](size_t index) const;
103 };
104
105
106 class Null : public Value
107 {
108 public:
109     bool toBool(void) const;
110     signed long long toSInt(void) const;
111     unsigned long long toUInt(void) const;
112     virtual float toFloat(void) const;
113     virtual double toDouble(void) const;
114     void *toPointer(void) const;
115     unsigned long long toUIntPtr(void) const;
116     const char *toString(void) const;
117     void visit(Visitor &visitor);
118 };
119
120
121 class Bool : public Value
122 {
123 public:
124     Bool(bool _value) : value(_value) {}
125
126     bool toBool(void) const;
127     signed long long toSInt(void) const;
128     unsigned long long toUInt(void) const;
129     virtual float toFloat(void) const;
130     virtual double toDouble(void) const;
131     void visit(Visitor &visitor);
132
133     bool value;
134 };
135
136
137 class SInt : public Value
138 {
139 public:
140     SInt(signed long long _value) : value(_value) {}
141
142     bool toBool(void) const;
143     signed long long toSInt(void) const;
144     unsigned long long toUInt(void) const;
145     virtual float toFloat(void) const;
146     virtual double toDouble(void) const;
147     void visit(Visitor &visitor);
148
149     signed long long value;
150 };
151
152
153 class UInt : public Value
154 {
155 public:
156     UInt(unsigned long long _value) : value(_value) {}
157
158     bool toBool(void) const;
159     signed long long toSInt(void) const;
160     unsigned long long toUInt(void) const;
161     virtual float toFloat(void) const;
162     virtual double toDouble(void) const;
163     void visit(Visitor &visitor);
164
165     unsigned long long value;
166 };
167
168
169 class Float : public Value
170 {
171 public:
172     Float(double _value) : value(_value) {}
173
174     bool toBool(void) const;
175     signed long long toSInt(void) const;
176     unsigned long long toUInt(void) const;
177     virtual float toFloat(void) const;
178     virtual double toDouble(void) const;
179     void visit(Visitor &visitor);
180
181     double value;
182 };
183
184
185 class String : public Value
186 {
187 public:
188     String(const char * _value) : value(_value) {}
189
190     bool toBool(void) const;
191     const char *toString(void) const;
192     void visit(Visitor &visitor);
193
194     const char * value;
195 };
196
197
198 class Enum : public Value
199 {
200 public:
201     Enum(const EnumSig *_sig) : sig(_sig) {}
202
203     bool toBool(void) const;
204     signed long long toSInt(void) const;
205     unsigned long long toUInt(void) const;
206     virtual float toFloat(void) const;
207     virtual double toDouble(void) const;
208     void visit(Visitor &visitor);
209
210     const EnumSig *sig;
211 };
212
213
214 class Bitmask : public UInt
215 {
216 public:
217     Bitmask(const BitmaskSig *_sig, unsigned long long _value) : UInt(_value), sig(_sig) {}
218
219     void visit(Visitor &visitor);
220
221     const BitmaskSig *sig;
222 };
223
224
225 class Struct : public Value
226 {
227 public:
228     Struct(StructSig *_sig) : sig(_sig), members(_sig->num_members) { }
229     ~Struct();
230
231     bool toBool(void) const;
232     void visit(Visitor &visitor);
233
234     const StructSig *sig;
235     std::vector<Value *> members;
236 };
237
238
239 class Array : public Value
240 {
241 public:
242     Array(size_t len) : values(len) {}
243     ~Array();
244
245     bool toBool(void) const;
246     void visit(Visitor &visitor);
247
248     std::vector<Value *> values;
249 };
250
251
252 class Blob : public Value
253 {
254 public:
255     Blob(size_t _size) {
256         size = _size;
257         buf = new char[_size];
258     }
259
260     ~Blob();
261
262     bool toBool(void) const;
263     void *toPointer(void) const;
264     void visit(Visitor &visitor);
265
266     size_t size;
267     char *buf;
268 };
269
270
271 class Pointer : public UInt
272 {
273 public:
274     Pointer(unsigned long long value) : UInt(value) {}
275
276     bool toBool(void) const;
277     void *toPointer(void) const;
278     unsigned long long toUIntPtr(void) const;
279     void visit(Visitor &visitor);
280 };
281
282
283 class Visitor
284 {
285 public:
286     virtual void visit(Null *);
287     virtual void visit(Bool *);
288     virtual void visit(SInt *);
289     virtual void visit(UInt *);
290     virtual void visit(Float *);
291     virtual void visit(String *);
292     virtual void visit(Enum *);
293     virtual void visit(Bitmask *);
294     virtual void visit(Struct *);
295     virtual void visit(Array *);
296     virtual void visit(Blob *);
297     virtual void visit(Pointer *);
298
299 protected:
300     inline void _visit(Value *value) {
301         if (value) { 
302             value->visit(*this); 
303         }
304     }
305 };
306
307
308 std::ostream & operator <<(std::ostream &os, Value *value);
309
310
311 class Call
312 {
313 public:
314     unsigned no;
315     const FunctionSig *sig;
316     std::vector<Value *> args;
317     Value *ret;
318
319     Call(FunctionSig *_sig) : sig(_sig), args(_sig->num_args), ret(0) { }
320     ~Call();
321
322     inline const char * name(void) const {
323         return sig->name;
324     }
325
326     inline Value & arg(unsigned index) {
327         assert(index < args.size());
328         return *(args[index]);
329     }
330 };
331
332
333 std::ostream & operator <<(std::ostream &os, Call &call);
334
335
336 } /* namespace Trace */
337
338 #endif /* _TRACE_MODEL_HPP_ */