OSDN Git Service

* insn.scm (/parse-insn-format): Watch for duplicate ifields.
authordevans <devans>
Mon, 23 Nov 2009 03:28:31 +0000 (03:28 +0000)
committerdevans <devans>
Mon, 23 Nov 2009 03:28:31 +0000 (03:28 +0000)
* read.scm (parse-error-continuable): New function.
(define /continuable-error-found?): New variable.
(/init-reader!): Initialize it.
(/finish-reader!): New function.
(cpu-load): Call it.
* utils-cgen.scm (obj-list-nub): New function.

cgen/ChangeLog
cgen/insn.scm
cgen/read.scm
cgen/utils-cgen.scm

index f3e5d84..4cd437d 100644 (file)
@@ -1,5 +1,13 @@
 2009-11-22  Doug Evans  <dje@sebabeach.org>
 
+       * insn.scm (/parse-insn-format): Watch for duplicate ifields.
+       * read.scm (parse-error-continuable): New function.
+       (define /continuable-error-found?): New variable.
+       (/init-reader!): Initialize it.
+       (/finish-reader!): New function.
+       (cpu-load): Call it.
+       * utils-cgen.scm (obj-list-nub): New function.
+
        * mach.scm (<derived-arch-data>): New member large-insn-word?.
        (/adata-set-derived!): Set it.
        (adata-large-insn-word?): New function.
index 0281401..1cc078a 100644 (file)
 ;
 ; An insn format field is a list of ifields that make up the instruction.
 ; All bits must be specified, including reserved bits
-; [at present no checking is made of this, but the rule still holds].
+; [at present little checking is made of this, but the rule still holds].
 ;
 ; A normal entry begins with `+' and then consist of the following:
 ; - operand name
                                     (not (ifld-beyond-base? f)))
                                   (ifields-simple-ifields parsed-ifld-list)))
                 (base-iflds-length (apply + (map ifld-length base-iflds))))
+
            ;; FIXME: We don't use parse-error here because some existing ports
            ;; have problems, and I don't have time to fix them right now.
            (cond ((< base-iflds-length base-len)
                                   (pretty-print-iflds parsed-ifld-list)
                                   "\nprovided spec")
                                  ifld-list)))
+
+           ;; Detect duplicate ifields.
+           (if (!= (length base-iflds)
+                   (length (obj-list-nub base-iflds)))
+               (parse-error-continuable context
+                                        "duplicate ifields present"
+                                        ifld-list))
            )
          ))
 
index fc87642..0695fd4 100644 (file)
                        ":")))
 )
 
-;;; Subroutine of parse-error, parse-warning to simplify them.
-;;; Flag an error or a warning.
-;;; EMITTER is a function of one argument, the message to print.
+;; Subroutine of parse-error, parse-warning to simplify them.
+;; Flag an error or a warning.
+;; EMITTER is a function of one argument, the message to print.
 
 (define (/parse-diagnostic emitter context message expr maybe-help-text)
   (if (not context)
          ""))))
 )
 
-;;; Signal a parse error while reading a .cpu file.
-;;; If CONTEXT is #f, use a default context of the current reader location
-;;; and an empty prefix.
-;;; If MAYBE-HELP-TEXT is specified, elide the last trailing \n.
-;;; Multiple lines of help text need embedded newlines, and should be no longer
-;;; than 79 characters.
+;; Signal a parse error while reading a .cpu file.
+;; Processing stops immediately.
+;; If CONTEXT is #f, use a default context of the current reader location
+;; and an empty prefix.
+;; If MAYBE-HELP-TEXT is specified, elide the last trailing \n.
+;; Multiple lines of help text need embedded newlines, and should be no longer
+;; than 79 characters.
 
 (define (parse-error context errmsg expr . maybe-help-text)
   (/parse-diagnostic error
                     (if (null? maybe-help-text) "" (car maybe-help-text)))
 )
 
-;;; Signal a parse warning while reading a .cpu file.
-;;; If CONTEXT is #f, use a default context of the current reader location
-;;; and an empty prefix.
-;;; If MAYBE-HELP-TEXT is specified, elide the last trailing \n.
-;;; Multiple lines of help text need embedded newlines, and should be no longer
-;;; than 79 characters.
+;; Same as parse-error, but continue processing.
+
+(define (parse-error-continuable context errmsg expr . maybe-help-text)
+  (set! /continuable-error-found? #t)
+  (/parse-diagnostic (lambda (text) (message "Error: " text "\n"))
+                    context
+                    errmsg
+                    expr
+                    (if (null? maybe-help-text) #f (car maybe-help-text)))
+)
+
+;; Signal a parse warning while reading a .cpu file.
+;; If CONTEXT is #f, use a default context of the current reader location
+;; and an empty prefix.
+;; If MAYBE-HELP-TEXT is specified, elide the last trailing \n.
+;; Multiple lines of help text need embedded newlines, and should be no longer
+;; than 79 characters.
 
 (define (parse-warning context errmsg expr . maybe-help-text)
   (/parse-diagnostic (lambda (text) (message "Warning: " text "\n"))
 \f
 ; .cpu file loader support
 
+;; #t if an error was found (but processing continued)
+(define /continuable-error-found? #f)
+
 ;; Initialize a new <reader> object.
 ;; This doesn't add cgen-specific commands, leaving each element (ifield,
 ;; hardware, etc.) to add their own.
 
   (set! /CGEN-RTL-VERSION /default-rtl-version)
 
+  (set! /continuable-error-found? #f)
+
   (reader-add-command! 'define-rtl-version
                       "Specify the RTL version being used.\n"
                       nil '(major minor) /cmd-define-rtl-version)
@@ -871,6 +888,14 @@ Define a preprocessor-style macro.
   *UNSPECIFIED*
 )
 
+;; Called at the end of .cpu file loading.
+
+(define (/finish-reader! file)
+  (if /continuable-error-found?
+      (error (string-append "Error loading " file)))
+  *UNSPECIFIED*
+)
+
 ; Prepare to parse a .cpu file.
 ; This initializes the application independent tables.
 ; KEEP-MACH specifies what machs to keep.
@@ -1035,8 +1060,9 @@ Define a preprocessor-style macro.
   (logit 1 "diags:   " diagnostic-options "\n")
   (set! arch-path (dirname file))
   (reader-read-file! file)
-  (logit 2 "Processing cpu description " file " ...\n")
   (/finish-parse-cpu!)
+  (/finish-reader! file)
+  (logit 1 "Processing cpu description " file " ...\n")
   (app-finisher!)
   (/global-error-checks)
   (analyzer!)
index 9ced1b2..6851125 100644 (file)
      " } }"
      ))
 )
+
 ; Return a boolean indicating if ATLIST indicates a CTI insn.
 
 (define (atlist-cti? atlist)
    ";} while (0)\n")
 )
 \f
-; Misc. object utilities.
+;; Misc. object utilities.
+
+;; Return the nub of a list of objects.
+
+(define (obj-list-nub obj-list)
+  (nub obj-list obj:name)
+)
 
-; Sort a list of objects with get-name methods alphabetically.
+;; Sort a list of objects with get-name methods alphabetically.
 
 (define (alpha-sort-obj-list l)
   (sort l