History

move static prototypes to libtcc.c

grischka committed 17 years ago

Commit 0a35f9d1 parent f9181414 files · +180 −154Browse files

Unified · Split

4 files
  1. libtcc.c +124 −1
  2. tcc.c +1 −1
  3. tcc.h +44 −146
  4. tccpp.c +11 −6
libtcc.c+124−1
@@ -20,6 +20,9 @@ · 19 unmodified lines
20 20
21#include "tcc.h"21#include "tcc.h"
22 22
23/********************************************************/
24/* global variables */
25
23/* display benchmark infos */26/* display benchmark infos */
24int total_lines;27int total_lines;
25int total_bytes;28int total_bytes;
@@ -112,6 +115,126 @@ const char **rt_bound_error_msg; · 86 unmodified lines
112/* XXX: get rid of this ASAP */115/* XXX: get rid of this ASAP */
113static struct TCCState *tcc_state;116static struct TCCState *tcc_state;
114 117
118/********************************************************/
119/* function prototypes */
120
121/* tccpp.c */
122static void next(void);
123char *get_tok_str(int v, CValue *cv);
124
125/* tccgen.c */
126static void parse_expr_type(CType *type);
127static void expr_type(CType *type);
128static void unary_type(CType *type);
129static void block(int *bsym, int *csym, int *case_sym, int *def_sym,
130 int case_reg, int is_expr);
131static int expr_const(void);
132static void expr_eq(void);
133static void gexpr(void);
134static void gen_inline_functions(void);
135static void decl(int l);
136static void decl_initializer(CType *type, Section *sec, unsigned long c,
137 int first, int size_only);
138static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r,
139 int has_init, int v, int scope);
140int gv(int rc);
141void gv2(int rc1, int rc2);
142void move_reg(int r, int s);
143void save_regs(int n);
144void save_reg(int r);
145void vpop(void);
146void vswap(void);
147void vdup(void);
148int get_reg(int rc);
149int get_reg_ex(int rc,int rc2);
150
151void gen_op(int op);
152void force_charshort_cast(int t);
153static void gen_cast(CType *type);
154void vstore(void);
155static Sym *sym_find(int v);
156static Sym *sym_push(int v, CType *type, int r, int c);
157
158/* type handling */
159static int type_size(CType *type, int *a);
160static inline CType *pointed_type(CType *type);
161static int pointed_size(CType *type);
162static int lvalue_type(int t);
163static int parse_btype(CType *type, AttributeDef *ad);
164static void type_decl(CType *type, AttributeDef *ad, int *v, int td);
165static int compare_types(CType *type1, CType *type2, int unqualified);
166static int is_compatible_types(CType *type1, CType *type2);
167static int is_compatible_parameter_types(CType *type1, CType *type2);
168
169int ieee_finite(double d);
170void vpushi(int v);
171void vpushll(long long v);
172void vrott(int n);
173void vnrott(int n);
174void lexpand_nr(void);
175static void vpush_global_sym(CType *type, int v);
176void vset(CType *type, int r, int v);
177void type_to_str(char *buf, int buf_size,
178 CType *type, const char *varstr);
179static Sym *get_sym_ref(CType *type, Section *sec,
180 unsigned long offset, unsigned long size);
181static Sym *external_global_sym(int v, CType *type, int r);
182
183/* section generation */
184static void section_realloc(Section *sec, unsigned long new_size);
185static void *section_ptr_add(Section *sec, unsigned long size);
186static void put_extern_sym(Sym *sym, Section *section,
187 unsigned long value, unsigned long size);
188static void greloc(Section *s, Sym *sym, unsigned long addr, int type);
189static int put_elf_str(Section *s, const char *sym);
190static int put_elf_sym(Section *s,
191 unsigned long value, unsigned long size,
192 int info, int other, int shndx, const char *name);
193static int add_elf_sym(Section *s, unsigned long value, unsigned long size,
194 int info, int other, int sh_num, const char *name);
195static void put_elf_reloc(Section *symtab, Section *s, unsigned long offset,
196 int type, int symbol);
197static void put_stabs(const char *str, int type, int other, int desc,
198 unsigned long value);
199static void put_stabs_r(const char *str, int type, int other, int desc,
200 unsigned long value, Section *sec, int sym_index);
201static void put_stabn(int type, int other, int desc, int value);
202static void put_stabd(int type, int other, int desc);
203static int tcc_add_dll(TCCState *s, const char *filename, int flags);
204
205#define AFF_PRINT_ERROR 0x0001 /* print error if file not found */
206#define AFF_REFERENCED_DLL 0x0002 /* load a referenced dll from another dll */
207#define AFF_PREPROCESS 0x0004 /* preprocess file */
208static int tcc_add_file_internal(TCCState *s, const char *filename, int flags);
209
210/* tcccoff.c */
211int tcc_output_coff(TCCState *s1, FILE *f);
212
213/* tccpe.c */
214void *resolve_sym(TCCState *s1, const char *sym, int type);
215int pe_load_def_file(struct TCCState *s1, int fd);
216int pe_test_res_file(void *v, int size);
217int pe_load_res_file(struct TCCState *s1, int fd);
218void pe_add_runtime(struct TCCState *s1);
219void pe_guess_outfile(char *objfilename, int output_type);
220int pe_output_file(struct TCCState *s1, const char *filename);
221
222/* tccasm.c */
223#ifdef CONFIG_TCC_ASM
224static void asm_expr(TCCState *s1, ExprValue *pe);
225static int asm_int_expr(TCCState *s1);
226static int find_constraint(ASMOperand *operands, int nb_operands,
227 const char *name, const char **pp);
228
229static int tcc_assemble(TCCState *s1, int do_preprocess);
230#endif
231
232static void asm_instr(void);
233static void asm_global_instr(void);
234
235/********************************************************/
236/* global variables */
237
115#ifdef TCC_TARGET_I386238#ifdef TCC_TARGET_I386
116#include "i386-gen.c"239#include "i386-gen.c"
117#endif240#endif
@@ -2118,7 +2241,7 @@ void tcc_set_lib_path(TCCState *s, const char *path) · 2000 unmodified lines
2118 s->tcc_lib_path = tcc_strdup(path);2241 s->tcc_lib_path = tcc_strdup(path);
2119}2242}
2120 2243
2121LIBTCCAPI void print_stats(TCCState *s, int64_t total_time)2244void tcc_print_stats(TCCState *s, int64_t total_time)
2122{2245{
2123 double tt;2246 double tt;
2124 tt = (double)total_time / 1000000.0;2247 tt = (double)total_time / 1000000.0;
tcc.c+1−1
@@ -531,7 +531,7 @@ int main(int argc, char **argv) · 530 unmodified lines
531 goto the_end;531 goto the_end;
532 532
533 if (do_bench)533 if (do_bench)
534 print_stats(s, getclock_us() - start_time);534 tcc_print_stats(s, getclock_us() - start_time);
535 535
536 if (s->output_type == TCC_OUTPUT_PREPROCESS) {536 if (s->output_type == TCC_OUTPUT_PREPROCESS) {
537 if (outfile)537 if (outfile)
tcc.h+44−146
@@ -341,6 +341,29 @@ typedef struct CachedInclude { · 340 unmodified lines
341 341
342#define CACHED_INCLUDES_HASH_SIZE 512342#define CACHED_INCLUDES_HASH_SIZE 512
343 343
344#ifdef CONFIG_TCC_ASM
345typedef struct ExprValue {
346 uint32_t v;
347 Sym *sym;
348} ExprValue;
349
350#define MAX_ASM_OPERANDS 30
351typedef struct ASMOperand {
352 int id; /* GCC 3 optionnal identifier (0 if number only supported */
353 char *constraint;
354 char asm_str[16]; /* computed asm string for operand */
355 SValue *vt; /* C value of the expression */
356 int ref_index; /* if >= 0, gives reference to a output constraint */
357 int input_index; /* if >= 0, gives reference to an input constraint */
358 int priority; /* priority, used to assign registers */
359 int reg; /* if >= 0, register number used for this operand */
360 int is_llong; /* true if double register value */
361 int is_memory; /* true if memory operand */
362 int is_rw; /* for '+' modifier */
363} ASMOperand;
364
365#endif
366
344struct TCCState {367struct TCCState {
345 int output_type;368 int output_type;
346 369
@@ -700,155 +723,24 @@ extern long double strtold (const char *__nptr, char **__endptr); · 353 unmodified lines
700#define PATHCMP strcmp723#define PATHCMP strcmp
701#endif724#endif
702 725
703static char *pstrcpy(char *buf, int buf_size, const char *s);
704static char *pstrcat(char *buf, int buf_size, const char *s);
705static char *tcc_basename(const char *name);
706static char *tcc_fileextension (const char *p);
707
708static void next(void);
709static void next_nomacro(void);
710static void next_nomacro_spc(void);
711static void parse_expr_type(CType *type);
712static void expr_type(CType *type);
713static void unary_type(CType *type);
714static void block(int *bsym, int *csym, int *case_sym, int *def_sym,
715 int case_reg, int is_expr);
716static int expr_const(void);
717static void expr_eq(void);
718static void gexpr(void);
719static void gen_inline_functions(void);
720static void decl(int l);
721static void decl_initializer(CType *type, Section *sec, unsigned long c,
722 int first, int size_only);
723static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r,
724 int has_init, int v, int scope);
725int gv(int rc);
726void gv2(int rc1, int rc2);
727void move_reg(int r, int s);
728void save_regs(int n);
729void save_reg(int r);
730void vpop(void);
731void vswap(void);
732void vdup(void);
733int get_reg(int rc);
734int get_reg_ex(int rc,int rc2);
735
736struct macro_level {
737 struct macro_level *prev;
738 int *p;
739};
740
741static void macro_subst(TokenString *tok_str, Sym **nested_list,
742 const int *macro_str, struct macro_level **can_read_stream);
743void gen_op(int op);
744void force_charshort_cast(int t);
745static void gen_cast(CType *type);
746void vstore(void);
747static Sym *sym_find(int v);
748static Sym *sym_push(int v, CType *type, int r, int c);
749
750/* type handling */
751static int type_size(CType *type, int *a);
752static inline CType *pointed_type(CType *type);
753static int pointed_size(CType *type);
754static int lvalue_type(int t);
755static int parse_btype(CType *type, AttributeDef *ad);
756static void type_decl(CType *type, AttributeDef *ad, int *v, int td);
757static int compare_types(CType *type1, CType *type2, int unqualified);
758static int is_compatible_types(CType *type1, CType *type2);
759static int is_compatible_parameter_types(CType *type1, CType *type2);
760
761int ieee_finite(double d);
762void error(const char *fmt, ...);726void error(const char *fmt, ...);
763void vpushi(int v);727void warning(const char *fmt, ...);
764void vpushll(long long v);728void tcc_set_lib_path_w32(TCCState *s);
765void vrott(int n);729int tcc_set_flag(TCCState *s, const char *flag_name, int value);
766void vnrott(int n);730void tcc_print_stats(TCCState *s, int64_t total_time);
767void lexpand_nr(void);
768static void vpush_global_sym(CType *type, int v);
769void vset(CType *type, int r, int v);
770void type_to_str(char *buf, int buf_size,
771 CType *type, const char *varstr);
772char *get_tok_str(int v, CValue *cv);
773static Sym *get_sym_ref(CType *type, Section *sec,
774 unsigned long offset, unsigned long size);
775static Sym *external_global_sym(int v, CType *type, int r);
776
777/* section generation */
778static void section_realloc(Section *sec, unsigned long new_size);
779static void *section_ptr_add(Section *sec, unsigned long size);
780static void put_extern_sym(Sym *sym, Section *section,
781 unsigned long value, unsigned long size);
782static void greloc(Section *s, Sym *sym, unsigned long addr, int type);
783static int put_elf_str(Section *s, const char *sym);
784static int put_elf_sym(Section *s,
785 unsigned long value, unsigned long size,
786 int info, int other, int shndx, const char *name);
787static int add_elf_sym(Section *s, unsigned long value, unsigned long size,
788 int info, int other, int sh_num, const char *name);
789static void put_elf_reloc(Section *symtab, Section *s, unsigned long offset,
790 int type, int symbol);
791static void put_stabs(const char *str, int type, int other, int desc,
792 unsigned long value);
793static void put_stabs_r(const char *str, int type, int other, int desc,
794 unsigned long value, Section *sec, int sym_index);
795static void put_stabn(int type, int other, int desc, int value);
796static void put_stabd(int type, int other, int desc);
797static int tcc_add_dll(TCCState *s, const char *filename, int flags);
798
799#define AFF_PRINT_ERROR 0x0001 /* print error if file not found */
800#define AFF_REFERENCED_DLL 0x0002 /* load a referenced dll from another dll */
801#define AFF_PREPROCESS 0x0004 /* preprocess file */
802static int tcc_add_file_internal(TCCState *s, const char *filename, int flags);
803
804/* tcccoff.c */
805int tcc_output_coff(TCCState *s1, FILE *f);
806
807/* tccpe.c */
808void *resolve_sym(TCCState *s1, const char *sym, int type);
809int pe_load_def_file(struct TCCState *s1, int fd);
810int pe_test_res_file(void *v, int size);
811int pe_load_res_file(struct TCCState *s1, int fd);
812void pe_add_runtime(struct TCCState *s1);
813void pe_guess_outfile(char *objfilename, int output_type);
814int pe_output_file(struct TCCState *s1, const char *filename);
815
816/* tccasm.c */
817
818#ifdef CONFIG_TCC_ASM
819 731
820typedef struct ExprValue {732static void tcc_free(void *ptr);
821 uint32_t v;733static void *tcc_malloc(unsigned long size);
822 Sym *sym;734static void *tcc_mallocz(unsigned long size);
823} ExprValue;735static void *tcc_realloc(void *ptr, unsigned long size);
824 736static char *tcc_strdup(const char *str);
825#define MAX_ASM_OPERANDS 30
826
827typedef struct ASMOperand {
828 int id; /* GCC 3 optionnal identifier (0 if number only supported */
829 char *constraint;
830 char asm_str[16]; /* computed asm string for operand */
831 SValue *vt; /* C value of the expression */
832 int ref_index; /* if >= 0, gives reference to a output constraint */
833 int input_index; /* if >= 0, gives reference to an input constraint */
834 int priority; /* priority, used to assign registers */
835 int reg; /* if >= 0, register number used for this operand */
836 int is_llong; /* true if double register value */
837 int is_memory; /* true if memory operand */
838 int is_rw; /* for '+' modifier */
839} ASMOperand;
840
841static void asm_expr(TCCState *s1, ExprValue *pe);
842static int asm_int_expr(TCCState *s1);
843static int find_constraint(ASMOperand *operands, int nb_operands,
844 const char *name, const char **pp);
845 737
846static int tcc_assemble(TCCState *s1, int do_preprocess);738static char *tcc_basename(const char *name);
847 739static char *tcc_fileextension (const char *name);
848#endif740static char *pstrcpy(char *buf, int buf_size, const char *s);
849 741static char *pstrcat(char *buf, int buf_size, const char *s);
850static void asm_instr(void);742static void dynarray_add(void ***ptab, int *nb_ptr, void *data);
851static void asm_global_instr(void);743static void dynarray_reset(void *pp, int *n);
852 744
853#ifdef CONFIG_TCC_BACKTRACE745#ifdef CONFIG_TCC_BACKTRACE
854extern int num_callers;746extern int num_callers;
@@ -863,3 +755,9 @@ static inline int is_float(int t) · 8 unmodified lines
863 return bt == VT_LDOUBLE || bt == VT_DOUBLE || bt == VT_FLOAT;755 return bt == VT_LDOUBLE || bt == VT_DOUBLE || bt == VT_FLOAT;
864}756}
865 757
758/* space exlcuding newline */
759static inline int is_space(int ch)
760{
761 return ch == ' ' || ch == '\t' || ch == '\v' || ch == '\f' || ch == '\r';
762}
763
tccpp.c+11−6
@@ -32,6 +32,17 @@ static char tok_two_chars[] = "<=\236>=\235!=\225&&\240||\241++\244--\242==\224< · 31 unmodified lines
32static unsigned char isidnum_table[256-CH_EOF];32static unsigned char isidnum_table[256-CH_EOF];
33 33
34 34
35struct macro_level {
36 struct macro_level *prev;
37 int *p;
38};
39
40static void next_nomacro(void);
41static void next_nomacro_spc(void);
42static void macro_subst(TokenString *tok_str, Sym **nested_list,
43 const int *macro_str, struct macro_level **can_read_stream);
44
45
35/* allocate a new token */46/* allocate a new token */
36static TokenSym *tok_alloc_new(TokenSym **pts, const char *str, int len)47static TokenSym *tok_alloc_new(TokenSym **pts, const char *str, int len)
37{48{
@@ -439,12 +450,6 @@ static uint8_t *parse_comment(uint8_t *p) · 401 unmodified lines
439 450
440#define cinp minp451#define cinp minp
441 452
442/* space exlcuding newline */
443LIBTCCAPI static inline int is_space(int ch)
444{
445 return ch == ' ' || ch == '\t' || ch == '\v' || ch == '\f' || ch == '\r';
446}
447
448static inline void skip_spaces(void)453static inline void skip_spaces(void)
449{454{
450 while (is_space(ch))455 while (is_space(ch))

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