#!/usr/bin/env python3 # Copyright (c) The mlkem-native project authors # Copyright (c) The mldsa-native project authors # SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT import subprocess import argparse import logging import pathlib import tempfile import platform import sys import os import re def patchup_disasm(asm, cfify=False): asm = asm.split("\n") indentation = 8 def decode_label(asm_line): r = re.search(r"^\s*[0-9a-fA-F]+\s*<([a-zA-Z0-9_]+)>:\s*$", asm_line) if r is None: return None return r.group(1) def make_label(lbl): if cfify: return "L" + lbl + ":" return lbl + ":" # Find first label for i, l in enumerate(asm): if decode_label(l) is not None: break asm = asm[i + 1 :] def gen(asm): for l in asm: if l.strip() == "": yield "" continue lbl = decode_label(l) # Re-format labels as assembly labels if lbl is not None: yield make_label(lbl) continue # Drop comments l = l.split(";")[0] # Re-format references to labels # Those are assumed to have the form `0xDEADBEEF