r/Compilers • u/PrathameshSavane • Sep 23 '26
Looking for feedback on an extensible multi-language compiler project
I'm planning to build a compiler project as a long-term academic and portfolio project, and I'd like feedback from people with experience in compiler development.
The overall idea is to build a modular compiler platform that can support multiple programming languages through separate frontends while sharing a common compilation pipeline.
My initial target is:
- C
- C++
- Python
- A small custom language of my own
The goal isn't to recreate GCC, Clang, or CPython. Instead, I want to explore how a compiler can be designed so that additional languages can be added later without rebuilding the entire system from scratch.
The planned project would include things such as:
- Multiple language frontends
- A common intermediate representation
- Compiler optimizations
- LLVM-based code generation
- Multiple possible targets
- A way to visualize the different stages of compilation
- Eventually, the ability to add new language frontends as plugins
I'm still at the architecture/design stage, so I'm particularly interested in feedback from people who have actually worked with compilers, LLVM, language implementation, or related systems.
A few things I'd especially like opinions on:
- Is this architecture a reasonable direction for a serious learning/portfolio project?
- What major design mistakes should I avoid early?
- Would you recommend designing a custom IR or relying more heavily on an existing IR such as LLVM IR?
- What parts of the project are worth implementing myself versus using existing compiler infrastructure?
- Are there any existing open-source projects or papers you would recommend studying before I start?
I'm deliberately keeping the initial scope broad and would expand the language support incrementally rather than trying to implement complete C++ or Python immediately.
I'd appreciate feedback particularly from people with compiler/language implementation experience rather than general programming advice.
3
u/die_liebe Sep 24 '26
The question is: What will you have that gcc and clang do not have? Have a look at the size of these projects, find out how many years of work are in it in total. Your project is unrealistic.
Note that Python is interpreted, and changes its semantics all the time. You will not be able to program so fast as they destroy backward compatibility.
2
u/MilkEnvironmental106 Sep 23 '26
Isn't this just llvm with extra steps?
2
u/kindredseer Sep 23 '26 edited Sep 23 '26
2
u/General_Purple3060 Sep 24 '26
One thing I’d be careful with is making the common IR responsible for everything.
I’ve been working on AET, a language extension on top of GCC, and one thing that became pretty clear is that not every bit of information you need during compilation naturally belongs in the IR.
Some of it is language-level semantics, some is target-specific backend stuff, and some is just cross-component communication inside the compiler. If you try to stuff all of that into the IR, the IR ends up carrying a bunch of responsibilities it really shouldn’t.
In my case, I ended up putting an explicit semantic layer on top of GCC instead of trying to encode every new AET feature directly into GIMPLE. That layer owns the AET-specific concepts and only lowers into GCC’s representations when the information actually fits the model.
So yeah, a common IR is useful, but I’d be careful about making it the place where all abstractions have to converge too early. The interesting question isn’t just “what can share an IR?” — it’s also “what shouldn’t be forced into it?”
1
u/raghu1660 21d ago
Hey bro check dm
1
u/SnooHobbies950 Sep 23 '26
I created a parser based on that philosophy: https://github.com/xjslang/xjs
The idea was to create a parser that could extend JS syntax. It might serve as inspiration for you.
1
u/kindredseer Sep 23 '26
I'm working on a project with similar goals. It currently parses C, C++ and a custom extension of C++. I have plans to add Python in the future. My idea was for all parsed languages to internally lower into a C-shaped AST tree carrying the extra semantics for the other languages. I have that working with C++ and the custom language extensions, but I'm not using LLVM, I'm using MIR instead (much smaller).
1
u/umlcat Sep 23 '26
Also have some similar forgotten hobbyist ´project of my own.
Which is the programming language are you going to use for your compiler tools ?
Libraries are important, you should know how to use Data Structures / Collections like Queue, Stack, Deque, List, etc.
1
u/adityazero Sep 23 '26
IMO this is not a good idea. Every compiler that does it ends up with tech debt that is hard to get around. clang and gcc are classic examples. It becomes complicated to take advantage of language features and they all have to lower to a common IR which makes the problem worse.
1
u/[deleted] Sep 23 '26
But it does sound like you are implementing C, C++ and Python.
For a learning project it sounds ambitious, especially with C++. Maybe start with subsets.
The architecture also might not be a good fit for Python which is dynamically typed and works best interpreted.
You already mention using a 'common IR' and using LLVM. Do you mean use a custom IR only vs LLVM only vs using both? (Eg. custom IR lowers to LLVM.)
Or is that IR just the AST? These terms can have broad meanings.
1
u/defmacro-jam Sep 23 '26
You’re going to want to have each of those front ends produce its own HIR that lowers to LLVM IR.
1
u/NYU_VM Sep 24 '26
Your proposal may sound really ambitious at surface but what it really is is naive. Trying to support statically typed compiled languages and dynamically typed interpreted languages is such a massive undertaking in itself. And to be truly general purpose as you suggest, you have to cater to everyone: static types, dynamic types, multiples of memory models, GC models, generics?, and so much more. You will essentially end up creating LLVM, Cpython and what not, but worse. There is a reason languages like Elixir, Java, C# run on their VM/runtime instead of targeting LLVM for native and LLVM also having such a low level IR.
A simple compiler or VM project will open your eyes into reality, challenges, opportunities and limitations. Maybe you have a novel idea worth trying out, you can implement and test them, just make sure not to crush the project under such huge scope creep, as if the project caters to everyone, it really ends up catering to no-one well