History

Add support of asm label for variables.

Add support for asm labels for variables, that is the ability to rename a variable at assembly level with __asm__ ("newname") appended in its declaration. See http://gcc.gnu.org/onlinedocs/gcc-4.4.4/gcc/Asm-Labels.html for more details.

Thomas Preud'homme committed 15 years ago

Commit 11b2d331 parent 32a682b1 file · +23 −10Browse files

Unified · Split

tccgen.c+23−10
@@ -75,7 +75,7 @@ static void type_decl(CType *type, AttributeDef *ad, int *v, int td); · 74 unmodified lines
7575 static void parse_expr_type(CType *type);
7676 static void decl_initializer(CType *type, Section *sec, unsigned long c, int first, int size_only);
7777 static void block(int *bsym, int *csym, int *case_sym, int *def_sym, int case_reg, int is_expr);
78−static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, int has_init, int v, int scope);
78+static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, int has_init, int v, char *asm_label, int scope);
7979 static void expr_eq(void);
8080 static void unary_type(CType *type);
8181 static int is_compatible_parameter_types(CType *type1, CType *type2);
@@ -3385,7 +3385,7 @@ ST_FUNC void unary(void) · 3303 unmodified lines
33853385 mk_pointer(&type);
33863386 type.t |= VT_ARRAY;
33873387 memset(&ad, 0, sizeof(AttributeDef));
3388− decl_initializer_alloc(&type, &ad, VT_CONST, 2, 0, 0);
3388+ decl_initializer_alloc(&type, &ad, VT_CONST, 2, 0, NULL, 0);
33893389 break;
33903390 case '(':
33913391 next();
@@ -3404,7 +3404,7 @@ ST_FUNC void unary(void) · 12 unmodified lines
34043404 if (!(type.t & VT_ARRAY))
34053405 r |= lvalue_type(type.t);
34063406 memset(&ad, 0, sizeof(AttributeDef));
3407− decl_initializer_alloc(&type, &ad, r, 1, 0, 0);
3407+ decl_initializer_alloc(&type, &ad, r, 1, 0, NULL, 0);
34083408 } else {
34093409 if (sizeof_caller) {
34103410 vpush(&type);
@@ -4992,12 +4992,14 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c, · 1581 unmodified lines
49924992 /* parse an initializer for type 't' if 'has_init' is non zero, and
49934993 allocate space in local or global data space ('r' is either
49944994 VT_LOCAL or VT_CONST). If 'v' is non zero, then an associated
4995− variable 'v' of scope 'scope' is declared before initializers are
4996− parsed. If 'v' is zero, then a reference to the new object is put
4997− in the value stack. If 'has_init' is 2, a special parsing is done
4998− to handle string constants. */
4995+ variable 'v' with an associated name represented by 'asm_label' of
4996+ scope 'scope' is declared before initializers are parsed. If 'v' is
4997+ zero, then a reference to the new object is put in the value stack.
4998+ If 'has_init' is 2, a special parsing is done to handle string
4999+ constants. */
49995000 static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r,
5000− int has_init, int v, int scope)
5001+ int has_init, int v, char *asm_label,
5002+ int scope)
50015003 {
50025004 int size, align, addr, data_offset;
50035005 int level;
@@ -5164,6 +5166,7 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, · 160 unmodified lines
51645166 if (v) {
51655167 if (scope != VT_CONST || !sym) {
51665168 sym = sym_push(v, type, r | VT_SYM, 0);
5169+ sym->asm_label = asm_label;
51675170 }
51685171 /* update symbol definition */
51695172 if (sec) {
@@ -5550,10 +5553,20 @@ ST_FUNC void decl(int l) · 380 unmodified lines
55505553 if (gnu_ext && (tok == TOK_ATTRIBUTE1 || tok == TOK_ATTRIBUTE2))
55515554 parse_attribute((AttributeDef *) &fn->type.ref->r);
55525555 } else {
5556+ char *asm_label; // associated asm label
5557+
55535558 /* not lvalue if array */
55545559 r = 0;
5560+ asm_label = NULL;
55555561 if (!(type.t & VT_ARRAY))
55565562 r |= lvalue_type(type.t);
5563+ if (tok == TOK_ASM1 || tok == TOK_ASM2 || tok == TOK_ASM3) {
5564+ CString astr;
5565+
5566+ asm_label_instr(&astr);
5567+ asm_label = tcc_strdup(astr.data);
5568+ cstr_free(&astr);
5569+ }
55575570 has_init = (tok == '=');
55585571 if ((btype.t & VT_EXTERN) ||
55595572 ((type.t & VT_ARRAY) && (type.t & VT_STATIC) &&
@@ -5562,7 +5575,7 @@ ST_FUNC void decl(int l) · 2 unmodified lines
55625575 /* NOTE: as GCC, uninitialized global static
55635576 arrays of null size are considered as
55645577 extern */
5565− external_sym(v, &type, r, NULL);
5578+ external_sym(v, &type, r, asm_label);
55665579 } else {
55675580 type.t |= (btype.t & VT_STATIC); /* Retain "static". */
55685581 if (type.t & VT_STATIC)
@@ -5571,7 +5584,7 @@ ST_FUNC void decl(int l) · 2 unmodified lines
55715584 r |= l;
55725585 if (has_init)
55735586 next();
5574− decl_initializer_alloc(&type, &ad, r, has_init, v, l);
5587+ decl_initializer_alloc(&type, &ad, r, has_init, v, asm_label, l);
55755588 }
55765589 }
55775590 if (tok != ',') {

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