History

added __TIME__ and __DATE__ support - added -v and -run options

bellard committed 23 years ago

Commit 40987541 parent dd56ab81 file · +38 −23Browse files

Unified · Split

tcc.c+38−23
@@ -3705,6 +3705,12 @@ static int *macro_arg_subst(Sym **nested_list, int *macro_str, Sym *args) · 3704 unmodified lines
3705 return str.str;3705 return str.str;
3706}3706}
3707 3707
3708static 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/* do macro substitution of current token with macro 's' and add3714/* do macro substitution of current token with macro 's' and add
3709 result to (tok_str,tok_len). 'nested_list' is the list of all3715 result to (tok_str,tok_len). 'nested_list' is the list of all
3710 macros we got inside to avoid recursing. Return non zero if no3716 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 cstrval = file->filename;3735 cstrval = file->filename;
3730 goto add_cstr;3736 goto add_cstr;
3731 tok_str_add2(tok_str, TOK_STR, &cval);3737 tok_str_add2(tok_str, TOK_STR, &cval);
3732 } else if (tok == TOK___DATE__) {3738 } else if (tok == TOK___DATE__ || tok == TOK___TIME__) {
3733 cstrval = "Jan 1 2002";3739 time_t ti;
3734 goto add_cstr;3740 struct tm *tm;
3735 } else if (tok == TOK___TIME__) {3741 char buf[64];
3736 cstrval = "00:00:00";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 add_cstr:3753 add_cstr:
3738 cstr_new(&cstr);3754 cstr_new(&cstr);
3739 cstr_cat(&cstr, cstrval);3755 cstr_cat(&cstr, cstrval);
@@ -9380,17 +9396,17 @@ static int64_t getclock_us(void) · 5640 unmodified lines
9380void help(void)9396void help(void)
9381{9397{
9382 printf("tcc version " TCC_VERSION " - Tiny C Compiler - Copyright (C) 2001, 2002 Fabrice Bellard\n" 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 " [-g] [-b] [-bt N] [-Ldir] [-llib] [-shared] [-static]\n"9400 " [-g] [-b] [-bt N] [-Ldir] [-llib] [-shared] [-static]\n"
9385 " [--] infile1 [infile2... --] [infile_args...]\n"9401 " [infile1 infile2...] [-run infile args...]\n"
9386 "\n"9402 "\n"
9387 "General options:\n"9403 "General options:\n"
9404 " -v display current version\n"
9388 " -c compile only - generate an object file\n"9405 " -c compile only - generate an object file\n"
9389 " -o outfile set output filename\n"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 " -Bdir set tcc internal library path\n"9407 " -Bdir set tcc internal library path\n"
9393 " -bench output compilation statistics\n"9408 " -bench output compilation statistics\n"
9409 " -run run compiled source\n"
9394 "Preprocessor options:\n"9410 "Preprocessor options:\n"
9395 " -Idir add include path 'dir'\n"9411 " -Idir add include path 'dir'\n"
9396 " -Dsym[=val] define 'sym' with value 'val'\n"9412 " -Dsym[=val] define 'sym' with value 'val'\n"
@@ -9421,7 +9437,6 @@ typedef struct TCCOption { · 24 unmodified lines
9421 9437
9422enum {9438enum {
9423 TCC_OPTION_HELP,9439 TCC_OPTION_HELP,
9424 TCC_OPTION_MARKER,
9425 TCC_OPTION_I,9440 TCC_OPTION_I,
9426 TCC_OPTION_D,9441 TCC_OPTION_D,
9427 TCC_OPTION_U,9442 TCC_OPTION_U,
@@ -9444,12 +9459,13 @@ enum { · 16 unmodified lines
9444 TCC_OPTION_nostdinc,9459 TCC_OPTION_nostdinc,
9445 TCC_OPTION_print_search_dirs,9460 TCC_OPTION_print_search_dirs,
9446 TCC_OPTION_rdynamic,9461 TCC_OPTION_rdynamic,
9462 TCC_OPTION_run,
9463 TCC_OPTION_v,
9447};9464};
9448 9465
9449static const TCCOption tcc_options[] = {9466static const TCCOption tcc_options[] = {
9450 { "h", TCC_OPTION_HELP, 0 },9467 { "h", TCC_OPTION_HELP, 0 },
9451 { "?", TCC_OPTION_HELP, 0 },9468 { "?", TCC_OPTION_HELP, 0 },
9452 { "-", TCC_OPTION_MARKER, 0 },
9453 { "I", TCC_OPTION_I, TCC_OPTION_HAS_ARG },9469 { "I", TCC_OPTION_I, TCC_OPTION_HAS_ARG },
9454 { "D", TCC_OPTION_D, TCC_OPTION_HAS_ARG },9470 { "D", TCC_OPTION_D, TCC_OPTION_HAS_ARG },
9455 { "U", TCC_OPTION_U, TCC_OPTION_HAS_ARG },9471 { "U", TCC_OPTION_U, TCC_OPTION_HAS_ARG },
@@ -9466,6 +9482,7 @@ static const TCCOption tcc_options[] = { · 10 unmodified lines
9466 { "static", TCC_OPTION_static, 0 },9482 { "static", TCC_OPTION_static, 0 },
9467 { "shared", TCC_OPTION_shared, 0 },9483 { "shared", TCC_OPTION_shared, 0 },
9468 { "o", TCC_OPTION_o, TCC_OPTION_HAS_ARG },9484 { "o", TCC_OPTION_o, TCC_OPTION_HAS_ARG },
9485 { "run", TCC_OPTION_run, 0 },
9469 { "rdynamic", TCC_OPTION_rdynamic, 0 }, /* currently ignored */9486 { "rdynamic", TCC_OPTION_rdynamic, 0 }, /* currently ignored */
9470 { "r", TCC_OPTION_r, 0 },9487 { "r", TCC_OPTION_r, 0 },
9471 { "W", TCC_OPTION_W, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP },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 { "f", TCC_OPTION_f, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP },9491 { "f", TCC_OPTION_f, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP },
9475 { "nostdinc", TCC_OPTION_nostdinc, 0 },9492 { "nostdinc", TCC_OPTION_nostdinc, 0 },
9476 { "print-search-dirs", TCC_OPTION_print_search_dirs, 0 }, 9493 { "print-search-dirs", TCC_OPTION_print_search_dirs, 0 },
9494 { "v", TCC_OPTION_v, 0 },
9477 { NULL },9495 { NULL },
9478};9496};
9479 9497
@@ -9491,11 +9509,11 @@ int main(int argc, char **argv) · 11 unmodified lines
9491 int print_search_dirs;9509 int print_search_dirs;
9492 9510
9493 s = tcc_new();9511 s = tcc_new();
9494 output_type = TCC_OUTPUT_MEMORY;9512 output_type = TCC_OUTPUT_EXE;
9495 9513
9496 optind = 1;9514 optind = 1;
9497 outfile = NULL;9515 outfile = NULL;
9498 multiple_files = 0;9516 multiple_files = 1;
9499 dminus = 0;9517 dminus = 0;
9500 files = NULL;9518 files = NULL;
9501 nb_files = 0;9519 nb_files = 0;
@@ -9556,15 +9574,6 @@ int main(int argc, char **argv) · 54 unmodified lines
9556 show_help:9574 show_help:
9557 help();9575 help();
9558 return 1;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 case TCC_OPTION_I:9577 case TCC_OPTION_I:
9569 if (tcc_add_include_path(s, optarg) < 0)9578 if (tcc_add_include_path(s, optarg) < 0)
9570 error("too many include paths");9579 error("too many include paths");
@@ -9635,12 +9644,18 @@ int main(int argc, char **argv) · 64 unmodified lines
9635 case TCC_OPTION_print_search_dirs:9644 case TCC_OPTION_print_search_dirs:
9636 print_search_dirs = 1;9645 print_search_dirs = 1;
9637 break;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 default:9654 default:
9639 break;9655 break;
9640 }9656 }
9641 }9657 }
9642 }9658 }
9643 end_parse:
9644 if (print_search_dirs) {9659 if (print_search_dirs) {
9645 /* enough for Linux kernel */9660 /* enough for Linux kernel */
9646 printf("install: %s/\n", tcc_lib_path);9661 printf("install: %s/\n", tcc_lib_path);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t