enable making tcc using libtcc

tcc-xref
grischka 2009-05-11 18:46:02 +02:00
parent 0a35f9d66e
commit 67aebdd5b7
3 changed files with 32 additions and 29 deletions

View File

@ -326,7 +326,7 @@ int ieee_finite(double d)
} }
/* copy a string and truncate it. */ /* copy a string and truncate it. */
static char *pstrcpy(char *buf, int buf_size, const char *s) char *pstrcpy(char *buf, int buf_size, const char *s)
{ {
char *q, *q_end; char *q, *q_end;
int c; int c;
@ -346,7 +346,7 @@ static char *pstrcpy(char *buf, int buf_size, const char *s)
} }
/* strcat and truncate. */ /* strcat and truncate. */
static char *pstrcat(char *buf, int buf_size, const char *s) char *pstrcat(char *buf, int buf_size, const char *s)
{ {
int len; int len;
len = strlen(buf); len = strlen(buf);
@ -356,7 +356,7 @@ static char *pstrcat(char *buf, int buf_size, const char *s)
} }
/* extract the basename of a file */ /* extract the basename of a file */
static char *tcc_basename(const char *name) char *tcc_basename(const char *name)
{ {
char *p = strchr(name, 0); char *p = strchr(name, 0);
while (p > name && !IS_PATHSEP(p[-1])) while (p > name && !IS_PATHSEP(p[-1]))
@ -364,7 +364,7 @@ static char *tcc_basename(const char *name)
return p; return p;
} }
static char *tcc_fileextension (const char *name) char *tcc_fileextension (const char *name)
{ {
char *b = tcc_basename(name); char *b = tcc_basename(name);
char *e = strrchr(b, '.'); char *e = strrchr(b, '.');
@ -418,7 +418,7 @@ int mem_max_size;
unsigned malloc_usable_size(void*); unsigned malloc_usable_size(void*);
#endif #endif
static inline void tcc_free(void *ptr) void tcc_free(void *ptr)
{ {
#ifdef MEM_DEBUG #ifdef MEM_DEBUG
mem_cur_size -= malloc_usable_size(ptr); mem_cur_size -= malloc_usable_size(ptr);
@ -426,7 +426,7 @@ static inline void tcc_free(void *ptr)
free(ptr); free(ptr);
} }
static void *tcc_malloc(unsigned long size) void *tcc_malloc(unsigned long size)
{ {
void *ptr; void *ptr;
ptr = malloc(size); ptr = malloc(size);
@ -440,7 +440,7 @@ static void *tcc_malloc(unsigned long size)
return ptr; return ptr;
} }
static void *tcc_mallocz(unsigned long size) void *tcc_mallocz(unsigned long size)
{ {
void *ptr; void *ptr;
ptr = tcc_malloc(size); ptr = tcc_malloc(size);
@ -448,7 +448,7 @@ static void *tcc_mallocz(unsigned long size)
return ptr; return ptr;
} }
static inline void *tcc_realloc(void *ptr, unsigned long size) void *tcc_realloc(void *ptr, unsigned long size)
{ {
void *ptr1; void *ptr1;
#ifdef MEM_DEBUG #ifdef MEM_DEBUG
@ -464,7 +464,7 @@ static inline void *tcc_realloc(void *ptr, unsigned long size)
return ptr1; return ptr1;
} }
static char *tcc_strdup(const char *str) char *tcc_strdup(const char *str)
{ {
char *ptr; char *ptr;
ptr = tcc_malloc(strlen(str) + 1); ptr = tcc_malloc(strlen(str) + 1);
@ -476,7 +476,7 @@ static char *tcc_strdup(const char *str)
#define malloc(s) use_tcc_malloc(s) #define malloc(s) use_tcc_malloc(s)
#define realloc(p, s) use_tcc_realloc(p, s) #define realloc(p, s) use_tcc_realloc(p, s)
static void dynarray_add(void ***ptab, int *nb_ptr, void *data) void dynarray_add(void ***ptab, int *nb_ptr, void *data)
{ {
int nb, nb_alloc; int nb, nb_alloc;
void **pp; void **pp;
@ -498,7 +498,7 @@ static void dynarray_add(void ***ptab, int *nb_ptr, void *data)
*nb_ptr = nb; *nb_ptr = nb;
} }
static void dynarray_reset(void *pp, int *n) void dynarray_reset(void *pp, int *n)
{ {
void **p; void **p;
for (p = *(void***)pp; *n; ++p, --*n) for (p = *(void***)pp; *n; ++p, --*n)
@ -2030,7 +2030,10 @@ static int tcc_add_file_internal(TCCState *s1, const char *filename, int flags)
int tcc_add_file(TCCState *s, const char *filename) int tcc_add_file(TCCState *s, const char *filename)
{ {
return tcc_add_file_internal(s, filename, AFF_PRINT_ERROR); if (s->output_type == TCC_OUTPUT_PREPROCESS)
return tcc_add_file_internal(s, filename, AFF_PRINT_ERROR | AFF_PREPROCESS);
else
return tcc_add_file_internal(s, filename, AFF_PRINT_ERROR);
} }
int tcc_add_library_path(TCCState *s, const char *pathname) int tcc_add_library_path(TCCState *s, const char *pathname)

10
tcc.c
View File

@ -509,13 +509,11 @@ int main(int argc, char **argv)
const char *filename; const char *filename;
filename = files[i]; filename = files[i];
if (output_type == TCC_OUTPUT_PREPROCESS) { if (filename[0] == '-' && filename[1]) {
if (tcc_add_file_internal(s, filename, if (tcc_add_library(s, filename + 2) < 0) {
AFF_PRINT_ERROR | AFF_PREPROCESS) < 0) error_noabort("cannot find %s", filename);
ret = 1; ret = 1;
} else if (filename[0] == '-' && filename[1]) { }
if (tcc_add_library(s, filename + 2) < 0)
error("cannot find %s", filename);
} else { } else {
if (1 == s->verbose) if (1 == s->verbose)
printf("-> %s\n", filename); printf("-> %s\n", filename);

24
tcc.h
View File

@ -724,23 +724,25 @@ extern long double strtold (const char *__nptr, char **__endptr);
#endif #endif
void error(const char *fmt, ...); void error(const char *fmt, ...);
void error_noabort(const char *fmt, ...);
void warning(const char *fmt, ...); void warning(const char *fmt, ...);
void tcc_set_lib_path_w32(TCCState *s); void tcc_set_lib_path_w32(TCCState *s);
int tcc_set_flag(TCCState *s, const char *flag_name, int value); int tcc_set_flag(TCCState *s, const char *flag_name, int value);
void tcc_print_stats(TCCState *s, int64_t total_time); void tcc_print_stats(TCCState *s, int64_t total_time);
static void tcc_free(void *ptr); void tcc_free(void *ptr);
static void *tcc_malloc(unsigned long size); void *tcc_malloc(unsigned long size);
static void *tcc_mallocz(unsigned long size); void *tcc_mallocz(unsigned long size);
static void *tcc_realloc(void *ptr, unsigned long size); void *tcc_realloc(void *ptr, unsigned long size);
static char *tcc_strdup(const char *str); char *tcc_strdup(const char *str);
static char *tcc_basename(const char *name); char *tcc_basename(const char *name);
static char *tcc_fileextension (const char *name); char *tcc_fileextension (const char *name);
static char *pstrcpy(char *buf, int buf_size, const char *s); char *pstrcpy(char *buf, int buf_size, const char *s);
static char *pstrcat(char *buf, int buf_size, const char *s); char *pstrcat(char *buf, int buf_size, const char *s);
static void dynarray_add(void ***ptab, int *nb_ptr, void *data); void dynarray_add(void ***ptab, int *nb_ptr, void *data);
static void dynarray_reset(void *pp, int *n); void dynarray_reset(void *pp, int *n);
#ifdef CONFIG_TCC_BACKTRACE #ifdef CONFIG_TCC_BACKTRACE
extern int num_callers; extern int num_callers;