https://github.com/trailofbits/macroni
C and C++ compiler frontend using PASTA to parse code, and VAST to represent the code as MLIR.
https://github.com/trailofbits/macroni
Last synced: 8 months ago
JSON representation
C and C++ compiler frontend using PASTA to parse code, and VAST to represent the code as MLIR.
- Host: GitHub
- URL: https://github.com/trailofbits/macroni
- Owner: trailofbits
- License: apache-2.0
- Created: 2023-05-09T22:26:40.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2024-08-14T15:15:10.000Z (almost 2 years ago)
- Last Synced: 2025-03-28T12:51:14.964Z (about 1 year ago)
- Language: C
- Size: 532 KB
- Stars: 40
- Watchers: 12
- Forks: 4
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Macroni
Macroni is an MLIR dialect that adds macro expansions to VAST's tower of IRS.
## Requirements
The following instructions assume you are using an Ubuntu 22.04.4 LTS operating
system and are at the root of a local clone of the macroni project tree:
- LLVM, MLIR, and a PASTA-specific version of Clang:
```bash
wget -O external/llvm-pasta-beeda8d.tar.xz https://github.com/trail-of-forks/llvm-project/releases/download/beeda8d/llvm-pasta-beeda8d.tar.xz
mkdir -p external/llvm-pasta-beeda8d
tar -xvf external/llvm-pasta-beeda8d.tar.xz --directory external/llvm-pasta-beeda8d/
```
- [`PASTA`](https://github.com/trailofbits/pasta/)
```bash
cd external/pasta
git submodule update --init
```
- [`VAST`](https://github.com/trailofbits/vast)
```bash
cd external/vast
git submodule update --init --recursive
```
- Ccache (not required but strongly recommended)
```bash
sudo apt install ccache
```
- Mold (not required but strongly recommended)
```bash
sudo apt install mold
```
- Ninja (not required but strongly recommended)
```bash
sudo apt install ninja-build
```
## Building Macroni
Configure Macroni, e.g., assuming all requirements and recommendations have been
installed:
```bash
cmake -S . -B build/ -G "Ninja Multi-Config" \
-D Clang_DIR:PATH="`realpath -s external/llvm-pasta-beeda8d/lib/cmake/clang`" \
-D CMAKE_BUILD_TYPE:STRING="Debug" \
-D CMAKE_C_COMPILER:PATH="`realpath -s external/llvm-pasta-beeda8d/bin/clang`" \
-D CMAKE_CXX_COMPILER:PATH="`realpath -s external/llvm-pasta-beeda8d/bin/clang++`" \
-D CMAKE_EXPORT_COMPILE_COMMANDS:BOOL=true \
-D CMAKE_INSTALL_PREFIX:PATH=build/ \
-D CMAKE_LINKER_TYPE:STRING=MOLD \
-D LLVM_DIR:PATH="`realpath -s external/llvm-pasta-beeda8d/lib/cmake/llvm`" \
-D LLVM_ENABLE_RTTI:BOOL=true \
-D LLVM_USE_LINKER:STRING="mold" \
-D MLIR_DIR:PATH="`realpath -s external/llvm-pasta-beeda8d/lib/cmake/mlir`"
```
Build macroni:
```bash
cmake --build build/
```
## Running Macroni
Once the `macronify` binary has been built, you can run it on a C source file.
Assuming `macronify` has been installed and its location added to your path:
```bash
macronify -xc some_file.c
```
## Testing
To run Macroni's tests first install LIT and FileCheck:
- LIT
```bash
python3 -m pip install lit
```
- FileCheck
```bash
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh 17
sudo apt install llvm-17-tools
```
Then add the following definitions when configuring building Macroni:
```bash
cmake -S . -B build/ -G "Ninja Multi-Config" \
...# Previous definitions
-D MACRONI_ENABLE_TESTING:BOOL=ON \
-D LLVM_EXTERNAL_LIT:STRING="`which -s lit`"
```
Finally, run Macroni's tests by building the target `check-macroni`:
```bash
cmake --build build/ --target check-macroni
```
## License
Macroni is licensed according to the Apache 2.0 license. Macroni links against
and uses Clang and LLVM APIs. Clang is also licensed under Apache 2.0, with
[LLVM](https://github.com/llvm/llvm-project/blob/main/clang/LICENSE.TXT)
exceptions.