dotnet / LLVMSharp

LLVM bindings for .NET Standard written in C# using ClangSharp
MIT License
844 stars 97 forks source link

LLVM calling conventions and parameter attributes #217

Open mrahhal opened 1 year ago

mrahhal commented 1 year ago

Hello. From what I can tell there's currently no way to specify the calling conventions and parameter attributes from LLVMSharp. Documentation for these here:

I don't mind trying to contribute these if they're missing, but I'm having a hard time finding any documentation at all for what libLLVM exposes related to this. (I'm aware that it's not exactly stable or properly documented from what I know)

mrahhal commented 1 year ago

I believe this is the binding for the function from the LLVM-C lib side for the parameter attributes: https://github.com/dotnet/LLVMSharp/blob/ea05882d8a677a1b76b7d9ef8eca64f43309c9ac/sources/LLVMSharp.Interop/llvm/LLVM.cs#L1710

But it doesn't have a managed wrapper.

Similarly, for calling conventions: https://github.com/dotnet/LLVMSharp/blob/ea05882d8a677a1b76b7d9ef8eca64f43309c9ac/sources/LLVMSharp.Interop/Extensions/LLVMValueRef.cs#L106

Which is the managed wrapper, but the type used is uint which is a bit opaque. An enum with the descriptive names from https://llvm.org/docs/LangRef.html#calling-conventions could be used instead.

If you can validate this, I'll try and contribute adding the proper wrappers for these.

tannergooding commented 1 year ago

But it doesn't have a managed wrapper.

The managed wrapper is very much a WIP and not everything has been exposed yet. Contributions are more than welcome to help get the missing pieces filled in.

Which is the managed wrapper, but the type used is uint which is a bit opaque.

The type is uint because that is what the C API returns: https://llvm.org/doxygen/group__LLVMCCoreValueFunction.html#ga36902516d7b958ce09642cfe8a96c887

The managed wrapper type Function is what would provide this in a more type-safe way via an enum. It would try to follow the general conventions laid out by the C++ API: https://llvm.org/doxygen/classllvm_1_1Function.html#a5f494edc0a569c7fc9ff4181243be1ed

mrahhal commented 1 year ago

Thanks for confirming. I will try and work on these two as a start.