X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=trace_model.hpp;h=a2847547421f8972666681d0784882192e2fb628;hb=ac92a2115ab3c759add836e115f108c945e0195b;hp=e7a2249c7c979833fbd8e7519ef3f18a5a9c22c0;hpb=31c9f62616e2c59973ca00fd074e8c288f6488b3;p=apitrace diff --git a/trace_model.hpp b/trace_model.hpp index e7a2249..a284754 100644 --- a/trace_model.hpp +++ b/trace_model.hpp @@ -33,9 +33,7 @@ #include -#include #include -#include #include #include @@ -43,9 +41,46 @@ namespace Trace { +typedef unsigned Id; + + +struct FunctionSig { + Id id; + const char *name; + unsigned num_args; + const char **arg_names; +}; + + +struct StructSig { + Id id; + const char *name; + unsigned num_members; + const char **member_names; +}; + + +struct EnumSig { + Id id; + const char *name; + signed long long value; +}; + + +struct BitmaskFlag { + const char *name; + unsigned long long value; +}; + + +struct BitmaskSig { + Id id; + unsigned num_flags; + const BitmaskFlag *flags; +}; + + class Visitor; -class Dumper; -class UInt; class Value @@ -61,10 +96,13 @@ public: virtual double toDouble(void) const; virtual void *toPointer(void) const; + virtual void *toPointer(bool bind); virtual unsigned long long toUIntPtr(void) const; virtual const char *toString(void) const; const Value & operator[](size_t index) const; + + void dump(std::ostream &os, bool color=true); }; @@ -77,6 +115,7 @@ public: virtual float toFloat(void) const; virtual double toDouble(void) const; void *toPointer(void) const; + void *toPointer(bool bind); unsigned long long toUIntPtr(void) const; const char *toString(void) const; void visit(Visitor &visitor); @@ -150,34 +189,20 @@ public: class String : public Value { public: - String(std::string _value) : value(_value) {} + String(const char * _value) : value(_value) {} bool toBool(void) const; const char *toString(void) const; void visit(Visitor &visitor); - std::string value; + const char * value; }; class Enum : public Value { public: - struct Signature : public std::pair - { - Signature() - : std::pair() - {} - Signature(const std::string &n, Trace::Value *val) - : std::pair(n, val) - {} - ~Signature() - { - delete second; - } - }; - - Enum(const Signature *_sig) : sig(_sig) {} + Enum(const EnumSig *_sig) : sig(_sig) {} bool toBool(void) const; signed long long toSInt(void) const; @@ -186,39 +211,31 @@ public: virtual double toDouble(void) const; void visit(Visitor &visitor); - const Signature *sig; + const EnumSig *sig; }; class Bitmask : public UInt { public: - typedef std::pair Pair; - typedef std::vector Signature; - - Bitmask(const Signature *_sig, unsigned long long _value) : UInt(_value), sig(_sig) {} + Bitmask(const BitmaskSig *_sig, unsigned long long _value) : UInt(_value), sig(_sig) {} void visit(Visitor &visitor); - const Signature *sig; + const BitmaskSig *sig; }; class Struct : public Value { public: - struct Signature { - std::string name; - std::vector member_names; - }; - - Struct(Signature *_sig) : sig(_sig), members(_sig->member_names.size()) { } + Struct(StructSig *_sig) : sig(_sig), members(_sig->num_members) { } ~Struct(); bool toBool(void) const; void visit(Visitor &visitor); - const Signature *sig; + const StructSig *sig; std::vector members; }; @@ -242,16 +259,19 @@ public: Blob(size_t _size) { size = _size; buf = new char[_size]; + bound = false; } ~Blob(); bool toBool(void) const; void *toPointer(void) const; + void *toPointer(bool bind); void visit(Visitor &visitor); size_t size; char *buf; + bool bound; }; @@ -262,6 +282,7 @@ public: bool toBool(void) const; void *toPointer(void) const; + void *toPointer(bool bind); unsigned long long toUIntPtr(void) const; void visit(Visitor &visitor); }; @@ -292,26 +313,26 @@ protected: }; -std::ostream & operator <<(std::ostream &os, Value *value); +inline std::ostream & operator <<(std::ostream &os, Value *value) { + if (value) { + value->dump(os); + } + return os; +} class Call { public: - struct Signature { - std::string name; - std::vector arg_names; - }; - unsigned no; - const Signature *sig; + const FunctionSig *sig; std::vector args; Value *ret; - Call(Signature *_sig) : sig(_sig), args(_sig->arg_names.size()), ret(0) { } + Call(FunctionSig *_sig) : sig(_sig), args(_sig->num_args), ret(0) { } ~Call(); - inline const std::string & name(void) const { + inline const char * name(void) const { return sig->name; } @@ -319,10 +340,15 @@ public: assert(index < args.size()); return *(args[index]); } + + void dump(std::ostream &os, bool color=true); }; -std::ostream & operator <<(std::ostream &os, Call &call); +inline std::ostream & operator <<(std::ostream &os, Call &call) { + call.dump(os); + return os; +} } /* namespace Trace */