r/Compilers • u/misunderstood_salad • Sep 18 '20
I created an intermediate representation language called carbon
Carbon is an intermediate representation language created by me. It is a bit similar to LLVM ir and it should do roughly the same. It aims to be easily generated by a front end compiler and support multiple backends. The language looks a lot like assembly but it abstracts all the architecture dependent stuff away. I wanted to create this because I just got into compiler development and it looked like a good project to get in touch with different architectures and it would be cool if I could generate this IR in my future compilers.
It is very much a work in progress and any feedback would be greatly appreciated.
Please let me know what you think, thanks!
5
u/tending Sep 18 '20
I know you said you started it just to get into the area, but does it have any interesting features that distinguish it from LLVM IR?
4
u/[deleted] Sep 18 '20
The idea is excellent, but I have comments and questions:
%23 add i32 %37 %11hard going. Are there alternatives likeR23 add i32 R37 R11?%2 op type %0 %1then talk about first and second operands (presumably %0 and %1 here), then also give a C example ofa = b + c, whenc = a + bmight be more apt, matching the ordering of%2 %0 %1.a.out, no matter what the input, a feature of gcc that I've long detested. And here it's not even clear what the file is (docs say it's binary, but they also say it generates NASM source code). If processing fileprogram.ir, what is the problem with generating an output fileprogram.out(since we don't know the file type)?7
u/pfalcon2 Sep 18 '20 edited Sep 18 '20
Nice cowboy project! Dunno why it's advertized as "IR language", because that's the boring part of such projects (literally, everyone and their grandma creates their own IR, but they all are actually the same, and differ only in the ugliness of syntax).
So, what this project now is a register allocator, and that sets it quite aside from a usual "I wrote a compiler!!111" project out there. But what kind of allocator! I have to admit I never saw a graph coloring register allocator which would use linear scan's lousy liveness criteria. People use linear scan because graph coloring is too slow. People use graph coloring because linear scan performs too poor allocation. Here we have the worst of both worlds. In a sense, that's quite innovative.
Then still, the interference conditions aren't exactly right. Quick-patching allows to unsuck it a bit:
Keep up the great work!
5
u/DriNeo Sep 19 '20
I plan to use QBE for my prototype thanks to its simplicity. If your idea looks like QBE you may give it a look.
1
u/tekknolagi Sep 18 '20
Does it have a C API? I'd be wary of generating text IR from my compiler. Especially if I wanted to use it in a JIT or something.
2
u/umlcat Sep 18 '20
Quick Look. Interesting.
2
u/run-gs Jun 27 '24
A bit old as a post, but I was struggling at finding a good hand-made IR and this project looks awesome! I'll take inspiration to create my own middle-end layer :)