1 |
6 |
jlechner |
; CGEN Utilities.
|
2 |
|
|
; Copyright (C) 2000, 2002, 2003, 2009 Red Hat, Inc.
|
3 |
|
|
; This file is part of CGEN.
|
4 |
|
|
; See file COPYING.CGEN for details.
|
5 |
|
|
;
|
6 |
|
|
; This file contains utilities specific to cgen.
|
7 |
|
|
; Generic utilities should go in utils.scm.
|
8 |
|
|
|
9 |
|
|
; This is a debugging tool only, though it could have use in sanitized trees.
|
10 |
|
|
; Utility to display command line invocation for debugging purposes.
|
11 |
|
|
"cgen -s "; Output double-quotes if string has a space for better
|
12 |
|
|
|
13 |
|
|
" "; COS utilities.
|
14 |
|
|
|
15 |
|
|
; now they live here.
|
16 |
|
|
; Define the getter for a list of elements of a class.
|
17 |
|
|
; Define the setter for a list of elements of a class.
|
18 |
|
|
; Make an object, specifying values for particular elements.
|
19 |
|
|
; ??? Eventually move to cos.scm/cos.c.
|
20 |
|
|
"vmake: unknown options:";;; Source locations are recorded as a stack, with (ideally) one extra level
|
21 |
|
|
;;; for each macro invocation.
|
22 |
|
|
;; A list of "single-location" objects,
|
23 |
|
|
;; sorted by most recent location first.
|
24 |
|
|
;;; A single source location.
|
25 |
|
|
;;; This is recorded as a vector for simplicity.
|
26 |
|
|
;;; END? is true if the location marks the end of the expression.
|
27 |
|
|
;;; NOTE: LINE and COLUMN are origin-0 (the first line is line 0).
|
28 |
|
|
|
29 |
|
|
;; +1: numbers are recorded origin-0
|
30 |
|
|
":"":""(end)""";;; Same as single-location->string, except omit any directory info in
|
31 |
|
|
;;; the file name.
|
32 |
|
|
|
33 |
|
|
":"":""(end)""";;; Return a location in a readable form.
|
34 |
|
|
|
35 |
|
|
;;; in a readable form.
|
36 |
|
|
":"":";;; Return the top location on LOC's stack.
|
37 |
|
|
;;; Return a new <location> with FILE, LINE pushed onto the stack.
|
38 |
|
|
;;; Return a new <location> with NEW-LOC preappended to LOC.
|
39 |
|
|
;;; Return an unspecified <location>.
|
40 |
|
|
;;; This is mainly for use in debugging utilities.
|
41 |
|
|
;;; Ideally for .cpu-file related stuff we always have a location,
|
42 |
|
|
;;; but that's not always true.
|
43 |
|
|
"unspecified";;; Return a location denoting a builtin object.
|
44 |
|
|
"builtin";;; Return a <location> object for the current input port.
|
45 |
|
|
|
46 |
|
|
;;; An object property for tracking source locations during macro expansion.
|
47 |
|
|
|
48 |
|
|
; Each named entry in the description file typically has these three members:
|
49 |
|
|
; name, comment attrs.
|
50 |
|
|
; All objects defined in the .cpu file have these elements.
|
51 |
|
|
; Where in the class hierarchy they're recorded depends on the object.
|
52 |
|
|
; Additionally most objects have `name', `comment' and `attrs' elements.
|
53 |
|
|
; Utility to return the name as a string.
|
54 |
|
|
; Subclass of <ident> for use by description file objects.
|
55 |
|
|
;
|
56 |
|
|
; Records the source location of the object.
|
57 |
|
|
;
|
58 |
|
|
|
59 |
|
|
; relative position within the description file. It's generally more efficient
|
60 |
|
|
; to record some kinds of objects (e.g. insns) in a hash table. But we also
|
61 |
|
|
|
62 |
|
|
; position lets us generate an ordered list when we need to.
|
63 |
|
|
; We can't just use the line number because we want an ordering over multiple
|
64 |
|
|
; input files.
|
65 |
|
|
;; A <location> object.
|
66 |
|
|
;; #f for ordinal means "unassigned"
|
67 |
|
|
; Return a boolean indicating if X is a <source-ident>.
|
68 |
|
|
; Parsing utilities
|
69 |
|
|
|
70 |
|
|
;;; LOCATION must be an object created with make-location.
|
71 |
|
|
;; Location of the object being processed,
|
72 |
|
|
|
73 |
|
|
;; Error message prefix or #f if there is none.
|
74 |
|
|
; Accessors.
|
75 |
|
|
; Create a <context> object that is just a prefix.
|
76 |
|
|
; Create a <context> object that (current-reader-location) with PREFIX.
|
77 |
|
|
; Create a <context> object from <source-ident> object OBJ.
|
78 |
|
|
; Create a new context from CONTEXT with TEXT appended to the prefix.
|
79 |
|
|
; Create a new context from CONTEXT with NAME appended to the prefix.
|
80 |
|
|
":"; Call this to issue an error message when all you have is a context.
|
81 |
|
|
|
82 |
|
|
; INTRO is a general introduction to what cgen was doing.
|
83 |
|
|
; ERRMSG is, yes, you guessed it, the error message.
|
84 |
|
|
|
85 |
|
|
; Call this to issue an error message when you have a context and an
|
86 |
|
|
; <ident> or <source-ident> object (we call the "owner").
|
87 |
|
|
; CONTEXT is a <context> object or #f if there is none.
|
88 |
|
|
; OWNER is an <ident> or <source-ident> object or #f if there is none.
|
89 |
|
|
|
90 |
|
|
; If OWNER is non-#f, the text " of <object-name>" is appended.
|
91 |
|
|
; ERRMSG is, yes, you guessed it, the error message.
|
92 |
|
|
; EXPR is the value that had the error if there is one.
|
93 |
|
|
|
94 |
|
|
;; We want to include the source location in the error if we can.
|
95 |
|
|
" of """"Error"": ""\n~A:\n@ ~A:\n\n~A: ~A:""\n~A:\n~A:"; Parse an object name.
|
96 |
|
|
; NAME is either a symbol or a list of symbols which are concatenated
|
97 |
|
|
; together. Each element can in turn be a list of symbols, and so on.
|
98 |
|
|
|
99 |
|
|
; to using string-append or some such.
|
100 |
|
|
|
101 |
|
|
; COMMENT is either a string or a list of strings, each element of which may
|
102 |
|
|
; in turn be a list of strings.
|
103 |
|
|
"improper comment"; Parse a symbol.
|
104 |
|
|
"not a symbol or string"; Parse a string.
|
105 |
|
|
"not a string or symbol"; Parse a number.
|
106 |
|
|
; VALID-VALUES is a list of numbers and (min . max) pairs.
|
107 |
|
|
"not a number""invalid number"; Parse a boolean value
|
108 |
|
|
"not a boolean (#f/#t)"; Parse a list of handlers.
|
109 |
|
|
; Each entry is (symbol "string").
|
110 |
|
|
|
111 |
|
|
; The meaning is up to the application but generally the handler is a
|
112 |
|
|
; C/C++ function name.
|
113 |
|
|
|
114 |
|
|
; The result is handlers unchanged.
|
115 |
|
|
"bad handler spec""bad handler spec""unknown handler type"; Return a boolean indicating if X is a keyword.
|
116 |
|
|
; This also handles symbols named :foo because Guile doesn't stablely support
|
117 |
|
|
; :keywords (how does one enable :keywords? read-options doesn't appear to
|
118 |
|
|
; work).
|
119 |
|
|
; Convert a list like (#:key1 val1 #:key2 val2 ...) to
|
120 |
|
|
; ((#:key1 val1) (#:key2 val2) ...).
|
121 |
|
|
; Missing values are specified with an empty list.
|
122 |
|
|
; This also supports (:sym1 val1 ...) because Guile doesn't stablely support
|
123 |
|
|
|
124 |
|
|
; language).
|
125 |
|
|
|
126 |
|
|
; Signal an error if the argument name is not a symbol.
|
127 |
|
|
; This is done by each of the argument validation routines so the caller
|
128 |
|
|
; doesn't need to make two calls.
|
129 |
|
|
"empty argument spec""argument name not a symbol"; Signal a parse error if an argument was specified with a value.
|
130 |
|
|
; ARG-SPEC is (name value).
|
131 |
|
|
" takes zero arguments"; Validate and return a symbol argument.
|
132 |
|
|
; ARG-SPEC is (name value).
|
133 |
|
|
": argument not a symbol"; Sanitization
|
134 |
|
|
; Sanitization is handled via attributes. Anything that must be sanitized
|
135 |
|
|
; has a `sanitize' attribute with the value being the keyword to sanitize on.
|
136 |
|
|
; Ideally most, if not all, of the guts of the generated sanitization is here.
|
137 |
|
|
; Utility to simplify expression in .cpu file.
|
138 |
|
|
; Usage: (sanitize keyword entry-type entry-name1 [entry-name2 ...])
|
139 |
|
|
|
140 |
|
|
; It's written this way so Hobbit can handle it.
|
141 |
|
|
"sanitize""unknown entry type"; ENTRY is #f in the case where the element was discarded
|
142 |
|
|
|
143 |
|
|
; we're keeping everything, ensure ENTRY is not #f to
|
144 |
|
|
; catch spelling errors.
|
145 |
|
|
; Propagate the sanitize attribute to class members
|
146 |
|
|
; as necessary.
|
147 |
|
|
"sanitize""unknown "; caller eval's our result, so return a no-op
|
148 |
|
|
; Return TEXT sanitized with KEYWORD.
|
149 |
|
|
; TEXT must exist on a line (or lines) by itself.
|
150 |
|
|
; i.e. it is assumed that it begins at column 1 and ends with a newline.
|
151 |
|
|
; If KEYWORD is #f, no sanitization is generated.
|
152 |
|
|
""; pair? -> cheap list?
|
153 |
|
|
|
154 |
|
|
"/* start-""sanitize-"" */\n""/* end-""sanitize-"" */\n"""; split string to avoid removal
|
155 |
|
|
|
156 |
|
|
; OBJ may be #f.
|
157 |
|
|
; Cover procs to handle generation of object declarations and definitions.
|
158 |
|
|
; All object output should be routed through gen-decl and gen-defn.
|
159 |
|
|
|
160 |
|
|
"Generating decl for ""unknown"" ...\n"""; Send the gen-defn message to OBJ, and sanitize the output if necessary.
|
161 |
|
|
|
162 |
|
|
; Return the C/C++ type to use to hold a value for attribute ATTR.
|
163 |
|
|
"isa""CGEN_BITSET""int""unsigned int""int""enum ""_attr"; Return C macros for accessing an object's attributes ATTRS.
|
164 |
|
|
; PREFIX is one of "cgen_ifld", "cgen_hw", "cgen_operand", "cgen_insn".
|
165 |
|
|
; ATTRS is an alist of attribute values. The value is unimportant except that
|
166 |
|
|
|
167 |
|
|
; Non-bools need to be separated from bools as they're each recorded
|
168 |
|
|
|
169 |
|
|
; combined into one int to save space.
|
170 |
|
|
; ??? We assume there is at least one bool.
|
171 |
|
|
"/* "" 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.
|
172 |
|
|
; PREFIX is one of "cgen_ifld", "cgen_hw", "cgen_operand", "cgen_insn".
|
173 |
|
|
|
174 |
|
|
; it is used to determine bool/non-bool.
|
175 |
|
|
; Non-bools need to be separated from bools as they're each recorded
|
176 |
|
|
; differently. Non-bools are recorded in an int for each. All bools are
|
177 |
|
|
; combined into one int to save space.
|
178 |
|
|
|
179 |
|
|
"_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.
|
180 |
|
|
; PREFIX is the prefix arg to gen-attr-enum-decl.
|
181 |
|
|
"_"; Normal gen-mask argument to gen-bool-attrs.
|
182 |
|
|
|
183 |
|
|
; NAME is the name of the attribute.
|
184 |
|
|
|
185 |
|
|
; The tradeoff is simplicity vs perceived maximum number of boolean attributes
|
186 |
|
|
; needed. In the end the maximum number needn't be fixed, and the simplicity
|
187 |
|
|
; of the current way is good.
|
188 |
|
|
|
189 |
|
|
; ATTRS is an <attr-list> object, it need not be pre-sorted.
|
190 |
|
|
; GEN-MASK is a procedure that returns the C code of the mask.
|
191 |
|
|
|
192 |
|
|
; have to care about duplicates.
|
193 |
|
|
"|"; Return the C definition of OBJ's attributes.
|
194 |
|
|
; TYPE is one of 'ifld, 'hw, 'operand, 'insn.
|
195 |
|
|
; [Other objects have attributes but these are the only ones we currently
|
196 |
|
|
; emit definitions for.]
|
197 |
|
|
; OBJ is any object that supports the 'get-atlist message.
|
198 |
|
|
; ALL-ATTRS is an ordered alist of all attributes.
|
199 |
|
|
|
200 |
|
|
; duplicate entries have been removed.
|
201 |
|
|
|
202 |
|
|
"{ "", {"; For the boolean case, we can (currently) get away with only specifying
|
203 |
|
|
|
204 |
|
|
; default is currently always #f (and won't be changed without good
|
205 |
|
|
|
206 |
|
|
; has a specific spot in an array, all of them must be specified.
|
207 |
|
|
" 0"; drop the leading ","
|
208 |
|
|
; FIXME: Are we missing attr-prefix here?
|
209 |
|
|
", "" } }"; Return the C definition of the terminating entry of an object's attributes.
|
210 |
|
|
|
211 |
|
|
; "ordered" means all the non-boolean attributes are at the front and
|
212 |
|
|
; duplicate entries have been removed.
|
213 |
|
|
|
214 |
|
|
; FIXME: Are we missing attr-prefix here?
|
215 |
|
|
|
216 |
|
|
; Misc. gen-* procs
|
217 |
|
|
; Return name of obj as a C symbol.
|
218 |
|
|
; Return the name of the selected cpu family.
|
219 |
|
|
|
220 |
|
|
; FIXME: error checking
|
221 |
|
|
; Return HAVE_CPU_<CPU>.
|
222 |
|
|
"HAVE_CPU_"; Return the bfd mach name for MACH.
|
223 |
|
|
"bfd_mach_"; Return definition of C macro to get the value of SYM.
|
224 |
|
|
"#define GET_""("") ""\n"; Return definition of C macro to set the value of SYM.
|
225 |
|
|
"#define SET_""("""""", ""x) ("" = (x))\n"; Return definition of C macro to set the value of SYM, version 2.
|
226 |
|
|
|
227 |
|
|
; we prepend \ to each line.
|
228 |
|
|
"#define SET_""("""""", "") \\\n""do { \\\n""\n"";} while (0)\n"; Misc. object utilities.
|
229 |
|
|
; Sort a list of objects with get-name methods alphabetically.
|
230 |
|
|
|
231 |
|
|
"\
|
232 |
|
|
Mark an entry as being sanitized.
|
233 |
|
|
"; Return a pair of definitions for a C macro that concatenates its
|
234 |
|
|
|
235 |
|
|
; semantics: one contains ANSI concat operators (##), and the other
|
236 |
|
|
|
237 |
|
|
; use CONCATn(...) as defined in include/symcat.h, in order to avoid
|
238 |
|
|
|
239 |
|
|
"\
|
240 |
|
|
#if defined (__STDC__) || defined (ALMOST_STDC) || defined (HAVE_STRINGIZE)
|
241 |
|
|
#define ""##""
|
242 |
|
|
#else
|
243 |
|
|
#define ""/**/""
|
244 |
|
|
#endif
|
245 |
|
|
"
|