Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Would it even make sense to write a C# compiler that targets LLVM?

I'm thinking about writing a small C# compiler.

One idea I've been toying with is writing a subset of the C# grammar, say up to 2.0 for ANTLR. Then, using this to target the LLVM and write a native code compiler for C#?

Does this idea even make sense or would this not work? Would there be any way to still make calls to the BCL?

I know there is the CCI (Common Compiler Infrastructure) which would aid me in simply generating .NET executables. But I'm curious if what I said above would be possible?

like image 578
KingNestor Avatar asked Feb 11 '10 22:02

KingNestor


People also ask

Do people still write in C?

The C programming language has been alive and kicking since 1972, and it still reigns as one of the fundamental building blocks of our software-studded world.

Is C+ better then C?

Compared to C, C++ has significantly more libraries and functions to use. If you're working with complex software, C++ is a better fit because you have more libraries to rely on. Thinking practically, having knowledge of C++ is often a requirement for a variety of programming roles.

Is C+ a thing?

C+ (grade), an academic grade. C++, a programming language. C with Classes, predecessor to the C++ programming language. ANSI C, a programming language (as opposed to K&R C)

Is C hard to write?

It is not hard to learn C. Just like any other skill, you will need patience and resilience to master coding using C. The programming language features 32 keywords for its syntax. This makes it a relatively simple coding language to learn.


3 Answers

Mono already can be used with a LLVM backend.

More details in the Mono docs.

Check out the Limitations section, though.

UPDATE: as of Mono 2.8 the LLVM backend has graduated to stable. See the Mono 2.8 release notes.

like image 160
Mauricio Scheffer Avatar answered Oct 19 '22 15:10

Mauricio Scheffer


Beyond Mono already cited, Microsoft is working in its own implementation called LLILC (it isn't just an experiment). So it makes much sense.

like image 37
Maniero Avatar answered Oct 19 '22 15:10

Maniero


Unless you want to rewrite the entire standard library, too, it would be better to find a different project, if you're just looking for something to do. A possibility would be to write a .NET bytecode compiler or an IL assembler.

like image 1
Joel Avatar answered Oct 19 '22 15:10

Joel