History

cleanup: stop abuse of sym->r for inline functions

grischka committed 17 years ago

Commit d0b432a1 parent 5e83b642 files · +30 −27Browse files

Unified · Split

2 files
  1. tcc.h +10 −2
  2. tccgen.c +20 −25
tcc.h+10−2
@@ -262,7 +262,6 @@ typedef struct { · 261 unmodified lines
262262 #define FUNC_CALL(r) (((func_attr_t*)&(r))->func_call)
263263 #define FUNC_EXPORT(r) (((func_attr_t*)&(r))->func_export)
264264 #define FUNC_ARGS(r) (((func_attr_t*)&(r))->func_args)
265−#define INLINE_DEF(r) (*(int **)&(r))
266265 /* -------------------------------------------------- */
267266
268267 #define SYM_STRUCT 0x40000000 /* struct/union/enum symbol space */
@@ -331,6 +330,13 @@ typedef struct TokenString { · 62 unmodified lines
331330 int last_line_num;
332331 } TokenString;
333332
333+/* inline functions */
334+typedef struct InlineFunc {
335+ int *token_str;
336+ Sym *sym;
337+ char filename[1];
338+} InlineFunc;
339+
334340 /* include file cache, used to find files faster and also to eliminate
335341 inclusion if the include file is protected by #ifndef ... #endif */
336342 typedef struct CachedInclude {
@@ -362,7 +368,6 @@ typedef struct ASMOperand { · 25 unmodified lines
362368 int is_memory; /* true if memory operand */
363369 int is_rw; /* for '+' modifier */
364370 } ASMOperand;
365−
366371 #endif
367372
368373 struct TCCState {
@@ -479,6 +484,9 @@ struct TCCState { · 110 unmodified lines
479484 /* for tcc_relocate */
480485 int runtime_added;
481486
487+ struct InlineFunc **inline_fns;
488+ int nb_inline_fns;
489+
482490 #ifdef TCC_TARGET_X86_64
483491 /* write PLT and GOT here */
484492 char *runtime_plt_and_got;
tccgen.c+20−25
@@ -4914,21 +4914,22 @@ static void gen_function(Sym *sym) · 4913 unmodified lines
49144914 static void gen_inline_functions(void)
49154915 {
49164916 Sym *sym;
4917− CType *type;
4918− int *str, inline_generated;
4917+ int *str, inline_generated, i;
4918+ struct InlineFunc *fn;
49194919
49204920 /* iterate while inline function are referenced */
49214921 for(;;) {
49224922 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) {
49294927 /* the function was used: generate its code and
49304928 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);
49324933 sym->r = VT_SYM | VT_CONST;
49334934 sym->type.t &= ~VT_INLINE;
49344935
@@ -4945,21 +4946,7 @@ static void gen_inline_functions(void) · 10 unmodified lines
49454946 if (!inline_generated)
49464947 break;
49474948 }
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);
49634950 }
49644951
49654952 /* 'l' is VT_LOCAL or VT_CONST to define default storage type */
@@ -5070,6 +5057,8 @@ static void decl(int l) · 104 unmodified lines
50705057 (VT_INLINE | VT_STATIC)) {
50715058 TokenString func_str;
50725059 int block_level;
5060+ struct InlineFunc *fn;
5061+ const char *filename;
50735062
50745063 tok_str_new(&func_str);
50755064
@@ -5091,7 +5080,13 @@ static void decl(int l) · 15 unmodified lines
50915080 }
50925081 tok_str_add(&func_str, -1);
50935082 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+
50955090 } else {
50965091 /* compute text section */
50975092 cur_text_section = ad.section;

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