History

suppressed section_ptr - fixed constant string allocation

bellard committed 24 years ago

Commit f946dff1 parent 524be932 files · +45 −54Browse files

Unified · Split

2 files
  1. tcc.c +42 −52
  2. tccelf.c +3 −2
tcc.c+42−52
@@ -562,9 +562,10 @@ int expr_const(void); · 561 unmodified lines
562562 void expr_eq(void);
563563 void gexpr(void);
564564 void decl(int l);
565−void decl_initializer(int t, Section *sec, unsigned long c, int first, int size_only);
566−void decl_initializer_alloc(int t, AttributeDef *ad, int r, int has_init,
567− int v, int scope);
565+static void decl_initializer(int t, Section *sec, unsigned long c,
566+ int first, int size_only);
567+static void decl_initializer_alloc(int t, AttributeDef *ad, int r,
568+ int has_init, int v, int scope);
568569 int gv(int rc);
569570 void gv2(int rc1, int rc2);
570571 void move_reg(int r, int s);
@@ -607,7 +608,6 @@ static Sym *get_sym_ref(int t, Section *sec, · 36 unmodified lines
607608
608609 /* section generation */
609610 static void section_realloc(Section *sec, unsigned long new_size);
610−static void *section_ptr(Section *sec, unsigned long size);
611611 static void *section_ptr_add(Section *sec, unsigned long size);
612612 static void put_extern_sym(Sym *sym, Section *section,
613613 unsigned long value, unsigned long size);
@@ -873,17 +873,7 @@ static void section_realloc(Section *sec, unsigned long new_size) · 259 unmodified lines
873873 }
874874
875875 /* reserve at least 'size' bytes in section 'sec' from
876− sec->data_offset. Optimized for speed */
877−static inline void *section_ptr(Section *sec, unsigned long size)
878−{
879− unsigned long offset, offset1;
880− offset = sec->data_offset;
881− offset1 = offset + size;
882− if (offset1 > sec->data_allocated)
883− section_realloc(sec, offset1);
884− return sec->data + offset;
885−}
886−
876+ sec->data_offset. */
887877 static void *section_ptr_add(Section *sec, unsigned long size)
888878 {
889879 unsigned long offset, offset1;
@@ -5010,7 +5000,7 @@ void gfunc_param_typed(GFuncContext *gf, Sym *func, Sym *arg) · 4120 unmodified lines
50105000
50115001 void unary(void)
50125002 {
5013− int n, t, ft, fc, align, size, r, data_offset;
5003+ int n, t, ft, align, size, r;
50145004 Sym *s;
50155005 GFuncContext gf;
50165006 AttributeDef ad;
@@ -5057,19 +5047,9 @@ void unary(void) · 40 unmodified lines
50575047 /* string parsing */
50585048 t = VT_BYTE;
50595049 str_init:
5060− type_size(t, &align);
5061− data_offset = data_section->data_offset;
5062− data_offset = (data_offset + align - 1) & -align;
5063− fc = data_offset;
5064− /* we must declare it as an array first to use initializer parser */
50655050 t = VT_ARRAY | mk_pointer(t);
5066− /* XXX: fix it */
5067− section_ptr(data_section, 1024);
5068− decl_initializer(t, data_section, data_offset, 1, 0);
5069− size = type_size(t, &align);
5070− data_offset += size;
5071− vpush_ref(t, data_section, fc, size);
5072− data_section->data_offset = data_offset;
5051+ memset(&ad, 0, sizeof(AttributeDef));
5052+ decl_initializer_alloc(t, &ad, VT_CONST, 2, 0, 0);
50735053 } else {
50745054 t = tok;
50755055 next();
@@ -5794,9 +5774,9 @@ void block(int *bsym, int *csym, int *case_sym, int *def_sym, int case_reg) · 718 unmodified lines
57945774 address. cur_index/cur_field is the pointer to the current
57955775 value. 'size_only' is true if only size info is needed (only used
57965776 in arrays) */
5797−void decl_designator(int t, Section *sec, unsigned long c,
5798− int *cur_index, Sym **cur_field,
5799− int size_only)
5777+static void decl_designator(int t, Section *sec, unsigned long c,
5778+ int *cur_index, Sym **cur_field,
5779+ int size_only)
58005780 {
58015781 Sym *s, *f;
58025782 int notfirst, index, align, l;
@@ -5871,8 +5851,8 @@ void decl_designator(int t, Section *sec, unsigned long c, · 68 unmodified lines
58715851 #define EXPR_ANY 2
58725852
58735853 /* store a value or an expression directly in global data or in local array */
5874−void init_putv(int t, Section *sec, unsigned long c,
5875− int v, int expr_type)
5854+static void init_putv(int t, Section *sec, unsigned long c,
5855+ int v, int expr_type)
58765856 {
58775857 int saved_global_expr, bt;
58785858 void *ptr;
@@ -5941,7 +5921,7 @@ void init_putv(int t, Section *sec, unsigned long c, · 62 unmodified lines
59415921 }
59425922
59435923 /* put zeros for variable based init */
5944−void init_putz(int t, Section *sec, unsigned long c, int size)
5924+static void init_putz(int t, Section *sec, unsigned long c, int size)
59455925 {
59465926 GFuncContext gf;
59475927
@@ -5965,7 +5945,8 @@ void init_putz(int t, Section *sec, unsigned long c, int size) · 17 unmodified lines
59655945 allocation. 'first' is true if array '{' must be read (multi
59665946 dimension implicit array init handling). 'size_only' is true if
59675947 size only evaluation is wanted (only for arrays). */
5968−void decl_initializer(int t, Section *sec, unsigned long c, int first, int size_only)
5948+static void decl_initializer(int t, Section *sec, unsigned long c,
5949+ int first, int size_only)
59695950 {
59705951 int index, array_length, n, no_oblock, nb, parlevel, i;
59715952 int t1, size1, align1, expr_type;
@@ -6118,14 +6099,15 @@ void decl_initializer(int t, Section *sec, unsigned long c, int first, int size_ · 146 unmodified lines
61186099 }
61196100 }
61206101
6121−/* parse an initializer for type 't' if 'has_init' is true, and
6102+/* parse an initializer for type 't' if 'has_init' is non zero, and
61226103 allocate space in local or global data space ('r' is either
61236104 VT_LOCAL or VT_CONST). If 'v' is non zero, then an associated
61246105 variable 'v' of scope 'scope' is declared before initializers are
61256106 parsed. If 'v' is zero, then a reference to the new object is put
6126− in the value stack. */
6127−void decl_initializer_alloc(int t, AttributeDef *ad, int r, int has_init,
6128− int v, int scope)
6107+ in the value stack. If 'has_init' is 2, a special parsing is done
6108+ to handle string constants. */
6109+static void decl_initializer_alloc(int t, AttributeDef *ad, int r,
6110+ int has_init, int v, int scope)
61296111 {
61306112 int size, align, addr, data_offset;
61316113 int level;
@@ -6145,19 +6127,27 @@ void decl_initializer_alloc(int t, AttributeDef *ad, int r, int has_init, · 13 unmodified lines
61456127 if (!has_init)
61466128 error("unknown type size");
61476129 /* get all init string */
6148− level = 0;
6149− while (level > 0 || (tok != ',' && tok != ';')) {
6150− if (tok < 0)
6151− error("unexpected end of file in initializer");
6152− tok_str_add_tok(&init_str);
6153− if (tok == '{')
6154− level++;
6155− else if (tok == '}') {
6156− if (level == 0)
6157− break;
6158− level--;
6130+ if (has_init == 2) {
6131+ /* only get strings */
6132+ while (tok == TOK_STR || tok == TOK_LSTR) {
6133+ tok_str_add_tok(&init_str);
6134+ next();
6135+ }
6136+ } else {
6137+ level = 0;
6138+ while (level > 0 || (tok != ',' && tok != ';')) {
6139+ if (tok < 0)
6140+ error("unexpected end of file in initializer");
6141+ tok_str_add_tok(&init_str);
6142+ if (tok == '{')
6143+ level++;
6144+ else if (tok == '}') {
6145+ if (level == 0)
6146+ break;
6147+ level--;
6148+ }
6149+ next();
61596150 }
6160− next();
61616151 }
61626152 tok_str_add(&init_str, -1);
61636153 tok_str_add(&init_str, 0);
@@ -7138,7 +7128,7 @@ int tcc_set_output_type(TCCState *s, int output_type) · 974 unmodified lines
71387128
71397129 void help(void)
71407130 {
7141− printf("tcc version 0.9.10pre1 - Tiny C Compiler - Copyright (C) 2001, 2002 Fabrice Bellard\n"
7131+ printf("tcc version 0.9.10 - Tiny C Compiler - Copyright (C) 2001, 2002 Fabrice Bellard\n"
71427132 "usage: tcc [-c] [-o outfile] [-Bdir] [-bench] [-Idir] [-Dsym[=val]] [-Usym]\n"
71437133 " [-g] [-b] [-Ldir] [-llib] [-shared] [-static]\n"
71447134 " [--] infile1 [infile2... --] [infile_args...]\n"
tccelf.c+3−2
@@ -1511,10 +1511,11 @@ static int tcc_load_object_file(TCCState *s1, · 1510 unmodified lines
15111511 if (sh->sh_type != SHT_NOBITS) {
15121512 unsigned char *ptr;
15131513 lseek(fd, file_offset + sh->sh_offset, SEEK_SET);
1514− ptr = section_ptr(s, size);
1514+ ptr = section_ptr_add(s, size);
15151515 read(fd, ptr, size);
1516+ } else {
1517+ s->data_offset += size;
15161518 }
1517− s->data_offset += size;
15181519 }
15191520
15201521 /* second short pass to update sh_link and sh_info fields of new

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