CodeSampleX

示例

llvmlite 0.49.0rc1: binding.create_mcjit_compiler

已验证示例 — pypi llvmlite 0.49.0rc1: binding.create_mcjit_compiler. contract 在 python 3.12 · linux debian/x64 · docker 上运行并通过: llvmlite.binding native target and…

sha256:f20775a4605b008c741b95d64029ea8a39cec91dd62ee0c2e50035885d5282d5

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。 MIT-0

执行证据

声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。

证据依据
签名契约通过
验证回执
1
构建过它的签名密钥
1
声明的环境 python 3.12 linux 24 · ubuntu · glibc 2.39 x64 python 3.12 python pip 24

验证运行环境

环境 契约 阶段 运行日期
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

案例

HOW
目标
verify pkg:pypi/llvmlite@0.49.0rc1
包
符号
  • llvmlite.binding.create_mcjit_compiler
环境
python 3.12
创建时间
2026-09-07T07:02:19Z

契约

  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

文件

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

下载源代码构件 (tar.gz)

源代码

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()

原始种子者

匿名