mirror of
https://github.com/frida/tinycc
synced 2024-11-27 10:09:42 +03:00
Add tcc_set_cpp_load_func()
Useful for loading preprocessor inputs from memory.
This commit is contained in:
parent
640e1a7827
commit
949e096b02
7
libtcc.c
7
libtcc.c
@ -610,6 +610,13 @@ LIBTCCAPI void *tcc_get_error_opaque(TCCState *s)
|
||||
return s->error_opaque;
|
||||
}
|
||||
|
||||
LIBTCCAPI void tcc_set_cpp_load_func(TCCState *s, void *cpp_load_opaque,
|
||||
const char *(*cpp_load_func)(void *opaque, const char *path, int *len))
|
||||
{
|
||||
s->cpp_load_opaque = cpp_load_opaque;
|
||||
s->cpp_load_func = cpp_load_func;
|
||||
}
|
||||
|
||||
/* error without aborting current compilation */
|
||||
PUB_FUNC void _tcc_error_noabort(const char *fmt, ...)
|
||||
{
|
||||
|
4
libtcc.h
4
libtcc.h
@ -33,6 +33,10 @@ LIBTCCAPI TCCErrorFunc tcc_get_error_func(TCCState *s);
|
||||
/* return error/warning callback opaque pointer */
|
||||
LIBTCCAPI void *tcc_get_error_opaque(TCCState *s);
|
||||
|
||||
/* set preprocessor loader callback */
|
||||
LIBTCCAPI void tcc_set_cpp_load_func(TCCState *s, void *cpp_load_opaque,
|
||||
const char *(*cpp_load_func)(void *opaque, const char *path, int *len));
|
||||
|
||||
/* set options as from command line (multiple supported) */
|
||||
LIBTCCAPI void tcc_set_options(TCCState *s, const char *str);
|
||||
|
||||
|
4
tcc.h
4
tcc.h
@ -801,6 +801,10 @@ struct TCCState {
|
||||
jmp_buf error_jmp_buf;
|
||||
int nb_errors;
|
||||
|
||||
/* filesystem handling */
|
||||
void *cpp_load_opaque;
|
||||
const char *(*cpp_load_func)(void *opaque, const char *path, int *len);
|
||||
|
||||
/* output file for preprocessing (-E) */
|
||||
FILE *ppfp;
|
||||
enum {
|
||||
|
24
tccpp.c
24
tccpp.c
@ -1879,8 +1879,28 @@ ST_FUNC void preprocess(int is_bof)
|
||||
goto include_done;
|
||||
}
|
||||
|
||||
if (tcc_open(s1, buf1) < 0)
|
||||
continue;
|
||||
if (s1->cpp_load_func) {
|
||||
const char *str;
|
||||
int len;
|
||||
|
||||
str = s1->cpp_load_func(s1->cpp_load_opaque, buf1, &len);
|
||||
if ((s1->verbose == 2 && str != NULL) || s1->verbose == 3)
|
||||
printf("%s %*s%s\n", str == NULL ? "nf" : "->",
|
||||
(int)(s1->include_stack_ptr - s1->include_stack), "",
|
||||
buf1);
|
||||
if (str == NULL)
|
||||
continue;
|
||||
|
||||
tcc_open_bf(s1, buf1, len);
|
||||
memcpy(file->buffer, str, len);
|
||||
|
||||
#ifdef _WIN32
|
||||
normalize_slashes(file->filename);
|
||||
#endif
|
||||
} else {
|
||||
if (tcc_open(s1, buf1) < 0)
|
||||
continue;
|
||||
}
|
||||
|
||||
file->include_next_index = i;
|
||||
#ifdef INC_DEBUG
|
||||
|
Loading…
Reference in New Issue
Block a user