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_
52 const char **arg_names;
60 const char **member_names;
67 signed long long value;
73 unsigned long long value;
80 const BitmaskFlag *flags;
91 virtual void visit(Visitor &visitor) = 0;
93 virtual bool toBool(void) const = 0;
94 virtual signed long long toSInt(void) const;
95 virtual unsigned long long toUInt(void) const;
96 virtual float toFloat(void) const;
97 virtual double toDouble(void) const;
99 virtual void *toPointer(void) const;
100 virtual unsigned long long toUIntPtr(void) const;
101 virtual const char *toString(void) const;
103 const Value & operator[](size_t index) const;
107 class Null : public Value
110 bool toBool(void) const;
111 signed long long toSInt(void) const;
112 unsigned long long toUInt(void) const;
113 virtual float toFloat(void) const;
114 virtual double toDouble(void) const;
115 void *toPointer(void) const;
116 unsigned long long toUIntPtr(void) const;
117 const char *toString(void) const;
118 void visit(Visitor &visitor);
122 class Bool : public Value
125 Bool(bool _value) : value(_value) {}
127 bool toBool(void) const;
128 signed long long toSInt(void) const;
129 unsigned long long toUInt(void) const;
130 virtual float toFloat(void) const;
131 virtual double toDouble(void) const;
132 void visit(Visitor &visitor);
138 class SInt : public Value
141 SInt(signed long long _value) : value(_value) {}
143 bool toBool(void) const;
144 signed long long toSInt(void) const;
145 unsigned long long toUInt(void) const;
146 virtual float toFloat(void) const;
147 virtual double toDouble(void) const;
148 void visit(Visitor &visitor);
150 signed long long value;
154 class UInt : public Value
157 UInt(unsigned long long _value) : value(_value) {}
159 bool toBool(void) const;
160 signed long long toSInt(void) const;
161 unsigned long long toUInt(void) const;
162 virtual float toFloat(void) const;
163 virtual double toDouble(void) const;
164 void visit(Visitor &visitor);
166 unsigned long long value;
170 class Float : public Value
173 Float(double _value) : value(_value) {}
175 bool toBool(void) const;
176 signed long long toSInt(void) const;
177 unsigned long long toUInt(void) const;
178 virtual float toFloat(void) const;
179 virtual double toDouble(void) const;
180 void visit(Visitor &visitor);
186 class String : public Value
189 String(const char * _value) : value(_value) {}
191 bool toBool(void) const;
192 const char *toString(void) const;
193 void visit(Visitor &visitor);
199 class Enum : public Value
202 Enum(const EnumSig *_sig) : sig(_sig) {}
204 bool toBool(void) const;
205 signed long long toSInt(void) const;
206 unsigned long long toUInt(void) const;
207 virtual float toFloat(void) const;
208 virtual double toDouble(void) const;
209 void visit(Visitor &visitor);
215 class Bitmask : public UInt
218 Bitmask(const BitmaskSig *_sig, unsigned long long _value) : UInt(_value), sig(_sig) {}
220 void visit(Visitor &visitor);
222 const BitmaskSig *sig;
226 class Struct : public Value
229 Struct(StructSig *_sig) : sig(_sig), members(_sig->num_members) { }
232 bool toBool(void) const;
233 void visit(Visitor &visitor);
235 const StructSig *sig;
236 std::vector<Value *> members;
240 class Array : public Value
243 Array(size_t len) : values(len) {}
246 bool toBool(void) const;
247 void visit(Visitor &visitor);
249 std::vector<Value *> values;
253 class Blob : public Value
258 buf = new char[_size];
263 bool toBool(void) const;
264 void *toPointer(void) const;
265 void visit(Visitor &visitor);
272 class Pointer : public UInt
275 Pointer(unsigned long long value) : UInt(value) {}
277 bool toBool(void) const;
278 void *toPointer(void) const;
279 unsigned long long toUIntPtr(void) const;
280 void visit(Visitor &visitor);
287 virtual void visit(Null *);
288 virtual void visit(Bool *);
289 virtual void visit(SInt *);
290 virtual void visit(UInt *);
291 virtual void visit(Float *);
292 virtual void visit(String *);
293 virtual void visit(Enum *);
294 virtual void visit(Bitmask *);
295 virtual void visit(Struct *);
296 virtual void visit(Array *);
297 virtual void visit(Blob *);
298 virtual void visit(Pointer *);
301 inline void _visit(Value *value) {
309 std::ostream & operator <<(std::ostream &os, Value *value);
316 const FunctionSig *sig;
317 std::vector<Value *> args;
320 Call(FunctionSig *_sig) : sig(_sig), args(_sig->num_args), ret(0) { }
323 inline const char * name(void) const {
327 inline Value & arg(unsigned index) {
328 assert(index < args.size());
329 return *(args[index]);
334 std::ostream & operator <<(std::ostream &os, Call &call);
337 } /* namespace Trace */
339 #endif /* _TRACE_MODEL_HPP_ */