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
37053705 return str.str;
37063706 }
37073707
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+
37083714 /* do macro substitution of current token with macro 's' and add
37093715 result to (tok_str,tok_len). 'nested_list' is the list of all
37103716 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
37293735 cstrval = file->filename;
37303736 goto add_cstr;
37313737 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;
37373753 add_cstr:
37383754 cstr_new(&cstr);
37393755 cstr_cat(&cstr, cstrval);
@@ -9380,17 +9396,17 @@ static int64_t getclock_us(void) · 5640 unmodified lines
93809396 void help(void)
93819397 {
93829398 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"
93849400 " [-g] [-b] [-bt N] [-Ldir] [-llib] [-shared] [-static]\n"
9385− " [--] infile1 [infile2... --] [infile_args...]\n"
9401+ " [infile1 infile2...] [-run infile args...]\n"
93869402 "\n"
93879403 "General options:\n"
9404+ " -v display current version\n"
93889405 " -c compile only - generate an object file\n"
93899406 " -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"
93929407 " -Bdir set tcc internal library path\n"
93939408 " -bench output compilation statistics\n"
9409+ " -run run compiled source\n"
93949410 "Preprocessor options:\n"
93959411 " -Idir add include path 'dir'\n"
93969412 " -Dsym[=val] define 'sym' with value 'val'\n"
@@ -9421,7 +9437,6 @@ typedef struct TCCOption { · 24 unmodified lines
94219437
94229438 enum {
94239439 TCC_OPTION_HELP,
9424− TCC_OPTION_MARKER,
94259440 TCC_OPTION_I,
94269441 TCC_OPTION_D,
94279442 TCC_OPTION_U,
@@ -9444,12 +9459,13 @@ enum { · 16 unmodified lines
94449459 TCC_OPTION_nostdinc,
94459460 TCC_OPTION_print_search_dirs,
94469461 TCC_OPTION_rdynamic,
9462+ TCC_OPTION_run,
9463+ TCC_OPTION_v,
94479464 };
94489465
94499466 static const TCCOption tcc_options[] = {
94509467 { "h", TCC_OPTION_HELP, 0 },
94519468 { "?", TCC_OPTION_HELP, 0 },
9452− { "-", TCC_OPTION_MARKER, 0 },
94539469 { "I", TCC_OPTION_I, TCC_OPTION_HAS_ARG },
94549470 { "D", TCC_OPTION_D, TCC_OPTION_HAS_ARG },
94559471 { "U", TCC_OPTION_U, TCC_OPTION_HAS_ARG },
@@ -9466,6 +9482,7 @@ static const TCCOption tcc_options[] = { · 10 unmodified lines
94669482 { "static", TCC_OPTION_static, 0 },
94679483 { "shared", TCC_OPTION_shared, 0 },
94689484 { "o", TCC_OPTION_o, TCC_OPTION_HAS_ARG },
9485+ { "run", TCC_OPTION_run, 0 },
94699486 { "rdynamic", TCC_OPTION_rdynamic, 0 }, /* currently ignored */
94709487 { "r", TCC_OPTION_r, 0 },
94719488 { "W", TCC_OPTION_W, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP },
@@ -9474,6 +9491,7 @@ static const TCCOption tcc_options[] = { · 2 unmodified lines
94749491 { "f", TCC_OPTION_f, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP },
94759492 { "nostdinc", TCC_OPTION_nostdinc, 0 },
94769493 { "print-search-dirs", TCC_OPTION_print_search_dirs, 0 },
9494+ { "v", TCC_OPTION_v, 0 },
94779495 { NULL },
94789496 };
94799497
@@ -9491,11 +9509,11 @@ int main(int argc, char **argv) · 11 unmodified lines
94919509 int print_search_dirs;
94929510
94939511 s = tcc_new();
9494− output_type = TCC_OUTPUT_MEMORY;
9512+ output_type = TCC_OUTPUT_EXE;
94959513
94969514 optind = 1;
94979515 outfile = NULL;
9498− multiple_files = 0;
9516+ multiple_files = 1;
94999517 dminus = 0;
95009518 files = NULL;
95019519 nb_files = 0;
@@ -9556,15 +9574,6 @@ int main(int argc, char **argv) · 54 unmodified lines
95569574 show_help:
95579575 help();
95589576 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;
95689577 case TCC_OPTION_I:
95699578 if (tcc_add_include_path(s, optarg) < 0)
95709579 error("too many include paths");
@@ -9635,12 +9644,18 @@ int main(int argc, char **argv) · 64 unmodified lines
96359644 case TCC_OPTION_print_search_dirs:
96369645 print_search_dirs = 1;
96379646 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;
96389654 default:
96399655 break;
96409656 }
96419657 }
96429658 }
9643− end_parse:
96449659 if (print_search_dirs) {
96459660 /* enough for Linux kernel */
96469661 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