core
core copied to clipboard
LLVM Loader
🚀 Feature
This is a plan for implementing the LLVM Loader for MetaCall. This is subject to many changes and it is open to suggestions from everyone.
Proposed Solution
As a first step, I wish to develop a POC with the basic working functionality of what is expected.
- [x] Emit the LLVM IR from C/C++ files using clang. These can be emitted in .ll or .bc formats.
- [x] Load the LLVM IR (.ll) file using the parseIRFile method of LLVM C++ API and store it in a module.
- [x] The main functionality would be to be able to implement the discover method. For this, we can iterate through the module and use the getFunctionList function of the API to fetch all the functions. If it is a valid function declaration, record this function and iterate through each of the functions to get their respective parameter lists.
- [x] Another main functionality would be to be able to call the functions dynamically. For this, we can simply make an ExecutionEngine and find the function by its name (we can do this as we've already got all the functions in the discover function). Then, we can simply execute it by specifying their parameters.
As the second step, I wish to map the POC to the actual loader according to MetaCall's design decisions and actually start implementing it for the core.
- [x] Perform mapping of various methods to proper places in the MetaCall loader in the core.
- [ ] Start implementing the MetaCall LLVM loader as a whole. (IN PROGRESS)
Proof of Concept (POC)
My LLVM Loader POC can be found here.
https://github.com/metacall/core/commit/af60ad595e61d52d537bc528039471a2773c4f90
I am going to left here information for develop this loader:
- In the build folder, run:
cmake -DOPTION_BUILD_LOADERS_LLVM=on ..
make llvm_loader metacall-llvm-test
ctest -VV -R metacall-llvm-test
- It needs LLVM v11.0.1.
Once this is finished, we can add documentation as written in this issue: https://github.com/metacall/core/issues/115
Here's the base implementation for the loader: https://github.com/metacall/core/commit/af60ad595e61d52d537bc528039471a2773c4f90
LLVM installation: https://apt.llvm.org/
I used the automatic script for installing llvm 11, as shown below.
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh 11
- It needs LLVM v11.0.1.
#137 changes the required version to v11
I have updated the build instructions here ( https://github.com/metacall/core/issues/114#issuecomment-832290058 ), in the last command I was using cmake instead of ctest.
Also I have cleaned up a bit the comments and solve a minor bug in the types (the string was wrong): https://github.com/metacall/core/commit/85472fa8b4a688a8a8a48a0f954df6bffbccc9a3
LLVM installation: https://apt.llvm.org/
I used the automatic script for installing llvm 11, as shown below.
wget https://apt.llvm.org/llvm.sh chmod +x llvm.sh sudo ./llvm.sh 11
Respect to this, it is documentation but it has to serve to implement the support of LLVM in docker, basically here: https://github.com/metacall/core/blob/develop/tools/metacall-environment.sh
It is a TODO that has to be done too, for having complete support of the LLVM Loader. Note, I am not sure but it may conflict with this: https://github.com/metacall/core/blob/b1331eb29d2899cd20af76add589e4272919cd65/tools/metacall-environment.sh#L370
Oh, cool then 👍