2022-05-02 22:50:44 +00:00
|
|
|
|
# Compilers: How To Make a Programming Language
|
2022-02-14 14:38:30 +00:00
|
|
|
|
|
2022-05-02 22:50:44 +00:00
|
|
|
|
Other compiler-related topics out of scope:
|
|
|
|
|
- What are programs anyway (Forth, LISP)
|
|
|
|
|
- Computation: Turing machines, lambda calculus
|
|
|
|
|
- Compiler optimization
|
|
|
|
|
- GC (motivated by LISP)
|
2022-02-14 14:38:30 +00:00
|
|
|
|
|
2022-05-02 22:50:44 +00:00
|
|
|
|
aesthetics:
|
|
|
|
|
- stay motivated; stick close to a c-like, imperative, procedural model because that's what people are used to
|
2022-02-14 14:38:30 +00:00
|
|
|
|
|
2022-05-02 22:50:44 +00:00
|
|
|
|
motivation / goals / what questions are we trying to answer:
|
|
|
|
|
- I want to be able to make a toy procedural language.
|
|
|
|
|
- like C, Algol, JS, Lua, etc.
|
|
|
|
|
- possible user motivations:
|
|
|
|
|
- I want to make a game scripting language
|
|
|
|
|
- I want to make a DSL for my job (and I want syntax highlighting!)
|
|
|
|
|
- I want to do simple static analysis of my projects
|
2022-02-14 14:38:30 +00:00
|
|
|
|
|
2022-05-02 22:50:44 +00:00
|
|
|
|
ok what do we want to cover
|
|
|
|
|
- classical compiler structure (lexer -> parser -> codegen)
|
2022-05-04 21:53:55 +00:00
|
|
|
|
|
|
|
|
|
| Title | Page |
|
|
|
|
|
|------------------------------|------|
|
|
|
|
|
| Phases of a Compiler | https://www.geeksforgeeks.org/phases-of-a-compiler/ |
|
|
|
|
|
| Compiler Architecture | https://cs.lmu.edu/~ray/notes/compilerarchitecture/ |
|
|
|
|
|
| Compiler Design | https://www.tutorialspoint.com/compiler_design/compiler_design_phases_of_compiler.htm |
|
|
|
|
|
| Structure of a Compiler | https://www.csd.uwo.ca/~mmorenom/CS447/Lectures/Introduction.html/node10.html |
|
|
|
|
|
| The Structure of a Compiler | https://www.brainkart.com/article/The-Structure-of-a-Compiler_8121/ |
|
|
|
|
|
| Wikipedia: Compiler | https://en.wikipedia.org/wiki/Compiler |
|
|
|
|
|
| Compiler Phases | https://www.javatpoint.com/compiler-phases |
|
|
|
|
|
| The Structure of a Compiler | https://pages.cs.wisc.edu/~fischer/cs536.s08/lectures/Lecture04.4up.pdf |
|
|
|
|
|
| Phases of a Compiler | https://www.guru99.com/compiler-design-phases-of-compiler.html |
|
|
|
|
|
| Writing a C Compiler (Pt. 1) | https://norasandler.com/2017/11/29/Write-a-Compiler.html |
|
|
|
|
|
| V: Structure of a Compiler | https://www.youtube.com/watch?v=RH02jcUiPI0 |
|
|
|
|
|
| V: Phases of a Compiler | https://www.youtube.com/watch?v=jE7f3sGLGVk |
|
|
|
|
|
| V: Compiler Design | https://www.youtube.com/watch?v=OZSGjRSHYUk |
|
|
|
|
|
| V: Different Phases of Comp | https://www.youtube.com/watch?v=TApMNhQPaCM |
|
|
|
|
|
| V: Phases of Compiler | https://www.youtube.com/watch?v=r2BRNodqbgI |
|
|
|
|
|
| V: Parser and Lexer (Pt. 1) | https://www.youtube.com/watch?v=eF9qWbuQLuw |
|
|
|
|
|
|
2022-05-02 22:50:44 +00:00
|
|
|
|
- semantic analysis / type checking
|
2022-05-06 00:05:11 +00:00
|
|
|
|
|
|
|
|
|
| Title | Page |
|
|
|
|
|
|-------------------------------|------|
|
|
|
|
|
| Semantic Analysis, Explained | https://monkeylearn.com/blog/semantic-analysis/ |
|
|
|
|
|
| Wikipedia | https://en.wikipedia.org/wiki/Compiler#Front_end |
|
|
|
|
|
| SA in Compiler Design | https://www.geeksforgeeks.org/semantic-analysis-in-compiler-design/ |
|
|
|
|
|
| Compiler Design - SA | https://www.tutorialspoint.com/compiler_design/compiler_design_semantic_analysis.htm |
|
|
|
|
|
| What is Semantic Analysis? | https://home.adelphi.edu/~siegfried/cs372/372l8.pdf |
|
|
|
|
|
| SA in Compiler Design | https://iq.opengenus.org/semantic-analysis-in-compiler-design/ |
|
|
|
|
|
| Implementation of SA | https://pgrandinetti.github.io/compilers/page/implementation-semantic-analysis/ |
|
|
|
|
|
| What is SA in a Compiler? | https://pgrandinetti.github.io/compilers/page/what-is-semantic-analysis-in-compilers/ |
|
|
|
|
|
| SA - An Overview | https://www.sciencedirect.com/topics/computer-science/semantic-analysis |
|
|
|
|
|
| SA (Slides) | https://www.computing.dcu.ie/~davids/courses/CA4003/CA4003_Semantic_Analysis_2p.pdf |
|
|
|
|
|
| V: The Semantic Analysis! | https://www.youtube.com/watch?v=j172YWmBk5A |
|
|
|
|
|
| V: Intro to Semantic Analysis | https://www.youtube.com/watch?v=cC8YRnDGMwI |
|
|
|
|
|
| V: Compiler Design SA | https://www.youtube.com/watch?v=57U6pQRnSJA |
|
|
|
|
|
| V: Semantic Analysis: Intro | https://www.youtube.com/watch?v=7pHmBEkeIdQ |
|
|
|
|
|
|
|
|
|
|
| Title | Page |
|
|
|
|
|
|----------------------------------|------|
|
|
|
|
|
| Type Checking in Compiler Design | https://www.geeksforgeeks.org/type-checking-in-compiler-design/ |
|
|
|
|
|
| Type Checking | https://www.brainkart.com/article/Type-Checking_8086/ |
|
|
|
|
|
| Type Checking (Slides) | https://www.slideshare.net/dipongkersen81/type-checkingcompilier-design |
|
|
|
|
|
| What is Static Type Checking? | https://www.tutorialspoint.com/what-is-static-type-checking |
|
|
|
|
|
| Type Checking in Compiler Design | https://www.wikitechy.com/tutorials/compiler-design/type-checking-in-compiler-design |
|
|
|
|
|
| Type Systems | https://www.csd.uwo.ca/~mmorenom/CS447/Lectures/TypeChecking.html/node1.html |
|
|
|
|
|
| V: Type Checking | https://www.youtube.com/watch?v=-TQVAKby6oI |
|
|
|
|
|
|
2022-05-02 22:50:44 +00:00
|
|
|
|
- modern compiler structures (IR / SSA, optimization)
|
|
|
|
|
- interpreters vs. JITs vs. AOTs vs. "transpilers"
|
|
|
|
|
- executables and linkers
|
|
|
|
|
- regular expressions?
|
|
|
|
|
- regular languages / grammars / language structure / automata
|
2022-05-04 21:53:55 +00:00
|
|
|
|
- terminology?
|
2022-02-14 14:38:30 +00:00
|
|
|
|
|
2022-05-02 22:50:44 +00:00
|
|
|
|
the c compilation process
|
|
|
|
|
- translation units
|
|
|
|
|
- preprocessing -> (the whole compilation process) -> object files -> linking
|
|
|
|
|
- c compilation model is not in favor any more, don't like compiling all these files separately
|
|
|
|
|
- ABIs and FFI
|
|
|
|
|
- should maybe be in separate article
|
|
|
|
|
|
2022-05-02 22:55:05 +00:00
|
|
|
|
experts / consultants:
|
|
|
|
|
- Bill
|
|
|
|
|
- NeGate
|
|
|
|
|
|
2022-05-02 22:50:44 +00:00
|
|
|
|
## The actual progression
|
|
|
|
|
|
|
|
|
|
- Simple expression interpreter (parse and evaluate)
|
|
|
|
|
- Classical compiler construction (lex -> parse -> output), semantic analysis / type checking
|
|
|
|
|
- motivation: complex structures! recursion! etc.
|
|
|
|
|
- many of these resources exist and cover different aspects of the process in different ways
|
|
|
|
|
- Grammars and language structure
|
|
|
|
|
- Types of output (interpreter vs. AOT vs. JIT, etc.)
|
|
|
|
|
- We can probably find resources on specific ones of these
|
|
|
|
|
- Modern phases (IR / SSA)
|
|
|
|
|
- Mention WASM?
|
|
|
|
|
- The terrors of the real world
|
|
|
|
|
- Executables, linkers, and debug info
|
|
|
|
|
- The C ABI and FFI
|
|
|
|
|
- Register allocation
|
|
|
|
|
- C is not the only language
|
|
|
|
|
- LISP
|
|
|
|
|
- Forth
|
|
|
|
|
- This could be a whole topic maybe
|
|
|
|
|
|
|
|
|
|
## Link dump
|
|
|
|
|
|
2022-05-04 21:53:55 +00:00
|
|
|
|
### Books
|
|
|
|
|
|
|
|
|
|
- Engineering a Compiler:
|
|
|
|
|
[Well liked]
|
|
|
|
|
http://www.r-5.org/files/books/computers/compilers/writing/Keith_Cooper_Linda_Torczon-Engineering_a_Compiler-EN.pdf
|
|
|
|
|
- Compiler Design in C:
|
|
|
|
|
[May have a full implementation inside]
|
|
|
|
|
https://holub.com/goodies/compiler/compilerDesignInC.pdf
|
|
|
|
|
- Dragon Book:
|
|
|
|
|
[Potentially outdated -- mixed reviews]
|
|
|
|
|
http://ce.sharif.edu/courses/94-95/1/ce414-2/resources/root/Text%20Books/Compiler%20Design/Alfred%20V.%20Aho,%20Monica%20S.%20Lam,%20Ravi%20Sethi,%20Jeffrey%20D.%20Ullman-Compilers%20-%20Principles,%20Techniques,%20and%20Tools-Pearson_Addison%20Wesley%20(2006).pdf
|
|
|
|
|
|
|
|
|
|
### Webpages
|
|
|
|
|
|
2022-05-02 22:50:44 +00:00
|
|
|
|
- lua grammar: http://lua-users.org/wiki/LuaGrammar
|
|
|
|
|
- pascal railroad diagrams: https://www.cs.utexas.edu/users/novak/grammar.html
|
|
|
|
|
- tons of links: https://github.com/aalhour/awesome-compilers
|
|
|
|
|
- expression parsing examples:
|
|
|
|
|
- pratt parsing and recursive descent: https://journal.stuffwithstuff.com/2011/03/19/pratt-parsers-expression-parsing-made-easy/
|
|
|
|
|
- dunno, not recursive descent: https://www.cs.rochester.edu/u/nelson/courses/csc_173/grammars/parsing.html
|
|
|
|
|
- gary bernhardt's compiler from scratch: https://www.destroyallsoftware.com/screencasts/catalog/a-compiler-from-scratch
|
|
|
|
|
- lambda calculus interpreter: https://justine.lol/lambda/
|
2022-05-04 21:53:55 +00:00
|
|
|
|
- chibicc (full, readable C compiler): https://github.com/rui314/chibicc
|
|
|
|
|
- A Compiler Writing Journey (has many pages/topics): https://github.com/DoctorWkt/acwj
|
2022-02-14 14:38:30 +00:00
|
|
|
|
|
2022-05-04 21:53:55 +00:00
|
|
|
|
#### From NeGate
|
|
|
|
|
- Near-Optimal Instruction Selection on DAGs: https://llvm.org/pubs/2008-CGO-DagISel.pdf
|
|
|
|
|
- The Design and Implementation of Gnu Compiler Generation Framework: https://www.cse.iitb.ac.in/~uday/courses/cs715-10/cs715-gcc-intro-handout.pdf
|
|
|
|
|
- Lecture Notes on Static Single Assignment Form: https://www.cs.cmu.edu/~rjsimmon/15411-f15/lec/10-ssa.pdf
|
|
|
|
|
- Simple and Efficient Construction of Static Single Assignment Form: https://pp.info.uni-karlsruhe.de/uploads/publikationen/braun13cc.pdf
|
|
|
|
|
- LLVM Greedy Register Allocator – Improving Region Split Decisions: https://llvm.org/devmtg/2018-04/slides/Yatsina-LLVM%20Greedy%20Register%20Allocator.pdf
|
|
|
|
|
- NULLSTONE Optimization Categories: ttp://www.nullstone.com/htmls/category.htm
|