r/Compilers • • Jun 22 '26

"badc" is a new cross-platform C compiler (as-as-a-libraty) crate/toolchain

0 Upvotes

Hi folks, here it is https://github.com/kromych/badc

It can (cross-)build Python 3.14 on 5 targets as well as sqllite3, other libraries, and passes their test suites. For extra fun, it can produce native/NT images and Windows drivers (EFI as well, didn't test though). I also stood up lots of validation in CI to make sure it works and gives enough perf to the compiled code despite being quite speedy to compile.

Some time ago I just needed to tweak what a compiler was emitting, and thought perhaps I should learn how to use the modern tools for producing code. And that really got out of hand as I love compiler and OS/hypervisor programming so decided to build a nimble compiler that would optimize but not too much, just enough not to be embarassing :D

There were times when I was writing algorithms down with a pencil on a paper from the Dragon and the Dinasour books to make sure I understand, and I didn't have a computer, too, lol. So adjusting to the new brave world another time!


r/Compilers • • Jun 21 '26

The LLVM Essence of Lowering MLIR to AArch64 with SME Support

Thumbnail federicobruzzone.github.io
8 Upvotes

Hi Folks 👋

I’d like to share a post explaining how to lower MLIR to AArch64 with SME support. I hope it’s useful for anyone getting started with this lowering.

I’d also be happy to hear any feedback, questions, or suggestions. Feel free to reach out :D


r/Compilers • • Jun 21 '26

A parser generator for rust, gazelle-parser

0 Upvotes

Creating a parser for a compiler is typically mechanical and somewhat boring part of compiler dev. My impression is that most people reach for recursive descent. I see the advantages of recursive descent due to the full control over speed, bespoke error messages and error recovery it allows, but at a price of a lot of engineering. Parser generators can help a lot when the language itself is still in flux / you are focused on the actual compiler it self first and foremost and you just want a correct parser that gives some error messages.

There a lot of parser generators out there, but still, for me, there was always a big barrier to using them.

  1. They typically are an extra build step
  2. You write action code inside the language spec / or you are visitor-pattern walking a CST
  3. Often still LALR(1) based with potential mysterious conflicts that are inexplicable, or LL based with left-recursion being awkward.
  4. Binary expressions, either through a hierarchy of add_expr, mul_expr. etc.. or through %prec annotations, but anyway completely statically for all binary operations.
  5. Hard to understand grammar issues
  6. Parse errors that are "Syntax error: expected ...", with error recovery through error tokens and error reductions that are manual inserted in the grammar

I tried to solve these issues in order to have a tool where these points are addressed to my satisfaction. It's accessible through just a rust macro, available when you import the crate (solves 1). The grammar specification is pure EBNF, no actions pure grammar, the user implements a set of macro-generated traits in normal rust (solves 2). The generator is full LR(1) capable (still small tables though) so all grammar conflicts have an understandable reason and gazelle reports said reason (either a full ambiguity / or at least 2 sentences that can't be distinguished with 1 token look ahead). This addresses point 3 and 5. Upon parse error you can keep parsing using a minimal cost error recovery model, this leads often to precise error reporting because it finds the correct repair and prevents cascading syntax failures, my examples show that its automatic error reports isn't far off from what gcc reports on c syntax errors (partially addresses point 6).

Lastly, it has a feature I haven't found in other generators, runtime precedence. Instead of
```
add_expr = add_expr '+' mul_expr | mul_expr
mul_expr = mul_expr '*' term_expr | term_expr
etc...
```
or
```
%left '+' '-'
%left '*' '/'
expr = expr '+' expr | expr '-' expr | expr '*' expr | expr '/' expr | ...
```

in gazelle you do
```
terminals {
LPAREN, RPAREN
prec OP
}
expr = expr OP expr => binop
| LPAREN expr RPAREN => paren
| term => term
```
OP is declared as a dynamic precedence token, so it could be '+', '-', '*', '/' together with its precedence. The correct syntax tree will be generated based on the runtime precedence provided for each token.

I used AI to build this library. Design is overwhelmingly mine
* Trait system to neatly factor grammar and actions
* The LR(1) table creation algorithm-variant that still produces LALR sized tables but full LR(1) language, it completely circumvents the problems of minimal LR and the elaborate fixes of IELR, and is just dead simple.
* Dynamic precedence, ie. unify shunting-yard inside canonical lr(1)

AI implemented standard algorithms like NFA->DFA, DFA minimization, dijkstra on error recovery etc..., lot of refactoring, writing tests. I benefited from AI refactoring in discovering the trait system. Being able to quickly iterate and try out was very beneficial.

gazelle-parser crate


r/Compilers • • Jun 19 '26

How do JIT compilers actually jump to the code they write?

50 Upvotes

Just emitting the assembly is "easy" (well, I mean the logical workings of how an AST is transformed into asm may be very complicated, but otherwise it's just like emitting any other sequence of bytes). However, actually jumping to the code seems to present a problem. With AOT compilation of a standalone executable it isn't, the code is compiled to a .exe or whatever the native format for an application is on that platform and then you run it. But with JIT-compiled Javascript, say, it's deeply embedded in and tied to the engine that generates it. Thus, this jump requires the JIT compiler to introspect about its own control flow and ABI and effectively inline the generated code into itself--to borrow a theater metaphor it "breaks the 4th wall" of the compiler. Some languages would even seem to actively try to fight this--for example for a JIT compiler written in rust, jumping to arbitrary asm is about as unsafe as it gets.

Does the JIT compiler need to use a small amount of inline assembly in its own source code to load the address of the block it just output into a register and then JMP to it? And what about the jump BACK to the JIT compiler when it finishes? To my knowledge there's no "address-of-this-statement operator" that can be used to tell the CPU where to go in the source of the compiler's code after it hits the end of the emitted block. Does the JIT compiler itself have to be compiled with a special compiler and/or with certain optimizations disabled so that its ABI and layout of its code in memory is stable enough that the compiler can know that its generated asm is always compatible with itself?

Alternatively, does the JIT write its instructions into a separate file on the filesystem and then rely on the operating system's dynamic linker to actually tie them together?

Is there a "toy" Javascript JIT compiler somewhere I can look at to see this in action? Obviously having fancy optimization passes or anything like that is unnecessary and may even make it harder to look for the key bit of logic--just a big switch that emits the most naive x86 or ARM opcode(s) for each AST node is enough, it's the mechanics of the jumping back/forth that I'm curious about.


r/Compilers • • Jun 19 '26

Building an AST on a live coding session

Thumbnail pvs-studio.com
1 Upvotes

Next week there's a live session on building an AST from scratch, part of the ongoing series where a senior C++ dev builds a programming language step by step just for the fun of it. Worth catching it live to ask questions as he goes. Previous episodes (lexer, parser) are up on youtube if you want to catch up first but this one's a solid entry point too


r/Compilers • • Jun 19 '26

Built Tamizhi (தமிழி) — a Linux-native programming language with LLVM backend, written in C

1 Upvotes

I've been working on a project called Tamizhi — a programming language designed for fast Linux automation, compiled via a custom LLVM backend.

Some details:

Custom LLVM-based compiler (generates native bitcode, not just interpreted)

Direct native system calls — no heavy wrapper layers for shell execution

AOT/JIT execution through a custom bytecode VM (calling it DNA-VM)

Self-contained installer that detects Termux/Linux and sets up the toolchain

It's still early (v0.1.5), so there's a lot to refine — error handling, stdlib, docs. I'm also working on integrating it into BDH Linux (an automation/dev-environment tool I maintain) so it can drive backend provisioning natively.

Repo's here if anyone wants to poke around or has feedback on the architecture: [https://github.com/BackendDeveloperHub/Tamizhi.git]

Happy to answer questions about the LLVM IR generation, parser design, or the VM if anyone's curious.


r/Compilers • • Jun 19 '26

Modelling finalizer blocks for my IR

4 Upvotes

My IR targets JS. It is/aims to be highly ECMA compliant (modulo 'with' semantics). Recently I have been rewriting some support classes/improving some data structures and have decided to redo the CFG classes completely. Try-catch-finally modelling was the part I was unhappy about in my earlier implementation. I had a complex mechanism for handling unions for exception edges which was very buggy (now, for simplicity I have now adopted fat block unions for exception edges; java like).

But still, one of the parts about the IR that still bugs me is the way I have implemented finaliser blocks. Finalizers are like mini functions calls (usually with special instructions in most target VMs). Finalizer return targets are in some sense "context sensitive" + they can be nested. In my current implementation this is exactly what it does (super imprecise at finalizer returns, but easy to implement). I can think of two ways to solve this situation off the top of my head:

1/ Keep the graph as it is, but introduce some kind of 'context' in the AI (Abstract Interpretation engine). Change the analysis infrastructure, leave graph structure untouched (hopefully less things break?!).

2/ Roll up the sleeves, and clone/inline the blocks like the big boys (I think v8 does this). Nested finalisers calling other finalizers (just feels like something I am not emotionally equipped to deal with atm 😂).

If anyone has experience with handling such situations I would greatly appreciate your view on this. I know this might sound a bit silly, but JS does require a bit of extra maintenance at times (emitting instructions to move certain elements to heap, clearing out the catch offsets from stack, potentially calling iterator callbacks, the whole deal); so any change I make might end up becoming a week of debugging exercise. As I am the sole developer and maintainer of the project, I have become a bit more cautious about taking abrupt decisions which could end up breaking more things than they fix.


r/Compilers • • Jun 19 '26

I am creating a compiler

0 Upvotes

I am creating a compiler for my own programming language, I have been suffering a lot but I am improving slowly, it has been alot of Google and asking ChatGPT for small exemples, trying to recreate but for what I want, realizing it doesnt really work trying to fix etc.

It has been an interesting experience, im currently at the type checker


r/Compilers • • Jun 18 '26

From Minutes to Seconds: LLM-Guided Autotuning for Helion Kernels

Thumbnail pytorch.org
2 Upvotes

r/Compilers • • Jun 18 '26

Flat, fast, declarative parsing engine e

Thumbnail github.com
5 Upvotes

r/Compilers • • Jun 18 '26

V8 Engine Feedback Vector

6 Upvotes

Hello everyone,

Recently, I'm looking into v8 JavaScript Engine and found out about FeedBack Vector, which I want to investigate more about it in order to understand how the Engine assigns type at runtime after being interpreted by Ignition.

Although I tried to compile the v8 source code and it was able to run a simple script on my machine, I can't seem to be able to get the information regarding Feedback Vector and the data inside it.

So far, I have tried to use some promising flags that are available:

+ --log-feedback-vector
+ --maglev-print-feedback
+ --invocation-count-for-feedback-allocation=1
+ --no-lazy-feedback-allocation

None of them are working - no output to the terminal after I ran it.

I followed this (old and maybe outdated) article:
- An Introduction to Speculative Optimization in V8

With the same code, I can not retrieve the same BinaryOp which I believe have changed after many updates. I want to avoid any "natives syntax", in general, but even when I included it (e.g. %DebugPrint(add);), it does not seem to give me the information that I wanted like in the article.

My goal is to analyse JavaScript's V8 bytecode and output the correct possible types of variables (similar to what Mytype do). So if I can have another way to work around this, it would be very appreciated!

I don't know if this is the right place to ask these kind of question. Therefore, I'm sorry in advanced if this caused any confusion.

Thank you everyone for your time.


r/Compilers • • Jun 18 '26

My static analysis tool now supports compile database for linux kernel

Thumbnail reddit.com
1 Upvotes

r/Compilers • • Jun 17 '26

Loop Unrolling in the ML Era

Thumbnail hiraditya.github.io
4 Upvotes

r/Compilers • • Jun 16 '26

Using Task Graph Caching to Accelerate TVM Code Generation

Thumbnail dl.acm.org
7 Upvotes

r/Compilers • • Jun 17 '26

2026 contributors version of porting TH to ATen?

0 Upvotes

I’m looking to contribute and really liked the idea of working on porting TH to ATen but (sadly) all that work has been done. is there anything on a similar depth (doesn’t necessarily need to be porting) but gives the same vibe as manual refcounting, preprocessor shenanigans, kernel rewriting/new code.


r/Compilers • • Jun 16 '26

AET: An experiment in rethinking GCC target and machine abstractions

14 Upvotes

AET (Active Expandable Translator) is an experimental compiler project based on GCC.

The project explores how compiler internals can be structured to better support heterogeneous computing.

Modern compilers have mature target architectures, but many internal mechanisms were designed around a relatively fixed target model. As computing platforms become more diverse (CPU, GPU, AI accelerators), I started exploring a different approach:

Object-based abstraction of compiler internals.

The main idea is to transform scattered target and machine representation mechanisms into extensible objects, so that:

  • program models
  • machine descriptions
  • code generation behavior

can share a more unified abstraction.

In AET, target-specific behavior and machine representation are separated into extensible components. Different hardware platforms can provide their own implementations while sharing the same compiler workflow.

Current work includes:

  • GCC 15 based compiler
  • GIMPLE / RTL integration
  • NVIDIA PTX backend
  • Object-based compiler abstractions
  • Generic programming support through object reachability analysis

To validate the compiler beyond a language experiment, I also developed AET-CNN, an image classification training framework written in AET.

The project is still experimental. I am interested in feedback from people working on:

  • compiler architecture
  • programming languages
  • backend design
  • heterogeneous computing

GitHub:
https://github.com/onlineaet/aet

AET-CNN:
https://github.com/onlineaet/aet-cnn


r/Compilers • • Jun 15 '26

Scalable GPU Acceleration of Scalar Functions in Analytical Databases: Compilation, Benchmarking, and Optimization

Thumbnail microsoft.com
7 Upvotes

r/Compilers • • Jun 15 '26

Compiling Strassen-like Matrix Multiplication Algorithms to Fast CUDA Kernels

Thumbnail dl.acm.org
10 Upvotes

r/Compilers • • Jun 16 '26

Not able to figure out the problem with compiler

Post image
0 Upvotes

r/Compilers • • Jun 16 '26

Not able to figure out the problem with compiler

Post image
0 Upvotes

r/Compilers • • Jun 15 '26

Any book on compilers that is "concrete?"

39 Upvotes

I've completed nand2tetris last year, and I'm looking for a book that goes over more advanced topics like optimization. I'm currently reading through "Engineering a Compiler," but I don't find it very satisfying. I want to read a book that goes over advanced topics in compiler design while being very concrete: I want it to specify a specifc instruction set, either real or imaginary, and I want it to specify a specific programming language, either real and imaginary, and stick to those throughout the text, like in nand2tetris.


r/Compilers • • Jun 14 '26

Looking for some wisdom/insight as to whether to use C++ or Rust for my compiler projects.

33 Upvotes

Hi all,

So as the title suggests, I'm looking for some guidance on whether to make my compiler projects in C++ or Rust, especially when it comes to showing off the project(s) on a portfolio. I have a lot more (non-professional) experience in C++ (which I love) but I'm also interested in making stuff with Rust (which I also really love). My goal is to some day work professionally on compilers, whether it be front, middle, or back end.

Something that I'm constantly thinking about is whether or not a possible future employer will care whether I've used Rust more for C++-based positions (or vice versa C++ for Rust positions). I know this is probably not something that can be generalized, and there is probably no definitive answer to this, since it may vary based on whom exactly the position is posted for, but I'm hoping to get some perspective from you people whom probably have a lot more experience than me.


r/Compilers • • Jun 14 '26

I built a Lox-style bytecode VM in Rust to understand closures

20 Upvotes

I Spent the last few days building a Lox-style scripting language with a stack-based VM just to finally grasp closures. Ended up learning the hard way after fighting a brutal bug where multi-level upvalue capture kept hitting the wrong stack slot.

You can read more in the README from the repo: https://github.com/CAPRIOARA-MAGIKA/scripting-vm

Most of the things were polished last minute so don't expect much. The interpreter is incomplete so parity covers half the language; the VM is the main executor.

I would love some feedback from you guys and also if you find any bugs do let me know. Thanks for reading!