CodeSampleX

サンプル

llvmlite 0.49.0rc1: llvmlite

検証済みサンプル — pypi llvmlite 0.49.0rc1: llvmlite. python 3.12 · linux debian/x64 · docker で contract を実行し、成功しました: llvmlite module exposes __version__ string and…

sha256:1994dcfaa8cba0cbd4a2f0559caded2f1946fddaec0186828a6f91d5370a8c03

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 MIT-0

実行証拠

宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。

証拠の基準
署名済みコントラクト合格
検証レシート
1
ビルドした署名鍵
1
宣言された環境 linux 24 · ubuntu · glibc 2.39 x64 pip

検証実行環境

環境 コントラクト ステージ 実行日
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-19

ケース

HOW
ゴール
verify llvmlite in pkg:pypi/llvmlite@0.49.0rc1
パッケージ
シンボル
  • llvmlite
作成日
2026-09-17T16:27:17Z

コントラクト

  1. llvmlite module exposes __version__ string and binding llvm_version_info tuple
  2. llvmlite.binding.initialize raises RuntimeError notifying that LLVM initialization is handled automatically
  3. llvmlite.binding initializes native target and asmprinter for default triple
  4. llvmlite.ir creates module, function, basic block and builds integer addition instructions
  5. llvmlite.binding.parse_assembly parses LLVM IR string and verifies module without errors
  6. llvmlite.binding.create_mcjit_compiler compiles function and executes via ctypes returning expected result

ファイル

  • PROMPT.md
  • csx.json
  • requirements.txt
  • sample.py
  • 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 llvmlite in pkg:pypi/llvmlite@0.49.0rc1
Kind: HOW

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

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:23ae6e42c10bf04ebcf76a0e7305eaa76307a0c4d61ee4e3e0d37413ca8ba89e","contract":["llvmlite module exposes __version__ string and binding llvm_version_info tuple","llvmlite.binding.initialize raises RuntimeError notifying that LLVM initialization is handled automatically","llvmlite.binding initializes native target and asmprinter for default triple","llvmlite.ir creates module, function, basic block and builds integer addition instructions","llvmlite.binding.parse_assembly parses LLVM IR string and verifies module without errors","llvmlite.binding.create_mcjit_compiler compiles function and executes via ctypes returning expected result"],"goal":"verify llvmlite in pkg:pypi/llvmlite@0.49.0rc1","kind":"HOW","packages":["pkg:pypi/llvmlite@0.49.0rc1"],"schemaVersion":1,"symbols":["llvmlite"]},"contractCommand":["python","test/contract.py"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"pypi","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"pip","schemaVersion":1},"license":"MIT-0","packages":["pkg:pypi/llvmlite@0.49.0rc1"],"schemaVersion":1,"subject":"pkg:pypi/llvmlite@0.49.0rc1","symbols":["llvmlite"],"verifierAdapter":"python@1"}
requirements.txt
llvmlite==0.49.0rc1
sample.py
"""Sample demonstrating IR generation and execution using llvmlite."""

import ctypes
from typing import Tuple
import llvmlite
import llvmlite.binding as llvm
import llvmlite.ir as ir


def get_llvmlite_version() -> str:
    """Return llvmlite package version string."""
    return llvmlite.__version__


def get_llvm_version() -> Tuple[int, ...]:
    """Return LLVM version tuple."""
    return llvm.llvm_version_info


def build_add_ir() -> str:
    """Construct an LLVM IR module containing an integer addition function."""
    mod = ir.Module(name="adder_module")
    i32 = ir.IntType(32)
    fnty = ir.FunctionType(i32, [i32, i32])
    func = ir.Function(mod, fnty, name="add_two")
    block = func.append_basic_block(name="entry")
    builder = ir.IRBuilder(block)

    result = builder.add(func.args[0], func.args[1], name="sum_val")
    builder.ret(result)
    return str(mod)


def compile_and_run_adder(a: int, b: int) -> int:
    """Parse, verify, JIT-compile the addition function, and execute it."""
    llvm.initialize_native_target()
    llvm.initialize_native_asmprinter()

    ir_code = build_add_ir()
    parsed_mod = llvm.parse_assembly(ir_code)
    parsed_mod.verify()

    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)
    engine.add_module(parsed_mod)
    engine.finalize_object()
    engine.run_static_constructors()

    func_ptr = engine.get_function_address("add_two")
    c_func = ctypes.CFUNCTYPE(ctypes.c_int32, ctypes.c_int32, ctypes.c_int32)(func_ptr)
    return int(c_func(a, b))
spec.json
{
  "schemaVersion": 1,
  "goal": "verify llvmlite in pkg:pypi/llvmlite@0.49.0rc1",
  "kind": "HOW",
  "packages": [
    "pkg:pypi/llvmlite@0.49.0rc1"
  ],
  "symbols": [
    "llvmlite"
  ]
}
test/contract.py
"""Contract verification tests for llvmlite."""

import os
import sys

# Ensure project root is in sys.path
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

import llvmlite
import llvmlite.binding as llvm
import llvmlite.ir as ir
import sample


def test_version_info() -> None:
    """Assertion 1: llvmlite module exposes __version__ string and binding llvm_version_info tuple."""
    ver = sample.get_llvmlite_version()
    assert isinstance(ver, str)
    assert len(ver) > 0
    assert ver == llvmlite.__version__

    llvm_ver = sample.get_llvm_version()
    assert isinstance(llvm_ver, tuple)
    assert len(llvm_ver) >= 2
    assert llvm_ver == llvm.llvm_version_info


def test_initialization_deprecation() -> None:
    """Assertion 2: llvmlite.binding.initialize raises RuntimeError notifying that LLVM initialization is handled automatically."""
    raised = False
    try:
        llvm.initialize()
    except RuntimeError as exc:
        raised = True
        assert "deprecated" in str(exc) or "automatically" in str(exc)
    assert raised, "Expected llvm.initialize() to raise RuntimeError"


def test_native_target_initialization() -> None:
    """Assertion 3: llvmlite.binding initializes native target and asmprinter for default triple."""
    llvm.initialize_native_target()
    llvm.initialize_native_asmprinter()
    target = llvm.Target.from_default_triple()
    assert target is not None
    assert isinstance(target.name, str)
    assert len(target.name) > 0

    machine = target.create_target_machine()
    assert machine is not None
    assert isinstance(machine.triple, str)
    assert len(machine.triple) > 0


def test_ir_module_generation() -> None:
    """Assertion 4: llvmlite.ir creates module, function, basic block and builds integer addition instructions."""
    ir_text = sample.build_add_ir()
    assert isinstance(ir_text, str)
    assert 'ModuleID = "adder_module"' in ir_text
    assert "add_two" in ir_text
    assert "add i32" in ir_text
    assert "ret i32" in ir_text


def test_assembly_parsing_and_verification() -> None:
    """Assertion 5: llvmlite.binding.parse_assembly parses LLVM IR string and verifies module without errors."""
    ir_text = sample.build_add_ir()
    parsed_mod = llvm.parse_assembly(ir_text)
    assert parsed_mod is not None
    assert parsed_mod.verify() is None

    fn = parsed_mod.get_function("add_two")
    assert fn is not None
    assert fn.name == "add_two"


def test_jit_compilation_and_execution() -> None:
    """Assertion 6: llvmlite.binding.create_mcjit_compiler compiles function and executes via ctypes returning expected result."""
    result = sample.compile_and_run_adder(17, 25)
    assert result == 42

    result2 = sample.compile_and_run_adder(-10, 30)
    assert result2 == 20


def main() -> None:
    test_version_info()
    test_initialization_deprecation()
    test_native_target_initialization()
    test_ir_module_generation()
    test_assembly_parsing_and_verification()
    test_jit_compilation_and_execution()
    print("All contract assertions passed.")


if __name__ == "__main__":
    main()

オリジンシーダー

匿名