CodeSampleX

Ejemplo

llvmlite 0.49.0rc1: binding.create_mcjit_compiler

Muestra verificada para pypi llvmlite 0.49.0rc1: binding.create_mcjit_compiler. El contrato se ejecutó en python 3.12 · linux debian/x64 · docker y pasó.

sha256:f20775a4605b008c741b95d64029ea8a39cec91dd62ee0c2e50035885d5282d5

Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido. Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas. MIT-0

Evidencia de ejecución

El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.

Base de evidencia
Contrato firmado aprobado
Recibos de verificación
1
Claves de firma que lo compilaron
1
Entorno declarado python 3.12 linux 24 · ubuntu · glibc 2.39 x64 python 3.12 python pip 24

Entornos de las ejecuciones de verificación

Entorno Contrato Etapas Ejecución
python 3.12 · linux debian/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · python@1python:3.12-slim@sha256:09f7da3bc104…
2026-09-07

Caso

HOW
Objetivo
verify pkg:pypi/llvmlite@0.49.0rc1
Paquetes
Símbolos
  • llvmlite.binding.create_mcjit_compiler
Entorno
python 3.12
Creado
2026-09-07T07:02:19Z

Contrato

  1. llvmlite.binding native target and asmprinter initialization
  2. llvmlite.ir.Module and IRBuilder construct typed functions with arithmetic instructions
  3. llvmlite.binding.parse_assembly parses IR assembly string into verified ModuleRef
  4. llvmlite.binding.create_mcjit_compiler compiles module and retrieves executable function pointer

Archivos

  • PROMPT.md
  • csx.json
  • requirements.txt
  • spec.json
  • test/contract.py

Descargar el artefacto de código fuente (tar.gz)

Código fuente

PROMPT.md
Clean-room public code sample — generation instructions

Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.

A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.

Goal: verify pkg:pypi/llvmlite@0.49.0rc1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:pypi/llvmlite@0.49.0rc1

Rules:
  - One focused purpose; the smallest project that proves the goal.
  - Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
  - Pin every dependency with a lockfile so resolution is reproducible.
  - No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
  - No personal names, emails, company names, or project identifiers of any kind.
  - No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
  - Keep it under 200 files and 256KB packed.
csx.json
{"case":{"caseId":"case:sha256:0894e9153d28ab0c975f32f37a3ea658a87b5b4d08bcf00a5ec5cfd1441f4c71","contract":["llvmlite.binding native target and asmprinter initialization","llvmlite.ir.Module and IRBuilder construct typed functions with arithmetic instructions","llvmlite.binding.parse_assembly parses IR assembly string into verified ModuleRef","llvmlite.binding.create_mcjit_compiler compiles module and retrieves executable function pointer"],"goal":"verify pkg:pypi/llvmlite@0.49.0rc1","kind":"HOW","packages":["pkg:pypi/llvmlite@0.49.0rc1"],"schemaVersion":1,"symbols":["llvmlite.binding.create_mcjit_compiler"]},"contractCommand":["python","test/contract.py"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"pypi","executionContext":"python","language":"python","libc":"glibc","libcVersion":"2.39","moduleSystem":"standard","os":"linux","osVersionBucket":"24","packageManager":"pip","packageManagerVersion":"24.0","runtime":"python","runtimeVersion":"3.12","schemaVersion":1},"license":"MIT-0","packages":["pkg:pypi/llvmlite@0.49.0rc1"],"schemaVersion":1,"subject":"pkg:pypi/llvmlite@0.49.0rc1","symbols":["llvmlite.binding.create_mcjit_compiler"],"verifierAdapter":"python@1"}
requirements.txt
llvmlite==0.49.0rc1
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:pypi/llvmlite@0.49.0rc1",
  "kind": "HOW",
  "packages": [
    "pkg:pypi/llvmlite@0.49.0rc1"
  ],
  "symbols": [
    "llvmlite.binding.create_mcjit_compiler"
  ]
}
test/contract.py
import ctypes
import llvmlite
import llvmlite.binding as llvm
import llvmlite.ir as ir


def test_native_initialization() -> None:
    llvm.initialize_native_target()
    llvm.initialize_native_asmprinter()
    triple = llvm.get_default_triple()
    assert isinstance(triple, str) and len(triple) > 0


def test_ir_module_builder() -> str:
    module = ir.Module(name="mcjit_contract_mod")
    i32 = ir.IntType(32)
    func_type = ir.FunctionType(i32, [i32, i32])
    func = ir.Function(module, func_type, name="compute")
    block = func.append_basic_block(name="entry")
    builder = ir.IRBuilder(block)

    a, b = func.args
    prod = builder.mul(a, b, name="prod")
    result = builder.add(prod, ir.Constant(i32, 7), name="res")
    builder.ret(result)

    ir_str = str(module)
    assert "compute" in ir_str
    assert "mul" in ir_str
    assert "add" in ir_str
    assert "ret i32" in ir_str
    return ir_str


def test_parse_assembly_and_verify(ir_str: str) -> llvm.ModuleRef:
    mod = llvm.parse_assembly(ir_str)
    assert mod is not None
    mod.verify()
    return mod


def test_create_mcjit_compiler_and_execute(mod: llvm.ModuleRef) -> None:
    target = llvm.Target.from_default_triple()
    target_machine = target.create_target_machine()
    backing_mod = llvm.parse_assembly("")
    engine = llvm.create_mcjit_compiler(backing_mod, target_machine)
    assert engine is not None

    engine.add_module(mod)
    engine.finalize_object()
    engine.run_static_constructors()

    func_ptr = engine.get_function_address("compute")
    assert func_ptr != 0, "Function pointer must not be null"

    c_func = ctypes.CFUNCTYPE(ctypes.c_int32, ctypes.c_int32, ctypes.c_int32)(func_ptr)
    # (5 * 6) + 7 = 37
    assert c_func(5, 6) == 37
    # (0 * 10) + 7 = 7
    assert c_func(0, 10) == 7


def main() -> None:
    test_native_initialization()
    ir_str = test_ir_module_builder()
    mod = test_parse_assembly_and_verify(ir_str)
    test_create_mcjit_compiler_and_execute(mod)
    print("All contract assertions passed successfully.")


if __name__ == "__main__":
    main()

Seeder de origen

anónimo