X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=dispatch%2Fdispatch.py;h=60f95073b76d829c773b3dc653e6fadde895cfb0;hb=7a9fb5103e052150232b64cb5d99374cda3f1234;hp=491db91b5f98ed9bd5641e72b3c5700033c0b59c;hpb=4f242f43bf4b3c8f5daadc4496c0e84ae55117b3;p=apitrace diff --git a/dispatch/dispatch.py b/dispatch/dispatch.py index 491db91..60f9507 100644 --- a/dispatch/dispatch.py +++ b/dispatch/dispatch.py @@ -38,11 +38,11 @@ import specs.stdapi as stdapi def function_pointer_type(function): - return '__PFN' + function.name.upper() + return 'PFN_' + function.name.upper() def function_pointer_value(function): - return '__' + function.name + '_ptr' + return '_' + function.name + '_ptr' class Dispatcher: @@ -51,55 +51,58 @@ class Dispatcher: # Must be implemented by derived classes, which should define, declare, # or implement something like: # - # typedef void (*__PROC)(void); + # typedef void (*_PROC)(void); # - # static __PROC __getPublicProcAddress(const char *name); - # static __PROC __getPrivateProcAddress(const char *name); + # static _PROC _getPublicProcAddress(const char *name); + # static _PROC _getPrivateProcAddress(const char *name); # raise NotImplementedError - def dispatch_api(self, api): - for function in api.functions: - self.invokeFunction(function) + def dispatchModule(self, module): + for function in module.functions: + self.dispatchFunction(module, function) # define standard name aliases for convenience, but only when not # tracing, as that would cause symbol clashing with the tracing # functions print '#ifdef RETRACE' - for function in api.functions: - print '#define %s __%s' % (function.name, function.name) + for function in module.functions: + print '#define %s _%s' % (function.name, function.name) print '#endif /* RETRACE */' print - def invokeFunction(self, function): + def dispatchFunction(self, module, function): ptype = function_pointer_type(function) pvalue = function_pointer_value(function) print 'typedef ' + function.prototype('* %s' % ptype) + ';' print 'static %s %s = NULL;' % (ptype, pvalue) print - print 'static inline ' + function.prototype('__' + function.name) + ' {' - print ' const char *__name = "%s";' % function.name + print 'static inline ' + function.prototype('_' + function.name) + ' {' + print ' const char *_name = "%s";' % function.name if function.type is stdapi.Void: ret = '' else: ret = 'return ' - self.get_true_pointer(function) + self.invokeGetProcAddress(module, function) print ' %s%s(%s);' % (ret, pvalue, ', '.join([str(arg.name) for arg in function.args])) print '}' print - def isFunctionPublic(self, function): + def isFunctionPublic(self, module, function): return True - def get_true_pointer(self, function): + def getProcAddressName(self, module, function): + if self.isFunctionPublic(module, function): + return '_getPublicProcAddress' + else: + return '_getPrivateProcAddress' + + def invokeGetProcAddress(self, module, function): ptype = function_pointer_type(function) pvalue = function_pointer_value(function) - if self.isFunctionPublic(function): - get_proc_address = '__getPublicProcAddress' - else: - get_proc_address = '__getPrivateProcAddress' + getProcAddressName = self.getProcAddressName(module, function) print ' if (!%s) {' % (pvalue,) - print ' %s = (%s)%s(__name);' % (pvalue, ptype, get_proc_address) + print ' %s = (%s)%s(_name);' % (pvalue, ptype, getProcAddressName) print ' if (!%s) {' % (pvalue,) self.failFunction(function) print ' }' @@ -107,7 +110,7 @@ class Dispatcher: def failFunction(self, function): if function.type is stdapi.Void or function.fail is not None: - print r' os::log("warning: ignoring call to unavailable function %s\n", __name);' + print r' os::log("warning: ignoring call to unavailable function %s\n", _name);' if function.type is stdapi.Void: assert function.fail is None print ' return;' @@ -115,7 +118,7 @@ class Dispatcher: assert function.fail is not None print ' return %s;' % function.fail else: - print r' os::log("error: unavailable function %s\n", __name);' + print r' os::log("error: unavailable function %s\n", _name);' print r' os::abort();'