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

Update LLVM C API usage and remove hand-rolled code #358

Open
andrew-wja opened this issue Aug 31, 2021 · 1 comment
Open

Update LLVM C API usage and remove hand-rolled code #358

andrew-wja opened this issue Aug 31, 2021 · 1 comment

Comments

@andrew-wja
Copy link
Member

Since anyone last touched our FFI layer, the LLVM C API has been updated significantly. Most importantly, the LLVM C API now has functions which do things for which we have hand-rolled code in our FFI.

Where the LLVM C API now has a function that does something, and we have hand-rolled code that does something, we should remove our hand-rolled code and instead call the LLVM C API function.

This is quite a large undertaking, effectively being an audit of the entire FFI layer. However, it can be done piecewise, module-by-module.

This will result in our FFI layer becoming quite a lot smaller and simpler, which will make it easier to maintain going forward. It also reduces the likelihood of something breaking dues to a change in upstream LLVM, since we can assume that the LLVM project will ensure that their own C API is working.

@andrew-wja andrew-wja added this to the LLVM 12 Support milestone Aug 31, 2021
andrew-wja added a commit that referenced this issue Aug 31, 2021
…diagnose what is causing the failures. Audit LLVM.Internal.FFI.Type for duplication of the LLVM C API and remove it (addresses #358).
@andrew-wja
Copy link
Member Author

There are also places where we have an awkward division between our C/C++ code and Haskell. For example, there are many instances where we have FFI wrapper functions written in C++ which are themselves doing work using the LLVM C/C++ API. Arguably, we should be wrapping the more primitive C API functions which are being called, and doing that work in Haskell instead. Otherwise, we are effectively extending the LLVM C API with our own handwritten extra stuff, which is liable to break if the LLVM C API is updated.

A simple example is in the module LLVM.Internal.FFI.Assembly and in the corresponding AssemblyC.cpp file. In this instance, we could bind the C API function LLVMParseIRInContext, and make the function parseLLVMAssembly a Haskell function rather than have the logic inside the FFI wrapper function. This is a very trivial example, but there are other FFI wrapper functions doing a lot more work in C++.

andrew-wja added a commit to andrew-wja/llvm-hs that referenced this issue Aug 31, 2021
…o remove old, stale text, and encourage creation of issues for incomplete LLVM API coverage.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant