This project transpiles LLVM IR to .NET CIL. This enables robust, automated translation of C and C++ to low-level C#. Translated code is highly performant, AOT compatible, cross-platform, and semantically accurate.
While this project is intended to handle any LLVM IR, it works best when the input is generated on Windows with the following Clang command:
clang -g -fno-discard-value-names -fstandalone-debug -S -emit-llvm {inputFile} -o {outputFile}
This ensures that debug information is included and that parameter names are preserved, which helps with generating code that is more readable.
Install Ninja
Use ninja --version to verify that it's been added to the PATH.
Clang on Windows can have trouble finding the Windows SDK and Visual Studio libraries and includes. You can set the LIB and INCLUDE environmental variables to help it find them. Adjust the paths below to match your installation.
$env:LIB="C:\Program Files\Microsoft Visual Studio\18\Community\VC\Tools\MSVC\14.50.35717\lib\x64;C:\Program Files (x86)\Windows Kits\10\Lib\10.0.26100.0\um\x64;C:\Program Files (x86)\Windows Kits\10\Lib\10.0.26100.0\ucrt\x64"
$env:INCLUDE="C:\Program Files\Microsoft Visual Studio\18\Community\VC\Tools\MSVC\14.50.35717\include;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\um;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\ucrt"This is an example of an error you might see if Clang cannot find the necessary libraries:
-- Check for working C compiler: C:/Program Files/LLVM/bin/clang.exe - broken
CMake Error at C:/Program Files/CMake/share/cmake-4.2/Modules/CMakeTestCCompiler.cmake:67 (message):
The C compiler
"C:/Program Files/LLVM/bin/clang.exe"
is not able to compile a simple test program.
cmake -G "Ninja" \
-S ./path-to-directory-with-source-files/ \
-B ./path-to-build-output-directory/ \
-DCMAKE_C_COMPILER=clang \
-DCMAKE_CXX_COMPILER=clang++ \
-DCMAKE_C_FLAGS="-DNOMINMAX" \
-DCMAKE_CXX_FLAGS="-DNOMINMAX" \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON
This will generate a compile_commands.json file in the build output directory, which is necessary for a future step.
-DNOMINMAXensures that theminandmaxmacros do no interfere with compilation.
cmake --build ./path-to-build-output-directory/ --config Debug
This ensures that any generated files get generated.
LargeProjectCompiler.exe ./path-to/compile_commands.json
Use --help to see additional options.
There are plans to ship this as a NuGet tool for easy installation and usage.
The libLLVMSharp dependency is not included in the repository. The source code for it can be found here.