vnmakarov / mir

A lightweight JIT compiler based on MIR (Medium Internal Representation) and C11 JIT compiler and interpreter based on MIR
MIT License
2.32k stars 149 forks source link

Automated Meta Code Generation of MIR Code and Infrastructure #43

Open sirinath opened 4 years ago

sirinath commented 4 years ago

This might not be immediately actionable but can we have and DSL which describes the passing of a language MIR mapping and the optimisations applied where the code needed will be automatically generated. Also, the DSL should be able to describe itself so a future version of the DSL can be described in an older version. This way the code base will not be C but a purpose-built language on its own right. This way MIR will become more easy to understand, modify and improve.

vnmakarov commented 4 years ago

In some way, the current mapping description is already kind of DSL implemented on the top of C:

https://github.com/vnmakarov/mir/blob/ced76203bf5c4d27ade5f21b15208fedfecf1fc4/mir-gen-x86_64.c#L725-L779

For example, binutils is using even more primitive approach based on C macros and binutils supports much more architectures than one.

To create a general DSL to describe insns (and MIR mapping) of existing processors is a pretty big job. Architectures are so different.

I know one attempt https://sourceware.org/cgen written by one my former colleague. I would not say that its description is more understandable. It failed to be used by binutils, gcc, gdb, simulators etc.

So I prefer a natural approach, informal MIR insn defs in MIR.md and approach currently used by x86_64 mir generator. As I add more architectures, I may be will see that I need implementation of more general DSL.