History

added hash tables - add -o option for debug output

bellard committed 25 years ago

Commit b9455a71 parent 44b5c971 file · +143 −78Browse files

Unified · Split

tcc.c+143−78
@@ -34,14 +34,18 @@ · 33 unmodified lines
34#define STRING_MAX_SIZE 102434#define STRING_MAX_SIZE 1024
35#define INCLUDE_PATHS_MAX 3235#define INCLUDE_PATHS_MAX 32
36 36
37#define TOK_HASH_SIZE 521
38#define TOK_ALLOC_INCR 256 /* must be a power of two */
39#define SYM_HASH_SIZE 263
40
37/* number of available temporary registers */41/* number of available temporary registers */
38#define NB_REGS 342#define NB_REGS 3
39/* defined if function parameters must be evaluated in revert order */43/* defined if function parameters must be evaluated in reverse order */
40#define INVERT_FUNC_PARAMS44#define INVERT_FUNC_PARAMS
41 45
42/* token symbol management */46/* token symbol management */
43typedef struct TokenSym {47typedef struct TokenSym {
44 struct TokenSym *next;48 struct TokenSym *hash_next;
45 int tok; /* token number */49 int tok; /* token number */
46 int len;50 int len;
47 char str[1];51 char str[1];
@@ -54,8 +58,14 @@ typedef struct Sym { · 6 unmodified lines
54 int c; /* associated number */58 int c; /* associated number */
55 struct Sym *next; /* next related symbol */59 struct Sym *next; /* next related symbol */
56 struct Sym *prev; /* prev symbol in stack */60 struct Sym *prev; /* prev symbol in stack */
61 struct Sym *hash_next; /* next symbol in hash table */
57} Sym;62} Sym;
58 63
64typedef struct SymStack {
65 struct Sym *top;
66 struct Sym *hash[SYM_HASH_SIZE];
67} SymStack;
68
59#define SYM_STRUCT 0x40000000 /* struct/union/enum symbol space */69#define SYM_STRUCT 0x40000000 /* struct/union/enum symbol space */
60#define SYM_FIELD 0x20000000 /* struct/union field symbol space */70#define SYM_FIELD 0x20000000 /* struct/union field symbol space */
61 71
@@ -87,10 +97,12 @@ typedef struct { · 25 unmodified lines
87FILE *file;97FILE *file;
88int tok, tok1, tokc, rsym, anon_sym,98int tok, tok1, tokc, rsym, anon_sym,
89 prog, ind, loc, glo, vt, vc, const_wanted, line_num;99 prog, ind, loc, glo, vt, vc, const_wanted, line_num;
90TokenSym *first_ident;100int tok_ident;
101TokenSym **table_ident;
102TokenSym *hash_ident[521];
91char token_buf[STRING_MAX_SIZE + 1];103char token_buf[STRING_MAX_SIZE + 1];
92char *filename, *funcname;104char *filename, *funcname;
93Sym *define_stack, *global_stack, *local_stack, *label_stack;105SymStack define_stack, global_stack, local_stack, label_stack;
94 106
95int vstack[VSTACK_SIZE], *vstack_ptr;107int vstack[VSTACK_SIZE], *vstack_ptr;
96int *macro_ptr, *macro_ptr_allocated;108int *macro_ptr, *macro_ptr_allocated;
@@ -283,14 +295,14 @@ void *dlsym(void *handle, char *symbol) · 186 unmodified lines
283 295
284#endif296#endif
285 297
286int isid(c)298inline int isid(c)
287{299{
288 return (c >= 'a' & c <= 'z') |300 return (c >= 'a' && c <= 'z') ||
289 (c >= 'A' & c <= 'Z') |301 (c >= 'A' && c <= 'Z') ||
290 c == '_';302 c == '_';
291}303}
292 304
293int isnum(c)305inline int isnum(c)
294{306{
295 return c >= '0' & c <= '9';307 return c >= '0' & c <= '9';
296}308}
@@ -341,31 +353,40 @@ void test_lvalue() · 44 unmodified lines
341 353
342TokenSym *tok_alloc(char *str, int len)354TokenSym *tok_alloc(char *str, int len)
343{355{
344 TokenSym *ts, **pts;356 TokenSym *ts, **pts, **ptable;
345 int t;357 int h, i;
346 358
347 if (len <= 0)359 if (len <= 0)
348 len = strlen(str);360 len = strlen(str);
349 361 h = 1;
350 t = TOK_IDENT;362 for(i=0;i<len;i++)
351 pts = &first_ident;363 h = ((h << 8) | (str[i] & 0xff)) % TOK_HASH_SIZE;
364
365 pts = &hash_ident[h];
352 while (1) {366 while (1) {
353 ts = *pts;367 ts = *pts;
354 if (!ts)368 if (!ts)
355 break;369 break;
356 if (ts->len == len && !memcmp(ts->str, str, len))370 if (ts->len == len && !memcmp(ts->str, str, len))
357 return ts;371 return ts;
358 t++;372 pts = &(ts->hash_next);
359 pts = &(ts->next);373 }
374 /* expand token table if needed */
375 i = tok_ident - TOK_IDENT;
376 if ((i % TOK_ALLOC_INCR) == 0) {
377 ptable = realloc(table_ident, (i + TOK_ALLOC_INCR) * sizeof(TokenSym *));
378 if (!ptable)
379 error("memory full");
380 table_ident = ptable;
360 }381 }
361 ts = malloc(sizeof(TokenSym) + len);382 ts = malloc(sizeof(TokenSym) + len);
362 if (!ts)383 if (!ts)
363 error("memory full");384 error("memory full");
364 ts->tok = t;385 table_ident[i] = ts;
386 ts->tok = tok_ident++;
365 ts->len = len;387 ts->len = len;
366 ts->next = NULL;388 ts->hash_next = NULL;
367 memcpy(ts->str, str, len + 1);389 memcpy(ts->str, str, len + 1);
368
369 *pts = ts;390 *pts = ts;
370 return ts;391 return ts;
371}392}
@@ -425,40 +446,65 @@ char *get_tok_str(int v, int c) · 53 unmodified lines
425 *p++ = v;446 *p++ = v;
426 *p = '\0';447 *p = '\0';
427 return buf;448 return buf;
449 } else if (v < tok_ident) {
450 return table_ident[v - TOK_IDENT]->str;
428 } else {451 } else {
429 ts = first_ident;452 /* should never happen */
430 while (ts != NULL) {
431 if (ts->tok == v)
432 return ts->str;
433 ts = ts->next;
434 }
435 return NULL;453 return NULL;
436 }454 }
437}455}
438 456
457/* push, without hashing */
458Sym *sym_push2(Sym **ps, int v, int t, int c)
459{
460 Sym *s;
461 s = malloc(sizeof(Sym));
462 if (!s)
463 error("memory full");
464 s->v = v;
465 s->t = t;
466 s->c = c;
467 s->next = NULL;
468 /* add in stack */
469 s->prev = *ps;
470 *ps = s;
471 return s;
472}
473
439/* find a symbol and return its associated structure. 's' is the top474/* find a symbol and return its associated structure. 's' is the top
440 of the symbol stack */475 of the symbol stack */
441Sym *sym_find1(Sym *s, int v)476Sym *sym_find2(Sym *s, int v)
442{477{
443 while (s) {478 while (s) {
444 if (s->v == v)479 if (s->v == v)
445 return s;480 return s;
446 s = s->prev;481 s = s->prev;
447 }482 }
448 return 0;483 return NULL;
449}484}
450 485
451Sym *sym_push1(Sym **ps, int v, int t, int c)486/* find a symbol and return its associated structure. 'st' is the
487 symbol stack */
488Sym *sym_find1(SymStack *st, int v)
452{489{
453 Sym *s;490 Sym *s;
454 s = malloc(sizeof(Sym));491
455 if (!s)492 s = st->hash[v % SYM_HASH_SIZE];
456 error("memory full");493 while (s) {
457 s->v = v;494 if (s->v == v)
458 s->t = t;495 return s;
459 s->c = c;496 s = s->hash_next;
460 s->next = NULL;497 }
461 s->prev = *ps;498 return 0;
499}
500
501Sym *sym_push1(SymStack *st, int v, int t, int c)
502{
503 Sym *s, **ps;
504 s = sym_push2(&st->top, v, t, c);
505 /* add in hash table */
506 ps = &st->hash[s->v % SYM_HASH_SIZE];
507 s->hash_next = *ps;
462 *ps = s;508 *ps = s;
463 return s;509 return s;
464}510}
@@ -467,33 +513,35 @@ Sym *sym_push1(Sym **ps, int v, int t, int c) · 2 unmodified lines
467Sym *sym_find(int v)513Sym *sym_find(int v)
468{514{
469 Sym *s;515 Sym *s;
470 s = sym_find1(local_stack, v);516 s = sym_find1(&local_stack, v);
471 if (!s)517 if (!s)
472 s = sym_find1(global_stack, v);518 s = sym_find1(&global_stack, v);
473 return s;519 return s;
474}520}
475 521
476/* push a given symbol on the symbol stack */522/* push a given symbol on the symbol stack */
477Sym *sym_push(int v, int t, int c)523Sym *sym_push(int v, int t, int c)
478{524{
479 if (local_stack)525 if (local_stack.top)
480 return sym_push1(&local_stack, v, t, c);526 return sym_push1(&local_stack, v, t, c);
481 else527 else
482 return sym_push1(&global_stack, v, t, c);528 return sym_push1(&global_stack, v, t, c);
483}529}
484 530
485/* pop symbols until top reaches 'b' */531/* pop symbols until top reaches 'b' */
486void sym_pop(Sym **ps, Sym *b)532void sym_pop(SymStack *st, Sym *b)
487{533{
488 Sym *s, *ss;534 Sym *s, *ss;
489 535
490 s = *ps;536 s = st->top;
491 while(s != b) {537 while(s != b) {
492 ss = s->prev;538 ss = s->prev;
539 /* free hash table entry */
540 st->hash[s->v % SYM_HASH_SIZE] = s->hash_next;
493 free(s);541 free(s);
494 s = ss;542 s = ss;
495 }543 }
496 *ps = b;544 st->top = b;
497}545}
498 546
499int ch, ch1;547int ch, ch1;
@@ -640,7 +688,7 @@ int expr_preprocess() · 140 unmodified lines
640 t = tok;688 t = tok;
641 if (t == '(') 689 if (t == '(')
642 next_nomacro();690 next_nomacro();
643 c = sym_find1(define_stack, tok) != 0;691 c = sym_find1(&define_stack, tok) != 0;
644 if (t == '(')692 if (t == '(')
645 next_nomacro();693 next_nomacro();
646 tok = TOK_NUM;694 tok = TOK_NUM;
@@ -748,7 +796,7 @@ void preprocess() · 101 unmodified lines
748 s->next = first;796 s->next = first;
749 } else if (tok == TOK_UNDEF) {797 } else if (tok == TOK_UNDEF) {
750 next_nomacro();798 next_nomacro();
751 s = sym_find1(define_stack, tok);799 s = sym_find1(&define_stack, tok);
752 /* undefine symbol by putting an invalid name */800 /* undefine symbol by putting an invalid name */
753 if (s)801 if (s)
754 s->v = 0;802 s->v = 0;
@@ -823,7 +871,7 @@ void preprocess() · 68 unmodified lines
823 c = 0;871 c = 0;
824 do_ifdef:872 do_ifdef:
825 next_nomacro();873 next_nomacro();
826 c = (sym_find1(define_stack, tok) != 0) ^ c;874 c = (sym_find1(&define_stack, tok) != 0) ^ c;
827 do_if:875 do_if:
828 if (ifdef_stack_ptr >= ifdef_stack + IFDEF_STACK_SIZE)876 if (ifdef_stack_ptr >= ifdef_stack + IFDEF_STACK_SIZE)
829 error("memory full");877 error("memory full");
@@ -1094,7 +1142,7 @@ int *macro_arg_subst(Sym **nested_list, int *macro_str, Sym *args) · 264 unmodified lines
1094 t = *macro_str++;1142 t = *macro_str++;
1095 if (!t)1143 if (!t)
1096 break;1144 break;
1097 s = sym_find1(args, t);1145 s = sym_find2(args, t);
1098 if (s) {1146 if (s) {
1099 token_buf[0] = '\0';1147 token_buf[0] = '\0';
1100 st = (int *)s->c;1148 st = (int *)s->c;
@@ -1122,7 +1170,7 @@ int *macro_arg_subst(Sym **nested_list, int *macro_str, Sym *args) · 21 unmodified lines
1122 } else if (t == TOK_NUM || t == TOK_CCHAR || t == TOK_STR) {1170 } else if (t == TOK_NUM || t == TOK_CCHAR || t == TOK_STR) {
1123 tok_add2(&str, &len, t, *macro_ptr++);1171 tok_add2(&str, &len, t, *macro_ptr++);
1124 } else {1172 } else {
1125 s = sym_find1(args, t);1173 s = sym_find2(args, t);
1126 if (s) {1174 if (s) {
1127 st = (int *)s->c;1175 st = (int *)s->c;
1128 /* if '##' is present before or after , no arg substitution */1176 /* if '##' is present before or after , no arg substitution */
@@ -1199,7 +1247,7 @@ int *macro_twosharps(int *macro_str) · 70 unmodified lines
1199void macro_subst(int **tok_str, int *tok_len, 1247void macro_subst(int **tok_str, int *tok_len,
1200 Sym **nested_list, int *macro_str)1248 Sym **nested_list, int *macro_str)
1201{1249{
1202 Sym *s, *args, *sa;1250 Sym *s, *args, *sa, *sa1;
1203 int *str, parlevel, len, *mstr, t, *saved_macro_ptr;1251 int *str, parlevel, len, *mstr, t, *saved_macro_ptr;
1204 int mstr_allocated, *macro_str1;1252 int mstr_allocated, *macro_str1;
1205 1253
@@ -1228,10 +1276,10 @@ void macro_subst(int **tok_str, int *tok_len, · 22 unmodified lines
1228 } else if (tok == TOK___TIME__) {1276 } else if (tok == TOK___TIME__) {
1229 tok_add2(tok_str, tok_len, TOK_STR, 1277 tok_add2(tok_str, tok_len, TOK_STR,
1230 (int)tok_alloc("00:00:00", 0));1278 (int)tok_alloc("00:00:00", 0));
1231 } else if ((s = sym_find1(define_stack, tok)) != NULL) {1279 } else if ((s = sym_find1(&define_stack, tok)) != NULL) {
1232 /* if symbol is a macro, prepare substitution */1280 /* if symbol is a macro, prepare substitution */
1233 /* if nested substitution, do nothing */1281 /* if nested substitution, do nothing */
1234 if (sym_find1(*nested_list, tok))1282 if (sym_find2(*nested_list, tok))
1235 goto no_subst;1283 goto no_subst;
1236 mstr = (int *)s->c;1284 mstr = (int *)s->c;
1237 mstr_allocated = 0;1285 mstr_allocated = 0;
@@ -1270,7 +1318,7 @@ void macro_subst(int **tok_str, int *tok_len, · 32 unmodified lines
1270 next_nomacro();1318 next_nomacro();
1271 }1319 }
1272 tok_add(&str, &len, 0);1320 tok_add(&str, &len, 0);
1273 sym_push1(&args, sa->v & ~SYM_FIELD, 0, (int)str);1321 sym_push2(&args, sa->v & ~SYM_FIELD, 0, (int)str);
1274 if (tok != ',')1322 if (tok != ',')
1275 break;1323 break;
1276 next_nomacro();1324 next_nomacro();
@@ -1283,15 +1331,19 @@ void macro_subst(int **tok_str, int *tok_len, · 6 unmodified lines
1283 /* free memory */1331 /* free memory */
1284 sa = args;1332 sa = args;
1285 while (sa) {1333 while (sa) {
1334 sa1 = sa->prev;
1286 free((int *)sa->c);1335 free((int *)sa->c);
1287 sa = sa->prev;1336 free(sa);
1337 sa = sa1;
1288 }1338 }
1289 sym_pop(&args, NULL);
1290 mstr_allocated = 1;1339 mstr_allocated = 1;
1291 }1340 }
1292 sym_push1(nested_list, s->v, 0, 0);1341 sym_push2(nested_list, s->v, 0, 0);
1293 macro_subst(tok_str, tok_len, nested_list, mstr);1342 macro_subst(tok_str, tok_len, nested_list, mstr);
1294 sym_pop(nested_list, (*nested_list)->prev);1343 /* pop nested defined symbol */
1344 sa1 = *nested_list;
1345 *nested_list = sa1->prev;
1346 free(sa1);
1295 if (mstr_allocated)1347 if (mstr_allocated)
1296 free(mstr);1348 free(mstr);
1297 } else {1349 } else {
@@ -2425,7 +2477,7 @@ void unary() · 1127 unmodified lines
2425#ifdef INVERT_FUNC_PARAMS2477#ifdef INVERT_FUNC_PARAMS
2426 {2478 {
2427 int *str, len, parlevel, *saved_macro_ptr;2479 int *str, len, parlevel, *saved_macro_ptr;
2428 Sym *args;2480 Sym *args, *s1;
2429 2481
2430 /* read each argument and store it on a stack */2482 /* read each argument and store it on a stack */
2431 /* XXX: merge it with macro args ? */2483 /* XXX: merge it with macro args ? */
@@ -2445,7 +2497,7 @@ void unary() · 13 unmodified lines
2445 }2497 }
2446 tok_add(&str, &len, -1); /* end of file added */2498 tok_add(&str, &len, -1); /* end of file added */
2447 tok_add(&str, &len, 0);2499 tok_add(&str, &len, 0);
2448 sym_push1(&args, 0, 0, (int)str);2500 sym_push2(&args, 0, 0, (int)str);
2449 if (tok != ',')2501 if (tok != ',')
2450 break;2502 break;
2451 next();2503 next();
@@ -2462,8 +2514,10 @@ void unary() · 10 unmodified lines
2462 next();2514 next();
2463 expr_eq();2515 expr_eq();
2464 gfunc_param();2516 gfunc_param();
2517 s1 = args->prev;
2465 free((int *)args->c);2518 free((int *)args->c);
2466 sym_pop(&args, args->prev);2519 free(args);
2520 args = s1;
2467 }2521 }
2468 macro_ptr = saved_macro_ptr;2522 macro_ptr = saved_macro_ptr;
2469 /* restore token */2523 /* restore token */
@@ -2692,7 +2746,7 @@ void block(int *bsym, int *csym, int *case_sym, int *def_sym, int case_reg) · 222 unmodified lines
2692 } else if (tok == '{') {2746 } else if (tok == '{') {
2693 next();2747 next();
2694 /* declarations */2748 /* declarations */
2695 s = local_stack;2749 s = local_stack.top;
2696 while (tok != '}') {2750 while (tok != '}') {
2697 decl(VT_LOCAL);2751 decl(VT_LOCAL);
2698 block(bsym, csym, case_sym, def_sym, case_reg);2752 block(bsym, csym, case_sym, def_sym, case_reg);
@@ -2810,7 +2864,7 @@ void block(int *bsym, int *csym, int *case_sym, int *def_sym, int case_reg) · 111 unmodified lines
2810 } else2864 } else
2811 if (tok == TOK_GOTO) {2865 if (tok == TOK_GOTO) {
2812 next();2866 next();
2813 s = sym_find1(label_stack, tok);2867 s = sym_find1(&label_stack, tok);
2814 /* put forward definition if needed */2868 /* put forward definition if needed */
2815 if (!s)2869 if (!s)
2816 s = sym_push1(&label_stack, tok, VT_FORWARD, 0);2870 s = sym_push1(&label_stack, tok, VT_FORWARD, 0);
@@ -2827,7 +2881,7 @@ void block(int *bsym, int *csym, int *case_sym, int *def_sym, int case_reg) · 10 unmodified lines
2827 if (tok == ':') {2881 if (tok == ':') {
2828 next();2882 next();
2829 /* label case */2883 /* label case */
2830 s = sym_find1(label_stack, b);2884 s = sym_find1(&label_stack, b);
2831 if (s) {2885 if (s) {
2832 if (!(s->t & VT_FORWARD))2886 if (!(s->t & VT_FORWARD))
2833 error("multiple defined label");2887 error("multiple defined label");
@@ -2988,7 +3042,6 @@ void decl_assign(int t, int c, int first) · 154 unmodified lines
2988 } else {3042 } else {
2989 if ((t & VT_VALMASK) == VT_CONST) {3043 if ((t & VT_VALMASK) == VT_CONST) {
2990 v = expr_const();3044 v = expr_const();
2991 printf("v=%d\n", v);
2992 if (t & VT_BYTE)3045 if (t & VT_BYTE)
2993 *(char *)c = v;3046 *(char *)c = v;
2994 else if (t & VT_SHORT)3047 else if (t & VT_SHORT)
@@ -3135,11 +3188,20 @@ void open_dll(char *libname) · 140 unmodified lines
3135 error((char *)dlerror());3188 error((char *)dlerror());
3136}3189}
3137 3190
3191/* output a binary file (for testing) */
3192void build_exe(char *filename)
3193{
3194 FILE *f;
3195 f = fopen(filename, "w");
3196 fwrite((void *)prog, 1, ind - prog, f);
3197 fclose(f);
3198}
3199
3138int main(int argc, char **argv)3200int main(int argc, char **argv)
3139{3201{
3140 Sym *s;3202 Sym *s;
3141 int (*t)();3203 int (*t)();
3142 char *p, *r;3204 char *p, *r, *outfile;
3143 int optind;3205 int optind;
3144 3206
3145 include_paths[0] = "/usr/include";3207 include_paths[0] = "/usr/include";
@@ -3148,6 +3210,7 @@ int main(int argc, char **argv) · 2 unmodified lines
3148 nb_include_paths = 3;3210 nb_include_paths = 3;
3149 3211
3150 /* add all tokens */3212 /* add all tokens */
3213 tok_ident = TOK_IDENT;
3151 p = "int\0void\0char\0if\0else\0while\0break\0return\0for\0extern\0static\0unsigned\0goto\0do\0continue\0switch\0case\0const\0volatile\0long\0register\0signed\0auto\0inline\0restrict\0float\0double\0short\0struct\0union\0typedef\0default\0enum\0sizeof\0define\0include\0ifdef\0ifndef\0elif\0endif\0defined\0undef\0error\0line\0__LINE__\0__FILE__\0__DATE__\0__TIME__\0__VA_ARGS__\0__func__\0main\0";3214 p = "int\0void\0char\0if\0else\0while\0break\0return\0for\0extern\0static\0unsigned\0goto\0do\0continue\0switch\0case\0const\0volatile\0long\0register\0signed\0auto\0inline\0restrict\0float\0double\0short\0struct\0union\0typedef\0default\0enum\0sizeof\0define\0include\0ifdef\0ifndef\0elif\0endif\0defined\0undef\0error\0line\0__LINE__\0__FILE__\0__DATE__\0__TIME__\0__VA_ARGS__\0__func__\0main\0";
3152 while (*p) {3215 while (*p) {
3153 r = p;3216 r = p;
@@ -3163,8 +3226,10 @@ int main(int argc, char **argv) · 9 unmodified lines
3163#endif3226#endif
3164 3227
3165 optind = 1;3228 optind = 1;
3229 outfile = NULL;
3166 while (1) {3230 while (1) {
3167 if (optind >= argc) {3231 if (optind >= argc) {
3232 show_help:
3168 printf("tcc version 0.9 - Tiny C Compiler - Copyright (C) 2001 Fabrice Bellard\n" 3233 printf("tcc version 0.9 - Tiny C Compiler - Copyright (C) 2001 Fabrice Bellard\n"
3169 "usage: tcc [-Idir] [-Dsym] [-llib] infile [infile_arg...]\n");3234 "usage: tcc [-Idir] [-Dsym] [-llib] infile [infile_arg...]\n");
3170 return 1;3235 return 1;
@@ -3172,6 +3237,7 @@ int main(int argc, char **argv) · 1 unmodified line
3172 r = argv[optind];3237 r = argv[optind];
3173 if (r[0] != '-')3238 if (r[0] != '-')
3174 break;3239 break;
3240 optind++;
3175 if (r[1] == 'I') {3241 if (r[1] == 'I') {
3176 if (nb_include_paths >= INCLUDE_PATHS_MAX)3242 if (nb_include_paths >= INCLUDE_PATHS_MAX)
3177 error("too many include paths");3243 error("too many include paths");
@@ -3180,11 +3246,15 @@ int main(int argc, char **argv) · 2 unmodified lines
3180 define_symbol(r + 2);3246 define_symbol(r + 2);
3181 } else if (r[1] == 'l') {3247 } else if (r[1] == 'l') {
3182 open_dll(r + 2);3248 open_dll(r + 2);
3249 } else if (r[1] == 'o') {
3250 /* currently, only for testing, so not documented */
3251 if (optind >= argc)
3252 goto show_help;
3253 outfile = argv[optind++];
3183 } else {3254 } else {
3184 fprintf(stderr, "invalid option -- '%s'\n", r);3255 fprintf(stderr, "invalid option -- '%s'\n", r);
3185 exit(1);3256 exit(1);
3186 }3257 }
3187 optind++;
3188 }3258 }
3189 3259
3190 filename = argv[optind];3260 filename = argv[optind];
@@ -3210,23 +3280,18 @@ int main(int argc, char **argv) · 19 unmodified lines
3210 decl(VT_CONST);3280 decl(VT_CONST);
3211 if (tok != -1)3281 if (tok != -1)
3212 expect("declaration");3282 expect("declaration");
3213#ifdef TEST3283 if (outfile) {
3214 { 3284 build_exe(outfile);
3215 FILE *f;
3216 f = fopen(argv[optind + 1], "w");
3217 fwrite((void *)prog, 1, ind - prog, f);
3218 fclose(f);
3219 return 0;3285 return 0;
3220 }3286 } else {
3221#else3287 s = sym_find(TOK_MAIN);
3222 s = sym_find(TOK_MAIN);3288 if (!s)
3223 if (!s)3289 error("main() not defined");
3224 error("main() not defined");3290 t = (int (*)())s->c;
3225 t = (int (*)())s->c;
3226#ifdef PROFILE3291#ifdef PROFILE
3227 return 1;3292 return 1;
3228#else3293#else
3229 return (*t)(argc - optind, argv + optind);3294 return (*t)(argc - optind, argv + optind);
3230#endif
3231#endif3295#endif
3296 }
3232}3297}

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