diff options
author | José Fonseca <jfonseca@vmware.com> | 2010-11-25 09:36:04 +0000 |
---|---|---|
committer | José Fonseca <jfonseca@vmware.com> | 2010-11-25 09:36:04 +0000 |
commit | fa922145e14de53625b24349c4c36d4a8d326b86 (patch) | |
tree | bdcaad97784b5a9196da9d0f9bcb94c5ed695918 /trace_parser.hpp | |
parent | f9e6eb1f684d7cd2266771abc41a208cc46b1c14 (diff) |
Compress names better.
Diffstat (limited to 'trace_parser.hpp')
-rw-r--r-- | trace_parser.hpp | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/trace_parser.hpp b/trace_parser.hpp index 97dcf65..39fcfda 100644 --- a/trace_parser.hpp +++ b/trace_parser.hpp @@ -30,6 +30,8 @@ #include <cassert> #include <iostream> +#include <map> +#include <string> #include <zlib.h> @@ -44,6 +46,10 @@ class Parser { protected: gzFile file; + + typedef std::map<size_t, std::string> namemap; + namemap names; + public: Parser() { file = NULL; @@ -79,7 +85,7 @@ public: Call *parse_call(void) { Call *call = new Call; - call->name = read_string(); + call->name = read_name(); do { int c = read_byte(); switch(c) { @@ -104,7 +110,7 @@ public: void parse_arg(Call *call) { unsigned index = read_uint(); - std::string name = read_string(); + std::string name = read_name(); Value *value = parse_value(); if (index >= call->args.size()) { call->args.resize(index + 1); @@ -176,7 +182,7 @@ public: } Value *parse_const() { - std::string name = read_string(); + std::string name = read_name(); Value *value = parse_value(); return new Const(name, value); } @@ -194,7 +200,7 @@ public: value |= read_uint(); break; case Trace::TYPE_CONST: - read_string(); + read_name(); break; case Trace::TYPE_NULL: goto done; @@ -227,13 +233,12 @@ done: } Value *parse_struct() { - std::string name; + size_t length = read_uint(); /* XXX */ - name = read_string(); - while(name.length()) { + for (size_t i; i < length; ++i) { + std::string name = read_name(); Value *value = parse_value(); std::cout << " " << name << " = " << value << "\n"; - name = read_string(); } return NULL; } @@ -244,6 +249,18 @@ done: /* XXX */ return new UInt(addr); } + + std::string read_name(void) { + std::string name; + size_t id = read_uint(); + if (id >= names.size()) { + name = read_string(); + names[id] = name; + return name; + } else { + return names[id]; + } + } std::string read_string(void) { size_t len = read_uint(); |