changeset 554:8c020de0af57

Fix earlier options.c break-up by migrating some stuff from tcc.h to tinycc.h. (This means i386-tinycc can once again rebuild itself without segfaulting.)
author Rob Landley <rob@landley.net>
date Thu, 06 Mar 2008 20:53:55 -0600
parents 4533aa54ffcf
children 646f1f0972b6
files options.c tcc.c tcc.h tccelf.c tinycc.h
diffstat 5 files changed, 259 insertions(+), 171 deletions(-) [+]
line wrap: on
line diff
--- a/options.c	Mon Jan 21 00:29:43 2008 -0600
+++ b/options.c	Thu Mar 06 20:53:55 2008 -0600
@@ -7,17 +7,8 @@
  *  Licensed under GPLv2, see file LICENSE in this tarball
  */
 
-#include "tcc.h"
-
+#include "tinycc.h"
 
-void *xmalloc(unsigned long size);
-void dynarray_add(void ***ptab, int *nb_ptr, void *data);
-void add_dynarray_path(TCCState *s, char *pathname, struct dynarray *dd);
-int strstart(char *str, char *val, char **ptr);
-void warning(char *fmt, ...);
-int init_output_type(TCCState *s);
-
-extern char *tinycc_path;
 int do_bounds_check = 0;
 int do_debug = 0;
 int next_tok_flags;
@@ -36,16 +27,19 @@
 #define FD_INVERT 0x0002 /* invert value before storing */
 
 typedef struct FlagDef {
-    uint16_t offset;
+    //uint16_t offset;
+    int *var;
     uint16_t flags;
     char *name;
 } FlagDef;
 
+// was { offsetof(TCCState, warn_unsupported), 0, "unsupported" },
+
 static FlagDef warning_defs[] = {
-    { offsetof(TCCState, warn_unsupported), 0, "unsupported" },
-    { offsetof(TCCState, warn_write_strings), 0, "write-strings" },
-    { offsetof(TCCState, warn_error), 0, "error" },
-    { offsetof(TCCState, warn_implicit_function_declaration), WD_ALL,
+    { &tccg_warn_unsupported, 0, "unsupported" },
+    { &tccg_warn_write_strings, 0, "write-strings" },
+    { &tccg_warn_error, 0, "error" },
+    { &tccg_warn_implicit_function_declaration, WD_ALL,
       "implicit-function-declaration" },
 };
 
@@ -69,11 +63,11 @@
  found:
     if (p->flags & FD_INVERT)
         value = !value;
-    *(int *)((uint8_t *)s + p->offset) = value;
+    //*(int *)((uint8_t *)s + p->offset) = value;
+    *p->var = value;
     return 0;
 }
 
-
 /* set/reset a warning */
 int tcc_set_warning(TCCState *s, char *warning_name, int value)
 {
@@ -83,7 +77,8 @@
     if (!strcmp(warning_name, "all")) {
         for(i = 0, p = warning_defs; i < countof(warning_defs); i++, p++) {
             if (p->flags & WD_ALL)
-                *(int *)((uint8_t *)s + p->offset) = 1;
+                // *(int *)((uint8_t *)s + p->offset) = 1;
+                *p->var = 1;
         }
         return 0;
     } else {
@@ -93,10 +88,10 @@
 }
 
 static FlagDef flag_defs[] = {
-    { offsetof(TCCState, char_is_unsigned), 0, "unsigned-char" },
-    { offsetof(TCCState, char_is_unsigned), FD_INVERT, "signed-char" },
-    { offsetof(TCCState, nocommon), FD_INVERT, "common" },
-    { offsetof(TCCState, leading_underscore), 0, "leading-underscore" },
+    { &tccg_char_is_unsigned, 0, "unsigned-char" },
+    { &tccg_char_is_unsigned, FD_INVERT, "signed-char" },
+    { &tccg_nocommon, FD_INVERT, "common" },
+    { &tccg_leading_underscore, 0, "leading-underscore" },
 };
 
 /* set/reset a flag */
@@ -302,7 +297,7 @@
     while (1) {
         if (optind >= argc) {
             if (nb_files == 0 && !print_search_dirs) {
-                if (!s->verbose) help(s);
+                if (!tccg_verbose) help(s);
                 exit(1);
             } else break;
         }
@@ -355,7 +350,7 @@
                 help(s);
                 exit(1);
             case TCC_OPTION_I:
-                add_dynarray_path(s, optarg, &(s->include_paths));
+                add_dynarray_path(s, optarg, &tccg_include_paths);
                 break;
             case TCC_OPTION_D:
                 {
@@ -370,13 +365,13 @@
                 }
                 break;
             case TCC_OPTION_E:
-                s->output_type = TCC_OUTPUT_PREPROCESS;
+                tccg_output_type = TCC_OUTPUT_PREPROCESS;
                 break;
             case TCC_OPTION_U:
                 tcc_undefine_symbol(s, optarg);
                 break;
             case TCC_OPTION_L:
-                add_dynarray_path(s, optarg, &(s->library_paths));
+                add_dynarray_path(s, optarg, &tccg_library_paths);
                 break;
             case TCC_OPTION_B:
                 /* set tcc utilities path (mainly for tcc development) */
@@ -400,13 +395,13 @@
                 break;
             case TCC_OPTION_c:
                 multiple_files = 1;
-                s->output_type = TCC_OUTPUT_OBJ;
+                tccg_output_type = TCC_OUTPUT_OBJ;
                 break;
             case TCC_OPTION_static:
-                s->static_link = 1;
+                tccg_static_link = 1;
                 break;
             case TCC_OPTION_shared:
-                s->output_type = TCC_OUTPUT_DLL;
+                tccg_output_type = TCC_OUTPUT_DLL;
                 break;
             case TCC_OPTION_o:
                 multiple_files = 1;
@@ -415,13 +410,13 @@
             case TCC_OPTION_r:
                 /* generate a .o merging several output files */
                 reloc_output = 1;
-                s->output_type = TCC_OUTPUT_OBJ;
+                tccg_output_type = TCC_OUTPUT_OBJ;
                 break;
             case TCC_OPTION_nostdinc:
-                s->nostdinc = 1;
+                tccg_nostdinc = 1;
                 break;
             case TCC_OPTION_nostdlib:
-                s->nostdlib = 1;
+                tccg_nostdlib = 1;
                 break;
             case TCC_OPTION_print_search_dirs:
                 print_search_dirs = 1;
@@ -435,42 +430,41 @@
                         parse_args(s, argc1, argv1);
                     }
                     multiple_files = 0;
-                    s->output_type = TCC_OUTPUT_MEMORY;
+                    tccg_output_type = TCC_OUTPUT_MEMORY;
                 }
                 break;
             case TCC_OPTION_v:
-                if (!s->verbose++) show_version();
+                if (!tccg_verbose++) show_version();
                 break;
             case TCC_OPTION_f:
-                if (tcc_set_flag(s, optarg, 1) < 0 && s->warn_unsupported)
+                if (tcc_set_flag(s, optarg, 1) < 0 && tccg_warn_unsupported)
                     goto unsupported_option;
                 break;
             case TCC_OPTION_W:
-                if (tcc_set_warning(s, optarg, 1) < 0 && 
-                    s->warn_unsupported)
+                if (tcc_set_warning(s, optarg, 1) < 0 && tccg_warn_unsupported)
                     goto unsupported_option;
                 break;
             case TCC_OPTION_w:
-                s->warn_none = 1;
+                tccg_warn_none = 1;
                 break;
             case TCC_OPTION_rdynamic:
-                s->rdynamic = 1;
+                tccg_rdynamic = 1;
                 break;
             case TCC_OPTION_Wl:
                 {
                     char *p;
                     if (strstart(optarg, "-Ttext,", &p)) {
-                        s->text_addr = strtoul(p, NULL, 16);
-                        s->has_text_addr = 1;
+                        tccg_text_addr = strtoul(p, NULL, 16);
+                        tccg_has_text_addr = 1;
                     } else if (strstart(optarg, "--oformat,", &p)) {
                         if (strstart(p, "elf32-", NULL)) {
-                            s->output_format = TCC_OUTPUT_FORMAT_ELF;
+                            tccg_output_format = TCC_OUTPUT_FORMAT_ELF;
                         } else if (!strcmp(p, "binary")) {
-                            s->output_format = TCC_OUTPUT_FORMAT_BINARY;
+                            tccg_output_format = TCC_OUTPUT_FORMAT_BINARY;
                         } else
 #ifdef TCC_TARGET_COFF
                         if (!strcmp(p, "coff")) {
-                            s->output_format = TCC_OUTPUT_FORMAT_COFF;
+                            tccg_output_format = TCC_OUTPUT_FORMAT_COFF;
                         } else
 #endif
                         {
@@ -482,8 +476,8 @@
                 }
                 break;
             default:
-                if (s->warn_unsupported) {
-                unsupported_option:
+                if (tccg_warn_unsupported) {
+unsupported_option:
                     warning("unsupported option '%s'", r);
                 }
                 break;
@@ -502,7 +496,7 @@
     int64_t start_time = 0;
 
     s = tcc_new();
-    s->output_type = TCC_OUTPUT_EXE;
+    tccg_output_type = TCC_OUTPUT_EXE;
     outfile = NULL;
     multiple_files = 1;
     files = NULL;
@@ -544,11 +538,11 @@
     nb_objfiles = nb_files - nb_libraries;
 
     // if outfile provided without other options, we output an executable
-    if (outfile && s->output_type == TCC_OUTPUT_MEMORY)
-        s->output_type = TCC_OUTPUT_EXE;
+    if (outfile && tccg_output_type == TCC_OUTPUT_MEMORY)
+        tccg_output_type = TCC_OUTPUT_EXE;
 
     // check -c consistency : only single file handled. XXX: checks file type
-    if (s->output_type == TCC_OUTPUT_OBJ && !reloc_output) {
+    if (tccg_output_type == TCC_OUTPUT_OBJ && !reloc_output) {
         /* accepts only a single input file */
         if (nb_objfiles != 1)
             error("cannot specify multiple files with -c");
@@ -556,22 +550,22 @@
             error("cannot specify libraries with -c");
     }
 
-    if (s->output_type == TCC_OUTPUT_PREPROCESS) {
-        if (!outfile) s->outfile = stdout;
+    if (tccg_output_type == TCC_OUTPUT_PREPROCESS) {
+        if (!outfile) tccg_outfile = stdout;
         else {
-            s->outfile = fopen(outfile, "wb");
-            if (!s->outfile) error("could not open '%s'", outfile);
+            tccg_outfile = fopen(outfile, "wb");
+            if (!tccg_outfile) error("could not open '%s'", outfile);
         }
-    } else if (s->output_type != TCC_OUTPUT_MEMORY) {
+    } else if (tccg_output_type != TCC_OUTPUT_MEMORY) {
         if (!outfile) {
     /* compute default outfile name */
             pstrcpy(objfilename, sizeof(objfilename) - 1, 
                     /* strip path */
                     tcc_basename(files[0]));
 #ifdef TCC_TARGET_PE
-            pe_guess_outfile(objfilename, s->output_type);
+            pe_guess_outfile(objfilename, tccg_output_type);
 #else
-            if (s->output_type == TCC_OUTPUT_OBJ && !reloc_output) {
+            if (tccg_output_type == TCC_OUTPUT_OBJ && !reloc_output) {
                 char *ext = strrchr(objfilename, '.');
             if (!ext)
                 goto default_outfile;
@@ -592,14 +586,14 @@
 
     init_output_type(s);
 
-    /* compile or add each files or library */
-    for(i = 0;i < nb_files; i++) {
+    /* compile or add each file or library */
+    for(i = 0; i < nb_files; i++) {
         char *filename;
 
         next_tok_flags = TOK_FLAG_BOL | TOK_FLAG_BOF | TOK_FLAG_BOW;
 
         filename = files[i];
-        if (s->output_type == TCC_OUTPUT_PREPROCESS) {
+        if (tccg_output_type == TCC_OUTPUT_PREPROCESS) {
             tcc_add_file_internal(s, filename,
                                   AFF_PRINT_ERROR | AFF_PREPROCESS);
         } else if (filename[0] == '-') {
@@ -627,14 +621,14 @@
                total_bytes / total_time / 1000000.0); 
     }
 
-    if (s->output_type == TCC_OUTPUT_PREPROCESS) {
-        if (outfile) fclose(s->outfile);
+    if (tccg_output_type == TCC_OUTPUT_PREPROCESS) {
+        if (outfile) fclose(tccg_outfile);
         ret = 0;
-    } else if (s->output_type == TCC_OUTPUT_MEMORY) {
+    } else if (tccg_output_type == TCC_OUTPUT_MEMORY) {
         ret = tcc_run(s, argc - optind, argv + optind);
     } else
 #ifdef TCC_TARGET_PE
-    if (s->output_type != TCC_OUTPUT_OBJ) {
+    if (tccg_output_type != TCC_OUTPUT_OBJ) {
         ret = tcc_output_pe(s, outfile);
     } else
 #endif
--- a/tcc.c	Mon Jan 21 00:29:43 2008 -0600
+++ b/tcc.c	Thu Mar 06 20:53:55 2008 -0600
@@ -7,6 +7,7 @@
  *  Licensed under GPLv2, see file LICENSE in this tarball
  */
 
+#include "tinycc.h"
 #include "tcc.h"
 
 // This stuff is used by the code generation backend.
@@ -396,7 +397,7 @@
             }
         }
 #endif
-        if (tcc_state->leading_underscore && can_add_underscore) {
+        if (tccg_leading_underscore && can_add_underscore) {
             buf1[0] = '_';
             pstrcpy(buf1 + 1, sizeof(buf1) - 1, name);
             name = buf1;
@@ -485,7 +486,7 @@
     } else {
         s1->error_func(s1->error_opaque, buf);
     }
-    if (!is_warning || s1->warn_error)
+    if (!is_warning || tccg_warn_error)
         s1->nb_errors++;
 }
 
@@ -536,7 +537,7 @@
     TCCState *s1 = tcc_state;
     va_list ap;
 
-    if (s1->warn_none)
+    if (tccg_warn_none)
         return;
 
     va_start(ap, fmt);
@@ -1003,10 +1004,10 @@
 }
 
 /* space excluding newline */
-//static inline int is_space(int ch)
-//{
-//    return ch == ' ' || ch == '\t' || ch == '\v' || ch == '\f' || ch == '\r';
-//}
+int is_space(int ch)
+{
+    return strchr(" \t\v\f\r", ch);
+}
 
 /* handle '\[\r]\n' */
 static int handle_stray_noerror(void)
@@ -2006,16 +2007,16 @@
             if (s1->include_stack_ptr >= s1->include_stack + INCLUDE_STACK_SIZE)
                 error("#include recursion too deep");
             /* now search in all the include paths */
-            n = s1->include_paths.len + s1->sysinclude_paths.len;
+            n = tccg_include_paths.len + s1->sysinclude_paths.len;
             for(i = 0; i < n; i++) {
                 char *path;
-                int verbose = s1->verbose;
+                int verbose = tccg_verbose;
 
                 verbose -= (s1->include_stack_ptr != s1->include_stack);
-                if (i < s1->include_paths.len)
-                    path = s1->include_paths.data[i];
+                if (i < tccg_include_paths.len)
+                    path = tccg_include_paths.data[i];
                 else
-                    path = s1->sysinclude_paths.data[i - s1->include_paths.len];
+                    path = s1->sysinclude_paths.data[i - tccg_include_paths.len];
                 pstrcpy(buf1, sizeof(buf1), path);
                 pstrcat(buf1, sizeof(buf1), "/");
                 pstrcat(buf1, sizeof(buf1), buf);
@@ -5615,7 +5616,7 @@
             ad->dllexport = 1;
             break;
         default:
-            if (tcc_state->warn_unsupported)
+            if (tccg_warn_unsupported)
                 warning("'%s' attribute ignored", get_tok_str(t, NULL));
             /* skip parameters */
             if (tok == '(') {
@@ -5994,7 +5995,7 @@
 the_end:
     if ((t & (VT_SIGNED|VT_UNSIGNED)) == (VT_SIGNED|VT_UNSIGNED))
       error("signed and unsigned modifier");
-    if (tcc_state->char_is_unsigned) {
+    if (tccg_char_is_unsigned) {
         if ((t & (VT_SIGNED|VT_UNSIGNED|VT_BTYPE)) == VT_BYTE)
             t |= VT_UNSIGNED;
     }
@@ -6376,7 +6377,7 @@
         /* string parsing */
         t = VT_BYTE;
     str_init:
-        if (tcc_state->warn_write_strings)
+        if (tccg_warn_write_strings)
             t |= VT_CONSTANT;
         type.t = t;
         mk_pointer(&type);
@@ -6563,7 +6564,7 @@
                 error("'%s' undeclared", get_tok_str(t, NULL));
             /* for simple function calls, we tolerate undeclared
                external reference to int() function */
-            if (tcc_state->warn_implicit_function_declaration)
+            if (tccg_warn_implicit_function_declaration)
                 warning("implicit declaration of function '%s'",
                         get_tok_str(t, NULL));
             s = external_global_sym(t, &func_old_type, 0); 
@@ -8004,7 +8005,7 @@
         if (!sec) {
             if (has_init)
                 sec = data_section;
-            else if (tcc_state->nocommon)
+            else if (tccg_nocommon)
                 sec = bss_section;
         }
         if (sec) {
@@ -8543,9 +8544,9 @@
         if (tok == TOK_EOF)
             break;
         if (!last_is_space) {
-            fputc(' ', s1->outfile);
-        }
-        fputs(get_tok_str(tok, &tokc), s1->outfile);
+            fputc(' ', tccg_outfile);
+        }
+        fputs(get_tok_str(tok, &tokc), tccg_outfile);
         if (tok == TOK_LINEFEED) {
             last_is_space = 1;
             /* XXX: suppress that hack */
@@ -8785,7 +8786,7 @@
     int i, c;
 
     s = tcc_state = xzmalloc(sizeof(TCCState));
-    tcc_state->output_type = TCC_OUTPUT_MEMORY;
+    tccg_output_type = TCC_OUTPUT_MEMORY;
 
     /* init isidnum table */
     for(i=0;i<256;i++)
@@ -8872,11 +8873,11 @@
     s->alacarte_link = 1;
 
 #ifdef CHAR_IS_UNSIGNED
-    s->char_is_unsigned = 1;
+    tccg_char_is_unsigned = 1;
 #endif
 #if defined(TCC_TARGET_PE) && 0
     /* XXX: currently the PE linker is not ready to support that */
-    s->leading_underscore = 1;
+    tccg_leading_underscore = 1;
 #endif
     return s;
 }
@@ -8912,18 +8913,18 @@
     free(s1->loaded_dlls);
 
     /* library paths */
-    for(i = 0; i < s1->library_paths.len; i++)
-        free(s1->library_paths.data[i]);
-    free(s1->library_paths.data);
+    for(i = 0; i < tccg_library_paths.len; i++)
+        free(tccg_library_paths.data[i]);
+    free(tccg_library_paths.data);
 
     /* cached includes */
     for(i = 0; i < s1->nb_cached_includes; i++)
         free(s1->cached_includes[i]);
     free(s1->cached_includes);
 
-    for(i = 0; i < s1->include_paths.len; i++)
-        free(s1->include_paths.data[i]);
-    free(s1->include_paths.data);
+    for(i = 0; i < tccg_include_paths.len; i++)
+        free(tccg_include_paths.data[i]);
+    free(tccg_include_paths.data);
 
     for(i = 0; i < s1->sysinclude_paths.len; i++)
         free(s1->sysinclude_paths.data[i]);
@@ -8952,7 +8953,7 @@
     /* open the file */
     saved_file = file;
     file = tcc_open(s1, filename);
-    if (s1->verbose > !file)
+    if (tccg_verbose > !file)
         printf("%s file '%s'\n", file ? "Read" : "Tried", filename);
     if (!file) {
         if (flags & AFF_PRINT_ERROR) {
@@ -9001,7 +9002,7 @@
             if (ehdr.e_type == ET_REL) {
                 ret = tcc_load_object_file(s1, fd, 0);
             } else if (ehdr.e_type == ET_DYN) {
-                if (s1->output_type == TCC_OUTPUT_MEMORY) {
+                if (tccg_output_type == TCC_OUTPUT_MEMORY) {
 #ifdef TCC_TARGET_PE
                     ret = -1;
 #else
@@ -9061,9 +9062,9 @@
     char buf[1024];
     int i;
 
-    for(i = 0; i < s->library_paths.len; i++) {
+    for(i = 0; i < tccg_library_paths.len; i++) {
         snprintf(buf, sizeof(buf), "%s/%s", 
-                 s->library_paths.data[i], filename);
+                 tccg_library_paths.data[i], filename);
         if (tcc_add_file_internal(s, buf, flags) == 0)
             return 0;
     }
@@ -9077,7 +9078,7 @@
     int i;
     
     /* first we look for the dynamic library if not static linking */
-    if (!s->static_link) {
+    if (!tccg_static_link) {
 #ifdef TCC_TARGET_PE
         snprintf(buf, sizeof(buf), "%s.def", libraryname);
 #else
@@ -9088,9 +9089,9 @@
     }
 
     /* then we look for the static library */
-    for(i = 0; i < s->library_paths.len; i++) {
+    for(i = 0; i < tccg_library_paths.len; i++) {
         snprintf(buf, sizeof(buf), "%s/lib%s.a", 
-                 s->library_paths.data[i], libraryname);
+                 tccg_library_paths.data[i], libraryname);
         if (tcc_add_file_internal(s, buf, 0) == 0)
             return 0;
     }
@@ -9107,7 +9108,7 @@
 
 int init_output_type(TCCState *s)
 {
-    if (!s->nostdinc) {
+    if (!tccg_nostdinc) {
         char buf[1024];
 
         /* default include paths */
@@ -9118,11 +9119,11 @@
         add_dynarray_path(s, buf, &(s->sysinclude_paths));
     }
 
-    if (!s->nostdlib) {
+    if (!tccg_nostdlib) {
         char buf[1024];
         snprintf(buf, sizeof(buf), "%s/lib", tinycc_path);
-        add_dynarray_path(s, buf, &(s->library_paths));
-        add_dynarray_path(s, CC_LIBPATH, &(s->library_paths));
+        add_dynarray_path(s, buf, &(tccg_library_paths));
+        add_dynarray_path(s, CC_LIBPATH, &(tccg_library_paths));
     }
 
     /* if bound checking, then add corresponding sections */
@@ -9138,7 +9139,7 @@
     }
 #endif
 
-    if (s->char_is_unsigned) {
+    if (tccg_char_is_unsigned) {
         tcc_define_symbol(s, "__CHAR_UNSIGNED__", NULL);
     }
 
@@ -9156,10 +9157,10 @@
 
     /* add libc crt1/crti objects */
 #ifndef TCC_TARGET_PE
-    if ((s->output_type == TCC_OUTPUT_EXE || s->output_type == TCC_OUTPUT_DLL)
-        && !s->nostdlib)
+    if ((tccg_output_type == TCC_OUTPUT_EXE || tccg_output_type == TCC_OUTPUT_DLL)
+        && !tccg_nostdlib)
     {
-        if (s->output_type != TCC_OUTPUT_DLL)
+        if (tccg_output_type != TCC_OUTPUT_DLL)
             tcc_add_file(s, CC_CRTDIR "/crt1.o");
         tcc_add_file(s, CC_CRTDIR "/crti.o");
     }
--- a/tcc.h	Mon Jan 21 00:29:43 2008 -0600
+++ b/tcc.h	Thu Mar 06 20:53:55 2008 -0600
@@ -6,7 +6,7 @@
  *
  *  Licensed under GPLv2, see file LICENSE in this tarball.
  */
-#define _GNU_SOURCE
+// #define _GNU_SOURCE
 
 #ifdef CONFIG_TCCBOOT
 
@@ -293,9 +293,9 @@
 #define CACHED_INCLUDES_HASH_SIZE 512
 
 /* additional information about token */
-#define TOK_FLAG_BOW   0x0001 /* beginning of word before */
-#define TOK_FLAG_BOL   0x0002 /* beginning of line before */
-#define TOK_FLAG_BOF   0x0004 /* beginning of file before */
+//#define TOK_FLAG_BOW   0x0001 /* beginning of word before */
+//#define TOK_FLAG_BOL   0x0002 /* beginning of line before */
+//#define TOK_FLAG_BOF   0x0004 /* beginning of file before */
 #define TOK_FLAG_ENDIF 0x0008 /* a endif was found matching starting #ifdef */
 
 #define PARSE_FLAG_PREPROCESS 0x0001 /* activate preprocessing */
@@ -307,26 +307,26 @@
  
 #define SYM_POOL_NB (8192 / sizeof(Sym))
 
-struct dynarray {
-    char **data;
-    int len;
-};
+//struct dynarray {
+//    char **data;
+//    int len;
+//};
 
 struct TCCState {
-    int output_type;
+    //int output_type;
  
     BufferedFile **include_stack_ptr;
     int *ifdef_stack_ptr;
 
     /* include file handling */
-    struct dynarray include_paths;
+    // struct dynarray include_paths;
     struct dynarray sysinclude_paths;
 
     //struct dynarray cached_includes;
     CachedInclude **cached_includes;
     int nb_cached_includes;
 
-    struct dynarray library_paths;
+    // struct dynarray library_paths;
 
     /* array of all loaded dlls (including those referenced by loaded
        dlls) */
@@ -353,40 +353,40 @@
     /* exported dynamic symbol section */
     Section *dynsym;
 
-    int nostdinc; /* if true, no standard headers are added */
-    int nostdlib; /* if true, no standard libraries are added */
+    // int nostdinc; /* if true, no standard headers are added */
+    // int nostdlib; /* if true, no standard libraries are added */
 
-    int nocommon; /* if true, do not use common symbols for .bss data */
+    //int nocommon; /* if true, do not use common symbols for .bss data */
 
     /* if true, static linking is performed */
-    int static_link;
+    // int static_link;
 
     /* if true, all symbols are exported */
-    int rdynamic;
+    // int rdynamic;
 
     /* if true, describe each room as you enter it, unless it contains a grue */
-    int verbose;
+    // int verbose;
 
     /* if true, only link in referenced objects from archive */
     int alacarte_link;
 
     /* address of text section */
-    unsigned long text_addr;
-    int has_text_addr;
+    // unsigned long text_addr;
+    // int has_text_addr;
     
     /* output format, see TCC_OUTPUT_FORMAT_xxx */
-    int output_format;
+    // int output_format;
 
     /* C language options */
-    int char_is_unsigned;
-    int leading_underscore;
+    //int char_is_unsigned;
+    //int leading_underscore;
     
     /* warning switches */
-    int warn_write_strings;
-    int warn_unsupported;
-    int warn_error;
-    int warn_none;
-    int warn_implicit_function_declaration;
+    //int warn_write_strings;
+    //int warn_unsupported;
+    //int warn_error;
+    //int warn_none;
+    //int warn_implicit_function_declaration;
 
     /* error handling */
     void *error_opaque;
@@ -412,7 +412,7 @@
     int *pack_stack_ptr;
 
     /* output file for preprocessing */
-    FILE *outfile;
+    // FILE *outfile;
 };
 
 /* The current value can be: */
@@ -536,13 +536,13 @@
 #define TOK_A_SHL 0x81
 #define TOK_A_SAR 0x82
 
-#ifndef offsetof
-#define offsetof(type, field) ((size_t) &((type *)0)->field)
-#endif
+//#ifndef offsetof
+//#define offsetof(type, field) ((size_t) &((type *)0)->field)
+//#endif
 
-#ifndef countof
-#define countof(tab) (sizeof(tab) / sizeof((tab)[0]))
-#endif
+//#ifndef countof
+//#define countof(tab) (sizeof(tab) / sizeof((tab)[0]))
+//#endif
 
 /* WARNING: the content of this string encodes token numbers */
 static unsigned char tok_two_chars[] = "<=\236>=\235!=\225&&\240||\241++\244--\242==\224<<\1>>\2+=\253-=\255*=\252/=\257%=\245&=\246^=\336|=\374->\313..\250##\266";
@@ -551,7 +551,7 @@
 #define TOK_LINEFEED  10    /* line feed */
 
 /* all identificators and strings have token above that */
-#define TOK_IDENT 256
+//#define TOK_IDENT 256
 
 /* only used for i386 asm opcodes definitions */
 #define DEF_ASM(x) DEF(TOK_ASM_ ## x, #x)
@@ -662,7 +662,7 @@
 extern long double strtold (const char *__nptr, char **__endptr);
 #endif
 
-char *pstrcpy(char *buf, int buf_size, char *s);
+//char *pstrcpy(char *buf, int buf_size, char *s);
 static char *pstrcat(char *buf, int buf_size, char *s);
 static char *tcc_basename(char *name);
 
@@ -754,10 +754,10 @@
 static void put_stabd(int type, int other, int desc);
 static int tcc_add_dll(TCCState *s, char *filename, int flags);
 
-#define AFF_PRINT_ERROR     0x0001 /* print error if file not found */
+//#define AFF_PRINT_ERROR     0x0001 /* print error if file not found */
 #define AFF_REFERENCED_DLL  0x0002 /* load a referenced dll from another dll */
-#define AFF_PREPROCESS      0x0004 /* preprocess file */
-int tcc_add_file_internal(TCCState *s, char *filename, int flags);
+//#define AFF_PREPROCESS      0x0004 /* preprocess file */
+//int tcc_add_file_internal(TCCState *s, char *filename, int flags);
 
 /* tcccoff.c */
 int tcc_output_coff(TCCState *s1, FILE *f);
@@ -876,14 +876,14 @@
 
 static inline void *resolve_sym(TCCState *s1, char *sym, int type)
 {
-    return dlsym(RTLD_DEFAULT, sym);
+    return dlsym(0, sym);
 }
 
 /* space excluding newline */
-static inline int is_space(int ch)
-{
-    return ch == ' ' || ch == '\t' || ch == '\v' || ch == '\f' || ch == '\r';
-}
+//static inline int is_space(int ch)
+//{
+//    return ch == ' ' || ch == '\t' || ch == '\v' || ch == '\f' || ch == '\r';
+//}
 
 
 #endif
--- a/tccelf.c	Mon Jan 21 00:29:43 2008 -0600
+++ b/tccelf.c	Thu Mar 06 20:53:55 2008 -0600
@@ -476,7 +476,7 @@
         switch(type) {
 #if defined(TCC_TARGET_I386)
         case R_386_32:
-            if (s1->output_type == TCC_OUTPUT_DLL) {
+            if (tccg_output_type == TCC_OUTPUT_DLL) {
                 esym_index = s1->symtab_to_dynsym[sym_index];
                 qrel->r_offset = rel->r_offset;
                 if (esym_index) {
@@ -491,7 +491,7 @@
             *(int *)ptr += val;
             break;
         case R_386_PC32:
-            if (s1->output_type == TCC_OUTPUT_DLL) {
+            if (tccg_output_type == TCC_OUTPUT_DLL) {
                 /* DLL relocation */
                 esym_index = s1->symtab_to_dynsym[sym_index];
                 if (esym_index) {
@@ -739,7 +739,7 @@
             int modrm;
 
             /* if we build a DLL, we add a %ebx offset */
-            if (s1->output_type == TCC_OUTPUT_DLL)
+            if (tccg_output_type == TCC_OUTPUT_DLL)
                 modrm = 0xa3;
             else
                 modrm = 0x25;
@@ -768,7 +768,7 @@
 
             /* the symbol is modified so that it will be relocated to
                the PLT */
-            if (s1->output_type == TCC_OUTPUT_EXE)
+            if (tccg_output_type == TCC_OUTPUT_EXE)
                 offset = plt->data_offset - 16;
         }
 #elif defined(TCC_TARGET_ARM)
@@ -777,7 +777,7 @@
             uint8_t *p;
             
             /* if we build a DLL, we add a %ebx offset */
-            if (s1->output_type == TCC_OUTPUT_DLL)
+            if (tccg_output_type == TCC_OUTPUT_DLL)
                 error("DLLs unimplemented!");
 
             /* add a PLT entry */
@@ -799,7 +799,7 @@
 
             /* the symbol is modified so that it will be relocated to
                the PLT */
-            if (s1->output_type == TCC_OUTPUT_EXE)
+            if (tccg_output_type == TCC_OUTPUT_EXE)
                 offset = plt->data_offset - 16;
         }
 #elif defined(TCC_TARGET_C67)
@@ -995,7 +995,7 @@
         snprintf(buf, sizeof(buf), "%s/bcheck.o", tinycc_path);
         tcc_add_file(s1, buf);
 #ifdef TCC_TARGET_I386
-        if (s1->output_type != TCC_OUTPUT_MEMORY) {
+        if (tccg_output_type != TCC_OUTPUT_MEMORY) {
             /* add 'call __bound_init()' in .init section */
             init_section = find_section(s1, ".init");
             pinit = section_ptr_add(init_section, 5);
@@ -1009,11 +1009,11 @@
     }
 #endif
     // add libc
-    if (!s1->nostdlib) {
+    if (!tccg_nostdlib) {
         tcc_add_library(s1, "c");
         tcc_add_library(s1, "tinyccrt-" TINYCC_TARGET);
       // add crt end if not memory output
-      if (s1->output_type != TCC_OUTPUT_MEMORY)
+      if (tccg_output_type != TCC_OUTPUT_MEMORY)
           tcc_add_file(s1, CC_CRTDIR "/crtn.o");
     }
 }
@@ -1130,7 +1130,7 @@
     int type, file_type;
     unsigned long rel_addr, rel_size;
     
-    file_type = s1->output_type;
+    file_type = tccg_output_type;
     s1->nb_errors = 0;
 
     if (file_type != TCC_OUTPUT_OBJ) {
@@ -1149,7 +1149,7 @@
 
         tcc_add_linker_symbols(s1);
 
-        if (!s1->static_link) {
+        if (!tccg_static_link) {
             char *name;
             int sym_index, index;
             Elf32_Sym *esym, *sym_end;
@@ -1225,7 +1225,7 @@
                                 error_noabort("undefined symbol '%s'", name);
                             }
                         }
-                    } else if (s1->rdynamic && 
+                    } else if (tccg_rdynamic && 
                                ELF32_ST_BIND(sym->st_info) != STB_LOCAL) {
                         /* if -rdynamic option, then export all non
                            local symbols */
@@ -1328,7 +1328,7 @@
         phnum = 0;
         break;
     case TCC_OUTPUT_EXE:
-        if (!s1->static_link)
+        if (!tccg_static_link)
             phnum = 4;
         else
             phnum = 2;
@@ -1363,16 +1363,16 @@
     /* allocate program segment headers */
     phdr = xzmalloc(phnum * sizeof(Elf32_Phdr));
         
-    if (s1->output_format == TCC_OUTPUT_FORMAT_ELF) {
+    if (tccg_output_format == TCC_OUTPUT_FORMAT_ELF) {
         file_offset = sizeof(Elf32_Ehdr) + phnum * sizeof(Elf32_Phdr);
     } else {
         file_offset = 0;
     }
     if (phnum > 0) {
         /* compute section to program header mapping */
-        if (s1->has_text_addr) { 
+        if (tccg_has_text_addr) { 
             int a_offset, p_offset;
-            addr = s1->text_addr;
+            addr = tccg_text_addr;
             /* we ensure that (addr % ELF_PAGE_SIZE) == file_offset %
                ELF_PAGE_SIZE */
             a_offset = addr & (ELF_PAGE_SIZE - 1);
@@ -1471,7 +1471,7 @@
             ph->p_memsz = addr - ph->p_vaddr;
             ph++;
             if (j == 0) {
-                if (s1->output_format == TCC_OUTPUT_FORMAT_ELF) {
+                if (tccg_output_format == TCC_OUTPUT_FORMAT_ELF) {
                     /* if in the middle of a page, we duplicate the page in
                        memory so that one copy is RX and the other is RW */
                     if ((addr & (ELF_PAGE_SIZE - 1)) != 0)
@@ -1644,11 +1644,11 @@
     f = fdopen(fd, "wb");
 
 #ifdef TCC_TARGET_COFF
-    if (s1->output_format == TCC_OUTPUT_FORMAT_COFF) {
+    if (tccg_output_format == TCC_OUTPUT_FORMAT_COFF) {
         tcc_output_coff(s1, f);
     } else
 #endif
-    if (s1->output_format == TCC_OUTPUT_FORMAT_ELF) {
+    if (tccg_output_format == TCC_OUTPUT_FORMAT_ELF) {
         sort_syms(s1, symtab_section);
         
         /* align to 4 */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tinycc.h	Thu Mar 06 20:53:55 2008 -0600
@@ -0,0 +1,93 @@
+#include "libtinycc.h"
+
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/time.h>
+#include <time.h>
+
+// Data type for dynamic resizeable arrays
+struct dynarray {
+    char **data;
+    int len;
+};
+
+// All these tccg_ things can be grouped into a structure, but not until after
+// they're broken out of TCCState and moved over.
+
+// Warning switches
+
+int tccg_warn_unsupported;
+int tccg_warn_write_strings;
+int tccg_warn_error;
+int tccg_warn_implicit_function_declaration;
+int tccg_warn_none;
+
+// C language options
+
+int tccg_char_is_unsigned;
+int tccg_leading_underscore;
+
+// Don't merge identical symbols in .bss segment, error instead.
+int tccg_nocommon;
+
+// if true, describe each room as you enter it, unless it contains a grue
+int tccg_verbose;
+
+// Include file handling
+struct dynarray tccg_include_paths;
+struct dynarray tccg_library_paths;
+
+int tccg_output_type;
+int tccg_output_format;// TCC_OUTPUT_FORMAT_xxx
+int tccg_static_link;  // Perform static linking?
+int tccg_nostdinc;     // If true, no standard headers are added.
+int tccg_nostdlib;     // If true, no standard libraries are added.
+int tccg_rdynamic;     // Export all symbols.
+
+unsigned long tccg_text_addr;  // Address of text section.
+int tccg_has_text_addr;
+
+FILE *tccg_outfile;    // Output file for preprocessing.
+
+// Functions from elsewhere.
+
+void error(char *fmt, ...);
+void *xmalloc(unsigned long size);
+void dynarray_add(void ***ptab, int *nb_ptr, void *data);
+void add_dynarray_path(TCCState *s, char *pathname, struct dynarray *dd);
+int strstart(char *str, char *val, char **ptr);
+void warning(char *fmt, ...);
+int init_output_type(TCCState *s);
+char *pstrcpy(char *buf, int buf_size, char *s);
+int tcc_add_file_internal(TCCState *s, char *filename, int flags);
+
+extern char *tinycc_path;
+
+#ifndef offsetof
+#define offsetof(type, field) ((size_t) &((type *)0)->field)
+#endif
+
+#ifndef countof
+#define countof(tab) (sizeof(tab) / sizeof((tab)[0]))
+#endif
+
+// This token begins a word/line/file
+#define TOK_FLAG_BOW   0x0001
+#define TOK_FLAG_BOL   0x0002
+#define TOK_FLAG_BOF   0x0004
+
+// Add file flags (passed to tcc_add_file_internal())
+#define AFF_PRINT_ERROR     0x0001 // print error if file not found
+#define AFF_PREPROCESS      0x0004 // preprocess file
+
+// First identifier token
+#define TOK_IDENT      256  // First identifier/string token.
+
+// This should come from dlfcn.h but doesn't unless you claim to be written
+// by the fsf, which we aren't.
+#define RTLD_DEFAULT   0
+
+int is_space(int ch);