The tools are renamed after their input and output: zi2zx lowers source or ZIR to executable ZX, zx2native turns ZX into a native ELF, zx2wasm into a wasm32 module, and zi2c, zi2go and zi2zir keep their roles under cmd/ folders of the same names. zi2asm and the cmd/zir-* folders are gone, and tests/tool_names.sh keeps the old names out. zx2native keeps the direct encoder as its default; the machine pipeline replaces it once it reaches parity. The embedding API can run a verified bundle as x86-64 machine code in memory. Code is written to RW pages, relocated, then switched to RX, never RWX, and each instance gets its own data (cmd/zir/zir_native_memory.c, zir_host_native.c). Backend selection is BundleBackendPolicy: Engine and Native are strict, and Auto chooses by platform only, never by whether one program fits. A native gap is a named error, never a switch to the engine. Desktop x86-64 Auto stays on the engine until the native backend is complete. cmd/compiler_machine_image.zi adds the target-neutral machine image contract. The machine verifiers reject unknown relocation kinds, out-of-range symbols and addends, non-host external calls, native-width mismatches and missing stack or fuel facts. The machine pipeline lowers and encodes more of LIR. Docs, site pages, Kryon's build references and the benchmarks use the new names. Co-Authored-By: Claude Opus 5.5 <[email protected]>
94 lines
4.3 KiB
Python
Executable File
94 lines
4.3 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""Measure enum-heavy source checks and portable loading against preserved tools."""
|
|
import argparse
|
|
import hashlib
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
import subprocess
|
|
import sys
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
|
|
|
|
def fixture(size, iterations):
|
|
values = [7 + 3 * index for index in range(size)]
|
|
members = '\n'.join(f'V{index} :: {value};' for index, value in enumerate(values))
|
|
uses = '\n'.join(f'total += cast(s64)(Value.V{index});' for index in range(size))
|
|
source = f'''Value :: enum s64 {{
|
|
{members}
|
|
}}
|
|
#program_export
|
|
Answer :: () -> s64 {{
|
|
total: s64 = 0
|
|
for 0..{iterations - 1} {{
|
|
{uses}
|
|
}}
|
|
return total
|
|
}}
|
|
'''
|
|
return source, sum(values) * iterations
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument('--before-dir', type=Path, required=True)
|
|
parser.add_argument('--out', type=Path, required=True)
|
|
parser.add_argument('--sizes', type=int, nargs='+', default=[32, 128])
|
|
parser.add_argument('--iterations', type=int, default=32)
|
|
parser.add_argument('--repetitions', type=int, default=9)
|
|
parser.add_argument('--runs', type=int, default=9)
|
|
parser.add_argument('--project', nargs=3, action='append', default=[],
|
|
metavar=('NAME', 'ROOT', 'ENTRY'))
|
|
args = parser.parse_args()
|
|
if not args.sizes or len(set(args.sizes)) != len(args.sizes) or any(
|
|
size < 1 or size > 256 for size in args.sizes):
|
|
parser.error('unique enum sizes from 1 to 256 required')
|
|
if not 1 <= args.iterations <= 128 or args.repetitions < 1 or not 1 <= args.runs <= 10000:
|
|
parser.error('iterations 1..128, positive repetitions and runs 1..10000 required')
|
|
before = args.before_dir.resolve()
|
|
for name in ['zi2zir', 'zi2zx', 'libziran.a']:
|
|
if not (before/name).is_file(): parser.error(f'missing preserved baseline: {name}')
|
|
output = args.out.resolve()
|
|
if output.exists():
|
|
parser.error('archive needed receipts and remove inactive outputs before reusing --out')
|
|
output.mkdir(parents=True)
|
|
env = dict(os.environ)
|
|
for name in ['DISPLAY', 'WAYLAND_DISPLAY', 'XAUTHORITY', 'DBUS_SESSION_BUS_ADDRESS',
|
|
'ZIRAN_PROFILE', 'ZIRAN_VM_PROFILE']:
|
|
env.pop(name, None)
|
|
command = [sys.executable, str(ROOT/'bench/vm_startup.py'),
|
|
'--before-dir', str(before), '--out', str(output/'comparison'),
|
|
'--repetitions', str(args.repetitions), '--runs', str(args.runs)]
|
|
manifest = dict(generator_sha256=hashlib.sha256(Path(__file__).read_bytes()).hexdigest(),
|
|
iterations=args.iterations, cases=[],
|
|
oracle='Sum the explicit integer sequence 7 + 3*i, then multiply by loop iterations.')
|
|
for size in args.sizes:
|
|
directory = output/f'enums-{size}'
|
|
directory.mkdir()
|
|
source, expected = fixture(size, args.iterations)
|
|
entry = directory/'values.zi'
|
|
entry.write_text(source)
|
|
bundle = directory/'values.zx'
|
|
commands = [
|
|
[ROOT/'build/bin/zi2zir', '--root', directory, '-o', directory/'ir', entry],
|
|
[ROOT/'build/bin/zi2zx', '--root', directory, '--entry', 'values:Answer', '-o', bundle, entry],
|
|
[ROOT/'build/bin/zi2zx', '--root', directory/'ir', '--entry', 'values:Answer',
|
|
'-o', directory/'saved.zx', directory/'ir/values.zir'],
|
|
]
|
|
for argv in commands:
|
|
subprocess.run([str(part) for part in argv], cwd=ROOT, env=env, check=True)
|
|
if bundle.read_bytes() != (directory/'saved.zx').read_bytes():
|
|
raise AssertionError('source and saved enum bundles differ')
|
|
manifest['cases'].append(dict(size=size, source=str(entry), bundle=str(bundle), expected=expected,
|
|
source_sha256=hashlib.sha256(entry.read_bytes()).hexdigest(),
|
|
bundle_sha256=hashlib.sha256(bundle.read_bytes()).hexdigest()))
|
|
command.extend(['--case', f'enums{size}', str(entry), str(bundle), str(expected)])
|
|
for project in args.project: command.extend(['--project', *project])
|
|
(output/'fixtures.json').write_text(json.dumps(manifest, indent=2)+'\n')
|
|
subprocess.run(command, cwd=ROOT, env=env, check=True)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|