Here are the specs (Hardware and software) of my machine
RAM: 8GB
Proc : Intel Core i7-4510U @ 2.00GHz
Linux mint 18 Cinnamon
word size - 64 bit
Kernel - 4.4.0-21-generic
swap Size - 10GB
HDD : 150GB
There are two ways of installing
1. Install from apt-get
2. Building from src files using tar.gz
Make sure to check this requirements.
Reference: http://apt.llvm.org
1. http://llvm.org/docs/GettingStarted.html
2. https://www.youtube.com/watch?v=4iVc204omI0
3. http://llvm.org/docs/CMake.html
Writing a Sample Pass using LLVM
1. Source folder for LLVM:
~/install/llvm/llvm-3.9
2. Build folder for LLVM:
~/install/llvm/llvm-build
3. Create a CMakeLists.txt file as below
~/install/llvm/llvm-3.9/lib/Analysis/Sample (contains Sample.cpp and CMakeLists.txt)
~/install/llvm/llvm-build/lib/Analysis/Sample (contains only the CMakeLists.txt)
6. Append a line in ~/install/llvm/llvm-3.9/lib/Analysis/CMakeLists.txt
7. Created shared library at ~/install/llvm/llvm-build/lib/LLVMSample.so
$ cd ~/install/llvm/llvm-build
$ make
8. To run analysis on a test1.c program:
$ clang -S -O0 -emit-llvm test1.c -o test1.ll
$ opt -load ~/install/llvm/llvm-build/lib/LLVMSample.so -disable-output -sample test1.ll
Reference
1. http://llvm.org/docs/WritingAnLLVMPass.html
2. AMR, PA TAs
RAM: 8GB
Proc : Intel Core i7-4510U @ 2.00GHz
Linux mint 18 Cinnamon
word size - 64 bit
Kernel - 4.4.0-21-generic
swap Size - 10GB
HDD : 150GB
There are two ways of installing
1. Install from apt-get
2. Building from src files using tar.gz
Make sure to check this requirements.
GNU Make | 3.79, 3.79.1 | Makefile/build processor |
GCC | >=4.8.0 | C/C++ compiler |
python | >=2.7 | Automated test suite |
zlib | >=1.2.3.4 | Compression library //it worked without this |
1. Install from apt-get
$ sudo apt-get clang-3.9 llvm-3.9Reference: http://apt.llvm.org
2. Building LLVM 3.9.1 from Source
- Download two tar file for llvm & clang from here
- Extract both the files inside some folder // say llvm
- Rename llvm-3.9.1.src folder as llvm-3.9 //LLVM_SRC
- Rename cfe-3.9.1.src folder as clang and move inside folder llvm-3.9/tools
- Create a folder llvm/llvm-build and cd llvm-build // LLVM_OBJ
- cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE="Release" -DLLVM_ENABLE_ASSERTIONS=On /home/rajz/install/llvm/llvm-3.9
- // after some time
- make -j2
- //after some more time
- sudo make install
- opt --version
- clang --version
- //Done
1. http://llvm.org/docs/GettingStarted.html
2. https://www.youtube.com/watch?v=4iVc204omI0
3. http://llvm.org/docs/CMake.html
Writing a Sample Pass using LLVM
1. Source folder for LLVM:
~/install/llvm/llvm-3.9
2. Build folder for LLVM:
~/install/llvm/llvm-build
3. Create a CMakeLists.txt file as below
add_llvm_loadable_module( LLVMSample4. Create the Sample.cpp as below
Sample.cpp
PLUGIN_TOOL
opt
)
#include "llvm/IR/Function.h"5. Sample pass folders at:
#include "llvm/Pass.h"
#include "llvm/Support/raw_ostream.h"
using namespace llvm;
namespace {
struct Sample : public FunctionPass {
static char ID;
Sample() : FunctionPass(ID) {}
bool runOnFunction(Function &F) override {
errs() << "Sample: ";
errs().write_escaped(F.getName()) << '\n';
return false;
}
}; // end of struct Sample
} // end of anonymous namespace
char Sample::ID = 0;
static RegisterPassX("sample", "Sample Hello World Pass ",
false /* Only looks at CFG */,
false /* Analysis Pass */);
~/install/llvm/llvm-3.9/lib/Analysis/Sample (contains Sample.cpp and CMakeLists.txt)
~/install/llvm/llvm-build/lib/Analysis/Sample (contains only the CMakeLists.txt)
6. Append a line in ~/install/llvm/llvm-3.9/lib/Analysis/CMakeLists.txt
add_subdirectory(Sample)
7. Created shared library at ~/install/llvm/llvm-build/lib/LLVMSample.so
$ cd ~/install/llvm/llvm-build
$ make
8. To run analysis on a test1.c program:
$ clang -S -O0 -emit-llvm test1.c -o test1.ll
$ opt -load ~/install/llvm/llvm-build/lib/LLVMSample.so -disable-output -sample test1.ll
Reference
1. http://llvm.org/docs/WritingAnLLVMPass.html
2. AMR, PA TAs
No comments:
Post a Comment