1 /**************************************************************************
3 * Copyright 2010 VMware, Inc.
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:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
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
24 **************************************************************************/
27 * Object hierarchy for describing the traces in memory.
30 #ifndef _TRACE_MODEL_HPP_
31 #define _TRACE_MODEL_HPP_
51 const char **arg_names;
59 const char **member_names;
66 signed long long value;
72 unsigned long long value;
79 const BitmaskFlag *flags;
90 virtual void visit(Visitor &visitor) = 0;
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;
98 virtual void *toPointer(void) const;
99 virtual unsigned long long toUIntPtr(void) const;
100 virtual const char *toString(void) const;
102 const Value & operator[](size_t index) const;
106 class Null : public Value
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);
121 class Bool : public Value
124 Bool(bool _value) : value(_value) {}
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);
137 class SInt : public Value
140 SInt(signed long long _value) : value(_value) {}
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);
149 signed long long value;
153 class UInt : public Value
156 UInt(unsigned long long _value) : value(_value) {}
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);
165 unsigned long long value;
169 class Float : public Value
172 Float(double _value) : value(_value) {}
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);
185 class String : public Value
188 String(const char * _value) : value(_value) {}
190 bool toBool(void) const;
191 const char *toString(void) const;
192 void visit(Visitor &visitor);
198 class Enum : public Value
201 Enum(const EnumSig *_sig) : sig(_sig) {}
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);
214 class Bitmask : public UInt
217 Bitmask(const BitmaskSig *_sig, unsigned long long _value) : UInt(_value), sig(_sig) {}
219 void visit(Visitor &visitor);
221 const BitmaskSig *sig;
225 class Struct : public Value
228 Struct(StructSig *_sig) : sig(_sig), members(_sig->num_members) { }
231 bool toBool(void) const;
232 void visit(Visitor &visitor);
234 const StructSig *sig;
235 std::vector<Value *> members;
239 class Array : public Value
242 Array(size_t len) : values(len) {}
245 bool toBool(void) const;
246 void visit(Visitor &visitor);
248 std::vector<Value *> values;
252 class Blob : public Value
257 buf = new char[_size];
262 bool toBool(void) const;
263 void *toPointer(void) const;
264 void visit(Visitor &visitor);
271 class Pointer : public UInt
274 Pointer(unsigned long long value) : UInt(value) {}
276 bool toBool(void) const;
277 void *toPointer(void) const;
278 unsigned long long toUIntPtr(void) const;
279 void visit(Visitor &visitor);
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 *);
300 inline void _visit(Value *value) {
308 std::ostream & operator <<(std::ostream &os, Value *value);
315 const FunctionSig *sig;
316 std::vector<Value *> args;
319 Call(FunctionSig *_sig) : sig(_sig), args(_sig->num_args), ret(0) { }
322 inline const char * name(void) const {
326 inline Value & arg(unsigned index) {
327 assert(index < args.size());
328 return *(args[index]);
333 std::ostream & operator <<(std::ostream &os, Call &call);
336 } /* namespace Trace */
338 #endif /* _TRACE_MODEL_HPP_ */