❔ 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:
Problem is, I'm having trouble producing an assembly, like, at all:
- I keep reading
System.Reflection.Emitcan 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 - When I try to override
CompilationfromMicrosoft.CodeAnalysis, there areinternal abstractmembers which tells me I'm not supposed to touch it (I'm sure implementingMyLangCompilationis wayyy more work than I realize, but this seems like the nicest option) - (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
organization. Seems like this is the best bet so fardotnet - 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#.
- Maybe Mono.Cecil ????
C#/VB/F# compiler playground.
GitHub
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.