Unified · Split
| @@ -3705,6 +3705,12 @@ static int *macro_arg_subst(Sym **nested_list, int *macro_str, Sym *args) · 3704 unmodified lines | ||
| 3705 | 3705 | return str.str; |
| 3706 | 3706 | } |
| 3707 | 3707 | |
| 3708 | +static char const ab_month_name[12][4] = | |
| 3709 | +{ | |
| 3710 | + "Jan", "Feb", "Mar", "Apr", "May", "Jun", | |
| 3711 | + "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" | |
| 3712 | +}; | |
| 3713 | + | |
| 3708 | 3714 | /* do macro substitution of current token with macro 's' and add |
| 3709 | 3715 | result to (tok_str,tok_len). 'nested_list' is the list of all |
| 3710 | 3716 | macros we got inside to avoid recursing. Return non zero if no |
| @@ -3729,11 +3735,21 @@ static int macro_subst_tok(TokenString *tok_str, · 18 unmodified lines | ||
| 3729 | 3735 | cstrval = file->filename; |
| 3730 | 3736 | goto add_cstr; |
| 3731 | 3737 | tok_str_add2(tok_str, TOK_STR, &cval); |
| 3732 | − } else if (tok == TOK___DATE__) { | |
| 3733 | − cstrval = "Jan 1 2002"; | |
| 3734 | − goto add_cstr; | |
| 3735 | − } else if (tok == TOK___TIME__) { | |
| 3736 | − cstrval = "00:00:00"; | |
| 3738 | + } else if (tok == TOK___DATE__ || tok == TOK___TIME__) { | |
| 3739 | + time_t ti; | |
| 3740 | + struct tm *tm; | |
| 3741 | + char buf[64]; | |
| 3742 | + | |
| 3743 | + time(&ti); | |
| 3744 | + tm = localtime(&ti); | |
| 3745 | + if (tok == TOK___DATE__) { | |
| 3746 | + snprintf(buf, sizeof(buf), "%s %2d %d", | |
| 3747 | + ab_month_name[tm->tm_mon], tm->tm_mday, tm->tm_year + 1900); | |
| 3748 | + } else { | |
| 3749 | + snprintf(buf, sizeof(buf), "%02d:%02d:%02d", | |
| 3750 | + tm->tm_hour, tm->tm_min, tm->tm_sec); | |
| 3751 | + } | |
| 3752 | + cstrval = buf; | |
| 3737 | 3753 | add_cstr: |
| 3738 | 3754 | cstr_new(&cstr); |
| 3739 | 3755 | cstr_cat(&cstr, cstrval); |
| @@ -9380,17 +9396,17 @@ static int64_t getclock_us(void) · 5640 unmodified lines | ||
| 9380 | 9396 | void help(void) |
| 9381 | 9397 | { |
| 9382 | 9398 | printf("tcc version " TCC_VERSION " - Tiny C Compiler - Copyright (C) 2001, 2002 Fabrice Bellard\n" |
| 9383 | − "usage: tcc [-c] [-o outfile] [-Bdir] [-bench] [-Idir] [-Dsym[=val]] [-Usym]\n" | |
| 9399 | + "usage: tcc [-v] [-c] [-o outfile] [-Bdir] [-bench] [-Idir] [-Dsym[=val]] [-Usym]\n" | |
| 9384 | 9400 | " [-g] [-b] [-bt N] [-Ldir] [-llib] [-shared] [-static]\n" |
| 9385 | − " [--] infile1 [infile2... --] [infile_args...]\n" | |
| 9401 | + " [infile1 infile2...] [-run infile args...]\n" | |
| 9386 | 9402 | "\n" |
| 9387 | 9403 | "General options:\n" |
| 9404 | + " -v display current version\n" | |
| 9388 | 9405 | " -c compile only - generate an object file\n" |
| 9389 | 9406 | " -o outfile set output filename\n" |
| 9390 | − " -- allows multiples input files if no -o option given. Also\n" | |
| 9391 | − " separate input files from runtime arguments\n" | |
| 9392 | 9407 | " -Bdir set tcc internal library path\n" |
| 9393 | 9408 | " -bench output compilation statistics\n" |
| 9409 | + " -run run compiled source\n" | |
| 9394 | 9410 | "Preprocessor options:\n" |
| 9395 | 9411 | " -Idir add include path 'dir'\n" |
| 9396 | 9412 | " -Dsym[=val] define 'sym' with value 'val'\n" |
| @@ -9421,7 +9437,6 @@ typedef struct TCCOption { · 24 unmodified lines | ||
| 9421 | 9437 | |
| 9422 | 9438 | enum { |
| 9423 | 9439 | TCC_OPTION_HELP, |
| 9424 | − TCC_OPTION_MARKER, | |
| 9425 | 9440 | TCC_OPTION_I, |
| 9426 | 9441 | TCC_OPTION_D, |
| 9427 | 9442 | TCC_OPTION_U, |
| @@ -9444,12 +9459,13 @@ enum { · 16 unmodified lines | ||
| 9444 | 9459 | TCC_OPTION_nostdinc, |
| 9445 | 9460 | TCC_OPTION_print_search_dirs, |
| 9446 | 9461 | TCC_OPTION_rdynamic, |
| 9462 | + TCC_OPTION_run, | |
| 9463 | + TCC_OPTION_v, | |
| 9447 | 9464 | }; |
| 9448 | 9465 | |
| 9449 | 9466 | static const TCCOption tcc_options[] = { |
| 9450 | 9467 | { "h", TCC_OPTION_HELP, 0 }, |
| 9451 | 9468 | { "?", TCC_OPTION_HELP, 0 }, |
| 9452 | − { "-", TCC_OPTION_MARKER, 0 }, | |
| 9453 | 9469 | { "I", TCC_OPTION_I, TCC_OPTION_HAS_ARG }, |
| 9454 | 9470 | { "D", TCC_OPTION_D, TCC_OPTION_HAS_ARG }, |
| 9455 | 9471 | { "U", TCC_OPTION_U, TCC_OPTION_HAS_ARG }, |
| @@ -9466,6 +9482,7 @@ static const TCCOption tcc_options[] = { · 10 unmodified lines | ||
| 9466 | 9482 | { "static", TCC_OPTION_static, 0 }, |
| 9467 | 9483 | { "shared", TCC_OPTION_shared, 0 }, |
| 9468 | 9484 | { "o", TCC_OPTION_o, TCC_OPTION_HAS_ARG }, |
| 9485 | + { "run", TCC_OPTION_run, 0 }, | |
| 9469 | 9486 | { "rdynamic", TCC_OPTION_rdynamic, 0 }, /* currently ignored */ |
| 9470 | 9487 | { "r", TCC_OPTION_r, 0 }, |
| 9471 | 9488 | { "W", TCC_OPTION_W, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP }, |
| @@ -9474,6 +9491,7 @@ static const TCCOption tcc_options[] = { · 2 unmodified lines | ||
| 9474 | 9491 | { "f", TCC_OPTION_f, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP }, |
| 9475 | 9492 | { "nostdinc", TCC_OPTION_nostdinc, 0 }, |
| 9476 | 9493 | { "print-search-dirs", TCC_OPTION_print_search_dirs, 0 }, |
| 9494 | + { "v", TCC_OPTION_v, 0 }, | |
| 9477 | 9495 | { NULL }, |
| 9478 | 9496 | }; |
| 9479 | 9497 | |
| @@ -9491,11 +9509,11 @@ int main(int argc, char **argv) · 11 unmodified lines | ||
| 9491 | 9509 | int print_search_dirs; |
| 9492 | 9510 | |
| 9493 | 9511 | s = tcc_new(); |
| 9494 | − output_type = TCC_OUTPUT_MEMORY; | |
| 9512 | + output_type = TCC_OUTPUT_EXE; | |
| 9495 | 9513 | |
| 9496 | 9514 | optind = 1; |
| 9497 | 9515 | outfile = NULL; |
| 9498 | − multiple_files = 0; | |
| 9516 | + multiple_files = 1; | |
| 9499 | 9517 | dminus = 0; |
| 9500 | 9518 | files = NULL; |
| 9501 | 9519 | nb_files = 0; |
| @@ -9556,15 +9574,6 @@ int main(int argc, char **argv) · 54 unmodified lines | ||
| 9556 | 9574 | show_help: |
| 9557 | 9575 | help(); |
| 9558 | 9576 | return 1; |
| 9559 | − case TCC_OPTION_MARKER: | |
| 9560 | − /* '--' enables multiple files input and also ends several | |
| 9561 | − file input */ | |
| 9562 | − if (dminus && multiple_files) { | |
| 9563 | − optind--; /* argv[0] will be '--' */ | |
| 9564 | − goto end_parse; | |
| 9565 | − } | |
| 9566 | − dminus = 1; | |
| 9567 | − multiple_files = 1; | |
| 9568 | 9577 | case TCC_OPTION_I: |
| 9569 | 9578 | if (tcc_add_include_path(s, optarg) < 0) |
| 9570 | 9579 | error("too many include paths"); |
| @@ -9635,12 +9644,18 @@ int main(int argc, char **argv) · 64 unmodified lines | ||
| 9635 | 9644 | case TCC_OPTION_print_search_dirs: |
| 9636 | 9645 | print_search_dirs = 1; |
| 9637 | 9646 | break; |
| 9647 | + case TCC_OPTION_run: | |
| 9648 | + multiple_files = 0; | |
| 9649 | + output_type = TCC_OUTPUT_MEMORY; | |
| 9650 | + break; | |
| 9651 | + case TCC_OPTION_v: | |
| 9652 | + printf("tcc version %s\n", TCC_VERSION); | |
| 9653 | + return 0; | |
| 9638 | 9654 | default: |
| 9639 | 9655 | break; |
| 9640 | 9656 | } |
| 9641 | 9657 | } |
| 9642 | 9658 | } |
| 9643 | − end_parse: | |
| 9644 | 9659 | if (print_search_dirs) { |
| 9645 | 9660 | /* enough for Linux kernel */ |
| 9646 | 9661 | printf("install: %s/\n", tcc_lib_path); |