https://github.com/a2flo/tccpp
stripped-down Tiny C Compiler (tcc) for doing OpenCL C preprocessing
https://github.com/a2flo/tccpp
Last synced: 8 months ago
JSON representation
stripped-down Tiny C Compiler (tcc) for doing OpenCL C preprocessing
- Host: GitHub
- URL: https://github.com/a2flo/tccpp
- Owner: a2flo
- License: lgpl-2.1
- Created: 2013-04-11T21:16:09.000Z (about 13 years ago)
- Default Branch: master
- Last Pushed: 2014-09-17T07:00:49.000Z (over 11 years ago)
- Last Synced: 2025-05-15T01:39:58.359Z (about 1 year ago)
- Language: C
- Homepage:
- Size: 430 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.textile
- License: COPYING
Awesome Lists containing this project
README
*TCCPP & TCC - Tiny C Compiler*
"_Copyright (c) 2001-2004 Fabrice Bellard_":http://bellard.org/tcc/
_Copyright (c) 2013 Florian Ziesche (stripped-down TCCPP version)_
p. 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.
p. This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
p. 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":https://github.com/a2flo/oclraster 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
state,
// code input string + length
code_input, raw_code.length(),
// whether to print/add the include stack or not
true,
// the filename that should be used for this in-memory code
// - probably only useful when include stack printing is enabled
"in_memory_file.c",
// preprocessed output (manual string concat)
&ret_code,
// 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
tcc_delete(state);
return ret_code;
}