407 |
/* if true, only link in referenced objects from archive */ |
/* if true, only link in referenced objects from archive */ |
408 |
int alacarte_link; |
int alacarte_link; |
409 |
|
|
410 |
|
/* C language options */ |
411 |
|
int char_is_unsigned; |
412 |
|
|
413 |
/* warning switches */ |
/* warning switches */ |
414 |
int warn_write_strings; |
int warn_write_strings; |
415 |
int warn_unsupported; |
int warn_unsupported; |
416 |
int warn_error; |
int warn_error; |
417 |
int warn_none; |
int warn_none; |
418 |
|
int warn_implicit_function_declaration; |
419 |
|
|
420 |
/* error handling */ |
/* error handling */ |
421 |
void *error_opaque; |
void *error_opaque; |
6419 |
the_end: |
the_end: |
6420 |
if ((t & (VT_SIGNED|VT_UNSIGNED)) == (VT_SIGNED|VT_UNSIGNED)) |
if ((t & (VT_SIGNED|VT_UNSIGNED)) == (VT_SIGNED|VT_UNSIGNED)) |
6421 |
error("signed and unsigned modifier"); |
error("signed and unsigned modifier"); |
6422 |
#ifdef CHAR_IS_UNSIGNED |
if (tcc_state->char_is_unsigned) { |
6423 |
if ((t & (VT_SIGNED|VT_UNSIGNED|VT_BTYPE)) == VT_BYTE) |
if ((t & (VT_SIGNED|VT_UNSIGNED|VT_BTYPE)) == VT_BYTE) |
6424 |
t |= VT_UNSIGNED; |
t |= VT_UNSIGNED; |
6425 |
#endif |
} |
6426 |
t &= ~VT_SIGNED; |
t &= ~VT_SIGNED; |
6427 |
|
|
6428 |
/* long is never used as type */ |
/* long is never used as type */ |
6955 |
error("'%s' undeclared", get_tok_str(t, NULL)); |
error("'%s' undeclared", get_tok_str(t, NULL)); |
6956 |
/* for simple function calls, we tolerate undeclared |
/* for simple function calls, we tolerate undeclared |
6957 |
external reference to int() function */ |
external reference to int() function */ |
6958 |
|
if (tcc_state->warn_implicit_function_declaration) |
6959 |
|
warning("implicit declaration of function '%s'", |
6960 |
|
get_tok_str(t, NULL)); |
6961 |
s = external_global_sym(t, &func_old_type, 0); |
s = external_global_sym(t, &func_old_type, 0); |
6962 |
} |
} |
6963 |
vset(&s->type, s->r, s->c); |
vset(&s->type, s->r, s->c); |
9293 |
tcc_define_symbol(s, "arm", NULL); |
tcc_define_symbol(s, "arm", NULL); |
9294 |
tcc_define_symbol(s, "__APCS_32__", NULL); |
tcc_define_symbol(s, "__APCS_32__", NULL); |
9295 |
#endif |
#endif |
|
#ifdef CHAR_IS_UNSIGNED |
|
|
tcc_define_symbol(s, "__CHAR_UNSIGNED__", NULL); |
|
|
#endif |
|
9296 |
#if defined(linux) |
#if defined(linux) |
9297 |
tcc_define_symbol(s, "__linux__", NULL); |
tcc_define_symbol(s, "__linux__", NULL); |
9298 |
tcc_define_symbol(s, "linux", NULL); |
tcc_define_symbol(s, "linux", NULL); |
9329 |
".dynstrtab", |
".dynstrtab", |
9330 |
".dynhashtab", SHF_PRIVATE); |
".dynhashtab", SHF_PRIVATE); |
9331 |
s->alacarte_link = 1; |
s->alacarte_link = 1; |
9332 |
|
|
9333 |
|
#ifdef CHAR_IS_UNSIGNED |
9334 |
|
s->char_is_unsigned = 1; |
9335 |
|
#endif |
9336 |
return s; |
return s; |
9337 |
} |
} |
9338 |
|
|
9593 |
} |
} |
9594 |
#endif |
#endif |
9595 |
|
|
9596 |
|
if (s->char_is_unsigned) { |
9597 |
|
tcc_define_symbol(s, "__CHAR_UNSIGNED__", NULL); |
9598 |
|
} |
9599 |
|
|
9600 |
/* add debug sections */ |
/* add debug sections */ |
9601 |
if (do_debug) { |
if (do_debug) { |
9602 |
/* stab symbols */ |
/* stab symbols */ |
9619 |
return 0; |
return 0; |
9620 |
} |
} |
9621 |
|
|
9622 |
#define WD_ALL 0x0001 /* warning is activated when using -Wall */ |
#define WD_ALL 0x0001 /* warning is activated when using -Wall */ |
9623 |
|
#define FD_INVERT 0x0002 /* invert value before storing */ |
9624 |
|
|
9625 |
typedef struct WarningDef { |
typedef struct FlagDef { |
9626 |
int offset; |
uint16_t offset; |
9627 |
int flags; |
uint16_t flags; |
9628 |
const char *name; |
const char *name; |
9629 |
} WarningDef; |
} FlagDef; |
9630 |
|
|
9631 |
static const WarningDef warning_defs[] = { |
static const FlagDef warning_defs[] = { |
9632 |
{ offsetof(TCCState, warn_unsupported), 0, "unsupported" }, |
{ offsetof(TCCState, warn_unsupported), 0, "unsupported" }, |
9633 |
{ offsetof(TCCState, warn_write_strings), 0, "write-strings" }, |
{ offsetof(TCCState, warn_write_strings), 0, "write-strings" }, |
9634 |
{ offsetof(TCCState, warn_error), 0, "error" }, |
{ offsetof(TCCState, warn_error), 0, "error" }, |
9635 |
|
{ offsetof(TCCState, warn_implicit_function_declaration), WD_ALL, |
9636 |
|
"implicit-function-declaration" }, |
9637 |
}; |
}; |
9638 |
|
|
9639 |
|
static int set_flag(TCCState *s, const FlagDef *flags, int nb_flags, |
9640 |
|
const char *name, int value) |
9641 |
|
{ |
9642 |
|
int i; |
9643 |
|
const FlagDef *p; |
9644 |
|
const char *r; |
9645 |
|
|
9646 |
|
r = name; |
9647 |
|
if (r[0] == 'n' && r[1] == 'o' && r[2] == '-') { |
9648 |
|
r += 3; |
9649 |
|
value = !value; |
9650 |
|
} |
9651 |
|
for(i = 0, p = flags; i < nb_flags; i++, p++) { |
9652 |
|
if (!strcmp(r, p->name)) |
9653 |
|
goto found; |
9654 |
|
} |
9655 |
|
return -1; |
9656 |
|
found: |
9657 |
|
if (p->flags & FD_INVERT) |
9658 |
|
value = !value; |
9659 |
|
*(int *)((uint8_t *)s + p->offset) = value; |
9660 |
|
return 0; |
9661 |
|
} |
9662 |
|
|
9663 |
|
|
9664 |
/* set/reset a warning */ |
/* set/reset a warning */ |
9665 |
int tcc_set_warning(TCCState *s, const char *warning_name, int value) |
int tcc_set_warning(TCCState *s, const char *warning_name, int value) |
9666 |
{ |
{ |
9667 |
int i; |
int i; |
9668 |
const WarningDef *p; |
const FlagDef *p; |
9669 |
|
|
9670 |
if (!strcmp(warning_name, "all")) { |
if (!strcmp(warning_name, "all")) { |
9671 |
for(i = 0, p = warning_defs; i < countof(warning_defs); i++, p++) { |
for(i = 0, p = warning_defs; i < countof(warning_defs); i++, p++) { |
9672 |
if (p->flags & WD_ALL) |
if (p->flags & WD_ALL) |
9673 |
*(int *)((uint8_t *)s + p->offset) = 1; |
*(int *)((uint8_t *)s + p->offset) = 1; |
9674 |
} |
} |
9675 |
|
return 0; |
9676 |
} else { |
} else { |
9677 |
for(i = 0, p = warning_defs; i < countof(warning_defs); i++, p++) { |
return set_flag(s, warning_defs, countof(warning_defs), |
9678 |
if (!strcmp(warning_name, p->name)) |
warning_name, value); |
|
goto found; |
|
|
} |
|
|
return -1; |
|
|
found: |
|
|
*(int *)((uint8_t *)s + p->offset) = value; |
|
9679 |
} |
} |
9680 |
return 0; |
} |
9681 |
|
|
9682 |
|
static const FlagDef flag_defs[] = { |
9683 |
|
{ offsetof(TCCState, char_is_unsigned), 0, "unsigned-char" }, |
9684 |
|
{ offsetof(TCCState, char_is_unsigned), FD_INVERT, "signed-char" }, |
9685 |
|
}; |
9686 |
|
|
9687 |
|
/* set/reset a flag */ |
9688 |
|
int tcc_set_flag(TCCState *s, const char *flag_name, int value) |
9689 |
|
{ |
9690 |
|
return set_flag(s, flag_defs, countof(flag_defs), |
9691 |
|
flag_name, value); |
9692 |
} |
} |
9693 |
|
|
9694 |
#if !defined(LIBTCC) |
#if !defined(LIBTCC) |
9736 |
" -Bdir set tcc internal library path\n" |
" -Bdir set tcc internal library path\n" |
9737 |
" -bench output compilation statistics\n" |
" -bench output compilation statistics\n" |
9738 |
" -run run compiled source\n" |
" -run run compiled source\n" |
9739 |
" -Wwarning set or reset (with 'no-' prefix) 'warning'\n" |
" -fflag set or reset (with 'no-' prefix) 'flag' (see man page)\n" |
9740 |
|
" -Wwarning set or reset (with 'no-' prefix) 'warning' (see man page)\n" |
9741 |
" -w disable all warnings\n" |
" -w disable all warnings\n" |
9742 |
"Preprocessor options:\n" |
"Preprocessor options:\n" |
9743 |
" -Idir add include path 'dir'\n" |
" -Idir add include path 'dir'\n" |
10017 |
case TCC_OPTION_v: |
case TCC_OPTION_v: |
10018 |
printf("tcc version %s\n", TCC_VERSION); |
printf("tcc version %s\n", TCC_VERSION); |
10019 |
exit(0); |
exit(0); |
10020 |
|
case TCC_OPTION_f: |
10021 |
|
if (tcc_set_flag(s, optarg, 1) < 0 && s->warn_unsupported) |
10022 |
|
goto unsupported_option; |
10023 |
|
break; |
10024 |
case TCC_OPTION_W: |
case TCC_OPTION_W: |
10025 |
{ |
if (tcc_set_warning(s, optarg, 1) < 0 && |
10026 |
const char *p = optarg; |
s->warn_unsupported) |
10027 |
int value; |
goto unsupported_option; |
|
value = 1; |
|
|
if (p[0] == 'n' && p[1] == 'o' && p[2] == '-') { |
|
|
p += 2; |
|
|
value = 0; |
|
|
} |
|
|
if (tcc_set_warning(s, p, value) < 0 && s->warn_unsupported) |
|
|
goto unsupported_option; |
|
|
} |
|
10028 |
break; |
break; |
10029 |
case TCC_OPTION_w: |
case TCC_OPTION_w: |
10030 |
s->warn_none = 1; |
s->warn_none = 1; |