mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
The `__future__` we relied on is now, where the 3 specific things are all included [since Python 3.0](https://docs.python.org/3/library/__future__.html): * absolute_import * print_function * unicode_literals * division These import statements are no-ops and are no longer necessary.
30 lines
988 B
Python
Executable File
30 lines
988 B
Python
Executable File
#!/usr/bin/env python3
|
|
# Check HEX -- a stupid filter that allows hexadecimal literals to be checked
|
|
# for in LLVM IR FileCheck tests. It works by replacing occurrences of
|
|
# strings matching the regex /< (i[0-9]+) \s+ (0x[0-9A-Fa-f]+) >/x with the
|
|
# decimal literal equivalent that would really appear in printed LLVM IR.
|
|
|
|
import re
|
|
import sys
|
|
|
|
hex = re.compile(r"""<(i([0-9]+)\s+)0x([0-9A-Fa-f_]+)>""")
|
|
|
|
|
|
def hexReplace(match):
|
|
# Integer type is match group 1
|
|
ty = match.group(1)
|
|
# Integer bit width is match group 2
|
|
bits = int(match.group(2))
|
|
# Hex value is match group 3
|
|
value = int(match.group(3).replace("_", ""), base=16)
|
|
# LLVM prints the decimal value as if it's two's-complement signed in
|
|
# the given bitwidth, so the printed value will be negative if
|
|
# greater than 2^(bits - 1)
|
|
if value >= (1 << (bits - 1)):
|
|
value -= 1 << bits
|
|
return ty + str(value)
|
|
|
|
|
|
for line in sys.stdin:
|
|
print(re.sub(hex, hexReplace, line), end="")
|