diff --git a/src/init.c b/src/init.c index 9ee349a8dc5bc..83120da8e693f 100644 --- a/src/init.c +++ b/src/init.c @@ -83,6 +83,7 @@ jl_compileropts_t jl_compileropts = { NULL, // build_path 0, // code_coverage 0, // malloc_log JL_COMPILEROPT_CHECK_BOUNDS_DEFAULT, + JL_COMPILEROPT_DUMPBITCODE_OFF, 0 // int32_literals }; @@ -1011,6 +1012,16 @@ DLLEXPORT int julia_trampoline(int argc, char **argv, int (*pmain)(int ac,char * if (asprintf(&build_ji, "%s.ji",build_path) > 0) { jl_save_system_image(build_ji); free(build_ji); + if (jl_compileropts.dumpbitcode == JL_COMPILEROPT_DUMPBITCODE_ON) + { + char *build_bc; + if (asprintf(&build_bc, "%s.bc",build_path) > 0) { + jl_dump_bitcode(build_bc); + free(build_bc); + } else { + ios_printf(ios_stderr,"\nWARNING: failed to create string for .bc build path\n"); + } + } char *build_o; if (asprintf(&build_o, "%s.o",build_path) > 0) { jl_dump_objfile(build_o,0); diff --git a/src/julia.h b/src/julia.h index 739a91783a740..16635d85b2872 100644 --- a/src/julia.h +++ b/src/julia.h @@ -1326,6 +1326,7 @@ typedef struct { int8_t code_coverage; int8_t malloc_log; int8_t check_bounds; + int8_t dumpbitcode; int int_literals; } jl_compileropts_t; @@ -1340,6 +1341,9 @@ extern DLLEXPORT jl_compileropts_t jl_compileropts; #define JL_COMPILEROPT_CHECK_BOUNDS_ON 1 #define JL_COMPILEROPT_CHECK_BOUNDS_OFF 2 +#define JL_COMPILEROPT_DUMPBITCODE_ON 1 +#define JL_COMPILEROPT_DUMPBITCODE_OFF 2 + #ifdef __cplusplus } #endif diff --git a/ui/repl.c b/ui/repl.c index 6e37a089bd0d7..b01a46d91e0ab 100644 --- a/ui/repl.c +++ b/ui/repl.c @@ -80,7 +80,8 @@ static const char *opts = " --track-allocation={none|user|all}\n" " Count bytes allocated by each source line\n" " --check-bounds={yes|no} Emit bounds checks always or never (ignoring declarations)\n" - " --int-literals={32|64} Select integer literal size independent of platform\n"; + " --int-literals={32|64} Select integer literal size independent of platform\n" + " --dump-bitcode={yes|no} Dump bitcode for the system image (used with --build)\n"; void parse_opts(int *argcp, char ***argvp) { @@ -96,6 +97,7 @@ void parse_opts(int *argcp, char ***argvp) { "track-allocation",required_argument, 0, 'm' }, { "check-bounds", required_argument, 0, 300 }, { "int-literals", required_argument, 0, 301 }, + { "dump-bitcode", required_argument, 0, 302 }, { 0, 0, 0, 0 } }; int c; @@ -166,6 +168,12 @@ void parse_opts(int *argcp, char ***argvp) exit(1); } break; + case 302: + if (!strcmp(optarg,"yes")) + jl_compileropts.dumpbitcode = JL_COMPILEROPT_DUMPBITCODE_ON; + else if (!strcmp(optarg,"no")) + jl_compileropts.dumpbitcode = JL_COMPILEROPT_DUMPBITCODE_OFF; + break; default: ios_printf(ios_stderr, "julia: unhandled option -- %c\n", c); ios_printf(ios_stderr, "This is a bug, please report it.\n");