import sys
import gallium
import model
-from parser import TraceParser
+import parser
def make_image(surface):
show_image(self.cbufs[0])
-class Interpreter:
+class Interpreter(parser.TraceParser):
- def __init__(self):
+ def __init__(self, stream):
+ parser.TraceParser.__init__(self, stream)
self.objects = {}
self.result = None
self.globl = Global(self, None)
for call in trace.calls:
self.interpret_call(call)
- def interpret_call(self, call):
+ def handle_call(self, call):
sys.stderr.write("%s\n" % call)
args = [self.interpret_arg(arg) for name, arg in call.args]
return translator.visit(node)
-def main():
- for arg in sys.argv[1:]:
- if arg.endswith('.gz'):
- import gzip
- stream = gzip.GzipFile(arg, 'rt')
- else:
- stream = open(arg, 'rt')
- parser = TraceParser(stream)
- trace = parser.parse()
- interpreter = Interpreter()
- interpreter.interpret(trace)
-
-
if __name__ == '__main__':
- main()
+ parser.main(Interpreter)
def parse(self):
self.element_start('trace')
- calls = []
while self.token.type not in (ELEMENT_END, EOF):
- calls.append(self.parse_call())
+ call = self.parse_call()
+ self.handle_call(call)
if self.token.type != EOF:
self.element_end('trace')
- return Trace(calls)
def parse_call(self):
attrs = self.element_start('call')
return Pointer(address)
+ def handle_call(self, call):
+
+ pass
+
+
+class TraceDumper(TraceParser):
+
+
+ def handle_call(self, call):
+ print call
+
-def main():
+def main(ParserFactory):
for arg in sys.argv[1:]:
if arg.endswith('.gz'):
import gzip
stream = gzip.GzipFile(arg, 'rt')
else:
stream = open(arg, 'rt')
- parser = TraceParser(stream)
- trace = parser.parse()
- for call in trace.calls:
- print call
+ parser = ParserFactory(stream)
+ parser.parse()
if __name__ == '__main__':
- main()
+ main(TraceDumper)