Build an educational compiler from scratch.
Not even having a C
Image Not Showing Possible ReasonsLearn More →
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
How about VitaminC? I come up this idea with the C.C. Lemon thing.
Lai-YT
VitaminC it is!
Lee
Then, I suggest that we can use fruits as our organization name, and "Food for thought" as the description. 🤟🍊
Lee
It would be much more enjoyable if we could run the compiled C executable on an x86-64 computer, wouldn't it? XD (looking forward on supporting it as one of our goals)
Lai-YT
Sure, we can add x86-64 as our second target. I chose RISC-V and ARM because they are RISC family instructions, which are easier to implement. Let's add x86-64 to phase 2.
Lee
I would like to handcraft the parser, but I currently have no idea how to handle the lexer.
I will explore how other developers have dealt with the lexer and see if that gives me any ideas.
Lai-YT
Another option would be to use Lex and Yacc in Phase 1 to accelerate the development process. We could then prioritize optimization in Phase 2 or use a hand-written parser if optimization is not a major concern.
But make sure we're careful about using them so that our compiler is well-modularized and each component can evolve with as little pain as possible.
Lai-YT
Sure, using Lex and Yacc can save us time after finished writing our compiler homework.
Lee
I think there is an advantage to using intermediate representation (IR) early in the compiler development process.
By doing so, we can leverage the back-end of LLVM after implementing the front-end, rather than having to implement the entire compiler before being able to test it.
However, I am unsure about the level of difficulty involved in converting the code to IR instead of directly converting it into RISC-V instructions.
If it requires significant effort, the potential benefits may not justify the extra work involved.
Lai-YT, revised by ChatGPT
Nice one ChatGPT 😎Do we want to implement our own IR?
In the long term, yes, I do want us to development our own IR.
In the short term ,I think its more complicated since we don't have much experience in designing an IR. That's why I move implementing IR to phase 2 after we finished crafting a simple compile from frontend to backend. Also, I think after we implemented our own backend, we will have more thoughts on designing an IR.
Yet, you did mention one point on having an existing backend for us to test. Maybe we can try to leverage a small compiler backend like QBE?Lee
Designing a new IR seems quite unnecessary. It's hard to work with existing tools.
While LLVM's IR can be quite complex, the QBE back-end that you suggested seems like a good starting point for beginners like us.Image Not Showing Possible ReasonsLearn More →
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Lai-YT
Great! QBE's author even has a yacc example implementation, we can reference that example.
Lee
Cool!
Lai-YT
Will we need a simulator to actually run the the compiled executable?
Such as using Spike and QEMU.
Lai-YT
Yes! 🤟
Lee
Summary:
- Start with small things and expand its features.
- Always remember to initialize struct or other objects to zero, or you will get garbage. (I made this mistake several times. 😂)
- Shocking how someone can write a C compiler in a month, but he said he had 15 years of experience in C, so I guess that's why. 😧
- Rei(Author): Although I'm thinking that 8cc is one of the best programs I have ever written, I'd choose a different design than that if I were to write it again. Particularly, I'd use yacc instead of writing a parser by hand and introduce an intermediate language early on.
☝️ Something we can think about, but we're newbies compared with his experience. 😂
Lee
or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Do you want to remove this version name and description?
Syncing