URL
https://opencores.org/ocsvn/scarts/scarts/trunk
Subversion Repositories scarts
[/] [scarts/] [trunk/] [toolchain/] [scarts-binutils/] [binutils-2.19.1/] [cgen/] [utils-cgen.scm] - Rev 6
Compare with Previous | Blame | View Log
; CGEN Utilities. ; Copyright (C) 2000, 2002, 2003, 2009 Red Hat, Inc. ; This file is part of CGEN. ; See file COPYING.CGEN for details. ; ; This file contains utilities specific to cgen. ; Generic utilities should go in utils.scm. ; True if text of sanitize markers are to be emitted. ; This is a debugging tool only, though it could have use in sanitized trees. ; Utility to display command line invocation for debugging purposes. "cgen -s "; Output double-quotes if string has a space for better ; correspondence to how to specify string to shell. " "; COS utilities. ; Perhaps these should be provided with cos (cgen-object-system), but for ; now they live here. ; Define the getter for a list of elements of a class. ; Define the setter for a list of elements of a class. ; Make an object, specifying values for particular elements. ; ??? Eventually move to cos.scm/cos.c. "vmake: unknown options:";;; Source locations are recorded as a stack, with (ideally) one extra level ;;; for each macro invocation. ;; A list of "single-location" objects, ;; sorted by most recent location first. ;;; A single source location. ;;; This is recorded as a vector for simplicity. ;;; END? is true if the location marks the end of the expression. ;;; NOTE: LINE and COLUMN are origin-0 (the first line is line 0). ;;; Return a single-location in a readable form. ;; +1: numbers are recorded origin-0 ":"":""(end)""";;; Same as single-location->string, except omit any directory info in ;;; the file name. ;; +1: numbers are recorded origin-0 ":"":""(end)""";;; Return a location in a readable form. " referenced from:""\n"":";;; Return the location information in Guile's source-properties ;;; in a readable form. ":"":";;; Return the top location on LOC's stack. ;;; Return a new <location> with FILE, LINE pushed onto the stack. ;;; Return a new <location> with NEW-LOC preappended to LOC. ;;; Return an unspecified <location>. ;;; This is mainly for use in debugging utilities. ;;; Ideally for .cpu-file related stuff we always have a location, ;;; but that's not always true. "unspecified";;; Return a location denoting a builtin object. "builtin";;; Return a <location> object for the current input port. ;;; END? is true if the location marks the end of the expression. ;;; An object property for tracking source locations during macro expansion. ;;; Set FORM's location to LOC. ; Each named entry in the description file typically has these three members: ; name, comment attrs. ; All objects defined in the .cpu file have these elements. ; Where in the class hierarchy they're recorded depends on the object. ; Additionally most objects have `name', `comment' and `attrs' elements. ; Utility to return the name as a string. ; Subclass of <ident> for use by description file objects. ; ; Records the source location of the object. ; ; We also record an internally generated entry, ordinal, to record the ; relative position within the description file. It's generally more efficient ; to record some kinds of objects (e.g. insns) in a hash table. But we also ; want to emit these objects in file order. Recording the object's relative ; position lets us generate an ordered list when we need to. ; We can't just use the line number because we want an ordering over multiple ; input files. ;; A <location> object. ;; #f for ordinal means "unassigned" ; Return a boolean indicating if X is a <source-ident>. ; Parsing utilities ;;; A parsing/processing context, used to give better error messages. ;;; LOCATION must be an object created with make-location. ;; Location of the object being processed, ;; or #f if unknown (or there is none). ;; Error message prefix or #f if there is none. ; Accessors. ; Create a <context> object that is just a prefix. ; Create a <context> object that (current-reader-location) with PREFIX. ; Create a <context> object from <source-ident> object OBJ. ; Create a new context from CONTEXT with TEXT appended to the prefix. ; Create a new context from CONTEXT with NAME appended to the prefix. ":"; Call this to issue an error message when all you have is a context. ; CONTEXT is a <context> object or #f if there is none. ; INTRO is a general introduction to what cgen was doing. ; ERRMSG is, yes, you guessed it, the error message. ; EXPR is the value that had the error if there is one. ; Call this to issue an error message when you have a context and an ; <ident> or <source-ident> object (we call the "owner"). ; CONTEXT is a <context> object or #f if there is none. ; OWNER is an <ident> or <source-ident> object or #f if there is none. ; INTRO is a general introduction to what cgen was doing. ; If OWNER is non-#f, the text " of <object-name>" is appended. ; ERRMSG is, yes, you guessed it, the error message. ; EXPR is the value that had the error if there is one. ;; If we don't have a context, look at the owner to try to find one. ;; We want to include the source location in the error if we can. " of """"Error"": ""\n~A:\n@ ~A:\n\n~A: ~A:""\n~A:\n~A:"; Parse an object name. ; NAME is either a symbol or a list of symbols which are concatenated ; together. Each element can in turn be a list of symbols, and so on. ; This supports symbol concatenation in the description file without having ; to using string-append or some such. "improper name"; Parse an object comment. ; COMMENT is either a string or a list of strings, each element of which may ; in turn be a list of strings. "improper comment"; Parse a symbol. "not a symbol or string"; Parse a string. "not a string or symbol"; Parse a number. ; VALID-VALUES is a list of numbers and (min . max) pairs. "not a number""invalid number"; Parse a boolean value "not a boolean (#f/#t)"; Parse a list of handlers. ; Each entry is (symbol "string"). ; These map function to a handler for it. ; The meaning is up to the application but generally the handler is a ; C/C++ function name. ; ALLOWED is a list valid values for the symbol or #f if anything is allowed. ; The result is handlers unchanged. "bad handler spec""bad handler spec""unknown handler type"; Return a boolean indicating if X is a keyword. ; This also handles symbols named :foo because Guile doesn't stablely support ; :keywords (how does one enable :keywords? read-options doesn't appear to ; work). ; Convert a list like (#:key1 val1 #:key2 val2 ...) to ; ((#:key1 val1) (#:key2 val2) ...). ; Missing values are specified with an empty list. ; This also supports (:sym1 val1 ...) because Guile doesn't stablely support ; :keywords (#:keywords work, but #:foo shouldn't appear in the description ; language). ; Scan KL backwards, building up each element as we go. ; Signal an error if the argument name is not a symbol. ; This is done by each of the argument validation routines so the caller ; doesn't need to make two calls. "empty argument spec""argument name not a symbol"; Signal a parse error if an argument was specified with a value. ; ARG-SPEC is (name value). " takes zero arguments"; Validate and return a symbol argument. ; ARG-SPEC is (name value). ": argument not a symbol"; Sanitization ; Sanitization is handled via attributes. Anything that must be sanitized ; has a `sanitize' attribute with the value being the keyword to sanitize on. ; Ideally most, if not all, of the guts of the generated sanitization is here. ; Utility to simplify expression in .cpu file. ; Usage: (sanitize keyword entry-type entry-name1 [entry-name2 ...]) ; Enum attribute `(sanitize keyword)' is added to the entry. ; It's written this way so Hobbit can handle it. "sanitize""unknown entry type"; ENTRY is #f in the case where the element was discarded ; because its mach wasn't selected. But in the case where ; we're keeping everything, ensure ENTRY is not #f to ; catch spelling errors. ; Propagate the sanitize attribute to class members ; as necessary. "sanitize""unknown "; caller eval's our result, so return a no-op ; Return TEXT sanitized with KEYWORD. ; TEXT must exist on a line (or lines) by itself. ; i.e. it is assumed that it begins at column 1 and ends with a newline. ; If KEYWORD is #f, no sanitization is generated. ""; pair? -> cheap list? ; split string to avoid removal "/* start-""sanitize-"" */\n""/* end-""sanitize-"" */\n"""; split string to avoid removal "/* start-""sanitize-"" */\n""/* end-""sanitize-"" */\n"; Return TEXT sanitized with OBJ's sanitization, if it has any. ; OBJ may be #f. ; Cover procs to handle generation of object declarations and definitions. ; All object output should be routed through gen-decl and gen-defn. ; Send the gen-decl message to OBJ, and sanitize the output if necessary. "Generating decl for ""unknown"" ...\n"""; Send the gen-defn message to OBJ, and sanitize the output if necessary. "Generating defn for ""unknown"" ...\n"""; Attributes ; Return the C/C++ type to use to hold a value for attribute ATTR. "isa""CGEN_BITSET""int""unsigned int""int""enum ""_attr"; Return C macros for accessing an object's attributes ATTRS. ; PREFIX is one of "cgen_ifld", "cgen_hw", "cgen_operand", "cgen_insn". ; ATTRS is an alist of attribute values. The value is unimportant except that ; it is used to determine bool/non-bool. ; Non-bools need to be separated from bools as they're each recorded ; differently. Non-bools are recorded in an int for each. All bools are ; combined into one int to save space. ; ??? We assume there is at least one bool. "/* "" attribute accessor macros. */\n""#define CGEN_ATTR_""_""_VALUE(attrs) ""(((attrs)->bool & (1 << ""_"")) != 0)""((attrs)->nonbool[""_""-""_START_NBOOLS-1].""isa""""non""non""bitset)""\n""\n"; Return C code to declare an enum of attributes ATTRS. ; PREFIX is one of "cgen_ifld", "cgen_hw", "cgen_operand", "cgen_insn". ; ATTRS is an alist of attribute values. The value is unimportant except that ; it is used to determine bool/non-bool. ; Non-bools need to be separated from bools as they're each recorded ; differently. Non-bools are recorded in an int for each. All bools are ; combined into one int to save space. ; ??? We assume there is at least one bool. "_attr"" attrs""_""/* Number of non-boolean elements in ""_attr. */\n""#define ""_NBOOL_ATTRS ""(""_END_NBOOLS - ""_START_NBOOLS - 1)\n""\n"; Return name of symbol ATTR-NAME. ; PREFIX is the prefix arg to gen-attr-enum-decl. "_"; Normal gen-mask argument to gen-bool-attrs. ; Returns "(1<< PREFIX_NAME)" where PREFIX is from atlist-prefix and ; NAME is the name of the attribute. ; ??? This used to return PREFIX_NAME-CGEN_ATTR_BOOL_OFFSET. ; The tradeoff is simplicity vs perceived maximum number of boolean attributes ; needed. In the end the maximum number needn't be fixed, and the simplicity ; of the current way is good. "(1<<"")"; Return C expression of bitmasks of boolean attributes in ATTRS. ; ATTRS is an <attr-list> object, it need not be pre-sorted. ; GEN-MASK is a procedure that returns the C code of the mask. "0"; `|' is used here instead of `+' so we don't ; have to care about duplicates. "|"; Return the C definition of OBJ's attributes. ; TYPE is one of 'ifld, 'hw, 'operand, 'insn. ; [Other objects have attributes but these are the only ones we currently ; emit definitions for.] ; OBJ is any object that supports the 'get-atlist message. ; ALL-ATTRS is an ordered alist of all attributes. ; "ordered" means all the non-boolean attributes are at the front and ; duplicate entries have been removed. ; GEN-MASK is the gen-mask arg to gen-bool-attrs. "{ "", {"; For the boolean case, we can (currently) get away with only specifying ; the attributes that are used since they all fit in one int and the ; default is currently always #f (and won't be changed without good ; reason). In the non-boolean case order is important since each value ; has a specific spot in an array, all of them must be specified. " 0"; drop the leading "," ; FIXME: Are we missing attr-prefix here? ", "" } }"; Return the C definition of the terminating entry of an object's attributes. ; ALL-ATTRS is an ordered alist of all attributes. ; "ordered" means all the non-boolean attributes are at the front and ; duplicate entries have been removed. "{ 0, {"" { 0, 0 }"; drop the leading "," ; FIXME: Are we missing attr-prefix here? ", "" } }"; Return a boolean indicating if ATLIST indicates a CTI insn. ; Misc. gen-* procs ; Return name of obj as a C symbol. ; Return the name of the selected cpu family. ; An error is signalled if more than one has been selected. ; FIXME: error checking ; Return HAVE_CPU_<CPU>. "HAVE_CPU_"; Return the bfd mach name for MACH. "bfd_mach_"; Return definition of C macro to get the value of SYM. "#define GET_""("") ""\n"; Return definition of C macro to set the value of SYM. "#define SET_""("""""", ""x) ("" = (x))\n"; Return definition of C macro to set the value of SYM, version 2. ; EXPR is one or more C statements *without* proper \newline handling, ; we prepend \ to each line. "#define SET_""("""""", "") \\\n""do { \\\n""\n"";} while (0)\n"; Misc. object utilities. ; Sort a list of objects with get-name methods alphabetically. ; Called before loading the .cpu file to initialize. "\ Mark an entry as being sanitized. "; Return a pair of definitions for a C macro that concatenates its ; argument symbols. The definitions are conditional on ANSI C ; semantics: one contains ANSI concat operators (##), and the other ; uses the empty-comment trick (/**/). We must do this, rather than ; use CONCATn(...) as defined in include/symcat.h, in order to avoid ; spuriously expanding our macro's args. "\ #if defined (__STDC__) || defined (ALMOST_STDC) || defined (HAVE_STRINGIZE) #define ""##"" #else #define ""/**/"" #endif "