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
2020
2121 #include "tcc.h"
2222
23+/********************************************************/
24+/* global variables */
25+
2326 /* display benchmark infos */
2427 int total_lines;
2528 int total_bytes;
@@ -112,6 +115,126 @@ const char **rt_bound_error_msg; · 86 unmodified lines
112115 /* XXX: get rid of this ASAP */
113116 static struct TCCState *tcc_state;
114117
118+/********************************************************/
119+/* function prototypes */
120+
121+/* tccpp.c */
122+static void next(void);
123+char *get_tok_str(int v, CValue *cv);
124+
125+/* tccgen.c */
126+static void parse_expr_type(CType *type);
127+static void expr_type(CType *type);
128+static void unary_type(CType *type);
129+static void block(int *bsym, int *csym, int *case_sym, int *def_sym,
130+ int case_reg, int is_expr);
131+static int expr_const(void);
132+static void expr_eq(void);
133+static void gexpr(void);
134+static void gen_inline_functions(void);
135+static void decl(int l);
136+static void decl_initializer(CType *type, Section *sec, unsigned long c,
137+ int first, int size_only);
138+static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r,
139+ int has_init, int v, int scope);
140+int gv(int rc);
141+void gv2(int rc1, int rc2);
142+void move_reg(int r, int s);
143+void save_regs(int n);
144+void save_reg(int r);
145+void vpop(void);
146+void vswap(void);
147+void vdup(void);
148+int get_reg(int rc);
149+int get_reg_ex(int rc,int rc2);
150+
151+void gen_op(int op);
152+void force_charshort_cast(int t);
153+static void gen_cast(CType *type);
154+void vstore(void);
155+static Sym *sym_find(int v);
156+static Sym *sym_push(int v, CType *type, int r, int c);
157+
158+/* type handling */
159+static int type_size(CType *type, int *a);
160+static inline CType *pointed_type(CType *type);
161+static int pointed_size(CType *type);
162+static int lvalue_type(int t);
163+static int parse_btype(CType *type, AttributeDef *ad);
164+static void type_decl(CType *type, AttributeDef *ad, int *v, int td);
165+static int compare_types(CType *type1, CType *type2, int unqualified);
166+static int is_compatible_types(CType *type1, CType *type2);
167+static int is_compatible_parameter_types(CType *type1, CType *type2);
168+
169+int ieee_finite(double d);
170+void vpushi(int v);
171+void vpushll(long long v);
172+void vrott(int n);
173+void vnrott(int n);
174+void lexpand_nr(void);
175+static void vpush_global_sym(CType *type, int v);
176+void vset(CType *type, int r, int v);
177+void type_to_str(char *buf, int buf_size,
178+ CType *type, const char *varstr);
179+static Sym *get_sym_ref(CType *type, Section *sec,
180+ unsigned long offset, unsigned long size);
181+static Sym *external_global_sym(int v, CType *type, int r);
182+
183+/* section generation */
184+static void section_realloc(Section *sec, unsigned long new_size);
185+static void *section_ptr_add(Section *sec, unsigned long size);
186+static void put_extern_sym(Sym *sym, Section *section,
187+ unsigned long value, unsigned long size);
188+static void greloc(Section *s, Sym *sym, unsigned long addr, int type);
189+static int put_elf_str(Section *s, const char *sym);
190+static int put_elf_sym(Section *s,
191+ unsigned long value, unsigned long size,
192+ int info, int other, int shndx, const char *name);
193+static int add_elf_sym(Section *s, unsigned long value, unsigned long size,
194+ int info, int other, int sh_num, const char *name);
195+static void put_elf_reloc(Section *symtab, Section *s, unsigned long offset,
196+ int type, int symbol);
197+static void put_stabs(const char *str, int type, int other, int desc,
198+ unsigned long value);
199+static void put_stabs_r(const char *str, int type, int other, int desc,
200+ unsigned long value, Section *sec, int sym_index);
201+static void put_stabn(int type, int other, int desc, int value);
202+static void put_stabd(int type, int other, int desc);
203+static 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 */
208+static int tcc_add_file_internal(TCCState *s, const char *filename, int flags);
209+
210+/* tcccoff.c */
211+int tcc_output_coff(TCCState *s1, FILE *f);
212+
213+/* tccpe.c */
214+void *resolve_sym(TCCState *s1, const char *sym, int type);
215+int pe_load_def_file(struct TCCState *s1, int fd);
216+int pe_test_res_file(void *v, int size);
217+int pe_load_res_file(struct TCCState *s1, int fd);
218+void pe_add_runtime(struct TCCState *s1);
219+void pe_guess_outfile(char *objfilename, int output_type);
220+int pe_output_file(struct TCCState *s1, const char *filename);
221+
222+/* tccasm.c */
223+#ifdef CONFIG_TCC_ASM
224+static void asm_expr(TCCState *s1, ExprValue *pe);
225+static int asm_int_expr(TCCState *s1);
226+static int find_constraint(ASMOperand *operands, int nb_operands,
227+ const char *name, const char **pp);
228+
229+static int tcc_assemble(TCCState *s1, int do_preprocess);
230+#endif
231+
232+static void asm_instr(void);
233+static void asm_global_instr(void);
234+
235+/********************************************************/
236+/* global variables */
237+
115238 #ifdef TCC_TARGET_I386
116239 #include "i386-gen.c"
117240 #endif
@@ -2118,7 +2241,7 @@ void tcc_set_lib_path(TCCState *s, const char *path) · 2000 unmodified lines
21182241 s->tcc_lib_path = tcc_strdup(path);
21192242 }
21202243
2121−LIBTCCAPI void print_stats(TCCState *s, int64_t total_time)
2244+void tcc_print_stats(TCCState *s, int64_t total_time)
21222245 {
21232246 double tt;
21242247 tt = (double)total_time / 1000000.0;
tcc.c+1−1
@@ -531,7 +531,7 @@ int main(int argc, char **argv) · 530 unmodified lines
531531 goto the_end;
532532
533533 if (do_bench)
534− print_stats(s, getclock_us() - start_time);
534+ tcc_print_stats(s, getclock_us() - start_time);
535535
536536 if (s->output_type == TCC_OUTPUT_PREPROCESS) {
537537 if (outfile)
tcc.h+44−146
@@ -341,6 +341,29 @@ typedef struct CachedInclude { · 340 unmodified lines
341341
342342 #define CACHED_INCLUDES_HASH_SIZE 512
343343
344+#ifdef CONFIG_TCC_ASM
345+typedef struct ExprValue {
346+ uint32_t v;
347+ Sym *sym;
348+} ExprValue;
349+
350+#define MAX_ASM_OPERANDS 30
351+typedef 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+
344367 struct TCCState {
345368 int output_type;
346369
@@ -700,155 +723,24 @@ extern long double strtold (const char *__nptr, char **__endptr); · 353 unmodified lines
700723 #define PATHCMP strcmp
701724 #endif
702725
703−static char *pstrcpy(char *buf, int buf_size, const char *s);
704−static char *pstrcat(char *buf, int buf_size, const char *s);
705−static char *tcc_basename(const char *name);
706−static char *tcc_fileextension (const char *p);
707−
708−static void next(void);
709−static void next_nomacro(void);
710−static void next_nomacro_spc(void);
711−static void parse_expr_type(CType *type);
712−static void expr_type(CType *type);
713−static void unary_type(CType *type);
714−static void block(int *bsym, int *csym, int *case_sym, int *def_sym,
715− int case_reg, int is_expr);
716−static int expr_const(void);
717−static void expr_eq(void);
718−static void gexpr(void);
719−static void gen_inline_functions(void);
720−static void decl(int l);
721−static void decl_initializer(CType *type, Section *sec, unsigned long c,
722− int first, int size_only);
723−static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r,
724− int has_init, int v, int scope);
725−int gv(int rc);
726−void gv2(int rc1, int rc2);
727−void move_reg(int r, int s);
728−void save_regs(int n);
729−void save_reg(int r);
730−void vpop(void);
731−void vswap(void);
732−void vdup(void);
733−int get_reg(int rc);
734−int get_reg_ex(int rc,int rc2);
735−
736−struct macro_level {
737− struct macro_level *prev;
738− int *p;
739−};
740−
741−static void macro_subst(TokenString *tok_str, Sym **nested_list,
742− const int *macro_str, struct macro_level **can_read_stream);
743−void gen_op(int op);
744−void force_charshort_cast(int t);
745−static void gen_cast(CType *type);
746−void vstore(void);
747−static Sym *sym_find(int v);
748−static Sym *sym_push(int v, CType *type, int r, int c);
749−
750−/* type handling */
751−static int type_size(CType *type, int *a);
752−static inline CType *pointed_type(CType *type);
753−static int pointed_size(CType *type);
754−static int lvalue_type(int t);
755−static int parse_btype(CType *type, AttributeDef *ad);
756−static void type_decl(CType *type, AttributeDef *ad, int *v, int td);
757−static int compare_types(CType *type1, CType *type2, int unqualified);
758−static int is_compatible_types(CType *type1, CType *type2);
759−static int is_compatible_parameter_types(CType *type1, CType *type2);
760−
761−int ieee_finite(double d);
762726 void error(const char *fmt, ...);
763−void vpushi(int v);
764−void vpushll(long long v);
765−void vrott(int n);
766−void vnrott(int n);
767−void lexpand_nr(void);
768−static void vpush_global_sym(CType *type, int v);
769−void vset(CType *type, int r, int v);
770−void type_to_str(char *buf, int buf_size,
771− CType *type, const char *varstr);
772−char *get_tok_str(int v, CValue *cv);
773−static Sym *get_sym_ref(CType *type, Section *sec,
774− unsigned long offset, unsigned long size);
775−static Sym *external_global_sym(int v, CType *type, int r);
776−
777−/* section generation */
778−static void section_realloc(Section *sec, unsigned long new_size);
779−static void *section_ptr_add(Section *sec, unsigned long size);
780−static void put_extern_sym(Sym *sym, Section *section,
781− unsigned long value, unsigned long size);
782−static void greloc(Section *s, Sym *sym, unsigned long addr, int type);
783−static int put_elf_str(Section *s, const char *sym);
784−static int put_elf_sym(Section *s,
785− unsigned long value, unsigned long size,
786− int info, int other, int shndx, const char *name);
787−static int add_elf_sym(Section *s, unsigned long value, unsigned long size,
788− int info, int other, int sh_num, const char *name);
789−static void put_elf_reloc(Section *symtab, Section *s, unsigned long offset,
790− int type, int symbol);
791−static void put_stabs(const char *str, int type, int other, int desc,
792− unsigned long value);
793−static void put_stabs_r(const char *str, int type, int other, int desc,
794− unsigned long value, Section *sec, int sym_index);
795−static void put_stabn(int type, int other, int desc, int value);
796−static void put_stabd(int type, int other, int desc);
797−static 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 */
802−static int tcc_add_file_internal(TCCState *s, const char *filename, int flags);
803−
804−/* tcccoff.c */
805−int tcc_output_coff(TCCState *s1, FILE *f);
806−
807−/* tccpe.c */
808−void *resolve_sym(TCCState *s1, const char *sym, int type);
809−int pe_load_def_file(struct TCCState *s1, int fd);
810−int pe_test_res_file(void *v, int size);
811−int pe_load_res_file(struct TCCState *s1, int fd);
812−void pe_add_runtime(struct TCCState *s1);
813−void pe_guess_outfile(char *objfilename, int output_type);
814−int pe_output_file(struct TCCState *s1, const char *filename);
815−
816−/* tccasm.c */
817−
818−#ifdef CONFIG_TCC_ASM
727+void warning(const char *fmt, ...);
728+void tcc_set_lib_path_w32(TCCState *s);
729+int tcc_set_flag(TCCState *s, const char *flag_name, int value);
730+void tcc_print_stats(TCCState *s, int64_t total_time);
819731
820−typedef struct ExprValue {
821− uint32_t v;
822− Sym *sym;
823−} ExprValue;
824−
825−#define MAX_ASM_OPERANDS 30
826−
827−typedef 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−
841−static void asm_expr(TCCState *s1, ExprValue *pe);
842−static int asm_int_expr(TCCState *s1);
843−static int find_constraint(ASMOperand *operands, int nb_operands,
844− const char *name, const char **pp);
732+static void tcc_free(void *ptr);
733+static void *tcc_malloc(unsigned long size);
734+static void *tcc_mallocz(unsigned long size);
735+static void *tcc_realloc(void *ptr, unsigned long size);
736+static char *tcc_strdup(const char *str);
845737
846−static int tcc_assemble(TCCState *s1, int do_preprocess);
847−
848−#endif
849−
850−static void asm_instr(void);
851−static void asm_global_instr(void);
738+static char *tcc_basename(const char *name);
739+static char *tcc_fileextension (const char *name);
740+static char *pstrcpy(char *buf, int buf_size, const char *s);
741+static char *pstrcat(char *buf, int buf_size, const char *s);
742+static void dynarray_add(void ***ptab, int *nb_ptr, void *data);
743+static void dynarray_reset(void *pp, int *n);
852744
853745 #ifdef CONFIG_TCC_BACKTRACE
854746 extern int num_callers;
@@ -863,3 +755,9 @@ static inline int is_float(int t) · 8 unmodified lines
863755 return bt == VT_LDOUBLE || bt == VT_DOUBLE || bt == VT_FLOAT;
864756 }
865757
758+/* space exlcuding newline */
759+static 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
3232 static unsigned char isidnum_table[256-CH_EOF];
3333
3434
35+struct macro_level {
36+ struct macro_level *prev;
37+ int *p;
38+};
39+
40+static void next_nomacro(void);
41+static void next_nomacro_spc(void);
42+static void macro_subst(TokenString *tok_str, Sym **nested_list,
43+ const int *macro_str, struct macro_level **can_read_stream);
44+
45+
3546 /* allocate a new token */
3647 static TokenSym *tok_alloc_new(TokenSym **pts, const char *str, int len)
3748 {
@@ -439,12 +450,6 @@ static uint8_t *parse_comment(uint8_t *p) · 401 unmodified lines
439450
440451 #define cinp minp
441452
442−/* space exlcuding newline */
443−LIBTCCAPI static inline int is_space(int ch)
444−{
445− return ch == ' ' || ch == '\t' || ch == '\v' || ch == '\f' || ch == '\r';
446−}
447−
448453 static inline void skip_spaces(void)
449454 {
450455 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