History

use faster I/O functions - static compile patches

bellard committed 24 years ago

Commit 711075f1 parent d7e05e11 file · +46 −14Browse files

Unified · Split

tcc.c+46−14
@@ -17,7 +17,12 @@ · 16 unmodified lines
17 * along with this program; if not, write to the Free Software17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */19 */
20#include <tcclib.h>20#include <stdlib.h>
21#include <stdio.h>
22#include <string.h>
23#ifndef CONFIG_TCC_STATIC
24#include <dlfcn.h>
25#endif
21 26
22//#define DEBUG27//#define DEBUG
23/* preprocessor debug */28/* preprocessor debug */
@@ -103,6 +108,10 @@ typedef struct { · 79 unmodified lines
103 int line_num;108 int line_num;
104} IncludeFile;109} IncludeFile;
105 110
111/* parser */
112FILE *file;
113int ch, ch1, tok, tokc, tok1, tok1c;
114
106/* loc : local variable index115/* loc : local variable index
107 glo : global variable index116 glo : global variable index
108 ind : output code ptr117 ind : output code ptr
@@ -110,8 +119,7 @@ typedef struct { · 1 unmodified line
110 prog: output code119 prog: output code
111 anon_sym: anonymous symbol index120 anon_sym: anonymous symbol index
112*/121*/
113FILE *file;122int rsym, anon_sym,
114int tok, tokc, tok1, tok1c, rsym, anon_sym,
115 prog, ind, loc, glo, vt, vc, const_wanted, line_num;123 prog, ind, loc, glo, vt, vc, const_wanted, line_num;
116int global_expr; /* true if compound literals must be allocated124int global_expr; /* true if compound literals must be allocated
117 globally (used during initializers parsing */125 globally (used during initializers parsing */
@@ -309,20 +317,49 @@ int pointed_size(int t); · 191 unmodified lines
309int ist(void);317int ist(void);
310int type_decl(int *v, int t, int td);318int type_decl(int *v, int t, int td);
311 319
312#ifdef PROFILE320#ifdef CONFIG_TCC_STATIC
321
322#define RTLD_LAZY 0x001
323#define RTLD_NOW 0x002
324#define RTLD_GLOBAL 0x100
325
313/* dummy function for profiling */326/* dummy function for profiling */
314void *dlopen(const char *filename, int flag)327void *dlopen(const char *filename, int flag)
315{328{
316 return (void *)1;329 return NULL;
317}330}
331
318const char *dlerror(void)332const char *dlerror(void)
319{333{
320 return "error";334 return "error";
321}335}
322 336
337typedef struct TCCSyms {
338 char *str;
339 void *ptr;
340} TCCSyms;
341
342#define TCCSYM(a) { #a, &a, },
343
344/* add the symbol you want here if no dynamic linking is done */
345static TCCSyms tcc_syms[] = {
346 TCCSYM(printf)
347 TCCSYM(fprintf)
348 TCCSYM(fopen)
349 TCCSYM(fclose)
350 { NULL, NULL },
351};
352
323void *dlsym(void *handle, char *symbol)353void *dlsym(void *handle, char *symbol)
324{354{
325 return (void *)1;355 TCCSyms *p;
356 p = tcc_syms;
357 while (p->str != NULL) {
358 if (!strcmp(p->str, symbol))
359 return p->ptr;
360 p++;
361 }
362 return NULL;
326}363}
327 364
328#endif365#endif
@@ -576,13 +613,12 @@ void sym_pop(SymStack *st, Sym *b) · 247 unmodified lines
576 st->top = b;613 st->top = b;
577}614}
578 615
579int ch, ch1;
580
581/* read next char from current input file */616/* read next char from current input file */
582void inp()617void inp(void)
583{618{
584 redo:619 redo:
585 ch1 = fgetc(file);620 /* faster than fgetc */
621 ch1 = getc_unlocked(file);
586 if (ch1 == -1) {622 if (ch1 == -1) {
587 if (include_stack_ptr == include_stack)623 if (include_stack_ptr == include_stack)
588 return;624 return;
@@ -3887,10 +3923,6 @@ int main(int argc, char **argv) · 3298 unmodified lines
3887 if (!s)3923 if (!s)
3888 error("main() not defined");3924 error("main() not defined");
3889 t = (int (*)())s->c;3925 t = (int (*)())s->c;
3890#ifdef PROFILE
3891 return 1;
3892#else
3893 return (*t)(argc - optind, argv + optind);3926 return (*t)(argc - optind, argv + optind);
3894#endif
3895 }3927 }
3896}3928}

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