def visitConst(self, const):
return const.type
+ def visitAlias(self, alias):
+ type = self.visit(alias.type)
+ if type is alias.type:
+ return alias
+ return type
+
+ def visitReference(self, reference):
+ return reference.type
+
def visitOpaque(self, opaque):
return opaque
print ' const trace::Array *__a%s = dynamic_cast<const trace::Array *>(&%s);' % (array.tag, rvalue)
print ' if (__a%s) {' % (array.tag)
length = '__a%s->values.size()' % array.tag
- print ' %s = new %s[%s];' % (lvalue, array.type, length)
+ print ' %s = _allocator.alloc<%s>(%s);' % (lvalue, array.type, length)
index = '__j' + array.tag
print ' for (size_t {i} = 0; {i} < {length}; ++{i}) {{'.format(i = index, length = length)
try:
def visitPointer(self, pointer, lvalue, rvalue):
print ' const trace::Array *__a%s = dynamic_cast<const trace::Array *>(&%s);' % (pointer.tag, rvalue)
print ' if (__a%s) {' % (pointer.tag)
- print ' %s = new %s;' % (lvalue, pointer.type)
+ print ' %s = _allocator.alloc<%s>();' % (lvalue, pointer.type)
try:
self.visit(pointer.type, '%s[0]' % (lvalue,), '*__a%s->values[0]' % (pointer.tag,))
finally:
def visitLinearPointer(self, pointer, lvalue, rvalue):
print ' %s = static_cast<%s>(retrace::toPointer(%s));' % (lvalue, pointer, rvalue)
+ def visitReference(self, reference, lvalue, rvalue):
+ self.visit(reference.type, lvalue, rvalue);
+
def visitHandle(self, handle, lvalue, rvalue):
#OpaqueValueDeserializer().visit(handle.type, lvalue, rvalue);
self.visit(handle.type, lvalue, rvalue);
if pointer.size is not None:
print r' retrace::addRegion((%s).toUIntPtr(), %s, %s);' % (rvalue, lvalue, pointer.size)
+ def visitReference(self, reference, lvalue, rvalue):
+ pass
+
def visitHandle(self, handle, lvalue, rvalue):
print ' %s __orig_result;' % handle.type
OpaqueValueDeserializer().visit(handle.type, '__orig_result', rvalue);
print '}'
print
+ def retraceInterfaceMethod(self, interface, method):
+ print 'static void retrace_%s__%s(trace::Call &call) {' % (interface.name, method.name)
+ self.retraceInterfaceMethodBody(interface, method)
+ print '}'
+ print
+
def retraceFunctionBody(self, function):
if not function.sideeffects:
print ' (void)call;'
return
+ self.deserializeArgs(function)
+
+ self.invokeFunction(function)
+
+ self.swizzleValues(function)
+
+ def retraceInterfaceMethodBody(self, interface, method):
+ if not method.sideeffects:
+ print ' (void)call;'
+ return
+
+ self.deserializeThisPointer(interface)
+
+ self.deserializeArgs(method)
+
+ self.invokeInterfaceMethod(interface, method)
+
+ self.swizzleValues(method)
+
+ def deserializeThisPointer(self, interface):
+ print ' %s *_this;' % (interface.name,)
+ # FIXME
+
+ def deserializeArgs(self, function):
+ print ' retrace::ScopedAllocator _allocator;'
+ print ' (void)_allocator;'
success = True
for arg in function.args:
arg_type = ConstRemover().visit(arg.type)
try:
self.extractArg(function, arg, arg_type, lvalue, rvalue)
except NotImplementedError:
- success = False
+ success = False
print ' %s = 0; // FIXME' % arg.name
+
if not success:
print ' if (1) {'
self.failFunction(function)
+ if function.name[-1].islower():
+ sys.stderr.write('warning: unsupported %s call\n' % function.name)
print ' }'
- self.invokeFunction(function)
+
+ def swizzleValues(self, function):
for arg in function.args:
if arg.output:
arg_type = ConstRemover().visit(arg.type)
self.regiterSwizzledValue(function.type, lvalue, rvalue)
except NotImplementedError:
print ' // XXX: result'
- if not success:
- if function.name[-1].islower():
- sys.stderr.write('warning: unsupported %s call\n' % function.name)
def failFunction(self, function):
print ' if (retrace::verbosity >= 0) {'
else:
print ' %s(%s);' % (function.name, arg_names)
+ def invokeInterfaceMethod(self, interface, method):
+ arg_names = ", ".join(method.argNames())
+ if method.type is not stdapi.Void:
+ print ' %s __result;' % (method.type)
+ print ' __result = _this->%s(%s);' % (method.name, arg_names)
+ print ' (void)__result;'
+ else:
+ print ' _this->%s(%s);' % (method.name, arg_names)
+
def filterFunction(self, function):
return True
table_name = 'retrace::callbacks'
- def retraceFunctions(self, functions):
- functions = filter(self.filterFunction, functions)
-
- for function in functions:
- self.retraceFunction(function)
-
- print 'const retrace::Entry %s[] = {' % self.table_name
- for function in functions:
- print ' {"%s", &retrace_%s},' % (function.name, function.name)
- print ' {NULL, NULL}'
- print '};'
- print
-
-
def retraceApi(self, api):
print '#include "trace_parser.hpp"'
handle_names.add(handle.name)
print
- self.retraceFunctions(api.functions)
+ functions = filter(self.filterFunction, api.functions)
+ for function in functions:
+ self.retraceFunction(function)
+ interfaces = api.getAllInterfaces()
+ for interface in interfaces:
+ for method in interface.iterMethods():
+ self.retraceInterfaceMethod(interface, method)
+
+ print 'const retrace::Entry %s[] = {' % self.table_name
+ for function in functions:
+ print ' {"%s", &retrace_%s},' % (function.name, function.name)
+ for interface in interfaces:
+ for method in interface.iterMethods():
+ print ' {"%s::%s", &retrace_%s__%s},' % (interface.name, method.name, interface.name, method.name)
+ print ' {NULL, NULL}'
+ print '};'
+ print