stardance has been extended another month! the new deadline is october 31 :)

You are browsing as a guest. Sign up (or log in) to start making projects!

Risc-V Compiler

  • 8 Devlogs
  • 53 Total hours

A Risc-V compiler written in C for the pico 2 W.

Open comments for this post

9h 17m 1s logged

Blinky blinky. First, I added parameters for calling functions. Then I had everything I needed to start adding GPIO support. I added the ability to toggle any of the GPIO pins on the pico 2. The compiler used the source code shown on the right and converted it into 386 lines of assembly. The compiled code is very fast! For every blink, it counts from 0 to 1000000

0
0
17
Open comments for this post

8h 50m 34s logged

I have done a lot of work on functions, variables, and control flow. I have also set up the required functions included automatically in each program. This part of the program manages things such as memory and function calls, which are essential to the execution of user code. This allowed me to generate functions, variables, and if statements now. The compiler outputted a 173 line program, but below shows a small section of the output. As you can see, the compiler is working!

0
0
18
Open comments for this post

8h 3m 35s logged

I made a lot of progress on the special parser. It converts the input into postfix notation, with the operators after the operands. Then, the ASM Generator uses the postfix notation to generate actual assembly! As you can see from the ✨Beautiful✨ picture I drew, this simple equation actually expands into many assembly instructions. Unfortunately, to make the special parser I had to get rid of most of the type checking.😐

0
0
33
Open comments for this post

9h 43m 32s logged

I worked on adding type checking. It is still missing a lot but if I don’t move on I am going to run out of time. I was able to get it to check for type errors within equations and assignments. I also started working on converting the tree into actual assembly, but I realized that it was parsing my addition right to left 🥀🥀. So I started the process of making a dedicated shunting yard parser for the equations

0
0
3
Open comments for this post

7h 47m 47s logged

Big progress!!! The syntax checking is done! I spent quite a long time creating the context-free grammar in an excel sheet. This defines all of the syntax rules allowed, and outlines which result in errors. This means that all of the functions/symbols for the language have been defined. I also added some error messages and started the semantic analyzer, which checks type errors.

0
0
46
Open comments for this post

3h 6m 41s logged

I received my two Pico 2s today. I spent some time trying out examples and modifying them, and I managed to get the LED to blink, which was surprisingly difficult to find examples for because I needed it in Risc-V assembly. Then I worked on generating a tree from the parser I made in the last devblog. It seems to work well, but it is kind of hard to tell. Next I think I’ll either do semantic error checking, or skip right to the assembly generation and worry about the semantics later :)

0
0
22
Open comments for this post

3h 29m 34s logged

I worked on creating the Syntax analyzer for my Risc-V compiler. This stage checks the structure of the program and any grammatical errors. I had to do a lot of research on CFGs (Context free grammars). They define the rules for the language. Below is a spreadsheet of the CFG. I will improve it in the future to add more functions. I implemented an LL(1) parser. I was successfully able to check the grammar of a simple program. I still need to make the parser construct an abstract syntax tree. I realized that it is quite difficult to find pictures to post because it mostly happens in the console, but trust me, interesting things are happening!

0
0
6
Open comments for this post

2h 45m 58s logged

I have just started working on my first compiler. I have coded a couple of interpreters before, but this is my first time creating a compiler. I am designing it for the Pico 2 W and will be translating a modified C into Risc-V assembly. So far I have created the lexer which separates the source code into tokens. I have also set up a nice starting infrastructure including some error tracing. Below is the output of a test source code tokenized. Funnily enough, I’m running this compiler on a Pico as well. In the future, I hope to incorporate this compiler into a Pico based OS.

0
0
33

Delete project?

Are you sure you want to permanently delete this project? This action cannot be undone.

All devlogs, followers, and associated data will be removed.

Followers

Loading…