mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-05 16:08:04 +02:00
gallium/tools: fixes to option handling
Not all options in the options object are set by all tools. Instead of using argparse result objects directly, use separate with default settings and copy relevant attributes there. Signed-off-by: Matti Hamalainen <ccr@tnsp.org> Reviewed-by: Jose Fonseca <jfonseca@vmware.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17108>
This commit is contained in:
parent
50b21fb6e4
commit
11ac33c2a9
3 changed files with 50 additions and 3 deletions
|
|
@ -789,6 +789,18 @@ class Interpreter(parser.SimpleTraceDumper):
|
|||
return self.options.verbosity >= level
|
||||
|
||||
|
||||
class DumpStateOptions(parser.ParseOptions):
|
||||
|
||||
def __init__(self, args=None):
|
||||
|
||||
# These will get initialized in ModelOptions.__init__()
|
||||
self.verbosity = None
|
||||
self.call = None
|
||||
self.draw = None
|
||||
|
||||
parser.ParseOptions.__init__(self, args)
|
||||
|
||||
|
||||
class Main(parser.Main):
|
||||
|
||||
def get_optparser(self):
|
||||
|
|
@ -804,6 +816,9 @@ class Main(parser.Main):
|
|||
optparser.add_argument("-d", "--draw", action="store", type=int, dest="draw", default=0xffffffff, help="dump on this draw")
|
||||
return optparser
|
||||
|
||||
def make_options(self, args):
|
||||
return DumpStateOptions(args)
|
||||
|
||||
def process_arg(self, stream, options):
|
||||
formatter = format.Formatter(sys.stderr)
|
||||
parser = Interpreter(stream, options, formatter)
|
||||
|
|
|
|||
|
|
@ -37,6 +37,25 @@ from io import StringIO
|
|||
import format
|
||||
|
||||
|
||||
class ModelOptions:
|
||||
|
||||
def __init__(self, args=None):
|
||||
# Initialize the options we need to exist,
|
||||
# with some reasonable defaults
|
||||
self.plain = False
|
||||
self.suppress_variants = False
|
||||
self.named_ptrs = False
|
||||
self.method_only = False
|
||||
|
||||
# If args is specified, we assume it is the result object
|
||||
# from ArgumentParser.parse_args(). Copy the attribute values
|
||||
# we have from it, if they exist.
|
||||
if args is not None:
|
||||
for var in self.__dict__:
|
||||
if var in args.__dict__:
|
||||
self.__dict__[var] = args.__dict__[var]
|
||||
|
||||
|
||||
class Node:
|
||||
|
||||
def visit(self, visitor):
|
||||
|
|
@ -238,7 +257,7 @@ class PrettyPrinter:
|
|||
self.formatter.text('}')
|
||||
|
||||
def visit_pointer(self, node):
|
||||
if "named_ptrs" in self.options and self.options.named_ptrs:
|
||||
if self.options.named_ptrs:
|
||||
self.formatter.address(node.ptr_list[node.address])
|
||||
else:
|
||||
self.formatter.address(node.address)
|
||||
|
|
|
|||
|
|
@ -382,7 +382,16 @@ class TraceDumper(SimpleTraceDumper):
|
|||
for call in self.call_stack:
|
||||
call.visit(self.pretty_printer)
|
||||
self.formatter.newline()
|
||||
|
||||
|
||||
|
||||
class ParseOptions(ModelOptions):
|
||||
|
||||
def __init__(self, args=None):
|
||||
# Initialize options local to this module
|
||||
self.plain = False
|
||||
|
||||
ModelOptions.__init__(self, args)
|
||||
|
||||
|
||||
class Main:
|
||||
'''Common main class for all retrace command line utilities.'''
|
||||
|
|
@ -393,6 +402,7 @@ class Main:
|
|||
def main(self):
|
||||
optparser = self.get_optparser()
|
||||
args = optparser.parse_args()
|
||||
options = self.make_options(args)
|
||||
|
||||
for fname in args.filename:
|
||||
try:
|
||||
|
|
@ -408,7 +418,10 @@ class Main:
|
|||
print("ERROR: {}".format(str(e)))
|
||||
sys.exit(1)
|
||||
|
||||
self.process_arg(stream, args)
|
||||
self.process_arg(stream, options)
|
||||
|
||||
def make_options(self, args):
|
||||
return ParseOptions(args)
|
||||
|
||||
def get_optparser(self):
|
||||
optparser = argparse.ArgumentParser(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue