beordle / tccjit

Using libtcc for compiling C at runtime

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Build Status

A small C++ wrapper around libtcc (❤️) (https://bellard.org/tcc/)

Compiles code at runtime :

#include "tccjit.hpp"

int main() {

    // generate the code
    jit::Module module(
        "void func(char * txt) {"
        "    printf(\"Hello, %s\\n\", txt);"
        "}"
    );

    // fetch the function
    auto func = module.fn<void(char*)>("func");

    // run it
    func("World");

    return 0;
}

cmake generates a dynamic library that embeds libtcc, so it can be used directly in your c++ project :

g++ -L. -ltccjit example.cpp -o example

About

Using libtcc for compiling C at runtime

License:BSD 2-Clause "Simplified" License


Languages

Language:C++ 62.6%Language:CMake 36.1%Language:Shell 1.3%