From 1d5d809818ea1bc3c0037bbd6cc8eb16d3bc3fc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Fri, 21 Feb 2025 04:08:30 -0500 Subject: [PATCH] glapi: remove unused python code detected by a program called vulture Reviewed-by: Adam Jackson Part-of: --- src/mapi/glapi/gen/glX_XML.py | 66 +----------------- src/mapi/glapi/gen/glX_proto_common.py | 17 +---- src/mapi/glapi/gen/glX_proto_send.py | 12 ++-- src/mapi/glapi/gen/glX_proto_size.py | 95 +------------------------- src/mapi/glapi/gen/gl_XML.py | 18 ----- src/mapi/glapi/gen/gl_apitemp.py | 2 +- src/mapi/glapi/gen/gl_enums.py | 4 +- src/mapi/glapi/gen/gl_procs.py | 2 +- src/mapi/glapi/gen/gl_x86-64_asm.py | 69 ------------------- src/mapi/glapi/gen/typeexpr.py | 4 -- 10 files changed, 11 insertions(+), 278 deletions(-) diff --git a/src/mapi/glapi/gen/glX_XML.py b/src/mapi/glapi/gen/glX_XML.py index 4006875767a..744b0a560ed 100644 --- a/src/mapi/glapi/gen/glX_XML.py +++ b/src/mapi/glapi/gen/glX_XML.py @@ -95,7 +95,6 @@ class glx_function(gl_XML.gl_function): self.dimensions_in_reply = 0 self.img_reset = None - self.server_handcode = 0 self.client_handcode = 0 self.ignore = 0 @@ -154,16 +153,12 @@ class glx_function(gl_XML.gl_function): handcode = child.get( 'handcode', 'false' ) if handcode == "false": - self.server_handcode = 0 self.client_handcode = 0 elif handcode == "true": - self.server_handcode = 1 self.client_handcode = 1 elif handcode == "client": - self.server_handcode = 0 self.client_handcode = 1 elif handcode == "server": - self.server_handcode = 1 self.client_handcode = 0 else: raise RuntimeError('Invalid handcode mode "%s" in function "%s".' % (handcode, self.name)) @@ -185,40 +180,6 @@ class glx_function(gl_XML.gl_function): return - def has_variable_size_request(self): - """Determine if the GLX request packet is variable sized. - - The GLX request packet is variable sized in several common - situations. - - 1. The function has a non-output parameter that is counted - by another parameter (e.g., the 'textures' parameter of - glDeleteTextures). - - 2. The function has a non-output parameter whose count is - determined by another parameter that is an enum (e.g., the - 'params' parameter of glLightfv). - - 3. The function has a non-output parameter that is an - image. - - 4. The function must be hand-coded on the server. - """ - - if self.glx_rop == 0: - return 0 - - if self.server_handcode or self.images: - return 1 - - for param in self.parameters: - if not param.is_output: - if param.counter or len(param.count_parameter_list): - return 1 - - return 0 - - def variable_length_parameter(self): for param in self.parameters: if not param.is_output: @@ -238,7 +199,7 @@ class glx_function(gl_XML.gl_function): # number of dimensions of the pixel data. if len(self.images) and not self.images[0].is_output: - [dim, junk, junk, junk, junk] = self.images[0].get_dimensions() + [dim, _, _, _, _] = self.images[0].get_dimensions() # The base size is the size of the pixel pack info # header used by images with the specified number @@ -270,11 +231,6 @@ class glx_function(gl_XML.gl_function): return - def offset_of(self, param_name): - self.calculate_offsets() - return self.parameters_by_name[ param_name ].offset - - def parameterIterateGlxSend(self, include_variable_parameters = 1): """Create an iterator for parameters in GLX request order.""" @@ -372,26 +328,6 @@ class glx_function(gl_XML.gl_function): return "%u%s" % (size, self.command_variable_length()) - def opcode_real_value(self): - """Get the true numeric value of the GLX opcode - - Behaves similarly to opcode_value, except for - X_GLXVendorPrivate and X_GLXVendorPrivateWithReply commands. - In these cases the value for the GLX opcode field (i.e., - 16 for X_GLXVendorPrivate or 17 for - X_GLXVendorPrivateWithReply) is returned. For other 'single' - commands, the opcode for the command (e.g., 101 for - X_GLsop_NewList) is returned.""" - - if self.glx_vendorpriv != 0: - if self.needs_reply(): - return 17 - else: - return 16 - else: - return self.opcode_value() - - def opcode_value(self): """Get the unique protocol opcode for the glXFunction""" diff --git a/src/mapi/glapi/gen/glX_proto_common.py b/src/mapi/glapi/gen/glX_proto_common.py index dba393d42bf..934f973ec15 100644 --- a/src/mapi/glapi/gen/glX_proto_common.py +++ b/src/mapi/glapi/gen/glX_proto_common.py @@ -27,21 +27,6 @@ import gl_XML, glX_XML -class glx_proto_item_factory(glX_XML.glx_item_factory): - """Factory to create GLX protocol oriented objects derived from gl_item.""" - - def create_type(self, element, context, category): - return glx_proto_type(element, context, category) - - -class glx_proto_type(gl_XML.gl_type): - def __init__(self, element, context, category): - gl_XML.gl_type.__init__(self, element, context, category) - - self.glx_name = element.get( "glx_name" ) - return - - class glx_print_proto(gl_XML.gl_print_base): def size_call(self, func, outputs_also = 0): """Create C code to calculate 'compsize'. @@ -55,7 +40,7 @@ class glx_print_proto(gl_XML.gl_print_base): for param in func.parameterIterator(): if outputs_also or not param.is_output: if param.is_image(): - [dim, w, h, d, junk] = param.get_dimensions() + [dim, w, h, d, _] = param.get_dimensions() compsize = '__glImageSize(%s, %s, %s, %s, %s, %s)' % (w, h, d, param.img_format, param.img_type, param.img_target) if not param.img_send_null: diff --git a/src/mapi/glapi/gen/glX_proto_send.py b/src/mapi/glapi/gen/glX_proto_send.py index 562c04c1ad8..a676bc09ae1 100644 --- a/src/mapi/glapi/gen/glX_proto_send.py +++ b/src/mapi/glapi/gen/glX_proto_send.py @@ -59,7 +59,7 @@ def hash_pixel_function(func): hash_suf = "" for param in func.parameterIterateGlxSend(): if param.is_image(): - [dim, junk, junk, junk, junk] = param.get_dimensions() + [dim, _, _, _, _] = param.get_dimensions() d = (dim + 1) & ~1 hash_pre = "%uD%uD_" % (d - 1, d) @@ -140,7 +140,6 @@ class glx_pixel_function_stub(glX_XML.glx_function): self.dimensions_in_reply = func.dimensions_in_reply self.img_reset = None - self.server_handcode = 0 self.client_handcode = 0 self.ignore = 0 @@ -157,7 +156,6 @@ class PrintGlxProtoStubs(glX_proto_common.glx_print_proto): self.license = license.bsd_license_template % ( "(C) Copyright IBM Corporation 2004, 2005", "IBM") - self.last_category = "" self.generic_sizes = [3, 4, 6, 8, 12, 16, 24, 32] self.pixel_stubs = {} self.debug = 0 @@ -661,7 +659,7 @@ generic_%u_byte( GLint rop, const void * ptr ) print(' %s_reply_t *reply = %s_reply(c, %s, NULL);' % (xcb_name, xcb_name, xcb_request)) if output: if output.is_image(): - [dim, w, h, d, junk] = output.get_dimensions() + [dim, w, h, d, _] = output.get_dimensions() if f.dimensions_in_reply: w = "reply->width" h = "reply->height" @@ -733,7 +731,7 @@ generic_%u_byte( GLint rop, const void * ptr ) for p in f.parameterIterateOutputs(): if p.is_image(): - [dim, w, h, d, junk] = p.get_dimensions() + [dim, w, h, d, _] = p.get_dimensions() if f.dimensions_in_reply: print(" __glXReadPixelReply(dpy, gc, %u, 0, 0, 0, %s, %s, %s, GL_TRUE);" % (dim, p.img_format, p.img_type, p.name)) else: @@ -802,7 +800,7 @@ generic_%u_byte( GLint rop, const void * ptr ) p_string += ", " + param.name if param.is_image(): - [dim, junk, junk, junk, junk] = param.get_dimensions() + [dim, _, _, _, _] = param.get_dimensions() if f.pad_after(param): p_string += ", 1" @@ -997,8 +995,6 @@ class PrintGlxProtoInit_h(gl_XML.gl_print_base): """Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas. (C) Copyright IBM Corporation 2004""", "PRECISION INSIGHT, IBM") self.header_tag = "_INDIRECT_H_" - - self.last_category = "" return diff --git a/src/mapi/glapi/gen/glX_proto_size.py b/src/mapi/glapi/gen/glX_proto_size.py index 5d94d856c44..98f7839a017 100644 --- a/src/mapi/glapi/gen/glX_proto_size.py +++ b/src/mapi/glapi/gen/glX_proto_size.py @@ -109,82 +109,6 @@ class glx_enum_function(object): return self.mode - def PrintUsingTable(self): - """Emit the body of the __gl*_size function using a pair - of look-up tables and a mask. The mask is calculated such - that (e & mask) is unique for all the valid values of e for - this function. The result of (e & mask) is used as an index - into the first look-up table. If it matches e, then the - same entry of the second table is returned. Otherwise zero - is returned. - - It seems like this should cause better code to be generated. - However, on x86 at least, the resulting .o file is about 20% - larger then the switch-statment version. I am leaving this - code in because the results may be different on other - platforms (e.g., PowerPC or x86-64).""" - - return 0 - count = 0 - for a in self.enums: - count += 1 - - if -1 in self.count: - return 0 - - # Determine if there is some mask M, such that M = (2^N) - 1, - # that will generate unique values for all of the enums. - - mask = 0 - for i in [1, 2, 3, 4, 5, 6, 7, 8]: - mask = (1 << i) - 1 - - fail = 0; - for a in self.enums: - for b in self.enums: - if a != b: - if (a & mask) == (b & mask): - fail = 1; - - if not fail: - break; - else: - mask = 0 - - if (mask != 0) and (mask < (2 * count)): - masked_enums = {} - masked_count = {} - - for i in range(0, mask + 1): - masked_enums[i] = "0"; - masked_count[i] = 0; - - for c in self.count: - for e in self.count[c]: - i = e & mask - enum_obj = self.enums[e][0] - masked_enums[i] = '0x%04x /* %s */' % (e, enum_obj.name ) - masked_count[i] = c - - - print(' static const GLushort a[%u] = {' % (mask + 1)) - for e in masked_enums: - print(' %s, ' % (masked_enums[e])) - print(' };') - - print(' static const GLubyte b[%u] = {' % (mask + 1)) - for c in masked_count: - print(' %u, ' % (masked_count[c])) - print(' };') - - print(' const unsigned idx = (e & 0x%02xU);' % (mask)) - print('') - print(' return (e == a[idx]) ? (GLint) b[idx] : 0;') - return 1; - else: - return 0; - - def PrintUsingSwitch(self, name): """Emit the body of the __gl*_size function using a switch-statement.""" @@ -228,10 +152,7 @@ class glx_enum_function(object): print('GLint') print('__gl%s_size( GLenum e )' % (name)) print('{') - - if not self.PrintUsingTable(): - self.PrintUsingSwitch(name) - + self.PrintUsingSwitch(name) print('}') print('') @@ -326,20 +247,6 @@ class PrintGlxSizeStubs_h(PrintGlxSizeStubs_common): print('extern GLint __gl%s_size(GLenum);' % (func.name)) -class PrintGlxReqSize_common(gl_XML.gl_print_base): - """Common base class for PrintGlxSizeReq_h and PrintGlxSizeReq_h. - - The main purpose of this common base class is to provide the infrastructure - for the derrived classes to iterate over the same set of functions. - """ - - def __init__(self): - gl_XML.gl_print_base.__init__(self) - - self.name = "glX_proto_size.py (from Mesa)" - self.license = license.bsd_license_template % ( "(C) Copyright IBM Corporation 2005", "IBM") - - def _parser(): """Parse arguments and return a namespace.""" parser = argparse.ArgumentParser() diff --git a/src/mapi/glapi/gen/gl_XML.py b/src/mapi/glapi/gen/gl_XML.py index 651c9d1bf02..ab86d660c09 100644 --- a/src/mapi/glapi/gen/gl_XML.py +++ b/src/mapi/glapi/gen/gl_XML.py @@ -298,10 +298,6 @@ class gl_type( gl_item ): return - def get_type_expression(self): - return self.type_expr - - class gl_enum( gl_item ): def __init__(self, element, context, category): gl_item.__init__(self, element, context, category) @@ -915,16 +911,6 @@ class gl_api(object): return self.functions_by_name.values() - def enumIterateByName(self): - keys = sorted(self.enums_by_name.keys()) - - list = [] - for enum in keys: - list.append( self.enums_by_name[ enum ] ) - - return iter(list) - - def categoryIterate(self): """Iterate over categories. @@ -950,10 +936,6 @@ class gl_api(object): return ["", None] - def typeIterate(self): - return self.types_by_name.values() - - def find_type( self, type_name ): if type_name in self.types_by_name: return self.types_by_name[ type_name ].type_expr diff --git a/src/mapi/glapi/gen/gl_apitemp.py b/src/mapi/glapi/gen/gl_apitemp.py index 61d73b270fb..685345a7f56 100644 --- a/src/mapi/glapi/gen/gl_apitemp.py +++ b/src/mapi/glapi/gen/gl_apitemp.py @@ -94,7 +94,7 @@ class PrintGlOffsets(gl_XML.gl_print_base): if name not in static_data.libgl_public_functions: need_proto = True elif self.es: - cat, num = api.get_category_for_name(name) + cat, _ = api.get_category_for_name(name) if (cat.startswith("es") or cat.startswith("GL_OES")): need_proto = True if need_proto: diff --git a/src/mapi/glapi/gen/gl_enums.py b/src/mapi/glapi/gen/gl_enums.py index 00305c7dfff..d880d882479 100644 --- a/src/mapi/glapi/gen/gl_enums.py +++ b/src/mapi/glapi/gen/gl_enums.py @@ -165,7 +165,7 @@ _mesa_lookup_prim_by_nr(GLuint nr) # of characters rather than as a string literal to work-around MSVC's # 65535 character limit. for enum in sorted_enum_values: - (name, pri) = self.enum_table[enum] + (name, _) = self.enum_table[enum] print(" ", end=' ') for ch in name: print("'%c'," % ch, end=' ') @@ -181,7 +181,7 @@ _mesa_lookup_prim_by_nr(GLuint nr) print('static const enum_elt enum_string_table_offsets[%u] =' % (len(self.enum_table))) print('{') for enum in sorted_enum_values: - (name, pri) = self.enum_table[enum] + (name, _) = self.enum_table[enum] print(' { %5u, 0x%08X }, /* %s */' % (string_offsets[enum], enum, name)) print('};') print('') diff --git a/src/mapi/glapi/gen/gl_procs.py b/src/mapi/glapi/gen/gl_procs.py index 30061238f7e..7a633ff8bd7 100644 --- a/src/mapi/glapi/gen/gl_procs.py +++ b/src/mapi/glapi/gen/gl_procs.py @@ -124,7 +124,7 @@ typedef struct { categories = {} for func in api.functionIterateByOffset(): for n in func.entry_points: - cat, num = api.get_category_for_name(n) + cat, _ = api.get_category_for_name(n) if (cat.startswith("es") or cat.startswith("GL_OES")): if cat not in categories: categories[cat] = [] diff --git a/src/mapi/glapi/gen/gl_x86-64_asm.py b/src/mapi/glapi/gen/gl_x86-64_asm.py index bcba43f6cf0..3ed5d1fb87e 100644 --- a/src/mapi/glapi/gen/gl_x86-64_asm.py +++ b/src/mapi/glapi/gen/gl_x86-64_asm.py @@ -31,75 +31,6 @@ import license import gl_XML, glX_XML import static_data -def should_use_push(registers): - for [reg, offset] in registers: - if reg[1:4] == "xmm": - return 0 - - N = len(registers) - return (N & 1) != 0 - - -def local_size(registers): - # The x86-64 ABI says "the value (%rsp - 8) is always a multiple of - # 16 when control is transfered to the function entry point." This - # means that the local stack usage must be (16*N)+8 for some value - # of N. (16*N)+8 = (8*(2N))+8 = 8*(2N+1). As long as N is odd, we - # meet this requirement. - - N = (len(registers) | 1) - return 8*N - - -def save_all_regs(registers): - adjust_stack = 0 - if not should_use_push(registers): - adjust_stack = local_size(registers) - print('\tsubq\t$%u, %%rsp' % (adjust_stack)) - - for [reg, stack_offset] in registers: - save_reg( reg, stack_offset, adjust_stack ) - return - - -def restore_all_regs(registers): - adjust_stack = 0 - if not should_use_push(registers): - adjust_stack = local_size(registers) - - temp = copy.deepcopy(registers) - while len(temp): - [reg, stack_offset] = temp.pop() - restore_reg(reg, stack_offset, adjust_stack) - - if adjust_stack: - print('\taddq\t$%u, %%rsp' % (adjust_stack)) - return - - -def save_reg(reg, offset, use_move): - if use_move: - if offset == 0: - print('\tmovq\t%s, (%%rsp)' % (reg)) - else: - print('\tmovq\t%s, %u(%%rsp)' % (reg, offset)) - else: - print('\tpushq\t%s' % (reg)) - - return - - -def restore_reg(reg, offset, use_move): - if use_move: - if offset == 0: - print('\tmovq\t(%%rsp), %s' % (reg)) - else: - print('\tmovq\t%u(%%rsp), %s' % (offset, reg)) - else: - print('\tpopq\t%s' % (reg)) - - return - class PrintGenericStubs(gl_XML.gl_print_base): diff --git a/src/mapi/glapi/gen/typeexpr.py b/src/mapi/glapi/gen/typeexpr.py index a5c47cd7950..49b4ae2fee5 100644 --- a/src/mapi/glapi/gen/typeexpr.py +++ b/src/mapi/glapi/gen/typeexpr.py @@ -225,10 +225,6 @@ class type_expression(object): return s - def get_base_type_node(self): - return self.expr[0] - - def get_base_name(self): if len(self.expr): return self.expr[0].name