https://github.com/mrlsd/toy-codegen
Toy Codegen as example for `semantic-analyzer-rs` library.
https://github.com/mrlsd/toy-codegen
Last synced: about 2 months ago
JSON representation
Toy Codegen as example for `semantic-analyzer-rs` library.
- Host: GitHub
- URL: https://github.com/mrlsd/toy-codegen
- Owner: mrLSD
- License: mit
- Created: 2023-11-11T19:01:35.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2024-08-17T13:42:21.000Z (over 1 year ago)
- Last Synced: 2025-01-06T14:42:28.798Z (about 1 year ago)
- Language: Rust
- Size: 133 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Toy Codegen
Toy Codegen is the example compiler for [semantic-analyzer-rs](https://github.com/mrLSD).
As Codegen backend used LLVM, with [inkwell](https://github.com/TheDan64/inkwell).
## Basic design
There is a basic implementation of `code-generation`. The `Semantic AST` structure is
used as a basic data source. This means that any subset of `programming languages`
can be represented, the main criterion for which is representability in a
finite AST structure of Semantic Analyzer, which is used in the `semantic-analyzer`
library.
### Codegen implementation
The codege is focused only on those instructions that are presented as
an AST sample. And it is not intended to cover all possible complex
cases of code generation based on a complete set of `SemanticStateContext`
instructions. However, the end result is a fully functional binary code.
The basic parts is:
- [x] Function declarations
- [x] Functions parameters initializations
- [ ] Types declarations
- [ ] Constants declarations
- [x] Function body implementation
- [x] Let-binding
- [x] Codegen variables state
- [ ] Binding
- [x] Expressions
- [x] Codegen type conversions
- [ ] If conditions flow
- [ ] Loop conditions flow
- [ ] Function return flow
- [x] Target triple initialization (LLVM backend)
- [x] LLVM IR source code generation (and store to file)
- [x] Binary code generation (and store to file)
- [x] Code generation error flow with custom error types
## LICENCE: MIT