ds5678 4e675f8e04 Add support for vector and poison LLVM value kinds
Extended InstructionLifter to handle LLVMConstantVectorValueKind by extracting element type and count, and LLVMPoisonValueValueKind by loading a default variable of the correct type. This improves handling of additional LLVM constant types.
2026-05-25 13:23:48 -07:00
2025-06-30 12:14:51 -07:00
2025-06-30 12:14:51 -07:00
2025-11-25 17:32:26 -08:00

AssetRipper.Translation.LlvmIR

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.

Compiling small projects to LLVM IR with Clang

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.

Compiling large projects to LLVM IR with CMake on Windows

Install Ninja

Use ninja --version to verify that it's been added to the PATH.

Environmental variables

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.

Run CMake

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.

Flags

  • -DNOMINMAX ensures that the min and max macros do no interfere with compilation.

Compile the project normally

cmake --build ./path-to-build-output-directory/ --config Debug

This ensures that any generated files get generated.

Compile the project to LLVM IR

LargeProjectCompiler.exe ./path-to/compile_commands.json

Use --help to see additional options.

NuGet tool

There are plans to ship this as a NuGet tool for easy installation and usage.

S
Description
Convert LLVM IR to .NET CIL
Readme MIT
849 KiB
0 Stars 1 Watchers 0 Forks
Languages
C# 99.1%
ANTLR 0.9%