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;
104 void dump(std::ostream &os, bool color=true);
108 class Null : public Value
111 bool toBool(void) const;
112 signed long long toSInt(void) const;
113 unsigned long long toUInt(void) const;
114 virtual float toFloat(void) const;
115 virtual double toDouble(void) const;
116 void *toPointer(void) const;
117 unsigned long long toUIntPtr(void) const;
118 const char *toString(void) const;
119 void visit(Visitor &visitor);
123 class Bool : public Value
126 Bool(bool _value) : value(_value) {}
128 bool toBool(void) const;
129 signed long long toSInt(void) const;
130 unsigned long long toUInt(void) const;
131 virtual float toFloat(void) const;
132 virtual double toDouble(void) const;
133 void visit(Visitor &visitor);
139 class SInt : public Value
142 SInt(signed long long _value) : value(_value) {}
144 bool toBool(void) const;
145 signed long long toSInt(void) const;
146 unsigned long long toUInt(void) const;
147 virtual float toFloat(void) const;
148 virtual double toDouble(void) const;
149 void visit(Visitor &visitor);
151 signed long long value;
155 class UInt : public Value
158 UInt(unsigned long long _value) : value(_value) {}
160 bool toBool(void) const;
161 signed long long toSInt(void) const;
162 unsigned long long toUInt(void) const;
163 virtual float toFloat(void) const;
164 virtual double toDouble(void) const;
165 void visit(Visitor &visitor);
167 unsigned long long value;
171 class Float : public Value
174 Float(double _value) : value(_value) {}
176 bool toBool(void) const;
177 signed long long toSInt(void) const;
178 unsigned long long toUInt(void) const;
179 virtual float toFloat(void) const;
180 virtual double toDouble(void) const;
181 void visit(Visitor &visitor);
187 class String : public Value
190 String(const char * _value) : value(_value) {}
192 bool toBool(void) const;
193 const char *toString(void) const;
194 void visit(Visitor &visitor);
200 class Enum : public Value
203 Enum(const EnumSig *_sig) : sig(_sig) {}
205 bool toBool(void) const;
206 signed long long toSInt(void) const;
207 unsigned long long toUInt(void) const;
208 virtual float toFloat(void) const;
209 virtual double toDouble(void) const;
210 void visit(Visitor &visitor);
216 class Bitmask : public UInt
219 Bitmask(const BitmaskSig *_sig, unsigned long long _value) : UInt(_value), sig(_sig) {}
221 void visit(Visitor &visitor);
223 const BitmaskSig *sig;
227 class Struct : public Value
230 Struct(StructSig *_sig) : sig(_sig), members(_sig->num_members) { }
233 bool toBool(void) const;
234 void visit(Visitor &visitor);
236 const StructSig *sig;
237 std::vector<Value *> members;
241 class Array : public Value
244 Array(size_t len) : values(len) {}
247 bool toBool(void) const;
248 void visit(Visitor &visitor);
250 std::vector<Value *> values;
254 class Blob : public Value
259 buf = new char[_size];
264 bool toBool(void) const;
265 void *toPointer(void) const;
266 void visit(Visitor &visitor);
273 class Pointer : public UInt
276 Pointer(unsigned long long value) : UInt(value) {}
278 bool toBool(void) const;
279 void *toPointer(void) const;
280 unsigned long long toUIntPtr(void) const;
281 void visit(Visitor &visitor);
288 virtual void visit(Null *);
289 virtual void visit(Bool *);
290 virtual void visit(SInt *);
291 virtual void visit(UInt *);
292 virtual void visit(Float *);
293 virtual void visit(String *);
294 virtual void visit(Enum *);
295 virtual void visit(Bitmask *);
296 virtual void visit(Struct *);
297 virtual void visit(Array *);
298 virtual void visit(Blob *);
299 virtual void visit(Pointer *);
302 inline void _visit(Value *value) {
310 inline std::ostream & operator <<(std::ostream &os, Value *value) {
322 const FunctionSig *sig;
323 std::vector<Value *> args;
326 Call(FunctionSig *_sig) : sig(_sig), args(_sig->num_args), ret(0) { }
329 inline const char * name(void) const {
333 inline Value & arg(unsigned index) {
334 assert(index < args.size());
335 return *(args[index]);
338 void dump(std::ostream &os, bool color=true);
342 inline std::ostream & operator <<(std::ostream &os, Call &call) {
348 } /* namespace Trace */
350 #endif /* _TRACE_MODEL_HPP_ */