aboutsummaryrefslogtreecommitdiffstats
path: root/src/comp.c
diff options
context:
space:
mode:
authorArthur Miller2021-09-10 20:57:19 +0200
committerAndrea Corallo2021-09-10 21:04:41 +0200
commitdea67939b65f39b60d8e990745504bd8f9e3be2c (patch)
tree8ffad5c53b9f3fdd219d14197168e8b971672dc6 /src/comp.c
parent6eba633eadc4228f2b132cea257f1b32691fd6b2 (diff)
downloademacs-dea67939b65f39b60d8e990745504bd8f9e3be2c.tar.gz
emacs-dea67939b65f39b60d8e990745504bd8f9e3be2c.zip
Add support for GCC compiler command-line options
* lisp/emacs-lisp/comp.el ('native-comp-compiler-options): New option. * lisp/emacs-lisp/bytecomp.el (byte-compile-from-buffer): Add support for new 'native-comp-compiler-options'. * src/comp.c (Fcomp_native_compiler_options_effective_p): New function. (add_compiler_options): New function. (Fcomp__compile_ctxt_to_file): Call 'add_compiler_options'.
Diffstat (limited to 'src/comp.c')
-rw-r--r--src/comp.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/comp.c b/src/comp.c
index 7e21331e666..0012860096d 100644
--- a/src/comp.c
+++ b/src/comp.c
@@ -515,6 +515,7 @@ typedef struct {
515typedef struct { 515typedef struct {
516 EMACS_INT speed; 516 EMACS_INT speed;
517 EMACS_INT debug; 517 EMACS_INT debug;
518 Lisp_Object compiler_options;
518 Lisp_Object driver_options; 519 Lisp_Object driver_options;
519 gcc_jit_context *ctxt; 520 gcc_jit_context *ctxt;
520 gcc_jit_type *void_type; 521 gcc_jit_type *void_type;
@@ -4383,6 +4384,22 @@ DEFUN ("comp-native-driver-options-effective-p",
4383} 4384}
4384#pragma GCC diagnostic pop 4385#pragma GCC diagnostic pop
4385 4386
4387#pragma GCC diagnostic ignored "-Waddress"
4388DEFUN ("comp-native-compiler-options-effective-p",
4389 Fcomp_native_compiler_options_effective_p,
4390 Scomp_native_compiler_options_effective_p,
4391 0, 0, 0,
4392 doc: /* Return t if `comp-native-compiler-options' is effective. */)
4393 (void)
4394{
4395#if defined (LIBGCCJIT_HAVE_gcc_jit_context_add_command_line_option)
4396 if (gcc_jit_context_add_command_line_option)
4397 return Qt;
4398#endif
4399 return Qnil;
4400}
4401#pragma GCC diagnostic pop
4402
4386static void 4403static void
4387add_driver_options (void) 4404add_driver_options (void)
4388{ 4405{
@@ -4422,6 +4439,43 @@ add_driver_options (void)
4422#endif 4439#endif
4423} 4440}
4424 4441
4442static void
4443add_compiler_options (void)
4444{
4445 Lisp_Object options = Fsymbol_value (Qnative_comp_compiler_options);
4446
4447#if defined (LIBGCCJIT_HAVE_gcc_jit_context_add_command_line_option)
4448 load_gccjit_if_necessary (true);
4449 if (!NILP (Fcomp_native_compiler_options_effective_p ()))
4450 FOR_EACH_TAIL (options)
4451 gcc_jit_context_add_command_line_option (comp.ctxt,
4452 /* FIXME: Need to encode
4453 this, but how? either
4454 ENCODE_FILE or
4455 ENCODE_SYSTEM. */
4456 SSDATA (XCAR (options)));
4457#endif
4458 if (CONSP (options))
4459 xsignal1 (Qnative_compiler_error,
4460 build_string ("Customizing native compiler options"
4461 " via `comp-native-compiler-options' is"
4462 " only available on libgccjit version 9"
4463 " and above."));
4464
4465 /* Captured `comp-native-compiler-options' because file-local. */
4466#if defined (LIBGCCJIT_HAVE_gcc_jit_context_add_command_line_option)
4467 options = comp.compiler_options;
4468 if (!NILP (Fcomp_native_compiler_options_effective_p ()))
4469 FOR_EACH_TAIL (options)
4470 gcc_jit_context_add_command_line_option (comp.ctxt,
4471 /* FIXME: Need to encode
4472 this, but how? either
4473 ENCODE_FILE or
4474 ENCODE_SYSTEM. */
4475 SSDATA (XCAR (options)));
4476#endif
4477}
4478
4425DEFUN ("comp--compile-ctxt-to-file", Fcomp__compile_ctxt_to_file, 4479DEFUN ("comp--compile-ctxt-to-file", Fcomp__compile_ctxt_to_file,
4426 Scomp__compile_ctxt_to_file, 4480 Scomp__compile_ctxt_to_file,
4427 1, 1, 0, 4481 1, 1, 0,
@@ -4467,6 +4521,7 @@ DEFUN ("comp--compile-ctxt-to-file", Fcomp__compile_ctxt_to_file,
4467 comp.debug = XFIXNUM (CALL1I (comp-ctxt-debug, Vcomp_ctxt)); 4521 comp.debug = XFIXNUM (CALL1I (comp-ctxt-debug, Vcomp_ctxt));
4468 eassert (comp.debug < INT_MAX); 4522 eassert (comp.debug < INT_MAX);
4469 comp.driver_options = CALL1I (comp-ctxt-driver-options, Vcomp_ctxt); 4523 comp.driver_options = CALL1I (comp-ctxt-driver-options, Vcomp_ctxt);
4524 comp.compiler_options = CALL1I (comp-ctxt-compiler-options, Vcomp_ctxt);
4470 4525
4471 if (comp.debug) 4526 if (comp.debug)
4472 gcc_jit_context_set_bool_option (comp.ctxt, 4527 gcc_jit_context_set_bool_option (comp.ctxt,
@@ -4541,6 +4596,7 @@ DEFUN ("comp--compile-ctxt-to-file", Fcomp__compile_ctxt_to_file,
4541 "-fdisable-tree-isolate-paths"); 4596 "-fdisable-tree-isolate-paths");
4542#endif 4597#endif
4543 4598
4599 add_compiler_options ();
4544 add_driver_options (); 4600 add_driver_options ();
4545 4601
4546 if (comp.debug > 1) 4602 if (comp.debug > 1)
@@ -5248,6 +5304,7 @@ compiled one. */);
5248 DEFSYM (Qnative_comp_speed, "native-comp-speed"); 5304 DEFSYM (Qnative_comp_speed, "native-comp-speed");
5249 DEFSYM (Qnative_comp_debug, "native-comp-debug"); 5305 DEFSYM (Qnative_comp_debug, "native-comp-debug");
5250 DEFSYM (Qnative_comp_driver_options, "native-comp-driver-options"); 5306 DEFSYM (Qnative_comp_driver_options, "native-comp-driver-options");
5307 DEFSYM (Qnative_comp_compiler_options, "native-comp-compiler-options");
5251 DEFSYM (Qcomp_libgccjit_reproducer, "comp-libgccjit-reproducer"); 5308 DEFSYM (Qcomp_libgccjit_reproducer, "comp-libgccjit-reproducer");
5252 5309
5253 /* Limple instruction set. */ 5310 /* Limple instruction set. */
@@ -5357,6 +5414,7 @@ compiled one. */);
5357 defsubr (&Scomp_el_to_eln_rel_filename); 5414 defsubr (&Scomp_el_to_eln_rel_filename);
5358 defsubr (&Scomp_el_to_eln_filename); 5415 defsubr (&Scomp_el_to_eln_filename);
5359 defsubr (&Scomp_native_driver_options_effective_p); 5416 defsubr (&Scomp_native_driver_options_effective_p);
5417 defsubr (&Scomp_native_compiler_options_effective_p);
5360 defsubr (&Scomp__install_trampoline); 5418 defsubr (&Scomp__install_trampoline);
5361 defsubr (&Scomp__init_ctxt); 5419 defsubr (&Scomp__init_ctxt);
5362 defsubr (&Scomp__release_ctxt); 5420 defsubr (&Scomp__release_ctxt);