© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
42 replies
🔹

❔ IL CodeGen for toy compiler [advice]

I am trying to learn more about compilers. I'd like to target some type of IR language for a toy compiler, because I don't really want to target a high-level language and I don't want to mess with LLVM stuff yet. WASM seems like a good target and I'll probably go with it if this IL stuff does not work out, but being able to leverage a bunch of BCL code from the start even for a toy language sounds really cool, so I'd like to start out targeting a small, small subset of IL.

Problem is, I'm having trouble producing an assembly, like, at all:
1. I keep reading
System.Reflection.Emit
System.Reflection.Emit
can write a dynamic assembly to a PE, but all this seems like it's .NET Framework stuff. I've also heard emit can be slow but this is a toy project so whatever
2. When I try to override
Compilation
Compilation
from
Microsoft.CodeAnalysis
Microsoft.CodeAnalysis
, there are
internal abstract
internal abstract
members which tells me I'm not supposed to touch it (I'm sure implementing
MyLangCompilation
MyLangCompilation
is wayyy more work than I realize, but this seems like the nicest option)
3. (https://github.com/kkokosa/Mobius.ILasm)[Mobius.ILasm] is apparently what https://sharplab.io uses to compile IL, and while this is a toy project and I'm not stuck up, I was hoping to plug into something from
dotnet
dotnet
organization. Seems like this is the best bet so far
4. I know the F# compiler predates Roslyn and can produce IL on it own, so I tried peeking into it to see if there are any interfaces (nuget packages, dependencies, idk, etc.,) that it plugs into when emitting IL.. you know, for things like release signing, writing to streams, byte alignment,, just "staying in spec" type stuff, and I came away so confused seeing why the Rosyln team didn't bother trying to fit in F#.
5. Maybe Mono.Cecil ????
SharpLab
C#/VB/F# compiler playground.
GitHub
GitHub - jbevain/cecil: Cecil is a library to inspect, modify and c...
Cecil is a library to inspect, modify and create .NET programs and libraries. - GitHub - jbevain/cecil: Cecil is a library to inspect, modify and create .NET programs and libraries.
GitHub - jbevain/cecil: Cecil is a library to inspect, modify and c...
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

✅ IL for function vs expression-bodied-function
C#CC# / help
2y ago
✅ Modern T4 Replacement for Design Time Codegen
C#CC# / help
11mo ago
Previewing IL generated by ILGenerator
C#CC# / help
3y ago
Advice for tutoring someone
C#CC# / help
12mo ago