Unified · Split
| @@ -587,7 +587,7 @@ static Sym *sym_find(int v); · 586 unmodified lines | |||
| 587 | static Sym *sym_push(int v, CType *type, int r, int c); | 587 | static Sym *sym_push(int v, CType *type, int r, int c); |
| 588 | 588 | ||
| 589 | /* type handling */ | 589 | /* type handling */ |
| 590 | int type_size(CType *type, int *a); | 590 | static int type_size(CType *type, int *a); |
| 591 | static inline CType *pointed_type(CType *type); | 591 | static inline CType *pointed_type(CType *type); |
| 592 | static int pointed_size(CType *type); | 592 | static int pointed_size(CType *type); |
| 593 | static int lvalue_type(int t); | 593 | static int lvalue_type(int t); |
| @@ -2554,6 +2554,9 @@ static void preprocess(int is_bof) · 1960 unmodified lines | |||
| 2554 | else | 2554 | else |
| 2555 | warning("#warning %s", buf); | 2555 | warning("#warning %s", buf); |
| 2556 | break; | 2556 | break; |
| 2557 | case TOK_PRAGMA: | ||
| 2558 | /* ignored */ | ||
| 2559 | break; | ||
| 2557 | default: | 2560 | default: |
| 2558 | if (tok == TOK_LINEFEED || tok == '!' || tok == TOK_CINT) { | 2561 | if (tok == TOK_LINEFEED || tok == '!' || tok == TOK_CINT) { |
| 2559 | /* '!' is ignored to allow C scripts. numbers are ignored | 2562 | /* '!' is ignored to allow C scripts. numbers are ignored |
| @@ -5154,7 +5157,7 @@ static void gen_cast(CType *type) · 2594 unmodified lines | |||
| 5154 | } | 5157 | } |
| 5155 | 5158 | ||
| 5156 | /* return type size. Put alignment at 'a' */ | 5159 | /* return type size. Put alignment at 'a' */ |
| 5157 | int type_size(CType *type, int *a) | 5160 | static int type_size(CType *type, int *a) |
| 5158 | { | 5161 | { |
| 5159 | Sym *s; | 5162 | Sym *s; |
| 5160 | int bt; | 5163 | int bt; |
| @@ -5163,7 +5166,7 @@ int type_size(CType *type, int *a) · 2 unmodified lines | |||
| 5163 | if (bt == VT_STRUCT) { | 5166 | if (bt == VT_STRUCT) { |
| 5164 | /* struct/union */ | 5167 | /* struct/union */ |
| 5165 | s = type->ref; | 5168 | s = type->ref; |
| 5166 | *a = 4; /* XXX: cannot store it yet. Doing that is safe */ | 5169 | *a = s->r; |
| 5167 | return s->c; | 5170 | return s->c; |
| 5168 | } else if (bt == VT_PTR) { | 5171 | } else if (bt == VT_PTR) { |
| 5169 | if (type->t & VT_ARRAY) { | 5172 | if (type->t & VT_ARRAY) { |
| @@ -5177,7 +5180,7 @@ int type_size(CType *type, int *a) · 7 unmodified lines | |||
| 5177 | *a = LDOUBLE_ALIGN; | 5180 | *a = LDOUBLE_ALIGN; |
| 5178 | return LDOUBLE_SIZE; | 5181 | return LDOUBLE_SIZE; |
| 5179 | } else if (bt == VT_DOUBLE || bt == VT_LLONG) { | 5182 | } else if (bt == VT_DOUBLE || bt == VT_LLONG) { |
| 5180 | *a = 8; | 5183 | *a = 4; /* XXX: i386 specific */ |
| 5181 | return 8; | 5184 | return 8; |
| 5182 | } else if (bt == VT_INT || bt == VT_ENUM || bt == VT_FLOAT) { | 5185 | } else if (bt == VT_INT || bt == VT_ENUM || bt == VT_FLOAT) { |
| 5183 | *a = 4; | 5186 | *a = 4; |
| @@ -5634,12 +5637,9 @@ static void struct_decl(CType *type, int u) · 450 unmodified lines | |||
| 5634 | error("struct/union/enum already defined"); | 5637 | error("struct/union/enum already defined"); |
| 5635 | /* cannot be empty */ | 5638 | /* cannot be empty */ |
| 5636 | c = 0; | 5639 | c = 0; |
| 5637 | maxalign = 0; | 5640 | /* non empty enums are not allowed */ |
| 5638 | ps = &s->next; | 5641 | if (a == TOK_ENUM) { |
| 5639 | bit_pos = 0; | 5642 | for(;;) { |
| 5640 | offset = 0; | ||
| 5641 | while (1) { | ||
| 5642 | if (a == TOK_ENUM) { | ||
| 5643 | v = tok; | 5643 | v = tok; |
| 5644 | next(); | 5644 | next(); |
| 5645 | if (tok == '=') { | 5645 | if (tok == '=') { |
| @@ -5652,7 +5652,16 @@ static void struct_decl(CType *type, int u) · 6 unmodified lines | |||
| 5652 | if (tok == ',') | 5652 | if (tok == ',') |
| 5653 | next(); | 5653 | next(); |
| 5654 | c++; | 5654 | c++; |
| 5655 | } else { | 5655 | if (tok == '}') |
| 5656 | break; | ||
| 5657 | } | ||
| 5658 | skip('}'); | ||
| 5659 | } else { | ||
| 5660 | maxalign = 1; | ||
| 5661 | ps = &s->next; | ||
| 5662 | bit_pos = 0; | ||
| 5663 | offset = 0; | ||
| 5664 | while (tok != '}') { | ||
| 5656 | parse_btype(&btype, &ad); | 5665 | parse_btype(&btype, &ad); |
| 5657 | while (1) { | 5666 | while (1) { |
| 5658 | bit_size = -1; | 5667 | bit_size = -1; |
| @@ -5682,7 +5691,8 @@ static void struct_decl(CType *type, int u) · 23 unmodified lines | |||
| 5682 | bt = type1.t & VT_BTYPE; | 5691 | bt = type1.t & VT_BTYPE; |
| 5683 | if (bt != VT_INT && | 5692 | if (bt != VT_INT && |
| 5684 | bt != VT_BYTE && | 5693 | bt != VT_BYTE && |
| 5685 | bt != VT_SHORT) | 5694 | bt != VT_SHORT && |
| 5695 | bt != VT_ENUM) | ||
| 5686 | error("bitfields must have scalar type"); | 5696 | error("bitfields must have scalar type"); |
| 5687 | bsize = size * 8; | 5697 | bsize = size * 8; |
| 5688 | if (bit_size > bsize) { | 5698 | if (bit_size > bsize) { |
| @@ -5741,18 +5751,17 @@ static void struct_decl(CType *type, int u) · 52 unmodified lines | |||
| 5741 | *ps = ss; | 5751 | *ps = ss; |
| 5742 | ps = &ss->next; | 5752 | ps = &ss->next; |
| 5743 | } | 5753 | } |
| 5744 | if (tok == ';' || tok == -1) | 5754 | if (tok == ';' || tok == TOK_EOF) |
| 5745 | break; | 5755 | break; |
| 5746 | skip(','); | 5756 | skip(','); |
| 5747 | } | 5757 | } |
| 5748 | skip(';'); | 5758 | skip(';'); |
| 5749 | } | 5759 | } |
| 5750 | if (tok == '}') | 5760 | skip('}'); |
| 5751 | break; | 5761 | /* store size and alignment */ |
| 5762 | s->c = (c + maxalign - 1) & -maxalign; | ||
| 5763 | s->r = maxalign; | ||
| 5752 | } | 5764 | } |
| 5753 | skip('}'); | ||
| 5754 | /* size for struct/union, dummy for enum */ | ||
| 5755 | s->c = (c + maxalign - 1) & -maxalign; | ||
| 5756 | } | 5765 | } |
| 5757 | } | 5766 | } |
| 5758 | 5767 | ||
| @@ -6653,18 +6662,17 @@ static void expr_land(void) · 894 unmodified lines | |||
| 6653 | int t; | 6662 | int t; |
| 6654 | 6663 | ||
| 6655 | expr_or(); | 6664 | expr_or(); |
| 6656 | t = 0; | 6665 | if (tok == TOK_LAND) { |
| 6657 | while (1) { | 6666 | t = 0; |
| 6658 | if (tok != TOK_LAND) { | 6667 | for(;;) { |
| 6659 | if (t) { | 6668 | t = gtst(1, t); |
| 6660 | t = gtst(1, t); | 6669 | if (tok != TOK_LAND) { |
| 6661 | vseti(VT_JMPI, t); | 6670 | vseti(VT_JMPI, t); |
| 6671 | break; | ||
| 6662 | } | 6672 | } |
| 6663 | break; | 6673 | next(); |
| 6674 | expr_or(); | ||
| 6664 | } | 6675 | } |
| 6665 | t = gtst(1, t); | ||
| 6666 | next(); | ||
| 6667 | expr_or(); | ||
| 6668 | } | 6676 | } |
| 6669 | } | 6677 | } |
| 6670 | 6678 | ||
| @@ -6673,18 +6681,17 @@ static void expr_lor(void) · 2 unmodified lines | |||
| 6673 | int t; | 6681 | int t; |
| 6674 | 6682 | ||
| 6675 | expr_land(); | 6683 | expr_land(); |
| 6676 | t = 0; | 6684 | if (tok == TOK_LOR) { |
| 6677 | while (1) { | 6685 | t = 0; |
| 6678 | if (tok != TOK_LOR) { | 6686 | for(;;) { |
| 6679 | if (t) { | 6687 | t = gtst(0, t); |
| 6680 | t = gtst(0, t); | 6688 | if (tok != TOK_LOR) { |
| 6681 | vseti(VT_JMP, t); | 6689 | vseti(VT_JMP, t); |
| 6690 | break; | ||
| 6682 | } | 6691 | } |
| 6683 | break; | 6692 | next(); |
| 6693 | expr_land(); | ||
| 6684 | } | 6694 | } |
| 6685 | t = gtst(0, t); | ||
| 6686 | next(); | ||
| 6687 | expr_land(); | ||
| 6688 | } | 6695 | } |
| 6689 | } | 6696 | } |
| 6690 | 6697 | ||
| @@ -6714,8 +6721,16 @@ static void expr_eq(void) · 23 unmodified lines | |||
| 6714 | expr_lor(); | 6721 | expr_lor(); |
| 6715 | if (tok == '?') { | 6722 | if (tok == '?') { |
| 6716 | next(); | 6723 | next(); |
| 6717 | save_regs(1); /* we need to save all registers here except | 6724 | if (vtop != vstack) { |
| 6718 | at the top because it is a branch point */ | 6725 | /* needed to avoid having different registers saved in |
| 6726 | each branch */ | ||
| 6727 | if (is_float(vtop->type.t)) | ||
| 6728 | rc = RC_FLOAT; | ||
| 6729 | else | ||
| 6730 | rc = RC_INT; | ||
| 6731 | gv(rc); | ||
| 6732 | save_regs(1); | ||
| 6733 | } | ||
| 6719 | tt = gtst(1, 0); | 6734 | tt = gtst(1, 0); |
| 6720 | gexpr(); | 6735 | gexpr(); |
| 6721 | type1 = vtop->type; | 6736 | type1 = vtop->type; |
| @@ -6723,7 +6738,6 @@ static void expr_eq(void) · 1 unmodified line | |||
| 6723 | vtop--; /* no vpop so that FP stack is not flushed */ | 6738 | vtop--; /* no vpop so that FP stack is not flushed */ |
| 6724 | skip(':'); | 6739 | skip(':'); |
| 6725 | u = gjmp(0); | 6740 | u = gjmp(0); |
| 6726 | |||
| 6727 | gsym(tt); | 6741 | gsym(tt); |
| 6728 | expr_eq(); | 6742 | expr_eq(); |
| 6729 | type2 = vtop->type; | 6743 | type2 = vtop->type; |
| @@ -6776,6 +6790,7 @@ static void expr_eq(void) · 46 unmodified lines | |||
| 6776 | to handle a complicated move */ | 6790 | to handle a complicated move */ |
| 6777 | rc = RC_IRET; | 6791 | rc = RC_IRET; |
| 6778 | } | 6792 | } |
| 6793 | |||
| 6779 | r2 = gv(rc); | 6794 | r2 = gv(rc); |
| 6780 | /* this is horrible, but we must also convert first | 6795 | /* this is horrible, but we must also convert first |
| 6781 | operand */ | 6796 | operand */ |
| @@ -8509,6 +8524,11 @@ TCCState *tcc_new(void) · 1727 unmodified lines | |||
| 8509 | #endif | 8524 | #endif |
| 8510 | /* tiny C specific defines */ | 8525 | /* tiny C specific defines */ |
| 8511 | tcc_define_symbol(s, "__TINYC__", NULL); | 8526 | tcc_define_symbol(s, "__TINYC__", NULL); |
| 8527 | |||
| 8528 | /* tiny C & gcc defines */ | ||
| 8529 | tcc_define_symbol(s, "__SIZE_TYPE__", "unsigned int"); | ||
| 8530 | tcc_define_symbol(s, "__PTRDIFF_TYPE__", "int"); | ||
| 8531 | tcc_define_symbol(s, "__WCHAR_TYPE__", "int"); | ||
| 8512 | 8532 | ||
| 8513 | /* default library paths */ | 8533 | /* default library paths */ |
| 8514 | tcc_add_library_path(s, "/usr/local/lib"); | 8534 | tcc_add_library_path(s, "/usr/local/lib"); |