| @@ -81,7 +81,7 @@ static void type_decl(CType *type, AttributeDef *ad, int *v, int td); · 80 unmodified lines |
| 81 | static void parse_expr_type(CType *type); | 81 | static void parse_expr_type(CType *type); |
| 82 | static void decl_initializer(CType *type, Section *sec, unsigned long c, int first, int size_only); | 82 | static void decl_initializer(CType *type, Section *sec, unsigned long c, int first, int size_only); |
| 83 | static void block(int *bsym, int *csym, int *case_sym, int *def_sym, int case_reg, int is_expr); | 83 | static void block(int *bsym, int *csym, int *case_sym, int *def_sym, int case_reg, int is_expr); |
| 84 | static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, int has_init, int v, char *asm_label, int scope); | 84 | static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, int has_init, int v, int scope); |
| 85 | static int decl0(int l, int is_for_loop_init); | 85 | static int decl0(int l, int is_for_loop_init); |
| 86 | static void expr_eq(void); | 86 | static void expr_eq(void); |
| 87 | static void unary_type(CType *type); | 87 | static void unary_type(CType *type); |
| @@ -158,7 +158,6 @@ static inline Sym *sym_malloc(void) · 70 unmodified lines |
| 158 | ST_INLN void sym_free(Sym *sym) | 158 | ST_INLN void sym_free(Sym *sym) |
| 159 | { | 159 | { |
| 160 | sym->next = sym_free_first; | 160 | sym->next = sym_free_first; |
| 161 | tcc_free(sym->asm_label); | | |
| 162 | sym_free_first = sym; | 161 | sym_free_first = sym; |
| 163 | } | 162 | } |
| 164 | | 163 | |
| @@ -173,7 +172,7 @@ ST_FUNC Sym *sym_push2(Sym **ps, int v, int t, long c) · 8 unmodified lines |
| 173 | get_tok_str(v, NULL)); | 172 | get_tok_str(v, NULL)); |
| 174 | } | 173 | } |
| 175 | s = sym_malloc(); | 174 | s = sym_malloc(); |
| 176 | s->asm_label = NULL; | 175 | s->asm_label = 0; |
| 177 | s->v = v; | 176 | s->v = v; |
| 178 | s->type.t = t; | 177 | s->type.t = t; |
| 179 | s->type.ref = NULL; | 178 | s->type.ref = NULL; |
| @@ -443,10 +442,8 @@ ST_FUNC Sym *external_global_sym(int v, CType *type, int r) · 263 unmodified lines |
| 443 | return s; | 442 | return s; |
| 444 | } | 443 | } |
| 445 | | 444 | |
| 446 | /* define a new external reference to a symbol 'v' with alternate asm | 445 | /* define a new external reference to a symbol 'v' */ |
| 447 | name 'asm_label' of type 'u'. 'asm_label' is equal to NULL if there | 446 | static Sym *external_sym(int v, CType *type, int r) |
| 448 | is no alternate name (most cases) */ | | |
| 449 | static Sym *external_sym(int v, CType *type, int r, char *asm_label) | | |
| 450 | { | 447 | { |
| 451 | Sym *s; | 448 | Sym *s; |
| 452 | | 449 | |
| @@ -454,7 +451,6 @@ static Sym *external_sym(int v, CType *type, int r, char *asm_label) · 1 unmodified line |
| 454 | if (!s) { | 451 | if (!s) { |
| 455 | /* push forward reference */ | 452 | /* push forward reference */ |
| 456 | s = sym_push(v, type, r | VT_CONST | VT_SYM, 0); | 453 | s = sym_push(v, type, r | VT_CONST | VT_SYM, 0); |
| 457 | s->asm_label = asm_label ? tcc_strdup(asm_label) : 0; | | |
| 458 | s->type.t |= VT_EXTERN; | 454 | s->type.t |= VT_EXTERN; |
| 459 | } else if (s->type.ref == func_old_type.ref) { | 455 | } else if (s->type.ref == func_old_type.ref) { |
| 460 | s->type.ref = type->ref; | 456 | s->type.ref = type->ref; |
| @@ -3386,16 +3382,21 @@ ST_FUNC void parse_asm_str(CString *astr) · 2925 unmodified lines |
| 3386 | cstr_ccat(astr, '\0'); | 3382 | cstr_ccat(astr, '\0'); |
| 3387 | } | 3383 | } |
| 3388 | | 3384 | |
| 3389 | /* Parse an asm label and return the label | 3385 | /* Parse an asm label and return the token */ |
| 3390 | * Don't forget to free the CString in the caller! */ | 3386 | static int asm_label_instr(void) |
| 3391 | static void asm_label_instr(CString *astr) | | |
| 3392 | { | 3387 | { |
| | 3388 | int v; |
| | 3389 | CString astr; |
| | 3390 | |
| 3393 | next(); | 3391 | next(); |
| 3394 | parse_asm_str(astr); | 3392 | parse_asm_str(&astr); |
| 3395 | skip(')'); | 3393 | skip(')'); |
| 3396 | #ifdef ASM_DEBUG | 3394 | #ifdef ASM_DEBUG |
| 3397 | printf("asm_alias: \"%s\"\n", (char *)astr->data); | 3395 | printf("asm_alias: \"%s\"\n", (char *)astr.data); |
| 3398 | #endif | 3396 | #endif |
| | 3397 | v = tok_alloc(astr.data, astr.size - 1)->tok; |
| | 3398 | cstr_free(&astr); |
| | 3399 | return v; |
| 3399 | } | 3400 | } |
| 3400 | | 3401 | |
| 3401 | static void post_type(CType *type, AttributeDef *ad) | 3402 | static void post_type(CType *type, AttributeDef *ad) |
| @@ -3801,7 +3802,7 @@ ST_FUNC void unary(void) · 399 unmodified lines |
| 3801 | mk_pointer(&type); | 3802 | mk_pointer(&type); |
| 3802 | type.t |= VT_ARRAY; | 3803 | type.t |= VT_ARRAY; |
| 3803 | memset(&ad, 0, sizeof(AttributeDef)); | 3804 | memset(&ad, 0, sizeof(AttributeDef)); |
| 3804 | decl_initializer_alloc(&type, &ad, VT_CONST, 2, 0, NULL, 0); | 3805 | decl_initializer_alloc(&type, &ad, VT_CONST, 2, 0, 0); |
| 3805 | break; | 3806 | break; |
| 3806 | case '(': | 3807 | case '(': |
| 3807 | next(); | 3808 | next(); |
| @@ -3820,7 +3821,7 @@ ST_FUNC void unary(void) · 12 unmodified lines |
| 3820 | if (!(type.t & VT_ARRAY)) | 3821 | if (!(type.t & VT_ARRAY)) |
| 3821 | r |= lvalue_type(type.t); | 3822 | r |= lvalue_type(type.t); |
| 3822 | memset(&ad, 0, sizeof(AttributeDef)); | 3823 | memset(&ad, 0, sizeof(AttributeDef)); |
| 3823 | decl_initializer_alloc(&type, &ad, r, 1, 0, NULL, 0); | 3824 | decl_initializer_alloc(&type, &ad, r, 1, 0, 0); |
| 3824 | } else { | 3825 | } else { |
| 3825 | if (sizeof_caller) { | 3826 | if (sizeof_caller) { |
| 3826 | vpush(&type); | 3827 | vpush(&type); |
| @@ -4199,7 +4200,7 @@ ST_FUNC void unary(void) · 372 unmodified lines |
| 4199 | break; | 4200 | break; |
| 4200 | } | 4201 | } |
| 4201 | if (!s) | 4202 | if (!s) |
| 4202 | tcc_error("field not found: %s", get_tok_str(tok & ~SYM_FIELD, NULL)); | 4203 | tcc_error("field not found: %s", get_tok_str(tok & ~SYM_FIELD, &tokc)); |
| 4203 | /* add field offset to pointer */ | 4204 | /* add field offset to pointer */ |
| 4204 | vtop->type = char_pointer_type; /* change type to 'char *' */ | 4205 | vtop->type = char_pointer_type; /* change type to 'char *' */ |
| 4205 | vpushi(s->c); | 4206 | vpushi(s->c); |
| @@ -5742,14 +5743,12 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c, · 1536 unmodified lines |
| 5742 | /* parse an initializer for type 't' if 'has_init' is non zero, and | 5743 | /* parse an initializer for type 't' if 'has_init' is non zero, and |
| 5743 | allocate space in local or global data space ('r' is either | 5744 | allocate space in local or global data space ('r' is either |
| 5744 | VT_LOCAL or VT_CONST). If 'v' is non zero, then an associated | 5745 | VT_LOCAL or VT_CONST). If 'v' is non zero, then an associated |
| 5745 | variable 'v' with an associated name represented by 'asm_label' of | 5746 | variable 'v' of scope 'scope' is declared before initializers |
| 5746 | scope 'scope' is declared before initializers are parsed. If 'v' is | 5747 | are parsed. If 'v' is zero, then a reference to the new object |
| 5747 | zero, then a reference to the new object is put in the value stack. | 5748 | is put in the value stack. If 'has_init' is 2, a special parsing |
| 5748 | If 'has_init' is 2, a special parsing is done to handle string | 5749 | is done to handle string constants. */ |
| 5749 | constants. */ | | |
| 5750 | static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, | 5750 | static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, |
| 5751 | int has_init, int v, char *asm_label, | 5751 | int has_init, int v, int scope) |
| 5752 | int scope) | | |
| 5753 | { | 5752 | { |
| 5754 | int size, align, addr, data_offset; | 5753 | int size, align, addr, data_offset; |
| 5755 | int level; | 5754 | int level; |
| @@ -5931,7 +5930,7 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, · 175 unmodified lines |
| 5931 | if (v) { | 5930 | if (v) { |
| 5932 | if (scope != VT_CONST || !sym) { | 5931 | if (scope != VT_CONST || !sym) { |
| 5933 | sym = sym_push(v, type, r | VT_SYM, 0); | 5932 | sym = sym_push(v, type, r | VT_SYM, 0); |
| 5934 | sym->asm_label = asm_label ? tcc_strdup(asm_label) : 0; | 5933 | sym->asm_label = ad->asm_label; |
| 5935 | } | 5934 | } |
| 5936 | /* update symbol definition */ | 5935 | /* update symbol definition */ |
| 5937 | if (sec) { | 5936 | if (sec) { |
| @@ -6162,7 +6161,6 @@ static int decl0(int l, int is_for_loop_init) · 224 unmodified lines |
| 6162 | CType type, btype; | 6161 | CType type, btype; |
| 6163 | Sym *sym; | 6162 | Sym *sym; |
| 6164 | AttributeDef ad; | 6163 | AttributeDef ad; |
| 6165 | char *asm_label = 0; // associated asm label | | |
| 6166 | | 6164 | |
| 6167 | while (1) { | 6165 | while (1) { |
| 6168 | if (!parse_btype(&btype, &ad)) { | 6166 | if (!parse_btype(&btype, &ad)) { |
| @@ -6218,17 +6216,12 @@ static int decl0(int l, int is_for_loop_init) · 49 unmodified lines |
| 6218 | func_decl_list(sym); | 6216 | func_decl_list(sym); |
| 6219 | } | 6217 | } |
| 6220 | | 6218 | |
| 6221 | tcc_free(asm_label); | | |
| 6222 | asm_label = 0; | | |
| 6223 | if (gnu_ext && (tok == TOK_ASM1 || tok == TOK_ASM2 || tok == TOK_ASM3)) { | 6219 | if (gnu_ext && (tok == TOK_ASM1 || tok == TOK_ASM2 || tok == TOK_ASM3)) { |
| 6224 | CString astr; | 6220 | ad.asm_label = asm_label_instr(); |
| 6225 | | | |
| 6226 | asm_label_instr(&astr); | | |
| 6227 | asm_label = tcc_strdup(astr.data); | | |
| 6228 | cstr_free(&astr); | | |
| 6229 | | | |
| 6230 | /* parse one last attribute list, after asm label */ | 6221 | /* parse one last attribute list, after asm label */ |
| 6231 | parse_attribute(&ad); | 6222 | parse_attribute(&ad); |
| | 6223 | if (tok == '{') |
| | 6224 | expect(";"); |
| 6232 | } | 6225 | } |
| 6233 | | 6226 | |
| 6234 | if (ad.a.weak) | 6227 | if (ad.a.weak) |
| @@ -6371,7 +6364,8 @@ static int decl0(int l, int is_for_loop_init) · 136 unmodified lines |
| 6371 | /* NOTE: as GCC, uninitialized global static | 6364 | /* NOTE: as GCC, uninitialized global static |
| 6372 | arrays of null size are considered as | 6365 | arrays of null size are considered as |
| 6373 | extern */ | 6366 | extern */ |
| 6374 | sym = external_sym(v, &type, r, asm_label); | 6367 | sym = external_sym(v, &type, r); |
| | 6368 | sym->asm_label = ad.asm_label; |
| 6375 | | 6369 | |
| 6376 | if (ad.alias_target) { | 6370 | if (ad.alias_target) { |
| 6377 | Section tsec; | 6371 | Section tsec; |
| @@ -6393,14 +6387,12 @@ static int decl0(int l, int is_for_loop_init) · 15 unmodified lines |
| 6393 | r |= l; | 6387 | r |= l; |
| 6394 | if (has_init) | 6388 | if (has_init) |
| 6395 | next(); | 6389 | next(); |
| 6396 | decl_initializer_alloc(&type, &ad, r, has_init, v, asm_label, l); | 6390 | decl_initializer_alloc(&type, &ad, r, has_init, v, l); |
| 6397 | } | 6391 | } |
| 6398 | } | 6392 | } |
| 6399 | if (tok != ',') { | 6393 | if (tok != ',') { |
| 6400 | if (is_for_loop_init) { | 6394 | if (is_for_loop_init) |
| 6401 | tcc_free(asm_label); | | |
| 6402 | return 1; | 6395 | return 1; |
| 6403 | } | | |
| 6404 | skip(';'); | 6396 | skip(';'); |
| 6405 | break; | 6397 | break; |
| 6406 | } | 6398 | } |
| @@ -6409,7 +6401,6 @@ static int decl0(int l, int is_for_loop_init) · 2 unmodified lines |
| 6409 | ad.a.aligned = 0; | 6401 | ad.a.aligned = 0; |
| 6410 | } | 6402 | } |
| 6411 | } | 6403 | } |
| 6412 | tcc_free(asm_label); | | |
| 6413 | return 0; | 6404 | return 0; |
| 6414 | } | 6405 | } |
| 6415 | | 6406 | |