r/Compilers • u/zlfn • 18d ago
Introduce LLVM Z80 Backend
Hello, I'm posting here because I think many people might be interested in our project.
We are developing a complete Z80 backend for LLVM. It currently supports the Z80 and SM83 (Game Boy CPU) and offers performance and stability comparable to existing compilers for Z80.
You can check the benchmark here (though I made it, so it may not be completely fair) :
https://zlfn.github.io/z80-bench/
And you can also try it out on godbolt: https://godbolt.org/z/4v19Gjd9E
Our goal is to create a modern and efficient Z80 compiler that can be used as a toolchain for various retro computing projects.
We are looking for users and contributors for our project! If you like the project, feel free to try it out, and if you have any suggestions for improvement, please let us know through project issues or discussions. Thanks!
21
u/realrealvantheman 18d ago edited 18d ago
PLEASE dont be slop this actually looks cool edit: its vibecoded
1
u/zlfn 18d ago edited 18d ago
We are using AI at a similar level to the LLVM upstream, and detailed questons and answers can be found in the FAQ : https://github.com/llvm-z80/llvm-z80/wiki/FAQ
It's fine if you don't want to use my project because it was written with AI, but these days there's hardly any compiler project that doesn't use AI at all. Every Z80 compiler I know of currently uses LLMs to some extent.
1
u/Stunning_Pineapple57 18d ago
But does it work? Does it produce results in the same order of magnitude of size and speed optimization as say llvm-mos for the 6502? Or is it just a “first pass vibe coded proof of concept”?
1
u/zlfn 18d ago
It's about as stable as SDCC IMO. The generated code is slightly larger than SDCC's, but quite a bit faster in many cases. (SDCC is the most widely used Z80 C compiler currently)
By the way, we have a tool for verifying Z80 compiler's correctness, and I've actually used it to find a few miscompilations in SDCC as well.
1
1
u/Torn_up_yarn 10d ago
The code generated is currently comparable to z88dk zsdcc. Vibe code experiments have shown that 10%-20% improvements from that is reachable.
3
u/MithrilHuman 18d ago edited 18d ago •
![]()
![]()
It's vibe coded, but all companies I have worked for are using AI for LLVM and MLIR development. It's inevitable. As long as you have reviewed the code, can answer questions and direct the AI, the companies are fine with it.
Edit: Downvote me all you want but there's no way to survive in the industry without AI.
4
u/weregod 17d ago
Who will debug slop code in compilers? If you don't have time to write code yourself you will not have resources to test and debug it.
4
u/whizzter 17d ago
I'm usually in the AI-sceptic corner (I don't even have a Claude account despite most of the office being deeply AI-pilled, only used a bit of co-pilot in VS with whatever models).
But much compiler work to get things running is eminent for being done quickly and verified by humans. Think of f.ex. add/sub/mul/div/mod/or/xor/and operators, they all work on 2 operands, might have different precedence levels, map to different instructions (perhaps even somewhat differently shaped ones, needing to weed through instruction set references), make add work and then let an AI rip through unit tests and implementation of the other ones sounds like a sane plan to get done quickly on something that'd be a slog for humans to work through (I'd rather focus on the important parts manually like making sure stack frames are handled correctly,LCIM,etc whilst some kind of assistant can do the "boring" parts in a way that I can easily verify myself).
Now, ideally some of the grunt-work could have been avoided if we'd have good portable ideally licensed machine readable datasets of things like instruction sets and encodings, but we mostly don't.
3
u/weregod 17d ago
IMHO verifiing LLM boilerplate code is more work than writing it manually. If it is low stake low effort project maybe this will work. But debugging compilers is too hard to delay understanding of code to test stage.
3
3
u/MithrilHuman 17d ago
We use it in ROCm, and I interviewed with CUDA teams. They use it too. AI is good at debugging code given you know how to setup codename indexing and memory, or AI ops team in your company does that for you.
2
u/gplgang 17d ago
I've been having a lot of trouble using them for writing code, but they've been extremely valuable for debugging or certain constrained things (an instruction encoder was one). Are you finding luck with them for writing code you ship? I got burned one too many times from it and stopped trying in my compiler, though I do get curious still
1
u/whizzter 17d ago
The thing in a scenario like this is that you can setup a testing harness with a source-of-truth with a real compiler and/or unoptimized code, glancing at the code no being insane and passing would probably be enough to get 98% of the way.
Also, I'm thinking this is more ok (building a compiler for a retro-platform) as opposed to building a compiler for something that is exposed to the internet with some stakes.
1
u/Stunning_Pineapple57 10d ago
With a compiler as long as the compile speeds are fine it’s not so much a case of verifying the compiler code but verifying the results and its an area which is more deterministic and less subject so easy to verify and measure
7
u/MithrilHuman 17d ago edited 17d ago
Dedicated test and debug agents and teams. That's how AMD works now. I don't make the rules, management does. If you're not using AI, you're low performing.
0
0
18d ago
[deleted]
4
3
u/PACmaneatsbloons 18d ago
Þat is because it is an LLVM fork. You are looking at þe LLVM stats.
3
u/zsaleeba 18d ago
I think this may be the first time I've ever seen thorn (þ) used casually, in the wild
3
2
u/amgdev9 18d ago
That means rust for gameboy? 👀
0
u/zlfn 18d ago
Yes, at first it was made to bring Rust to the Game Boy: https://www.reddit.com/r/rust/comments/1w4g9vv/the_worlds_first_game_boy_rom_written_in_pure_rust/
There are also others who have developed Game Boy ROMs in Swift/Zig + LLVM-Z80
6
u/theangryepicbanana 18d ago
a z80 llvm backend already exists, get your vibecoded slop outta here
4
u/shrimpster00 18d ago
Yeah, there's been a few. I made a proof-of-concept myself once for my old graphing calculators.
0
u/zlfn 18d ago
Oh... I don't think you'd know more about existing Z80 backends than I do.
If you're talking about the (e)Z80-clang series, it's built almost exclusively for the eZ80's ADL mode. It does support the Z80, but it's hard to call that full support. It's more of a bonus, after all.
https://github.com/dinoboards/ez80-clang
https://github.com/CE-Programming/llvm-project
https://github.com/jacobly0/llvm-project1
2
18d ago
You can check the benchmark here
This is great, finally I can compare my own Z80 backend (for my language). This was done last year to test out my Z80 emulator.
I have the 'sieve' benchmark too (also from the BYTE article!). The results compared to the first two columns in that link are:
Cycles Time Size
SDCC 2.35M 588ms 135 bytes
LLVM-Z80 2.26M 565ms 216
Mine 5.66M 1420ms 290So not that great, but then mine is not an optimising compiler: it more or less just directly translates stack-IL code. However it is roughly on a par with some of those other products.
3
u/zsaleeba 18d ago edited 18d ago
SDCC really is remarkably good. I've been working on a Z80 backend for my compiler, too, and it's still a long way from SDCC and LLVM-Z80. Register allocation for tiny 8 bit CPUs is a whole different ball game from large, modern CPUs.
5
u/tommythorn 18d ago
Yes, as Z80 is an awful compiler target lots of hand tuning and adhoc codegen can go a long way and actually there's little room for Dragonbook style optimization. HiTech C (IIRC) and BLS Pascal did a remarkable job.
Context: I worked on Small-C 1985-1986 and occasionally dream in Z80 opcodes (my first computer was Z80 based and initially could only be programmed in hex code).
AI-assisted development is here to stay. My only concern is that it has led to a "fork-first, and abandon tomorrow" mentality. I hope the OP's project is the exception.
1
u/zlfn 18d ago
Actually, many of LLVM's optimizations are quite helpful for the Z80 as well. Of course, there are cases where they don't work, but Dragon Book-style optimizations are effective in quite a few cases.
By today's standards, it's hard to call HI-TECH C's optimization particularly good. There are much better compilers now. Some Small-C-based forks are still around, and I'm curious whether you've looked into any of them. Anyway, since z88dk currently relies on Small-C, LLVM-Z80 also supports a Small-C-compatible ABI as an option.
FYI, this project has been in development for about 10 months now, so I don't think you need to worry about it being abandoned anytime soon.
1
u/tommythorn 18d ago
Heh, sorry just disregard my HI-TECH comment. I literally haven't thought about it in 40 years and I may well have been thinking about something else.
I don't do anything with Z80 anymore and would probably not touch compilers, outside of wacky languages or interesting new architectures (github.com/tommythorn).
1
u/Torn_up_yarn 10d ago
Vibecoded experiments have shown that the LLVM core _can_ be taught about the peculiarities of the Z80 processor (so that for instance the B register is free for DJNZ in the innermost loop, etc). Then comes the process of coding it correctly...
2
u/whizzter 17d ago
Hmh, I was actually looking around recently for SDCC alternatives due to some codegen issues on my Gameboy game (really not feeling like dropping down to ASM for much of it), part was size and part was feeling that a lot could be done more "focused" like Oscar64 seems to do on MOS.
That code-size growth doesn't feel too promising though since I'm already starting to feel a squeze on a main page and I'd rather have the core mechanics,etc fit in one bank, u/zlfn what's the main parts LLVM does good (since perf seems good) and what needs improvement (70% bloat doesn't sound as nice)?
1
u/zlfn 17d ago
LLVM shows considerable strength in global optimization, and many routines benefit from its advanced IR-level optimizations, which SDCC does not provide.
For example, in this case the LLVM optimizer simplifies the C code significantly before it reaches the backend, so it produces better code than SDCC: https://godbolt.org/z/4sjzqGxc8
However, because these optimizations are designed for "general" targets, they can sometimes produce inefficient code for the Z80. Here the code is slower because LLVM replaces the subtraction loop with a division (since division is very fast on most modern machines): https://godbolt.org/z/Y8K5joooY
In addition, LLVM's register allocator is generally designed with a large number of general-purpose registers in mind, which makes it inefficient for targets like the Z80. SDCC, on the other hand, allocates registers much more efficiently because it uses a special allocator that is only practical when there are few registers (as I recall, the running time of SDCC's tree-decomposition-based allocator grows exponentially with the number of registers).
Also, SDCC's backend is still more mature than LLVM-Z80's, so there are still many areas where our optimization is immature: https://godbolt.org/z/9f3Pbjaov
We are improving the compiler by raising the quality of the backend and tuning LLVM's optimizations at the backend level. Improvements that are useful in general are also contributed upstream to LLVM.
In the long term, we also aim to build our own register allocator.
If you try it out, your feedback would be a great help to LLVM-Z80!
1
u/nicholas_hubbard 18d ago edited 18d ago
I helped create a Sega Genesis emulator a long time ago for a retro game company. The Sega Genesis uses a Z80 for audio processing. We used an existing Z80 emulator that I had to hook up to the rest of the system. I remember the hell of hours of reading Z80 instruction backtrace to debug bad audio in some cases. It drove me a bit insane.
I'm going to see if I can help out on this since I have some prior experience with Z80 assembly.
1
-5
u/seg_lol 18d ago
Sitting down and having an LLM interview you about what you know about Z80 to create doc would probably be a great start. Tell claude code to enumerate the gh issues and then use those for a QA session on how you would address each one or where to look for more info.
2
u/MCWizardYT 18d ago
Or maybe they want to do it themselves for the experience rather than instructing a chatbot to do the work for them
1
u/seg_lol 17d ago
Where did I say that a chatbot would take work away? Being able to do a targeted knowledge transfer from /u/nicholas_hubbard to a Z80 backend is not limited by the LLM, it is limited by how much time they have.
I offered a technique that I have used and could be effective for others. How that advice is used is up to the participants. Take it or leave it, I don't care.
1
1
u/whizzter 17d ago
Actually stumbled upon this project a few weeks back when researching due to feeling shortcomings of SDCC for a game, felt a tad too much AI vibe and a bit unclear on how well supported GBZ80 is but seeing life in trying to get a community is a good indicator.
Got started on tinkering on a C compiler to compile my game demo but might give this a stab at compiling it first (The generated code size increase vs SDCC in that other comment did give me a bit of a pause though).
3
u/zlfn 17d ago
AI is used quite a lot, yes. Still, I review almost every change carefully and correct it myself. English isn't my first language, though, so using AI for translation probably added to the "AI vibe" as well.
GBZ80 (we call it SM83, since the Game Boy CPU is actually quite different from the Z80) is a tier-1 target in this project. In fact, the project was originally made for the Game Boy. But my recent work has been focused on the Z80, so there are still a few rough edges on the SM83 side.
As for the code size increase, it's a problem shared by LLVM-based compilers for tiny targets in general, and LLVM-MOS has a similar issue: https://thred.github.io/c-bench-64/benchmarks/ This is because some of LLVM's general optimizations don't fit small targets like these very well.
That said, we're working on a lot of optimizations to address this, and we're trying to make it the most efficient Z80 compiler out there. If you try it and give us feedback, it would be a huge help to the project.
1
1
u/rocco_himel 17d ago
Please give me a good reason why LLVMs are good.
1
u/Torn_up_yarn 10d ago
LLVM is a compiler architecture, not a large language model.
1
u/rocco_himel 10d ago
I never said an LLVM was an LLM. They are two very separate things.
1
u/Torn_up_yarn 8d ago
True. But why then question why a LLVM compiler is a good thing?
1
u/rocco_himel 8d ago edited 8d ago
Because I would like to know why OP thinks an LLVM architecture is a good thing.
1
u/zlfn 8d ago
Well... I think others have already explained why LLVM is good, but anyway:
We can easily leverage great existing optimizations, many of which are also useful for the Z80.
The tools provided by LLVM are much more "modern" than those of the existing Z80 compilers. For example, SDCC uses an object format called ASxxxx XL4, which has a considerably less efficient structure than the ELF format used by LLVM (and other modern tools).
By implementing an LLVM backend, we can make multiple languages run on the Z80. Rust, Swift, and Zig are representative examples.
Because LLVM has a "modular" structure, we don't have to worry about maintaining the frontend or middle-end. Clang is much more user-friendly than other C frontends, especially because it provides excellent error messages.
There are countless other reasons why LLVM's structure is so good. (Of course, it's not without its flaws.)
1
u/rocco_himel 8d ago
You're confusing complexity with progress.
LLVM is a gigantic compiler infrastructure designed to solve problems that most programmers don't even have. You're talking about an 8-bit Z80 processor, and your solution is to bring in an enormous compiler framework with millions of lines of code.
That's ridiculous.
First, optimizations aren't magic. The Z80 has a small instruction set, a limited number of registers, and a very specific architecture. A compiler written specifically for the Z80 can optimize for those limitations without dragging in an entire compiler infrastructure.
Second, it absolutely does not matter if ELF is more modern. Modern doesn't mean better. An object format should be simple enough that a programmer can understand it and write a linker for it. You're treating ELF like it's some great technological achievement when it's just a file format. The CPU doesn't care how modern your object files are.
Third, supporting Rust, Swift, and Zig sounds impressive, but those languages weren't designed for an 8-bit computer with 64 kilobytes of address space. Having an LLVM backend doesn't magically make their runtime requirements, memory models, and standard libraries compatible with the Z80.
Fourth, you're saying LLVM is better because you don't have to maintain the frontend or optimizer. That's not simplicity, but dependency. Now your compiler depends on a massive external project that you don't control.
I wrote my own compiler because I wanted to understand and control the entire system. The compiler, assembler, linker, operating system, and programming language were designed to work together.
You don't need a gigantic abstraction layer between the programmer and the machine.
If I were writing a Z80 compiler, I'd write a small compiler that generates Z80 machine code directly. I'd make the assembler and linker simple enough that one person could understand the entire implementation.
That's good engineering.
LLVM has legitimate uses, but you're acting like using the biggest and most complicated tool automatically makes your software better when it really doesn't.
The purpose of a compiler is to translate a programming language into machine code. If you need millions of lines of infrastructure to accomplish that on an 8-bit processor, maybe you should reconsider your design.
I am definitely not trying to attack you here, in fact I want you to keep doing this. I just don’t think an LLVM for a Z80 makes sense.
1
u/zlfn 8d ago
First, I think the LLVM middle-end is more useful for optimization than you might expect. Having an unusual architecture doesn't have much to do with the middle-end optimizing code to run faster in general. In practice, the LLVM optimizer in LLVM-Z80 simplifies a lot of C code before it even reaches the backend, and in many cases it helps produce much more efficient code than SDCC, the existing compiler.
Second, maybe calling it "the ASxxxx format" made it sound like I was focusing on the format itself. The bigger problem is that SDCC, probably the most mature existing compiler, and its surrounding ecosystem are quite inefficient. For example, unless an archive is split up by function, SDCC doesn't even offer the basic ability to remove unused functions from the binary at link time. With LLVM, on the other hand, a little effort gets you lld, along with powerful LTO.
Third, Rust, (Embedded) Swift, and Zig don't have memory models that are very different from C's, so they share the same inefficiencies as C. Programming the Z80 in C hasn't been very efficient for the past half century either, and LLVM-Z80 is just an attempt to make that more effective. I don't know Zig and Swift very well (other people are working on those), but for Rust, there are lots of bare-metal platforms that use only no_std and core without the standard library. Are they all "targets that don't fit Rust" just because the standard library can't be ported to them? In practice, Z80 code written in Rust isn't that different in efficiency from Z80 code written in C.
Fourth, understanding and controlling the whole system is a good goal, of course, but LLVM-Z80's goal is simply to provide the best compiler people can use. There are already well-built frontends and middle-ends, so why rebuild them from scratch? It does mean depending on the whole LLVM project, but I don't really see why that's a bad thing. It just has a different goal from other compiler projects. Isn't it much easier for one person to understand just the backend, with LLVM's abstractions behind it, than to understand the frontend, middle-end, and backend all at once?
Also, you might think compiling C for an 8-bit processor is simpler than for other platforms, but generating efficient Z80 code is actually a pretty complex problem. Even SDCC, a compiler built specifically for 8-bit processors as you suggested, is about 100,000 lines once you add up the frontend, the shared code, and the Z80 backend. LLVM-Z80 is under 30,000 lines.
1
u/rocco_himel 7d ago
You’re missing my point. I’m not saying LLVM can’t produce good machine code. I’m saying that producing good machine code isn’t the only thing that matters when you’re designing a compiler.
If LLVM-Z80 produces better code than SDCC, that’s a legitimate achievement. I’m not going to argue against actual results. But you haven’t demonstrated that LLVM is necessary to achieve those results. You’ve demonstrated that LLVM-Z80 is better at certain optimizations than an existing compiler.
The linker argument is reasonable too. Dead-code elimination and link-time optimization are useful. But those aren’t features that inherently require LLVM. You can implement them in a smaller toolchain. Whether that’s worth the development effort is a separate question.
As for Rust, I agree that you can write bare-metal programs without a standard library. That doesn’t mean every language feature is equally suitable for every processor. But if your Rust backend produces code comparable to C, then that’s a good result. I’m not going to pretend otherwise.
My disagreement is with your definition of a good compiler. You want to reuse existing infrastructure to produce efficient machine code and support multiple languages. That’s a reasonable goal. I want a compiler where the entire implementation is small enough to understand, modify, and maintain without depending on an enormous external project.
You say LLVM-Z80 is under 30,000 lines. That’s the backend. It doesn’t include the LLVM infrastructure required to make it work. Comparing that number with SDCC’s complete compiler implementation is misleading. You’re counting the code you wrote, not the code your compiler depends on.
And yes, generating efficient Z80 code is complicated. Nobody said otherwise. But adding a massive compiler framework doesn’t make that complexity disappear. It moves much of it into software maintained by somebody else.
I’m not arguing that everyone should write a compiler from scratch. I’m arguing that understanding and controlling the complete system is a legitimate engineering objective, not some outdated philosophy.
If your goal is to provide the best optimizing compiler for the Z80, LLVM might be the right choice. If your goal is a small, independent, understandable toolchain, it probably isn’t.
Those are different goals.I just don’t agree that reusing a massive existing system is automatically better engineering than building something specifically for the machine you’re targeting.
1
u/zlfn 5d ago edited 5d ago
It seems our views on what better engineering means are quite different. To me, better engineering means getting the best possible result with the least possible effort. For that goal, LLVM is a framework that fits very well. As you said, a small, independent, easy-to-understand toolchain is not LLVM-Z80's goal, and I never argued that LLVM-Z80 is a good compiler because it is small and easy to understand.
From a maintenance perspective, too, the frontend and the middle end are as complex as the backend, and they call for engineering that is completely separate from it. If someone else is willing to maintain those for you while you focus on the backend, why would you turn that down?
Minimizing dependencies can be one sign of good engineering, of course. But many modern projects also treat achieving more with less effort through good dependencies as important engineering. In other words, don't reinvent the wheel. Should we reimplement the operating system and libc just to build a web backend we fully understand? I don't think so.
Building a compiler specifically for the target machine has its merits. But having compilers for many architectures share their common parts and maintain them together is also a well-proven approach, and that is how GCC and LLVM work.
As you said, understanding and controlling the whole system is a legitimate engineering goal. I just don't think it's a good way to build a good compiler. To me, good engineering means reaching the highest level of completeness with the least effort. Understanding the whole ecosystem from scratch, from the frontend, middle end, and backend to the linker and assembler, would take contributors several times more effort than implementing a Z80 backend. LLVM-Z80, on the other hand, reaches its engineering goals more simply by implementing a Z80 backend on top of the LLVM framework.
There are many ways to define "good". But to me, what generally makes a compiler "good" is producing the most efficient output for the user's code. By that standard, LLVM is a "good" framework, and using it is justified.
1
u/Torn_up_yarn 6d ago
It moves much of it into software maintained by somebody else.
This. Exactly this. Somebody else than you might care for this when you lose interest.
1
u/Torn_up_yarn 6d ago
There is value in having the open source compiler with the largest momentum currently, target small and old CPU targets too. There is a large value in standing on the shoulders of others.
If you were writing a Z80 compiler you would rediscover yet again how hard it is to get it to generate as good code as LLVM-Z80 provenly can. If you don't care about code density and speed then by all means write your own compiler...
1
u/ilnarildarovuch 16d ago
As the saying goes: if you have to explain, then you don't need to explain.
1
u/rocco_himel 16d ago
What the hell is that’s supposed to mean?
1
u/ilnarildarovuch 16d ago
Just guess
1
u/rocco_himel 16d ago
“If you have to explain, then you don’t need to explain”.
Can you please explain further what this means?
1
u/ilnarildarovuch 16d ago
Если нужно объяснять, то не нужно объяснять
1
u/rocco_himel 16d ago
I asked you to explain further, not to repeat yourself.
1
u/ilnarildarovuch 16d ago
LLVM is a module system, that uses do much thing, so it's even hard to name everything. But for output: it's more optimized, determined.
1
u/R-ten-K 16d ago edited 16d ago
Basically LLVM makes sophisticated compiler technology reusable, scalable, and economically viable, by decoupling programming languages from the processor architecture. So the target languages for the compiler can share a common intermediate representation and optimization infrastructure.
This is a tremendous multiplier effect: improvements to the compiler infrastructure benefit multiple languages and architectures simultaneously. Similarly, adding a new backend can also make new architectures accessible right away without requiring massive retooling or rewriting of the compiler from scratch.
1
u/Slow-Sweet7991 16d ago
Looking to contribute to a new llvm backend or new npu target in IREE or any MLIR-based compiler. If anyone is doing any open-source project, please let me know.
0
u/True_Locksmith2751 18d ago
Hi! I’d like to join to the project. Is contributing to the code should be manually or using Claude code is ok?
1
u/zlfn 17d ago
Yes, in general, it's fine to use whatever coding assistant you like.
However, you should be able to explain your code and take responsibility for it. (Most open-source projects, such as Linux and LLVM, have similar policies.)
If I used Claude Code all day, I could quickly produce a massive optimization patch with a +10,000-line diff, but in the long run, code like that is hard to maintain.
You're free to submit PRs, but I only have limited time to review code, so PRs with huge diffs that are hard to follow may end up sitting unreviewed for a long time.
Also, for changes that need design discussion, such as new features or behavior changes, please open a discussion or an issue first and reach an agreement before starting work.
0
17d ago
The scale of this project is huge. I tried downloading it, but gave up after 30 minutes when it had only extracted 60,000 of the 200,000 files from the download.
How many of those 200K files are specific to Z80, and how many of the latter were machine-generated? How big is a standalone compiler binary?
Just trying to get a sense of it (as the stuff I do is on a tiny scale by comparison).
2
u/zlfn 17d ago
The reason this project is so large is that it is fundamentally a fork of LLVM project.
The Z80 backend itself is only a few hundred files, and excluding tests and the runtime, it comes to around 30,000 lines of code.
If you only want the final compiler binaries, you can download them here. It's about several hundred megabytes : https://github.com/llvm-z80/llvm-z80/releases
1
u/Torn_up_yarn 10d ago
When cloning you can tell git to only take a subset (like the latest) which helps quite a lot. This carries the history of the llvm project...
13
u/Hjalfi 18d ago
Do you know about the llvm-mos65 project, which is doing the same for the 6502? If not you should probably talk to them --- they have done lots of 8-bit specific optimisations like moving locals into globals where safe. While the Z80 is a little more C-friendly than the 6502, it still hates stack frames, so this would be useful for you?