use faster I/O functions - static compile patches

This commit is contained in:
bellard 2001-12-06 23:39:24 +00:00
parent d7e05e1b8f
commit 711075fe3b

60
tcc.c
View File

@ -17,7 +17,12 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
#include <tcclib.h> #include <stdlib.h>
#include <stdio.h>
#include <string.h>
#ifndef CONFIG_TCC_STATIC
#include <dlfcn.h>
#endif
//#define DEBUG //#define DEBUG
/* preprocessor debug */ /* preprocessor debug */
@ -103,6 +108,10 @@ typedef struct {
int line_num; int line_num;
} IncludeFile; } IncludeFile;
/* parser */
FILE *file;
int ch, ch1, tok, tokc, tok1, tok1c;
/* loc : local variable index /* loc : local variable index
glo : global variable index glo : global variable index
ind : output code ptr ind : output code ptr
@ -110,8 +119,7 @@ typedef struct {
prog: output code prog: output code
anon_sym: anonymous symbol index anon_sym: anonymous symbol index
*/ */
FILE *file; int rsym, anon_sym,
int tok, tokc, tok1, tok1c, rsym, anon_sym,
prog, ind, loc, glo, vt, vc, const_wanted, line_num; prog, ind, loc, glo, vt, vc, const_wanted, line_num;
int global_expr; /* true if compound literals must be allocated int global_expr; /* true if compound literals must be allocated
globally (used during initializers parsing */ globally (used during initializers parsing */
@ -309,20 +317,49 @@ int pointed_size(int t);
int ist(void); int ist(void);
int type_decl(int *v, int t, int td); int type_decl(int *v, int t, int td);
#ifdef PROFILE #ifdef CONFIG_TCC_STATIC
#define RTLD_LAZY 0x001
#define RTLD_NOW 0x002
#define RTLD_GLOBAL 0x100
/* dummy function for profiling */ /* dummy function for profiling */
void *dlopen(const char *filename, int flag) void *dlopen(const char *filename, int flag)
{ {
return (void *)1; return NULL;
} }
const char *dlerror(void) const char *dlerror(void)
{ {
return "error"; return "error";
} }
typedef struct TCCSyms {
char *str;
void *ptr;
} TCCSyms;
#define TCCSYM(a) { #a, &a, },
/* add the symbol you want here if no dynamic linking is done */
static TCCSyms tcc_syms[] = {
TCCSYM(printf)
TCCSYM(fprintf)
TCCSYM(fopen)
TCCSYM(fclose)
{ NULL, NULL },
};
void *dlsym(void *handle, char *symbol) void *dlsym(void *handle, char *symbol)
{ {
return (void *)1; TCCSyms *p;
p = tcc_syms;
while (p->str != NULL) {
if (!strcmp(p->str, symbol))
return p->ptr;
p++;
}
return NULL;
} }
#endif #endif
@ -576,13 +613,12 @@ void sym_pop(SymStack *st, Sym *b)
st->top = b; st->top = b;
} }
int ch, ch1;
/* read next char from current input file */ /* read next char from current input file */
void inp() void inp(void)
{ {
redo: redo:
ch1 = fgetc(file); /* faster than fgetc */
ch1 = getc_unlocked(file);
if (ch1 == -1) { if (ch1 == -1) {
if (include_stack_ptr == include_stack) if (include_stack_ptr == include_stack)
return; return;
@ -3887,10 +3923,6 @@ int main(int argc, char **argv)
if (!s) if (!s)
error("main() not defined"); error("main() not defined");
t = (int (*)())s->c; t = (int (*)())s->c;
#ifdef PROFILE
return 1;
#else
return (*t)(argc - optind, argv + optind); return (*t)(argc - optind, argv + optind);
#endif
} }
} }