- #A RETARGETABLE C COMPILER DESIGN AND IMPLEMENTATION CODE#
- #A RETARGETABLE C COMPILER DESIGN AND IMPLEMENTATION PLUS#
It is hard to implement such extensions for GCC or Clang, get approval to include them into GCC or Clang repositories, or support them on the side. All these checks would be the marked program points I am talking about.
#A RETARGETABLE C COMPILER DESIGN AND IMPLEMENTATION PLUS#
It also checks that the plus method for integers was not redefined, that there is no overflow, that it doesn't need to use multi-precision numbers, and so on.
#A RETARGETABLE C COMPILER DESIGN AND IMPLEMENTATION CODE#
For example, the C code implementing the CRuby virtual machine's plus bytecode for integers checks the operand types. Here I can mention the lacc, 8cc, and 9cc compiler projects.Īlso, I want to extend the C language in the future to mark program points where the C-to-MIR compiler should profile the code and generate speculative and de-optimized code depending on the execution profile. On the other hand, some people have written small C compilers pretty quickly. It is not an easy task, either, and could create a maintenance burden in the future. But this would create a dependency on an external project. I could implement an LLVM IR-to-MIR compiler or write a GCC port targeting MIR.
There are several ways to implement a C-to-MIR compiler. The combined code can be optimized and just-in-timed into high-performance machine code. Standard Ruby methods implemented in C can be translated into MIR and can be inlined with MIR code generated from Ruby bytecode. To start using the MIR project to implement a Ruby JIT compiler, I needed a C-to-MIR compiler. Originally, I started the MIR project to address drawbacks of the current CRuby JIT by adding tiered JIT compilation. In this article, I would like to correct these omissions. I have previously written about other parts of the MIR project (see MIR: A lightweight JIT compiler project, but I never wrote in detail about the C-to-MIR compiler, C interpreter, or JIT. Because MIR can be interpreted and just-in-timed, I easily extended this C-to-MIR compiler into a C interpreter and JIT compiler. The cornerstone of the project is a machine-independent medium-level intermediate representation (MIR).Ī big part of the project consists of code that compiles C source code into MIR. For the past two years I've worked on a project implementing a universal lightweight Just-in-Time (JIT) compiler known as MIR.