lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nwelln...@apache.org
Subject [lucy-commits] [09/15] git commit: refs/heads/install-c-library - Regenerate charmonizer.c
Date Sat, 18 May 2013 19:23:54 GMT
Regenerate charmonizer.c


Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/e7cdce42
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/e7cdce42
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/e7cdce42

Branch: refs/heads/install-c-library
Commit: e7cdce42b6d5ad011f3192d9bbd3727541dd7775
Parents: cf630fc
Author: Nick Wellnhofer <wellnhofer@aevum.de>
Authored: Sat May 18 12:28:05 2013 +0200
Committer: Nick Wellnhofer <wellnhofer@aevum.de>
Committed: Sat May 18 19:15:55 2013 +0200

----------------------------------------------------------------------
 clownfish/compiler/common/charmonizer.c |  698 +++++++++++++++++++++-----
 clownfish/runtime/common/charmonizer.c  |  405 ++++++++++------
 common/charmonizer.c                    |  412 ++++++++++------
 3 files changed, 1089 insertions(+), 426 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/e7cdce42/clownfish/compiler/common/charmonizer.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/common/charmonizer.c b/clownfish/compiler/common/charmonizer.c
index 3d02760..f89aebe 100644
--- a/clownfish/compiler/common/charmonizer.c
+++ b/clownfish/compiler/common/charmonizer.c
@@ -936,6 +936,36 @@ chaz_Probe_msvc_version_num(void);
 
 /***************************************************************************/
 
+#line 21 "src/Charmonizer/Probe/Booleans.h"
+/* Charmonizer/Probe/Booleans.h -- bool type.
+ *
+ * If stdbool.h is is available, it will be pound-included in the configuration
+ * header.  If it is not, the following typedef will be defined:
+ *
+ * bool
+ *
+ * These symbols will be defined if they are not already:
+ *
+ * true
+ * false
+ */
+
+#ifndef H_CHAZ_BOOLEANS
+#define H_CHAZ_BOOLEANS
+
+#include <stdio.h>
+
+/* Run the Booleans module.
+ */
+void chaz_Booleans_run(void);
+
+#endif /* H_CHAZ_BOOLEANS */
+
+
+
+
+/***************************************************************************/
+
 #line 21 "src/Charmonizer/Probe/BuildEnv.h"
 /* Charmonizer/Probe/BuildEnv.h -- Build environment.
  *
@@ -1013,6 +1043,45 @@ void chaz_DirManip_run(void);
 
 /***************************************************************************/
 
+#line 21 "src/Charmonizer/Probe/FuncMacro.h"
+/* Charmonizer/Probe/FuncMacro.h
+ */
+
+#ifndef H_CHAZ_FUNC_MACRO
+#define H_CHAZ_FUNC_MACRO
+
+#include <stdio.h>
+
+/* Run the FuncMacro module.
+ *
+ * If __func__ successfully resolves, this will be defined:
+ *
+ * HAS_ISO_FUNC_MACRO
+ *
+ * If __FUNCTION__ successfully resolves, this will be defined:
+ *
+ * HAS_GNUC_FUNC_MACRO
+ *
+ * If one or the other succeeds, these will be defined:
+ *
+ * HAS_FUNC_MACRO
+ * FUNC_MACRO
+ *
+ * The "inline" keyword will also be probed for.  If it is available, the
+ * following macro will be defined to "inline", otherwise it will be defined
+ * to nothing.
+ *
+ * INLINE
+ */
+void chaz_FuncMacro_run(void);
+
+#endif /* H_CHAZ_FUNC_MACRO */
+
+
+
+
+/***************************************************************************/
+
 #line 20 "src/Charmonizer/Probe/Headers.h"
 /* Charmonizer/Probe/Headers.h
  */
@@ -1210,6 +1279,22 @@ void chaz_Strings_run(void);
 
 /***************************************************************************/
 
+#line 21 "src/Charmonizer/Probe/SymbolVisibility.h"
+/* Charmonizer/Probe/SymbolVisibility.h
+ */
+
+#ifndef H_CHAZ_SYMBOLVISIBILITY
+#define H_CHAZ_SYMBOLVISIBILITY
+
+void chaz_SymbolVisibility_run(void);
+
+#endif /* H_CHAZ_SYMBOLVISIBILITY */
+
+
+
+
+/***************************************************************************/
+
 #line 21 "src/Charmonizer/Probe/UnusedVars.h"
 /* Charmonizer/Probe/UnusedVars.h
  */
@@ -2177,6 +2262,7 @@ typedef struct chaz_ConfElem {
 /* Static vars. */
 static struct {
     FILE          *fh;
+    char          *MODULE_NAME;
     chaz_ConfElem *defs;
     size_t         def_cap;
     size_t         def_count;
@@ -2274,18 +2360,17 @@ chaz_ConfWriterC_vappend_conf(const char *fmt, va_list args) {
 
 static int
 chaz_ConfWriterC_sym_is_uppercase(const char *sym) {
-    unsigned i;
-    for (i = 0; sym[i] != 0; i++) {
-        if (!isupper(sym[i])) {
-            if (islower(sym[i])) {
-                return false;
-            }
-            else if (sym[i] != '_') {
-                return true;
-            }
-        }
+    return isupper(sym[0]);
+}
+
+static char*
+chaz_ConfWriterC_uppercase_string(const char *src) {
+    char *retval = chaz_Util_strdup(src);
+    size_t i;
+    for (i = 0; retval[i]; ++i) {
+        retval[i] = toupper(retval[i]);
     }
-    return true;
+    return retval;
 }
 
 static void
@@ -2320,9 +2405,10 @@ chaz_ConfWriterC_add_global_def(const char *sym, const char *value) {
 
 static void
 chaz_ConfWriterC_append_global_def_to_conf(const char *sym,
-        const char *value) {
+                                           const char *value) {
     char *name_end = strchr(sym, '(');
     if (name_end == NULL) {
+        if (strcmp(sym, value) == 0) { return; }
         fprintf(chaz_ConfWriterC.fh, "#ifndef %s\n", sym);
     }
     else {
@@ -2364,7 +2450,8 @@ chaz_ConfWriterC_add_global_typedef(const char *type, const char *alias) {
 
 static void
 chaz_ConfWriterC_append_global_typedef_to_conf(const char *type,
-        const char *alias) {
+                                               const char *alias) {
+    if (strcmp(type, alias) == 0) { return; }
     fprintf(chaz_ConfWriterC.fh, "typedef %s %s;\n", type, alias);
 }
 
@@ -2393,32 +2480,37 @@ chaz_ConfWriterC_append_local_include_to_conf(const char *header) {
 static void
 chaz_ConfWriterC_start_module(const char *module_name) {
     fprintf(chaz_ConfWriterC.fh, "\n/* %s */\n", module_name);
+    chaz_ConfWriterC.MODULE_NAME
+        = chaz_ConfWriterC_uppercase_string(module_name);
 }
 
 static void
 chaz_ConfWriterC_end_module(void) {
+    size_t num_globals = 0;
     size_t i;
     chaz_ConfElem *defs = chaz_ConfWriterC.defs;
     for (i = 0; i < chaz_ConfWriterC.def_count; i++) {
         switch (defs[i].type) {
+            case CHAZ_CONFELEM_GLOBAL_DEF:
+                ++num_globals;
+            /* fall through */
             case CHAZ_CONFELEM_DEF:
                 chaz_ConfWriterC_append_def_to_conf(defs[i].str1,
                                                     defs[i].str2);
                 break;
-            case CHAZ_CONFELEM_GLOBAL_DEF:
-                chaz_ConfWriterC_append_global_def_to_conf(defs[i].str1,
-                                                           defs[i].str2);
-                break;
+            case CHAZ_CONFELEM_GLOBAL_TYPEDEF: {
+                ++num_globals;
+                char *sym = chaz_ConfWriterC_uppercase_string(defs[i].str1);
+                chaz_ConfWriterC_append_def_to_conf(sym, defs[i].str2);
+                free(sym);
+            }
+            /* fall through */
             case CHAZ_CONFELEM_TYPEDEF:
                 chaz_ConfWriterC_append_typedef_to_conf(defs[i].str2,
                                                         defs[i].str1);
                 break;
-            case CHAZ_CONFELEM_GLOBAL_TYPEDEF:
-                chaz_ConfWriterC_append_global_typedef_to_conf(defs[i].str2,
-                                                               defs[i].str1);
-                break;
             case CHAZ_CONFELEM_SYS_INCLUDE:
-                chaz_ConfWriterC_append_sys_include_to_conf(defs[i].str1);
+                ++num_globals;
                 break;
             case CHAZ_CONFELEM_LOCAL_INCLUDE:
                 chaz_ConfWriterC_append_local_include_to_conf(defs[i].str1);
@@ -2436,7 +2528,7 @@ chaz_ConfWriterC_end_module(void) {
     );
     for (i = 0; i < chaz_ConfWriterC.def_count; i++) {
         switch (defs[i].type) {
-            case CHAZ_CONFELEM_DEF: 
+            case CHAZ_CONFELEM_DEF:
             case CHAZ_CONFELEM_TYPEDEF:
                 {
                     const char *sym = defs[i].str1;
@@ -2463,8 +2555,41 @@ chaz_ConfWriterC_end_module(void) {
     }
 
     fprintf(chaz_ConfWriterC.fh, "#endif /* USE_SHORT_NAMES */\n");
+
+    /* Write out global definitions and system includes. */
+    if (num_globals) {
+        fprintf(chaz_ConfWriterC.fh, "\n#ifdef CHY_EMPLOY_%s\n\n",
+                chaz_ConfWriterC.MODULE_NAME);
+        for (i = 0; i < chaz_ConfWriterC.def_count; i++) {
+            switch (defs[i].type) {
+                case CHAZ_CONFELEM_GLOBAL_DEF:
+                    chaz_ConfWriterC_append_global_def_to_conf(defs[i].str1,
+                                                               defs[i].str2);
+                    break;
+                case CHAZ_CONFELEM_GLOBAL_TYPEDEF:
+                    chaz_ConfWriterC_append_global_typedef_to_conf(
+                            defs[i].str2, defs[i].str1);
+                    break;
+                case CHAZ_CONFELEM_SYS_INCLUDE:
+                    chaz_ConfWriterC_append_sys_include_to_conf(defs[i].str1);
+                    break;
+                case CHAZ_CONFELEM_DEF:
+                case CHAZ_CONFELEM_TYPEDEF:
+                case CHAZ_CONFELEM_LOCAL_INCLUDE:
+                    /* no-op */
+                    break;
+                default:
+                    chaz_Util_die("Internal error: bad element type %d",
+                                  (int)defs[i].type);
+            }
+        }
+        fprintf(chaz_ConfWriterC.fh, "\n#endif /* EMPLOY_%s */\n",
+                chaz_ConfWriterC.MODULE_NAME);
+    }
+
     fprintf(chaz_ConfWriterC.fh, "\n");
 
+    free(chaz_ConfWriterC.MODULE_NAME);
     chaz_ConfWriterC_clear_def_list();
 }
 
@@ -4454,6 +4579,41 @@ chaz_Probe_msvc_version_num(void) {
 
 /***************************************************************************/
 
+#line 17 "src/Charmonizer/Probe/Booleans.c"
+/* #include "Charmonizer/Core/HeaderChecker.h" */
+/* #include "Charmonizer/Core/ConfWriter.h" */
+/* #include "Charmonizer/Probe/Booleans.h" */
+
+void
+chaz_Booleans_run(void) {
+    int has_stdbool = chaz_HeadCheck_check_header("stdbool.h");
+
+    chaz_ConfWriter_start_module("Booleans");
+
+    if (has_stdbool) {
+        chaz_ConfWriter_add_def("HAS_STDBOOL_H", NULL);
+        chaz_ConfWriter_add_sys_include("stdbool.h");
+    }
+    else {
+        chaz_ConfWriter_append_conf(
+            "#if (defined(CHY_EMPLOY_BOOLEANS) && !defined(__cplusplus))\n"
+            "  typedef int bool;\n"
+            "  #ifndef true\n"
+            "    #define true 1\n"
+            "  #endif\n"
+            "  #ifndef false\n"
+            "    #define false 0\n"
+            "  #endif\n"
+            "#endif\n");
+    }
+
+    chaz_ConfWriter_end_module();
+}
+
+
+
+/***************************************************************************/
+
 #line 17 "src/Charmonizer/Probe/BuildEnv.c"
 /* #include "Charmonizer/Core/HeaderChecker.h" */
 /* #include "Charmonizer/Core/ConfWriter.h" */
@@ -4669,6 +4829,147 @@ chaz_DirManip_run(void) {
 
 /***************************************************************************/
 
+#line 17 "src/Charmonizer/Probe/FuncMacro.c"
+/* #include "Charmonizer/Core/Compiler.h" */
+/* #include "Charmonizer/Core/ConfWriter.h" */
+/* #include "Charmonizer/Core/Util.h" */
+/* #include "Charmonizer/Probe/FuncMacro.h" */
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+/* Probe for ISO func macro. */
+static int
+chaz_FuncMacro_probe_iso() {
+    static const char iso_func_code[] =
+        CHAZ_QUOTE(  #include <stdio.h>                )
+        CHAZ_QUOTE(  int main() {                      )
+        CHAZ_QUOTE(      printf("%s", __func__);       )
+        CHAZ_QUOTE(      return 0;                     )
+        CHAZ_QUOTE(  }                                 );
+    size_t output_len;
+    char *output;
+    int success = false;
+
+    output = chaz_CC_capture_output(iso_func_code, &output_len);
+    if (output != NULL && strncmp(output, "main", 4) == 0) {
+        success = true;
+    }
+    free(output);
+
+    return success;
+}
+
+static int
+chaz_FuncMacro_probe_gnu() {
+    /* Code for verifying GNU func macro. */
+    static const char gnu_func_code[] =
+        CHAZ_QUOTE(  #include <stdio.h>                )
+        CHAZ_QUOTE(  int main() {                      )
+        CHAZ_QUOTE(      printf("%s", __FUNCTION__);   )
+        CHAZ_QUOTE(      return 0;                     )
+        CHAZ_QUOTE(  }                                 );
+    size_t output_len;
+    char *output;
+    int success = false;
+
+    output = chaz_CC_capture_output(gnu_func_code, &output_len);
+    if (output != NULL && strncmp(output, "main", 4) == 0) {
+        success = true;
+    }
+    free(output);
+
+    return success;
+}
+
+/* Attempt to verify inline keyword. */
+static char*
+chaz_FuncMacro_try_inline(const char *keyword, size_t *output_len) {
+    static const char inline_code[] =
+        CHAZ_QUOTE(  #include <stdio.h>                )
+        CHAZ_QUOTE(  static %s int foo() { return 1; } )
+        CHAZ_QUOTE(  int main() {                      )
+        CHAZ_QUOTE(      printf("%%d", foo());         )
+        CHAZ_QUOTE(      return 0;                     )
+        CHAZ_QUOTE(  }                                 );
+    char code[sizeof(inline_code) + 30];
+    sprintf(code, inline_code, keyword);
+    return chaz_CC_capture_output(code, output_len);
+}
+
+static void
+chaz_FuncMacro_probe_inline(void) {
+    static const char* inline_options[] = {
+        "__inline",
+        "__inline__",
+        "inline"
+    };
+    const int num_inline_options = sizeof(inline_options) / sizeof(void*);
+    int has_inline = false;
+    int i;
+
+    for (i = 0; i < num_inline_options; i++) {
+        const char *inline_option = inline_options[i];
+        size_t output_len;
+        char *output = chaz_FuncMacro_try_inline(inline_option, &output_len);
+        if (output != NULL) {
+            has_inline = true;
+            chaz_ConfWriter_add_def("INLINE", inline_option);
+            free(output);
+            break;
+        }
+    }
+    if (!has_inline) {
+        chaz_ConfWriter_add_def("INLINE", NULL);
+    }
+}
+
+void
+chaz_FuncMacro_run(void) {
+    int has_funcmac      = false;
+    int has_iso_funcmac  = false;
+    int has_gnuc_funcmac = false;
+
+    chaz_ConfWriter_start_module("FuncMacro");
+
+    /* Check for func macros. */
+    if (chaz_FuncMacro_probe_iso()) {
+        has_funcmac     = true;
+        has_iso_funcmac = true;
+    }
+    if (chaz_FuncMacro_probe_gnu()) {
+        has_funcmac      = true;
+        has_gnuc_funcmac = true;
+    }
+
+    /* Write out common defines. */
+    if (has_funcmac) {
+        const char *macro_text = has_iso_funcmac
+                                 ? "__func__"
+                                 : "__FUNCTION__";
+        chaz_ConfWriter_add_def("HAS_FUNC_MACRO", NULL);
+        chaz_ConfWriter_add_def("FUNC_MACRO", macro_text);
+    }
+
+    /* Write out specific defines. */
+    if (has_iso_funcmac) {
+        chaz_ConfWriter_add_def("HAS_ISO_FUNC_MACRO", NULL);
+    }
+    if (has_gnuc_funcmac) {
+        chaz_ConfWriter_add_def("HAS_GNUC_FUNC_MACRO", NULL);
+    }
+
+    /* Check for inline keyword. */
+    chaz_FuncMacro_probe_inline();
+
+    chaz_ConfWriter_end_module();
+}
+
+
+
+
+/***************************************************************************/
+
 #line 17 "src/Charmonizer/Probe/Headers.c"
 /* #include "Charmonizer/Core/HeaderChecker.h" */
 /* #include "Charmonizer/Core/ConfWriter.h" */
@@ -4936,7 +5237,7 @@ static const char chaz_Integers_u64_to_double_code[] =
     CHAZ_QUOTE(  #include <stdio.h>                        )
     CHAZ_QUOTE(  int main()                                )
     CHAZ_QUOTE(  {                                         )
-    CHAZ_QUOTE(      unsigned __int64 int_num = 0;         )
+    CHAZ_QUOTE(      unsigned %s int_num = 0;              )
     CHAZ_QUOTE(      double float_num;                     )
     CHAZ_QUOTE(      float_num = (double)int_num;          )
     CHAZ_QUOTE(      printf("%%f\n", float_num);           )
@@ -5093,13 +5394,6 @@ chaz_Integers_run(void) {
         }
     }
 
-    /* Determine whether conversion of unsigned __int64 to double works */
-    if (has___int64) {
-        if (!chaz_CC_test_compile(chaz_Integers_u64_to_double_code)) {
-            can_convert_u64_to_double = false;
-        }
-    }
-
     /* Write out some conditional defines. */
     if (has_inttypes) {
         chaz_ConfWriter_add_def("HAS_INTTYPES_H", NULL);
@@ -5148,92 +5442,179 @@ chaz_Integers_run(void) {
         chaz_ConfWriter_add_def("HAS_INT64_T", NULL);
     }
 
-    /* Write typedefs, maximums/minimums and literals macros. */
-    if (has_inttypes) {
-        chaz_ConfWriter_add_sys_include("inttypes.h");
+    /* Create macro for promoting pointers to integers. */
+    if (has_64) {
+        if (sizeof_ptr == 8) {
+            chaz_ConfWriter_add_def("PTR_TO_I64(ptr)",
+                                    "((int64_t)(uint64_t)(ptr))");
+        }
+        else {
+            chaz_ConfWriter_add_def("PTR_TO_I64(ptr)",
+                                    "((int64_t)(uint32_t)(ptr))");
+        }
     }
-    else {
-        if (has_stdint) {
-            chaz_ConfWriter_add_sys_include("stdint.h");
+
+    /* Create macro for converting uint64_t to double. */
+    if (has_64) {
+        /*
+         * Determine whether unsigned 64-bit integers can be converted to
+         * double. Older MSVC versions don't support this conversion.
+         */
+        sprintf(code_buf, chaz_Integers_u64_to_double_code, i64_t_type);
+        output = chaz_CC_capture_output(code_buf, &output_len);
+        if (output != NULL) {
+            chaz_ConfWriter_add_def("U64_TO_DOUBLE(num)", "((double)(num))");
+            free(output);
         }
         else {
-            /* We support only the following subset of stdint.h
-             *   int8_t
-             *   int16_t
-             *   int32_t
-             *   int64_t
-             *   uint8_t
-             *   uint16_t
-             *   uint32_t
-             *   uint64_t
-             *   INT8_MAX
-             *   INT16_MAX
-             *   INT32_MAX
-             *   INT64_MAX
-             *   INT8_MIN
-             *   INT16_MIN
-             *   INT32_MIN
-             *   INT64_MIN
-             *   UINT8_MAX
-             *   UINT16_MAX
-             *   UINT32_MAX
-             *   UINT64_MAX
-             *   SIZE_MAX
-             *   INT32_C
-             *   INT64_C
-             *   UINT32_C
-             *   UINT64_C
-             */
-            if (has_8) {
-                chaz_ConfWriter_add_global_typedef("signed char", "int8_t");
-                chaz_ConfWriter_add_global_typedef("unsigned char", "uint8_t");
-                chaz_ConfWriter_add_global_def("INT8_MAX", "127");
-                chaz_ConfWriter_add_global_def("INT8_MIN", "-128");
-                chaz_ConfWriter_add_global_def("UINT8_MAX", "255");
-            }
-            if (has_16) {
-                chaz_ConfWriter_add_global_typedef("signed short", "int16_t");
-                chaz_ConfWriter_add_global_typedef("unsigned short",
-                                                   "uint16_t");
-                chaz_ConfWriter_add_global_def("INT16_MAX", "32767");
-                chaz_ConfWriter_add_global_def("INT16_MIN", "-32768");
-                chaz_ConfWriter_add_global_def("UINT16_MAX", "65535");
-            }
-            if (has_32) {
-                chaz_ConfWriter_add_global_typedef(i32_t_type, "int32_t");
-                sprintf(scratch, "unsigned %s", i32_t_type);
-                chaz_ConfWriter_add_global_typedef(scratch, "uint32_t");
-                chaz_ConfWriter_add_global_def("INT32_MAX", "2147483647");
-                chaz_ConfWriter_add_global_def("INT32_MIN", "(-INT32_MAX-1)");
-                chaz_ConfWriter_add_global_def("UINT32_MAX", "4294967295U");
-                if (strcmp(i32_t_postfix, "") == 0) {
-                    chaz_ConfWriter_add_global_def("INT32_C(n)", "n");
-                }
-                else {
-                    sprintf(scratch, "n##%s", i32_t_postfix);
-                    chaz_ConfWriter_add_global_def("INT32_C(n)", scratch);
-                }
-                sprintf(scratch, "n##%s", u32_t_postfix);
-                chaz_ConfWriter_add_global_def("UINT32_C(n)", scratch);
+            chaz_ConfWriter_add_def(
+                "U64_TO_DOUBLE(num)",
+                "((num) & UINT64_C(0x8000000000000000) ? "
+                "(double)(int64_t)((num) & UINT64_C(0x7FFFFFFFFFFFFFFF)) + "
+                "9223372036854775808.0 : "
+                "(double)(int64_t)(num))");
+        }
+    }
+
+    chaz_ConfWriter_end_module();
+
+    /* Integer typedefs. */
+
+    chaz_ConfWriter_start_module("IntegerTypes");
+
+    if (has_stdint) {
+        chaz_ConfWriter_add_sys_include("stdint.h");
+    }
+    else {
+        /* We support only the following subset of stdint.h
+         *   int8_t
+         *   int16_t
+         *   int32_t
+         *   int64_t
+         *   uint8_t
+         *   uint16_t
+         *   uint32_t
+         *   uint64_t
+         */
+        if (has_8) {
+            chaz_ConfWriter_add_global_typedef("signed char", "int8_t");
+            chaz_ConfWriter_add_global_typedef("unsigned char", "uint8_t");
+        }
+        if (has_16) {
+            chaz_ConfWriter_add_global_typedef("signed short", "int16_t");
+            chaz_ConfWriter_add_global_typedef("unsigned short", "uint16_t");
+        }
+        if (has_32) {
+            chaz_ConfWriter_add_global_typedef(i32_t_type, "int32_t");
+            sprintf(scratch, "unsigned %s", i32_t_type);
+            chaz_ConfWriter_add_global_typedef(scratch, "uint32_t");
+        }
+        if (has_64) {
+            chaz_ConfWriter_add_global_typedef(i64_t_type, "int64_t");
+            sprintf(scratch, "unsigned %s", i64_t_type);
+            chaz_ConfWriter_add_global_typedef(scratch, "uint64_t");
+        }
+    }
+
+    chaz_ConfWriter_end_module();
+
+    /* Integer limits. */
+
+    chaz_ConfWriter_start_module("IntegerLimits");
+
+    if (has_stdint) {
+        chaz_ConfWriter_add_sys_include("stdint.h");
+    }
+    else {
+        /* We support only the following subset of stdint.h
+         *   INT8_MAX
+         *   INT16_MAX
+         *   INT32_MAX
+         *   INT64_MAX
+         *   INT8_MIN
+         *   INT16_MIN
+         *   INT32_MIN
+         *   INT64_MIN
+         *   UINT8_MAX
+         *   UINT16_MAX
+         *   UINT32_MAX
+         *   UINT64_MAX
+         *   SIZE_MAX
+         */
+        if (has_8) {
+            chaz_ConfWriter_add_global_def("INT8_MAX", "127");
+            chaz_ConfWriter_add_global_def("INT8_MIN", "-128");
+            chaz_ConfWriter_add_global_def("UINT8_MAX", "255");
+        }
+        if (has_16) {
+            chaz_ConfWriter_add_global_def("INT16_MAX", "32767");
+            chaz_ConfWriter_add_global_def("INT16_MIN", "-32768");
+            chaz_ConfWriter_add_global_def("UINT16_MAX", "65535");
+        }
+        if (has_32) {
+            chaz_ConfWriter_add_global_def("INT32_MAX", "2147483647");
+            chaz_ConfWriter_add_global_def("INT32_MIN", "(-INT32_MAX-1)");
+            chaz_ConfWriter_add_global_def("UINT32_MAX", "4294967295U");
+        }
+        if (has_64) {
+            sprintf(scratch, "9223372036854775807%s", i64_t_postfix);
+            chaz_ConfWriter_add_global_def("INT64_MAX", scratch);
+            chaz_ConfWriter_add_global_def("INT64_MIN", "(-INT64_MAX-1)");
+            sprintf(scratch, "18446744073709551615%s", u64_t_postfix);
+            chaz_ConfWriter_add_global_def("UINT64_MAX", scratch);
+        }
+        chaz_ConfWriter_add_global_def("SIZE_MAX", "((size_t)-1)");
+    }
+
+    chaz_ConfWriter_end_module();
+
+    /* Integer literals. */
+
+    chaz_ConfWriter_start_module("IntegerLiterals");
+
+    if (has_stdint) {
+        chaz_ConfWriter_add_sys_include("stdint.h");
+    }
+    else {
+        /* We support only the following subset of stdint.h
+         *   INT32_C
+         *   INT64_C
+         *   UINT32_C
+         *   UINT64_C
+         */
+        if (has_32) {
+            if (strcmp(i32_t_postfix, "") == 0) {
+                chaz_ConfWriter_add_global_def("INT32_C(n)", "n");
             }
-            if (has_64) {
-                chaz_ConfWriter_add_global_typedef(i64_t_type, "int64_t");
-                sprintf(scratch, "unsigned %s", i64_t_type);
-                chaz_ConfWriter_add_global_typedef(scratch, "uint64_t");
-                sprintf(scratch, "9223372036854775807%s", i64_t_postfix);
-                chaz_ConfWriter_add_global_def("INT64_MAX", scratch);
-                chaz_ConfWriter_add_global_def("INT64_MIN", "(-INT64_MAX-1)");
-                sprintf(scratch, "18446744073709551615%s", u64_t_postfix);
-                chaz_ConfWriter_add_global_def("UINT64_MAX", scratch);
-                sprintf(scratch, "n##%s", i64_t_postfix);
-                chaz_ConfWriter_add_global_def("INT64_C(n)", scratch);
-                sprintf(scratch, "n##%s", u64_t_postfix);
-                chaz_ConfWriter_add_global_def("UINT64_C(n)", scratch);
+            else {
+                sprintf(scratch, "n##%s", i32_t_postfix);
+                chaz_ConfWriter_add_global_def("INT32_C(n)", scratch);
             }
-            chaz_ConfWriter_add_global_def("SIZE_MAX", "((size_t)-1)");
+            sprintf(scratch, "n##%s", u32_t_postfix);
+            chaz_ConfWriter_add_global_def("UINT32_C(n)", scratch);
         }
+        if (has_64) {
+            sprintf(scratch, "n##%s", i64_t_postfix);
+            chaz_ConfWriter_add_global_def("INT64_C(n)", scratch);
+            sprintf(scratch, "n##%s", u64_t_postfix);
+            chaz_ConfWriter_add_global_def("UINT64_C(n)", scratch);
+        }
+    }
+
+    chaz_ConfWriter_end_module();
+
+    /* Integer format strings. */
+
+    chaz_ConfWriter_start_module("IntegerFormatStrings");
 
-        /* Create the PRId64 and PRIu64 printf macros. */
+    if (has_inttypes) {
+        chaz_ConfWriter_add_sys_include("inttypes.h");
+    }
+    else {
+        /* We support only the following subset of inttypes.h
+         *   PRId64
+         *   PRIu64
+         */
         if (has_64) {
             int i;
             const char *options[] = {
@@ -5272,32 +5653,6 @@ chaz_Integers_run(void) {
         }
     }
 
-    /* Create macro for promoting pointers to integers. */
-    if (has_64) {
-        if (sizeof_ptr == 8) {
-            chaz_ConfWriter_add_def("PTR_TO_I64(ptr)",
-                                    "((int64_t)(uint64_t)(ptr))");
-        }
-        else {
-            chaz_ConfWriter_add_def("PTR_TO_I64(ptr)",
-                                    "((int64_t)(uint32_t)(ptr))");
-        }
-    }
-
-    /* Create macro for converting uint64_t to double. */
-    if (can_convert_u64_to_double) {
-        chaz_ConfWriter_add_def("U64_TO_DOUBLE(num)",
-                                "((double)(num))");
-    }
-    else {
-        chaz_ConfWriter_add_def(
-            "U64_TO_DOUBLE(num)",
-            "((num) & UINT64_C(0x8000000000000000) ? "
-            "(double)(int64_t)((num) & UINT64_C(0x7FFFFFFFFFFFFFFF)) + "
-            "9223372036854775808.0 : "
-            "(double)(int64_t)(num))");
-    }
-
     chaz_ConfWriter_end_module();
 }
 
@@ -5392,6 +5747,71 @@ chaz_Strings_probe_c99_snprintf(void) {
 
 /***************************************************************************/
 
+#line 17 "src/Charmonizer/Probe/SymbolVisibility.c"
+/* #include "Charmonizer/Probe/SymbolVisibility.h" */
+/* #include "Charmonizer/Core/Compiler.h" */
+/* #include "Charmonizer/Core/ConfWriter.h" */
+/* #include "Charmonizer/Core/Util.h" */
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+static const char chaz_SymbolVisibility_symbol_exporting_code[] =
+    CHAZ_QUOTE(  %s int exported_function() {   )
+    CHAZ_QUOTE(      return 42;                 )
+    CHAZ_QUOTE(  }                              )
+    CHAZ_QUOTE(  int main() {                   )
+    CHAZ_QUOTE(      return 0;                  )
+    CHAZ_QUOTE(  }                              );
+
+void
+chaz_SymbolVisibility_run(void) {
+    chaz_CFlags *temp_cflags = chaz_CC_get_temp_cflags();
+    int can_control_visibility = false;
+    char code_buf[sizeof(chaz_SymbolVisibility_symbol_exporting_code) + 100];
+
+    chaz_ConfWriter_start_module("SymbolVisibility");
+    chaz_CFlags_set_warnings_as_errors(temp_cflags);
+
+    /* Windows. */
+    if (!can_control_visibility) {
+        char export_win[] = "__declspec(dllexport)";
+        sprintf(code_buf, chaz_SymbolVisibility_symbol_exporting_code,
+                export_win);
+        if (chaz_CC_test_compile(code_buf)) {
+            can_control_visibility = true;
+            chaz_ConfWriter_add_def("EXPORT", export_win);
+            chaz_ConfWriter_add_def("IMPORT", "__declspec(dllimport)");
+        }
+    }
+
+    /* GCC. */
+    if (!can_control_visibility) {
+        char export_gcc[] = "__attribute__ ((visibility (\"default\")))";
+        sprintf(code_buf, chaz_SymbolVisibility_symbol_exporting_code,
+                export_gcc);
+        if (chaz_CC_test_compile(code_buf)) {
+            can_control_visibility = true;
+            chaz_ConfWriter_add_def("EXPORT", export_gcc);
+            chaz_ConfWriter_add_def("IMPORT", NULL);
+        }
+    }
+
+    chaz_CFlags_clear(temp_cflags);
+
+    /* Default. */
+    if (!can_control_visibility) {
+        chaz_ConfWriter_add_def("EXPORT", NULL);
+        chaz_ConfWriter_add_def("IMPORT", NULL);
+    }
+
+    chaz_ConfWriter_end_module();
+}
+
+
+
+/***************************************************************************/
+
 #line 17 "src/Charmonizer/Probe/UnusedVars.c"
 /* #include "Charmonizer/Core/ConfWriter.h" */
 /* #include "Charmonizer/Core/Util.h" */
@@ -5672,12 +6092,18 @@ int main(int argc, const char **argv) {
         S_add_compiler_flags(&args);
     }
 
+    /* Define stdint types in charmony.h. */
+    chaz_ConfWriter_append_conf("#define CHY_EMPLOY_INTEGERTYPES\n\n");
+
     /* Run probe modules. */
     chaz_BuildEnv_run();
     chaz_DirManip_run();
     chaz_Headers_run();
+    chaz_FuncMacro_run();
+    chaz_Booleans_run();
     chaz_Integers_run();
     chaz_Strings_run();
+    chaz_SymbolVisibility_run();
     chaz_UnusedVars_run();
 
     if (args.write_makefile) {

http://git-wip-us.apache.org/repos/asf/lucy/blob/e7cdce42/clownfish/runtime/common/charmonizer.c
----------------------------------------------------------------------
diff --git a/clownfish/runtime/common/charmonizer.c b/clownfish/runtime/common/charmonizer.c
index d494373..0b9bbaf 100644
--- a/clownfish/runtime/common/charmonizer.c
+++ b/clownfish/runtime/common/charmonizer.c
@@ -2456,6 +2456,7 @@ typedef struct chaz_ConfElem {
 /* Static vars. */
 static struct {
     FILE          *fh;
+    char          *MODULE_NAME;
     chaz_ConfElem *defs;
     size_t         def_cap;
     size_t         def_count;
@@ -2553,18 +2554,17 @@ chaz_ConfWriterC_vappend_conf(const char *fmt, va_list args) {
 
 static int
 chaz_ConfWriterC_sym_is_uppercase(const char *sym) {
-    unsigned i;
-    for (i = 0; sym[i] != 0; i++) {
-        if (!isupper(sym[i])) {
-            if (islower(sym[i])) {
-                return false;
-            }
-            else if (sym[i] != '_') {
-                return true;
-            }
-        }
+    return isupper(sym[0]);
+}
+
+static char*
+chaz_ConfWriterC_uppercase_string(const char *src) {
+    char *retval = chaz_Util_strdup(src);
+    size_t i;
+    for (i = 0; retval[i]; ++i) {
+        retval[i] = toupper(retval[i]);
     }
-    return true;
+    return retval;
 }
 
 static void
@@ -2599,9 +2599,10 @@ chaz_ConfWriterC_add_global_def(const char *sym, const char *value) {
 
 static void
 chaz_ConfWriterC_append_global_def_to_conf(const char *sym,
-        const char *value) {
+                                           const char *value) {
     char *name_end = strchr(sym, '(');
     if (name_end == NULL) {
+        if (strcmp(sym, value) == 0) { return; }
         fprintf(chaz_ConfWriterC.fh, "#ifndef %s\n", sym);
     }
     else {
@@ -2643,7 +2644,8 @@ chaz_ConfWriterC_add_global_typedef(const char *type, const char *alias) {
 
 static void
 chaz_ConfWriterC_append_global_typedef_to_conf(const char *type,
-        const char *alias) {
+                                               const char *alias) {
+    if (strcmp(type, alias) == 0) { return; }
     fprintf(chaz_ConfWriterC.fh, "typedef %s %s;\n", type, alias);
 }
 
@@ -2672,32 +2674,37 @@ chaz_ConfWriterC_append_local_include_to_conf(const char *header) {
 static void
 chaz_ConfWriterC_start_module(const char *module_name) {
     fprintf(chaz_ConfWriterC.fh, "\n/* %s */\n", module_name);
+    chaz_ConfWriterC.MODULE_NAME
+        = chaz_ConfWriterC_uppercase_string(module_name);
 }
 
 static void
 chaz_ConfWriterC_end_module(void) {
+    size_t num_globals = 0;
     size_t i;
     chaz_ConfElem *defs = chaz_ConfWriterC.defs;
     for (i = 0; i < chaz_ConfWriterC.def_count; i++) {
         switch (defs[i].type) {
+            case CHAZ_CONFELEM_GLOBAL_DEF:
+                ++num_globals;
+            /* fall through */
             case CHAZ_CONFELEM_DEF:
                 chaz_ConfWriterC_append_def_to_conf(defs[i].str1,
                                                     defs[i].str2);
                 break;
-            case CHAZ_CONFELEM_GLOBAL_DEF:
-                chaz_ConfWriterC_append_global_def_to_conf(defs[i].str1,
-                                                           defs[i].str2);
-                break;
+            case CHAZ_CONFELEM_GLOBAL_TYPEDEF: {
+                ++num_globals;
+                char *sym = chaz_ConfWriterC_uppercase_string(defs[i].str1);
+                chaz_ConfWriterC_append_def_to_conf(sym, defs[i].str2);
+                free(sym);
+            }
+            /* fall through */
             case CHAZ_CONFELEM_TYPEDEF:
                 chaz_ConfWriterC_append_typedef_to_conf(defs[i].str2,
                                                         defs[i].str1);
                 break;
-            case CHAZ_CONFELEM_GLOBAL_TYPEDEF:
-                chaz_ConfWriterC_append_global_typedef_to_conf(defs[i].str2,
-                                                               defs[i].str1);
-                break;
             case CHAZ_CONFELEM_SYS_INCLUDE:
-                chaz_ConfWriterC_append_sys_include_to_conf(defs[i].str1);
+                ++num_globals;
                 break;
             case CHAZ_CONFELEM_LOCAL_INCLUDE:
                 chaz_ConfWriterC_append_local_include_to_conf(defs[i].str1);
@@ -2715,7 +2722,7 @@ chaz_ConfWriterC_end_module(void) {
     );
     for (i = 0; i < chaz_ConfWriterC.def_count; i++) {
         switch (defs[i].type) {
-            case CHAZ_CONFELEM_DEF: 
+            case CHAZ_CONFELEM_DEF:
             case CHAZ_CONFELEM_TYPEDEF:
                 {
                     const char *sym = defs[i].str1;
@@ -2742,8 +2749,41 @@ chaz_ConfWriterC_end_module(void) {
     }
 
     fprintf(chaz_ConfWriterC.fh, "#endif /* USE_SHORT_NAMES */\n");
+
+    /* Write out global definitions and system includes. */
+    if (num_globals) {
+        fprintf(chaz_ConfWriterC.fh, "\n#ifdef CHY_EMPLOY_%s\n\n",
+                chaz_ConfWriterC.MODULE_NAME);
+        for (i = 0; i < chaz_ConfWriterC.def_count; i++) {
+            switch (defs[i].type) {
+                case CHAZ_CONFELEM_GLOBAL_DEF:
+                    chaz_ConfWriterC_append_global_def_to_conf(defs[i].str1,
+                                                               defs[i].str2);
+                    break;
+                case CHAZ_CONFELEM_GLOBAL_TYPEDEF:
+                    chaz_ConfWriterC_append_global_typedef_to_conf(
+                            defs[i].str2, defs[i].str1);
+                    break;
+                case CHAZ_CONFELEM_SYS_INCLUDE:
+                    chaz_ConfWriterC_append_sys_include_to_conf(defs[i].str1);
+                    break;
+                case CHAZ_CONFELEM_DEF:
+                case CHAZ_CONFELEM_TYPEDEF:
+                case CHAZ_CONFELEM_LOCAL_INCLUDE:
+                    /* no-op */
+                    break;
+                default:
+                    chaz_Util_die("Internal error: bad element type %d",
+                                  (int)defs[i].type);
+            }
+        }
+        fprintf(chaz_ConfWriterC.fh, "\n#endif /* EMPLOY_%s */\n",
+                chaz_ConfWriterC.MODULE_NAME);
+    }
+
     fprintf(chaz_ConfWriterC.fh, "\n");
 
+    free(chaz_ConfWriterC.MODULE_NAME);
     chaz_ConfWriterC_clear_def_list();
 }
 
@@ -4806,7 +4846,7 @@ chaz_Booleans_run(void) {
     }
     else {
         chaz_ConfWriter_append_conf(
-            "#ifndef __cplusplus\n"
+            "#if (defined(CHY_EMPLOY_BOOLEANS) && !defined(__cplusplus))\n"
             "  typedef int bool;\n"
             "  #ifndef true\n"
             "    #define true 1\n"
@@ -5053,14 +5093,35 @@ chaz_Floats_run(void) {
     chaz_ConfWriter_start_module("Floats");
 
     chaz_ConfWriter_append_conf(
-        "typedef union { uint32_t i; float f; } chy_floatu32;\n"
-        "typedef union { uint64_t i; double d; } chy_floatu64;\n"
-        "static const chy_floatu32 chy_f32inf    = {UINT32_C(0x7f800000)};\n"
-        "static const chy_floatu32 chy_f32neginf = {UINT32_C(0xff800000)};\n"
-        "static const chy_floatu32 chy_f32nan    = {UINT32_C(0x7fc00000)};\n"
-        "static const chy_floatu64 chy_f64inf    = {UINT64_C(0x7ff0000000000000)};\n"
-        "static const chy_floatu64 chy_f64neginf = {UINT64_C(0xfff0000000000000)};\n"
-        "static const chy_floatu64 chy_f64nan    = {UINT64_C(0x7ff8000000000000)};\n"
+        "typedef union { unsigned char c[4]; float f; } chy_floatu32;\n"
+        "typedef union { unsigned char c[8]; double d; } chy_floatu64;\n"
+        "#ifdef CHY_BIG_END\n"
+        "static const chy_floatu32 chy_f32inf\n"
+        "    = { { 0x7F, 0x80, 0, 0 } };\n"
+        "static const chy_floatu32 chy_f32neginf\n"
+        "    = { { 0xFF, 0x80, 0, 0 } };\n"
+        "static const chy_floatu32 chy_f32nan\n"
+        "    = { { 0x7F, 0xC0, 0, 0 } };\n"
+        "static const chy_floatu64 chy_f64inf\n"
+        "    = { { 0x7F, 0xF0, 0, 0, 0, 0, 0, 0 } };\n"
+        "static const chy_floatu64 chy_f64neginf\n"
+        "    = { { 0xFF, 0xF0, 0, 0, 0, 0, 0, 0 } };\n"
+        "static const chy_floatu64 chy_f64nan\n"
+        "    = { { 0x7F, 0xF8, 0, 0, 0, 0, 0, 0 } };\n"
+        "#else /* BIG_END */\n"
+        "static const chy_floatu32 chy_f32inf\n"
+        "    = { { 0, 0, 0x80, 0x7F } };\n"
+        "static const chy_floatu32 chy_f32neginf\n"
+        "    = { { 0, 0, 0x80, 0xFF } };\n"
+        "static const chy_floatu32 chy_f32nan\n"
+        "    = { { 0, 0, 0xC0, 0x7F } };\n"
+        "static const chy_floatu64 chy_f64inf\n"
+        "    = { { 0, 0, 0, 0, 0, 0, 0xF0, 0x7F } };\n"
+        "static const chy_floatu64 chy_f64neginf\n"
+        "    = { { 0, 0, 0, 0, 0, 0, 0xF0, 0xFF } };\n"
+        "static const chy_floatu64 chy_f64nan\n"
+        "    = { { 0, 0, 0, 0, 0, 0, 0xF8, 0x7F } };\n"
+        "#endif /* BIG_END */\n"
     );
     chaz_ConfWriter_add_def("F32_INF", "(chy_f32inf.f)");
     chaz_ConfWriter_add_def("F32_NEGINF", "(chy_f32neginf.f)");
@@ -5517,7 +5578,7 @@ static const char chaz_Integers_u64_to_double_code[] =
     CHAZ_QUOTE(  #include <stdio.h>                        )
     CHAZ_QUOTE(  int main()                                )
     CHAZ_QUOTE(  {                                         )
-    CHAZ_QUOTE(      unsigned __int64 int_num = 0;         )
+    CHAZ_QUOTE(      unsigned %s int_num = 0;              )
     CHAZ_QUOTE(      double float_num;                     )
     CHAZ_QUOTE(      float_num = (double)int_num;          )
     CHAZ_QUOTE(      printf("%%f\n", float_num);           )
@@ -5674,13 +5735,6 @@ chaz_Integers_run(void) {
         }
     }
 
-    /* Determine whether conversion of unsigned __int64 to double works */
-    if (has___int64) {
-        if (!chaz_CC_test_compile(chaz_Integers_u64_to_double_code)) {
-            can_convert_u64_to_double = false;
-        }
-    }
-
     /* Write out some conditional defines. */
     if (has_inttypes) {
         chaz_ConfWriter_add_def("HAS_INTTYPES_H", NULL);
@@ -5729,92 +5783,179 @@ chaz_Integers_run(void) {
         chaz_ConfWriter_add_def("HAS_INT64_T", NULL);
     }
 
-    /* Write typedefs, maximums/minimums and literals macros. */
-    if (has_inttypes) {
-        chaz_ConfWriter_add_sys_include("inttypes.h");
+    /* Create macro for promoting pointers to integers. */
+    if (has_64) {
+        if (sizeof_ptr == 8) {
+            chaz_ConfWriter_add_def("PTR_TO_I64(ptr)",
+                                    "((int64_t)(uint64_t)(ptr))");
+        }
+        else {
+            chaz_ConfWriter_add_def("PTR_TO_I64(ptr)",
+                                    "((int64_t)(uint32_t)(ptr))");
+        }
     }
-    else {
-        if (has_stdint) {
-            chaz_ConfWriter_add_sys_include("stdint.h");
+
+    /* Create macro for converting uint64_t to double. */
+    if (has_64) {
+        /*
+         * Determine whether unsigned 64-bit integers can be converted to
+         * double. Older MSVC versions don't support this conversion.
+         */
+        sprintf(code_buf, chaz_Integers_u64_to_double_code, i64_t_type);
+        output = chaz_CC_capture_output(code_buf, &output_len);
+        if (output != NULL) {
+            chaz_ConfWriter_add_def("U64_TO_DOUBLE(num)", "((double)(num))");
+            free(output);
         }
         else {
-            /* We support only the following subset of stdint.h
-             *   int8_t
-             *   int16_t
-             *   int32_t
-             *   int64_t
-             *   uint8_t
-             *   uint16_t
-             *   uint32_t
-             *   uint64_t
-             *   INT8_MAX
-             *   INT16_MAX
-             *   INT32_MAX
-             *   INT64_MAX
-             *   INT8_MIN
-             *   INT16_MIN
-             *   INT32_MIN
-             *   INT64_MIN
-             *   UINT8_MAX
-             *   UINT16_MAX
-             *   UINT32_MAX
-             *   UINT64_MAX
-             *   SIZE_MAX
-             *   INT32_C
-             *   INT64_C
-             *   UINT32_C
-             *   UINT64_C
-             */
-            if (has_8) {
-                chaz_ConfWriter_add_global_typedef("signed char", "int8_t");
-                chaz_ConfWriter_add_global_typedef("unsigned char", "uint8_t");
-                chaz_ConfWriter_add_global_def("INT8_MAX", "127");
-                chaz_ConfWriter_add_global_def("INT8_MIN", "-128");
-                chaz_ConfWriter_add_global_def("UINT8_MAX", "255");
-            }
-            if (has_16) {
-                chaz_ConfWriter_add_global_typedef("signed short", "int16_t");
-                chaz_ConfWriter_add_global_typedef("unsigned short",
-                                                   "uint16_t");
-                chaz_ConfWriter_add_global_def("INT16_MAX", "32767");
-                chaz_ConfWriter_add_global_def("INT16_MIN", "-32768");
-                chaz_ConfWriter_add_global_def("UINT16_MAX", "65535");
-            }
-            if (has_32) {
-                chaz_ConfWriter_add_global_typedef(i32_t_type, "int32_t");
-                sprintf(scratch, "unsigned %s", i32_t_type);
-                chaz_ConfWriter_add_global_typedef(scratch, "uint32_t");
-                chaz_ConfWriter_add_global_def("INT32_MAX", "2147483647");
-                chaz_ConfWriter_add_global_def("INT32_MIN", "(-INT32_MAX-1)");
-                chaz_ConfWriter_add_global_def("UINT32_MAX", "4294967295U");
-                if (strcmp(i32_t_postfix, "") == 0) {
-                    chaz_ConfWriter_add_global_def("INT32_C(n)", "n");
-                }
-                else {
-                    sprintf(scratch, "n##%s", i32_t_postfix);
-                    chaz_ConfWriter_add_global_def("INT32_C(n)", scratch);
-                }
-                sprintf(scratch, "n##%s", u32_t_postfix);
-                chaz_ConfWriter_add_global_def("UINT32_C(n)", scratch);
+            chaz_ConfWriter_add_def(
+                "U64_TO_DOUBLE(num)",
+                "((num) & UINT64_C(0x8000000000000000) ? "
+                "(double)(int64_t)((num) & UINT64_C(0x7FFFFFFFFFFFFFFF)) + "
+                "9223372036854775808.0 : "
+                "(double)(int64_t)(num))");
+        }
+    }
+
+    chaz_ConfWriter_end_module();
+
+    /* Integer typedefs. */
+
+    chaz_ConfWriter_start_module("IntegerTypes");
+
+    if (has_stdint) {
+        chaz_ConfWriter_add_sys_include("stdint.h");
+    }
+    else {
+        /* We support only the following subset of stdint.h
+         *   int8_t
+         *   int16_t
+         *   int32_t
+         *   int64_t
+         *   uint8_t
+         *   uint16_t
+         *   uint32_t
+         *   uint64_t
+         */
+        if (has_8) {
+            chaz_ConfWriter_add_global_typedef("signed char", "int8_t");
+            chaz_ConfWriter_add_global_typedef("unsigned char", "uint8_t");
+        }
+        if (has_16) {
+            chaz_ConfWriter_add_global_typedef("signed short", "int16_t");
+            chaz_ConfWriter_add_global_typedef("unsigned short", "uint16_t");
+        }
+        if (has_32) {
+            chaz_ConfWriter_add_global_typedef(i32_t_type, "int32_t");
+            sprintf(scratch, "unsigned %s", i32_t_type);
+            chaz_ConfWriter_add_global_typedef(scratch, "uint32_t");
+        }
+        if (has_64) {
+            chaz_ConfWriter_add_global_typedef(i64_t_type, "int64_t");
+            sprintf(scratch, "unsigned %s", i64_t_type);
+            chaz_ConfWriter_add_global_typedef(scratch, "uint64_t");
+        }
+    }
+
+    chaz_ConfWriter_end_module();
+
+    /* Integer limits. */
+
+    chaz_ConfWriter_start_module("IntegerLimits");
+
+    if (has_stdint) {
+        chaz_ConfWriter_add_sys_include("stdint.h");
+    }
+    else {
+        /* We support only the following subset of stdint.h
+         *   INT8_MAX
+         *   INT16_MAX
+         *   INT32_MAX
+         *   INT64_MAX
+         *   INT8_MIN
+         *   INT16_MIN
+         *   INT32_MIN
+         *   INT64_MIN
+         *   UINT8_MAX
+         *   UINT16_MAX
+         *   UINT32_MAX
+         *   UINT64_MAX
+         *   SIZE_MAX
+         */
+        if (has_8) {
+            chaz_ConfWriter_add_global_def("INT8_MAX", "127");
+            chaz_ConfWriter_add_global_def("INT8_MIN", "-128");
+            chaz_ConfWriter_add_global_def("UINT8_MAX", "255");
+        }
+        if (has_16) {
+            chaz_ConfWriter_add_global_def("INT16_MAX", "32767");
+            chaz_ConfWriter_add_global_def("INT16_MIN", "-32768");
+            chaz_ConfWriter_add_global_def("UINT16_MAX", "65535");
+        }
+        if (has_32) {
+            chaz_ConfWriter_add_global_def("INT32_MAX", "2147483647");
+            chaz_ConfWriter_add_global_def("INT32_MIN", "(-INT32_MAX-1)");
+            chaz_ConfWriter_add_global_def("UINT32_MAX", "4294967295U");
+        }
+        if (has_64) {
+            sprintf(scratch, "9223372036854775807%s", i64_t_postfix);
+            chaz_ConfWriter_add_global_def("INT64_MAX", scratch);
+            chaz_ConfWriter_add_global_def("INT64_MIN", "(-INT64_MAX-1)");
+            sprintf(scratch, "18446744073709551615%s", u64_t_postfix);
+            chaz_ConfWriter_add_global_def("UINT64_MAX", scratch);
+        }
+        chaz_ConfWriter_add_global_def("SIZE_MAX", "((size_t)-1)");
+    }
+
+    chaz_ConfWriter_end_module();
+
+    /* Integer literals. */
+
+    chaz_ConfWriter_start_module("IntegerLiterals");
+
+    if (has_stdint) {
+        chaz_ConfWriter_add_sys_include("stdint.h");
+    }
+    else {
+        /* We support only the following subset of stdint.h
+         *   INT32_C
+         *   INT64_C
+         *   UINT32_C
+         *   UINT64_C
+         */
+        if (has_32) {
+            if (strcmp(i32_t_postfix, "") == 0) {
+                chaz_ConfWriter_add_global_def("INT32_C(n)", "n");
             }
-            if (has_64) {
-                chaz_ConfWriter_add_global_typedef(i64_t_type, "int64_t");
-                sprintf(scratch, "unsigned %s", i64_t_type);
-                chaz_ConfWriter_add_global_typedef(scratch, "uint64_t");
-                sprintf(scratch, "9223372036854775807%s", i64_t_postfix);
-                chaz_ConfWriter_add_global_def("INT64_MAX", scratch);
-                chaz_ConfWriter_add_global_def("INT64_MIN", "(-INT64_MAX-1)");
-                sprintf(scratch, "18446744073709551615%s", u64_t_postfix);
-                chaz_ConfWriter_add_global_def("UINT64_MAX", scratch);
-                sprintf(scratch, "n##%s", i64_t_postfix);
-                chaz_ConfWriter_add_global_def("INT64_C(n)", scratch);
-                sprintf(scratch, "n##%s", u64_t_postfix);
-                chaz_ConfWriter_add_global_def("UINT64_C(n)", scratch);
+            else {
+                sprintf(scratch, "n##%s", i32_t_postfix);
+                chaz_ConfWriter_add_global_def("INT32_C(n)", scratch);
             }
-            chaz_ConfWriter_add_global_def("SIZE_MAX", "((size_t)-1)");
+            sprintf(scratch, "n##%s", u32_t_postfix);
+            chaz_ConfWriter_add_global_def("UINT32_C(n)", scratch);
+        }
+        if (has_64) {
+            sprintf(scratch, "n##%s", i64_t_postfix);
+            chaz_ConfWriter_add_global_def("INT64_C(n)", scratch);
+            sprintf(scratch, "n##%s", u64_t_postfix);
+            chaz_ConfWriter_add_global_def("UINT64_C(n)", scratch);
         }
+    }
+
+    chaz_ConfWriter_end_module();
+
+    /* Integer format strings. */
 
-        /* Create the PRId64 and PRIu64 printf macros. */
+    chaz_ConfWriter_start_module("IntegerFormatStrings");
+
+    if (has_inttypes) {
+        chaz_ConfWriter_add_sys_include("inttypes.h");
+    }
+    else {
+        /* We support only the following subset of inttypes.h
+         *   PRId64
+         *   PRIu64
+         */
         if (has_64) {
             int i;
             const char *options[] = {
@@ -5853,32 +5994,6 @@ chaz_Integers_run(void) {
         }
     }
 
-    /* Create macro for promoting pointers to integers. */
-    if (has_64) {
-        if (sizeof_ptr == 8) {
-            chaz_ConfWriter_add_def("PTR_TO_I64(ptr)",
-                                    "((int64_t)(uint64_t)(ptr))");
-        }
-        else {
-            chaz_ConfWriter_add_def("PTR_TO_I64(ptr)",
-                                    "((int64_t)(uint32_t)(ptr))");
-        }
-    }
-
-    /* Create macro for converting uint64_t to double. */
-    if (can_convert_u64_to_double) {
-        chaz_ConfWriter_add_def("U64_TO_DOUBLE(num)",
-                                "((double)(num))");
-    }
-    else {
-        chaz_ConfWriter_add_def(
-            "U64_TO_DOUBLE(num)",
-            "((num) & UINT64_C(0x8000000000000000) ? "
-            "(double)(int64_t)((num) & UINT64_C(0x7FFFFFFFFFFFFFFF)) + "
-            "9223372036854775808.0 : "
-            "(double)(int64_t)(num))");
-    }
-
     chaz_ConfWriter_end_module();
 }
 

http://git-wip-us.apache.org/repos/asf/lucy/blob/e7cdce42/common/charmonizer.c
----------------------------------------------------------------------
diff --git a/common/charmonizer.c b/common/charmonizer.c
index e065c93..d3d0048 100644
--- a/common/charmonizer.c
+++ b/common/charmonizer.c
@@ -2456,6 +2456,7 @@ typedef struct chaz_ConfElem {
 /* Static vars. */
 static struct {
     FILE          *fh;
+    char          *MODULE_NAME;
     chaz_ConfElem *defs;
     size_t         def_cap;
     size_t         def_count;
@@ -2553,18 +2554,17 @@ chaz_ConfWriterC_vappend_conf(const char *fmt, va_list args) {
 
 static int
 chaz_ConfWriterC_sym_is_uppercase(const char *sym) {
-    unsigned i;
-    for (i = 0; sym[i] != 0; i++) {
-        if (!isupper(sym[i])) {
-            if (islower(sym[i])) {
-                return false;
-            }
-            else if (sym[i] != '_') {
-                return true;
-            }
-        }
+    return isupper(sym[0]);
+}
+
+static char*
+chaz_ConfWriterC_uppercase_string(const char *src) {
+    char *retval = chaz_Util_strdup(src);
+    size_t i;
+    for (i = 0; retval[i]; ++i) {
+        retval[i] = toupper(retval[i]);
     }
-    return true;
+    return retval;
 }
 
 static void
@@ -2599,9 +2599,10 @@ chaz_ConfWriterC_add_global_def(const char *sym, const char *value) {
 
 static void
 chaz_ConfWriterC_append_global_def_to_conf(const char *sym,
-        const char *value) {
+                                           const char *value) {
     char *name_end = strchr(sym, '(');
     if (name_end == NULL) {
+        if (strcmp(sym, value) == 0) { return; }
         fprintf(chaz_ConfWriterC.fh, "#ifndef %s\n", sym);
     }
     else {
@@ -2643,7 +2644,8 @@ chaz_ConfWriterC_add_global_typedef(const char *type, const char *alias) {
 
 static void
 chaz_ConfWriterC_append_global_typedef_to_conf(const char *type,
-        const char *alias) {
+                                               const char *alias) {
+    if (strcmp(type, alias) == 0) { return; }
     fprintf(chaz_ConfWriterC.fh, "typedef %s %s;\n", type, alias);
 }
 
@@ -2672,32 +2674,37 @@ chaz_ConfWriterC_append_local_include_to_conf(const char *header) {
 static void
 chaz_ConfWriterC_start_module(const char *module_name) {
     fprintf(chaz_ConfWriterC.fh, "\n/* %s */\n", module_name);
+    chaz_ConfWriterC.MODULE_NAME
+        = chaz_ConfWriterC_uppercase_string(module_name);
 }
 
 static void
 chaz_ConfWriterC_end_module(void) {
+    size_t num_globals = 0;
     size_t i;
     chaz_ConfElem *defs = chaz_ConfWriterC.defs;
     for (i = 0; i < chaz_ConfWriterC.def_count; i++) {
         switch (defs[i].type) {
+            case CHAZ_CONFELEM_GLOBAL_DEF:
+                ++num_globals;
+            /* fall through */
             case CHAZ_CONFELEM_DEF:
                 chaz_ConfWriterC_append_def_to_conf(defs[i].str1,
                                                     defs[i].str2);
                 break;
-            case CHAZ_CONFELEM_GLOBAL_DEF:
-                chaz_ConfWriterC_append_global_def_to_conf(defs[i].str1,
-                                                           defs[i].str2);
-                break;
+            case CHAZ_CONFELEM_GLOBAL_TYPEDEF: {
+                ++num_globals;
+                char *sym = chaz_ConfWriterC_uppercase_string(defs[i].str1);
+                chaz_ConfWriterC_append_def_to_conf(sym, defs[i].str2);
+                free(sym);
+            }
+            /* fall through */
             case CHAZ_CONFELEM_TYPEDEF:
                 chaz_ConfWriterC_append_typedef_to_conf(defs[i].str2,
                                                         defs[i].str1);
                 break;
-            case CHAZ_CONFELEM_GLOBAL_TYPEDEF:
-                chaz_ConfWriterC_append_global_typedef_to_conf(defs[i].str2,
-                                                               defs[i].str1);
-                break;
             case CHAZ_CONFELEM_SYS_INCLUDE:
-                chaz_ConfWriterC_append_sys_include_to_conf(defs[i].str1);
+                ++num_globals;
                 break;
             case CHAZ_CONFELEM_LOCAL_INCLUDE:
                 chaz_ConfWriterC_append_local_include_to_conf(defs[i].str1);
@@ -2715,7 +2722,7 @@ chaz_ConfWriterC_end_module(void) {
     );
     for (i = 0; i < chaz_ConfWriterC.def_count; i++) {
         switch (defs[i].type) {
-            case CHAZ_CONFELEM_DEF: 
+            case CHAZ_CONFELEM_DEF:
             case CHAZ_CONFELEM_TYPEDEF:
                 {
                     const char *sym = defs[i].str1;
@@ -2742,8 +2749,41 @@ chaz_ConfWriterC_end_module(void) {
     }
 
     fprintf(chaz_ConfWriterC.fh, "#endif /* USE_SHORT_NAMES */\n");
+
+    /* Write out global definitions and system includes. */
+    if (num_globals) {
+        fprintf(chaz_ConfWriterC.fh, "\n#ifdef CHY_EMPLOY_%s\n\n",
+                chaz_ConfWriterC.MODULE_NAME);
+        for (i = 0; i < chaz_ConfWriterC.def_count; i++) {
+            switch (defs[i].type) {
+                case CHAZ_CONFELEM_GLOBAL_DEF:
+                    chaz_ConfWriterC_append_global_def_to_conf(defs[i].str1,
+                                                               defs[i].str2);
+                    break;
+                case CHAZ_CONFELEM_GLOBAL_TYPEDEF:
+                    chaz_ConfWriterC_append_global_typedef_to_conf(
+                            defs[i].str2, defs[i].str1);
+                    break;
+                case CHAZ_CONFELEM_SYS_INCLUDE:
+                    chaz_ConfWriterC_append_sys_include_to_conf(defs[i].str1);
+                    break;
+                case CHAZ_CONFELEM_DEF:
+                case CHAZ_CONFELEM_TYPEDEF:
+                case CHAZ_CONFELEM_LOCAL_INCLUDE:
+                    /* no-op */
+                    break;
+                default:
+                    chaz_Util_die("Internal error: bad element type %d",
+                                  (int)defs[i].type);
+            }
+        }
+        fprintf(chaz_ConfWriterC.fh, "\n#endif /* EMPLOY_%s */\n",
+                chaz_ConfWriterC.MODULE_NAME);
+    }
+
     fprintf(chaz_ConfWriterC.fh, "\n");
 
+    free(chaz_ConfWriterC.MODULE_NAME);
     chaz_ConfWriterC_clear_def_list();
 }
 
@@ -4806,7 +4846,7 @@ chaz_Booleans_run(void) {
     }
     else {
         chaz_ConfWriter_append_conf(
-            "#ifndef __cplusplus\n"
+            "#if (defined(CHY_EMPLOY_BOOLEANS) && !defined(__cplusplus))\n"
             "  typedef int bool;\n"
             "  #ifndef true\n"
             "    #define true 1\n"
@@ -5053,14 +5093,35 @@ chaz_Floats_run(void) {
     chaz_ConfWriter_start_module("Floats");
 
     chaz_ConfWriter_append_conf(
-        "typedef union { uint32_t i; float f; } chy_floatu32;\n"
-        "typedef union { uint64_t i; double d; } chy_floatu64;\n"
-        "static const chy_floatu32 chy_f32inf    = {UINT32_C(0x7f800000)};\n"
-        "static const chy_floatu32 chy_f32neginf = {UINT32_C(0xff800000)};\n"
-        "static const chy_floatu32 chy_f32nan    = {UINT32_C(0x7fc00000)};\n"
-        "static const chy_floatu64 chy_f64inf    = {UINT64_C(0x7ff0000000000000)};\n"
-        "static const chy_floatu64 chy_f64neginf = {UINT64_C(0xfff0000000000000)};\n"
-        "static const chy_floatu64 chy_f64nan    = {UINT64_C(0x7ff8000000000000)};\n"
+        "typedef union { unsigned char c[4]; float f; } chy_floatu32;\n"
+        "typedef union { unsigned char c[8]; double d; } chy_floatu64;\n"
+        "#ifdef CHY_BIG_END\n"
+        "static const chy_floatu32 chy_f32inf\n"
+        "    = { { 0x7F, 0x80, 0, 0 } };\n"
+        "static const chy_floatu32 chy_f32neginf\n"
+        "    = { { 0xFF, 0x80, 0, 0 } };\n"
+        "static const chy_floatu32 chy_f32nan\n"
+        "    = { { 0x7F, 0xC0, 0, 0 } };\n"
+        "static const chy_floatu64 chy_f64inf\n"
+        "    = { { 0x7F, 0xF0, 0, 0, 0, 0, 0, 0 } };\n"
+        "static const chy_floatu64 chy_f64neginf\n"
+        "    = { { 0xFF, 0xF0, 0, 0, 0, 0, 0, 0 } };\n"
+        "static const chy_floatu64 chy_f64nan\n"
+        "    = { { 0x7F, 0xF8, 0, 0, 0, 0, 0, 0 } };\n"
+        "#else /* BIG_END */\n"
+        "static const chy_floatu32 chy_f32inf\n"
+        "    = { { 0, 0, 0x80, 0x7F } };\n"
+        "static const chy_floatu32 chy_f32neginf\n"
+        "    = { { 0, 0, 0x80, 0xFF } };\n"
+        "static const chy_floatu32 chy_f32nan\n"
+        "    = { { 0, 0, 0xC0, 0x7F } };\n"
+        "static const chy_floatu64 chy_f64inf\n"
+        "    = { { 0, 0, 0, 0, 0, 0, 0xF0, 0x7F } };\n"
+        "static const chy_floatu64 chy_f64neginf\n"
+        "    = { { 0, 0, 0, 0, 0, 0, 0xF0, 0xFF } };\n"
+        "static const chy_floatu64 chy_f64nan\n"
+        "    = { { 0, 0, 0, 0, 0, 0, 0xF8, 0x7F } };\n"
+        "#endif /* BIG_END */\n"
     );
     chaz_ConfWriter_add_def("F32_INF", "(chy_f32inf.f)");
     chaz_ConfWriter_add_def("F32_NEGINF", "(chy_f32neginf.f)");
@@ -5517,7 +5578,7 @@ static const char chaz_Integers_u64_to_double_code[] =
     CHAZ_QUOTE(  #include <stdio.h>                        )
     CHAZ_QUOTE(  int main()                                )
     CHAZ_QUOTE(  {                                         )
-    CHAZ_QUOTE(      unsigned __int64 int_num = 0;         )
+    CHAZ_QUOTE(      unsigned %s int_num = 0;              )
     CHAZ_QUOTE(      double float_num;                     )
     CHAZ_QUOTE(      float_num = (double)int_num;          )
     CHAZ_QUOTE(      printf("%%f\n", float_num);           )
@@ -5674,13 +5735,6 @@ chaz_Integers_run(void) {
         }
     }
 
-    /* Determine whether conversion of unsigned __int64 to double works */
-    if (has___int64) {
-        if (!chaz_CC_test_compile(chaz_Integers_u64_to_double_code)) {
-            can_convert_u64_to_double = false;
-        }
-    }
-
     /* Write out some conditional defines. */
     if (has_inttypes) {
         chaz_ConfWriter_add_def("HAS_INTTYPES_H", NULL);
@@ -5729,92 +5783,179 @@ chaz_Integers_run(void) {
         chaz_ConfWriter_add_def("HAS_INT64_T", NULL);
     }
 
-    /* Write typedefs, maximums/minimums and literals macros. */
-    if (has_inttypes) {
-        chaz_ConfWriter_add_sys_include("inttypes.h");
+    /* Create macro for promoting pointers to integers. */
+    if (has_64) {
+        if (sizeof_ptr == 8) {
+            chaz_ConfWriter_add_def("PTR_TO_I64(ptr)",
+                                    "((int64_t)(uint64_t)(ptr))");
+        }
+        else {
+            chaz_ConfWriter_add_def("PTR_TO_I64(ptr)",
+                                    "((int64_t)(uint32_t)(ptr))");
+        }
     }
-    else {
-        if (has_stdint) {
-            chaz_ConfWriter_add_sys_include("stdint.h");
+
+    /* Create macro for converting uint64_t to double. */
+    if (has_64) {
+        /*
+         * Determine whether unsigned 64-bit integers can be converted to
+         * double. Older MSVC versions don't support this conversion.
+         */
+        sprintf(code_buf, chaz_Integers_u64_to_double_code, i64_t_type);
+        output = chaz_CC_capture_output(code_buf, &output_len);
+        if (output != NULL) {
+            chaz_ConfWriter_add_def("U64_TO_DOUBLE(num)", "((double)(num))");
+            free(output);
         }
         else {
-            /* We support only the following subset of stdint.h
-             *   int8_t
-             *   int16_t
-             *   int32_t
-             *   int64_t
-             *   uint8_t
-             *   uint16_t
-             *   uint32_t
-             *   uint64_t
-             *   INT8_MAX
-             *   INT16_MAX
-             *   INT32_MAX
-             *   INT64_MAX
-             *   INT8_MIN
-             *   INT16_MIN
-             *   INT32_MIN
-             *   INT64_MIN
-             *   UINT8_MAX
-             *   UINT16_MAX
-             *   UINT32_MAX
-             *   UINT64_MAX
-             *   SIZE_MAX
-             *   INT32_C
-             *   INT64_C
-             *   UINT32_C
-             *   UINT64_C
-             */
-            if (has_8) {
-                chaz_ConfWriter_add_global_typedef("signed char", "int8_t");
-                chaz_ConfWriter_add_global_typedef("unsigned char", "uint8_t");
-                chaz_ConfWriter_add_global_def("INT8_MAX", "127");
-                chaz_ConfWriter_add_global_def("INT8_MIN", "-128");
-                chaz_ConfWriter_add_global_def("UINT8_MAX", "255");
-            }
-            if (has_16) {
-                chaz_ConfWriter_add_global_typedef("signed short", "int16_t");
-                chaz_ConfWriter_add_global_typedef("unsigned short",
-                                                   "uint16_t");
-                chaz_ConfWriter_add_global_def("INT16_MAX", "32767");
-                chaz_ConfWriter_add_global_def("INT16_MIN", "-32768");
-                chaz_ConfWriter_add_global_def("UINT16_MAX", "65535");
-            }
-            if (has_32) {
-                chaz_ConfWriter_add_global_typedef(i32_t_type, "int32_t");
-                sprintf(scratch, "unsigned %s", i32_t_type);
-                chaz_ConfWriter_add_global_typedef(scratch, "uint32_t");
-                chaz_ConfWriter_add_global_def("INT32_MAX", "2147483647");
-                chaz_ConfWriter_add_global_def("INT32_MIN", "(-INT32_MAX-1)");
-                chaz_ConfWriter_add_global_def("UINT32_MAX", "4294967295U");
-                if (strcmp(i32_t_postfix, "") == 0) {
-                    chaz_ConfWriter_add_global_def("INT32_C(n)", "n");
-                }
-                else {
-                    sprintf(scratch, "n##%s", i32_t_postfix);
-                    chaz_ConfWriter_add_global_def("INT32_C(n)", scratch);
-                }
-                sprintf(scratch, "n##%s", u32_t_postfix);
-                chaz_ConfWriter_add_global_def("UINT32_C(n)", scratch);
+            chaz_ConfWriter_add_def(
+                "U64_TO_DOUBLE(num)",
+                "((num) & UINT64_C(0x8000000000000000) ? "
+                "(double)(int64_t)((num) & UINT64_C(0x7FFFFFFFFFFFFFFF)) + "
+                "9223372036854775808.0 : "
+                "(double)(int64_t)(num))");
+        }
+    }
+
+    chaz_ConfWriter_end_module();
+
+    /* Integer typedefs. */
+
+    chaz_ConfWriter_start_module("IntegerTypes");
+
+    if (has_stdint) {
+        chaz_ConfWriter_add_sys_include("stdint.h");
+    }
+    else {
+        /* We support only the following subset of stdint.h
+         *   int8_t
+         *   int16_t
+         *   int32_t
+         *   int64_t
+         *   uint8_t
+         *   uint16_t
+         *   uint32_t
+         *   uint64_t
+         */
+        if (has_8) {
+            chaz_ConfWriter_add_global_typedef("signed char", "int8_t");
+            chaz_ConfWriter_add_global_typedef("unsigned char", "uint8_t");
+        }
+        if (has_16) {
+            chaz_ConfWriter_add_global_typedef("signed short", "int16_t");
+            chaz_ConfWriter_add_global_typedef("unsigned short", "uint16_t");
+        }
+        if (has_32) {
+            chaz_ConfWriter_add_global_typedef(i32_t_type, "int32_t");
+            sprintf(scratch, "unsigned %s", i32_t_type);
+            chaz_ConfWriter_add_global_typedef(scratch, "uint32_t");
+        }
+        if (has_64) {
+            chaz_ConfWriter_add_global_typedef(i64_t_type, "int64_t");
+            sprintf(scratch, "unsigned %s", i64_t_type);
+            chaz_ConfWriter_add_global_typedef(scratch, "uint64_t");
+        }
+    }
+
+    chaz_ConfWriter_end_module();
+
+    /* Integer limits. */
+
+    chaz_ConfWriter_start_module("IntegerLimits");
+
+    if (has_stdint) {
+        chaz_ConfWriter_add_sys_include("stdint.h");
+    }
+    else {
+        /* We support only the following subset of stdint.h
+         *   INT8_MAX
+         *   INT16_MAX
+         *   INT32_MAX
+         *   INT64_MAX
+         *   INT8_MIN
+         *   INT16_MIN
+         *   INT32_MIN
+         *   INT64_MIN
+         *   UINT8_MAX
+         *   UINT16_MAX
+         *   UINT32_MAX
+         *   UINT64_MAX
+         *   SIZE_MAX
+         */
+        if (has_8) {
+            chaz_ConfWriter_add_global_def("INT8_MAX", "127");
+            chaz_ConfWriter_add_global_def("INT8_MIN", "-128");
+            chaz_ConfWriter_add_global_def("UINT8_MAX", "255");
+        }
+        if (has_16) {
+            chaz_ConfWriter_add_global_def("INT16_MAX", "32767");
+            chaz_ConfWriter_add_global_def("INT16_MIN", "-32768");
+            chaz_ConfWriter_add_global_def("UINT16_MAX", "65535");
+        }
+        if (has_32) {
+            chaz_ConfWriter_add_global_def("INT32_MAX", "2147483647");
+            chaz_ConfWriter_add_global_def("INT32_MIN", "(-INT32_MAX-1)");
+            chaz_ConfWriter_add_global_def("UINT32_MAX", "4294967295U");
+        }
+        if (has_64) {
+            sprintf(scratch, "9223372036854775807%s", i64_t_postfix);
+            chaz_ConfWriter_add_global_def("INT64_MAX", scratch);
+            chaz_ConfWriter_add_global_def("INT64_MIN", "(-INT64_MAX-1)");
+            sprintf(scratch, "18446744073709551615%s", u64_t_postfix);
+            chaz_ConfWriter_add_global_def("UINT64_MAX", scratch);
+        }
+        chaz_ConfWriter_add_global_def("SIZE_MAX", "((size_t)-1)");
+    }
+
+    chaz_ConfWriter_end_module();
+
+    /* Integer literals. */
+
+    chaz_ConfWriter_start_module("IntegerLiterals");
+
+    if (has_stdint) {
+        chaz_ConfWriter_add_sys_include("stdint.h");
+    }
+    else {
+        /* We support only the following subset of stdint.h
+         *   INT32_C
+         *   INT64_C
+         *   UINT32_C
+         *   UINT64_C
+         */
+        if (has_32) {
+            if (strcmp(i32_t_postfix, "") == 0) {
+                chaz_ConfWriter_add_global_def("INT32_C(n)", "n");
             }
-            if (has_64) {
-                chaz_ConfWriter_add_global_typedef(i64_t_type, "int64_t");
-                sprintf(scratch, "unsigned %s", i64_t_type);
-                chaz_ConfWriter_add_global_typedef(scratch, "uint64_t");
-                sprintf(scratch, "9223372036854775807%s", i64_t_postfix);
-                chaz_ConfWriter_add_global_def("INT64_MAX", scratch);
-                chaz_ConfWriter_add_global_def("INT64_MIN", "(-INT64_MAX-1)");
-                sprintf(scratch, "18446744073709551615%s", u64_t_postfix);
-                chaz_ConfWriter_add_global_def("UINT64_MAX", scratch);
-                sprintf(scratch, "n##%s", i64_t_postfix);
-                chaz_ConfWriter_add_global_def("INT64_C(n)", scratch);
-                sprintf(scratch, "n##%s", u64_t_postfix);
-                chaz_ConfWriter_add_global_def("UINT64_C(n)", scratch);
+            else {
+                sprintf(scratch, "n##%s", i32_t_postfix);
+                chaz_ConfWriter_add_global_def("INT32_C(n)", scratch);
             }
-            chaz_ConfWriter_add_global_def("SIZE_MAX", "((size_t)-1)");
+            sprintf(scratch, "n##%s", u32_t_postfix);
+            chaz_ConfWriter_add_global_def("UINT32_C(n)", scratch);
         }
+        if (has_64) {
+            sprintf(scratch, "n##%s", i64_t_postfix);
+            chaz_ConfWriter_add_global_def("INT64_C(n)", scratch);
+            sprintf(scratch, "n##%s", u64_t_postfix);
+            chaz_ConfWriter_add_global_def("UINT64_C(n)", scratch);
+        }
+    }
+
+    chaz_ConfWriter_end_module();
+
+    /* Integer format strings. */
 
-        /* Create the PRId64 and PRIu64 printf macros. */
+    chaz_ConfWriter_start_module("IntegerFormatStrings");
+
+    if (has_inttypes) {
+        chaz_ConfWriter_add_sys_include("inttypes.h");
+    }
+    else {
+        /* We support only the following subset of inttypes.h
+         *   PRId64
+         *   PRIu64
+         */
         if (has_64) {
             int i;
             const char *options[] = {
@@ -5853,32 +5994,6 @@ chaz_Integers_run(void) {
         }
     }
 
-    /* Create macro for promoting pointers to integers. */
-    if (has_64) {
-        if (sizeof_ptr == 8) {
-            chaz_ConfWriter_add_def("PTR_TO_I64(ptr)",
-                                    "((int64_t)(uint64_t)(ptr))");
-        }
-        else {
-            chaz_ConfWriter_add_def("PTR_TO_I64(ptr)",
-                                    "((int64_t)(uint32_t)(ptr))");
-        }
-    }
-
-    /* Create macro for converting uint64_t to double. */
-    if (can_convert_u64_to_double) {
-        chaz_ConfWriter_add_def("U64_TO_DOUBLE(num)",
-                                "((double)(num))");
-    }
-    else {
-        chaz_ConfWriter_add_def(
-            "U64_TO_DOUBLE(num)",
-            "((num) & UINT64_C(0x8000000000000000) ? "
-            "(double)(int64_t)((num) & UINT64_C(0x7FFFFFFFFFFFFFFF)) + "
-            "9223372036854775808.0 : "
-            "(double)(int64_t)(num))");
-    }
-
     chaz_ConfWriter_end_module();
 }
 
@@ -7023,6 +7138,13 @@ int main(int argc, const char **argv) {
         }
     }
 
+    /* Employ integer features but don't define stdint types in charmony.h. */
+    chaz_ConfWriter_append_conf(
+        "#define CHY_EMPLOY_INTEGERLIMITS\n"
+        "#define CHY_EMPLOY_INTEGERLITERALS\n"
+        "#define CHY_EMPLOY_INTEGERFORMATSTRINGS\n\n"
+    );
+
     /* Run probe modules. */
     chaz_BuildEnv_run();
     chaz_DirManip_run();


Mime
View raw message