Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/omarazizi/expression-compiler
Simple Expression Compiler in C++ & LLVM
https://github.com/omarazizi/expression-compiler
compiler llvm llvm-i
Last synced: 23 days ago
JSON representation
Simple Expression Compiler in C++ & LLVM
- Host: GitHub
- URL: https://github.com/omarazizi/expression-compiler
- Owner: OmarAzizi
- Created: 2024-06-18T15:27:39.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2024-06-18T16:03:04.000Z (5 months ago)
- Last Synced: 2024-10-15T17:37:23.074Z (23 days ago)
- Topics: compiler, llvm, llvm-i
- Language: C++
- Homepage:
- Size: 12.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# expression-compiler
This is just me practicing compiler engineering after a long time of not doing so :)## How to Compile
First clone the repository
```bash
git clone https://github.com/OmarAzizi/expression-compiler.git && cd expression-compiler
```Then make the `build` directory and change into it
```bash
mkdir build && cd build
```Run the build command
```bash
cmake -GNinja -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DLLVM_DIR=/usr/lib/llvm ../ && ninja
```Then go into the `src` directory inside of `build` where you will find the `calc` executable and run the following command:
```bash
./calc "with a: a*3" | llc -filetype=obj -relocation-model=pic -o=expr.o
```
**Note**: The expression could be changed to anything you want, with any amount of variablesThen link `expr.o` with the runtime library `rtcalc.c` as follows:
```bashclang -o expr expr.o ../../rtcalc.c
clang -o expr expr.o ../../rtcalc.c
```
After running the `expr` executable you will be asked to input a value for `a`## Example of compiling an expression
![image](https://github.com/OmarAzizi/expression-compiler/assets/110500643/2c14dfef-b7a3-41c9-bf79-857124d7b089)