a2flo / tccpp

stripped-down Tiny C Compiler (tcc) for doing OpenCL C preprocessing

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TCCPP & TCC – Tiny C Compiler

Copyright © 2001-2004 Fabrice Bellard
Copyright © 2013 Florian Ziesche (stripped-down TCCPP version)

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

Purpose of this project:
After much thought (and attempts to the contrary), I finally decided that I needed a C preprocessor for the oclraster project to preprocess user provided OpenCL/oclraster shaders/programs.
Note: even though this project can still be compiled and used as a standalone binary/preprocessor, its use in that state is relatively limited, since I’ve removed most of the unnecessary command line and system specific functionality.

in-memory preprocessing sample (mixed C/C++)

string preprocess_code(const int argc, const char** argv, const string& raw_code) {
    // init
    string ret_code = "";
    TCCState* state = tcc_new();
    state->output_type = TCC_OUTPUT_PREPROCESS;
    // let tcc parse the input arguments
    tcc_parse_args(state, argc, argv);
    // in-memory preprocessing
    const uint8_t* code_input = (const uint8_t*)raw_code.c_str();
    tcc_in_memory_preprocess(// the just created tcc state object - thanks to this, tccpp is
                             // multi-threading capable, i.e. you can create a TCCState object for
                             // each thread and then call tcc_in_memory_preprocess from each
                             // thread with their resp. state object
                             // code input string + length
                             code_input, raw_code.length(),
                             // whether to print/add the include stack or not
                             // the filename that should be used for this in-memory code
                             // - probably only useful when include stack printing is enabled
                             // preprocessed output (manual string concat)
                             // user provided function that is called for each preprocessed token
                             // here: just add the token to ret/ret_code
                             [](const char* str, void* ret) -> void {
                                 *(string*)ret += str;
    // cleanup + return
    return ret_code;

ezoic increase your site revenue


stripped-down Tiny C Compiler (tcc) for doing OpenCL C preprocessing

License:GNU Lesser General Public License v2.1


Language:C 97.0%Language:Lua 1.7%Language:Shell 1.2%