@@ -52,7 +52,7 @@ def _showwarning(message, category, filename, lineno, file=None, line=None):
52
52
file .write (warnings .formatwarning (message , category , filename , lineno , line ))
53
53
54
54
55
- def _parse_args ():
55
+ def _get_parser ():
56
56
parser = argparse .ArgumentParser (description = __doc__ )
57
57
parser .add_argument ("-w" , action = "store_true" , help = "suppress warnings" )
58
58
parser .add_argument (
@@ -65,18 +65,7 @@ def _parse_args():
65
65
help = "the binary to use to generate the test case " "(default: llvm-mca)" ,
66
66
)
67
67
parser .add_argument ("tests" , metavar = "<test-path>" , nargs = "+" )
68
- args = common .parse_commandline_args (parser )
69
-
70
- _configure_warnings (args )
71
-
72
- if not args .llvm_mca_binary :
73
- raise Error ("--llvm-mca-binary value cannot be empty string" )
74
-
75
- if "llvm-mca" not in os .path .basename (args .llvm_mca_binary ):
76
- _warn ("unexpected binary name: {}" .format (args .llvm_mca_binary ))
77
-
78
- return args
79
-
68
+ return parser
80
69
81
70
def _get_run_infos (run_lines , args ):
82
71
run_infos = []
@@ -546,39 +535,48 @@ def _write_output(
546
535
f .writelines (["{}\n " .format (l ).encode ("utf-8" ) for l in output_lines ])
547
536
548
537
538
+ def update_test_file (args , test_path , autogenerated_note ):
539
+ sys .stderr .write ("Test: {}\n " .format (test_path ))
540
+
541
+ # Call this per test. By default each warning will only be written once
542
+ # per source location. Reset the warning filter so that now each warning
543
+ # will be written once per source location per test.
544
+ _configure_warnings (args )
545
+
546
+ with open (test_path ) as f :
547
+ input_lines = [l .rstrip () for l in f ]
548
+
549
+ run_lines = common .find_run_lines (test_path , input_lines )
550
+ run_infos = _get_run_infos (run_lines , args )
551
+ common_prefix , prefix_pad = _get_useful_prefix_info (run_infos )
552
+ block_infos = _get_block_infos (run_infos , test_path , args , common_prefix )
553
+ _write_output (
554
+ test_path ,
555
+ input_lines ,
556
+ run_infos ,
557
+ block_infos ,
558
+ args ,
559
+ common_prefix ,
560
+ prefix_pad ,
561
+ )
562
+
549
563
def main ():
550
- args = _parse_args ()
551
- test_paths = [test for pattern in args .tests for test in glob .glob (pattern )]
552
- for test_path in test_paths :
553
- sys .stderr .write ("Test: {}\n " .format (test_path ))
554
-
555
- # Call this per test. By default each warning will only be written once
556
- # per source location. Reset the warning filter so that now each warning
557
- # will be written once per source location per test.
558
- _configure_warnings (args )
559
-
560
- if not os .path .isfile (test_path ):
561
- raise Error ("could not find test file: {}" .format (test_path ))
562
-
563
- with open (test_path ) as f :
564
- input_lines = [l .rstrip () for l in f ]
565
-
566
- run_lines = common .find_run_lines (test_path , input_lines )
567
- run_infos = _get_run_infos (run_lines , args )
568
- common_prefix , prefix_pad = _get_useful_prefix_info (run_infos )
569
- block_infos = _get_block_infos (run_infos , test_path , args , common_prefix )
570
- _write_output (
571
- test_path ,
572
- input_lines ,
573
- run_infos ,
574
- block_infos ,
575
- args ,
576
- common_prefix ,
577
- prefix_pad ,
578
- )
564
+ script_name = "utils/" + os .path .basename (__file__ )
565
+ parser = _get_parser ()
566
+ args = common .parse_commandline_args (parser )
567
+ if not args .llvm_mca_binary :
568
+ raise Error ("--llvm-mca-binary value cannot be empty string" )
579
569
580
- return 0
570
+ if "llvm-mca" not in os .path .basename (args .llvm_mca_binary ):
571
+ _warn ("unexpected binary name: {}" .format (args .llvm_mca_binary ))
581
572
573
+ for ti in common .itertests (args .tests , parser , script_name = script_name ):
574
+ try :
575
+ update_test_file (ti .args , ti .path , ti .test_autogenerated_note )
576
+ except Exception :
577
+ common .warn ("Error processing file" , test_file = ti .path )
578
+ raise
579
+ return 0
582
580
583
581
if __name__ == "__main__" :
584
582
try :
0 commit comments