forked from Mirrors/tinycc
added __TIME__ and __DATE__ support - added -v and -run options
parent
dd56ab8c77
commit
40987541dc
61
tcc.c
61
tcc.c
|
@ -3705,6 +3705,12 @@ static int *macro_arg_subst(Sym **nested_list, int *macro_str, Sym *args)
|
||||||
return str.str;
|
return str.str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char const ab_month_name[12][4] =
|
||||||
|
{
|
||||||
|
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
|
||||||
|
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
|
||||||
|
};
|
||||||
|
|
||||||
/* do macro substitution of current token with macro 's' and add
|
/* do macro substitution of current token with macro 's' and add
|
||||||
result to (tok_str,tok_len). 'nested_list' is the list of all
|
result to (tok_str,tok_len). 'nested_list' is the list of all
|
||||||
macros we got inside to avoid recursing. Return non zero if no
|
macros we got inside to avoid recursing. Return non zero if no
|
||||||
|
@ -3729,11 +3735,21 @@ static int macro_subst_tok(TokenString *tok_str,
|
||||||
cstrval = file->filename;
|
cstrval = file->filename;
|
||||||
goto add_cstr;
|
goto add_cstr;
|
||||||
tok_str_add2(tok_str, TOK_STR, &cval);
|
tok_str_add2(tok_str, TOK_STR, &cval);
|
||||||
} else if (tok == TOK___DATE__) {
|
} else if (tok == TOK___DATE__ || tok == TOK___TIME__) {
|
||||||
cstrval = "Jan 1 2002";
|
time_t ti;
|
||||||
goto add_cstr;
|
struct tm *tm;
|
||||||
} else if (tok == TOK___TIME__) {
|
char buf[64];
|
||||||
cstrval = "00:00:00";
|
|
||||||
|
time(&ti);
|
||||||
|
tm = localtime(&ti);
|
||||||
|
if (tok == TOK___DATE__) {
|
||||||
|
snprintf(buf, sizeof(buf), "%s %2d %d",
|
||||||
|
ab_month_name[tm->tm_mon], tm->tm_mday, tm->tm_year + 1900);
|
||||||
|
} else {
|
||||||
|
snprintf(buf, sizeof(buf), "%02d:%02d:%02d",
|
||||||
|
tm->tm_hour, tm->tm_min, tm->tm_sec);
|
||||||
|
}
|
||||||
|
cstrval = buf;
|
||||||
add_cstr:
|
add_cstr:
|
||||||
cstr_new(&cstr);
|
cstr_new(&cstr);
|
||||||
cstr_cat(&cstr, cstrval);
|
cstr_cat(&cstr, cstrval);
|
||||||
|
@ -9380,17 +9396,17 @@ static int64_t getclock_us(void)
|
||||||
void help(void)
|
void help(void)
|
||||||
{
|
{
|
||||||
printf("tcc version " TCC_VERSION " - Tiny C Compiler - Copyright (C) 2001, 2002 Fabrice Bellard\n"
|
printf("tcc version " TCC_VERSION " - Tiny C Compiler - Copyright (C) 2001, 2002 Fabrice Bellard\n"
|
||||||
"usage: tcc [-c] [-o outfile] [-Bdir] [-bench] [-Idir] [-Dsym[=val]] [-Usym]\n"
|
"usage: tcc [-v] [-c] [-o outfile] [-Bdir] [-bench] [-Idir] [-Dsym[=val]] [-Usym]\n"
|
||||||
" [-g] [-b] [-bt N] [-Ldir] [-llib] [-shared] [-static]\n"
|
" [-g] [-b] [-bt N] [-Ldir] [-llib] [-shared] [-static]\n"
|
||||||
" [--] infile1 [infile2... --] [infile_args...]\n"
|
" [infile1 infile2...] [-run infile args...]\n"
|
||||||
"\n"
|
"\n"
|
||||||
"General options:\n"
|
"General options:\n"
|
||||||
|
" -v display current version\n"
|
||||||
" -c compile only - generate an object file\n"
|
" -c compile only - generate an object file\n"
|
||||||
" -o outfile set output filename\n"
|
" -o outfile set output filename\n"
|
||||||
" -- allows multiples input files if no -o option given. Also\n"
|
|
||||||
" separate input files from runtime arguments\n"
|
|
||||||
" -Bdir set tcc internal library path\n"
|
" -Bdir set tcc internal library path\n"
|
||||||
" -bench output compilation statistics\n"
|
" -bench output compilation statistics\n"
|
||||||
|
" -run run compiled source\n"
|
||||||
"Preprocessor options:\n"
|
"Preprocessor options:\n"
|
||||||
" -Idir add include path 'dir'\n"
|
" -Idir add include path 'dir'\n"
|
||||||
" -Dsym[=val] define 'sym' with value 'val'\n"
|
" -Dsym[=val] define 'sym' with value 'val'\n"
|
||||||
|
@ -9421,7 +9437,6 @@ typedef struct TCCOption {
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
TCC_OPTION_HELP,
|
TCC_OPTION_HELP,
|
||||||
TCC_OPTION_MARKER,
|
|
||||||
TCC_OPTION_I,
|
TCC_OPTION_I,
|
||||||
TCC_OPTION_D,
|
TCC_OPTION_D,
|
||||||
TCC_OPTION_U,
|
TCC_OPTION_U,
|
||||||
|
@ -9444,12 +9459,13 @@ enum {
|
||||||
TCC_OPTION_nostdinc,
|
TCC_OPTION_nostdinc,
|
||||||
TCC_OPTION_print_search_dirs,
|
TCC_OPTION_print_search_dirs,
|
||||||
TCC_OPTION_rdynamic,
|
TCC_OPTION_rdynamic,
|
||||||
|
TCC_OPTION_run,
|
||||||
|
TCC_OPTION_v,
|
||||||
};
|
};
|
||||||
|
|
||||||
static const TCCOption tcc_options[] = {
|
static const TCCOption tcc_options[] = {
|
||||||
{ "h", TCC_OPTION_HELP, 0 },
|
{ "h", TCC_OPTION_HELP, 0 },
|
||||||
{ "?", TCC_OPTION_HELP, 0 },
|
{ "?", TCC_OPTION_HELP, 0 },
|
||||||
{ "-", TCC_OPTION_MARKER, 0 },
|
|
||||||
{ "I", TCC_OPTION_I, TCC_OPTION_HAS_ARG },
|
{ "I", TCC_OPTION_I, TCC_OPTION_HAS_ARG },
|
||||||
{ "D", TCC_OPTION_D, TCC_OPTION_HAS_ARG },
|
{ "D", TCC_OPTION_D, TCC_OPTION_HAS_ARG },
|
||||||
{ "U", TCC_OPTION_U, TCC_OPTION_HAS_ARG },
|
{ "U", TCC_OPTION_U, TCC_OPTION_HAS_ARG },
|
||||||
|
@ -9466,6 +9482,7 @@ static const TCCOption tcc_options[] = {
|
||||||
{ "static", TCC_OPTION_static, 0 },
|
{ "static", TCC_OPTION_static, 0 },
|
||||||
{ "shared", TCC_OPTION_shared, 0 },
|
{ "shared", TCC_OPTION_shared, 0 },
|
||||||
{ "o", TCC_OPTION_o, TCC_OPTION_HAS_ARG },
|
{ "o", TCC_OPTION_o, TCC_OPTION_HAS_ARG },
|
||||||
|
{ "run", TCC_OPTION_run, 0 },
|
||||||
{ "rdynamic", TCC_OPTION_rdynamic, 0 }, /* currently ignored */
|
{ "rdynamic", TCC_OPTION_rdynamic, 0 }, /* currently ignored */
|
||||||
{ "r", TCC_OPTION_r, 0 },
|
{ "r", TCC_OPTION_r, 0 },
|
||||||
{ "W", TCC_OPTION_W, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP },
|
{ "W", TCC_OPTION_W, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP },
|
||||||
|
@ -9474,6 +9491,7 @@ static const TCCOption tcc_options[] = {
|
||||||
{ "f", TCC_OPTION_f, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP },
|
{ "f", TCC_OPTION_f, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP },
|
||||||
{ "nostdinc", TCC_OPTION_nostdinc, 0 },
|
{ "nostdinc", TCC_OPTION_nostdinc, 0 },
|
||||||
{ "print-search-dirs", TCC_OPTION_print_search_dirs, 0 },
|
{ "print-search-dirs", TCC_OPTION_print_search_dirs, 0 },
|
||||||
|
{ "v", TCC_OPTION_v, 0 },
|
||||||
{ NULL },
|
{ NULL },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -9491,11 +9509,11 @@ int main(int argc, char **argv)
|
||||||
int print_search_dirs;
|
int print_search_dirs;
|
||||||
|
|
||||||
s = tcc_new();
|
s = tcc_new();
|
||||||
output_type = TCC_OUTPUT_MEMORY;
|
output_type = TCC_OUTPUT_EXE;
|
||||||
|
|
||||||
optind = 1;
|
optind = 1;
|
||||||
outfile = NULL;
|
outfile = NULL;
|
||||||
multiple_files = 0;
|
multiple_files = 1;
|
||||||
dminus = 0;
|
dminus = 0;
|
||||||
files = NULL;
|
files = NULL;
|
||||||
nb_files = 0;
|
nb_files = 0;
|
||||||
|
@ -9556,15 +9574,6 @@ int main(int argc, char **argv)
|
||||||
show_help:
|
show_help:
|
||||||
help();
|
help();
|
||||||
return 1;
|
return 1;
|
||||||
case TCC_OPTION_MARKER:
|
|
||||||
/* '--' enables multiple files input and also ends several
|
|
||||||
file input */
|
|
||||||
if (dminus && multiple_files) {
|
|
||||||
optind--; /* argv[0] will be '--' */
|
|
||||||
goto end_parse;
|
|
||||||
}
|
|
||||||
dminus = 1;
|
|
||||||
multiple_files = 1;
|
|
||||||
case TCC_OPTION_I:
|
case TCC_OPTION_I:
|
||||||
if (tcc_add_include_path(s, optarg) < 0)
|
if (tcc_add_include_path(s, optarg) < 0)
|
||||||
error("too many include paths");
|
error("too many include paths");
|
||||||
|
@ -9635,12 +9644,18 @@ int main(int argc, char **argv)
|
||||||
case TCC_OPTION_print_search_dirs:
|
case TCC_OPTION_print_search_dirs:
|
||||||
print_search_dirs = 1;
|
print_search_dirs = 1;
|
||||||
break;
|
break;
|
||||||
|
case TCC_OPTION_run:
|
||||||
|
multiple_files = 0;
|
||||||
|
output_type = TCC_OUTPUT_MEMORY;
|
||||||
|
break;
|
||||||
|
case TCC_OPTION_v:
|
||||||
|
printf("tcc version %s\n", TCC_VERSION);
|
||||||
|
return 0;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
end_parse:
|
|
||||||
if (print_search_dirs) {
|
if (print_search_dirs) {
|
||||||
/* enough for Linux kernel */
|
/* enough for Linux kernel */
|
||||||
printf("install: %s/\n", tcc_lib_path);
|
printf("install: %s/\n", tcc_lib_path);
|
||||||
|
|
Loading…
Reference in New Issue