Skip to content

Expose AddModuleFlag functionality within LLVMModuleRef#181

Merged
tannergooding merged 12 commits intodotnet:mainfrom
ryan-moreno:main
Nov 15, 2021
Merged

Expose AddModuleFlag functionality within LLVMModuleRef#181
tannergooding merged 12 commits intodotnet:mainfrom
ryan-moreno:main

Conversation

@ryan-moreno
Copy link
Copy Markdown
Contributor

@ryan-moreno ryan-moreno commented Nov 12, 2021

This PR exposes the LLVMAddModuleFlag and LLVMLinkModules2 functionality within the LLVMModuleRef class. This allows for a more straightforward method for adding module flags using the LLVMSharp API and provides a way to link modules using the LLVMSharp API. It also adds a test to ensure that LLVMAddModuleFlag constructs the correct flag behavior in the outputted debug information.

The addition of the AddModuleFlag functionality also helps to clarify this situation:
There are two different ways to add a module flag in LLVM Native: A) using LLVMAddModuleFlag (which expects a 0-based LLVMModuleFlagBehavior) and B) using LLVMAddNamedMetadataOperand (which expects a 1-based behavior represented by a uint). Exposing the AddModuleFlag functionality is meant to ease this confusion by adding a more straightforward method to create module flags that uses the LLVMModuleFlagBehavior enum as expected.

@ryan-moreno ryan-moreno changed the title Expose LLVMAddModuleFlag functionality Expose LLVMAddModuleFlag functionality within LLVMModuleRef Nov 12, 2021
@ryan-moreno ryan-moreno changed the title Expose LLVMAddModuleFlag functionality within LLVMModuleRef Expose AddModuleFlag functionality within LLVMModuleRef Nov 12, 2021

public static bool LinkModules(LLVMModuleRef Dest, LLVMModuleRef Src)
{
return Convert.ToBoolean(LLVM.LinkModules2(Dest, Src));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The following is simpler and going to be much more efficient:

Suggested change
return Convert.ToBoolean(LLVM.LinkModules2(Dest, Src));
return LLVM.LinkModules2(Dest, Src) != 0;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated with your suggestion. Since this is effectively just a wrapper around LLVM.LinkModules2 (no longer a function for the LLVMModuleRef class), I think it might be better off without this function entirely. Thoughts?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either works. There isn't some "C wrapper" for the LLVM Linker type exposed by C++; so there isn't a separate "better" place to expose a friendly wrapper.

@tannergooding tannergooding merged commit ad498be into dotnet:main Nov 15, 2021
@tannergooding
Copy link
Copy Markdown
Member

Thanks for the contribution!

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.

2 participants