| @@ -25,11 +25,15 @@ · 24 unmodified lines |
| 25 | #include <math.h> | 25 | #include <math.h> |
| 26 | #include <unistd.h> | 26 | #include <unistd.h> |
| 27 | #include <signal.h> | 27 | #include <signal.h> |
| | 28 | #include <malloc.h> |
| | 29 | #include <unistd.h> |
| | 30 | #include <fcntl.h> |
| | 31 | #ifndef WIN32 |
| 28 | #include <sys/ucontext.h> | 32 | #include <sys/ucontext.h> |
| 29 | #include <sys/mman.h> | 33 | #include <sys/mman.h> |
| 30 | #include <elf.h> | 34 | #endif |
| 31 | #include <stab.h> | 35 | #include "elf.h" |
| 32 | #include <malloc.h> | 36 | #include "stab.h" |
| 33 | #ifndef CONFIG_TCC_STATIC | 37 | #ifndef CONFIG_TCC_STATIC |
| 34 | #include <dlfcn.h> | 38 | #include <dlfcn.h> |
| 35 | #endif | 39 | #endif |
| @@ -145,15 +149,22 @@ typedef struct AttributeDef { · 109 unmodified lines |
| 145 | #define TYPE_ABSTRACT 1 /* type without variable */ | 149 | #define TYPE_ABSTRACT 1 /* type without variable */ |
| 146 | #define TYPE_DIRECT 2 /* type with variable */ | 150 | #define TYPE_DIRECT 2 /* type with variable */ |
| 147 | | 151 | |
| 148 | typedef struct { | 152 | #define IO_BUF_SIZE 8192 |
| 149 | FILE *file; | 153 | |
| 150 | char *filename; | 154 | typedef struct BufferedFile { |
| 151 | int line_num; | 155 | unsigned char *buf_ptr; |
| 152 | } IncludeFile; | 156 | unsigned char *buf_end; |
| | 157 | int fd; |
| | 158 | int line_num; /* current line number - here to simply code */ |
| | 159 | char filename[1024]; /* current filename - here to simply code */ |
| | 160 | unsigned char buffer[IO_BUF_SIZE + 1]; /* extra size for CH_EOB char */ |
| | 161 | } BufferedFile; |
| | 162 | |
| | 163 | #define CH_EOB 0 /* end of buffer or '\0' char in file */ |
| | 164 | #define CH_EOF (-1) /* end of file */ |
| 153 | | 165 | |
| 154 | /* parser */ | 166 | /* parser */ |
| 155 | FILE *file; | 167 | struct BufferedFile *file; |
| 156 | int line_num; | | |
| 157 | int ch, ch1, tok, tok1; | 168 | int ch, ch1, tok, tok1; |
| 158 | CValue tokc, tok1c; | 169 | CValue tokc, tok1c; |
| 159 | | 170 | |
| @@ -185,14 +196,14 @@ int tok_ident; · 25 unmodified lines |
| 185 | TokenSym **table_ident; | 196 | TokenSym **table_ident; |
| 186 | TokenSym *hash_ident[TOK_HASH_SIZE]; | 197 | TokenSym *hash_ident[TOK_HASH_SIZE]; |
| 187 | char token_buf[STRING_MAX_SIZE + 1]; | 198 | char token_buf[STRING_MAX_SIZE + 1]; |
| 188 | char *filename, *funcname; | 199 | char *funcname; |
| 189 | /* contains global symbols which remain between each translation unit */ | 200 | /* contains global symbols which remain between each translation unit */ |
| 190 | SymStack extern_stack; | 201 | SymStack extern_stack; |
| 191 | SymStack define_stack, global_stack, local_stack, label_stack; | 202 | SymStack define_stack, global_stack, local_stack, label_stack; |
| 192 | | 203 | |
| 193 | SValue vstack[VSTACK_SIZE], *vtop; | 204 | SValue vstack[VSTACK_SIZE], *vtop; |
| 194 | int *macro_ptr, *macro_ptr_allocated; | 205 | int *macro_ptr, *macro_ptr_allocated; |
| 195 | IncludeFile include_stack[INCLUDE_STACK_SIZE], *include_stack_ptr; | 206 | BufferedFile *include_stack[INCLUDE_STACK_SIZE], **include_stack_ptr; |
| 196 | int ifdef_stack[IFDEF_STACK_SIZE], *ifdef_stack_ptr; | 207 | int ifdef_stack[IFDEF_STACK_SIZE], *ifdef_stack_ptr; |
| 197 | char *include_paths[INCLUDE_PATHS_MAX]; | 208 | char *include_paths[INCLUDE_PATHS_MAX]; |
| 198 | int nb_include_paths; | 209 | int nb_include_paths; |
| @@ -316,6 +327,8 @@ int tcc_ext = 1; · 117 unmodified lines |
| 316 | #define TOK_A_SHL 0x81 | 327 | #define TOK_A_SHL 0x81 |
| 317 | #define TOK_A_SAR 0x82 | 328 | #define TOK_A_SAR 0x82 |
| 318 | | 329 | |
| | 330 | #define TOK_EOF (-1) /* end of file */ |
| | 331 | |
| 319 | /* all identificators and strings have token above that */ | 332 | /* all identificators and strings have token above that */ |
| 320 | #define TOK_IDENT 256 | 333 | #define TOK_IDENT 256 |
| 321 | | 334 | |
| @@ -344,8 +357,10 @@ enum { · 22 unmodified lines |
| 344 | TOK_LONG, | 357 | TOK_LONG, |
| 345 | TOK_REGISTER, | 358 | TOK_REGISTER, |
| 346 | TOK_SIGNED, | 359 | TOK_SIGNED, |
| | 360 | TOK___SIGNED__, /* gcc keyword */ |
| 347 | TOK_AUTO, | 361 | TOK_AUTO, |
| 348 | TOK_INLINE, | 362 | TOK_INLINE, |
| | 363 | TOK___INLINE__, /* gcc keyword */ |
| 349 | TOK_RESTRICT, | 364 | TOK_RESTRICT, |
| 350 | | 365 | |
| 351 | /* unsupported type */ | 366 | /* unsupported type */ |
| @@ -392,9 +407,22 @@ enum { · 40 unmodified lines |
| 392 | TOK___UNUSED__, | 407 | TOK___UNUSED__, |
| 393 | }; | 408 | }; |
| 394 | | 409 | |
| | 410 | #ifdef WIN32 |
| | 411 | #define snprintf _snprintf |
| | 412 | /* currently incorrect */ |
| | 413 | long double strtold(const char *nptr, char **endptr) |
| | 414 | { |
| | 415 | return (long double)strtod(nptr, endptr); |
| | 416 | } |
| | 417 | float strtof(const char *nptr, char **endptr) |
| | 418 | { |
| | 419 | return (float)strtod(nptr, endptr); |
| | 420 | } |
| | 421 | #else |
| 395 | /* XXX: need to define this to use them in non ISOC99 context */ | 422 | /* XXX: need to define this to use them in non ISOC99 context */ |
| 396 | extern float strtof (const char *__nptr, char **__endptr); | 423 | extern float strtof (const char *__nptr, char **__endptr); |
| 397 | extern long double strtold (const char *__nptr, char **__endptr); | 424 | extern long double strtold (const char *__nptr, char **__endptr); |
| | 425 | #endif |
| 398 | | 426 | |
| 399 | void sum(int l); | 427 | void sum(int l); |
| 400 | void next(void); | 428 | void next(void); |
| @@ -495,7 +523,7 @@ static TCCSyms tcc_syms[] = { · 94 unmodified lines |
| 495 | { NULL, NULL }, | 523 | { NULL, NULL }, |
| 496 | }; | 524 | }; |
| 497 | | 525 | |
| 498 | void *dlsym(void *handle, char *symbol) | 526 | void *dlsym(void *handle, const char *symbol) |
| 499 | { | 527 | { |
| 500 | TCCSyms *p; | 528 | TCCSyms *p; |
| 501 | p = tcc_syms; | 529 | p = tcc_syms; |
| @@ -582,25 +610,27 @@ unsigned long long __ldtoull(long double a) · 80 unmodified lines |
| 582 | | 610 | |
| 583 | /********************************************************/ | 611 | /********************************************************/ |
| 584 | | 612 | |
| 585 | /* copy a string and truncate it */ | 613 | /* copy a string and truncate it. */ |
| 586 | char *pstrcpy(char *buf, int buf_size, const char *s) | 614 | char *pstrcpy(char *buf, int buf_size, const char *s) |
| 587 | { | 615 | { |
| 588 | char *q, *q_end; | 616 | char *q, *q_end; |
| 589 | int c; | 617 | int c; |
| 590 | | 618 | |
| 591 | q = buf; | 619 | if (buf_size > 0) { |
| 592 | q_end = buf + buf_size - 1; | 620 | q = buf; |
| 593 | while (q < q_end) { | 621 | q_end = buf + buf_size - 1; |
| 594 | c = *s++; | 622 | while (q < q_end) { |
| 595 | if (c == '\0') | 623 | c = *s++; |
| 596 | break; | 624 | if (c == '\0') |
| 597 | *q++ = c; | 625 | break; |
| | 626 | *q++ = c; |
| | 627 | } |
| | 628 | *q = '\0'; |
| 598 | } | 629 | } |
| 599 | *q = '\0'; | | |
| 600 | return buf; | 630 | return buf; |
| 601 | } | 631 | } |
| 602 | | 632 | |
| 603 | /* strcat and truncate */ | 633 | /* strcat and truncate. */ |
| 604 | char *pstrcat(char *buf, int buf_size, const char *s) | 634 | char *pstrcat(char *buf, int buf_size, const char *s) |
| 605 | { | 635 | { |
| 606 | int len; | 636 | int len; |
| @@ -624,12 +654,19 @@ Section *new_section(const char *name, int sh_type, int sh_flags) · 17 unmodified lines |
| 624 | sec->sh_num = ++section_num; | 654 | sec->sh_num = ++section_num; |
| 625 | sec->sh_type = sh_type; | 655 | sec->sh_type = sh_type; |
| 626 | sec->sh_flags = sh_flags; | 656 | sec->sh_flags = sh_flags; |
| | 657 | #ifdef WIN32 |
| | 658 | /* XXX: currently, a single malloc */ |
| | 659 | data = malloc(SECTION_VSIZE); |
| | 660 | if (data == NULL) |
| | 661 | error("could not alloc section '%s'", name); |
| | 662 | #else |
| 627 | data = mmap(NULL, SECTION_VSIZE, | 663 | data = mmap(NULL, SECTION_VSIZE, |
| 628 | PROT_EXEC | PROT_READ | PROT_WRITE, | 664 | PROT_EXEC | PROT_READ | PROT_WRITE, |
| 629 | MAP_PRIVATE | MAP_ANONYMOUS, | 665 | MAP_PRIVATE | MAP_ANONYMOUS, |
| 630 | -1, 0); | 666 | -1, 0); |
| 631 | if (data == (void *)(-1)) | 667 | if (data == (void *)(-1)) |
| 632 | error("could not mmap section '%s'", name); | 668 | error("could not mmap section '%s'", name); |
| | 669 | #endif |
| 633 | sec->data = data; | 670 | sec->data = data; |
| 634 | sec->data_ptr = data; | 671 | sec->data_ptr = data; |
| 635 | psec = &first_section; | 672 | psec = &first_section; |
| @@ -706,11 +743,11 @@ static inline int toup(int c) · 70 unmodified lines |
| 706 | | 743 | |
| 707 | void printline(void) | 744 | void printline(void) |
| 708 | { | 745 | { |
| 709 | IncludeFile *f; | 746 | BufferedFile **f; |
| 710 | for(f = include_stack; f < include_stack_ptr; f++) | 747 | for(f = include_stack; f < include_stack_ptr; f++) |
| 711 | fprintf(stderr, "In file included from %s:%d:\n", | 748 | fprintf(stderr, "In file included from %s:%d:\n", |
| 712 | f->filename, f->line_num); | 749 | (*f)->filename, (*f)->line_num); |
| 713 | fprintf(stderr, "%s:%d: ", filename, line_num); | 750 | fprintf(stderr, "%s:%d: ", file->filename, file->line_num); |
| 714 | } | 751 | } |
| 715 | | 752 | |
| 716 | void error(const char *fmt, ...) | 753 | void error(const char *fmt, ...) |
| @@ -976,39 +1013,94 @@ void sym_undef(SymStack *st, Sym *s) · 259 unmodified lines |
| 976 | s->v = 0; | 1013 | s->v = 0; |
| 977 | } | 1014 | } |
| 978 | | 1015 | |
| | 1016 | /* I/O layer */ |
| | 1017 | |
| | 1018 | BufferedFile *tcc_open(const char *filename) |
| | 1019 | { |
| | 1020 | int fd; |
| | 1021 | BufferedFile *bf; |
| | 1022 | |
| | 1023 | fd = open(filename, O_RDONLY); |
| | 1024 | if (fd < 0) |
| | 1025 | return NULL; |
| | 1026 | bf = malloc(sizeof(BufferedFile)); |
| | 1027 | if (!bf) { |
| | 1028 | close(fd); |
| | 1029 | return NULL; |
| | 1030 | } |
| | 1031 | bf->fd = fd; |
| | 1032 | bf->buf_ptr = bf->buffer; |
| | 1033 | bf->buf_end = bf->buffer; |
| | 1034 | bf->buffer[0] = CH_EOB; /* put eob symbol */ |
| | 1035 | pstrcpy(bf->filename, sizeof(bf->filename), filename); |
| | 1036 | bf->line_num = 1; |
| | 1037 | return bf; |
| | 1038 | } |
| | 1039 | |
| | 1040 | void tcc_close(BufferedFile *bf) |
| | 1041 | { |
| | 1042 | close(bf->fd); |
| | 1043 | free(bf); |
| | 1044 | } |
| | 1045 | |
| | 1046 | /* read one char. MUST call tcc_fillbuf if CH_EOB is read */ |
| | 1047 | #define TCC_GETC(bf) (*(bf)->buf_ptr++) |
| | 1048 | |
| | 1049 | /* fill input buffer and return next char */ |
| | 1050 | int tcc_getc_slow(BufferedFile *bf) |
| | 1051 | { |
| | 1052 | int len; |
| | 1053 | /* only tries to read if really end of buffer */ |
| | 1054 | if (bf->buf_ptr >= bf->buf_end) { |
| | 1055 | if (bf->fd != -1) { |
| | 1056 | len = read(bf->fd, bf->buffer, IO_BUF_SIZE); |
| | 1057 | if (len < 0) |
| | 1058 | len = 0; |
| | 1059 | } else { |
| | 1060 | len = 0; |
| | 1061 | } |
| | 1062 | bf->buf_ptr = bf->buffer; |
| | 1063 | bf->buf_end = bf->buffer + len; |
| | 1064 | *bf->buf_end = CH_EOB; |
| | 1065 | } |
| | 1066 | if (bf->buf_ptr < bf->buf_end) { |
| | 1067 | return *bf->buf_ptr++; |
| | 1068 | } else { |
| | 1069 | bf->buf_ptr = bf->buf_end; |
| | 1070 | return CH_EOF; |
| | 1071 | } |
| | 1072 | } |
| | 1073 | |
| 979 | /* no need to put that inline */ | 1074 | /* no need to put that inline */ |
| 980 | int handle_eof(void) | 1075 | void handle_eob(void) |
| 981 | { | 1076 | { |
| 982 | if (include_stack_ptr == include_stack) | 1077 | for(;;) { |
| 983 | return -1; | 1078 | ch1 = tcc_getc_slow(file); |
| 984 | /* add end of include file debug info */ | 1079 | if (ch1 != CH_EOF) |
| 985 | if (do_debug) { | 1080 | return; |
| 986 | put_stabd(N_EINCL, 0, 0); | 1081 | |
| | 1082 | if (include_stack_ptr == include_stack) |
| | 1083 | return; |
| | 1084 | /* add end of include file debug info */ |
| | 1085 | if (do_debug) { |
| | 1086 | put_stabd(N_EINCL, 0, 0); |
| | 1087 | } |
| | 1088 | /* pop include stack */ |
| | 1089 | tcc_close(file); |
| | 1090 | include_stack_ptr--; |
| | 1091 | file = *include_stack_ptr; |
| 987 | } | 1092 | } |
| 988 | /* pop include stack */ | | |
| 989 | fclose(file); | | |
| 990 | free(filename); | | |
| 991 | include_stack_ptr--; | | |
| 992 | file = include_stack_ptr->file; | | |
| 993 | filename = include_stack_ptr->filename; | | |
| 994 | line_num = include_stack_ptr->line_num; | | |
| 995 | return 0; | | |
| 996 | } | 1093 | } |
| 997 | | 1094 | |
| 998 | /* read next char from current input file */ | 1095 | /* read next char from current input file */ |
| 999 | static inline void inp(void) | 1096 | static inline void inp(void) |
| 1000 | { | 1097 | { |
| 1001 | redo: | 1098 | ch1 = TCC_GETC(file); |
| 1002 | /* faster than fgetc */ | 1099 | /* end of buffer/file handling */ |
| 1003 | ch1 = getc_unlocked(file); | 1100 | if (ch1 == CH_EOB) |
| 1004 | if (ch1 == -1) { | 1101 | handle_eob(); |
| 1005 | if (handle_eof() < 0) | | |
| 1006 | return; | | |
| 1007 | else | | |
| 1008 | goto redo; | | |
| 1009 | } | | |
| 1010 | if (ch1 == '\n') | 1102 | if (ch1 == '\n') |
| 1011 | line_num++; | 1103 | file->line_num++; |
| 1012 | // printf("ch1=%c 0x%x\n", ch1, ch1); | 1104 | // printf("ch1=%c 0x%x\n", ch1, ch1); |
| 1013 | } | 1105 | } |
| 1014 | | 1106 | |
| @@ -1219,7 +1311,7 @@ void preprocess(void) · 204 unmodified lines |
| 1219 | int size, i, c, v, t, *str, len; | 1311 | int size, i, c, v, t, *str, len; |
| 1220 | char buf[1024], *q, *p; | 1312 | char buf[1024], *q, *p; |
| 1221 | char buf1[1024]; | 1313 | char buf1[1024]; |
| 1222 | FILE *f; | 1314 | BufferedFile *f; |
| 1223 | Sym **ps, *first, *s; | 1315 | Sym **ps, *first, *s; |
| 1224 | | 1316 | |
| 1225 | cinp(); | 1317 | cinp(); |
| @@ -1304,15 +1396,15 @@ void preprocess(void) · 78 unmodified lines |
| 1304 | if (c == '\"') { | 1396 | if (c == '\"') { |
| 1305 | /* first search in current dir if "header.h" */ | 1397 | /* first search in current dir if "header.h" */ |
| 1306 | size = 0; | 1398 | size = 0; |
| 1307 | p = strrchr(filename, '/'); | 1399 | p = strrchr(file->filename, '/'); |
| 1308 | if (p) | 1400 | if (p) |
| 1309 | size = p + 1 - filename; | 1401 | size = p + 1 - file->filename; |
| 1310 | if (size > sizeof(buf1) - 1) | 1402 | if (size > sizeof(buf1) - 1) |
| 1311 | size = sizeof(buf1) - 1; | 1403 | size = sizeof(buf1) - 1; |
| 1312 | memcpy(buf1, filename, size); | 1404 | memcpy(buf1, file->filename, size); |
| 1313 | buf1[size] = '\0'; | 1405 | buf1[size] = '\0'; |
| 1314 | pstrcat(buf1, sizeof(buf1), buf); | 1406 | pstrcat(buf1, sizeof(buf1), buf); |
| 1315 | f = fopen(buf1, "r"); | 1407 | f = tcc_open(buf1); |
| 1316 | if (f) | 1408 | if (f) |
| 1317 | goto found; | 1409 | goto found; |
| 1318 | } | 1410 | } |
| @@ -1321,7 +1413,7 @@ void preprocess(void) · 2 unmodified lines |
| 1321 | strcpy(buf1, include_paths[i]); | 1413 | strcpy(buf1, include_paths[i]); |
| 1322 | strcat(buf1, "/"); | 1414 | strcat(buf1, "/"); |
| 1323 | strcat(buf1, buf); | 1415 | strcat(buf1, buf); |
| 1324 | f = fopen(buf1, "r"); | 1416 | f = tcc_open(buf1); |
| 1325 | if (f) | 1417 | if (f) |
| 1326 | goto found; | 1418 | goto found; |
| 1327 | } | 1419 | } |
| @@ -1330,16 +1422,11 @@ void preprocess(void) · 2 unmodified lines |
| 1330 | found: | 1422 | found: |
| 1331 | /* push current file in stack */ | 1423 | /* push current file in stack */ |
| 1332 | /* XXX: fix current line init */ | 1424 | /* XXX: fix current line init */ |
| 1333 | include_stack_ptr->file = file; | 1425 | *include_stack_ptr++ = file; |
| 1334 | include_stack_ptr->filename = filename; | | |
| 1335 | include_stack_ptr->line_num = line_num; | | |
| 1336 | include_stack_ptr++; | | |
| 1337 | file = f; | 1426 | file = f; |
| 1338 | filename = strdup(buf1); | | |
| 1339 | line_num = 1; | | |
| 1340 | /* add include file debug info */ | 1427 | /* add include file debug info */ |
| 1341 | if (do_debug) { | 1428 | if (do_debug) { |
| 1342 | put_stabs(filename, N_BINCL, 0, 0, 0); | 1429 | put_stabs(file->filename, N_BINCL, 0, 0, 0); |
| 1343 | } | 1430 | } |
| 1344 | } else if (tok == TOK_IFNDEF) { | 1431 | } else if (tok == TOK_IFNDEF) { |
| 1345 | c = 1; | 1432 | c = 1; |
| @@ -1382,14 +1469,14 @@ void preprocess(void) · 36 unmodified lines |
| 1382 | next(); | 1469 | next(); |
| 1383 | if (tok != TOK_CINT) | 1470 | if (tok != TOK_CINT) |
| 1384 | error("#line"); | 1471 | error("#line"); |
| 1385 | line_num = tokc.i; | 1472 | file->line_num = tokc.i; |
| 1386 | skip_spaces(); | 1473 | skip_spaces(); |
| 1387 | if (ch != '\n') { | 1474 | if (ch != '\n') { |
| 1388 | next(); | 1475 | next(); |
| 1389 | if (tok != TOK_STR) | 1476 | if (tok != TOK_STR) |
| 1390 | error("#line"); | 1477 | error("#line"); |
| 1391 | /* XXX: potential memory leak */ | 1478 | pstrcpy(file->filename, sizeof(file->filename), |
| 1392 | filename = strdup(get_tok_str(tok, &tokc)); | 1479 | get_tok_str(tok, &tokc)); |
| 1393 | } | 1480 | } |
| 1394 | } else if (tok == TOK_ERROR) { | 1481 | } else if (tok == TOK_ERROR) { |
| 1395 | error("#error"); | 1482 | error("#error"); |
| @@ -2025,10 +2112,10 @@ void macro_subst(int **tok_str, int *tok_len, · 629 unmodified lines |
| 2025 | break; | 2112 | break; |
| 2026 | /* special macros */ | 2113 | /* special macros */ |
| 2027 | if (tok == TOK___LINE__) { | 2114 | if (tok == TOK___LINE__) { |
| 2028 | cval.i = line_num; | 2115 | cval.i = file->line_num; |
| 2029 | tok_add2(tok_str, tok_len, TOK_CINT, &cval); | 2116 | tok_add2(tok_str, tok_len, TOK_CINT, &cval); |
| 2030 | } else if (tok == TOK___FILE__) { | 2117 | } else if (tok == TOK___FILE__) { |
| 2031 | cval.ts = tok_alloc(filename, 0); | 2118 | cval.ts = tok_alloc(file->filename, 0); |
| 2032 | tok_add2(tok_str, tok_len, TOK_STR, &cval); | 2119 | tok_add2(tok_str, tok_len, TOK_STR, &cval); |
| 2033 | } else if (tok == TOK___DATE__) { | 2120 | } else if (tok == TOK___DATE__) { |
| 2034 | cval.ts = tok_alloc("Jan 1 1970", 0); | 2121 | cval.ts = tok_alloc("Jan 1 1970", 0); |
| @@ -3912,8 +3999,10 @@ int parse_btype(int *type_ptr, AttributeDef *ad) · 1877 unmodified lines |
| 3912 | case TOK_VOLATILE: | 3999 | case TOK_VOLATILE: |
| 3913 | case TOK_REGISTER: | 4000 | case TOK_REGISTER: |
| 3914 | case TOK_SIGNED: | 4001 | case TOK_SIGNED: |
| | 4002 | case TOK___SIGNED__: |
| 3915 | case TOK_AUTO: | 4003 | case TOK_AUTO: |
| 3916 | case TOK_INLINE: | 4004 | case TOK_INLINE: |
| | 4005 | case TOK___INLINE__: |
| 3917 | case TOK_RESTRICT: | 4006 | case TOK_RESTRICT: |
| 3918 | next(); | 4007 | next(); |
| 3919 | break; | 4008 | break; |
| @@ -4665,10 +4754,10 @@ void block(int *bsym, int *csym, int *case_sym, int *def_sym, int case_reg) · 745 unmodified lines |
| 4665 | | 4754 | |
| 4666 | /* generate line number info */ | 4755 | /* generate line number info */ |
| 4667 | if (do_debug && | 4756 | if (do_debug && |
| 4668 | (last_line_num != line_num || last_ind != ind)) { | 4757 | (last_line_num != file->line_num || last_ind != ind)) { |
| 4669 | put_stabn(N_SLINE, 0, line_num, ind - func_ind); | 4758 | put_stabn(N_SLINE, 0, file->line_num, ind - func_ind); |
| 4670 | last_ind = ind; | 4759 | last_ind = ind; |
| 4671 | last_line_num = line_num; | 4760 | last_line_num = file->line_num; |
| 4672 | } | 4761 | } |
| 4673 | | 4762 | |
| 4674 | if (tok == TOK_IF) { | 4763 | if (tok == TOK_IF) { |
| @@ -5339,7 +5428,7 @@ void put_func_debug(int t) · 664 unmodified lines |
| 5339 | /* XXX: we put here a dummy type */ | 5428 | /* XXX: we put here a dummy type */ |
| 5340 | snprintf(buf, sizeof(buf), "%s:%c1", | 5429 | snprintf(buf, sizeof(buf), "%s:%c1", |
| 5341 | funcname, t & VT_STATIC ? 'f' : 'F'); | 5430 | funcname, t & VT_STATIC ? 'f' : 'F'); |
| 5342 | put_stabs(buf, N_FUN, 0, line_num, ind); | 5431 | put_stabs(buf, N_FUN, 0, file->line_num, ind); |
| 5343 | func_ind = ind; | 5432 | func_ind = ind; |
| 5344 | last_ind = 0; | 5433 | last_ind = 0; |
| 5345 | last_line_num = 0; | 5434 | last_line_num = 0; |
| @@ -5533,13 +5622,11 @@ int tcc_compile_file(const char *filename1) · 187 unmodified lines |
| 5533 | Sym *define_start; | 5622 | Sym *define_start; |
| 5534 | char buf[512]; | 5623 | char buf[512]; |
| 5535 | | 5624 | |
| 5536 | line_num = 1; | | |
| 5537 | funcname = ""; | 5625 | funcname = ""; |
| 5538 | filename = (char *)filename1; | | |
| 5539 | | 5626 | |
| 5540 | file = fopen(filename, "r"); | 5627 | file = tcc_open(filename1); |
| 5541 | if (!file) | 5628 | if (!file) |
| 5542 | error("file '%s' not found", filename); | 5629 | error("file '%s' not found", filename1); |
| 5543 | include_stack_ptr = include_stack; | 5630 | include_stack_ptr = include_stack; |
| 5544 | ifdef_stack_ptr = ifdef_stack; | 5631 | ifdef_stack_ptr = ifdef_stack; |
| 5545 | | 5632 | |
| @@ -5551,7 +5638,8 @@ int tcc_compile_file(const char *filename1) · 5 unmodified lines |
| 5551 | getcwd(buf, sizeof(buf)); | 5638 | getcwd(buf, sizeof(buf)); |
| 5552 | pstrcat(buf, sizeof(buf), "/"); | 5639 | pstrcat(buf, sizeof(buf), "/"); |
| 5553 | put_stabs(buf, N_SO, 0, 0, (unsigned long)text_section->data_ptr); | 5640 | put_stabs(buf, N_SO, 0, 0, (unsigned long)text_section->data_ptr); |
| 5554 | put_stabs(filename, N_SO, 0, 0, (unsigned long)text_section->data_ptr); | 5641 | put_stabs(file->filename, N_SO, 0, 0, |
| | 5642 | (unsigned long)text_section->data_ptr); |
| 5555 | } | 5643 | } |
| 5556 | /* define common 'char *' type because it is often used internally | 5644 | /* define common 'char *' type because it is often used internally |
| 5557 | for arrays and struct dereference */ | 5645 | for arrays and struct dereference */ |
| @@ -5564,7 +5652,7 @@ int tcc_compile_file(const char *filename1) · 6 unmodified lines |
| 5564 | decl(VT_CONST); | 5652 | decl(VT_CONST); |
| 5565 | if (tok != -1) | 5653 | if (tok != -1) |
| 5566 | expect("declaration"); | 5654 | expect("declaration"); |
| 5567 | fclose(file); | 5655 | tcc_close(file); |
| 5568 | | 5656 | |
| 5569 | /* end of translation unit info */ | 5657 | /* end of translation unit info */ |
| 5570 | if (do_debug) { | 5658 | if (do_debug) { |
| @@ -5993,6 +6081,7 @@ void rt_error(unsigned long pc, const char *fmt, ...) · 422 unmodified lines |
| 5993 | va_end(ap); | 6081 | va_end(ap); |
| 5994 | } | 6082 | } |
| 5995 | | 6083 | |
| | 6084 | #ifndef WIN32 |
| 5996 | /* signal handler for fatal errors */ | 6085 | /* signal handler for fatal errors */ |
| 5997 | static void sig_error(int signum, siginfo_t *siginf, void *puc) | 6086 | static void sig_error(int signum, siginfo_t *siginf, void *puc) |
| 5998 | { | 6087 | { |
| @@ -6033,19 +6122,23 @@ static void sig_error(int signum, siginfo_t *siginf, void *puc) · 34 unmodified lines |
| 6033 | } | 6122 | } |
| 6034 | exit(255); | 6123 | exit(255); |
| 6035 | } | 6124 | } |
| | 6125 | #endif |
| 6036 | | 6126 | |
| 6037 | /* launch the compiled program with the given arguments */ | 6127 | /* launch the compiled program with the given arguments */ |
| 6038 | int launch_exe(int argc, char **argv) | 6128 | int launch_exe(int argc, char **argv) |
| 6039 | { | 6129 | { |
| 6040 | Sym *s; | 6130 | Sym *s; |
| 6041 | int (*t)(); | 6131 | int (*t)(); |
| 6042 | struct sigaction sigact; | | |
| 6043 | | 6132 | |
| 6044 | s = sym_find1(&extern_stack, TOK_MAIN); | 6133 | s = sym_find1(&extern_stack, TOK_MAIN); |
| 6045 | if (!s || (s->r & VT_FORWARD)) | 6134 | if (!s || (s->r & VT_FORWARD)) |
| 6046 | error("main() not defined"); | 6135 | error("main() not defined"); |
| 6047 | | 6136 | |
| 6048 | if (do_debug) { | 6137 | if (do_debug) { |
| | 6138 | #ifdef WIN32 |
| | 6139 | error("debug mode currently not available for Windows"); |
| | 6140 | #else |
| | 6141 | struct sigaction sigact; |
| 6049 | /* install TCC signal handlers to print debug info on fatal | 6142 | /* install TCC signal handlers to print debug info on fatal |
| 6050 | runtime errors */ | 6143 | runtime errors */ |
| 6051 | sigact.sa_flags = SA_SIGINFO | SA_ONESHOT; | 6144 | sigact.sa_flags = SA_SIGINFO | SA_ONESHOT; |
| @@ -6056,9 +6149,13 @@ int launch_exe(int argc, char **argv) · 4 unmodified lines |
| 6056 | sigaction(SIGSEGV, &sigact, NULL); | 6149 | sigaction(SIGSEGV, &sigact, NULL); |
| 6057 | sigaction(SIGBUS, &sigact, NULL); | 6150 | sigaction(SIGBUS, &sigact, NULL); |
| 6058 | sigaction(SIGABRT, &sigact, NULL); | 6151 | sigaction(SIGABRT, &sigact, NULL); |
| | 6152 | #endif |
| 6059 | } | 6153 | } |
| 6060 | | 6154 | |
| 6061 | if (do_bounds_check) { | 6155 | if (do_bounds_check) { |
| | 6156 | #ifdef WIN32 |
| | 6157 | error("bound checking currently not available for Windows"); |
| | 6158 | #else |
| 6062 | int *p, *p_end; | 6159 | int *p, *p_end; |
| 6063 | __bound_init(); | 6160 | __bound_init(); |
| 6064 | /* add all known static regions */ | 6161 | /* add all known static regions */ |
| @@ -6068,6 +6165,7 @@ int launch_exe(int argc, char **argv) · 3 unmodified lines |
| 6068 | __bound_new_region((void *)p[0], p[1]); | 6165 | __bound_new_region((void *)p[0], p[1]); |
| 6069 | p += 2; | 6166 | p += 2; |
| 6070 | } | 6167 | } |
| | 6168 | #endif |
| 6071 | } | 6169 | } |
| 6072 | | 6170 | |
| 6073 | t = (int (*)())s->c; | 6171 | t = (int (*)())s->c; |
| @@ -6077,7 +6175,7 @@ int launch_exe(int argc, char **argv) · 3 unmodified lines |
| 6077 | | 6175 | |
| 6078 | void help(void) | 6176 | void help(void) |
| 6079 | { | 6177 | { |
| 6080 | printf("tcc version 0.9.3 - Tiny C Compiler - Copyright (C) 2001, 2002 Fabrice Bellard\n" | 6178 | printf("tcc version 0.9.4 - Tiny C Compiler - Copyright (C) 2001, 2002 Fabrice Bellard\n" |
| 6081 | "usage: tcc [-Idir] [-Dsym[=val]] [-Usym] [-llib] [-g] [-b]\n" | 6179 | "usage: tcc [-Idir] [-Dsym[=val]] [-Usym] [-llib] [-g] [-b]\n" |
| 6082 | " [-i infile] infile [infile_args...]\n" | 6180 | " [-i infile] infile [infile_args...]\n" |
| 6083 | "\n" | 6181 | "\n" |
| @@ -6103,7 +6201,7 @@ int main(int argc, char **argv) · 19 unmodified lines |
| 6103 | | 6201 | |
| 6104 | /* add all tokens */ | 6202 | /* add all tokens */ |
| 6105 | tok_ident = TOK_IDENT; | 6203 | tok_ident = TOK_IDENT; |
| 6106 | 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\0_Bool\0short\0struct\0union\0typedef\0default\0enum\0sizeof\0__attribute__\0define\0include\0ifdef\0ifndef\0elif\0endif\0defined\0undef\0error\0line\0__LINE__\0__FILE__\0__DATE__\0__TIME__\0__VA_ARGS__\0__func__\0main\0section\0__section__\0aligned\0__aligned__\0unused\0__unused__\0"; | 6204 | p = "int\0void\0char\0if\0else\0while\0break\0return\0for\0extern\0static\0unsigned\0goto\0do\0continue\0switch\0case\0const\0volatile\0long\0register\0signed\0__signed__\0auto\0inline\0__inline__\0restrict\0float\0double\0_Bool\0short\0struct\0union\0typedef\0default\0enum\0sizeof\0__attribute__\0define\0include\0ifdef\0ifndef\0elif\0endif\0defined\0undef\0error\0line\0__LINE__\0__FILE__\0__DATE__\0__TIME__\0__VA_ARGS__\0__func__\0main\0section\0__section__\0aligned\0__aligned__\0unused\0__unused__\0"; |
| 6107 | while (*p) { | 6205 | while (*p) { |
| 6108 | r = p; | 6206 | r = p; |
| 6109 | while (*r++); | 6207 | while (*r++); |