- fixed a lot of 'enum type mixed with ...' warnings
[cparser] / main.c
diff --git a/main.c b/main.c
index 9b82e23..b3a9065 100644 (file)
--- a/main.c
+++ b/main.c
 #define fdopen(fd, mode)         _fdopen(fd, mode)
 #define popen(cmd, mode)         _popen(cmd, mode)
 #define pclose(file)             _pclose(file)
+#define unlink(filename)         _unlink(filename)
 
 #else
 #include <unistd.h>
 #define HAVE_MKSTEMP
 #endif
 
-#ifndef WITH_LIBCORE
-#define WITH_LIBCORE
-#endif
-
 #include <libfirm/firm.h>
 #include <libfirm/be.h>
 
@@ -79,6 +76,7 @@
 #include "write_caml.h"
 #include "revision.h"
 #include "warning.h"
+#include "mangle.h"
 
 #ifndef PREPROCESSOR
 #ifdef __APPLE__
 #endif
 
 /** The current c mode/dialect. */
-lang_features_t c_mode = _C89 | _ANSI | _C99 | _GNUC;
+unsigned int c_mode = _C89 | _ANSI | _C99 | _GNUC;
 
 /** The 'machine size', 16, 32 or 64 bit, 32bit is the default. */
 unsigned int machine_size = 32;
@@ -118,6 +116,8 @@ bool use_builtins = false;
 /** we have extern function with const attribute. */
 bool have_const_functions = false;
 
+atomic_type_kind_t wchar_atomic_kind = ATOMIC_TYPE_INT;
+
 /* to switch on printing of implicit casts */
 extern bool print_implicit_casts;
 
@@ -144,11 +144,13 @@ typedef enum filetype_t {
 } filetype_t;
 
 struct file_list_entry_t {
-       const char        *name; /**< filename or NULL for stdin */
-       filetype_t         type;
+       const char  *name; /**< filename or NULL for stdin */
+       filetype_t   type;
        file_list_entry_t *next;
 };
 
+static file_list_entry_t *temp_files;
+
 #if defined(_DEBUG) || defined(FIRM_DEBUG)
 /**
  * Debug printf implementation.
@@ -404,9 +406,34 @@ static FILE *make_temp_file(char *buffer, size_t buflen, const char *prefix)
                exit(1);
        }
 
+       file_list_entry_t *entry = xmalloc(sizeof(*entry));
+       memset(entry, 0, sizeof(*entry));
+
+       size_t  name_len = strlen(buffer) + 1;
+       char   *name     = malloc(name_len);
+       memcpy(name, buffer, name_len);
+       entry->name      = name;
+
+       entry->next = temp_files;
+       temp_files  = entry;
+
        return out;
 }
 
+static void free_temp_files(void)
+{
+       file_list_entry_t *entry = temp_files;
+       file_list_entry_t *next;
+       for ( ; entry != NULL; entry = next) {
+               next = entry->next;
+
+               unlink(entry->name);
+               free((char*) entry->name);
+               free(entry);
+       }
+       temp_files = NULL;
+}
+
 /**
  * Do the necessary lowering for compound parameters.
  */
@@ -536,6 +563,7 @@ static void init_os_support(void)
        switch (firm_opt.os_support) {
        case OS_SUPPORT_MINGW:
                set_be_option("ia32-gasmode=mingw");
+               wchar_atomic_kind = ATOMIC_TYPE_USHORT;
                break;
        case OS_SUPPORT_LINUX:
                set_be_option("ia32-gasmode=elf");
@@ -574,6 +602,8 @@ int main(int argc, char **argv)
        bool               construct_dep_target = false;
        struct obstack     file_obst;
 
+       atexit(free_temp_files);
+
        /* hack for now... */
        if (strstr(argv[0], "pptest") != NULL) {
                extern int pptest_main(int argc, char **argv);
@@ -651,8 +681,8 @@ int main(int argc, char **argv)
 
        /* parse rest of options */
        lang_standard_t standard        = STANDARD_DEFAULT;
-       lang_features_t features_on     = 0;
-       lang_features_t features_off    = 0;
+       unsigned        features_on     = 0;
+       unsigned        features_off    = 0;
        filetype_t      forced_filetype = FILETYPE_AUTODETECT;
        bool            help_displayed  = false;
        bool            argument_errors = false;
@@ -1023,6 +1053,7 @@ int main(int argc, char **argv)
        init_ast();
        init_parser();
        init_ast2firm();
+       init_mangle();
 
        if (construct_dep_target) {
                if (outname != 0 && strlen(outname) >= 2) {
@@ -1341,6 +1372,7 @@ do_parsing:
        obstack_free(&ldflags_obst, NULL);
        obstack_free(&file_obst, NULL);
 
+       exit_mangle();
        exit_ast2firm();
        exit_parser();
        exit_ast();