mirror of
https://github.com/mirror/tinycc.git
synced 2025-01-29 06:10:09 +08:00
libtcc: cleanup -x<filetype> switch code
Abusing filename[0] as type is just too much of a hack.
-- From 0536407204
This commit is contained in:
parent
e630113771
commit
09a487eb2b
39
libtcc.c
39
libtcc.c
@ -1304,7 +1304,8 @@ ST_FUNC int tcc_add_file_internal(TCCState *s1, const char *filename, int flags,
|
|||||||
parse_flags = 0;
|
parse_flags = 0;
|
||||||
#ifdef CONFIG_TCC_ASM
|
#ifdef CONFIG_TCC_ASM
|
||||||
/* if .S file, define __ASSEMBLER__ like gcc does */
|
/* if .S file, define __ASSEMBLER__ like gcc does */
|
||||||
if ((filetype == TCC_FILETYPE_ASM) || (filetype == TCC_FILETYPE_ASM_PP)) {
|
if (filetype == TCC_FILETYPE_ASM
|
||||||
|
|| filetype == TCC_FILETYPE_ASM_PP) {
|
||||||
tcc_define_symbol(s1, "__ASSEMBLER__", NULL);
|
tcc_define_symbol(s1, "__ASSEMBLER__", NULL);
|
||||||
parse_flags = PARSE_FLAG_ASM_FILE;
|
parse_flags = PARSE_FLAG_ASM_FILE;
|
||||||
}
|
}
|
||||||
@ -2048,33 +2049,29 @@ static void parse_option_D(TCCState *s1, const char *optarg)
|
|||||||
|
|
||||||
static void args_parser_add_file(TCCState *s, const char* filename, int filetype)
|
static void args_parser_add_file(TCCState *s, const char* filename, int filetype)
|
||||||
{
|
{
|
||||||
int len = strlen(filename);
|
struct filespec *f = tcc_malloc(sizeof *f + strlen(filename));
|
||||||
char *p = tcc_malloc(len + 2);
|
|
||||||
if (filetype) {
|
if (filetype == 0) {
|
||||||
*p = filetype;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
/* use a file extension to detect a filetype */
|
/* use a file extension to detect a filetype */
|
||||||
const char *ext = tcc_fileextension(filename);
|
const char *ext = tcc_fileextension(filename);
|
||||||
if (ext[0]) {
|
if (ext[0]) {
|
||||||
ext++;
|
ext++;
|
||||||
if (!strcmp(ext, "S"))
|
if (!strcmp(ext, "S"))
|
||||||
*p = TCC_FILETYPE_ASM_PP;
|
filetype = TCC_FILETYPE_ASM_PP;
|
||||||
|
else if (!strcmp(ext, "s"))
|
||||||
|
filetype = TCC_FILETYPE_ASM;
|
||||||
|
else if (!PATHCMP(ext, "c") || !PATHCMP(ext, "i"))
|
||||||
|
filetype = TCC_FILETYPE_C;
|
||||||
else
|
else
|
||||||
if (!strcmp(ext, "s"))
|
filetype = TCC_FILETYPE_BINARY;
|
||||||
*p = TCC_FILETYPE_ASM;
|
} else {
|
||||||
else
|
filetype = TCC_FILETYPE_C;
|
||||||
if (!PATHCMP(ext, "c") || !PATHCMP(ext, "i"))
|
|
||||||
*p = TCC_FILETYPE_C;
|
|
||||||
else
|
|
||||||
*p = TCC_FILETYPE_BINARY;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
*p = TCC_FILETYPE_C;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
strcpy(p+1, filename);
|
|
||||||
dynarray_add((void ***)&s->files, &s->nb_files, p);
|
f->type = filetype;
|
||||||
|
strcpy(f->name, filename);
|
||||||
|
dynarray_add((void ***)&s->files, &s->nb_files, f);
|
||||||
}
|
}
|
||||||
|
|
||||||
ST_FUNC int tcc_parse_args1(TCCState *s, int argc, char **argv)
|
ST_FUNC int tcc_parse_args1(TCCState *s, int argc, char **argv)
|
||||||
@ -2158,7 +2155,7 @@ ST_FUNC int tcc_parse_args1(TCCState *s, int argc, char **argv)
|
|||||||
tcc_set_lib_path(s, optarg);
|
tcc_set_lib_path(s, optarg);
|
||||||
break;
|
break;
|
||||||
case TCC_OPTION_l:
|
case TCC_OPTION_l:
|
||||||
args_parser_add_file(s, r, TCC_FILETYPE_BINARY);
|
args_parser_add_file(s, optarg, 'l');
|
||||||
s->nb_libraries++;
|
s->nb_libraries++;
|
||||||
break;
|
break;
|
||||||
case TCC_OPTION_pthread:
|
case TCC_OPTION_pthread:
|
||||||
|
8
libtcc.h
8
libtcc.h
@ -49,10 +49,10 @@ LIBTCCAPI void tcc_undefine_symbol(TCCState *s, const char *sym);
|
|||||||
|
|
||||||
/* add a file (C file, dll, object, library, ld script). Return -1 if error. */
|
/* add a file (C file, dll, object, library, ld script). Return -1 if error. */
|
||||||
LIBTCCAPI int tcc_add_file(TCCState *s, const char *filename, int filetype);
|
LIBTCCAPI int tcc_add_file(TCCState *s, const char *filename, int filetype);
|
||||||
#define TCC_FILETYPE_BINARY 1
|
#define TCC_FILETYPE_BINARY 'b'
|
||||||
#define TCC_FILETYPE_C 2
|
#define TCC_FILETYPE_C 'c'
|
||||||
#define TCC_FILETYPE_ASM 3
|
#define TCC_FILETYPE_ASM 's'
|
||||||
#define TCC_FILETYPE_ASM_PP 4
|
#define TCC_FILETYPE_ASM_PP 'S'
|
||||||
|
|
||||||
/* compile a string containing a C source. Return -1 if error. */
|
/* compile a string containing a C source. Return -1 if error. */
|
||||||
LIBTCCAPI int tcc_compile_string(TCCState *s, const char *buf);
|
LIBTCCAPI int tcc_compile_string(TCCState *s, const char *buf);
|
||||||
|
20
tcc.c
20
tcc.c
@ -307,23 +307,17 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
/* compile or add each files or library */
|
/* compile or add each files or library */
|
||||||
for(i = ret = 0; i < s->nb_files && ret == 0; i++) {
|
for(i = ret = 0; i < s->nb_files && ret == 0; i++) {
|
||||||
int filetype = *(unsigned char *)s->files[i];
|
struct filespec *f = s->files[i];
|
||||||
const char *filename = s->files[i] + 1;
|
if (f->type == 'l') {
|
||||||
if (filename[0] == '-' && filename[1] == 'l') {
|
if (tcc_add_library_err(s, f->name) < 0)
|
||||||
if (tcc_add_library(s, filename + 2) < 0) {
|
ret = 1;
|
||||||
/* don't fail on -lm as it's harmless to skip math lib */
|
|
||||||
if (strcmp(filename + 2, "m")) {
|
|
||||||
tcc_error_noabort("cannot find library 'lib%s'", filename + 2);
|
|
||||||
ret = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (1 == s->verbose)
|
if (1 == s->verbose)
|
||||||
printf("-> %s\n", filename);
|
printf("-> %s\n", f->name);
|
||||||
if (tcc_add_file(s, filename, filetype) < 0)
|
if (tcc_add_file(s, f->name, f->type) < 0)
|
||||||
ret = 1;
|
ret = 1;
|
||||||
if (!first_file)
|
if (!first_file)
|
||||||
first_file = filename;
|
first_file = f->name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
6
tcc.h
6
tcc.h
@ -850,7 +850,7 @@ struct TCCState {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* used by main and tcc_parse_args only */
|
/* used by main and tcc_parse_args only */
|
||||||
char **files; /* files seen on command line */
|
struct filespec **files; /* files seen on command line */
|
||||||
int nb_files; /* number thereof */
|
int nb_files; /* number thereof */
|
||||||
int nb_libraries; /* number of libs thereof */
|
int nb_libraries; /* number of libs thereof */
|
||||||
char *outfile; /* output filename */
|
char *outfile; /* output filename */
|
||||||
@ -863,6 +863,10 @@ struct TCCState {
|
|||||||
ParseArgsState *parse_args_state;
|
ParseArgsState *parse_args_state;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct filespec {
|
||||||
|
char type, name[1];
|
||||||
|
};
|
||||||
|
|
||||||
/* The current value can be: */
|
/* The current value can be: */
|
||||||
#define VT_VALMASK 0x003f /* mask for value location, register or: */
|
#define VT_VALMASK 0x003f /* mask for value location, register or: */
|
||||||
#define VT_CONST 0x0030 /* constant in vc (must be first non register value) */
|
#define VT_CONST 0x0030 /* constant in vc (must be first non register value) */
|
||||||
|
Loading…
Reference in New Issue
Block a user