OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-binutils/] [binutils-2.19.1/] [cgen/] [attr.scm] - Rev 6

Compare with Previous | Blame | View Log

; Attributes.
; Copyright (C) 2000, 2003, 2005, 2009 Red Hat, Inc.
; This file is part of CGEN.
; See file COPYING.CGEN for details.
; There are 4 kinds of attributes: boolean, integer, enum, and bitset.  Boolean
; attributes are really enum attributes with two possible values, but they
; occur frequently enough that they are special cased.
;
; All objects that use attributes must have two methods:
; - 'get-atlist - returns the object's attr-list
; - 'set-atlist! - set the object's attr-list
;
; In .cpu files, attribute lists are associative lists of (NAME VALUE).
; 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
; (attributes that don't appear in any generated code).
;
; Example:
; (FOO1 !FOO2 (BAR 3) (FOO3 X) (MACH sparc,sparclite))
;
; ??? Implementation of expressions is being postponed as long
; as possible, avoiding adding complications for complication's sake, and
; because I'm not completely sure how I want to do them.
; The syntax for an expression value is (ATTR (rtx-func ...)).
;
; ??? May wish to allow a bitset attribute like (ATTR val1,!val2), where `!'
; means to turn off that particular bit (or bits if val2 refers to several).
;
; ??? May wish to allow specifying enum attributes by only having to
; specify the value (move names into "enum space" or some such).
; An attr-list (or "atlist") is a collection of attributes.
; Attributes are stored as an associative list.
; There is possible confusion between "alist" (associative-list) and
; "atlist" (attribute-list) but in practice I haven't had a problem.
; ??? May wish to change this to a list of objects, as the alist doesn't carry
; enough info.  However the alist is simple and fast.
; An empty attribute-list.
""; The attribute baseclass.
; The attributes of <ident> are the set of attributes for this attribute
; [meaning attributes themselves can have attributes].
; [Ya, that's clumsily written.  I left it that way for fun.]
; An odd notion that is of some use.  It's current raison d'etre is to
; support sanitization of attributes [which is implemented with the
; `sanitize' attribute].
; List of object types this attribute is for.
; Possible element values are:
; attr, enum, cpu, mach, model, ifield, hardware, operand,
; insn
; A value of #f means the attribute is for everything.
; Accessors.
; A class for each type of attribute.
; `values' exists for boolean-attribute to simplify the code, it's ignored.
; Ditto for `default'.  The default for boolean-attribute is always #f.
; VALUES is ignored for string-attribute.
; For bitset attributes VALUES is a list of
; (symbol bit-number-or-#f attr-list comment-or-#f),
; one for each bit.
; If bit-number is #f (unspecified), cgen will choose.
; Int's are used to record the bitset in the generated code so there's a limit
; of 32 elements, though there's nothing inherent in the description language
; that precludes removing the limit.
; NOTE: While one might want to record each element as an object, there's
; currently no need for the added complexity.
; For integer attributes VALUES is a list of (int),
; one for each possible value,
; or the empty list of all values are permissible.
; Note that each element is itself a list.  This is for consistency.
; For enum attributes VALUES is a list of
; (symbol enum-value-or-#f attr-list comment-or-#f),
; one for each possible.
; If enum-value is #f (unspecified) cgen will apply the standard rule for
; assigning enum values.
; NOTE: While one might want to record each element as an object, there's
; currently no need for the added complexity.
; Return a boolean indicating if X is a <boolean-attribute> object.
; Return a boolean indicating if X is a <bitset-attribute> object.
; Return a symbol indicating the kind of attribute ATTR is.
; The result is one of boolean,integer,enum,bitset or string.
"attr-kind: internal error, not an attribute class"; Accessors.
; Create an attribute.
; Attributes are stored in attribute lists using the actual value
; rather than an object containing the value, so we only have to cons
; NAME and VALUE rather than building some object.  This is for simplicity
; and speed.  We try to incrementally complicate things, only as necessary.
; VALUE must be #f or #t.
; VALUES must be a comma separated list of symbols
; (e.g. val1,val2 not (val1 val2)).
; FIXME: require values to be a string (i.e. "val1,val2")
; VALUE must be a number (or maybe a symbol).
; VALUE must be a symbol.
;;; Return a procedure to parse an attribute.
;;; RIGHT-TYPE? is a procedure that verifies the value is the right type.
;;; MESSAGE is printed if there is an error.
; A boolean attribute's value is either #t or #f.
"boolean attribute not one of #f/#t""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
; been read in.
; ??? Need to decide whether all define-mach's must appear before any
; define-insn's.  It would be nice to be able to spread an architecture's
; description over several .cpu files.
; ??? On the other hand, all machs are specified in define-arch.
; Perhaps creation of builtins could be defered until then.
"improper bitset attribute"; An integer attribute's value is a number
; (or maybe a symbol representing that value).
"improper integer attribute"; An enum attribute's value is a symbol representing that value.
"improper enum attribute"; Parse a boolean attribute's value definition.
"boolean value list must be (#f #t)"; Ignore values for strings.  We can't do any error checking since
; the default value is (#f #t).
; Parse a bitset attribute's value definition.
; FIXME: treated as enum?
""; Parse an integer attribute's value definition.
; VALUES may be #f which means any value is ok.
"invalid element in integer attribute list"; Parse an enum attribute's value definition.
; See parse-enum-vals for more info.
""; Make an attribute list object from a list of name/value pairs.
; Parse an attribute definition.
; This is the main routine for building an attribute object from a
; 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.
"Processing attribute "" ...\n";; Pick out name first to augment the error context.
""; Set the default.
"invalid default""""invalid default""invalid default""invalid default"; Read an attribute description
; This is the main routine for analyzing attributes in the .cpu file.
; CONTEXT is a <context> object for error messages.
; ARG-LIST is an associative list of field name and field value.
; -attr-parse is invoked to create the attribute object.
; attribute type
""; assume for everything
; #f indicates "not set"
; #f indicates "not set"
; Loop over each element in ARG-LIST, recording what's found.
"invalid attribute type""invalid attribute arg"; Must have type now.
"type not specified"; Establish proper defaults now that we know the type.
; really a nop, but for consistency
;; FIXME
"bitset-attribute default not specified""bitset-attribute values not specified";; FIXME
; really a nop, but for consistency
;; FIXME
"enum-attribute default not specified""bitset-attribute values not specified"; Now that we've identified the elements, build the object.
; Main routines for defining attributes in .cpu files.
"define-attr"; Query routines.
; Lookup ATTR-NAME in ATTR-LIST.
; The result is the object or #f if not found.
; Return a boolean indicating if boolean attribute ATTR is "true" in
; attribute alist ALIST.
; Note that if the attribute isn't present, it is defined to be #f.
"Not a boolean attribute:"; Return a boolean indicating if attribute ATTR is present in
; attribute alist ALIST.
; Expand attribute value ATVAL, which is an rtx expression.
; OWNER is the containing object or #f if there is none.
; OWNER is needed if an attribute is defined in terms of other attributes.
; If it's #f obviously ATVAL can't be defined in terms of others.
"-attr-eval: internal error, unsupported result:"; Return value of ATTR in attribute alist ALIST.
; If not present, return the default value.
; OWNER is the containing object or #f if there is none.
; pair? -> cheap non-null-list?
; Return the value of ATTR in ATLIST.
; OWNER is the containing object or #f if there is none.
; Same as atlist-attr-value but return nil if attribute not present.
; pair? -> cheap non-null-list?
; Return the default for attribute A.
; If A isn't a non-boolean attribute, we assume it's a boolean one, and
; return #f (??? for backward's compatibility, to be removed in time).
; OWNER is the containing object or #f if there is none.
; pair? -> cheap non-null-list?
; If no default was provided, use the first value.
; Return a boolean indicating if X is present in BITSET.
; Bitset values are recorded as val1,val2,....
; Routines for accessing attributes in objects.
; Get/set attributes of OBJ.
; OBJ is any object which supports the get-atlist message.
; As a speed up, we allow objects to specify an empty attribute list
; with #f or (), rather than creating an attr-list object.
; ??? There is atlist-empty now which should be used directly.
; Add attribute ATTR to OBJ.
; The attribute is prepended to the front so it overrides any existing
; definition.
; Add attribute list ATLIST to OBJ.
; Attributes in ATLIST override existing values, so ATLIST is "prepended".
; Must have same prefix.
; Return boolean of whether OBJ has boolean attribute ATTR or not.
; OBJ is any object that supports attributes.
; FIXME: for backward compatibility.  Delete in time.
; Return a boolean indicating if attribute ATTR is present in OBJ.
; Return value of attribute ATTR in OBJ.
; If the attribute isn't present, the default is returned.
; OBJ is any object that supports the get-atlist method.
; Return boolean of whether OBJ has attribute ATTR value VALUE or not.
; OBJ is any object that supports attributes.
; NOTE: The default value of the attribute IS considered.
; Return boolean of whether OBJ explicitly has attribute ATTR value VALUE
; or not.
; OBJ is any object that supports attributes.
; NOTE: The default value of the attribute IS NOT considered.
; Utilities.
; Convert a bitset value "a,b,c" into a list (a b c).
; Generate a list representing a bit mask of the indices of 'values'
; within 'all-values'. Each element in the resulting list represents a byte.
; Both bits and bytes are indexed from left to right starting at 0
; with 8 bits in a byte.
"charmask-bytes for "" ""\n""indices: ""\n""result: ""\n"; Convert a bitset value into a bit string based on the
; index of each member in values
"{ "", \"""\\x""\" }"; Return the enum of ATTR-NAME for type TYPE.
; TYPE is one of 'ifld, 'hw, 'operand, 'insn.
"CGEN_""_"; Return a list of enum value definitions for gen-enum-decl.
; Attributes numbers are organized as follows: booleans are numbered 0-31.
; The range is because that's what fits in a portable int.  Unused numbers
; are left unused.  Non-booleans are numbered starting at 32.
; An alternative is start numbering the booleans at 32.  The generated code
; is simpler with the current way (the "- 32" to get back the bit number or
; array index number occurs less often).
;
; Three special values are created:
; END-BOOLS - mark end of boolean attributes
; END-NBOOLS - mark end of non-boolean attributes
; START-NBOOLS - marks the start of the non-boolean attributes
; (needed in case first non-bool is sanytized out).
;
; ATTR-OBJ-LIST is a list of <attribute> objects (always subclassed of course).
; Sort an alist of attributes so non-boolean attributes are at the front.
; This is used to sort a particular object's attributes.
; This is required by the C support code (cgen.h:CGEN_ATTR_VALUE).
; Boolean attributes appear as (NAME . #t/#f), non-boolean ones appear as
; (NAME . VALUE).  Attributes of the same type are sorted by name.
;(display (list a b "\n"))
; we know b is non-bool here
; we know a is non-bool here
; Sort ATTR-LIST into two lists: bools and non-bools.
; The car of the result is the bools, the cdr is the non-bools.
; Attributes requiring a fixed index have the INDEX attribute,
; and used for the few special attributes that are refered to by
; architecture independent code.
; For each of non-bools and bools, put attributes with the INDEX attribute
; first.  This is used to sort a list of attributes for output (e.g. define
; the attr enum).
;
; FIXME: Record index number with the INDEX attribute and sort on it.
; At present it's just a boolean.
; Return number of non-bools in attributes ATLIST.
; Given an alist of attributes, return the non-bools.
; Given an alist of attributes, return the bools.
; Parse an attribute spec.
; CONTEXT is a <context> object or #f if there is none.
; ATTRS is a list of attribute specs (e.g. (FOO !BAR (BAZ 3))).
; The result is the attribute alist.
"improper attribute list"; boolean attribute
"unknown attribute""unknown attribute""improper attribute"; Parse an object attribute spec.
; ATTRS is a list of attribute specs (e.g. (FOO !BAR (BAZ 3))).
; The result is an <attr-list> object.
; Return the source form of an atlist's values.
; Externally attributes are ((name1 value1) (name2 value2) ...).
; Internally they are ((name1 . value1) (name2 . value2) ...).
; Cons an attribute to an attribute list to create a new attribute list.
; ATLIST is either an attr-list object or #f or () (both of the latter two
; signify an empty attribute list, in which case we make the prefix of the
; result "").
""; Append one attribute list to another.
; The prefix for the new atlist is taken from the first one.
; Remove meta-attributes from ALIST.
; "meta" may be the wrong adjective to use here.
; The attributes in question are not intended to appear in generated files.
; They started out being attributes of attributes, hence the name "meta".
; FIXME: Why not use find?
; Remove meta-attributes from ATTR-LIST.
; "meta" may be the wrong adjective to use here.
; The attributes in question are not intended to appear in generated files.
; They started out being attributes of attributes, hence the name "meta".
; FIXME: Why not use find?
; Remove duplicates from ATTRS, a list of attributes.
; Attribute lists are typically small so we use a simple O^2 algorithm.
; The leading entry of an attribute overrides subsequent ones so this is
; defined to pick the first entry of each attribute.
; Return a list of all attrs in TABLE-LIST, a list of lists of arbitrary
; elements.   A list of lists is passed to simplify computation of insn
; attributes where the insns and macro-insns are on separate lists and
; appending them into one list would be unnecessarily expensive.
; ACCESSOR is a function to access the attrs field from TABLE-LIST.
; Duplicates are eliminated and the list is sorted so non-boolean attributes
; are at the front (required by the C code that fetches attribute values).
; STD-ATTRS is an `attr-list' object of attrs that are always available.
; The actual values returned are random (e.g. #t vs #f).  We could
; canonicalize them.
; The result is an alist of all the attributes that are used in TABLE-LIST.
; ??? The cdr of each element is some random value.  Perhaps it should be
; the default value or perhaps we should just return a list of names.
; ??? No longer used.
; Return lists of attributes for particular object types.
; FIXME: The output shouldn't be required to be sorted.
; Current behaviour puts the non-bools at the front.
; Methods to emit the C value of an attribute.
; These don't _really_ belong here (C code doesn't belong in the appl'n
; independent part of CGEN), but there isn't a better place for them
; (maybe utils-cgen.scm?) and there's only a few of them.
"0""1";(string-upcase (string-append (obj:str-name self) "_" value)))
"isa""|(1<<""_"")""{ ""isa""{ ""|(1<<""_"")"", 0 }"" }""{ { "", 0 } }""_""{ { "", 0 } }";; Doesn't handle escape sequences.
"\"""\""; Called before loading a .cpu file to initialize.
"\
Define an attribute, name/value pair list version.
"; Called before a . cpu file is read in to install any builtins.
; One thing this does is define all attributes requiring a fixed index,
; keeping them all in one place.
; ??? Perhaps it would make sense to define all predefined attributes here.
"virtual object"; The meta attribute is used for attributes that aren't to appear in
; generated output (need a better name).
; Objects to keep local to a generated file.
; Attributes requiring fixed indices.
; ALIAS is used for instructions that are aliases of more general insns.
; ALIAS insns are ignored by the simulator.
"insn is an alias of another"; Called after loading a .cpu file to perform any post-processing required.
 

Compare with Previous | Blame | View Log

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.