0

I'm currently designing a CLR-compatible programming language. I wrote the parser in ANTLR and would now like to build a .NET assembly out of the code. Currently I use AssemblyBuilder and co. to generate classes, methods and the assembly itself. Now I want to output the method body (statements, loops, conditionals,...). Is directly emitting IL using ILGenerator the best/only way, or are there better or easier alternatives?

Also, I first wanted to use .NET 5 for the project, but the AssemblyBuilder.Save method is not supported in .NET Core yet. Because of that, I had to restart with .NET Framwework 4.8, which does not support the latest language features. Furthermore, I'd like for the output assembly to be .NET 5/6 too. Is there another way, do save a dynamic assembly to the disk in .NET 5?

Jonas _
  • 69
  • 1
  • 6
  • Maybe outputting C# code and compiling it would be easier? In .NET Core you can use Microsoft.CodeAnalysis.CSharp and CSharpCompilation class to generate an assembly. Here I found a compiler example https://stackoverflow.com/a/64164070/5805327 – mcbr Nov 04 '21 at 21:39
  • 1
    Roslyn compiler platform already has IL emitter, https://learn.microsoft.com/en-us/dotnet/csharp/roslyn-sdk/compiler-api-model so you just reuse whatever available from there. – Lex Li Nov 04 '21 at 23:03

0 Answers0