import subprocess
import re
disassembly = subprocess.check_output(
["llvm-objdump-18", "-d", "encode.o", "--no-print-imm-hex"]
).splitlines()
for line in disassembly:
m = re.match(
r"^\s*[0-9a-f]+:\s*(?:([0-9a-f]{4}) ?([0-9a-f]{4})?)\s*(\S+)\t?([^;<@]*)(@.*)?(<.*>\s*)?(;.*)?$",
line.decode(),
)
if m is not None:
hw1 = bytes.fromhex(m.groups()[0])
data = bytearray([hw1[1], hw1[0]])
if m.groups()[1] is not None:
hw2 = bytes.fromhex(m.groups()[1])
data += bytes([hw2[1], hw2[0]])
op = m.groups()[2]
args = m.groups()[3].lower().strip()
vector = f"{data.hex():<8} {op:<9}{args}".strip()
print(vector)