]> git.cworth.org Git - apitrace/blob - trace_parser.hpp
962c323d4d9ef379e8a0c074bf3962fcd813fc9d
[apitrace] / trace_parser.hpp
1 /**************************************************************************
2  *
3  * Copyright 2010 VMware, Inc.
4  * All Rights Reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  *
24  **************************************************************************/
25
26 #ifndef _TRACE_PARSER_HPP_
27 #define _TRACE_PARSER_HPP_
28
29
30 #include <iostream>
31 #include <list>
32
33 #include "trace_file.hpp"
34 #include "trace_format.hpp"
35 #include "trace_model.hpp"
36
37
38 namespace Trace {
39
40 class Parser
41 {
42 protected:
43     File *file;
44
45     typedef std::list<Call *> CallList;
46     CallList calls;
47
48     // Helper template that extends a base signature structure, with additional
49     // parsing information.
50     template< class T >
51     struct SigState : public T {
52         // Offset in the file of where signature was defined.  It is used when
53         // reparsing to determine whether the signature definition is to be
54         // expected next or not.
55         File::Offset offset;
56     };
57
58     typedef SigState<FunctionSig> FunctionSigState;
59     typedef SigState<StructSig> StructSigState;
60     typedef SigState<EnumSig> EnumSigState;
61     typedef SigState<BitmaskSig> BitmaskSigState;
62
63     typedef std::vector<FunctionSigState *> FunctionMap;
64     typedef std::vector<StructSigState *> StructMap;
65     typedef std::vector<EnumSigState *> EnumMap;
66     typedef std::vector<BitmaskSigState *> BitmaskMap;
67
68     FunctionMap functions;
69     StructMap structs;
70     EnumMap enums;
71     BitmaskMap bitmasks;
72
73     bool m_supportsSeeking;
74
75     unsigned next_call_no;
76
77 public:
78     unsigned long long version;
79
80     Parser();
81
82     ~Parser();
83
84     bool open(const char *filename);
85
86     void close(void);
87
88     Call *parse_call(void);
89
90     bool supportsOffsets() const
91     {
92         return file->supportsOffsets();
93     }
94
95     File::Offset currentOffset()
96     {
97         return file->currentOffset();
98     }
99
100     void setCurrentOffset(const File::Offset &offset)
101     {
102         file->setCurrentOffset(offset);
103     }
104
105     unsigned currentCallNumber() const
106     {
107         return next_call_no;
108     }
109
110     void setCurrentCallNumber(unsigned num)
111     {
112         next_call_no = num;
113     }
114
115     int percentRead()
116     {
117         return file->percentRead();
118     }
119
120     Call *scan_call();
121
122 protected:
123     FunctionSig *parse_function_sig(void);
124     StructSig *parse_struct_sig();
125     EnumSig *parse_enum_sig();
126     BitmaskSig *parse_bitmask_sig();
127
128     void parse_enter(void);
129     void scan_enter(void);
130
131     Call *parse_leave(void);
132     Call *scan_leave(void);
133
134     bool parse_call_details(Call *call);
135     bool scan_call_details(Call *call);
136
137     void parse_arg(Call *call);
138     void scan_arg(Call *call);
139
140     Value *parse_value(void);
141     void scan_value(void);
142
143     Value *parse_sint();
144     void scan_sint();
145
146     Value *parse_uint();
147     void scan_uint();
148
149     Value *parse_float();
150     void scan_float();
151
152     Value *parse_double();
153     void scan_double();
154
155     Value *parse_string();
156     void scan_string();
157
158     Value *parse_enum();
159     void scan_enum();
160
161     Value *parse_bitmask();
162     void scan_bitmask();
163
164     Value *parse_array(void);
165     void scan_array(void);
166
167     Value *parse_blob(void);
168     void scan_blob(void);
169
170     Value *parse_struct();
171     void scan_struct();
172
173     Value *parse_opaque();
174     void scan_opaque();
175
176     const char * read_string(void);
177     void skip_string(void);
178
179     unsigned long long read_uint(void);
180     void skip_uint(void);
181
182     inline int read_byte(void);
183     inline void skip_byte(void);
184 };
185
186
187 } /* namespace Trace */
188
189 #endif /* _TRACE_PARSER_HPP_ */