diff options
-rw-r--r-- | trace.py | 11 | ||||
-rw-r--r-- | trace_model.cpp | 62 | ||||
-rw-r--r-- | trace_model.hpp | 19 | ||||
-rw-r--r-- | trace_parser.hpp | 33 | ||||
-rw-r--r-- | trace_write.cpp | 17 | ||||
-rw-r--r-- | trace_write.hpp | 12 |
6 files changed, 93 insertions, 61 deletions
@@ -51,11 +51,16 @@ class DumpDeclarator(stdapi.OnceVisitor): for type, name in struct.members: self.visit(type) print 'static void __traceStruct%s(const %s &value) {' % (struct.id, struct.expr) - print ' Trace::BeginStruct(%u);' % len(struct.members) + print ' static const char * members[%u] = {' % (len(struct.members),) + for type, name, in struct.members: + print ' "%s",' % (name,) + print ' };' + print ' static const Trace::StructSig sig = {' + print ' %u, "%s", %u, members' % (int(struct.id), struct.name, len(struct.members)) + print ' };' + print ' Trace::BeginStruct(&sig);' for type, name in struct.members: - print ' Trace::BeginMember("%s");' % (name,) dump_instance(type, 'value.%s' % (name,)) - print ' Trace::EndMember();' print ' Trace::EndStruct();' print '}' print diff --git a/trace_model.cpp b/trace_model.cpp index fb25826f..d0bf31d5 100644 --- a/trace_model.cpp +++ b/trace_model.cpp @@ -31,46 +31,17 @@ namespace Trace { -void Null::visit(Visitor &visitor) { - visitor.visit(this); -} - -void Bool::visit(Visitor &visitor) { - visitor.visit(this); -} - -void SInt::visit(Visitor &visitor) { - visitor.visit(this); -} - -void UInt::visit(Visitor &visitor) { - visitor.visit(this); -} - -void Float::visit(Visitor &visitor) { - visitor.visit(this); -} - -void String::visit(Visitor &visitor) { - visitor.visit(this); -} - -void Enum::visit(Visitor &visitor) { - visitor.visit(this); -} - -void Bitmask::visit(Visitor &visitor) { - visitor.visit(this); -} - -void Array::visit(Visitor &visitor) { - visitor.visit(this); -} - -void Blob::visit(Visitor &visitor) { - visitor.visit(this); -} - +void Null::visit(Visitor &visitor) { visitor.visit(this); } +void Bool::visit(Visitor &visitor) { visitor.visit(this); } +void SInt::visit(Visitor &visitor) { visitor.visit(this); } +void UInt::visit(Visitor &visitor) { visitor.visit(this); } +void Float::visit(Visitor &visitor) { visitor.visit(this); } +void String::visit(Visitor &visitor) { visitor.visit(this); } +void Enum::visit(Visitor &visitor) { visitor.visit(this); } +void Bitmask::visit(Visitor &visitor) { visitor.visit(this); } +void Struct::visit(Visitor &visitor) { visitor.visit(this); } +void Array::visit(Visitor &visitor) { visitor.visit(this); } +void Blob::visit(Visitor &visitor) { visitor.visit(this); } class Dumper : public Visitor { @@ -156,6 +127,17 @@ public: } } + void visit(Struct *s) { + const char *sep = ""; + os << "{"; + for (unsigned i = 0; i < s->members.size(); ++i) { + os << sep << italic << s->sig->member_names[i] << normal << " = "; + _visit(s->members[i]); + sep = ", "; + } + os << "}"; + } + void visit(Array *array) { if (array->values.size() == 1) { os << "&"; diff --git a/trace_model.hpp b/trace_model.hpp index 5c162bc7..c65fa03f 100644 --- a/trace_model.hpp +++ b/trace_model.hpp @@ -185,6 +185,23 @@ public: }; +class Struct : public Value +{ +public: + struct Signature { + std::string name; + std::vector<std::string> member_names; + }; + + Struct(Signature *_sig) : sig(_sig), members(_sig->member_names.size()) { } + + void visit(Visitor &visitor); + + const Signature *sig; + std::vector<Value *> members; +}; + + class Array : public Value { public: @@ -226,6 +243,7 @@ public: virtual void visit(String *) {assert(0);} virtual void visit(Enum *) {assert(0);} virtual void visit(Bitmask *bitmask) {visit(static_cast<UInt *>(bitmask));} + virtual void visit(Struct *) {assert(0);} virtual void visit(Array *) {assert(0);} virtual void visit(Blob *) {assert(0);} @@ -271,7 +289,6 @@ public: }; - std::ostream & operator <<(std::ostream &os, Call &call); diff --git a/trace_parser.hpp b/trace_parser.hpp index 254141c1..e9f8c428 100644 --- a/trace_parser.hpp +++ b/trace_parser.hpp @@ -59,6 +59,9 @@ protected: typedef std::map<size_t, Call::Signature *> FunctionMap; FunctionMap functions; + typedef std::map<size_t, Struct::Signature *> StructMap; + StructMap structs; + typedef std::map<size_t, Enum *> EnumMap; EnumMap enums; @@ -311,14 +314,30 @@ public: } Value *parse_struct() { - size_t length = read_uint(); - /* XXX */ - for (size_t i = 0; i < length; ++i) { - std::string name = read_name(); - Value *value = parse_value(); - std::cout << " " << name << " = " << value << "\n"; + size_t id = read_uint(); + + Struct::Signature *sig; + StructMap::const_iterator it = structs.find(id); + if (it == structs.end()) { + sig = new Struct::Signature; + sig->name = read_string(); + unsigned size = read_uint(); + for (unsigned i = 0; i < size; ++i) { + sig->member_names.push_back(read_string()); + } + structs[id] = sig; + } else { + sig = it->second; + } + assert(sig); + + Struct *value = new Struct(sig); + + for (size_t i = 0; i < sig->member_names.size(); ++i) { + value->members[i] = parse_value(); } - return NULL; + + return value; } Value *parse_opaque() { diff --git a/trace_write.cpp b/trace_write.cpp index cdc3892a..5df4ae13 100644 --- a/trace_write.cpp +++ b/trace_write.cpp @@ -171,6 +171,7 @@ void Close(void) { static unsigned call_no = 0; static std::map<Id, bool> functions; +static std::map<Id, bool> structs; static std::map<Id, bool> enums; static std::map<Id, bool> bitmasks; @@ -223,13 +224,17 @@ void BeginArray(size_t length) { WriteUInt(length); } -void BeginStruct(size_t length) { +void BeginStruct(const StructSig *sig) { WriteByte(Trace::TYPE_STRUCT); - WriteUInt(length); -} - -void BeginMember(const char *name) { - WriteName(name); + WriteUInt(sig->id); + if (!structs[sig->id]) { + WriteString(sig->name); + WriteUInt(sig->num_members); + for (unsigned i = 0; i < sig->num_members; ++i) { + WriteString(sig->members[i]); + } + structs[sig->id] = true; + } } void LiteralBool(bool value) { diff --git a/trace_write.hpp b/trace_write.hpp index 428b30fa..66057df2 100644 --- a/trace_write.hpp +++ b/trace_write.hpp @@ -37,6 +37,13 @@ namespace Trace { const char **args; }; + struct StructSig { + Id id; + const char *name; + unsigned num_members; + const char **members; + }; + struct EnumSig { Id id; const char *name; @@ -75,12 +82,9 @@ namespace Trace { inline void BeginElement(void) {} inline void EndElement(void) {} - void BeginStruct(size_t length); + void BeginStruct(const StructSig *sig); inline void EndStruct(void) {} - void BeginMember(const char *name); - inline void EndMember(void) {} - void LiteralBool(bool value); void LiteralSInt(signed long long value); void LiteralUInt(unsigned long long value); |