emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master dea6793: Add support for GCC compiler command-line options


From: Andrea Corallo
Subject: master dea6793: Add support for GCC compiler command-line options
Date: Fri, 10 Sep 2021 15:05:02 -0400 (EDT)

branch: master
commit dea67939b65f39b60d8e990745504bd8f9e3be2c
Author: Arthur Miller <arthur.miller@live.com>
Commit: Andrea Corallo <akrl@sdf.org>

    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'.
---
 lisp/emacs-lisp/bytecomp.el |  3 +++
 lisp/emacs-lisp/comp.el     | 18 ++++++++++++++
 src/comp.c                  | 58 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 79 insertions(+)

diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el
index 8ea591b..47b3c82 100644
--- a/lisp/emacs-lisp/bytecomp.el
+++ b/lisp/emacs-lisp/bytecomp.el
@@ -2257,6 +2257,9 @@ With argument ARG, insert value in current buffer after 
the form."
           (push `(native-comp-speed . ,native-comp-speed) 
byte-native-qualities)
           (defvar native-comp-debug)
           (push `(native-comp-debug . ,native-comp-debug) 
byte-native-qualities)
+          (defvar native-comp-compiler-options)
+          (push `(native-comp-compiler-options . ,native-comp-compiler-options)
+                byte-native-qualities)
           (defvar native-comp-driver-options)
           (push `(native-comp-driver-options . ,native-comp-driver-options)
                 byte-native-qualities)
diff --git a/lisp/emacs-lisp/comp.el b/lisp/emacs-lisp/comp.el
index 80a1da5..92928e4 100644
--- a/lisp/emacs-lisp/comp.el
+++ b/lisp/emacs-lisp/comp.el
@@ -166,6 +166,16 @@ if `confirm-kill-processes' is non-nil."
   :type 'boolean
   :version "28.1")
 
+(defcustom native-comp-compiler-options nil
+  "Command line options passed verbatim to GCC compiler.
+Note that not all options are meaningful and some options might even
+break your Emacs.  Use at own risk.
+
+Passing these options is only available in libgccjit version 9
+and above."
+  :type '(repeat string)
+  :version "28.1")
+
 (defcustom native-comp-driver-options nil
   "Options passed verbatim to the native compiler's back-end driver.
 Note that not all options are meaningful; typically only the options
@@ -755,6 +765,8 @@ Returns ELT."
          :documentation "Default speed for this compilation unit.")
   (debug native-comp-debug :type number
          :documentation "Default debug level for this compilation unit.")
+  (compiler-options native-comp-compiler-options :type list
+                    :documentation "Options for the GCC compiler.")
   (driver-options native-comp-driver-options :type list
          :documentation "Options for the GCC driver.")
   (top-level-forms () :type list
@@ -1347,6 +1359,8 @@ clashes."
                                                byte-native-qualities)
         (comp-ctxt-debug comp-ctxt) (alist-get 'native-comp-debug
                                                byte-native-qualities)
+        (comp-ctxt-compiler-options comp-ctxt) (alist-get 
'native-comp-compiler-options
+                                                        byte-native-qualities)
         (comp-ctxt-driver-options comp-ctxt) (alist-get 
'native-comp-driver-options
                                                         byte-native-qualities)
         (comp-ctxt-top-level-forms comp-ctxt)
@@ -3663,6 +3677,8 @@ Prepare every function for final compilation and drive 
the C back-end."
                            comp-libgccjit-reproducer ,comp-libgccjit-reproducer
                            comp-ctxt ,comp-ctxt
                            native-comp-eln-load-path 
',native-comp-eln-load-path
+                           native-comp-compiler-options
+                           ',native-comp-compiler-options
                            native-comp-driver-options
                            ',native-comp-driver-options
                            load-path ',load-path)
@@ -3926,6 +3942,8 @@ display a message."
                                  comp-libgccjit-reproducer 
,comp-libgccjit-reproducer
                                  comp-async-compilation t
                                  native-comp-eln-load-path 
',native-comp-eln-load-path
+                                 native-comp-compiler-options
+                                 ',native-comp-compiler-options
                                  native-comp-driver-options
                                  ',native-comp-driver-options
                                  load-path ',load-path
diff --git a/src/comp.c b/src/comp.c
index 7e21331..0012860 100644
--- a/src/comp.c
+++ b/src/comp.c
@@ -515,6 +515,7 @@ typedef struct {
 typedef struct {
   EMACS_INT speed;
   EMACS_INT debug;
+  Lisp_Object compiler_options;
   Lisp_Object driver_options;
   gcc_jit_context *ctxt;
   gcc_jit_type *void_type;
@@ -4383,6 +4384,22 @@ DEFUN ("comp-native-driver-options-effective-p",
 }
 #pragma GCC diagnostic pop
 
+#pragma GCC diagnostic ignored "-Waddress"
+DEFUN ("comp-native-compiler-options-effective-p",
+       Fcomp_native_compiler_options_effective_p,
+       Scomp_native_compiler_options_effective_p,
+       0, 0, 0,
+       doc: /* Return t if `comp-native-compiler-options' is effective.  */)
+  (void)
+{
+#if defined (LIBGCCJIT_HAVE_gcc_jit_context_add_command_line_option)
+  if (gcc_jit_context_add_command_line_option)
+    return Qt;
+#endif
+  return Qnil;
+}
+#pragma GCC diagnostic pop
+
 static void
 add_driver_options (void)
 {
@@ -4422,6 +4439,43 @@ add_driver_options (void)
 #endif
 }
 
+static void
+add_compiler_options (void)
+{
+  Lisp_Object options = Fsymbol_value (Qnative_comp_compiler_options);
+
+#if defined (LIBGCCJIT_HAVE_gcc_jit_context_add_command_line_option)
+  load_gccjit_if_necessary (true);
+  if (!NILP (Fcomp_native_compiler_options_effective_p ()))
+    FOR_EACH_TAIL (options)
+        gcc_jit_context_add_command_line_option (comp.ctxt,
+                                                 /* FIXME: Need to encode
+                                                    this, but how? either
+                                                    ENCODE_FILE or
+                                                    ENCODE_SYSTEM.  */
+                                                 SSDATA (XCAR (options)));
+#endif
+  if (CONSP (options))
+    xsignal1 (Qnative_compiler_error,
+             build_string ("Customizing native compiler options"
+                           " via `comp-native-compiler-options' is"
+                           " only available on libgccjit version 9"
+                           " and above."));
+
+  /* Captured `comp-native-compiler-options' because file-local.  */
+#if defined (LIBGCCJIT_HAVE_gcc_jit_context_add_command_line_option)
+  options = comp.compiler_options;
+  if (!NILP (Fcomp_native_compiler_options_effective_p ()))
+    FOR_EACH_TAIL (options)
+      gcc_jit_context_add_command_line_option (comp.ctxt,
+                                               /* FIXME: Need to encode
+                                                  this, but how? either
+                                                  ENCODE_FILE or
+                                                  ENCODE_SYSTEM.  */
+                                               SSDATA (XCAR (options)));
+#endif
+}
+
 DEFUN ("comp--compile-ctxt-to-file", Fcomp__compile_ctxt_to_file,
        Scomp__compile_ctxt_to_file,
        1, 1, 0,
@@ -4467,6 +4521,7 @@ DEFUN ("comp--compile-ctxt-to-file", 
Fcomp__compile_ctxt_to_file,
   comp.debug = XFIXNUM (CALL1I (comp-ctxt-debug, Vcomp_ctxt));
   eassert (comp.debug < INT_MAX);
   comp.driver_options = CALL1I (comp-ctxt-driver-options, Vcomp_ctxt);
+  comp.compiler_options = CALL1I (comp-ctxt-compiler-options, Vcomp_ctxt);
 
   if (comp.debug)
       gcc_jit_context_set_bool_option (comp.ctxt,
@@ -4541,6 +4596,7 @@ DEFUN ("comp--compile-ctxt-to-file", 
Fcomp__compile_ctxt_to_file,
                                             "-fdisable-tree-isolate-paths");
 #endif
 
+  add_compiler_options ();
   add_driver_options ();
 
   if (comp.debug > 1)
@@ -5248,6 +5304,7 @@ compiled one.  */);
   DEFSYM (Qnative_comp_speed, "native-comp-speed");
   DEFSYM (Qnative_comp_debug, "native-comp-debug");
   DEFSYM (Qnative_comp_driver_options, "native-comp-driver-options");
+  DEFSYM (Qnative_comp_compiler_options, "native-comp-compiler-options");
   DEFSYM (Qcomp_libgccjit_reproducer, "comp-libgccjit-reproducer");
 
   /* Limple instruction set.  */
@@ -5357,6 +5414,7 @@ compiled one.  */);
   defsubr (&Scomp_el_to_eln_rel_filename);
   defsubr (&Scomp_el_to_eln_filename);
   defsubr (&Scomp_native_driver_options_effective_p);
+  defsubr (&Scomp_native_compiler_options_effective_p);
   defsubr (&Scomp__install_trampoline);
   defsubr (&Scomp__init_ctxt);
   defsubr (&Scomp__release_ctxt);



reply via email to

[Prev in Thread] Current Thread [Next in Thread]