This is the mail archive of the cgen@sourceware.org mailing list for the CGEN project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] Add some error checking to /rtx-canon-operands


Hi.

I added some new rtx functions and while testing them noticed
the rtl canonicalizer was creating incorrect modes (from intentionally
bad rtl) but the error wasn't being caught.
This patch adds the necessary checking.
In the process of testing that I found I needed `if' to be able to
return a symbol (for attribute calculations).

Checked in.

2010-01-20  Doug Evans  <dje@sebabeach.org>

	* rtl-traverse.scm (/rtx-canon-anycexprmode): New function.
	(/rtx-make-canon-table): Add entry for ANYCEXPRMODE.
	(/rtx-canon-operands): Print expr-mode if /rtx-canon-debug?
	Do final error check on mode assigned to expression.
	(/rtx-make-traverser-table): Add entry for ANYCEXPRMODE.
	* rtl-xform.scm (/rtx-trim-args): Handle ANYCEXPRMODE.
	* rtl.scm (/rtx-valid-mode-types): Add ANYCEXPRMODE.
	* rtx-funcs.scm (c-code, c-call, c-raw-call): Use ANYCEXPRMODE.
	(if, cond, case): Use ANYEXPRMODE.

Index: rtl-traverse.scm
===================================================================
RCS file: /cvs/src/src/cgen/rtl-traverse.scm,v
retrieving revision 1.20
diff -u -p -r1.20 rtl-traverse.scm
--- rtl-traverse.scm	14 Nov 2009 20:16:34 -0000	1.20
+++ rtl-traverse.scm	21 Jan 2010 06:32:11 -0000
@@ -1,5 +1,5 @@
 ;; RTL traversing support.
-;; Copyright (C) 2000, 2001, 2009 Red Hat, Inc.
+;; Copyright (C) 2000, 2001, 2009, 2010 Red Hat, Inc.
 ;; This file is part of CGEN.
 ;; See file COPYING.CGEN for details.
 
@@ -314,6 +314,16 @@
   (let ((val-obj (mode:lookup val)))
     (if (and val-obj
 	     (or (memq (mode:class val-obj) '(INT UINT FLOAT))
+		 (memq val '(DFLT PTR VOID SYM))))
+	#f
+	(/rtx-canon-error cstate "expecting a numeric mode, PTR, VOID, or SYM"
+			  val parent-expr op-num)))
+)
+
+(define (/rtx-canon-anycexprmode val mode parent-expr op-num cstate env depth)
+  (let ((val-obj (mode:lookup val)))
+    (if (and val-obj
+	     (or (memq (mode:class val-obj) '(INT UINT FLOAT))
 		 (memq val '(DFLT PTR VOID))))
 	#f
 	(/rtx-canon-error cstate "expecting a numeric mode, PTR, or VOID"
@@ -552,6 +562,7 @@
 	  (cons 'ANYFLOATMODE /rtx-canon-anyfloatmode)
 	  (cons 'ANYNUMMODE /rtx-canon-anynummode)
 	  (cons 'ANYEXPRMODE /rtx-canon-anyexprmode)
+	  (cons 'ANYCEXPRMODE /rtx-canon-anycexprmode)
 	  (cons 'EXPLNUMMODE /rtx-canon-explnummode)
 	  (cons 'VOIDORNUMMODE /rtx-canon-voidornummode)
 	  (cons 'VOIDMODE /rtx-canon-voidmode)
@@ -611,6 +622,14 @@
 					 (symbol->string (cadr args)))
 			  this-expr parent-expr #f))
 
+    (if /rtx-canon-debug?
+	(begin
+	  (display (spaces (* 4 depth)))
+	  (display "expr-mode ")
+	  (display expr-mode)
+	  (newline)
+	  (force-output)))
+
     (let loop ((env env)
 	       (op-num 0)
 	       (arg-types all-arg-types)
@@ -655,16 +674,24 @@
 				      (else
 				       (vector-ref operands arg-num))))
 				   (expr-to-match-obj (rtx-lookup (rtx-name expr-to-match)))
-				   (result-mode (or (rtx-result-mode expr-to-match-obj)
-						    (let ((expr-mode (rtx-mode expr-to-match)))
-						      (if (eq? expr-mode 'DFLT)
-							  (if (eq? requested-mode-name 'DFLT)
-							      (/rtx-canon-error cstate
-										"unable to determine mode of expression from arguments, please specify a mode"
-										this-expr parent-expr #f)
-							      requested-mode-name)
-							  expr-mode)))))
-			      (vector-set! operands 1 result-mode)))))
+				   (new-expr-mode (or (rtx-result-mode expr-to-match-obj)
+						      (let ((expr-mode (rtx-mode expr-to-match)))
+							(if (eq? expr-mode 'DFLT)
+							    (if (eq? requested-mode-name 'DFLT)
+								(/rtx-canon-error cstate
+										  "unable to determine mode of expression from arguments, please specify a mode"
+										  this-expr parent-expr #f)
+								requested-mode-name)
+							    expr-mode)))))
+			      ;; Verify the mode to be recorded matches the spec.
+			      (let* ((expr-mode-spec (cadr all-arg-types))
+				     (canoner (cdr expr-mode-spec)))
+				;; Ignore the result of the canoner, we just
+				;; want the error checking.
+				(canoner new-expr-mode #f this-expr 1
+					 cstate env depth))
+			      (vector-set! operands 1 new-expr-mode)))))
+
 		     ;; The expression's mode might still be DFLT.
 		     ;; If it is, fetch the mode of the MATCHEXPR operand,
 		     ;; or MATCHSEQ operand, or containing expression.
@@ -1587,6 +1614,7 @@
 	  (cons 'ANYFLOATMODE /rtx-traverse-normal-operand)
 	  (cons 'ANYNUMMODE /rtx-traverse-normal-operand)
 	  (cons 'ANYEXPRMODE /rtx-traverse-normal-operand)
+	  (cons 'ANYCEXPRMODE /rtx-traverse-normal-operand)
 	  (cons 'EXPLNUMMODE /rtx-traverse-normal-operand)
 	  (cons 'VOIDORNUMMODE /rtx-traverse-normal-operand)
 	  (cons 'VOIDMODE /rtx-traverse-normal-operand)
Index: rtl-xform.scm
===================================================================
RCS file: /cvs/src/src/cgen/rtl-xform.scm,v
retrieving revision 1.11
diff -u -p -r1.11 rtl-xform.scm
--- rtl-xform.scm	12 Nov 2009 16:05:29 -0000	1.11
+++ rtl-xform.scm	21 Jan 2010 06:32:11 -0000
@@ -1,6 +1,6 @@
 ;; Various RTL transformations.
 ;;
-;; Copyright (C) 2000, 2009 Red Hat, Inc.
+;; Copyright (C) 2000, 2009, 2010 Red Hat, Inc.
 ;; This file is part of CGEN.
 ;; See file COPYING.CGEN for details.
 ;;
@@ -422,8 +422,8 @@
 	      ((OPTIONS)
 	       (assert #f)) ; shouldn't get here
 
-	      ((ANYINTMODE ANYFLOATMODE ANYNUMMODE ANYEXPRMODE EXPLNUMMODE
-		VOIDORNUMMODE VOIDMODE BIMODE INTMODE
+	      ((ANYINTMODE ANYFLOATMODE ANYNUMMODE ANYEXPRMODE ANYCEXPRMODE
+		EXPLNUMMODE VOIDORNUMMODE VOIDMODE BIMODE INTMODE
 		SYMMODE INSNMODE MACHMODE)
 	       #f) ; leave arg untouched
 
Index: rtl.scm
===================================================================
RCS file: /cvs/src/src/cgen/rtl.scm,v
retrieving revision 1.28
diff -u -p -r1.28 rtl.scm
--- rtl.scm	23 Nov 2009 09:03:01 -0000	1.28
+++ rtl.scm	21 Jan 2010 06:32:11 -0000
@@ -1,5 +1,5 @@
 ; Basic RTL support.
-; Copyright (C) 2000, 2001, 2009 Red Hat, Inc.
+; Copyright (C) 2000, 2001, 2009, 2010 Red Hat, Inc.
 ; This file is part of CGEN.
 ; See file COPYING.CGEN for details.
 
@@ -50,7 +50,8 @@
 		; ANYINTMODE - any integer mode
 		; ANYFLOATMODE - any floating point mode
 		; ANYNUMMODE - any numeric mode
-		; ANYEXPRMODE - VOID, PTR, or any numeric mode
+		; ANYEXPRMODE - VOID, PTR, SYM, or any numeric mode
+		; ANYCEXPRMODE - VOID, PTR, or any numeric mode
 		; EXPLNUMMODE - explicit numeric mode, can't be DFLT or VOID
 		; VOIDORNUMMODE - VOID or any numeric mode
 		; VOIDMODE - must be `VOID'
@@ -154,8 +155,8 @@
 
 (define /rtx-valid-mode-types
   '(
-    ANYINTMODE ANYFLOATMODE ANYNUMMODE ANYEXPRMODE EXPLNUMMODE VOIDORNUMMODE
-    VOIDMODE BIMODE INTMODE SYMMODE INSNMODE MACHMODE
+    ANYINTMODE ANYFLOATMODE ANYNUMMODE ANYEXPRMODE ANYCEXPRMODE EXPLNUMMODE
+    VOIDORNUMMODE VOIDMODE BIMODE INTMODE SYMMODE INSNMODE MACHMODE
    )
 )
 
Index: rtx-funcs.scm
===================================================================
RCS file: /cvs/src/src/cgen/rtx-funcs.scm,v
retrieving revision 1.17
diff -u -p -r1.17 rtx-funcs.scm
--- rtx-funcs.scm	5 Nov 2009 16:55:33 -0000	1.17
+++ rtx-funcs.scm	21 Jan 2010 06:32:11 -0000
@@ -1,5 +1,5 @@
 ; Standard RTL functions.
-; Copyright (C) 2000, 2009 Red Hat, Inc.
+; Copyright (C) 2000, 2009, 2010 Red Hat, Inc.
 ; This file is part of CGEN.
 ; See file COPYING.CGEN for details.
 
@@ -504,7 +504,7 @@
 
 (drn (c-code &options &mode text)
      #f
-     (OPTIONS ANYEXPRMODE STRING) (NA NA NA)
+     (OPTIONS ANYCEXPRMODE STRING) (NA NA NA)
      UNSPEC
      #f
 )
@@ -521,7 +521,7 @@
 
 (drn (c-call &options &mode name . args)
      #f
-     (OPTIONS ANYEXPRMODE STRING . RTX) (NA NA NA . ANY)
+     (OPTIONS ANYCEXPRMODE STRING . RTX) (NA NA NA . ANY)
      UNSPEC
      #f
 )
@@ -530,7 +530,7 @@
 
 (drn (c-raw-call &options &mode name . args)
      #f
-     (OPTIONS ANYEXPRMODE STRING . RTX) (NA NA NA . ANY)
+     (OPTIONS ANYCEXPRMODE STRING . RTX) (NA NA NA . ANY)
      UNSPEC
      #f
 )
@@ -1083,7 +1102,7 @@
 (drn (if &options &mode cond then . else)
      #f
      ;; ??? It would be cleaner if TESTRTX had to have BI mode.
-     (OPTIONS VOIDORNUMMODE TESTRTX RTX . RTX) (NA NA ANYINT MATCHEXPR . MATCH3)
+     (OPTIONS ANYEXPRMODE TESTRTX RTX . RTX) (NA NA ANYINT MATCHEXPR . MATCH3)
      IF
      (apply e-if (append! (list *estate* mode cond then) else))
 )
@@ -1095,7 +1114,7 @@
 ; the same mode as the result.
 (drsn (cond &options &mode . cond-code-list)
      #f
-      (OPTIONS VOIDORNUMMODE . CONDRTX) (NA NA . MATCHEXPR)
+      (OPTIONS ANYEXPRMODE . CONDRTX) (NA NA . MATCHEXPR)
       COND
       #f
 )
@@ -1105,7 +1124,7 @@
 ; the same mode as the result.
 (drn (case &options &mode test . case-list)
      #f
-     (OPTIONS VOIDORNUMMODE RTX . CASERTX) (NA NA ANY . MATCHEXPR)
+     (OPTIONS ANYEXPRMODE RTX . CASERTX) (NA NA ANY . MATCHEXPR)
      COND
      #f
 )


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]