X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=trace_model.hpp;h=5c51bba7d06c345a541b8dca59cebe1291d546f6;hb=b5f2ee344ef2914ca141608107c571ec0c28c6a6;hp=eb28465625cc18a5d0d1262a202084e2adca6ca4;hpb=ec494edf0f473db4088c23ec7a97f20eab393c2d;p=apitrace diff --git a/trace_model.hpp b/trace_model.hpp index eb28465..5c51bba 100644 --- a/trace_model.hpp +++ b/trace_model.hpp @@ -34,16 +34,52 @@ #include #include -#include #include #include -#include "trace_writer.hpp" - 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; @@ -64,6 +100,8 @@ public: virtual const char *toString(void) const; const Value & operator[](size_t index) const; + + void dump(std::ostream &os, bool color=true); }; @@ -189,18 +227,13 @@ public: class Struct : public Value { public: - struct Signature { - const char *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; }; @@ -274,23 +307,23 @@ 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 { - const char * 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 char * name(void) const { @@ -301,10 +334,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 */