1#!/usr/bin/env python3 2# -*- coding: utf-8 -*- 3# Copyright 2020 The ChromiumOS Authors 4# Use of this source code is governed by a BSD-style license that can be 5# found in the LICENSE file. 6 7"""Command script without compiler support for pass level bisection. 8 9This script generates a pseudo log which a workable compiler should print out. 10It assumes that -opt-bisect-limit and -print-debug-counter are supported by the 11compiler. 12""" 13 14 15import os 16import sys 17 18from binary_search_tool.test import common 19 20 21def Main(argv): 22 if not os.path.exists("./is_setup"): 23 return 1 24 25 if len(argv) != 3: 26 return 1 27 28 limit_flags = os.environ["LIMIT_FLAGS"] 29 opt_bisect_exist = False 30 debug_counter_exist = False 31 32 for option in limit_flags.split(): 33 if "-opt-bisect-limit" in option: 34 opt_bisect_limit = int(option.split("=")[-1]) 35 opt_bisect_exist = True 36 if "-debug-counter=" in option: 37 debug_counter = int(option.split("=")[-1]) 38 debug_counter_exist = True 39 40 if not opt_bisect_exist: 41 return 1 42 43 # Manually set total number and bad number 44 total_pass = 10 45 total_transform = 20 46 bad_pass = int(argv[1]) 47 bad_transform = int(argv[2]) 48 49 if opt_bisect_limit == -1: 50 opt_bisect_limit = total_pass 51 52 for i in range(1, total_pass + 1): 53 bisect_str = ( 54 "BISECT: %srunning pass (%d) Combine redundant " 55 "instructions on function (f1)" 56 % ("NOT " if i > opt_bisect_limit else "", i) 57 ) 58 print(bisect_str, file=sys.stderr) 59 60 if debug_counter_exist: 61 print("Counters and values:", file=sys.stderr) 62 print( 63 "instcombine-visit : {%d, 0, %d}" 64 % (total_transform, debug_counter), 65 file=sys.stderr, 66 ) 67 68 if opt_bisect_limit > bad_pass or ( 69 debug_counter_exist and debug_counter > bad_transform 70 ): 71 common.WriteWorkingSet([1]) 72 else: 73 common.WriteWorkingSet([0]) 74 75 return 0 76 77 78if __name__ == "__main__": 79 retval = Main(sys.argv) 80 sys.exit(retval) 81