public inbox for cgen@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Enable the Guile compiler
@ 2023-08-22 18:51 Tom Tromey
  2023-08-22 19:04 ` Jose E. Marchesi
  0 siblings, 1 reply; 5+ messages in thread
From: Tom Tromey @ 2023-08-22 18:51 UTC (permalink / raw)
  To: cgen; +Cc: Tom Tromey

This patch changes cgen so that the Guile compiler can be used.
Mainly this is done by using eval-when to ensure that files are loaded
during the compilation process.  However, "-s" handling and
srcdir-setting are also cleaned up, using Guile's (current-filename)
feature.

The main benefit of using the compiler is that it is much faster, once
the scripts have been compiled.  Also it simplifies the use of cgen,
as users don't need to remember to set an environment variable before
invoking it.
---
 cgen-doc.scm        | 47 +++++-------------------------
 cgen-gas.scm        | 56 +++++++++--------------------------
 cgen-intrinsics.scm | 47 +++++-------------------------
 cgen-opc.scm        | 55 ++++++++---------------------------
 cgen-sid.scm        | 51 +++++++-------------------------
 cgen-sim.scm        | 53 +++++++--------------------------
 cgen-stest.scm      | 57 ++++++++++--------------------------
 cgen-testsuite.scm  | 49 +++++++------------------------
 dev-utils.scm       |  4 +--
 dev.scm             | 10 +++----
 guile.scm           |  2 --
 read.scm            | 71 +++++++++++++++++++++++----------------------
 12 files changed, 131 insertions(+), 371 deletions(-)

diff --git a/cgen-doc.scm b/cgen-doc.scm
index 83af463..5aa751b 100644
--- a/cgen-doc.scm
+++ b/cgen-doc.scm
@@ -2,18 +2,16 @@
 ; This is invoked to build: $arch.html.
 ; Copyright (C) 2003, 2009 Doug Evans
 ; This file is part of CGEN.
-;
-; This is a standalone script, we don't load anything until we parse the
-; -s argument (keeps reliance off of environment variables, etc.).
 
-; Load the various support routines.
+(eval-when (expand load eval)
+	   ;; Kept global so it's available to the other .scm files.
+	   (define srcdir (dirname (current-filename)))
+	   (add-to-load-path srcdir)
 
-(define (load-files srcdir)
-  (load (string-append srcdir "/read.scm"))
-  (load (string-append srcdir "/desc.scm"))
-  (load (string-append srcdir "/desc-cpu.scm"))
-  (load (string-append srcdir "/html.scm"))
-)
+	   (load-from-path "read")
+	   (load-from-path "desc")
+	   (load-from-path "desc-cpu")
+	   (load-from-path "html"))
 
 (define doc-arguments
   (list
@@ -29,40 +27,11 @@
    )
 )
 
-; Kept global so it's available to the other .scm files.
-(define srcdir ".")
-
-; Scan argv for -s srcdir.
-; We can't process any other args until we find the cgen source dir.
-; The result is srcdir.
-; We assume "-s" isn't the argument to another option.  Unwise, yes.
-; Alternatives are to require it to be the first argument or at least preceed
-; any option with a "-s" argument, or to put knowledge of the common argument
-; set and common argument parsing code in every top level file.
-
-(define (find-srcdir argv)
-  (let loop ((argv argv))
-    (if (null? argv)
-	(error "`-s srcdir' not present, can't load cgen"))
-    (if (string=? "-s" (car argv))
-	(begin
-	  (if (null? (cdr argv))
-	      (error "missing srcdir arg to `-s'"))
-	  (cadr argv))
-	(loop (cdr argv))))	
-)
-
 ; Main routine, parses options and calls generators.
 
 (define (cgen-doc argv)
   (let ()
 
-    ; Find and set srcdir, then load all Scheme code.
-    ; Drop the first argument, it is the script name (i.e. argv[0]).
-    (set! srcdir (find-srcdir (cdr argv)))
-    (set! %load-path (cons srcdir %load-path))
-    (load-files srcdir)
-
     (display-argv argv)
 
     (cgen #:argv argv
diff --git a/cgen-gas.scm b/cgen-gas.scm
index 3d33e92..1e12819 100644
--- a/cgen-gas.scm
+++ b/cgen-gas.scm
@@ -5,19 +5,20 @@
 ; This is invoked to build several .s files and a "build script",
 ; which generates the .d files and .exp DejaGNU test case.
 
-; Load the various support routines.
-
-(define (load-files srcdir)
-  (load (string-append srcdir "/read.scm"))
-  (load (string-append srcdir "/desc.scm"))
-  (load (string-append srcdir "/desc-cpu.scm"))
-  (load (string-append srcdir "/opcodes.scm"))
-  (load (string-append srcdir "/opc-asmdis.scm"))
-  (load (string-append srcdir "/opc-ibld.scm"))
-  (load (string-append srcdir "/opc-itab.scm"))
-  (load (string-append srcdir "/opc-opinst.scm"))
-  (load (string-append srcdir "/gas-test.scm"))
-)
+(eval-when (expand load eval)
+	   ;; Kept global so it's available to the other .scm files.
+	   (define srcdir (dirname (current-filename)))
+	   (add-to-load-path srcdir)
+
+	   (load-from-path "read")
+	   (load-from-path "desc")
+	   (load-from-path "desc-cpu")
+	   (load-from-path "opcodes")
+	   (load-from-path "opc-asmdis")
+	   (load-from-path "opc-ibld")
+	   (load-from-path "opc-itab")
+	   (load-from-path "opc-opinst")
+	   (load-from-path "gas-test"))
 
 (define gas-arguments
   (list
@@ -30,40 +31,11 @@
    )
 )
 
-; Kept global so it's available to the other .scm files.
-(define srcdir ".")
-
-; Scan argv for -s srcdir.
-; We can't process any other args until we find the cgen source dir.
-; The result is srcdir.
-; We assume "-s" isn't the argument to another option.  Unwise, yes.
-; Alternatives are to require it to be the first argument or at least preceed
-; any option with a "-s" argument, or to put knowledge of the common argument
-; set and common argument parsing code in every top level file.
-
-(define (find-srcdir argv)
-  (let loop ((argv argv))
-    (if (null? argv)
-	(error "`-s srcdir' not present, can't load cgen"))
-    (if (string=? "-s" (car argv))
-	(begin
-	  (if (null? (cdr argv))
-	      (error "missing srcdir arg to `-s'"))
-	  (cadr argv))
-	(loop (cdr argv))))	
-)
-
 ; Main routine, parses options and calls generators.
 
 (define (cgen-gas argv)
   (let ()
 
-    ; Find and set srcdir, then load all Scheme code.
-    ; Drop the first argument, it is the script name (i.e. argv[0]).
-    (set! srcdir (find-srcdir (cdr argv)))
-    (set! %load-path (cons srcdir %load-path))
-    (load-files srcdir)
-
     (display-argv argv)
 
     (cgen #:argv argv
diff --git a/cgen-intrinsics.scm b/cgen-intrinsics.scm
index 16e0338..1e5f882 100644
--- a/cgen-intrinsics.scm
+++ b/cgen-intrinsics.scm
@@ -6,19 +6,15 @@
 ;
 ; Copyright (C) 2000, 2009 Red Hat, Inc.
 ; This file is part of CGEN.
-;
-; This is a standalone script, we don't load anything until we parse the
-; -s argument (keeps reliance off of environment variables, etc.).
-
-; Load the various support routines.
 
-(define (load-files srcdir)
-  ; Fix up Scheme to be what we use (guile is always in flux).
-  (primitive-load-path (string-append srcdir "/guile.scm"))
+(eval-when (expand load eval)
+	   ;; Kept global so it's available to the other .scm files.
+	   (define srcdir (dirname (current-filename)))
+	   (add-to-load-path srcdir)
 
-  (load (string-append srcdir "/read.scm"))
-  (load (string-append srcdir "/intrinsics.scm"))
-)
+	   (load-from-path "guile")
+	   (load-from-path "read")
+	   (load-from-path "intrinsics"))
 
 (define intrinsics-isas '())
 
@@ -38,40 +34,11 @@
    (list "-T" "file" "generate intrinsic-testsuite.c in <file>" #f
 	 (lambda (arg) (file-write arg intrinsic-testsuite.c)))))
 
-; Kept global so it's available to the other .scm files.
-(define srcdir ".")
-
-; Scan argv for -s srcdir.
-; We can't process any other args until we find the cgen source dir.
-; The result is srcdir.
-; We assume "-s" isn't the argument to another option.  Unwise, yes.
-; Alternatives are to require it to be the first argument or at least preceed
-; any option with a "-s" argument, or to put knowledge of the common argument
-; set and common argument parsing code in every top level file.
-
-(define (find-srcdir argv)
-  (let loop ((argv argv))
-    (if (null? argv)
-	(error "`-s srcdir' not present, can't load cgen"))
-    (if (string=? "-s" (car argv))
-	(begin
-	  (if (null? (cdr argv))
-	      (error "missing srcdir arg to `-s'"))
-	  (cadr argv))
-	(loop (cdr argv))))	
-)
-
 ; Main routine, parses options and calls generators.
 
 (define (cgen-intrinsics argv)
   (let ()
 
-    ; Find and set srcdir, then load all Scheme code.
-    ; Drop the first argument, it is the script name (i.e. argv[0]).
-    (set! srcdir (find-srcdir (cdr argv)))
-    (set! %load-path (cons srcdir %load-path))
-    (load-files srcdir)
-
     (display-argv argv)
 
     (cgen #:argv argv
diff --git a/cgen-opc.scm b/cgen-opc.scm
index 276fdb8..cac5115 100644
--- a/cgen-opc.scm
+++ b/cgen-opc.scm
@@ -3,22 +3,20 @@
 ; $arch-opc.h, $arch-opc.c, $arch-asm.in, $arch-dis.in, and $arch-ibld.[ch].
 ; Copyright (C) 2000, 2009 Red Hat, Inc.
 ; This file is part of CGEN.
-;
-; This is a standalone script, we don't load anything until we parse the
-; -s argument (keeps reliance off of environment variables, etc.).
 
-; Load the various support routines.
+(eval-when (expand load eval)
+	   ;; Kept global so it's available to the other .scm files.
+	   (define srcdir (dirname (current-filename)))
+	   (add-to-load-path srcdir)
 
-(define (load-files srcdir)
-  (load (string-append srcdir "/read.scm"))
-  (load (string-append srcdir "/desc.scm"))
-  (load (string-append srcdir "/desc-cpu.scm"))
-  (load (string-append srcdir "/opcodes.scm"))
-  (load (string-append srcdir "/opc-asmdis.scm"))
-  (load (string-append srcdir "/opc-ibld.scm"))
-  (load (string-append srcdir "/opc-itab.scm"))
-  (load (string-append srcdir "/opc-opinst.scm"))
-)
+	   (load-from-path "read")
+	   (load-from-path "desc")
+	   (load-from-path "desc-cpu")
+	   (load-from-path "opcodes")
+	   (load-from-path "opc-asmdis")
+	   (load-from-path "opc-ibld")
+	   (load-from-path "opc-itab")
+	   (load-from-path "opc-opinst"))
 
 (define opc-arguments
   (list
@@ -60,40 +58,11 @@
 ; ((-R) (file-write *arg* cgen-reloc.c))
 ; ((-S) (file-write *arg* cgen-bfdcpu.c))
 
-; Kept global so it's available to the other .scm files.
-(define srcdir ".")
-
-; Scan argv for -s srcdir.
-; We can't process any other args until we find the cgen source dir.
-; The result is srcdir.
-; We assume "-s" isn't the argument to another option.  Unwise, yes.
-; Alternatives are to require it to be the first argument or at least preceed
-; any option with a "-s" argument, or to put knowledge of the common argument
-; set and common argument parsing code in every top level file.
-
-(define (find-srcdir argv)
-  (let loop ((argv argv))
-    (if (null? argv)
-	(error "`-s srcdir' not present, can't load cgen"))
-    (if (string=? "-s" (car argv))
-	(begin
-	  (if (null? (cdr argv))
-	      (error "missing srcdir arg to `-s'"))
-	  (cadr argv))
-	(loop (cdr argv))))	
-)
-
 ; Main routine, parses options and calls generators.
 
 (define (cgen-opc argv)
   (let ()
 
-    ; Find and set srcdir, then load all Scheme code.
-    ; Drop the first argument, it is the script name (i.e. argv[0]).
-    (set! srcdir (find-srcdir (cdr argv)))
-    (set! %load-path (cons srcdir %load-path))
-    (load-files srcdir)
-
     (display-argv argv)
 
     (cgen #:argv argv
diff --git a/cgen-sid.scm b/cgen-sid.scm
index bb74a7b..ab9e505 100644
--- a/cgen-sid.scm
+++ b/cgen-sid.scm
@@ -3,20 +3,18 @@
 ; semantics.cxx, sem-switch.cxx, model.h, model.cxx
 ; Copyright (C) 2000, 2003, 2009 Red Hat, Inc.
 ; This file is part of CGEN.
-;
-; This is a standalone script, we don't load anything until we parse the
-; -s argument (keeps reliance off of environment variables, etc.).
 
-; Load the various support routines.
+(eval-when (expand load eval)
+	   ;; Kept global so it's available to the other .scm files.
+	   (define srcdir (dirname (current-filename)))
+	   (add-to-load-path srcdir)
 
-(define (load-files srcdir)
-  (load (string-append srcdir "/read.scm"))
-  (load (string-append srcdir "/utils-sim.scm"))
-  (load (string-append srcdir "/sid.scm"))
-  (load (string-append srcdir "/sid-cpu.scm"))
-  (load (string-append srcdir "/sid-model.scm"))
-  (load (string-append srcdir "/sid-decode.scm"))
-)
+	   (load-from-path "read")
+	   (load-from-path "utils-sim")
+	   (load-from-path "sid")
+	   (load-from-path "sid-cpu")
+	   (load-from-path "sid-model")
+	   (load-from-path "sid-decode"))
 
 (define sim-arguments
   (list
@@ -53,40 +51,11 @@
    )
 )
 
-; Kept global so it's available to the other .scm files.
-(define srcdir ".")
-
-; Scan argv for -s srcdir.
-; We can't process any other args until we find the cgen source dir.
-; The result is srcdir.
-; We assume "-s" isn't the argument to another option.  Unwise, yes.
-; Alternatives are to require it to be the first argument or at least preceed
-; any option with a "-s" argument, or to put knowledge of the common argument
-; set and common argument parsing code in every top level file.
-
-(define (find-srcdir argv)
-  (let loop ((argv argv))
-    (if (null? argv)
-	(error "`-s srcdir' not present, can't load cgen"))
-    (if (string=? "-s" (car argv))
-	(begin
-	  (if (null? (cdr argv))
-	      (error "missing srcdir arg to `-s'"))
-	  (cadr argv))
-	(loop (cdr argv))))	
-)
-
 ; Main routine, parses options and calls generators.
 
 (define (cgen-sim argv)
   (let ()
 
-    ; Find and set srcdir, then load all Scheme code.
-    ; Drop the first argument, it is the script name (i.e. argv[0]).
-    (set! srcdir (find-srcdir (cdr argv)))
-    (set! %load-path (cons srcdir %load-path))
-    (load-files srcdir)
-
     (display-argv argv)
 
     (cgen #:argv argv
diff --git a/cgen-sim.scm b/cgen-sim.scm
index 2b9f962..ec7b84c 100644
--- a/cgen-sim.scm
+++ b/cgen-sim.scm
@@ -6,21 +6,19 @@
 ;
 ; Copyright (C) 2000, 2009 Red Hat, Inc.
 ; This file is part of CGEN.
-;
-; This is a standalone script, we don't load anything until we parse the
-; -s argument (keeps reliance off of environment variables, etc.).
 
-; Load the various support routines.
+(eval-when (expand load eval)
+	   ;; Kept global so it's available to the other .scm files.
+	   (define srcdir (dirname (current-filename)))
+	   (add-to-load-path srcdir)
 
-(define (load-files srcdir)
-  (load (string-append srcdir "/read.scm"))
-  (load (string-append srcdir "/utils-sim.scm"))
-  (load (string-append srcdir "/sim.scm"))
-  (load (string-append srcdir "/sim-arch.scm"))
-  (load (string-append srcdir "/sim-cpu.scm"))
-  (load (string-append srcdir "/sim-model.scm"))
-  (load (string-append srcdir "/sim-decode.scm"))
-)
+	   (load-from-path "read")
+	   (load-from-path "utils-sim")
+	   (load-from-path "sim")
+	   (load-from-path "sim-arch")
+	   (load-from-path "sim-cpu")
+	   (load-from-path "sim-model")
+	   (load-from-path "sim-decode"))
 
 (define sim-arguments
   (list
@@ -81,40 +79,11 @@
    )
 )
 
-; Kept global so it's available to the other .scm files.
-(define srcdir ".")
-
-; Scan argv for -s srcdir.
-; We can't process any other args until we find the cgen source dir.
-; The result is srcdir.
-; We assume "-s" isn't the argument to another option.  Unwise, yes.
-; Alternatives are to require it to be the first argument or at least preceed
-; any option with a "-s" argument, or to put knowledge of the common argument
-; set and common argument parsing code in every top level file.
-
-(define (find-srcdir argv)
-  (let loop ((argv argv))
-    (if (null? argv)
-	(error "`-s srcdir' not present, can't load cgen"))
-    (if (string=? "-s" (car argv))
-	(begin
-	  (if (null? (cdr argv))
-	      (error "missing srcdir arg to `-s'"))
-	  (cadr argv))
-	(loop (cdr argv))))
-)
-
 ; Main routine, parses options and calls generators.
 
 (define (cgen-sim argv)
   (let ()
 
-    ; Find and set srcdir, then load all Scheme code.
-    ; Drop the first argument, it is the script name (i.e. argv[0]).
-    (set! srcdir (find-srcdir (cdr argv)))
-    (set! %load-path (cons srcdir %load-path))
-    (load-files srcdir)
-
     (display-argv argv)
 
     (cgen #:argv argv
diff --git a/cgen-stest.scm b/cgen-stest.scm
index 10f62a8..7214f82 100644
--- a/cgen-stest.scm
+++ b/cgen-stest.scm
@@ -6,18 +6,22 @@
 ; generate the .d files and .exp file.
 ; This is invoked to build: tmp-build.sh cpu-cpu.exp
 \f
-; Load the various support routines
-(define (load-files srcdir)
-  (load (string-append srcdir "/read.scm"))
-  (load (string-append srcdir "/desc.scm"))
-  (load (string-append srcdir "/desc-cpu.scm"))
-  (load (string-append srcdir "/opcodes.scm"))
-  (load (string-append srcdir "/opc-asmdis.scm"))
-  (load (string-append srcdir "/opc-ibld.scm"))
-  (load (string-append srcdir "/opc-itab.scm"))
-  (load (string-append srcdir "/opc-opinst.scm"))
-  (load (string-append srcdir "/sim-test.scm"))
-)
+(use-modules (ice-9 slib))
+
+(eval-when (expand load eval)
+	   ;; Kept global so it's available to the other .scm files.
+	   (define srcdir (dirname (current-filename)))
+	   (add-to-load-path srcdir)
+
+	   (load-from-path "read")
+	   (load-from-path "desc")
+	   (load-from-path "desc-cpu")
+	   (load-from-path "opcodes")
+	   (load-from-path "opc-asmdis")
+	   (load-from-path "opc-ibld")
+	   (load-from-path "opc-itab")
+	   (load-from-path "opc-opinst")
+	   (load-from-path "sim-test"))
 
 (define stest-arguments
   (list
@@ -30,40 +34,11 @@
    )
 )
 
-; Kept global so it's available to the other .scm files.
-(define srcdir ".")
-
-; Scan argv for -s srcdir.
-; We can't process any other args until we find the cgen source dir.
-; The result is srcdir.
-; We assume "-s" isn't the argument to another option.  Unwise, yes.
-; Alternatives are to require it to be the first argument or at least preceed
-; any option with a "-s" argument, or to put knowledge of the common argument
-; set and common argument parsing code in every top level file.
-
-(define (find-srcdir argv)
-  (let loop ((argv argv))
-    (if (null? argv)
-	(error "`-s srcdir' not present, can't load cgen"))
-    (if (string=? "-s" (car argv))
-	(begin
-	  (if (null? (cdr argv))
-	      (error "missing srcdir arg to `-s'"))
-	  (cadr argv))
-	(loop (cdr argv))))	
-)
-
 ; Main routine, parses options and calls generators.
 
 (define (cgen-stest argv)
   (let ()
 
-    ; Find and set srcdir, then load all Scheme code.
-    ; Drop the first argument, it is the script name (i.e. argv[0]).
-    (set! srcdir (find-srcdir (cdr argv)))
-    (set! %load-path (cons srcdir %load-path))
-    (load-files srcdir)
-
     (display-argv argv)
 
     (cgen #:argv argv
diff --git a/cgen-testsuite.scm b/cgen-testsuite.scm
index 0c37be3..ae78cff 100644
--- a/cgen-testsuite.scm
+++ b/cgen-testsuite.scm
@@ -1,18 +1,18 @@
 ; CGEN testsuite driver.
 ; Copyright (C) 2009 Doug Evans
 ; This file is part of CGEN.
-;
-; This is a standalone script, we don't load anything until we parse the
-; -s argument (keeps reliance off of environment variables, etc.).
 
-; Load the various support routines.
+(eval-when (expand load eval)
+	   ;; Kept global so it's available to the other .scm files.
+	   (define srcdir (dirname (current-filename)))
+	   (add-to-load-path srcdir)
 
-(define (load-files srcdir)
-  (load (string-append srcdir "/read.scm"))
-  (load (string-append srcdir "/desc.scm"))
-  (load (string-append srcdir "/desc-cpu.scm"))
-  (load (string-append srcdir "/testsuite.scm"))
-)
+	   (use-modules (ice-9 slib))
+
+	   (load-from-path "read")
+	   (load-from-path "desc")
+	   (load-from-path "desc-cpu")
+	   (load-from-path "testsuite"))
 
 (define testsuite-arguments
   (list
@@ -22,40 +22,11 @@
    )
 )
 
-; Kept global so it's available to the other .scm files.
-(define srcdir ".")
-
-; Scan argv for -s srcdir.
-; We can't process any other args until we find the cgen source dir.
-; The result is srcdir.
-; We assume "-s" isn't the argument to another option.  Unwise, yes.
-; Alternatives are to require it to be the first argument or at least preceed
-; any option with a "-s" argument, or to put knowledge of the common argument
-; set and common argument parsing code in every top level file.
-
-(define (find-srcdir argv)
-  (let loop ((argv argv))
-    (if (null? argv)
-	(error "`-s srcdir' not present, can't load cgen"))
-    (if (string=? "-s" (car argv))
-	(begin
-	  (if (null? (cdr argv))
-	      (error "missing srcdir arg to `-s'"))
-	  (cadr argv))
-	(loop (cdr argv))))	
-)
-
 ; Main routine, parses options and calls generators.
 
 (define (cgen-testsuite argv)
   (let ()
 
-    ; Find and set srcdir, then load all Scheme code.
-    ; Drop the first argument, it is the script name (i.e. argv[0]).
-    (set! srcdir (find-srcdir (cdr argv)))
-    (set! %load-path (cons srcdir %load-path))
-    (load-files srcdir)
-
     (display-argv argv)
 
     (cgen #:argv argv
diff --git a/dev-utils.scm b/dev-utils.scm
index 89c1ee1..fe7cd7a 100644
--- a/dev-utils.scm
+++ b/dev-utils.scm
@@ -6,8 +6,8 @@
 ;; This file contains a collection of utilities for use when
 ;; analyzing cpu files from Scheme.
 
-(define srcdir ".")
-(set! %load-path (cons srcdir %load-path))
+(define srcdir (dirname (current-filename)))
+(add-to-load-path srcdir)
 
 (define (load-doc)
   (load "read")
diff --git a/dev.scm b/dev.scm
index 2b31688..12be288 100644
--- a/dev.scm
+++ b/dev.scm
@@ -6,11 +6,11 @@
 ; This file is loaded in during an interactive guile session to
 ; develop and debug CGEN.
 
-; First load guile.scm to coerce guile into something we've been using.
-; Guile is always in flux.
-(load "guile.scm")
-
-(load "dev-utils.scm")
+(eval-when (expand load eval)
+	   ;; First load guile.scm to coerce guile into something we've been using.
+	   ;; Guile is always in flux.
+	   (load-from-path "guile")
+	   (load-from-path "dev-utils"))
 
 ; Also defined in read.scm, but we need it earlier.
 (define APPLICATION 'UNKNOWN)
diff --git a/guile.scm b/guile.scm
index 5899f15..274264a 100644
--- a/guile.scm
+++ b/guile.scm
@@ -6,8 +6,6 @@
 (define (eval1 expr)
   (eval expr (current-module)))
 
-(define load primitive-load-path)
-
 (define %stat stat)
 
 (debug-enable 'backtrace)
diff --git a/read.scm b/read.scm
index e6c2bde..392e7ba 100644
--- a/read.scm
+++ b/read.scm
@@ -62,41 +62,42 @@
 \f
 ;; Variables representing misc. global constants.
 
-;; Load the base cgen files.
-
-(load "pmacros")
-(load "cos")
-(load "slib/logical")
-(load "slib/sort")
-;; Used to pretty-print debugging messages.
-(load "slib/pp")
-;; Used by pretty-print.
-(load "slib/random")
-(load "slib/genwrite")
-(load "utils")
-(load "utils-cgen")
-(load "attr")
-(load "enum")
-(load "mach")
-(load "model")
-(load "types")
-(load "mode")
-(load "ifield")
-(load "iformat")
-(load "hardware")
-(load "operand")
-(load "insn")
-(load "minsn")
-(load "decode")
-(load "rtl")
-(load "rtl-traverse")
-(load "rtl-xform")
-(load "rtx-funcs")
-(load "rtl-c")
-(load "semantics")
-(load "sem-frags")
-(load "utils-gen")
-(load "pgmr-tools")
+(eval-when (expand load eval)
+	   ;; Load the base cgen files.
+
+	   (load-from-path "pmacros")
+	   (load-from-path "cos")
+	   (load-from-path "slib/logical")
+	   (load-from-path "slib/sort")
+	   ;; Used to pretty-print debugging messages.
+	   (load-from-path "slib/pp")
+	   ;; Used by pretty-print.
+	   (load-from-path "slib/random")
+	   (load-from-path "slib/genwrite")
+	   (load-from-path "utils")
+	   (load-from-path "utils-cgen")
+	   (load-from-path "attr")
+	   (load-from-path "enum")
+	   (load-from-path "mach")
+	   (load-from-path "model")
+	   (load-from-path "types")
+	   (load-from-path "mode")
+	   (load-from-path "ifield")
+	   (load-from-path "iformat")
+	   (load-from-path "hardware")
+	   (load-from-path "operand")
+	   (load-from-path "insn")
+	   (load-from-path "minsn")
+	   (load-from-path "decode")
+	   (load-from-path "rtl")
+	   (load-from-path "rtl-traverse")
+	   (load-from-path "rtl-xform")
+	   (load-from-path "rtx-funcs")
+	   (load-from-path "rtl-c")
+	   (load-from-path "semantics")
+	   (load-from-path "sem-frags")
+	   (load-from-path "utils-gen")
+	   (load-from-path "pgmr-tools"))
 \f
 ;; A list of three numbers designating the cgen version: major minor fixlevel.
 ;; The "50" is a generic indicator that we're between 1.1 and 1.2.
-- 
2.41.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Enable the Guile compiler
  2023-08-22 18:51 [PATCH] Enable the Guile compiler Tom Tromey
@ 2023-08-22 19:04 ` Jose E. Marchesi
  2023-08-22 19:43   ` Tom Tromey
  0 siblings, 1 reply; 5+ messages in thread
From: Jose E. Marchesi @ 2023-08-22 19:04 UTC (permalink / raw)
  To: Tom Tromey; +Cc: cgen


Hi Tom.

> This patch changes cgen so that the Guile compiler can be used.
> Mainly this is done by using eval-when to ensure that files are loaded
> during the compilation process.  However, "-s" handling and
> srcdir-setting are also cleaned up, using Guile's (current-filename)
> feature.
>
> The main benefit of using the compiler is that it is much faster, once
> the scripts have been compiled.  Also it simplifies the use of cgen,
> as users don't need to remember to set an environment variable before
> invoking it.

Does this work with the current way binutils Makefiles use to invoke
cgen, or it needs an accompanying binutils patch?

> ---
>  cgen-doc.scm        | 47 +++++-------------------------
>  cgen-gas.scm        | 56 +++++++++--------------------------
>  cgen-intrinsics.scm | 47 +++++-------------------------
>  cgen-opc.scm        | 55 ++++++++---------------------------
>  cgen-sid.scm        | 51 +++++++-------------------------
>  cgen-sim.scm        | 53 +++++++--------------------------
>  cgen-stest.scm      | 57 ++++++++++--------------------------
>  cgen-testsuite.scm  | 49 +++++++------------------------
>  dev-utils.scm       |  4 +--
>  dev.scm             | 10 +++----
>  guile.scm           |  2 --
>  read.scm            | 71 +++++++++++++++++++++++----------------------
>  12 files changed, 131 insertions(+), 371 deletions(-)
>
> diff --git a/cgen-doc.scm b/cgen-doc.scm
> index 83af463..5aa751b 100644
> --- a/cgen-doc.scm
> +++ b/cgen-doc.scm
> @@ -2,18 +2,16 @@
>  ; This is invoked to build: $arch.html.
>  ; Copyright (C) 2003, 2009 Doug Evans
>  ; This file is part of CGEN.
> -;
> -; This is a standalone script, we don't load anything until we parse the
> -; -s argument (keeps reliance off of environment variables, etc.).
>  
> -; Load the various support routines.
> +(eval-when (expand load eval)
> +	   ;; Kept global so it's available to the other .scm files.
> +	   (define srcdir (dirname (current-filename)))
> +	   (add-to-load-path srcdir)
>  
> -(define (load-files srcdir)
> -  (load (string-append srcdir "/read.scm"))
> -  (load (string-append srcdir "/desc.scm"))
> -  (load (string-append srcdir "/desc-cpu.scm"))
> -  (load (string-append srcdir "/html.scm"))
> -)
> +	   (load-from-path "read")
> +	   (load-from-path "desc")
> +	   (load-from-path "desc-cpu")
> +	   (load-from-path "html"))
>  
>  (define doc-arguments
>    (list
> @@ -29,40 +27,11 @@
>     )
>  )
>  
> -; Kept global so it's available to the other .scm files.
> -(define srcdir ".")
> -
> -; Scan argv for -s srcdir.
> -; We can't process any other args until we find the cgen source dir.
> -; The result is srcdir.
> -; We assume "-s" isn't the argument to another option.  Unwise, yes.
> -; Alternatives are to require it to be the first argument or at least preceed
> -; any option with a "-s" argument, or to put knowledge of the common argument
> -; set and common argument parsing code in every top level file.
> -
> -(define (find-srcdir argv)
> -  (let loop ((argv argv))
> -    (if (null? argv)
> -	(error "`-s srcdir' not present, can't load cgen"))
> -    (if (string=? "-s" (car argv))
> -	(begin
> -	  (if (null? (cdr argv))
> -	      (error "missing srcdir arg to `-s'"))
> -	  (cadr argv))
> -	(loop (cdr argv))))	
> -)
> -
>  ; Main routine, parses options and calls generators.
>  
>  (define (cgen-doc argv)
>    (let ()
>  
> -    ; Find and set srcdir, then load all Scheme code.
> -    ; Drop the first argument, it is the script name (i.e. argv[0]).
> -    (set! srcdir (find-srcdir (cdr argv)))
> -    (set! %load-path (cons srcdir %load-path))
> -    (load-files srcdir)
> -
>      (display-argv argv)
>  
>      (cgen #:argv argv
> diff --git a/cgen-gas.scm b/cgen-gas.scm
> index 3d33e92..1e12819 100644
> --- a/cgen-gas.scm
> +++ b/cgen-gas.scm
> @@ -5,19 +5,20 @@
>  ; This is invoked to build several .s files and a "build script",
>  ; which generates the .d files and .exp DejaGNU test case.
>  
> -; Load the various support routines.
> -
> -(define (load-files srcdir)
> -  (load (string-append srcdir "/read.scm"))
> -  (load (string-append srcdir "/desc.scm"))
> -  (load (string-append srcdir "/desc-cpu.scm"))
> -  (load (string-append srcdir "/opcodes.scm"))
> -  (load (string-append srcdir "/opc-asmdis.scm"))
> -  (load (string-append srcdir "/opc-ibld.scm"))
> -  (load (string-append srcdir "/opc-itab.scm"))
> -  (load (string-append srcdir "/opc-opinst.scm"))
> -  (load (string-append srcdir "/gas-test.scm"))
> -)
> +(eval-when (expand load eval)
> +	   ;; Kept global so it's available to the other .scm files.
> +	   (define srcdir (dirname (current-filename)))
> +	   (add-to-load-path srcdir)
> +
> +	   (load-from-path "read")
> +	   (load-from-path "desc")
> +	   (load-from-path "desc-cpu")
> +	   (load-from-path "opcodes")
> +	   (load-from-path "opc-asmdis")
> +	   (load-from-path "opc-ibld")
> +	   (load-from-path "opc-itab")
> +	   (load-from-path "opc-opinst")
> +	   (load-from-path "gas-test"))
>  
>  (define gas-arguments
>    (list
> @@ -30,40 +31,11 @@
>     )
>  )
>  
> -; Kept global so it's available to the other .scm files.
> -(define srcdir ".")
> -
> -; Scan argv for -s srcdir.
> -; We can't process any other args until we find the cgen source dir.
> -; The result is srcdir.
> -; We assume "-s" isn't the argument to another option.  Unwise, yes.
> -; Alternatives are to require it to be the first argument or at least preceed
> -; any option with a "-s" argument, or to put knowledge of the common argument
> -; set and common argument parsing code in every top level file.
> -
> -(define (find-srcdir argv)
> -  (let loop ((argv argv))
> -    (if (null? argv)
> -	(error "`-s srcdir' not present, can't load cgen"))
> -    (if (string=? "-s" (car argv))
> -	(begin
> -	  (if (null? (cdr argv))
> -	      (error "missing srcdir arg to `-s'"))
> -	  (cadr argv))
> -	(loop (cdr argv))))	
> -)
> -
>  ; Main routine, parses options and calls generators.
>  
>  (define (cgen-gas argv)
>    (let ()
>  
> -    ; Find and set srcdir, then load all Scheme code.
> -    ; Drop the first argument, it is the script name (i.e. argv[0]).
> -    (set! srcdir (find-srcdir (cdr argv)))
> -    (set! %load-path (cons srcdir %load-path))
> -    (load-files srcdir)
> -
>      (display-argv argv)
>  
>      (cgen #:argv argv
> diff --git a/cgen-intrinsics.scm b/cgen-intrinsics.scm
> index 16e0338..1e5f882 100644
> --- a/cgen-intrinsics.scm
> +++ b/cgen-intrinsics.scm
> @@ -6,19 +6,15 @@
>  ;
>  ; Copyright (C) 2000, 2009 Red Hat, Inc.
>  ; This file is part of CGEN.
> -;
> -; This is a standalone script, we don't load anything until we parse the
> -; -s argument (keeps reliance off of environment variables, etc.).
> -
> -; Load the various support routines.
>  
> -(define (load-files srcdir)
> -  ; Fix up Scheme to be what we use (guile is always in flux).
> -  (primitive-load-path (string-append srcdir "/guile.scm"))
> +(eval-when (expand load eval)
> +	   ;; Kept global so it's available to the other .scm files.
> +	   (define srcdir (dirname (current-filename)))
> +	   (add-to-load-path srcdir)
>  
> -  (load (string-append srcdir "/read.scm"))
> -  (load (string-append srcdir "/intrinsics.scm"))
> -)
> +	   (load-from-path "guile")
> +	   (load-from-path "read")
> +	   (load-from-path "intrinsics"))
>  
>  (define intrinsics-isas '())
>  
> @@ -38,40 +34,11 @@
>     (list "-T" "file" "generate intrinsic-testsuite.c in <file>" #f
>  	 (lambda (arg) (file-write arg intrinsic-testsuite.c)))))
>  
> -; Kept global so it's available to the other .scm files.
> -(define srcdir ".")
> -
> -; Scan argv for -s srcdir.
> -; We can't process any other args until we find the cgen source dir.
> -; The result is srcdir.
> -; We assume "-s" isn't the argument to another option.  Unwise, yes.
> -; Alternatives are to require it to be the first argument or at least preceed
> -; any option with a "-s" argument, or to put knowledge of the common argument
> -; set and common argument parsing code in every top level file.
> -
> -(define (find-srcdir argv)
> -  (let loop ((argv argv))
> -    (if (null? argv)
> -	(error "`-s srcdir' not present, can't load cgen"))
> -    (if (string=? "-s" (car argv))
> -	(begin
> -	  (if (null? (cdr argv))
> -	      (error "missing srcdir arg to `-s'"))
> -	  (cadr argv))
> -	(loop (cdr argv))))	
> -)
> -
>  ; Main routine, parses options and calls generators.
>  
>  (define (cgen-intrinsics argv)
>    (let ()
>  
> -    ; Find and set srcdir, then load all Scheme code.
> -    ; Drop the first argument, it is the script name (i.e. argv[0]).
> -    (set! srcdir (find-srcdir (cdr argv)))
> -    (set! %load-path (cons srcdir %load-path))
> -    (load-files srcdir)
> -
>      (display-argv argv)
>  
>      (cgen #:argv argv
> diff --git a/cgen-opc.scm b/cgen-opc.scm
> index 276fdb8..cac5115 100644
> --- a/cgen-opc.scm
> +++ b/cgen-opc.scm
> @@ -3,22 +3,20 @@
>  ; $arch-opc.h, $arch-opc.c, $arch-asm.in, $arch-dis.in, and $arch-ibld.[ch].
>  ; Copyright (C) 2000, 2009 Red Hat, Inc.
>  ; This file is part of CGEN.
> -;
> -; This is a standalone script, we don't load anything until we parse the
> -; -s argument (keeps reliance off of environment variables, etc.).
>  
> -; Load the various support routines.
> +(eval-when (expand load eval)
> +	   ;; Kept global so it's available to the other .scm files.
> +	   (define srcdir (dirname (current-filename)))
> +	   (add-to-load-path srcdir)
>  
> -(define (load-files srcdir)
> -  (load (string-append srcdir "/read.scm"))
> -  (load (string-append srcdir "/desc.scm"))
> -  (load (string-append srcdir "/desc-cpu.scm"))
> -  (load (string-append srcdir "/opcodes.scm"))
> -  (load (string-append srcdir "/opc-asmdis.scm"))
> -  (load (string-append srcdir "/opc-ibld.scm"))
> -  (load (string-append srcdir "/opc-itab.scm"))
> -  (load (string-append srcdir "/opc-opinst.scm"))
> -)
> +	   (load-from-path "read")
> +	   (load-from-path "desc")
> +	   (load-from-path "desc-cpu")
> +	   (load-from-path "opcodes")
> +	   (load-from-path "opc-asmdis")
> +	   (load-from-path "opc-ibld")
> +	   (load-from-path "opc-itab")
> +	   (load-from-path "opc-opinst"))
>  
>  (define opc-arguments
>    (list
> @@ -60,40 +58,11 @@
>  ; ((-R) (file-write *arg* cgen-reloc.c))
>  ; ((-S) (file-write *arg* cgen-bfdcpu.c))
>  
> -; Kept global so it's available to the other .scm files.
> -(define srcdir ".")
> -
> -; Scan argv for -s srcdir.
> -; We can't process any other args until we find the cgen source dir.
> -; The result is srcdir.
> -; We assume "-s" isn't the argument to another option.  Unwise, yes.
> -; Alternatives are to require it to be the first argument or at least preceed
> -; any option with a "-s" argument, or to put knowledge of the common argument
> -; set and common argument parsing code in every top level file.
> -
> -(define (find-srcdir argv)
> -  (let loop ((argv argv))
> -    (if (null? argv)
> -	(error "`-s srcdir' not present, can't load cgen"))
> -    (if (string=? "-s" (car argv))
> -	(begin
> -	  (if (null? (cdr argv))
> -	      (error "missing srcdir arg to `-s'"))
> -	  (cadr argv))
> -	(loop (cdr argv))))	
> -)
> -
>  ; Main routine, parses options and calls generators.
>  
>  (define (cgen-opc argv)
>    (let ()
>  
> -    ; Find and set srcdir, then load all Scheme code.
> -    ; Drop the first argument, it is the script name (i.e. argv[0]).
> -    (set! srcdir (find-srcdir (cdr argv)))
> -    (set! %load-path (cons srcdir %load-path))
> -    (load-files srcdir)
> -
>      (display-argv argv)
>  
>      (cgen #:argv argv
> diff --git a/cgen-sid.scm b/cgen-sid.scm
> index bb74a7b..ab9e505 100644
> --- a/cgen-sid.scm
> +++ b/cgen-sid.scm
> @@ -3,20 +3,18 @@
>  ; semantics.cxx, sem-switch.cxx, model.h, model.cxx
>  ; Copyright (C) 2000, 2003, 2009 Red Hat, Inc.
>  ; This file is part of CGEN.
> -;
> -; This is a standalone script, we don't load anything until we parse the
> -; -s argument (keeps reliance off of environment variables, etc.).
>  
> -; Load the various support routines.
> +(eval-when (expand load eval)
> +	   ;; Kept global so it's available to the other .scm files.
> +	   (define srcdir (dirname (current-filename)))
> +	   (add-to-load-path srcdir)
>  
> -(define (load-files srcdir)
> -  (load (string-append srcdir "/read.scm"))
> -  (load (string-append srcdir "/utils-sim.scm"))
> -  (load (string-append srcdir "/sid.scm"))
> -  (load (string-append srcdir "/sid-cpu.scm"))
> -  (load (string-append srcdir "/sid-model.scm"))
> -  (load (string-append srcdir "/sid-decode.scm"))
> -)
> +	   (load-from-path "read")
> +	   (load-from-path "utils-sim")
> +	   (load-from-path "sid")
> +	   (load-from-path "sid-cpu")
> +	   (load-from-path "sid-model")
> +	   (load-from-path "sid-decode"))
>  
>  (define sim-arguments
>    (list
> @@ -53,40 +51,11 @@
>     )
>  )
>  
> -; Kept global so it's available to the other .scm files.
> -(define srcdir ".")
> -
> -; Scan argv for -s srcdir.
> -; We can't process any other args until we find the cgen source dir.
> -; The result is srcdir.
> -; We assume "-s" isn't the argument to another option.  Unwise, yes.
> -; Alternatives are to require it to be the first argument or at least preceed
> -; any option with a "-s" argument, or to put knowledge of the common argument
> -; set and common argument parsing code in every top level file.
> -
> -(define (find-srcdir argv)
> -  (let loop ((argv argv))
> -    (if (null? argv)
> -	(error "`-s srcdir' not present, can't load cgen"))
> -    (if (string=? "-s" (car argv))
> -	(begin
> -	  (if (null? (cdr argv))
> -	      (error "missing srcdir arg to `-s'"))
> -	  (cadr argv))
> -	(loop (cdr argv))))	
> -)
> -
>  ; Main routine, parses options and calls generators.
>  
>  (define (cgen-sim argv)
>    (let ()
>  
> -    ; Find and set srcdir, then load all Scheme code.
> -    ; Drop the first argument, it is the script name (i.e. argv[0]).
> -    (set! srcdir (find-srcdir (cdr argv)))
> -    (set! %load-path (cons srcdir %load-path))
> -    (load-files srcdir)
> -
>      (display-argv argv)
>  
>      (cgen #:argv argv
> diff --git a/cgen-sim.scm b/cgen-sim.scm
> index 2b9f962..ec7b84c 100644
> --- a/cgen-sim.scm
> +++ b/cgen-sim.scm
> @@ -6,21 +6,19 @@
>  ;
>  ; Copyright (C) 2000, 2009 Red Hat, Inc.
>  ; This file is part of CGEN.
> -;
> -; This is a standalone script, we don't load anything until we parse the
> -; -s argument (keeps reliance off of environment variables, etc.).
>  
> -; Load the various support routines.
> +(eval-when (expand load eval)
> +	   ;; Kept global so it's available to the other .scm files.
> +	   (define srcdir (dirname (current-filename)))
> +	   (add-to-load-path srcdir)
>  
> -(define (load-files srcdir)
> -  (load (string-append srcdir "/read.scm"))
> -  (load (string-append srcdir "/utils-sim.scm"))
> -  (load (string-append srcdir "/sim.scm"))
> -  (load (string-append srcdir "/sim-arch.scm"))
> -  (load (string-append srcdir "/sim-cpu.scm"))
> -  (load (string-append srcdir "/sim-model.scm"))
> -  (load (string-append srcdir "/sim-decode.scm"))
> -)
> +	   (load-from-path "read")
> +	   (load-from-path "utils-sim")
> +	   (load-from-path "sim")
> +	   (load-from-path "sim-arch")
> +	   (load-from-path "sim-cpu")
> +	   (load-from-path "sim-model")
> +	   (load-from-path "sim-decode"))
>  
>  (define sim-arguments
>    (list
> @@ -81,40 +79,11 @@
>     )
>  )
>  
> -; Kept global so it's available to the other .scm files.
> -(define srcdir ".")
> -
> -; Scan argv for -s srcdir.
> -; We can't process any other args until we find the cgen source dir.
> -; The result is srcdir.
> -; We assume "-s" isn't the argument to another option.  Unwise, yes.
> -; Alternatives are to require it to be the first argument or at least preceed
> -; any option with a "-s" argument, or to put knowledge of the common argument
> -; set and common argument parsing code in every top level file.
> -
> -(define (find-srcdir argv)
> -  (let loop ((argv argv))
> -    (if (null? argv)
> -	(error "`-s srcdir' not present, can't load cgen"))
> -    (if (string=? "-s" (car argv))
> -	(begin
> -	  (if (null? (cdr argv))
> -	      (error "missing srcdir arg to `-s'"))
> -	  (cadr argv))
> -	(loop (cdr argv))))
> -)
> -
>  ; Main routine, parses options and calls generators.
>  
>  (define (cgen-sim argv)
>    (let ()
>  
> -    ; Find and set srcdir, then load all Scheme code.
> -    ; Drop the first argument, it is the script name (i.e. argv[0]).
> -    (set! srcdir (find-srcdir (cdr argv)))
> -    (set! %load-path (cons srcdir %load-path))
> -    (load-files srcdir)
> -
>      (display-argv argv)
>  
>      (cgen #:argv argv
> diff --git a/cgen-stest.scm b/cgen-stest.scm
> index 10f62a8..7214f82 100644
> --- a/cgen-stest.scm
> +++ b/cgen-stest.scm
> @@ -6,18 +6,22 @@
>  ; generate the .d files and .exp file.
>  ; This is invoked to build: tmp-build.sh cpu-cpu.exp
>  \f
> -; Load the various support routines
> -(define (load-files srcdir)
> -  (load (string-append srcdir "/read.scm"))
> -  (load (string-append srcdir "/desc.scm"))
> -  (load (string-append srcdir "/desc-cpu.scm"))
> -  (load (string-append srcdir "/opcodes.scm"))
> -  (load (string-append srcdir "/opc-asmdis.scm"))
> -  (load (string-append srcdir "/opc-ibld.scm"))
> -  (load (string-append srcdir "/opc-itab.scm"))
> -  (load (string-append srcdir "/opc-opinst.scm"))
> -  (load (string-append srcdir "/sim-test.scm"))
> -)
> +(use-modules (ice-9 slib))
> +
> +(eval-when (expand load eval)
> +	   ;; Kept global so it's available to the other .scm files.
> +	   (define srcdir (dirname (current-filename)))
> +	   (add-to-load-path srcdir)
> +
> +	   (load-from-path "read")
> +	   (load-from-path "desc")
> +	   (load-from-path "desc-cpu")
> +	   (load-from-path "opcodes")
> +	   (load-from-path "opc-asmdis")
> +	   (load-from-path "opc-ibld")
> +	   (load-from-path "opc-itab")
> +	   (load-from-path "opc-opinst")
> +	   (load-from-path "sim-test"))
>  
>  (define stest-arguments
>    (list
> @@ -30,40 +34,11 @@
>     )
>  )
>  
> -; Kept global so it's available to the other .scm files.
> -(define srcdir ".")
> -
> -; Scan argv for -s srcdir.
> -; We can't process any other args until we find the cgen source dir.
> -; The result is srcdir.
> -; We assume "-s" isn't the argument to another option.  Unwise, yes.
> -; Alternatives are to require it to be the first argument or at least preceed
> -; any option with a "-s" argument, or to put knowledge of the common argument
> -; set and common argument parsing code in every top level file.
> -
> -(define (find-srcdir argv)
> -  (let loop ((argv argv))
> -    (if (null? argv)
> -	(error "`-s srcdir' not present, can't load cgen"))
> -    (if (string=? "-s" (car argv))
> -	(begin
> -	  (if (null? (cdr argv))
> -	      (error "missing srcdir arg to `-s'"))
> -	  (cadr argv))
> -	(loop (cdr argv))))	
> -)
> -
>  ; Main routine, parses options and calls generators.
>  
>  (define (cgen-stest argv)
>    (let ()
>  
> -    ; Find and set srcdir, then load all Scheme code.
> -    ; Drop the first argument, it is the script name (i.e. argv[0]).
> -    (set! srcdir (find-srcdir (cdr argv)))
> -    (set! %load-path (cons srcdir %load-path))
> -    (load-files srcdir)
> -
>      (display-argv argv)
>  
>      (cgen #:argv argv
> diff --git a/cgen-testsuite.scm b/cgen-testsuite.scm
> index 0c37be3..ae78cff 100644
> --- a/cgen-testsuite.scm
> +++ b/cgen-testsuite.scm
> @@ -1,18 +1,18 @@
>  ; CGEN testsuite driver.
>  ; Copyright (C) 2009 Doug Evans
>  ; This file is part of CGEN.
> -;
> -; This is a standalone script, we don't load anything until we parse the
> -; -s argument (keeps reliance off of environment variables, etc.).
>  
> -; Load the various support routines.
> +(eval-when (expand load eval)
> +	   ;; Kept global so it's available to the other .scm files.
> +	   (define srcdir (dirname (current-filename)))
> +	   (add-to-load-path srcdir)
>  
> -(define (load-files srcdir)
> -  (load (string-append srcdir "/read.scm"))
> -  (load (string-append srcdir "/desc.scm"))
> -  (load (string-append srcdir "/desc-cpu.scm"))
> -  (load (string-append srcdir "/testsuite.scm"))
> -)
> +	   (use-modules (ice-9 slib))
> +
> +	   (load-from-path "read")
> +	   (load-from-path "desc")
> +	   (load-from-path "desc-cpu")
> +	   (load-from-path "testsuite"))
>  
>  (define testsuite-arguments
>    (list
> @@ -22,40 +22,11 @@
>     )
>  )
>  
> -; Kept global so it's available to the other .scm files.
> -(define srcdir ".")
> -
> -; Scan argv for -s srcdir.
> -; We can't process any other args until we find the cgen source dir.
> -; The result is srcdir.
> -; We assume "-s" isn't the argument to another option.  Unwise, yes.
> -; Alternatives are to require it to be the first argument or at least preceed
> -; any option with a "-s" argument, or to put knowledge of the common argument
> -; set and common argument parsing code in every top level file.
> -
> -(define (find-srcdir argv)
> -  (let loop ((argv argv))
> -    (if (null? argv)
> -	(error "`-s srcdir' not present, can't load cgen"))
> -    (if (string=? "-s" (car argv))
> -	(begin
> -	  (if (null? (cdr argv))
> -	      (error "missing srcdir arg to `-s'"))
> -	  (cadr argv))
> -	(loop (cdr argv))))	
> -)
> -
>  ; Main routine, parses options and calls generators.
>  
>  (define (cgen-testsuite argv)
>    (let ()
>  
> -    ; Find and set srcdir, then load all Scheme code.
> -    ; Drop the first argument, it is the script name (i.e. argv[0]).
> -    (set! srcdir (find-srcdir (cdr argv)))
> -    (set! %load-path (cons srcdir %load-path))
> -    (load-files srcdir)
> -
>      (display-argv argv)
>  
>      (cgen #:argv argv
> diff --git a/dev-utils.scm b/dev-utils.scm
> index 89c1ee1..fe7cd7a 100644
> --- a/dev-utils.scm
> +++ b/dev-utils.scm
> @@ -6,8 +6,8 @@
>  ;; This file contains a collection of utilities for use when
>  ;; analyzing cpu files from Scheme.
>  
> -(define srcdir ".")
> -(set! %load-path (cons srcdir %load-path))
> +(define srcdir (dirname (current-filename)))
> +(add-to-load-path srcdir)
>  
>  (define (load-doc)
>    (load "read")
> diff --git a/dev.scm b/dev.scm
> index 2b31688..12be288 100644
> --- a/dev.scm
> +++ b/dev.scm
> @@ -6,11 +6,11 @@
>  ; This file is loaded in during an interactive guile session to
>  ; develop and debug CGEN.
>  
> -; First load guile.scm to coerce guile into something we've been using.
> -; Guile is always in flux.
> -(load "guile.scm")
> -
> -(load "dev-utils.scm")
> +(eval-when (expand load eval)
> +	   ;; First load guile.scm to coerce guile into something we've been using.
> +	   ;; Guile is always in flux.
> +	   (load-from-path "guile")
> +	   (load-from-path "dev-utils"))
>  
>  ; Also defined in read.scm, but we need it earlier.
>  (define APPLICATION 'UNKNOWN)
> diff --git a/guile.scm b/guile.scm
> index 5899f15..274264a 100644
> --- a/guile.scm
> +++ b/guile.scm
> @@ -6,8 +6,6 @@
>  (define (eval1 expr)
>    (eval expr (current-module)))
>  
> -(define load primitive-load-path)
> -
>  (define %stat stat)
>  
>  (debug-enable 'backtrace)
> diff --git a/read.scm b/read.scm
> index e6c2bde..392e7ba 100644
> --- a/read.scm
> +++ b/read.scm
> @@ -62,41 +62,42 @@
>  \f
>  ;; Variables representing misc. global constants.
>  
> -;; Load the base cgen files.
> -
> -(load "pmacros")
> -(load "cos")
> -(load "slib/logical")
> -(load "slib/sort")
> -;; Used to pretty-print debugging messages.
> -(load "slib/pp")
> -;; Used by pretty-print.
> -(load "slib/random")
> -(load "slib/genwrite")
> -(load "utils")
> -(load "utils-cgen")
> -(load "attr")
> -(load "enum")
> -(load "mach")
> -(load "model")
> -(load "types")
> -(load "mode")
> -(load "ifield")
> -(load "iformat")
> -(load "hardware")
> -(load "operand")
> -(load "insn")
> -(load "minsn")
> -(load "decode")
> -(load "rtl")
> -(load "rtl-traverse")
> -(load "rtl-xform")
> -(load "rtx-funcs")
> -(load "rtl-c")
> -(load "semantics")
> -(load "sem-frags")
> -(load "utils-gen")
> -(load "pgmr-tools")
> +(eval-when (expand load eval)
> +	   ;; Load the base cgen files.
> +
> +	   (load-from-path "pmacros")
> +	   (load-from-path "cos")
> +	   (load-from-path "slib/logical")
> +	   (load-from-path "slib/sort")
> +	   ;; Used to pretty-print debugging messages.
> +	   (load-from-path "slib/pp")
> +	   ;; Used by pretty-print.
> +	   (load-from-path "slib/random")
> +	   (load-from-path "slib/genwrite")
> +	   (load-from-path "utils")
> +	   (load-from-path "utils-cgen")
> +	   (load-from-path "attr")
> +	   (load-from-path "enum")
> +	   (load-from-path "mach")
> +	   (load-from-path "model")
> +	   (load-from-path "types")
> +	   (load-from-path "mode")
> +	   (load-from-path "ifield")
> +	   (load-from-path "iformat")
> +	   (load-from-path "hardware")
> +	   (load-from-path "operand")
> +	   (load-from-path "insn")
> +	   (load-from-path "minsn")
> +	   (load-from-path "decode")
> +	   (load-from-path "rtl")
> +	   (load-from-path "rtl-traverse")
> +	   (load-from-path "rtl-xform")
> +	   (load-from-path "rtx-funcs")
> +	   (load-from-path "rtl-c")
> +	   (load-from-path "semantics")
> +	   (load-from-path "sem-frags")
> +	   (load-from-path "utils-gen")
> +	   (load-from-path "pgmr-tools"))
>  \f
>  ;; A list of three numbers designating the cgen version: major minor fixlevel.
>  ;; The "50" is a generic indicator that we're between 1.1 and 1.2.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Enable the Guile compiler
  2023-08-22 19:04 ` Jose E. Marchesi
@ 2023-08-22 19:43   ` Tom Tromey
  2023-08-22 19:54     ` Jose E. Marchesi
  0 siblings, 1 reply; 5+ messages in thread
From: Tom Tromey @ 2023-08-22 19:43 UTC (permalink / raw)
  To: Jose E. Marchesi; +Cc: Tom Tromey, cgen

Jose> Does this work with the current way binutils Makefiles use to invoke
Jose> cgen, or it needs an accompanying binutils patch?

Yes, though I have a patch to somewhat simplify that as well.

This patch also seems to make things work fine with Guile 2.2.

Worth noting that the compiler speeds things up quite a bit, and Guile
3.0 seems to be even faster than 2.2.  So, it's worth using that if you
can.

Tom

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Enable the Guile compiler
  2023-08-22 19:43   ` Tom Tromey
@ 2023-08-22 19:54     ` Jose E. Marchesi
  2023-08-22 20:05       ` Tom Tromey
  0 siblings, 1 reply; 5+ messages in thread
From: Jose E. Marchesi @ 2023-08-22 19:54 UTC (permalink / raw)
  To: Tom Tromey; +Cc: cgen


> Jose> Does this work with the current way binutils Makefiles use to invoke
> Jose> cgen, or it needs an accompanying binutils patch?
>
> Yes, though I have a patch to somewhat simplify that as well.
>
> This patch also seems to make things work fine with Guile 2.2.
>
> Worth noting that the compiler speeds things up quite a bit, and Guile
> 3.0 seems to be even faster than 2.2.  So, it's worth using that if you
> can.

Awesome :)
OK, thanks!

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Enable the Guile compiler
  2023-08-22 19:54     ` Jose E. Marchesi
@ 2023-08-22 20:05       ` Tom Tromey
  0 siblings, 0 replies; 5+ messages in thread
From: Tom Tromey @ 2023-08-22 20:05 UTC (permalink / raw)
  To: Jose E. Marchesi; +Cc: Tom Tromey, cgen

>> Worth noting that the compiler speeds things up quite a bit, and Guile
>> 3.0 seems to be even faster than 2.2.  So, it's worth using that if you
>> can.

Jose> Awesome :)
Jose> OK, thanks!

Thanks.  I'm going to push it.

FTR I had actually tried guile2.0 -- for whatever reason that is the
default on this machine.  I tried 2.2 just now, though, and that also
works.

Tom

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-08-22 20:05 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-22 18:51 [PATCH] Enable the Guile compiler Tom Tromey
2023-08-22 19:04 ` Jose E. Marchesi
2023-08-22 19:43   ` Tom Tromey
2023-08-22 19:54     ` Jose E. Marchesi
2023-08-22 20:05       ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).