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
1717 * along with this program; if not, write to the Free Software
1818 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
1919 */
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
2126
2227 //#define DEBUG
2328 /* preprocessor debug */
@@ -103,6 +108,10 @@ typedef struct { · 79 unmodified lines
103108 int line_num;
104109 } IncludeFile;
105110
111+/* parser */
112+FILE *file;
113+int ch, ch1, tok, tokc, tok1, tok1c;
114+
106115 /* loc : local variable index
107116 glo : global variable index
108117 ind : output code ptr
@@ -110,8 +119,7 @@ typedef struct { · 1 unmodified line
110119 prog: output code
111120 anon_sym: anonymous symbol index
112121 */
113−FILE *file;
114−int tok, tokc, tok1, tok1c, rsym, anon_sym,
122+int rsym, anon_sym,
115123 prog, ind, loc, glo, vt, vc, const_wanted, line_num;
116124 int global_expr; /* true if compound literals must be allocated
117125 globally (used during initializers parsing */
@@ -309,20 +317,49 @@ int pointed_size(int t); · 191 unmodified lines
309317 int ist(void);
310318 int type_decl(int *v, int t, int td);
311319
312−#ifdef PROFILE
320+#ifdef CONFIG_TCC_STATIC
321+
322+#define RTLD_LAZY 0x001
323+#define RTLD_NOW 0x002
324+#define RTLD_GLOBAL 0x100
325+
313326 /* dummy function for profiling */
314327 void *dlopen(const char *filename, int flag)
315328 {
316− return (void *)1;
329+ return NULL;
317330 }
331+
318332 const char *dlerror(void)
319333 {
320334 return "error";
321335 }
322336
337+typedef 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 */
345+static TCCSyms tcc_syms[] = {
346+ TCCSYM(printf)
347+ TCCSYM(fprintf)
348+ TCCSYM(fopen)
349+ TCCSYM(fclose)
350+ { NULL, NULL },
351+};
352+
323353 void *dlsym(void *handle, char *symbol)
324354 {
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;
326363 }
327364
328365 #endif
@@ -576,13 +613,12 @@ void sym_pop(SymStack *st, Sym *b) · 247 unmodified lines
576613 st->top = b;
577614 }
578615
579−int ch, ch1;
580−
581616 /* read next char from current input file */
582−void inp()
617+void inp(void)
583618 {
584619 redo:
585− ch1 = fgetc(file);
620+ /* faster than fgetc */
621+ ch1 = getc_unlocked(file);
586622 if (ch1 == -1) {
587623 if (include_stack_ptr == include_stack)
588624 return;
@@ -3887,10 +3923,6 @@ int main(int argc, char **argv) · 3298 unmodified lines
38873923 if (!s)
38883924 error("main() not defined");
38893925 t = (int (*)())s->c;
3890−#ifdef PROFILE
3891− return 1;
3892−#else
38933926 return (*t)(argc - optind, argv + optind);
3894−#endif
38953927 }
38963928 }

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