Add --charmonic option to cfc With --charmonic, cfc makes cfish_platform.h include charmony.h and use its CHY_* macros for platform-specific settings. This is needed when cross-compiling.
Otherwise, the CHY_* values from the CFC configuration are used. This breaks cross compilation but allows to build Clownfish projects without Charmonizer. Run cfc with --charmonic when building the runtime. Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/ae56843f Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/ae56843f Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/ae56843f Branch: refs/heads/master Commit: ae56843f1f0907e4376aa380df646b79d04d210b Parents: cadebb9 Author: Nick Wellnhofer <wellnho...@aevum.de> Authored: Fri Feb 3 22:15:05 2017 +0100 Committer: Nick Wellnhofer <wellnho...@aevum.de> Committed: Sat Feb 4 18:13:34 2017 +0100 ---------------------------------------------------------------------- compiler/c/cfc.c | 7 +- compiler/go/cfc/cfc.go | 3 +- compiler/perl/lib/Clownfish/CFC.xs | 2 +- compiler/python/src/cfc/_cfc.c | 2 +- compiler/ruby/ext/Clownfish/CFC.c | 3 +- compiler/src/CFCBindCore.c | 271 +++++++++++++++----------------- compiler/src/CFCBindCore.h | 6 +- runtime/common/charmonizer.c | 5 +- runtime/common/charmonizer.main | 5 +- 9 files changed, 148 insertions(+), 156 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/ae56843f/compiler/c/cfc.c ---------------------------------------------------------------------- diff --git a/compiler/c/cfc.c b/compiler/c/cfc.c index d329708..21bd989 100644 --- a/compiler/c/cfc.c +++ b/compiler/c/cfc.c @@ -45,6 +45,7 @@ struct CFCArgs { char **parcels; char *header_filename; char *footer_filename; + int charmonic; }; typedef struct CFCArgs CFCArgs; @@ -109,6 +110,10 @@ S_parse_arguments(int argc, char **argv, CFCArgs *args) { for (i = 1; i < argc; i++) { char *arg = argv[i]; + if (strcmp(arg, "--charmonic") == 0) { + args->charmonic = 1; + continue; + } if (S_parse_string_argument(arg, "--dest", &args->dest)) { continue; } @@ -238,7 +243,7 @@ main(int argc, char **argv) { footer = CFCUtil_strdup(""); } - core_binding = CFCBindCore_new(hierarchy, header, footer); + core_binding = CFCBindCore_new(hierarchy, header, footer, args.charmonic); CFCBindCore_write_all_modified(core_binding, 0); c_binding = CFCC_new(hierarchy, header, footer); http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/ae56843f/compiler/go/cfc/cfc.go ---------------------------------------------------------------------- diff --git a/compiler/go/cfc/cfc.go b/compiler/go/cfc/cfc.go index d24f957..2ea823e 100644 --- a/compiler/go/cfc/cfc.go +++ b/compiler/go/cfc/cfc.go @@ -146,7 +146,8 @@ func NewBindCore(hierarchy *Hierarchy, header string, footer string) *BindCore { defer C.free(unsafe.Pointer(headerCString)) defer C.free(unsafe.Pointer(footerCString)) obj := &BindCore{ - C.CFCBindCore_new(hierarchy.ref, headerCString, footerCString), + C.CFCBindCore_new(hierarchy.ref, headerCString, footerCString, + 0), } runtime.SetFinalizer(obj, (*BindCore).finalize) return obj http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/ae56843f/compiler/perl/lib/Clownfish/CFC.xs ---------------------------------------------------------------------- diff --git a/compiler/perl/lib/Clownfish/CFC.xs b/compiler/perl/lib/Clownfish/CFC.xs index 8caa0b7..c5ee7dd 100644 --- a/compiler/perl/lib/Clownfish/CFC.xs +++ b/compiler/perl/lib/Clownfish/CFC.xs @@ -1871,7 +1871,7 @@ _new(hierarchy, header, footer) const char *header; const char *footer; CODE: - CFCBindCore *self = CFCBindCore_new(hierarchy, header, footer); + CFCBindCore *self = CFCBindCore_new(hierarchy, header, footer, 0); RETVAL = S_cfcbase_to_perlref(self); CFCBase_decref((CFCBase*)self); OUTPUT: RETVAL http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/ae56843f/compiler/python/src/cfc/_cfc.c ---------------------------------------------------------------------- diff --git a/compiler/python/src/cfc/_cfc.c b/compiler/python/src/cfc/_cfc.c index e7e8f3f..30968b3 100644 --- a/compiler/python/src/cfc/_cfc.c +++ b/compiler/python/src/cfc/_cfc.c @@ -306,7 +306,7 @@ S_CFCBindCore_new(PyTypeObject *type, PyObject *args, &footer); if (!result) { return NULL; } CFCHierarchy *hierarchy = S_to_Hierarchy(hierarchy_wrapped); - CFCBindCore *obj = CFCBindCore_new(hierarchy, header, footer); + CFCBindCore *obj = CFCBindCore_new(hierarchy, header, footer, 0); return S_wrap_cfcbase(BindCore_pytype, obj); } http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/ae56843f/compiler/ruby/ext/Clownfish/CFC.c ---------------------------------------------------------------------- diff --git a/compiler/ruby/ext/Clownfish/CFC.c b/compiler/ruby/ext/Clownfish/CFC.c index 3ade99e..85d803e 100644 --- a/compiler/ruby/ext/Clownfish/CFC.c +++ b/compiler/ruby/ext/Clownfish/CFC.c @@ -44,7 +44,8 @@ S_CFC_Binding_Core_Init(VALUE self_rb, VALUE params) { Data_Get_Struct(hierarchy, CFCHierarchy, hierarchy_obj); Data_Get_Struct(self_rb, CFCBindCore, self); - self = CFCBindCore_new(hierarchy_obj, StringValuePtr(header), StringValuePtr(footer)); + self = CFCBindCore_new(hierarchy_obj, StringValuePtr(header), + StringValuePtr(footer), 0); DATA_PTR(self_rb) = self; return self_rb; http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/ae56843f/compiler/src/CFCBindCore.c ---------------------------------------------------------------------- diff --git a/compiler/src/CFCBindCore.c b/compiler/src/CFCBindCore.c index 5920550..4bd943e 100644 --- a/compiler/src/CFCBindCore.c +++ b/compiler/src/CFCBindCore.c @@ -40,6 +40,7 @@ struct CFCBindCore { CFCHierarchy *hierarchy; char *c_header; char *c_footer; + int charmonic; }; /* Write the "parcel.h" header file, which contains common symbols needed by @@ -59,21 +60,6 @@ S_write_parcel_c(CFCBindCore *self, CFCParcel *parcel); static void S_write_platform_h(CFCBindCore *self); -static char* -S_charmony_feature_defines(); - -static char* -S_charmony_string_defines(); - -static char* -S_charmony_stdbool_defines(); - -static char* -S_charmony_stdint_defines(); - -static char* -S_charmony_alloca_defines(); - static void S_write_host_data_json(CFCBindCore *self, CFCParcel *parcel, const char *dest_dir, const char *host_lang); @@ -86,20 +72,21 @@ static const CFCMeta CFCBINDCORE_META = { CFCBindCore* CFCBindCore_new(CFCHierarchy *hierarchy, const char *header, - const char *footer) { + const char *footer, int charmonic) { CFCBindCore *self = (CFCBindCore*)CFCBase_allocate(&CFCBINDCORE_META); - return CFCBindCore_init(self, hierarchy, header, footer); + return CFCBindCore_init(self, hierarchy, header, footer, charmonic); } CFCBindCore* CFCBindCore_init(CFCBindCore *self, CFCHierarchy *hierarchy, - const char *header, const char *footer) { + const char *header, const char *footer, int charmonic) { CFCUTIL_NULL_CHECK(hierarchy); CFCUTIL_NULL_CHECK(header); CFCUTIL_NULL_CHECK(footer); self->hierarchy = (CFCHierarchy*)CFCBase_incref((CFCBase*)hierarchy); self->c_header = CFCUtil_make_c_comment(header); self->c_footer = CFCUtil_make_c_comment(footer); + self->charmonic = charmonic; return self; } @@ -519,11 +506,126 @@ S_write_parcel_c(CFCBindCore *self, CFCParcel *parcel) { */ static void S_write_platform_h(CFCBindCore *self) { - char *feature_defs = S_charmony_feature_defines(); - char *string_defs = S_charmony_string_defines(); - char *stdbool_defs = S_charmony_stdbool_defines(); - char *stdint_defs = S_charmony_stdint_defines(); - char *alloca_defs = S_charmony_alloca_defines(); + const char *content; + + if (self->charmonic) { + content = + "#include \"charmony.h\"\n" + "\n" + "#ifdef CHY_HAS_FUNC_MACRO\n" + " #define CFISH_HAS_FUNC_MACRO\n" + "#endif\n" + "#ifdef CHY_HAS_VARIADIC_MACROS\n" + " #define CFISH_HAS_VARIADIC_MACROS\n" + "#endif\n" + "#ifdef CHY_HAS_ISO_VARIADIC_MACROS\n" + " #define CFISH_HAS_ISO_VARIADIC_MACROS\n" + "#endif\n" + "#ifdef CHY_HAS_GNUC_VARIADIC_MACROS\n" + " #define CFISH_HAS_GNUC_VARIADIC_MACROS\n" + "#endif\n" + "\n" + "#define CFISH_INLINE CHY_INLINE\n" + "#define CFISH_EXPORT CHY_EXPORT\n" + "#define CFISH_IMPORT CHY_IMPORT\n" + "#define CFISH_FUNC_MACRO CHY_FUNC_MACRO\n" + "\n" + "#ifdef CHY_HAS_STDBOOL_H\n" + " #include <stdbool.h>\n" + "#else\n" + " #if (!defined(__cplusplus) && !defined(CFISH_HAS_STDBOOL))\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" + "#endif\n" + "\n" + "#ifdef CHY_HAS_STDINT_H\n" + " #include <stdint.h>\n" + "#else\n" + " #ifndef CFISH_HAS_STDINT\n" + " typedef CHY_INT8_T int8_t;\n" + " typedef CHY_UINT8_T uint8_t;\n" + " typedef CHY_INT16_T int16_t;\n" + " typedef CHY_UINT16_T uint16_t;\n" + " typedef CHY_INT32_T int32_t;\n" + " typedef CHY_UINT32_T uint32_t;\n" + " typedef CHY_INT64_T int64_t;\n" + " typedef CHY_UINT64_T uint64_t;\n" + " #endif\n" + "#endif\n" + "\n" + "#if defined(CHY_ALLOCA_IN_STDLIB_H)\n" + " #include <stdlib.h>\n" + "#elif defined(CHY_HAS_ALLOCA_H)\n" + " #include <alloca.h>\n" + "#elif defined(CHY_HAS_MALLOC_H)\n" + " #include <malloc.h>\n" + "#endif\n" + "#define cfish_alloca chy_alloca\n"; + } + else { + // Use the same values CFC was compiled with. + content = +#ifdef CHY_HAS_FUNC_MACRO + "#define CFISH_HAS_FUNC_MACRO\n" +#endif +#ifdef CHY_HAS_VARIADIC_MACROS + "#define CFISH_HAS_VARIADIC_MACROS\n" +#endif +#ifdef CHY_HAS_ISO_VARIADIC_MACROS + "#define CFISH_HAS_ISO_VARIADIC_MACROS\n" +#endif +#ifdef CHY_HAS_GNUC_VARIADIC_MACROS + "#define CFISH_HAS_GNUC_VARIADIC_MACROS\n" +#endif + "#define CFISH_INLINE " XSTRING(CHY_INLINE) "\n" + "#define CFISH_EXPORT " XSTRING(CHY_EXPORT) "\n" + "#define CFISH_IMPORT " XSTRING(CHY_IMPORT) "\n" + "#define CFISH_FUNC_MACRO " XSTRING(CHY_FUNC_MACRO) "\n" + "\n" +#ifdef CHY_HAS_STDBOOL_H + "#include <stdbool.h>\n" +#else + "#if (!defined(__cplusplus) && !defined(CFISH_HAS_STDBOOL))\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" +#endif + "\n" +#ifdef CHY_HAS_STDINT_H + "#include <stdint.h>\n" +#else + "#ifndef CFISH_HAS_STDINT\n" + " typedef " XSTRING(CHY_INT8_T) " int8_t;\n" + " typedef " XSTRING(CHY_UINT8_T) " uint8_t;\n" + " typedef " XSTRING(CHY_INT16_T) " int16_t;\n" + " typedef " XSTRING(CHY_UINT16_T) " uint16_t;\n" + " typedef " XSTRING(CHY_INT32_T) " int32_t;\n" + " typedef " XSTRING(CHY_UINT32_T) " uint32_t;\n" + " typedef " XSTRING(CHY_INT64_T) " int64_t;\n" + " typedef " XSTRING(CHY_UINT64_T) " uint64_t;\n" + "#endif\n" +#endif + "\n" +#if defined(CHY_ALLOCA_IN_STDLIB_H) + "#include <stdlib.h>\n" +#elif defined(CHY_HAS_ALLOCA_H) + "#include <alloca.h>\n" +#elif defined(CHY_HAS_MALLOC_H) + "#include <malloc.h>\n" +#endif + "#define cfish_alloca " XSTRING(chy_alloca) "\n"; + } const char pattern[] = "%s" @@ -536,12 +638,6 @@ S_write_platform_h(CFCBindCore *self) { "#endif\n" "\n" "%s" - "%s" - "\n" - "%s" - "%s" - "\n" - "%s" "\n" "#ifdef __cplusplus\n" "}\n" @@ -552,9 +648,7 @@ S_write_platform_h(CFCBindCore *self) { "%s" "\n"; char *file_content - = CFCUtil_sprintf(pattern, self->c_header, feature_defs, string_defs, - stdbool_defs, stdint_defs, alloca_defs, - self->c_footer); + = CFCUtil_sprintf(pattern, self->c_header, content, self->c_footer); // Unlink then write file. const char *inc_dest = CFCHierarchy_get_include_dest(self->hierarchy); @@ -563,119 +657,6 @@ S_write_platform_h(CFCBindCore *self) { remove(filepath); CFCUtil_write_file(filepath, file_content, strlen(file_content)); FREEMEM(filepath); - - FREEMEM(feature_defs); - FREEMEM(string_defs); - FREEMEM(stdbool_defs); - FREEMEM(stdint_defs); - FREEMEM(alloca_defs); - FREEMEM(file_content); -} - -static char* -S_charmony_feature_defines() { - char *defines = CFCUtil_strdup(""); - -#ifdef CHY_HAS_FUNC_MACRO - // Needed by Err.cfh. - defines = CFCUtil_cat(defines, "#define CFISH_HAS_FUNC_MACRO\n", NULL); -#endif -#ifdef CHY_HAS_VARIADIC_MACROS - // Needed by Err.cfh. - defines = CFCUtil_cat(defines, "#define CFISH_HAS_VARIADIC_MACROS\n", - NULL); -#endif -#ifdef CHY_HAS_ISO_VARIADIC_MACROS - // Needed by Err.cfh. - defines = CFCUtil_cat(defines, "#define CFISH_HAS_ISO_VARIADIC_MACROS\n", - NULL); -#endif -#ifdef CHY_HAS_GNUC_VARIADIC_MACROS - // Needed by Err.cfh. - defines = CFCUtil_cat(defines, "#define CFISH_HAS_GNUC_VARIADIC_MACROS\n", - NULL); -#endif - - return defines; -} - -static char* -S_charmony_string_defines() { - const char *pattern = - "#define CFISH_INLINE %s\n" - "#define CFISH_EXPORT %s\n" - "#define CFISH_IMPORT %s\n" - "#define CFISH_FUNC_MACRO %s\n"; - char *defines - = CFCUtil_sprintf(pattern, - XSTRING(CHY_INLINE), - XSTRING(CHY_EXPORT), - XSTRING(CHY_IMPORT), - XSTRING(CHY_FUNC_MACRO)); - - return defines; -} - -static char* -S_charmony_stdbool_defines() { -#ifdef CHY_HAS_STDBOOL_H - const char *defines = "#include <stdbool.h>\n"; -#else - const char *defines = - "#if (!defined(__cplusplus) && !defined(CFISH_HAS_STDBOOL))\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"; -#endif - - return CFCUtil_strdup(defines); -} - -static char* -S_charmony_stdint_defines() { -#ifdef CHY_HAS_STDINT_H - return CFCUtil_strdup("#include <stdint.h>\n"); -#else - const char *pattern = - "#ifndef CFISH_HAS_STDINT\n" - " typedef %s int8_t;\n" - " typedef %s uint8_t;\n" - " typedef %s int16_t;\n" - " typedef %s uint16_t;\n" - " typedef %s int32_t;\n" - " typedef %s uint32_t;\n" - " typedef %s int64_t;\n" - " typedef %s uint64_t;\n" - "#endif\n"; - return CFCUtil_sprintf(pattern, - XSTRING(CHY_INT8_T), XSTRING(CHY_UINT8_T), - XSTRING(CHY_INT16_T), XSTRING(CHY_UINT16_T), - XSTRING(CHY_INT32_T), XSTRING(CHY_UINT32_T), - XSTRING(CHY_INT64_T), XSTRING(CHY_UINT64_T)); -#endif -} - -static char* -S_charmony_alloca_defines() { - char *defines = CFCUtil_strdup(""); - -#if defined(CHY_HAS_ALLOCA_H) - defines = CFCUtil_cat(defines, "#include <alloca.h>\n", NULL); -#elif defined(CHY_HAS_MALLOC_H) - defines = CFCUtil_cat(defines, "#include <malloc.h>\n", NULL); -#elif defined(CHY_ALLOCA_IN_STDLIB_H) - defines = CFCUtil_cat(defines, "#include <stdlib.h>\n", NULL); -#endif - - defines = CFCUtil_cat(defines, "#define cfish_alloca ", - XSTRING(chy_alloca), "\n", NULL); - - return defines; } void http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/ae56843f/compiler/src/CFCBindCore.h ---------------------------------------------------------------------- diff --git a/compiler/src/CFCBindCore.h b/compiler/src/CFCBindCore.h index aa40bb2..ff81594 100644 --- a/compiler/src/CFCBindCore.h +++ b/compiler/src/CFCBindCore.h @@ -38,14 +38,16 @@ struct CFCHierarchy; * typically, an "autogenerated file" warning. * @param footer Text to be appended to the end of each generated C file -- * typically copyright information. + * @param charmonic If true, make cfish_platform.h include charmony.h. + * Otherwise, use the same config CFC was compiled with. */ CFCBindCore* CFCBindCore_new(struct CFCHierarchy *hierarchy, const char *header, - const char *footer); + const char *footer, int charmonic); CFCBindCore* CFCBindCore_init(CFCBindCore *self, struct CFCHierarchy *hierarchy, - const char *header, const char *footer); + const char *header, const char *footer, int charmonic); void CFCBindCore_destroy(CFCBindCore *self); http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/ae56843f/runtime/common/charmonizer.c ---------------------------------------------------------------------- diff --git a/runtime/common/charmonizer.c b/runtime/common/charmonizer.c index c010f5e..c9eceb2 100644 --- a/runtime/common/charmonizer.c +++ b/runtime/common/charmonizer.c @@ -8509,6 +8509,7 @@ int main(int argc, const char **argv) { chaz_Floats_run(); chaz_LargeFiles_run(); chaz_Memory_run(); + chaz_SymbolVisibility_run(); chaz_VariadicMacros_run(); /* Local definitions. */ @@ -8910,8 +8911,8 @@ cfish_MakeFile_write_c_cfc_rules(cfish_MakeFile *self) { rule = chaz_MakeFile_add_rule(self->makefile, self->autogen_target, cfc_exe); chaz_MakeRule_add_prereq(rule, "$(CLOWNFISH_HEADERS)"); - cfc_command = chaz_Util_join("", cfc_exe, " --source=", self->core_dir, - " --source=", self->test_dir, + cfc_command = chaz_Util_join("", cfc_exe, " --charmonic --source=", + self->core_dir, " --source=", self->test_dir, " --dest=autogen --header=cfc_header", NULL); chaz_MakeRule_add_command(rule, cfc_command); http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/ae56843f/runtime/common/charmonizer.main ---------------------------------------------------------------------- diff --git a/runtime/common/charmonizer.main b/runtime/common/charmonizer.main index a98c031..e8a21fd 100644 --- a/runtime/common/charmonizer.main +++ b/runtime/common/charmonizer.main @@ -129,6 +129,7 @@ int main(int argc, const char **argv) { chaz_Floats_run(); chaz_LargeFiles_run(); chaz_Memory_run(); + chaz_SymbolVisibility_run(); chaz_VariadicMacros_run(); /* Local definitions. */ @@ -530,8 +531,8 @@ cfish_MakeFile_write_c_cfc_rules(cfish_MakeFile *self) { rule = chaz_MakeFile_add_rule(self->makefile, self->autogen_target, cfc_exe); chaz_MakeRule_add_prereq(rule, "$(CLOWNFISH_HEADERS)"); - cfc_command = chaz_Util_join("", cfc_exe, " --source=", self->core_dir, - " --source=", self->test_dir, + cfc_command = chaz_Util_join("", cfc_exe, " --charmonic --source=", + self->core_dir, " --source=", self->test_dir, " --dest=autogen --header=cfc_header", NULL); chaz_MakeRule_add_command(rule, cfc_command);