Compiler Weekly: LLVM to AVR

Now that we have a working LLVM backend, I wanted to make one small step forward this week. Right now, the LLVM backend setup targets x86_64 based machines. That means the program that it creates will run on my laptop. But what if I want to run my program on something different?

I have a lot of AVR microcontrollers. They are small 8-bit chips that are good for controlling small circuits. If you have ever used an Arduino the AVR chip is the main chip inside it. My goal for this week is to have my compiler produce a hex file that I can upload and run directly on one of these chips. More specifically I want to run it on an ATmega328P.

Written 07/11/2021

Compiler Weekly: LLVM Backend

All of my compiler projects so far have been focusing on the frontend. I spent a lot of time focusing on parsing languages but the runtime is usually very small. Now it’s time to take a closer look at the backend and build up some new tools.

I chose to work with LLVM because it has some great properties. I wanted a tool that could create native binaries. In my opinion, there is a huge advantage of having native code over using an interpreter or vm. I also know that LLVM has a well supported and known API. It’s a great way to get started building compilers that you know will work because other people have done it.

This week, my project will use LLVM to produce hello world binaries. There wont be much flexibility but it will show the basics needed to setup your own LLVM compiler.

Written 30/10/2021

Compiler Weekly: Truth

This week I took yet another look at improving the parser logic that I have been using. In the past I tried to use parser-combinators to build up my parsers with the idea that they might be smaller, simpler or better. This time I decided to simply write the parser from scratch.

Written 26/10/2021

Compiler Weekly: BrainF*** Interpreter

This week I set out to solve my parser woes from my last post. I worked really hard to build a library that would match my needs. In the end I came up with a project called pebble_parser. Its a similar parser combinator library to pom but with a better syntax and it works on iterators rather than arrays.

My project for this week was to build a BrainF**k compiler. Its a simple language with very little syntax. I figured it would be a great way to test out my parser without having too hard a project to complete.

Written 17/10/2021

Compiler Weekly: Calculator REPL

For this post (and maybe the next few) I want to try something different. Im calling this series “compiler weekly” because I want to explore different parts of compilers in fast iterations.

My goal of this week was to figure out what tools to use when building compilers in rust. I needed a good lexer and parser. Ideally a set of libraries that are easy to use, expressive, extendable and with good error messages.

To test this I build a very simple calculator REPL. It takes math input like this: 5 + 5 / 10 and will print out the answer. It will not handle brackets, order of operations or any other intricacies of calculators. Those are problems for a later time.

Written 13/10/2021
1 of 4 >