Coder Social home page Coder Social logo

toy-kint's Introduction

cs526-project

HelloWorld: Your First Pass

The HelloWorld pass from HelloWorld.cpp is a self-contained reference example. The corresponding CMakeLists.txt implements the minimum set-up for an out-of-source pass.

For every function defined in the input module, HelloWorld prints its name and the number of arguments that it takes. You can build it like this:

export LLVM_DIR=<installation/dir/of/llvm/16>
cmake -DLT_LLVM_INSTALL_DIR=$LLVM_DIR -GNinja -B build -DCMAKE_EXPORT_COMPILE_COMMANDS=1 && cmake --build ./build/ -v

Before you can test it, you need to prepare an input file:

# Make sure inside build folder generate an LLVM test file
$LLVM_DIR/bin/clang -Xclang -disable-O0-optnone -S -emit-llvm ./tests/input_for_hello.c -o ./build/input_for_hello.ll

Finally, run HelloWorld with opt (use libHelloWorld.so on Linux and libHelloWorld.dylib on Mac OS):

# Run the pass
$LLVM_DIR/bin/opt -load-pass-plugin ./build/lib/libHelloWorld.so -passes=hello-world -disable-output ./build/input_for_hello.ll
# Expected output
(llvm-tutor) Hello from: foo
(llvm-tutor)   number of arguments: 1
(llvm-tutor) Hello from: bar
(llvm-tutor)   number of arguments: 2
(llvm-tutor) Hello from: fez
(llvm-tutor)   number of arguments: 3
(llvm-tutor) Hello from: main
(llvm-tutor)   number of arguments: 2

The HelloWorld pass doesn't modify the input module. The -disable-output flag is used to prevent opt from printing the output bitcode file.

Kint

For Kint the command is slightly different

export LLVM_DIR=<installation/dir/of/llvm/16>
cmake -DLT_LLVM_INSTALL_DIR=$LLVM_DIR -B build -DCMAKE_EXPORT_COMPILE_COMMANDS=1 && cmake --build ./build/

Before you can test it, you need to prepare an input file:

# Make sure inside build folder generate an LLVM test file
$LLVM_DIR/bin/clang -O0 -Xclang -disable-O0-optnone -S -emit-llvm ./tests/input_for_cc.c -o ./build/input_for_cc.ll
$LLVM_DIR/bin/opt -passes="mem2reg,dce" -S ./build/input_for_cc.ll -o ./build/input_for_cc.ll
$LLVM_DIR/bin/clang -O0 -Xclang -disable-O0-optnone -S -emit-llvm ./tests/input_for_taint.c -o ./build/input_for_taint.ll

Finally, run KINT with opt (use KINT.so) on Linux

# Run the pass
$LLVM_DIR/bin/opt -load-pass-plugin ./build/lib/KINT.so -passes=check-insertion-pass,smt-query-pass -disable-output ./build/input_for_cc.ll
$LLVM_DIR/bin/opt -load-pass-plugin ./build/lib/KINT.so -passes=kint-range-analysis -disable-output ./build/input_for_taint.ll

toy-kint's People

Contributors

chinrw avatar xuyangt3 avatar yuzhuowangbarry avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.