LLVMSharp icon indicating copy to clipboard operation
LLVMSharp copied to clipboard

Can you create a custom backend with this binding?

Open furesoft opened this issue 2 years ago • 3 comments

Hi,

I am wondering if I can write my own llvm backend with this binding in c#?

furesoft avatar Jan 06 '23 13:01 furesoft

To the extent that the official LLVM-C bindings allow you to, yes.

LLVM-C (and therefore LLVMSharp) cover most of the core APIs you need. However, it is ultimately not as verbose as the LLVM C++ API surface.

ClangSharp works around this limitation by providing libClangSharp to fill the gap around any missing API surface. There are plans for LLVMSharp to eventually do the same, but I haven't had enough time to do that yet (nor have there been enough contributors for the work to be done by someone else).

tannergooding avatar Jan 06 '23 16:01 tannergooding

I cannot find LLVMTargetMachine on ClangSharp as well to write a custom backend

furesoft avatar Jan 06 '23 16:01 furesoft

LLVM-C exports it as LLVMGetExecutionEngineTargetMachine and corresponding APIs that take LLVMTargetMachineRef

LLVMSharp exposes this as a "raw API" LLVM.GetExecutionEngineTargetMachine and as helper method on the LLVMExecutionEngineRef type (in turn, APIs that take LLVMTargetMachineRef are exposed as helper methods on that type).

There is a WIP higher level wrapper that exposes all of this as managed types and tries to mirror the C++ API surface, but it isn't complete and there is functionality available in the "raw API" that isn't exposed yet.

-- As an additional note, I would recommend using LLVMSharp 8.0.0-beta or later (ideally 15.0.0-beta, as that's the latest). The older bindings have many known bugs and are actually overall less stable/correct.

The only reason a stable version of the new bindings hasn't been published yet is because I haven't had the time to finish validating the packages are being properly code signed (it only recently became enabled for the project).

tannergooding avatar Jan 06 '23 16:01 tannergooding