OSDN Git Service

2007-02-05 Dave Brolley <brolley@redhat.com>
authorbrolley <brolley>
Mon, 5 Feb 2007 19:43:30 +0000 (19:43 +0000)
committerbrolley <brolley>
Mon, 5 Feb 2007 19:43:30 +0000 (19:43 +0000)
        * opc-asmdis.scm (-gen-init-asm-fn): Include CGEN_ASM_INIT_HOOK
        in the generated code for @arch@_cgen_init_asm if it is defined.

        * Contribute the following changes:
        2005-04-05  Richard Sandiford  <rsandifo@redhat.com>

        * attr.scm (<string-attribute>): New attribute class.
        (attr-kind): Handle <string-attribute>.
        (parse-simple-attribute): New function.
        (<boolean-attribute> 'parse-value): Use parse-simple-attribute.
        (<bitset-attribute> 'parse-value): Likewise.
        (<boolean-attribute> 'parse-value): Likewise.
        (<enum-attribute> 'parse-value): Likewise.
        (<string-attribute> 'parse-value): New function.
        (-attr-parse): Handle <string-attribute>.
        (-attr-read): Likewise.
        (<string-attribute> 'gen-value-for-defn-raw): New function.
        (<string-attribute> 'gen-value-for-defn): New function.

cgen/ChangeLog
cgen/attr.scm
cgen/opc-asmdis.scm

index 5f4b8da..27a6ef6 100644 (file)
@@ -1,3 +1,24 @@
+2007-02-05  Dave Brolley  <brolley@redhat.com>
+
+       * opc-asmdis.scm (-gen-init-asm-fn): Include CGEN_ASM_INIT_HOOK
+       in the generated code for @arch@_cgen_init_asm if it is defined.
+
+       * Contribute the following changes:
+       2005-04-05  Richard Sandiford  <rsandifo@redhat.com>
+
+       * attr.scm (<string-attribute>): New attribute class.
+       (attr-kind): Handle <string-attribute>.
+       (parse-simple-attribute): New function.
+       (<boolean-attribute> 'parse-value): Use parse-simple-attribute.
+       (<bitset-attribute> 'parse-value): Likewise.
+       (<boolean-attribute> 'parse-value): Likewise.
+       (<enum-attribute> 'parse-value): Likewise.
+       (<string-attribute> 'parse-value): New function.
+       (-attr-parse): Handle <string-attribute>.
+       (-attr-read): Likewise.
+       (<string-attribute> 'gen-value-for-defn-raw): New function.
+       (<string-attribute> 'gen-value-for-defn): New function.
+
 2006-11-07  Dave Brolley  <brolley@redhat.com>
 
        * sid-model.scm (gen-model-unit-fn-decl): Use symbol->string where
index c013bf3..7b7e79c 100644 (file)
@@ -1,5 +1,5 @@
 ; Attributes.
-; Copyright (C) 2000, 2003 Red Hat, Inc.
+; Copyright (C) 2000, 2003, 2005 Red Hat, Inc.
 ; This file is part of CGEN.
 ; See file COPYING.CGEN for details.
 
@@ -15,6 +15,7 @@
 ; 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
              nil)
 )
 
+; VALUES is ignored for string-attribute.
+
+(define <string-attribute>
+  (class-make '<string-attribute>
+             '(<attribute>)
+             '(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.
 (define (bitset-attr? x) (class-instance? <bitset-attribute> x))
 
 ; Return a symbol indicating the kind of attribute ATTR is.
-; The result is one of boolean,integer,enum,bitset.
+; The result is one of boolean,integer,enum,bitset or string.
 
 (define (attr-kind attr)
   (case (object-class-name attr)
     ((<boolean-attribute>) 'boolean)
+    ((<string-attribute>)  'string)
     ((<integer-attribute>) 'integer)
     ((<enum-attribute>)    'enum)
     ((<bitset-attribute>)  'bitset)
 
 (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!
  <boolean-attribute> '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))))
+ (parse-simple-attribute boolean? "boolean attribute not one of #f/#t")
 )
 
+(method-make!
+ <string-attribute> '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
 
 (method-make!
  <bitset-attribute> '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))))
+ (parse-simple-attribute (lambda (x) (or (symbol? x) (string? x)))
+                        "improper bitset attribute")
 )
 
 ; An integer attribute's value is a number
 
 (method-make!
  <integer-attribute> '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))))
+ (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!
  <enum-attribute> '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-simple-attribute (lambda (x) (or (symbol? x) (string? x)))
+                        "improper enum attribute")
 )
 
 ; Parse a boolean attribute's value definition.
        (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!
+ <string-attribute> 'parse-value-def
+ (lambda (self errtxt values) #f)
+)
+
 ; Parse a bitset attribute's value definition.
 ; FIXME: treated as enum?
 
 ; 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>.
+; 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.
 
                (not (rtx? default)))
           (parse-error errtxt "invalid default" default))
        (elm-xset! result 'default default))
+      ((<string-attribute>)
+       (let ((default (or default "")))
+        (if (and (not (string? default))
+                 (not (rtx? default)))
+            (parse-error errtxt "invalid default" default))
+        (elm-xset! result 'default default)))
       ((<integer-attribute>)
        (let ((default (if default default (if (null? values) 0 (car values)))))
         (if (and (not (integer? default))
            (case elm-name
              ((type) (set! type-class (case (cadr arg)
                                        ((boolean) <boolean-attribute>)
+                                       ((string) <string-attribute>)
                                        ((bitset) <bitset-attribute>)
                                        ((integer) <integer-attribute>)
                                        ((enum) <enum-attribute>)
      ", 0 } }")
  )
 )
+
+;; Doesn't handle escape sequences.
+(method-make!
+ <string-attribute> 'gen-value-for-defn-raw
+ (lambda (self value)
+   (string-append "\"" value "\""))
+)
+
+(method-make!
+ <string-attribute> 'gen-value-for-defn
+ (lambda (self value)
+   (send self 'gen-value-for-defn-raw value))
+)
+
 \f
 ; Called before loading a .cpu file to initialize.
 
index f6691f8..c181c57 100644 (file)
@@ -70,6 +70,9 @@ void
   @arch@_cgen_init_ibld_table (cd);
   cd->parse_handlers = & @arch@_cgen_parse_handlers[0];
   cd->parse_operand = @arch@_cgen_parse_operand;
+#ifdef CGEN_ASM_INIT_HOOK
+CGEN_ASM_INIT_HOOK
+#endif
 "
    -asm-init-code
 "}\n\n"