Files
TheRock/compiler/amd-llvm/llvm/utils/convert-constraint-log-to-z3.py
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

72 lines
1.7 KiB
Python
Executable File

#!/usr/bin/env python
"""
Helper script to convert the log generated by '-debug-only=constraint-system'
to a Python script that uses Z3 to verify the decisions using Z3's Python API.
Example usage:
> cat path/to/file.log
---
x6 + -1 * x7 <= -1
x6 + -1 * x7 <= -2
sat
> ./convert-constraint-log-to-z3.py path/to/file.log > check.py && python ./check.py
> cat check.py
from z3 import *
x3 = Int("x3")
x1 = Int("x1")
x2 = Int("x2")
s = Solver()
s.add(x1 + -1 * x2 <= 0)
s.add(x2 + -1 * x3 <= 0)
s.add(-1 * x1 + x3 <= -1)
assert(s.check() == unsat)
print('all checks passed')
"""
import argparse
import re
def main():
parser = argparse.ArgumentParser(
description="Convert constraint log to script to verify using Z3."
)
parser.add_argument(
"log_file", metavar="log", type=str, help="constraint-system log file"
)
args = parser.parse_args()
content = ""
with open(args.log_file, "rt") as f:
content = f.read()
groups = content.split("---")
var_re = re.compile("x\d+")
print("from z3 import *")
for group in groups:
constraints = [g.strip() for g in group.split("\n") if g.strip() != ""]
variables = set()
for c in constraints[:-1]:
for m in var_re.finditer(c):
variables.add(m.group())
if len(variables) == 0:
continue
for v in variables:
print('{} = Int("{}")'.format(v, v))
print("s = Solver()")
for c in constraints[:-1]:
print("s.add({})".format(c))
expected = constraints[-1].strip()
print("assert(s.check() == {})".format(expected))
print('print("all checks passed")')
if __name__ == "__main__":
main()