GCC / Clang (Linux) |
---|
Metasm is a just-in-time compiler written in C++, it fits in 20 instructions.
This project is firstly made to be used with Moe, but since i'm writing Moe and Metasm in a generic way, i found legitimate to create a repository for each.
#include <Metasm.hpp>
#include <iostream>
int main()
{
meta::Engine engine(5);
std::string script_test6 =
"PUSH 5\n"
"PUSH 3\n"
"MUL\n" // 15
"PUSH 4\n" // 15 4
"MUL\n" // 60
"PUSH 10\n" // 60 10
"SWAP\n" // 10 60
"DIV\n" // 6
"PRINT\n";
// 6
engine.load_script( script_test6 );
std::function<int(void)> function = engine.compile(); // in-memory compilation
std::cout << function() << std::endl;
engine.compile( "basics-output", true ); // generates executable and assembly file from it
}
Metasm uses CMake, and requires libgccjit installed
With llvm clang you need g++-6 to be installed
Options | Description | Default Value |
---|---|---|
BUILD_SHARED | builds Metasm as SHARED if ON | OFF |
BUILD_EXAMPLES | build examples | ON |
DEBUG | Enable debugging symbols | OFF |
may supports:
- GCC
- 5
- 6
- Clang
- 3.6
- 3.7
- 3.8
- 3.9
let's say GP is the gccjit location where libgccjit.so is located:
apt-get install libgccjit-6-dev
git clone https://github.com/tonykero/Metasm.git
cd Metasm
mkdir build && cd build
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${GP}
export LIBRARY_PATH=${LIBRARY_PATH}:${GP}
export PATH=${PATH}:${GP}
cmake -DGCCJIT_PATH=${GP} .. && make -j4
The path i used was /usr/lib/gcc/x86_64-linux-gnu/6 with libgccjit-6-dev
Described here