tags:

views:

132

answers:

4

Is there any way to write a LLVM front end compiler in C#?

A: 

If you are looking to have a LLVM compiler FOR C#, Mono 2.6 can use LLVM

phsr
No, I'm looking to write a LLVM compiler IN C#.
TTT
If you want, I'll delete this anwser
phsr
+2  A: 

C# can read textfiles and write binary files, and it is turing complete.

So yes, you can.

jdv
+2  A: 

I don't see why not. There is a language reference for LLVM and as long as you are compliant with the language, there is no reason you can't write something in C# which will parse that language and either:

  • Produce output based on the language (like a real-time interpreter)
  • Create an assembly in C# which will execute the LLVM instructions

This isn't to say it will be easy, but it can be done.

casperOne
A: 

There are two ways. You could P/Invoke LLVM's C bindings (more than enough for implementing a compiler backend), or you could write your own wrapper with C++/CLI.

I used Clang-generated XML AST dump for LLVM's C bindings headers to generate .NET bindings for them automatically. Sorry, no sources for bindings, but you could use Reflector on MBaseLLVM.dll:

http://www.meta-alternative.net/templateC-0.0.1.zip

It's a compiler from C to LLVM, written in a .NET language (pfront).

SK-logic