Skip to content

Add managed accessors for types, values, constants, and globals - #261

Merged
tannergooding merged 1 commit into
dotnet:mainfrom
tannergooding:tannergooding-cpp-api-surface-gaps
Jul 15, 2026
Merged

Add managed accessors for types, values, constants, and globals#261
tannergooding merged 1 commit into
dotnet:mainfrom
tannergooding:tannergooding-cpp-api-surface-gaps

Conversation

@tannergooding

Copy link
Copy Markdown
Member

Fills in the high-level C++-mirroring managed API (sources/LLVMSharp) with the self-contained accessors that need no libLLVMSharp native support. This is the first of three slices: the instruction, module, and context/target surface follows in later PRs, and the native-dependent accessors come after the libLLVMSharp helpers land.

To let wrapper-returning accessors reach their owning context without threading it through every constructor, this mirrors ClangSharp's ownership model: LLVMContext keeps a static weak registry keyed by LLVMContextRef, and Value/Type recover their managed context from their own handle (Handle.Context).


Added managed surface:

  • TypesType predicates, Context, ScalarType, Dump/PrintToString; IntegerType.BitWidth; SequentialType.ElementType; ArrayType/VectorType.NumElements; PointerType.AddressSpace; FunctionType return/params/vararg; StructType name/packed/opaque/elements/SetBody.
  • Value/UserContext, Kind, Name, Type, Dump, PrintToString; NumOperands, GetOperand, SetOperand.
  • ConstantsIsNullValue, GetAggregateElement; ConstantInt SExt/ZExtValue; ConstantFP ValueAsDouble/GetDouble; ConstantDataSequential IsString/AsString; ConstantExpr.Opcode; BlockAddress.Function/BasicBlock.
  • Globals/FunctionGlobalValue linkage/visibility/DLL-storage/unnamed-addr/section/value-type; GlobalVariable initializer/constant/thread-local/erase; Function type/return/params/basic-blocks/GC/personality/verify; GlobalAlias.Aliasee; GlobalIFunc.Resolver.

Also surfaces the existing LLVMAliasGetAliasee/SetAliasee, LLVMGet/SetGlobalIFuncResolver, LLVMGet/SetUnnamedAddress, and LLVMGetBlockAddressFunction/BasicBlock C-API on LLVMValueRef, which the managed accessors consume.

Function.ReturnType deliberately routes through FunctionType.ReturnType (pure LLVM-C) rather than the native Function_getReturnType helper, keeping it in this no-native slice.

Builds with 0 warnings; adds ManagedApi.cs (9 tests) exercising the new surface. net10.0, 2606 tests pass.

Fill in the high-level C++-mirroring managed API (sources/LLVMSharp) with the
self-contained accessors that need no libLLVMSharp native support, deferring the
instruction, module, and context surface to follow-up PRs.

Mirror ClangSharp's ownership model so wrapper-returning accessors can reach
their owning context: LLVMContext keeps a static weak registry keyed by
LLVMContextRef, and Value/Type recover their managed context from their own
handle rather than threading it through every constructor.

Also surface the existing Aliasee, GlobalIFuncResolver, UnnamedAddress, and
block-address getters on LLVMValueRef, which the managed accessors consume.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@tannergooding
tannergooding merged commit 6836bd0 into dotnet:main Jul 15, 2026
31 of 34 checks passed
@tannergooding
tannergooding deleted the tannergooding-cpp-api-surface-gaps branch July 15, 2026 19:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant