1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

mjit_config.h: more macros

* Makefie.in, win32/Makefile.sub: add more macros for compiler to
  mjit_config.h.

* mjit.c: unification VC and GCC in progress.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62356 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2018-02-11 04:54:15 +00:00
parent 3b6bb3deef
commit 8f66876988
3 changed files with 99 additions and 81 deletions

View file

@ -541,8 +541,31 @@ mjit_config.h:
$(Q:@=:) set -x; \ $(Q:@=:) set -x; \
echo '#ifndef RUBY_MJIT_CONFIG_H'; \ echo '#ifndef RUBY_MJIT_CONFIG_H'; \
echo '#define RUBY_MJIT_CONFIG_H 1'; \ echo '#define RUBY_MJIT_CONFIG_H 1'; \
set x $(CC) && shift && echo '#define MJIT_CC "'$$1'"' \\; \ \
set x $(CC) && shift && echo '#define MJIT_CC_COMMON "'$$1'"' \\; \
shift && for w do echo ' , "'$$w'"' \\; done; \ shift && for w do echo ' , "'$$w'"' \\; done; \
echo ' /* MJIT_CC */'; \ echo ' /* MJIT_CC_COMMON */'; \
\
\
set x -w $(ARCH_FLAG) && shift && echo '#define MJIT_CFLAGS "'$$1'"' \\; \
shift && for w do echo ' , "'$$w'"' \\; done; \
echo ' /* MJIT_CFLAGS */'; \
\
set x $(optflags) && shift && echo '#define MJIT_OPTFLAGS "'$$1'"' \\; \
shift && for w do echo ' , "'$$w'"' \\; done; \
echo ' /* MJIT_OPTFLAGS */'; \
\
set x $(debugflags) && shift && echo '#define MJIT_DEBUGFLAGS "'$$1'"' \\; \
shift && for w do echo ' , "'$$w'"' \\; done; \
echo ' /* MJIT_DEBUGFLAGS */'; \
\
set x @LDSHARED@ && shift && echo '#define MJIT_LDSHARED "'$$1'"' \\; \
shift && for w do echo ' , "'$$w'"' \\; done; \
echo ' /* MJIT_LDSHARED */'; \
\
set x @DLDFLAGS@ && shift && echo '#define MJIT_DLDFLAGS "'$$1'"' \\; \
shift && for w do echo ' , "'$$w'"' \\; done; \
echo ' /* MJIT_DLDFLAGS */'; \
\
echo '#endif /* RUBY_MJIT_CONFIG_H */'; \ echo '#endif /* RUBY_MJIT_CONFIG_H */'; \
} > $@ } > $@

125
mjit.c
View file

@ -573,57 +573,30 @@ free_list(struct rb_mjit_unit_list *list)
XXX_USE_PCH_ARAGS define additional options to use the precomiled XXX_USE_PCH_ARAGS define additional options to use the precomiled
header. */ header. */
static const char *const GCC_DEBUG_ARGS[] = {"-O0", "-g", NULL}; static const char *const CC_DEBUG_ARGS[] = {MJIT_DEBUGFLAGS, NULL};
static const char *const GCC_OPTIMIZE_ARGS[] = {"-O2", NULL}; static const char *const CC_OPTIMIZE_ARGS[] = {MJIT_OPTFLAGS, NULL};
static const char *const GCC_COMMON_ARGS[] = { static const char *const CC_COMMON_ARGS[] = {
MJIT_CC, MJIT_CC_COMMON, MJIT_CFLAGS,
#ifdef __clang__ #if defined __GNUC__ && !defined __clang__
# ifdef __MACH__
"-dynamic",
# else
"-fPIC", "-shared",
# endif /* #if __MACH__ */
"-w", "-bundle",
#else
"-Wfatal-errors", "-fPIC", "-shared", "-w", "-Wfatal-errors", "-fPIC", "-shared", "-w",
"-pipe", "-nostartfiles", "-nodefaultlibs", "-nostdlib", "-pipe", "-nostartfiles", "-nodefaultlibs", "-nostdlib",
#endif #endif
NULL NULL
}; };
static const char *const GCC_LDSHARED_ARGS[] = { static const char *const CC_LDSHARED_ARGS[] = {MJIT_LDSHARED, NULL};
"-Wl,-undefined", "-Wl,dynamic_lookup", static const char *const CC_DLDFLAGS_ARGS[] = {
MJIT_DLDFLAGS,
NULL NULL
}; };
static const char GCC_USE_PCH_ARGS[] =
#ifdef __clang__ #ifdef __clang__
"-include-pch" static const char GCC_USE_PCH_ARGS[] = "-include-pch";
#else static const char GCC_EMIT_PCH_ARGS[] = "-emit-pch";
"-I"
#endif
;
static const char *const GCC_EMIT_PCH_ARGS[] = {
#ifdef __clang__
"-emit-pch",
#endif
NULL
};
#ifdef _MSC_VER
static const char *const VC_COMMON_ARGS[] = {MJIT_CC, "-MD", "-LD", NULL};
static const char *const VC_DEBUG_ARGS[] = {"-O0", "-Zi", NULL};
static const char *const VC_OPTIMIZE_ARGS[] = {
# if _MSC_VER < 1400
"-O2b2xg-",
# else
"-O2sy-",
# endif
NULL};
#endif #endif
#define CC_CODEFLAG_ARGS (mjit_opts.debug ? CC_DEBUG_ARGS : CC_OPTIMIZE_ARGS)
/* Status of the the precompiled header creation. The status is /* Status of the the precompiled header creation. The status is
shared by the workers and the pch thread. */ shared by the workers and the pch thread. */
static enum {PCH_NOT_READY, PCH_FAILED, PCH_SUCCESS} pch_status; static enum {PCH_NOT_READY, PCH_FAILED, PCH_SUCCESS} pch_status;
@ -637,17 +610,17 @@ make_pch(void)
/* XXX TODO */ /* XXX TODO */
exit_code = 0; exit_code = 0;
#else #else
const char *last_args[4]; const char *rest_args[] = {
# ifdef __clang__
GCC_EMIT_PCH_ARGS,
# endif
"-o", pch_file, header_file,
NULL,
};
char **args; char **args;
verbose(2, "Creating precompiled header"); verbose(2, "Creating precompiled header");
last_args[0] = "-o"; args = form_args(3, CC_COMMON_ARGS, CC_CODEFLAG_ARGS, rest_args);
last_args[1] = pch_file;
last_args[2] = header_file;
last_args[3] = NULL;
args = form_args(4, GCC_COMMON_ARGS,
(mjit_opts.debug ? GCC_DEBUG_ARGS : GCC_OPTIMIZE_ARGS),
GCC_EMIT_PCH_ARGS, last_args);
if (args == NULL) { if (args == NULL) {
if (mjit_opts.warnings || mjit_opts.verbose) if (mjit_opts.warnings || mjit_opts.verbose)
fprintf(stderr, "MJIT warning: making precompiled header failed on forming args\n"); fprintf(stderr, "MJIT warning: making precompiled header failed on forming args\n");
@ -684,7 +657,7 @@ compile_c_to_so(const char *c_file, const char *so_file)
{ {
int exit_code; int exit_code;
const char *files[] = { const char *files[] = {
#ifdef __GNUC__ #ifdef __clang__
GCC_USE_PCH_ARGS, NULL, GCC_USE_PCH_ARGS, NULL,
#endif #endif
#ifndef _MSC_VER #ifndef _MSC_VER
@ -722,16 +695,12 @@ compile_c_to_so(const char *c_file, const char *so_file)
p = append_lit(p, "-Fe"); p = append_lit(p, "-Fe");
p = append_str2(p, so_file, solen); p = append_str2(p, so_file, solen);
*p = '\0'; *p = '\0';
args = form_args(4, VC_COMMON_ARGS,
(mjit_opts.debug ? VC_DEBUG_ARGS : VC_OPTIMIZE_ARGS),
files, libs);
#else #else
files[1] = pch_file; files[1] = pch_file;
files[numberof(files)-3] = so_file; files[numberof(files)-3] = so_file;
args = form_args(5, GCC_COMMON_ARGS,
(mjit_opts.debug ? GCC_DEBUG_ARGS : GCC_OPTIMIZE_ARGS),
GCC_LDSHARED_ARGS, files, libs);
#endif #endif
args = form_args(5, CC_LDSHARED_ARGS, CC_CODEFLAG_ARGS,
CC_DLDFLAGS_ARGS, files, libs);
if (args == NULL) if (args == NULL)
return FALSE; return FALSE;
@ -765,6 +734,23 @@ load_func_from_so(const char *so_file, const char *funcname, struct rb_mjit_unit
#define MJIT_TMP_PREFIX "_ruby_mjit_" #define MJIT_TMP_PREFIX "_ruby_mjit_"
#ifndef __clang__
static const char *
header_name_end(const char *s)
{
const char *e = s + strlen(s);
#ifdef __GNUC__
static const char suffix[] = ".gch";
/* chomp .gch suffix */
if (e > s+sizeof(suffix)-1 && strcmp(e-sizeof(suffix)+1, suffix) == 0) {
e -= sizeof(suffix)-1;
}
#endif
return e;
}
#endif
/* Compile ISeq in UNIT and return function pointer of JIT-ed code. /* Compile ISeq in UNIT and return function pointer of JIT-ed code.
It may return NOT_COMPILABLE_JIT_ISEQ_FUNC if something went wrong. */ It may return NOT_COMPILABLE_JIT_ISEQ_FUNC if something went wrong. */
static mjit_func_t static mjit_func_t
@ -805,18 +791,18 @@ convert_unit_to_func(struct rb_mjit_unit *unit)
return (mjit_func_t)NOT_COMPILABLE_JIT_ISEQ_FUNC; return (mjit_func_t)NOT_COMPILABLE_JIT_ISEQ_FUNC;
} }
#ifdef __clang__
/* -include-pch is used for Clang */ /* -include-pch is used for Clang */
#ifndef __clang__ #else
{ {
# ifdef __GNUC__
const char *s = pch_file; const char *s = pch_file;
const char *e = s + strlen(s); # else
static const char suffix[] = ".gch"; const char *s = header_file;
# endif
const char *e = header_name_end(s);
fprintf(f, "#include \""); fprintf(f, "#include \"");
/* chomp .gch suffix */
if (e > s+sizeof(suffix)-1 && strcmp(e-sizeof(suffix)+1, suffix) == 0) {
e -= sizeof(suffix)-1;
}
/* print pch_file except .gch */ /* print pch_file except .gch */
for (; s < e; s++) { for (; s < e; s++) {
switch(*s) { switch(*s) {
@ -1159,10 +1145,7 @@ mjit_get_iseq_func(const struct rb_iseq_constant_body *body)
#define RUBY_MJIT_HEADER_NAME "rb_mjit_min_header-" #define RUBY_MJIT_HEADER_NAME "rb_mjit_min_header-"
/* GCC and CLANG executable paths. TODO: The paths should absolute /* GCC and CLANG executable paths. TODO: The paths should absolute
ones to prevent changing C compiler for security reasons. */ ones to prevent changing C compiler for security reasons. */
#define GCC_PATH GCC_COMMON_ARGS[0] #define CC_PATH CC_COMMON_ARGS[0]
#ifdef _MSC_VER
# define VC_PATH "cl.exe"
#endif
static void static void
init_header_filename(void) init_header_filename(void)
@ -1307,21 +1290,11 @@ mjit_init(struct mjit_options *opts)
if (mjit_opts.max_cache_size < MIN_CACHE_SIZE) if (mjit_opts.max_cache_size < MIN_CACHE_SIZE)
mjit_opts.max_cache_size = MIN_CACHE_SIZE; mjit_opts.max_cache_size = MIN_CACHE_SIZE;
{ verbose(2, "MJIT: CC defaults to %s", CC_PATH);
#if _MSC_VER
verbose(2, "MJIT: CC defaults to cl");
#else
verbose(2, "MJIT: CC defaults to %s", GCC_PATH);
#endif
}
/* Initialize variables for compilation */ /* Initialize variables for compilation */
pch_status = PCH_NOT_READY; pch_status = PCH_NOT_READY;
#ifdef _MSC_VER cc_path = CC_PATH;
cc_path = VC_PATH;
#else
cc_path = GCC_PATH;
#endif
tmp_dir = system_tmpdir(); tmp_dir = system_tmpdir();

View file

@ -1248,8 +1248,30 @@ mjit_config.h:
#ifndef RUBY_MJIT_CONFIG_H #ifndef RUBY_MJIT_CONFIG_H
#define RUBY_MJIT_CONFIG_H 1 #define RUBY_MJIT_CONFIG_H 1
<<KEEP <<KEEP
@(set sep=#define MJIT_CC ) & \ @
@(set sep=#define MJIT_CC_COMMON ) & \
for %I in ($(CC)) do @(call echo.%%sep%%"%%~I" \& set sep= ,) >> $@ for %I in ($(CC)) do @(call echo.%%sep%%"%%~I" \& set sep= ,) >> $@
@echo /* MJIT_CC */>> $@ @echo /* MJIT_CC_COMMON */>> $@
@
@(set sep=#define MJIT_CFLAGS ) & \
for %I in ($(RUNTIMEFLAG) $(ARCH_FLAG)) do @(call echo.%%sep%%"%%~I" \& set sep= ,) >> $@
@echo /* MJIT_CFLAGS */>> $@
@
@(set sep=#define MJIT_OPTFLAGS ) & \
for %I in ($(OPTFLAGS)) do @(call echo.%%sep%%"%%~I" \& set sep= ,) >> $@
@echo /* MJIT_OPTFLAGS */>> $@
@
@(set sep=#define MJIT_DEBUGFLAGS ) & \
for %I in ($(DEBUGFLAGS)) do @(call echo.%%sep%%"%%~I" \& set sep= ,) >> $@
@echo /* MJIT_DEBUGFLAGS */>> $@
@
@(set sep=#define MJIT_LDSHARED ) & \
for %I in ($(LDSHARED)) do @(call echo.%%sep%%"%%~I" \& set sep= ,) >> $@
@echo /* MJIT_LDSHARED */>> $@
@
@(set sep=#define MJIT_DLDFLAGS ) & \
for %I in ($(DLDFLAGS)) do @(call echo.%%sep%%"%%~I" \& set sep= ,) >> $@
@echo /* MJIT_DLDFLAGS */>> $@
@
@echo #endif /* RUBY_MJIT_CONFIG_H */>> $@ @echo #endif /* RUBY_MJIT_CONFIG_H */>> $@
@$(Q:@=: :) type $@ @$(Q:@=: :) type $@