diff options
author | José Fonseca <jfonseca@vmware.com> | 2010-11-22 19:56:19 +0000 |
---|---|---|
committer | José Fonseca <jfonseca@vmware.com> | 2010-11-22 19:56:19 +0000 |
commit | 6f51d3b71cd318f8337e7f5fe791867fc2713a5b (patch) | |
tree | c0316bd352928c395bc1dabf642ddaa9aea247d1 /trace_parser.hpp | |
parent | 64f3de83d0792a6dcb5f21600b9baeb90715c3a7 (diff) |
Invert control flow to satisfy glut.
Diffstat (limited to 'trace_parser.hpp')
-rw-r--r-- | trace_parser.hpp | 45 |
1 files changed, 23 insertions, 22 deletions
diff --git a/trace_parser.hpp b/trace_parser.hpp index ea6c746..dc7b8d6 100644 --- a/trace_parser.hpp +++ b/trace_parser.hpp @@ -49,7 +49,11 @@ public: file = NULL; } - bool parse(const char *filename) { + ~Parser() { + close(); + } + + bool open(const char *filename) { unsigned long long version; file = gzopen(filename, "rb"); @@ -63,44 +67,41 @@ public: return false; } - while (!gzeof(file)) { - parse_call(); - } - return true; } - void parse_call(void) { - Call call; - call.name = read_string(); - int c; + void close(void) { + if (file) { + gzclose(file); + file = NULL; + } + } + + Call *parse_call(void) { + Call *call = new Call; + call->name = read_string(); do { - c = read_byte(); - if (c == Trace::CALL_END || c == -1) { - break; - } + int c = read_byte(); switch(c) { case Trace::CALL_END: - return; + return call; case Trace::CALL_ARG: - call.args.push_back(parse_arg()); + call->args.push_back(parse_arg()); break; case Trace::CALL_RET: - call.ret = parse_value(); + call->ret = parse_value(); break; default: std::cerr << "error: unknown call detail " << c << "\n"; assert(0); - break; + /* fallthrough */ + case -1: + delete call; + return NULL; } } while(true); - handle_call(call); } - virtual void handle_call(Call &call) { - std::cout << call; - } - Arg parse_arg(void) { std::string name = read_string(); Value *value = parse_value(); |