History

Add support of asm label for functions.

Add support for asm labels for functions, that is the ability to rename a function at assembly level with __asm__ ("newname") appended in function declaration.

Thomas Preud'homme committed 16 years ago

Commit 9b09fc31 parent a7fb00e4 files · +57 −2Browse files

Unified · Split

4 files
  1. libtcc.c +10 −1
  2. tcc.h +3 −0
  3. tccasm.c +20 −0
  4. tccgen.c +24 −1
libtcc.c+10−1
@@ -72,6 +72,12 @@ ST_DATA void *rt_prog_main; · 71 unmodified lines
7272 #endif /* ALL_IN_ONE */
7373
7474 /********************************************************/
75+#ifndef CONFIG_TCC_ASM_LABEL
76+ST_FUNC void asm_label_instr(CString *)
77+{
78+ error("inline asm() not supported");
79+}
80+#endif
7581 #ifndef CONFIG_TCC_ASM
7682 ST_FUNC void asm_instr(void)
7783 {
@@ -436,7 +442,10 @@ ST_FUNC void put_extern_sym2(Sym *sym, Section *section, · 358 unmodified lines
436442 }
437443
438444 if (!sym->c) {
439− name = get_tok_str(sym->v, NULL);
445+ if (sym->a)
446+ name = get_tok_str(sym->a, NULL);
447+ else
448+ name = get_tok_str(sym->v, NULL);
440449 #ifdef CONFIG_TCC_BCHECK
441450 if (tcc_state->do_bounds_check) {
442451 char buf[32];
tcc.h+3−0
@@ -118,6 +118,7 @@ · 117 unmodified lines
118118 #if !defined(TCC_TARGET_ARM) && !defined(TCC_TARGET_C67)
119119 #define CONFIG_TCC_ASM
120120 #endif
121+#define CONFIG_TCC_ASM_LABEL
121122
122123 /* object format selection */
123124 #if defined(TCC_TARGET_C67)
@@ -211,6 +212,7 @@ typedef struct SValue { · 87 unmodified lines
211212 /* symbol management */
212213 typedef struct Sym {
213214 int v; /* symbol token */
215+ int a; /* asm symbol token */
214216 long r; /* associated register */
215217 union {
216218 long c; /* associated number */
@@ -1189,6 +1191,7 @@ ST_FUNC int tcc_load_coff(TCCState * s1, int fd); · 972 unmodified lines
11891191
11901192 /* ------------ tccasm.c ------------ */
11911193 ST_FUNC void asm_instr(void);
1194+ST_FUNC void asm_label_instr(CString *);
11921195 ST_FUNC void asm_global_instr(void);
11931196
11941197 #ifdef CONFIG_TCC_ASM
tccasm.c+20−0
@@ -18,6 +18,8 @@ · 17 unmodified lines
1818 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1919 */
2020
21+#ifdef CONFIG_TCC_ASM
22+
2123 #include "tcc.h"
2224
2325 ST_FUNC int asm_get_local_label_name(TCCState *s1, unsigned int n)
@@ -991,6 +993,8 @@ static void parse_asm_operands(ASMOperand *operands, int *nb_operands_ptr, · 967 unmodified lines
991993 }
992994 }
993995
996+#endif
997+
994998 static void parse_asm_str(CString *astr)
995999 {
9961000 skip('(');
@@ -1006,6 +1010,20 @@ static void parse_asm_str(CString *astr) · 9 unmodified lines
10061010 cstr_ccat(astr, '\0');
10071011 }
10081012
1013+/* Parse an asm label and return the label
1014+ * Don't forget to free the CString in the caller! */
1015+static void asm_label_instr(CString *astr)
1016+{
1017+ next();
1018+ parse_asm_str(astr);
1019+ skip(')');
1020+#ifdef ASM_DEBUG
1021+ printf("asm_alias: \"%s\"\n", (char *)astr->data);
1022+#endif
1023+}
1024+
1025+#ifdef CONFIG_TCC_ASM
1026+
10091027 /* parse the GCC asm() instruction */
10101028 ST_FUNC void asm_instr(void)
10111029 {
@@ -1136,3 +1154,5 @@ ST_FUNC void asm_global_instr(void) · 124 unmodified lines
11361154
11371155 cstr_free(&astr);
11381156 }
1157+
1158+#endif
tccgen.c+24−1
@@ -136,6 +136,7 @@ ST_FUNC Sym *sym_push2(Sym **ps, int v, int t, long c) · 135 unmodified lines
136136 {
137137 Sym *s;
138138 s = sym_malloc();
139+ s->a = 0;
139140 s->v = v;
140141 s->type.t = t;
141142 s->type.ref = NULL;
@@ -368,6 +369,8 @@ static Sym *external_sym(int v, CType *type, int r) · 226 unmodified lines
368369 if (!s) {
369370 /* push forward reference */
370371 s = sym_push(v, type, r | VT_CONST | VT_SYM, 0);
372+ if (type && type->ref && type->ref->a)
373+ s->a = type->ref->a;
371374 s->type.t |= VT_EXTERN;
372375 } else if (s->type.ref == func_old_type.ref) {
373376 s->type.ref = type->ref;
@@ -2996,6 +2999,8 @@ static void post_type(CType *type, AttributeDef *ad) · 2622 unmodified lines
29962999 CType pt;
29973000
29983001 if (tok == '(') {
3002+ TokenSym *ts = NULL;
3003+
29993004 /* function declaration */
30003005 next();
30013006 l = 0;
@@ -3051,10 +3056,19 @@ static void post_type(CType *type, AttributeDef *ad) · 49 unmodified lines
30513056 /* NOTE: const is ignored in returned type as it has a special
30523057 meaning in gcc / C++ */
30533058 type->t &= ~(VT_STORAGE | VT_CONSTANT);
3059+ if (tok == TOK_ASM1 || tok == TOK_ASM2 || tok == TOK_ASM3) {
3060+ CString astr;
3061+
3062+ asm_label_instr(&astr);
3063+ ts = tok_alloc(astr.data, strlen(astr.data));
3064+ cstr_free(&astr);
3065+ }
30543066 post_type(type, ad);
30553067 /* we push a anonymous symbol which will contain the function prototype */
30563068 ad->func_args = arg_size;
30573069 s = sym_push(SYM_FIELD, type, INT_ATTR(ad), l);
3070+ if (ts != NULL)
3071+ s->a = ts->tok;
30583072 s->next = first;
30593073 type->t = t1 | VT_FUNC;
30603074 type->ref = s;
@@ -5228,7 +5242,10 @@ static void gen_function(Sym *sym) · 2167 unmodified lines
52285242 ind = cur_text_section->data_offset;
52295243 /* NOTE: we patch the symbol size later */
52305244 put_extern_sym(sym, cur_text_section, ind, 0);
5231− funcname = get_tok_str(sym->v, NULL);
5245+ if (sym->a)
5246+ funcname = get_tok_str(sym->a, NULL);
5247+ else
5248+ funcname = get_tok_str(sym->v, NULL);
52325249 func_ind = ind;
52335250 /* put debug symbol */
52345251 if (tcc_state->do_debug)
@@ -5308,6 +5325,12 @@ ST_FUNC void decl(int l) · 73 unmodified lines
53085325 Sym *sym;
53095326 AttributeDef ad;
53105327
5328+ /*
5329+ * type.ref must be either a valid reference or NULL for external_sym to
5330+ * work. As type = btype is executed before external_sym is call, setting
5331+ * btype.ref to 0 is enough.
5332+ */
5333+ btype.ref = 0;
53115334 while (1) {
53125335 if (!parse_btype(&btype, &ad)) {
53135336 /* skip redundant ';' */

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