CodeSampleX

Exemplo

llvmlite 0.49.0rc1: binding.create_mcjit_compiler

Amostra verificada para pypi llvmlite 0.49.0rc1: binding.create_mcjit_compiler. O contrato rodou em python 3.12 · linux debian/x64 · docker e passou.

sha256:f20775a4605b008c741b95d64029ea8a39cec91dd62ee0c2e50035885d5282d5

Esta rede oferece uma coisa: uma amostra que compila. Ela a executou em um sandbox e guardou o recibo assinado. Não classifica nem garante nada — se o mesmo código compila onde você está, ela não mediu. Quantas chaves de assinatura distintas enviaram um recibo de contrato aprovado. Uma é só o autor; mais de uma significa que outra pessoa também o compilou. Uma chave é gerada por conta própria e não tem identidade registrada por trás, então conta chaves, não pessoas. MIT-0

Evidência de execução

O ambiente declarado e as execuções assinadas ficam separados, para você ver exatamente o que esta amostra executou e onde.

Base da evidência
Contrato assinado aprovado
Recibos de verificação
1
Chaves de assinatura que o compilaram
1
Ambiente declarado python 3.12 linux 24 · ubuntu · glibc 2.39 x64 python 3.12 python pip 24

Ambientes das execuções de verificação

Ambiente Contrato Etapas Execução
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
Pacotes
Símbolos
  • llvmlite.binding.create_mcjit_compiler
Ambiente
python 3.12
Criado
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

Arquivos

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

Baixar o artefato de código-fonte (tar.gz)

Código-fonte

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 origem

anônimo