Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/sloorush/llvm-pass-learn

Small dummy llvm pass created while learning how to write a llvm pass.
https://github.com/sloorush/llvm-pass-learn

Last synced: about 1 month ago
JSON representation

Small dummy llvm pass created while learning how to write a llvm pass.

Awesome Lists containing this project

README

        

# llvm-pass-learn

A dummy LLVM pass collection made to learn.
It's for LLVM 14.

Build:

$ cd llvm-pass-skeleton
$ mkdir build
$ cd build
$ cmake ..
$ make
$ cd ..

## Logger Pass

A dummy LLVM pass to log the LLVM IR and get the functions, basic blocks, and instructions.

Run:

$ clang -flegacy-pass-manager -Xclang -load -Xclang build/logger/libLoggerPass.* a.cpp

## BadCalculator Pass

A bad calculator that changes you first addition to multiplication

Run:

$ clang -flegacy-pass-manager -Xclang -load -Xclang build/badCalculator/libBadCalculatorPass.* a.cpp

Example

```
❯ clang a.cpp
❯ ./a.out
❯ echo $?
6
❯ ./a.out a b c
❯ echo $?
9
❯ clang -flegacy-pass-manager -Xclang -load -Xclang build/badCalculator/libBadCalculatorPass.* a.cpp
HOHOHO Bad calculator
❯ ./a.out
❯ echo $?
5
❯ ./a.out a b c
❯ echo $?
20
```

## First operator

Logs the result of the first binary operation

Example

```
❯ cc -c rtlib.c
❯ clang -flegacy-pass-manager -Xclang -load -Xclang build/firstOperator/libFirstOperatorPass.so -c a.cpp
❯ cc rtlib.o a.o -o exe
❯ ./exe
computed: 6
```

---

Skeleton to write the LLVM pass was picked up from -> https://github.com/sampsyo/llvm-pass-skeleton