2 ##########################################################################
4 # Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
7 # Permission is hereby granted, free of charge, to any person obtaining a
8 # copy of this software and associated documentation files (the
9 # "Software"), to deal in the Software without restriction, including
10 # without limitation the rights to use, copy, modify, merge, publish,
11 # distribute, sub license, and/or sell copies of the Software, and to
12 # permit persons to whom the Software is furnished to do so, subject to
13 # the following conditions:
15 # The above copyright notice and this permission notice (including the
16 # next paragraph) shall be included in all copies or substantial portions
19 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22 # IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
23 # ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24 # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25 # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 ##########################################################################
30 '''Trace data model.'''
38 from cStringIO
import StringIO
40 from StringIO
import StringIO
47 def visit(self
, visitor
):
48 raise NotImplementedError
52 formatter
= format
.DefaultFormatter(stream
)
53 pretty_printer
= PrettyPrinter(formatter
)
54 self
.visit(pretty_printer
)
55 return stream
.getvalue()
60 def __init__(self
, value
):
63 def visit(self
, visitor
):
64 visitor
.visit_literal(self
)
69 def __init__(self
, value
):
71 self
._hexValue
= value
74 if self
._rawValue
is None:
75 self
._rawValue
= binascii
.a2b_hex(self
._hexValue
)
79 def visit(self
, visitor
):
80 visitor
.visit_blob(self
)
83 class NamedConstant(Node
):
85 def __init__(self
, name
):
88 def visit(self
, visitor
):
89 visitor
.visit_named_constant(self
)
94 def __init__(self
, elements
):
95 self
.elements
= elements
97 def visit(self
, visitor
):
98 visitor
.visit_array(self
)
103 def __init__(self
, name
, members
):
105 self
.members
= members
107 def visit(self
, visitor
):
108 visitor
.visit_struct(self
)
113 def __init__(self
, address
):
114 self
.address
= address
116 def visit(self
, visitor
):
117 visitor
.visit_pointer(self
)
122 def __init__(self
, no
, klass
, method
, args
, ret
, time
):
130 def visit(self
, visitor
):
131 visitor
.visit_call(self
)
136 def __init__(self
, calls
):
139 def visit(self
, visitor
):
140 visitor
.visit_trace(self
)
145 def visit_literal(self
, node
):
146 raise NotImplementedError
148 def visit_blob(self
, node
):
149 raise NotImplementedError
151 def visit_named_constant(self
, node
):
152 raise NotImplementedError
154 def visit_array(self
, node
):
155 raise NotImplementedError
157 def visit_struct(self
, node
):
158 raise NotImplementedError
160 def visit_pointer(self
, node
):
161 raise NotImplementedError
163 def visit_call(self
, node
):
164 raise NotImplementedError
166 def visit_trace(self
, node
):
167 raise NotImplementedError
172 def __init__(self
, formatter
):
173 self
.formatter
= formatter
175 def visit_literal(self
, node
):
176 if node
.value
is None:
177 self
.formatter
.literal('NULL')
180 if isinstance(node
.value
, basestring
):
181 self
.formatter
.literal('"' + node
.value
+ '"')
184 self
.formatter
.literal(repr(node
.value
))
186 def visit_blob(self
, node
):
187 self
.formatter
.address('blob()')
189 def visit_named_constant(self
, node
):
190 self
.formatter
.literal(node
.name
)
192 def visit_array(self
, node
):
193 self
.formatter
.text('{')
195 for value
in node
.elements
:
196 self
.formatter
.text(sep
)
199 self
.formatter
.text('}')
201 def visit_struct(self
, node
):
202 self
.formatter
.text('{')
204 for name
, value
in node
.members
:
205 self
.formatter
.text(sep
)
206 self
.formatter
.variable(name
)
207 self
.formatter
.text(' = ')
210 self
.formatter
.text('}')
212 def visit_pointer(self
, node
):
213 self
.formatter
.address(node
.address
)
215 def visit_call(self
, node
):
216 self
.formatter
.text('%s ' % node
.no
)
217 if node
.klass
is not None:
218 self
.formatter
.function(node
.klass
+ '::' + node
.method
)
220 self
.formatter
.function(node
.method
)
221 self
.formatter
.text('(')
223 for name
, value
in node
.args
:
224 self
.formatter
.text(sep
)
225 self
.formatter
.variable(name
)
226 self
.formatter
.text(' = ')
229 self
.formatter
.text(')')
230 if node
.ret
is not None:
231 self
.formatter
.text(' = ')
233 if node
.time
is not None:
234 self
.formatter
.text(' // time ')
235 node
.time
.visit(self
)
237 def visit_trace(self
, node
):
238 for call
in node
.calls
:
240 self
.formatter
.newline()