| 64 | |
| 65 | |
| 66 | def add_branch_hints(hint_file, weight, branch_hints, builtin_hashes): |
| 67 | try: |
| 68 | with open(hint_file, "r") as f: |
| 69 | for line in f.readlines(): |
| 70 | fields = line.split(',') |
| 71 | if fields[0] == BRANCH_HINT_MARKER: |
| 72 | builtin_name = fields[1] |
| 73 | true_block_id = int(fields[2]) |
| 74 | false_block_id = int(fields[3]) |
| 75 | key = (builtin_name, true_block_id, false_block_id) |
| 76 | delta = weight if (int(fields[4]) > 0) else -weight |
| 77 | if key not in branch_hints: |
| 78 | if must_agree: |
| 79 | # The boolean value records whether or not any conflicts have been |
| 80 | # found for this branch. |
| 81 | initial_hint = (False, 0) |
| 82 | else: |
| 83 | initial_hint = 0 |
| 84 | branch_hints[key] = initial_hint |
| 85 | if must_agree: |
| 86 | (has_conflicts, count) = branch_hints[key] |
| 87 | if not has_conflicts: |
| 88 | if abs(delta) + abs(count) == abs(delta + count): |
| 89 | branch_hints[key] = (False, count + delta) |
| 90 | else: |
| 91 | branch_hints[key] = (True, 0) |
| 92 | else: |
| 93 | branch_hints[key] += delta |
| 94 | elif fields[0] == BUILTIN_HASH_MARKER: |
| 95 | builtin_name = fields[1] |
| 96 | builtin_hash = int(fields[2]) |
| 97 | if builtin_name in builtin_hashes: |
| 98 | if builtin_hashes[builtin_name] != builtin_hash: |
| 99 | print("Builtin hashes {} and {} for {} do not match.".format( |
| 100 | builtin_hashes[builtin_name], builtin_hash, builtin_name)) |
| 101 | sys.exit(1) |
| 102 | else: |
| 103 | builtin_hashes[builtin_name] = builtin_hash |
| 104 | except IOError as e: |
| 105 | print("Cannot read from {}. {}.".format(hint_file, e.strerror)) |
| 106 | sys.exit(1) |
| 107 | |
| 108 | |
| 109 | def write_hints_to_output(output_file, branch_hints, builtin_hashes): |