Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: Migrating to OOP - DIBuilder #124

Closed
yowl opened this issue Dec 2, 2019 · 4 comments · Fixed by #125
Closed

Question: Migrating to OOP - DIBuilder #124

yowl opened this issue Dec 2, 2019 · 4 comments · Fixed by #125

Comments

@yowl
Copy link
Contributor

yowl commented Dec 2, 2019

Are there OOP equivalents for the DIBuilder funcitons, .e.g. LLVMCreateDIBuilder, LLVMDIBuilderCreateCompileUnit, LLVMDIBuilderCreateFile, LLVMDIBuilderCreateDebugLocation ?

@tannergooding
Copy link
Member

Not currently.

There are a number of the "raw" APIs that don't have the minimal wrapper bindings yet. If they existed they would be defined here: https://github.com/microsoft/LLVMSharp/blob/master/sources/LLVMSharp/Interop.Extensions/LLVMDIBuilderRef.cs

PRs are more than welcome if you would like to try adding them. Otherwise, I should (hopefully) be getting to it sometime this month.

@yowl
Copy link
Contributor Author

yowl commented Dec 2, 2019

Sure, I can do a PR for the ones I create. Any idea how I should create the LLVMOpaqueContext ** for DIBuilderCreateSubroutineType . I mean it looks like a pointer to an c style array, but how do I do that from c#, pinning GCHandles?

@tannergooding
Copy link
Member

For ClangSharp, I had been returning or taking Span<>/ReadOnlySpan<>.

You can see https://github.com/microsoft/ClangSharp/blob/ff9e62f98b047d7f2142c807be6be548afcd74e6/sources/ClangSharp/Interop.Extensions/CXCursor.cs#L168, https://github.com/microsoft/ClangSharp/blob/2321198c105452a52275a452e0e91c3d65bf4574/sources/ClangSharp/Interop.Extensions/CXTranslationUnit.cs#L221, and https://github.com/microsoft/ClangSharp/blob/2321198c105452a52275a452e0e91c3d65bf4574/sources/ClangSharp/Interop.Extensions/CXTranslationUnit.cs#L115 for examples.

So,

[DllImport(LibraryPath, CallingConvention = CallingConvention.Cdecl, EntryPoint = "LLVMDIBuilderCreateSubroutineType", ExactSpelling = true)]
[return: NativeTypeName("LLVMMetadataRef")]
public static extern LLVMOpaqueMetadata* DIBuilderCreateSubroutineType([NativeTypeName("LLVMDIBuilderRef")] LLVMOpaqueDIBuilder* Builder, [NativeTypeName("LLVMMetadataRef")] LLVMOpaqueMetadata* File, [NativeTypeName("LLVMMetadataRef *")] LLVMOpaqueMetadata** ParameterTypes, [NativeTypeName("unsigned int")] uint NumParameterTypes, LLVMDIFlags Flags);

would be something like:

public LLVMMetadataRef CreateSubroutineType(LLVMMetadataRef File, ReadOnlySpan<LLVMMetadataRef> ParameterTypes, LLVMDIFlags Flags)
{
    fixed (LLVMMetadataRef* pParameterTypes = ParameterTypes)
    {
        LLVM.DIBuilderCreateSubroutineType(this, File, (LLVMOpaqueMetadata**)pParameterTypes, (uint)ParameterTypes.Length, Flags);
    }
}

@yowl
Copy link
Contributor Author

yowl commented Dec 4, 2019

Thanks, I'm sure I'll have more questions, but can take them up in the PR.

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 a pull request may close this issue.

2 participants