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

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. 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()

오리진 시더

익명