mirror of
https://github.com/LLVMParty/llvm-nanobind
synced 2026-06-21 13:43:38 +00:00
1.9 KiB
1.9 KiB
Attribute API Refactor
Moved attribute management functions from module scope to object methods.
Summary
Refactored 7 global functions into methods on Function, Value, and Context classes following the API design philosophy of "methods belong to objects."
API Changes
Function Attributes → Function Methods
| Before | After |
|---|---|
llvm.add_attribute_at_index(fn, idx, attr) |
fn.add_attribute(idx, attr) |
llvm.get_enum_attribute_at_index(fn, idx, kind) |
fn.get_enum_attribute(idx, kind) |
llvm.get_attribute_count_at_index(fn, idx) |
fn.get_attribute_count(idx) |
Call Site Attributes → Value Methods
| Before | After |
|---|---|
llvm.add_callsite_attribute(call, idx, attr) |
call.add_callsite_attribute(idx, attr) |
llvm.get_callsite_enum_attribute(call, idx, kind) |
call.get_callsite_enum_attribute(idx, kind) |
llvm.get_callsite_attribute_count(call, idx) |
call.get_callsite_attribute_count(idx) |
Attribute Creation → Context Method
| Before | After |
|---|---|
llvm.create_enum_attribute(ctx, kind, val) |
ctx.create_enum_attribute(kind, val) |
Kept Global
llvm.get_last_enum_attribute_kind()- static registry lookup, no object context needed
Key Implementation Details
- Function methods added to
LLVMFunctionWrapperstruct - Call site methods added to
LLVMValueWrapperwith internal assertions for call/invoke instructions - Method naming: Used
add_callsite_attributeinstead ofadd_attributeon Value to avoid confusion with function attributes - No backward compatibility - old global functions were completely removed
Files Modified
src/llvm-nanobind.cpp- Added methods, removed globalsllvm_c_test/attributes.py- Updated to new APIllvm_c_test/echo.py- Updated attribute cloning inclone_attrs()
Completed
December 2025