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 void *toPointer(bool bind);
100 virtual unsigned long long toUIntPtr(void) const;
101 virtual const char *toString(void) const;
103 const Value & operator[](size_t index) const;
105 void dump(std::ostream &os, bool color=true);
109 class Null : public Value
112 bool toBool(void) const;
113 signed long long toSInt(void) const;
114 unsigned long long toUInt(void) const;
115 virtual float toFloat(void) const;
116 virtual double toDouble(void) const;
117 void *toPointer(void) const;
118 void *toPointer(bool bind);
119 unsigned long long toUIntPtr(void) const;
120 const char *toString(void) const;
121 void visit(Visitor &visitor);
125 class Bool : public Value
128 Bool(bool _value) : value(_value) {}
130 bool toBool(void) const;
131 signed long long toSInt(void) const;
132 unsigned long long toUInt(void) const;
133 virtual float toFloat(void) const;
134 virtual double toDouble(void) const;
135 void visit(Visitor &visitor);
141 class SInt : public Value
144 SInt(signed long long _value) : value(_value) {}
146 bool toBool(void) const;
147 signed long long toSInt(void) const;
148 unsigned long long toUInt(void) const;
149 virtual float toFloat(void) const;
150 virtual double toDouble(void) const;
151 void visit(Visitor &visitor);
153 signed long long value;
157 class UInt : public Value
160 UInt(unsigned long long _value) : value(_value) {}
162 bool toBool(void) const;
163 signed long long toSInt(void) const;
164 unsigned long long toUInt(void) const;
165 virtual float toFloat(void) const;
166 virtual double toDouble(void) const;
167 void visit(Visitor &visitor);
169 unsigned long long value;
173 class Float : public Value
176 Float(double _value) : value(_value) {}
178 bool toBool(void) const;
179 signed long long toSInt(void) const;
180 unsigned long long toUInt(void) const;
181 virtual float toFloat(void) const;
182 virtual double toDouble(void) const;
183 void visit(Visitor &visitor);
189 class String : public Value
192 String(const char * _value) : value(_value) {}
195 bool toBool(void) const;
196 const char *toString(void) const;
197 void visit(Visitor &visitor);
203 class Enum : public Value
206 Enum(const EnumSig *_sig) : sig(_sig) {}
208 bool toBool(void) const;
209 signed long long toSInt(void) const;
210 unsigned long long toUInt(void) const;
211 virtual float toFloat(void) const;
212 virtual double toDouble(void) const;
213 void visit(Visitor &visitor);
219 class Bitmask : public UInt
222 Bitmask(const BitmaskSig *_sig, unsigned long long _value) : UInt(_value), sig(_sig) {}
224 void visit(Visitor &visitor);
226 const BitmaskSig *sig;
230 class Struct : public Value
233 Struct(StructSig *_sig) : sig(_sig), members(_sig->num_members) { }
236 bool toBool(void) const;
237 void visit(Visitor &visitor);
239 const StructSig *sig;
240 std::vector<Value *> members;
244 class Array : public Value
247 Array(size_t len) : values(len) {}
250 bool toBool(void) const;
251 void visit(Visitor &visitor);
253 std::vector<Value *> values;
257 class Blob : public Value
262 buf = new char[_size];
268 bool toBool(void) const;
269 void *toPointer(void) const;
270 void *toPointer(bool bind);
271 void visit(Visitor &visitor);
279 class Pointer : public UInt
282 Pointer(unsigned long long value) : UInt(value) {}
284 bool toBool(void) const;
285 void *toPointer(void) const;
286 void *toPointer(bool bind);
287 unsigned long long toUIntPtr(void) const;
288 void visit(Visitor &visitor);
295 virtual void visit(Null *);
296 virtual void visit(Bool *);
297 virtual void visit(SInt *);
298 virtual void visit(UInt *);
299 virtual void visit(Float *);
300 virtual void visit(String *);
301 virtual void visit(Enum *);
302 virtual void visit(Bitmask *);
303 virtual void visit(Struct *);
304 virtual void visit(Array *);
305 virtual void visit(Blob *);
306 virtual void visit(Pointer *);
309 inline void _visit(Value *value) {
317 inline std::ostream & operator <<(std::ostream &os, Value *value) {
329 const FunctionSig *sig;
330 std::vector<Value *> args;
333 Call(FunctionSig *_sig) : sig(_sig), args(_sig->num_args), ret(0) { }
336 inline const char * name(void) const {
340 inline Value & arg(unsigned index) {
341 assert(index < args.size());
342 return *(args[index]);
345 void dump(std::ostream &os, bool color=true);
349 inline std::ostream & operator <<(std::ostream &os, Call &call) {
355 } /* namespace Trace */
357 #endif /* _TRACE_MODEL_HPP_ */