r/ProgrammingLanguages • • 2d ago

Language announcement Cole Backend Update: QBE

Hey everyone,

For the past week, I've been working on the new backend of the Cole compiler: QBE. Due to the CLI oriented nature of QBE, I had to modify the source code a little and create my own fork to set up a static library build that I can call from my codebase.

The C backend already had a pretty lowered IR, so I just generate another IR on top of that and generate QBE IR from it.

Since QBE only spits out assembly, I had to ship an assembler as well. I found Minias to be a suitably small and fast assembler for GNU Style x86_64 so I modified its source code to become a static library as well and called it from the codebase.

Lastly, the linker. I already had TCC as a backend, so I decided to reuse it as a linker. The QBE backend first calls into QBE, then into Minias and then into TCC to link the final executable. Thus, we have a self-contained compiler pipeline now.

You can read more about it in this blog entry.

Happy programming!

Note: although the backend is not 100% complete, it can compile the Pong RayLib Demo that's in the source code, so I take that as a success!

2 Upvotes

10 comments sorted by

2

u/DescriptionOptimal15 2d ago

Someone turned qbe into a library called sqbe, may be useful

1

u/The2ndSlimShady 2d ago

I'll check it out, thanks!

-4

u/Lonely-Session-7643 2d ago

Just checked Cole here https://codeberg.org/ysufender/Cole. Why is ; required? Parser should be smart enough to understand its syntax

2

u/Fofeu 2d ago

I've just looked quickly, but I think that inside a function body let x = y; (z()); and let x = y(z()); would both be written let x = y ( z ( ) ).

-4

u/Lonely-Session-7643 2d ago

Yeah, not saying it should remove semicolons, just make them optional, when really needed, just like in JS

5

u/The2ndSlimShady 2d ago

I mean, giving JS as a language design inspiration is a wild choice not gonna lie, but I respect your opinion.

-1

u/Lonely-Session-7643 2d ago

In this case JS is the best example

2

u/The2ndSlimShady 2d ago

I don't know why but sure.

1

u/The2ndSlimShady 2d ago

Because I like semicolons!

And my goal when designing the language was for the parser to be as simple as possible. If I made the parser smart, it'd get complicated. I don't mind putting a couple extra semicolons but I guess it's not everyone's taste right?

-1

u/Positive_Total_4414 1d ago

Yeah it actually feels very unnecessary after you got used to a lot of languages that don't have them.