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
262#define FUNC_CALL(r) (((func_attr_t*)&(r))->func_call)262#define FUNC_CALL(r) (((func_attr_t*)&(r))->func_call)
263#define FUNC_EXPORT(r) (((func_attr_t*)&(r))->func_export)263#define FUNC_EXPORT(r) (((func_attr_t*)&(r))->func_export)
264#define FUNC_ARGS(r) (((func_attr_t*)&(r))->func_args)264#define FUNC_ARGS(r) (((func_attr_t*)&(r))->func_args)
265#define INLINE_DEF(r) (*(int **)&(r))
266/* -------------------------------------------------- */265/* -------------------------------------------------- */
267 266
268#define SYM_STRUCT 0x40000000 /* struct/union/enum symbol space */267#define SYM_STRUCT 0x40000000 /* struct/union/enum symbol space */
@@ -331,6 +330,13 @@ typedef struct TokenString { · 62 unmodified lines
331 int last_line_num;330 int last_line_num;
332} TokenString;331} TokenString;
333 332
333/* inline functions */
334typedef struct InlineFunc {
335 int *token_str;
336 Sym *sym;
337 char filename[1];
338} InlineFunc;
339
334/* include file cache, used to find files faster and also to eliminate340/* include file cache, used to find files faster and also to eliminate
335 inclusion if the include file is protected by #ifndef ... #endif */341 inclusion if the include file is protected by #ifndef ... #endif */
336typedef struct CachedInclude {342typedef struct CachedInclude {
@@ -362,7 +368,6 @@ typedef struct ASMOperand { · 25 unmodified lines
362 int is_memory; /* true if memory operand */368 int is_memory; /* true if memory operand */
363 int is_rw; /* for '+' modifier */369 int is_rw; /* for '+' modifier */
364} ASMOperand;370} ASMOperand;
365
366#endif371#endif
367 372
368struct TCCState {373struct TCCState {
@@ -479,6 +484,9 @@ struct TCCState { · 110 unmodified lines
479 /* for tcc_relocate */484 /* for tcc_relocate */
480 int runtime_added;485 int runtime_added;
481 486
487 struct InlineFunc **inline_fns;
488 int nb_inline_fns;
489
482#ifdef TCC_TARGET_X86_64490#ifdef TCC_TARGET_X86_64
483 /* write PLT and GOT here */491 /* write PLT and GOT here */
484 char *runtime_plt_and_got;492 char *runtime_plt_and_got;
tccgen.c+20−25
@@ -4914,21 +4914,22 @@ static void gen_function(Sym *sym) · 4913 unmodified lines
4914static void gen_inline_functions(void)4914static void gen_inline_functions(void)
4915{4915{
4916 Sym *sym;4916 Sym *sym;
4917 CType *type;4917 int *str, inline_generated, i;
4918 int *str, inline_generated;4918 struct InlineFunc *fn;
4919 4919
4920 /* iterate while inline function are referenced */4920 /* iterate while inline function are referenced */
4921 for(;;) {4921 for(;;) {
4922 inline_generated = 0;4922 inline_generated = 0;
4923 for(sym = global_stack; sym != NULL; sym = sym->prev) {4923 for (i = 0; i < tcc_state->nb_inline_fns; ++i) {
4924 type = &sym->type;4924 fn = tcc_state->inline_fns[i];
4925 if (((type->t & VT_BTYPE) == VT_FUNC) &&4925 sym = fn->sym;
4926 (type->t & (VT_STATIC | VT_INLINE)) == 4926 if (sym && sym->c) {
4927 (VT_STATIC | VT_INLINE) &&
4928 sym->c != 0) {
4929 /* the function was used: generate its code and4927 /* the function was used: generate its code and
4930 convert it to a normal function */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 sym->r = VT_SYM | VT_CONST;4933 sym->r = VT_SYM | VT_CONST;
4933 sym->type.t &= ~VT_INLINE;4934 sym->type.t &= ~VT_INLINE;
4934 4935
@@ -4945,21 +4946,7 @@ static void gen_inline_functions(void) · 10 unmodified lines
4945 if (!inline_generated)4946 if (!inline_generated)
4946 break;4947 break;
4947 }4948 }
4948 4949 dynarray_reset(&tcc_state->inline_fns, &tcc_state->nb_inline_fns);
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 }
4963}4950}
4964 4951
4965/* 'l' is VT_LOCAL or VT_CONST to define default storage type */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 (VT_INLINE | VT_STATIC)) {5057 (VT_INLINE | VT_STATIC)) {
5071 TokenString func_str;5058 TokenString func_str;
5072 int block_level;5059 int block_level;
5060 struct InlineFunc *fn;
5061 const char *filename;
5073 5062
5074 tok_str_new(&func_str);5063 tok_str_new(&func_str);
5075 5064
@@ -5091,7 +5080,13 @@ static void decl(int l) · 15 unmodified lines
5091 }5080 }
5092 tok_str_add(&func_str, -1);5081 tok_str_add(&func_str, -1);
5093 tok_str_add(&func_str, 0);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 } else {5090 } else {
5096 /* compute text section */5091 /* compute text section */
5097 cur_text_section = ad.section;5092 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