From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16370 invoked by alias); 12 Jan 2007 21:56:14 -0000 Received: (qmail 16358 invoked by uid 22791); 12 Jan 2007 21:56:12 -0000 X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (66.187.233.31) by sourceware.org (qpsmtpd/0.31) with ESMTP; Fri, 12 Jan 2007 21:56:02 +0000 Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by mx1.redhat.com (8.12.11.20060308/8.12.11) with ESMTP id l0CLu0Y7025120 for ; Fri, 12 Jan 2007 16:56:00 -0500 Received: from potter.sfbay.redhat.com (potter.sfbay.redhat.com [172.16.27.15]) by int-mx1.corp.redhat.com (8.13.1/8.13.1) with ESMTP id l0CLtxHT023363 for ; Fri, 12 Jan 2007 16:55:59 -0500 Received: from [10.11.14.170] (vpn-14-170.rdu.redhat.com [10.11.14.170]) by potter.sfbay.redhat.com (8.12.11.20060308/8.12.11) with ESMTP id l0CLtuh0012851 for ; Fri, 12 Jan 2007 16:55:57 -0500 Message-ID: <45A803EC.5090006@redhat.com> Date: Fri, 12 Jan 2007 21:56:00 -0000 From: Dave Brolley User-Agent: Mozilla Thunderbird 1.0.2 (X11/20050317) MIME-Version: 1.0 To: cgen@sources.redhat.com Subject: [patch][rfc] New CGEN Attribute Type: string Content-Type: multipart/mixed; boundary="------------080502010606040607060803" X-IsSubscribed: yes Mailing-List: contact cgen-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cgen-owner@sourceware.org X-SW-Source: 2007-q1/txt/msg00001.txt.bz2 This is a multi-part message in MIME format. --------------080502010606040607060803 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-length: 313 Hi, I would like to commit the attached patch which adds a new attribute type: string. This is used by a new CGEN application for generating intrinsic functions which will be submitted along with the Toshiba MeP port soon, but is general enough to be considered separately. Seeking approval to commit. Dave --------------080502010606040607060803 Content-Type: text/plain; name="cgen.string-attr.ChangeLog" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="cgen.string-attr.ChangeLog" Content-length: 716 2007-01-12 Dave Brolley * Contribute the following changes: 2005-04-05 Richard Sandiford * attr.scm (): New attribute class. (attr-kind): Handle . (parse-simple-attribute): New function. ( 'parse-value): Use parse-simple-attribute. ( 'parse-value): Likewise. ( 'parse-value): Likewise. ( 'parse-value): Likewise. ( 'parse-value): New function. (-attr-parse): Handle . (-attr-read): Likewise. ( 'gen-value-for-defn-raw): New function. ( 'gen-value-for-defn): New function. --------------080502010606040607060803 Content-Type: text/plain; name="cgen.string-attr.patch.txt" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="cgen.string-attr.patch.txt" Content-length: 7902 Index: cgen/attr.scm =================================================================== RCS file: /cvs/src/src/cgen/attr.scm,v retrieving revision 1.4 diff -c -p -r1.4 attr.scm *** cgen/attr.scm 28 Oct 2005 19:30:02 -0000 1.4 --- cgen/attr.scm 11 Jan 2007 19:09:39 -0000 *************** *** 15,20 **** --- 15,21 ---- ; Boolean attributes are specified as (NAME #t) or (NAME #f), ; but for convenience ATTR and !ATTR are also supported. ; integer/enum attrs are specified as (ATTR value). + ; string attrs are specified as (ATTR value). ; Bitset attrs are specified as (ATTR val1,val2,val3). ; In all cases the value needn't be constant, and can be an expression, ; though expressions are currently only supported for META-attributes *************** *** 90,95 **** --- 91,105 ---- nil) ) + ; VALUES is ignored for string-attribute. + + (define + (class-make ' + '() + '(default values) + nil) + ) + ; For bitset attributes VALUES is a list of ; (symbol bit-number-or-#f attr-list comment-or-#f), ; one for each bit. *************** *** 143,153 **** (define (bitset-attr? x) (class-instance? x)) ; Return a symbol indicating the kind of attribute ATTR is. ! ; The result is one of boolean,integer,enum,bitset. (define (attr-kind attr) (case (object-class-name attr) (() 'boolean) (() 'integer) (() 'enum) (() 'bitset) --- 153,164 ---- (define (bitset-attr? x) (class-instance? x)) ; Return a symbol indicating the kind of attribute ATTR is. ! ; The result is one of boolean,integer,enum,bitset or string. (define (attr-kind attr) (case (object-class-name attr) (() 'boolean) + (() 'string) (() 'integer) (() 'enum) (() 'bitset) *************** *** 184,201 **** (define (enum-attr-make name value) (cons name value)) ; A boolean attribute's value is either #t or #f. (method-make! 'parse-value ! (lambda (self errtxt val) ! (if (and (not (null? val)) ! (boolean? (car val))) ! (cons (obj:name self) (car val)) ! (parse-error errtxt "boolean attribute not one of #f/#t" ! (cons (obj:name self) val)))) ) ; A bitset attribute's value is a comma separated list of elements. ; We don't validate the values. In the case of the MACH attribute, ; there's no current mechanism to create it after all define-mach's have --- 195,220 ---- (define (enum-attr-make name value) (cons name value)) + (define (parse-simple-attribute right-type? message) + (lambda (self errtxt val) + (if (and (not (null? val)) + (right-type? (car val)) + (null? (cdr val))) + (cons (obj:name self) (car val)) + (parse-error errtxt message (cons (obj:name self) val)))) + ) + ; A boolean attribute's value is either #t or #f. (method-make! 'parse-value ! (parse-simple-attribute boolean? "boolean attribute not one of #f/#t") ) + (method-make! + 'parse-value + (parse-simple-attribute string? "invalid argument to string attribute")) + ; A bitset attribute's value is a comma separated list of elements. ; We don't validate the values. In the case of the MACH attribute, ; there's no current mechanism to create it after all define-mach's have *************** *** 208,221 **** (method-make! 'parse-value ! (lambda (self errtxt val) ! (if (and (not (null? val)) ! (or (symbol? (car val)) ! (string? (car val))) ! (null? (cdr val))) ! (cons (obj:name self) (car val)) ! (parse-error errtxt "improper bitset attribute" ! (cons (obj:name self) val)))) ) ; An integer attribute's value is a number --- 227,234 ---- (method-make! 'parse-value ! (parse-simple-attribute (lambda (x) (or (symbol? x) (string? x))) ! "improper bitset attribute") ) ; An integer attribute's value is a number *************** *** 223,248 **** (method-make! 'parse-value ! (lambda (self errtxt val) ! (if (and (not (null? val)) ! (or (number? (car val)) (symbol? (car val))) ! (null? (cdr val))) ! (cons (obj:name self) (car val)) ! (parse-error errtxt "improper integer attribute" ! (cons (obj:name self) val)))) ) ; An enum attribute's value is a symbol representing that value. (method-make! 'parse-value ! (lambda (self errtxt val) ! (if (and (not (null? val)) ! (or (symbol? (car val)) (string? (car val))) ! (null? (cdr val))) ! (cons (obj:name self) (car val)) ! (parse-error errtxt "improper enum attribute" ! (cons (obj:name self) val)))) ) ; Parse a boolean attribute's value definition. --- 236,251 ---- (method-make! 'parse-value ! (parse-simple-attribute (lambda (x) (or (number? x) (symbol? x))) ! "improper integer attribute") ) ; An enum attribute's value is a symbol representing that value. (method-make! 'parse-value ! (parse-simple-attribute (lambda (x) (or (symbol? x) (string? x))) ! "improper enum attribute") ) ; Parse a boolean attribute's value definition. *************** *** 255,260 **** --- 258,271 ---- (parse-error errtxt "boolean value list must be (#f #t)" values))) ) + ; Ignore values for strings. We can't do any error checking since + ; the default value is (#f #t). + + (method-make! + 'parse-value-def + (lambda (self errtxt values) #f) + ) + ; Parse a bitset attribute's value definition. ; FIXME: treated as enum? *************** *** 297,303 **** ; description in the .cpu file. ; All arguments are in raw (non-evaluated) form. ; TYPE-CLASS is the class of the object to create. ! ; i.e. one of <{boolean,bitset,integer,enum}-attribute>. ; If DEFAULT is #f, use the first value. ; ??? Allowable values for integer attributes is wip. --- 308,314 ---- ; description in the .cpu file. ; All arguments are in raw (non-evaluated) form. ; TYPE-CLASS is the class of the object to create. ! ; i.e. one of <{boolean,bitset,integer,enum,string}-attribute>. ; If DEFAULT is #f, use the first value. ; ??? Allowable values for integer attributes is wip. *************** *** 318,323 **** --- 329,340 ---- (not (rtx? default))) (parse-error errtxt "invalid default" default)) (elm-xset! result 'default default)) + (() + (let ((default (or default ""))) + (if (and (not (string? default)) + (not (rtx? default))) + (parse-error errtxt "invalid default" default)) + (elm-xset! result 'default default))) (() (let ((default (if default default (if (null? values) 0 (car values))))) (if (and (not (integer? default)) *************** *** 359,364 **** --- 376,382 ---- (case elm-name ((type) (set! type-class (case (cadr arg) ((boolean) ) + ((string) ) ((bitset) ) ((integer) ) ((enum) ) *************** *** 1038,1043 **** --- 1056,1075 ---- ", 0 } }") ) ) + + ;; Doesn't handle escape sequences. + (method-make! + 'gen-value-for-defn-raw + (lambda (self value) + (string-append "\"" value "\"")) + ) + + (method-make! + 'gen-value-for-defn + (lambda (self value) + (send self 'gen-value-for-defn-raw value)) + ) + ; Called before loading a .cpu file to initialize. --------------080502010606040607060803--