| @@ -4914,21 +4914,22 @@ static void gen_function(Sym *sym) · 4913 unmodified lines |
| 4914 | 4914 | static void gen_inline_functions(void) |
| 4915 | 4915 | { |
| 4916 | 4916 | Sym *sym; |
| 4917 | | − CType *type; |
| 4918 | | − int *str, inline_generated; |
| 4917 | + int *str, inline_generated, i; |
| 4918 | + struct InlineFunc *fn; |
| 4919 | 4919 | |
| 4920 | 4920 | /* iterate while inline function are referenced */ |
| 4921 | 4921 | for(;;) { |
| 4922 | 4922 | inline_generated = 0; |
| 4923 | | − for(sym = global_stack; sym != NULL; sym = sym->prev) { |
| 4924 | | − type = &sym->type; |
| 4925 | | − if (((type->t & VT_BTYPE) == VT_FUNC) && |
| 4926 | | − (type->t & (VT_STATIC | VT_INLINE)) == |
| 4927 | | − (VT_STATIC | VT_INLINE) && |
| 4928 | | − sym->c != 0) { |
| 4923 | + for (i = 0; i < tcc_state->nb_inline_fns; ++i) { |
| 4924 | + fn = tcc_state->inline_fns[i]; |
| 4925 | + sym = fn->sym; |
| 4926 | + if (sym && sym->c) { |
| 4929 | 4927 | /* the function was used: generate its code and |
| 4930 | 4928 | convert it to a normal function */ |
| 4931 | | − str = INLINE_DEF(sym->r); |
| 4929 | + str = fn->token_str; |
| 4930 | + fn->sym = NULL; |
| 4931 | + if (file) |
| 4932 | + strcpy(file->filename, fn->filename); |
| 4932 | 4933 | sym->r = VT_SYM | VT_CONST; |
| 4933 | 4934 | sym->type.t &= ~VT_INLINE; |
| 4934 | 4935 | |
| @@ -4945,21 +4946,7 @@ static void gen_inline_functions(void) · 10 unmodified lines |
| 4945 | 4946 | if (!inline_generated) |
| 4946 | 4947 | break; |
| 4947 | 4948 | } |
| 4948 | | − |
| 4949 | | − /* free all remaining inline function tokens */ |
| 4950 | | − for(sym = global_stack; sym != NULL; sym = sym->prev) { |
| 4951 | | − type = &sym->type; |
| 4952 | | − if (((type->t & VT_BTYPE) == VT_FUNC) && |
| 4953 | | − (type->t & (VT_STATIC | VT_INLINE)) == |
| 4954 | | − (VT_STATIC | VT_INLINE)) { |
| 4955 | | − //gr printf("sym %d %s\n", sym->r, get_tok_str(sym->v, NULL)); |
| 4956 | | − if (sym->r == (VT_SYM | VT_CONST)) //gr beware! |
| 4957 | | − continue; |
| 4958 | | − str = INLINE_DEF(sym->r); |
| 4959 | | − tok_str_free(str); |
| 4960 | | − sym->r = 0; /* fail safe */ |
| 4961 | | − } |
| 4962 | | − } |
| 4949 | + dynarray_reset(&tcc_state->inline_fns, &tcc_state->nb_inline_fns); |
| 4963 | 4950 | } |
| 4964 | 4951 | |
| 4965 | 4952 | /* 'l' is VT_LOCAL or VT_CONST to define default storage type */ |
| @@ -5070,6 +5057,8 @@ static void decl(int l) · 104 unmodified lines |
| 5070 | 5057 | (VT_INLINE | VT_STATIC)) { |
| 5071 | 5058 | TokenString func_str; |
| 5072 | 5059 | int block_level; |
| 5060 | + struct InlineFunc *fn; |
| 5061 | + const char *filename; |
| 5073 | 5062 | |
| 5074 | 5063 | tok_str_new(&func_str); |
| 5075 | 5064 | |
| @@ -5091,7 +5080,13 @@ static void decl(int l) · 15 unmodified lines |
| 5091 | 5080 | } |
| 5092 | 5081 | tok_str_add(&func_str, -1); |
| 5093 | 5082 | tok_str_add(&func_str, 0); |
| 5094 | | − INLINE_DEF(sym->r) = func_str.str; |
| 5083 | + filename = file ? file->filename : ""; |
| 5084 | + fn = tcc_malloc(sizeof *fn + strlen(filename)); |
| 5085 | + strcpy(fn->filename, filename); |
| 5086 | + fn->sym = sym; |
| 5087 | + fn->token_str = func_str.str; |
| 5088 | + dynarray_add((void ***)&tcc_state->inline_fns, &tcc_state->nb_inline_fns, fn); |
| 5089 | + |
| 5095 | 5090 | } else { |
| 5096 | 5091 | /* compute text section */ |
| 5097 | 5092 | cur_text_section = ad.section; |