2 ; Copyright (C) 2000, 2001, 2005, 2009 Red Hat, Inc.
3 ; This file is part of CGEN.
4 ; See file COPYING.CGEN for details.
6 ; Operands map a set of values (registers, whatever) to an instruction field
7 ; or other indexing mechanism. Operands are also how the semantic code refers
8 ; to hardware elements.
10 ; The `<operand>' class.
12 ; ??? Need a new lighterweight version for instances in semantics.
13 ; This should only contain the static elements from the description file.
15 ; ??? Derived operands don't use all the current class members. Perhaps
16 ; split <operand> into two.
19 (class-make '<operand>
22 ; Name as used in semantic code.
23 ; Generally this is the same as NAME. It is changed by the
24 ; `operand:' rtx function. One reason is to set a "pretty"
25 ; name in tracing output (most useful in memory operands).
26 ; A more important reason is to help match semantic operands
27 ; with function unit input/output arguments.
30 ; Pretty name as used in tracing code.
31 ; Generally this is the same as the hardware element's name.
34 ; Semantic name of hardware element refered to by this operand.
37 ; Hardware type of operand, a subclass of <hardware-base>.
38 ; This is computed lazily from HW-NAME as many hardware
39 ; elements can have the same semantic name. Applications
40 ; that require a unique hardware element to be refered to are
41 ; required to ensure duplicates are discarded (usually done
42 ; by keeping the appropriate machs).
43 ; All h/w elements with the same semantic name are required
44 ; to be the same kind (register, immediate, etc.).
45 ; FIXME: Rename to hw.
48 ; Name of mode, as specified in description file.
49 ; This needn't be the actual mode, as WI will get coerced
50 ; to the actual word int mode.
53 ; The mode TYPE is being referenced in.
54 ; This is also looked up lazily for the same reasons as TYPE.
58 ; A number or #f used to select a variant of the hardware
59 ; element. An example is ASI's on sparc.
60 ; ??? I really need to be better at picking names.
63 ; Index into type, class <hw-index>.
64 ; For example in the case of an array of registers
65 ; it can be an instruction field or in the case of a memory
66 ; reference it can be a register operand (or general rtx).
67 ; ??? At present <hw-index> is a facade over the real index
68 ; type. Not sure what the best way to do this is.
71 ; Code to run when the operand is read or #f meaning pass
72 ; the request on to the hardware object.
75 ; Code to run when the operand is written or #f meaning pass
76 ; the request on to the hardware object.
79 ; Associative list of (symbol . "handler") entries.
80 ; Each entry maps an operation to its handler (which is up to
81 ; the application but is generally a function name).
84 ; Ordinal number of the operand in an insn's semantic
85 ; description. There is no relation between the number and
86 ; where in the semantics the operand appears. An operand that
87 ; is both read and written are given separate ordinal numbers
88 ; (inputs are treated separately from outputs).
91 ; Boolean indicating if the operand is conditionally
92 ; referenced. #f means the operand is always referenced by
96 ; whether (and by how much) this instance of the operand is
103 ; The default make! assigns the default h/w selector.
107 (lambda (self location name comment attrs
108 hw-name mode-name index handlers getter setter)
109 (elm-set! self 'location location)
110 (elm-set! self 'name name)
111 (elm-set! self 'sem-name name)
112 (elm-set! self 'pretty-sem-name hw-name)
113 (elm-set! self 'comment comment)
114 (elm-set! self 'attrs attrs)
115 (elm-set! self 'hw-name hw-name)
116 (elm-set! self 'mode-name mode-name)
117 (elm-set! self 'selector hw-selector-default)
118 (elm-set! self 'index index)
119 (elm-set! self 'handlers handlers)
120 (elm-set! self 'getter getter)
121 (elm-set! self 'setter setter)
125 ; FIXME: The prefix field- doesn't seem right. Indices needn't be
126 ; ifields, though for operands defined in .cpu files they usually are.
127 (method-make-forward! <operand> 'index '(field-start field-length))
131 (define op:sem-name (elm-make-getter <operand> 'sem-name))
132 (define op:set-sem-name! (elm-make-setter <operand> 'sem-name))
133 (define op:set-pretty-sem-name! (elm-make-setter <operand> 'pretty-sem-name))
134 (define op:hw-name (elm-make-getter <operand> 'hw-name))
135 (define op:mode-name (elm-make-getter <operand> 'mode-name))
136 (define op:selector (elm-make-getter <operand> 'selector))
137 ; FIXME: op:index should be named op:hwindex.
138 (define op:index (elm-make-getter <operand> 'index))
139 (define op:handlers (elm-make-getter <operand> 'handlers))
140 (define op:getter (elm-make-getter <operand> 'getter))
141 (define op:setter (elm-make-getter <operand> 'setter))
142 (define op:num (elm-make-getter <operand> 'num))
143 (define op:set-num! (elm-make-setter <operand> 'num))
144 (define op:cond? (elm-make-getter <operand> 'cond?))
145 (define op:set-cond?! (elm-make-setter <operand> 'cond?))
146 (define op:delay (elm-make-getter <operand> 'delayed))
147 (define op:set-delay! (elm-make-setter <operand> 'delayed))
149 ; Compute the hardware type lazily.
150 ; FIXME: op:type should be named op:hwtype or some such.
153 (let ((getter (elm-make-getter <operand> 'type)))
155 (let ((type (getter op)))
158 (let* ((hw-name (op:hw-name op))
159 (hw-objs (current-hw-sem-lookup hw-name)))
160 (if (!= (length hw-objs) 1)
161 (error "cannot resolve h/w reference" hw-name))
162 ((elm-make-setter <operand> 'type) op (car hw-objs))
166 ; Compute the operand's mode lazily (depends on hardware type which is
170 (let ((getter (elm-make-getter <operand> 'mode)))
172 (let ((mode (getter op)))
175 (let ((mode-name (op:mode-name op))
177 (let ((mode (if (eq? mode-name 'DFLT)
178 (hw-default-mode type)
179 (mode:lookup mode-name))))
180 ((elm-make-setter <operand> 'mode) op mode)
184 (method-make! <operand> 'get-mode (lambda (self) (op:mode self)))
187 ; Result is the <ifield> object or #f if there is none.
189 (define (op-ifield op)
190 (logit 4 " op-ifield op= " (obj:name op)
191 ", indx= " (obj:name (op:index op)) "\n")
192 (let ((indx (op:index op)))
194 (let ((maybe-ifld (hw-index:value (op:index op))))
195 (logit 4 " ifld=" (obj:name maybe-ifld) "\n")
196 (cond ((ifield? maybe-ifld) maybe-ifld)
197 ((derived-ifield? maybe-ifld) maybe-ifld)
198 ((ifield? indx) indx)
199 ((derived-ifield? indx) indx)
204 ; Return mode to use for index or #f if scalar.
205 ; This can't use method-make-forward! as we need to call op:type to
206 ; resolve the hardware reference.
209 <operand> 'get-index-mode
210 (lambda (self) (send (op:type self) 'get-index-mode))
213 ; Return the operand's enum.
216 (string-upcase (string-append "@ARCH@_OPERAND_" (gen-sym op)))
219 ; Return a boolean indicating if X is an operand.
221 (define (operand? x) (class-instance? <operand> x))
223 ; Default gen-pretty-name method.
224 ; Return a C string of the name intended for users.
226 ; FIXME: The current implementation is a quick hack. Parallel execution
227 ; support can create operands with long names. e.g. h-memory-add-WI-src2-slo16
228 ; The eventual way this will be handled is to record with each operand the
229 ; entry number (or some such) in the operand instance table so that for
230 ; registers we can compute the register's name.
233 <operand> 'gen-pretty-name
235 (let* ((name (->string (if (elm-bound? self 'pretty-sem-name)
236 (elm-get self 'pretty-sem-name)
237 (if (elm-bound? self 'sem-name)
238 (elm-get self 'sem-name)
240 (pname (cond ((string=? "h-memory" (string-take 8 name)) "memory")
241 ((string=? "h-" (string-take 2 name)) (string-drop 2 name))
243 (string-append "\"" pname "\"")))
248 ; Create a copy of operand OP in mode NEW-MODE-NAME.
249 ; NOTE: Even if the mode isn't changing this creates a copy.
250 ; If OP has been subclassed the result must contain the complete class
251 ; (e.g. the behaviour of `object-copy-top').
252 ; NEW-MODE-NAME must be a valid numeric mode.
254 (define (op:new-mode op new-mode-name)
255 (let ((result (object-copy-top op)))
256 ; (logit 1 "op:new-mode op=" (op:sem-name op)
257 ; " class=" (object-class-name op)
258 ; " hw-name=" (op:hw-name op)
259 ; " mode=" (op:mode op)
260 ; " newmode=" new-mode-name)
261 ; (if (or (eq? new-mode-name 'DFLT)
262 ; (eq? new-mode-name 'VOID) ; temporary: for upward compatibility
263 ; (mode:eq? new-mode-name (op:mode op)))
264 ; ; Mode isn't changing.
267 ; See if new mode is supported by the hardware.
268 (if (hw-mode-ok? (op:type op) new-mode-name (op:index op))
269 (let ((new-mode (mode:lookup new-mode-name)))
271 (error "op:new-mode: internal error, bad mode"
273 (elm-xset! result 'mode-name new-mode-name)
274 (elm-xset! result 'mode new-mode)
276 (parse-error (make-obj-context op "op:new-mode")
277 (string-append "invalid mode for operand `"
278 (->string (obj:name op))
283 ; Return #t if operand OP references its h/w element in its natural mode.
285 (define (op-natural-mode? op)
286 (or (eq? (op:mode-name op) 'DFLT)
287 (mode-compatible? 'samesize (op:mode op) (hw-default-mode (op:type op))))
292 ; Return list of ifields used by OP.
294 (define (op-iflds-used op)
295 (if (derived-operand? op)
296 (collect op-iflds-used (derived-args op))
298 (let ((indx (op:index op)))
299 (if (and (eq? (hw-index:type indx) 'ifield)
300 (not (= (ifld-length (hw-index:value indx)) 0)))
301 (ifld-needed-iflds (hw-index:value indx))
305 ; The `hw-index' class.
306 ; [Was named `index' but that conflicts with the C library function and caused
307 ; problems when using Hobbit. And `index' is too generic a name anyway.]
309 ; An operand combines a hardware object with its index.
310 ; e.g. in an array of registers an operand serves to combine the register bank
311 ; with the instruction field that chooses which one.
312 ; Hardware elements are accessed via other means as well besides instruction
313 ; fields so we need a way to designate something as being an index.
314 ; The `hw-index' class does that. It serves as a facade to the underlying
316 ; ??? Not sure whether this is the best way to handle this or not.
318 ; NAME is the name of the index or 'anonymous.
319 ; This is used, for example, to give a name to the simulator extraction
321 ; TYPE is a symbol that indicates what VALUE is.
322 ; scalar: the hardware object is a scalar, no index is required
323 ; [MODE and VALUE are #f to denote "undefined" in this case]
324 ; constant: a (non-negative) integer (FIXME: rename to const)
325 ; enum: an enum value stored as (enum-name . (enum-lookup-val enum-name)),
326 ; i.e. (name value . enum-obj)
327 ; str-expr: a C expression as a string
328 ; rtx: an rtx to be expanded
329 ; ifield: an <ifield> object
330 ; derived-ifield: a <derived-ifield> object ???
331 ; operand: an <operand> object
332 ; ??? A useful simplification may be to always record the value as an rtx
333 ; [which may require extensions to rtl so is deferred].
334 ; ??? We could use runtime type identification, but doing things this way
335 ; adds more structure.
337 ; MODE is the mode of VALUE, as a <mode> object.
338 ; If DFLT, mode must be obtained from VALUE.
339 ; DFLT is only allowable for rtx and operand types.
341 (define <hw-index> (class-make '<hw-index> nil '(name type mode value) nil))
344 ; Use obj:name for `name'.
345 (define hw-index:type (elm-make-getter <hw-index> 'type))
346 (define hw-index:mode (elm-make-getter <hw-index> 'mode))
347 (define hw-index:value (elm-make-getter <hw-index> 'value))
349 ; Allow the mode to be specified by its name.
352 (lambda (self name type mode value)
353 (elm-set! self 'name name)
354 (elm-set! self 'type type)
355 (elm-set! self 'mode (mode-maybe-lookup mode))
356 (elm-set! self 'value value)
364 (elm-get self 'name))
369 <hw-index> 'get-atlist
371 (case (hw-index:type self)
372 ((ifield) (obj-atlist (hw-index:value self)))
373 (else atlist-empty)))
376 ; ??? Until other things settle.
378 <hw-index> 'field-start
380 (if (eq? (hw-index:type self) 'ifield)
381 (send (hw-index:value self) 'field-start)
385 <hw-index> 'field-length
387 (if (eq? (hw-index:type self) 'ifield)
388 (send (hw-index:value self) 'field-length)
392 ;; Return #t if index is a constant.
394 (define (hw-index-constant? hw-index)
395 (memq (hw-index:type hw-index) '(constant enum))
398 ;; Given that (hw-index-constant? hw-index) is true, return the value.
400 (define (hw-index-constant-value hw-index)
401 (case (hw-index:type hw-index)
402 ((constant) (hw-index:value hw-index))
403 ((enum) (hw-index-enum-value hw-index))
404 (else (error "invalid constant hw-index" hw-index)))
407 ;; Make an enum <hw-index> given the enum's name.
409 (define (make-enum-hw-index name enum-name)
410 (make <hw-index> name 'enum UINT
411 (cons enum-name (enum-lookup-val enum-name)))
414 ;; Given an enum <hw-index>, return the enum's name.
416 (define (hw-index-enum-name hw-index)
417 (car (hw-index:value hw-index))
420 ;; Given an enum <hw-index>, return the enum's value.
422 (define (hw-index-enum-value hw-index)
423 (cadr (hw-index:value hw-index))
426 ;; Given an enum <hw-index>, return the enum's object.
428 (define (hw-index-enum-obj hw-index)
429 (cddr (hw-index:value hw-index))
432 ; There only ever needs to be one of these objects, so create one.
434 (define hw-index-scalar
435 ; We can't use `make' here as the make! method calls mode:lookup which
436 ; (a) doesn't exist if we're compiled with Hobbit and mode.scm isn't
437 ; and (b) will fail anyway since #f isn't a valid mode.
438 (let ((scalar-index (new <hw-index>)))
439 (elm-xset! scalar-index 'name 'hw-index-scalar)
440 (elm-xset! scalar-index 'type 'scalar)
441 (elm-xset! scalar-index 'mode #f)
442 (elm-xset! scalar-index 'value #f)
443 (lambda () scalar-index))
446 ; Placeholder for indices of "anyof" operands.
447 ; There only needs to be one of these, so we create one and always use that.
449 (define hw-index-anyof
450 ; We can't use `make' here as the make! method calls mode:lookup which
451 ; (a) doesn't exist if we're compiled with Hobbit and mode.scm isn't
452 ; and (b) will fail anyway since #f isn't a valid mode.
453 (let ((anyof-index (new <hw-index>)))
454 (elm-xset! anyof-index 'name 'hw-index-anyof)
455 (elm-xset! anyof-index 'type 'scalar)
456 (elm-xset! anyof-index 'mode #f)
457 (elm-xset! anyof-index 'value #f)
458 (lambda () anyof-index))
461 (define hw-index-derived
462 ; We can't use `make' here as the make! method calls mode:lookup which
463 ; (a) doesn't exist if we're compiled with Hobbit and mode.scm isn't
464 ; and (b) will fail anyway since #f isn't a valid mode.
465 (let ((derived-index (new <hw-index>)))
466 (elm-xset! derived-index 'name 'hw-index-derived)
467 (elm-xset! derived-index 'type 'scalar)
468 (elm-xset! derived-index 'mode #f)
469 (elm-xset! derived-index 'value #f)
470 (lambda () derived-index))
473 ; Hardware selector support.
475 ; A hardware "selector" is like an index except is along an atypical axis
476 ; and thus is rarely used. It exists to support things like ASI's on Sparc.
478 ; What to pass to indicate "default selector".
479 ; (??? value is temporary choice to be revisited).
480 (define hw-selector-default '(symbol NONE))
482 (define (hw-selector-default? sel) (equal? sel hw-selector-default))
486 ; Return list of hardware elements refered to in OP-LIST
487 ; with no duplicates.
489 (define (op-nub-hw op-list)
490 ; Build a list of hw elements.
491 (let ((hw-list (map (lambda (op)
492 (if (hw-ref? op) ; FIXME: hw-ref? is undefined
496 ; Now build an alist of (name . obj) elements, take the nub, then the cdr.
497 ; ??? These lists tend to be small so sorting first is probably overkill.
499 (alist-nub (alist-sort (map (lambda (hw) (cons (obj:name hw) hw))
505 ; Utility of /operand-parse-[gs]etter to build the expected syntax,
506 ; for use in error messages.
508 (define (/operand-g/setter-syntax rank setter?)
511 (numbers->string (iota rank) " index"))
520 ; Parse a getter spec.
521 ; The syntax is (([index-names]) (... code ...)).
522 ; Omit `index-names' for scalar objects.
523 ; {rank} is the required number of elements in {index-names}.
525 (define (/operand-parse-getter context getter rank)
529 (if (or (not (list? getter))
530 (!= (length getter) 2)
531 (not (and (list? (car getter))
532 (= (length (car getter)) rank))))
534 (string-append "invalid getter, should be "
535 (/operand-g/setter-syntax rank #f))
537 (if (not (rtx? (cadr getter)))
538 (parse-error context "invalid rtx expression" getter))
542 ; Parse a setter spec.
543 ; The syntax is (([index-names] newval) (... code ...)).
544 ; Omit `index-names' for scalar objects.
545 ; {rank} is the required number of elements in {index-names}.
547 (define (/operand-parse-setter context setter rank)
551 (if (or (not (list? setter))
552 (!= (length setter) 2)
553 (not (and (list? (car setter))
554 (= (+ 1 (length (car setter)) rank)))))
556 (string-append "invalid setter, should be "
557 (/operand-g/setter-syntax rank #t))
559 (if (not (rtx? (cadr setter)))
560 (parse-error context "invalid rtx expression" setter))
564 ; Parse an operand definition.
565 ; This is the main routine for building an operand object from a
566 ; description in the .cpu file.
567 ; All arguments are in raw (non-evaluated) form.
568 ; The result is the parsed object or #f if object isn't for selected mach(s).
569 ; ??? This only takes insn fields as the index. May need another proc (or an
570 ; enhancement of this one) that takes other kinds of indices.
572 (define (/operand-parse context name comment attrs hw mode index handlers getter setter)
573 (logit 2 "Processing operand " name " ...\n")
575 ;; Pick out name first to augment the error context.
576 (let* ((name (parse-name context name))
577 (context (context-append-name context name))
578 (atlist-obj (atlist-parse context attrs "cgen_operand"))
579 (isa-name-list (atlist-attr-value atlist-obj 'ISA #f)))
581 ;; Verify all specified ISAs are valid.
582 (if (not (all-true? (map current-isa-lookup isa-name-list)))
583 (parse-error context "unknown isa in isa list" isa-name-list))
585 (if (keep-atlist? atlist-obj #f)
587 (let ((hw-objs (current-hw-sem-lookup hw))
588 (mode-obj (parse-mode-name context mode))
589 (index-val (cond ((integer? index)
591 ((and (symbol? index) (enum-lookup-val index))
593 ((and (symbol? index) (current-ifld-lookup index isa-name-list))
597 (parse-error context "unknown enum or ifield" index)
598 (parse-error context "invalid operand index" index))))))
601 (parse-error context "unknown mode" mode))
602 ;; Disallow some obviously invalid numeric indices.
603 (if (and (number? index-val)
604 (or (not (integer? index-val))
606 (parse-error context "invalid integer index" index))
607 ;; If an enum is used, it must be non-negative.
608 (if (and (pair? index-val)
609 (< (car index-val) 0))
610 (parse-error context "negative enum value" index))
611 ;; NOTE: Don't validate HW until we know whether this operand
612 ;; will be kept or not. If not, HW may have been discarded too.
614 (parse-error context "unknown hardware element" hw))
616 ;; At this point INDEX-VAL is either an integer, (value . enum-obj),
617 ;; or an <ifield> object.
618 ;; Since we can't look up the hardware element at this time
619 ;; [well, actually we should be able to with a bit of work],
620 ;; we determine scalarness from an index of f-nil.
622 (cond ((integer? index-val)
623 (make <hw-index> (symbol-append 'i- name)
624 ;; FIXME: constant -> const
625 'constant UINT index-val))
626 ((pair? index-val) ;; enum?
627 (make <hw-index> (symbol-append 'i- name)
628 'enum UINT (cons index index-val)))
629 ((ifld-nil? index-val)
632 (make <hw-index> (symbol-append 'i- name)
633 'ifield UINT index-val)))))
635 (context-location context)
637 (parse-comment context comment)
638 ;; Copy FLD's attributes so one needn't duplicate attrs like
639 ;; PCREL-ADDR, etc. An operand inherits the attributes of
640 ;; its field. They are overridable of course, which is why we use
641 ;; `atlist-append' here.
642 (if (ifield? index-val)
643 (atlist-append atlist-obj (obj-atlist index-val))
645 hw ;; note that this is the hw's name, not an object
646 mode ;; ditto, this is a name, not an object
648 (parse-handlers context '(parse print) handlers)
649 (/operand-parse-getter context getter (if scalar? 0 1))
650 (/operand-parse-setter context setter (if scalar? 0 1))
654 (logit 2 "Ignoring " name ".\n")
658 ; Read an operand description.
659 ; This is the main routine for analyzing operands in the .cpu file.
660 ; CONTEXT is a <context> object for error messages.
661 ; ARG-LIST is an associative list of field name and field value.
662 ; /operand-parse is invoked to create the <operand> object.
664 (define (/operand-read context . arg-list)
670 (mode 'DFLT) ; use default mode of TYPE
677 (let loop ((arg-list arg-list))
680 (let ((arg (car arg-list))
681 (elm-name (caar arg-list)))
683 ((name) (set! name (cadr arg)))
684 ((comment) (set! comment (cadr arg)))
685 ((attrs) (set! attrs (cdr arg)))
686 ((type) (set! type (cadr arg)))
687 ((mode) (set! mode (cadr arg)))
688 ((index) (set! index (cadr arg)))
689 ((handlers) (set! handlers (cdr arg)))
690 ((getter) (set! getter (cdr arg)))
691 ((setter) (set! setter (cdr arg)))
692 (else (parse-error context "invalid operand arg" arg)))
693 (loop (cdr arg-list)))))
695 ; Now that we've identified the elements, build the object.
696 (/operand-parse context name comment attrs type mode index handlers
700 ; Define an operand object, name/value pair list version.
702 (define define-operand
704 (let ((op (apply /operand-read (cons (make-current-context "define-operand")
707 (current-op-add! op))
711 ; Define an operand object, all arguments specified.
713 (define (define-full-operand name comment attrs type mode index handlers getter setter)
714 (let ((op (/operand-parse (make-current-context "define-full-operand")
716 type mode index handlers getter setter)))
718 (current-op-add! op))
724 ; Derived operands are used to implement operands more complex than just
725 ; the mapping of an instruction field to a register bank. Their present
726 ; raison d'etre is to create a new axis on which to implement the complex
727 ; addressing modes of the i386 and m68k. The brute force way of describing
728 ; these instruction sets would be to have one `dni' per addressing mode
729 ; per instruction. What's needed is to abstract away the various addressing
730 ; modes within something like operands.
732 ; ??? While internally we end up with the "brute force" approach, in and of
733 ; itself that's ok because it's an internal implementation issue.
736 ; ??? Another way to go is to have one dni per addressing mode. That seems
737 ; less clean though as one dni would be any of add, sub, and, or, xor, etc.
739 ; ??? Some addressing modes have side-effects (e.g. pre-dec, etc. like insns).
740 ; This can be represented, but if two operands have side-effects special
741 ; trickery may be required to get the order of side-effects right. Need to
742 ; avoid any "trickery" at all.
744 ; ??? Not yet handled are modelling parameters.
745 ; ??? Not yet handled are the handlers,getter,setter spec of normal operands.
747 ; ??? Division of class members b/w <operand> and <derived-operand> is wip.
748 ; ??? As is potential introduction of other classes to properly organize
751 (define <derived-operand>
752 (class-make '<derived-operand>
755 ; Args (list of <operands> objects).
761 ; Base ifield, common to all choices.
765 ; <derived-ifield> object.
768 ; Assertions of any ifield values or #f if none.
769 (ifield-assertion . #f)
774 ;; <derived-operand> constructor.
775 ;; MODE is a <mode> object.
778 <derived-operand> 'make!
779 (lambda (self name comment attrs mode
780 args syntax base-ifield encoding ifield-assertion
782 (elm-set! self 'name name)
783 (elm-set! self 'comment comment)
784 (elm-set! self 'attrs attrs)
785 (elm-set! self 'sem-name name)
786 (elm-set! self 'pretty-sem-name #f) ;; FIXME
787 (elm-set! self 'hw-name #f) ;; FIXME
788 (elm-set! self 'mode mode)
789 (elm-set! self 'mode-name (obj:name mode))
790 (elm-set! self 'getter getter)
791 (elm-set! self 'setter setter)
792 ;; These are the additional fields in <derived-operand>.
793 (elm-set! self 'args args)
794 (elm-set! self 'syntax syntax)
795 (elm-set! self 'base-ifield base-ifield)
796 (elm-set! self 'encoding encoding)
797 (elm-set! self 'ifield-assertion ifield-assertion)
801 (define (derived-operand? x) (class-instance? <derived-operand> x))
803 (define-getters <derived-operand> derived
804 (args syntax base-ifield encoding ifield-assertion)
807 ; "anyof" operands are subclassed from derived operands.
808 ; They typically handle multiple addressing modes of CISC architectures.
810 (define <anyof-operand>
811 (class-make '<anyof-operand>
814 ; Base ifield, common to all choices.
818 ; List of <derived-operand> objects.
819 ; ??? Maybe allow <operand>'s too?
825 (define (anyof-operand? x) (class-instance? <anyof-operand> x))
828 <anyof-operand> 'make!
829 (lambda (self name comment attrs mode-name base-ifield choices)
830 (elm-set! self 'name name)
831 (elm-set! self 'comment comment)
832 (elm-set! self 'attrs attrs)
833 (elm-set! self 'sem-name name)
834 (elm-set! self 'pretty-sem-name #f) ;; FIXME
835 (elm-set! self 'hw-name #f) ;; FIXME
836 (elm-set! self 'mode-name mode-name)
837 (elm-set! self 'base-ifield base-ifield)
838 (elm-set! self 'choices choices)
839 ; Set index to a special marker value.
840 (elm-set! self 'index (hw-index-anyof))
844 (define-getters <anyof-operand> anyof (choices))
846 ; Derived/Anyof parsing support.
848 ; Subroutine of /derived-operand-parse to parse the encoding.
849 ; The result is a <derived-ifield> object.
850 ; The {owner} member still needs to be set!
852 (define (/derived-parse-encoding context isa-name-list operand-name encoding)
853 (if (or (null? encoding)
854 (not (list? encoding)))
855 (parse-error context "encoding not a list" encoding))
856 (if (not (eq? (car encoding) '+))
857 (parse-error context "encoding must begin with `+'" encoding))
859 ; ??? Calling /parse-insn-format is a quick hack.
860 ; It's an internal routine of some other file.
861 (let ((iflds (/parse-insn-format context #f isa-name-list encoding)))
862 (make <derived-ifield>
864 'derived-ifield ; (string-append "<derived-ifield> for " operand-name)
871 ;; Subroutine of /derived-operand-parse to parse the ifield assertion.
872 ;; The ifield assertion is either () or a (restricted) RTL expression
873 ;; asserting something about the ifield values of the containing insn.
874 ;; The result is #f if the assertion is (), or the canonical rtl.
876 (define (/derived-parse-ifield-assertion context isa-name-list ifield-assertion)
877 (if (null? ifield-assertion)
879 (rtx-canonicalize context 'INT isa-name-list nil ifield-assertion))
882 ; Parse a derived operand definition.
883 ; This is the main routine for building a derived operand object from a
884 ; description in the .cpu file.
885 ; All arguments are in raw (non-evaluated) form.
886 ; The result is the parsed object or #f if object isn't for selected mach(s).
888 ; ??? Currently no support for handlers(,???) found in normal operands.
889 ; Later, when necessary.
891 (define (/derived-operand-parse context name comment attrs mode
893 base-ifield encoding ifield-assertion
895 (logit 2 "Processing derived operand " name " ...\n")
897 ;; Pick out name first to augment the error context.
898 (let* ((name (parse-name context name))
899 (context (context-append-name context name))
900 (atlist-obj (atlist-parse context attrs "cgen_operand"))
901 (isa-name-list (atlist-attr-value atlist-obj 'ISA #f)))
903 ;; Verify all specified ISAs are valid.
904 (if (not (all-true? (map current-isa-lookup isa-name-list)))
905 (parse-error context "unknown isa in isa list" isa-name-list))
907 (if (keep-atlist? atlist-obj #f)
909 (let* ((mode-obj (parse-mode-name context mode))
910 (parsed-encoding (/derived-parse-encoding context isa-name-list
914 (parse-error context "unknown mode" mode))
917 (make <derived-operand>
919 (parse-comment context comment)
923 (if (not (symbol? a))
924 (parse-error context "arg not a symbol" a))
925 (let ((op (current-op-lookup a isa-name-list)))
927 (parse-error context "not an operand" a))
931 base-ifield ; FIXME: validate
933 (/derived-parse-ifield-assertion context isa-name-list
937 (/operand-parse-getter
940 (rtx-canonicalize context mode
946 (/operand-parse-setter
948 (list (append args '(newval))
949 (rtx-canonicalize context 'VOID
951 (list (list 'newval mode #f))
955 (elm-set! result 'hw-name (obj:name (hardware-for-mode mode-obj)))
956 ;(elm-set! result 'hw-name (obj:name parsed-encoding))
957 ;(elm-set! result 'hw-name base-ifield)
958 (elm-set! result 'index parsed-encoding)
959 ; (elm-set! result 'index (hw-index-derived)) ; A temporary dummy
960 (logit 2 " new derived-operand; name= " name
961 ", hw-name= " (op:hw-name result)
962 ", index=" (obj:name parsed-encoding) "\n")
963 (derived-ifield-set-owner! parsed-encoding result)
967 (logit 2 "Ignoring " name ".\n")
971 ; Read a derived operand description.
972 ; This is the main routine for analyzing derived operands in the .cpu file.
973 ; CONTEXT is a <context> object for error messages.
974 ; ARG-LIST is an associative list of field name and field value.
975 ; /derived-operand-parse is invoked to create the <derived-operand> object.
977 (define (/derived-operand-read context . arg-list)
982 (mode 'DFLT) ; use default mode of TYPE
987 (ifield-assertion nil)
992 (let loop ((arg-list arg-list))
995 (let ((arg (car arg-list))
996 (elm-name (caar arg-list)))
998 ((name) (set! name (cadr arg)))
999 ((comment) (set! comment (cadr arg)))
1000 ((attrs) (set! attrs (cdr arg)))
1001 ((mode) (set! mode (cadr arg)))
1002 ((args) (set! args (cadr arg)))
1003 ((syntax) (set! syntax (cadr arg)))
1004 ((base-ifield) (set! base-ifield (cadr arg)))
1005 ((encoding) (set! encoding (cadr arg)))
1006 ((ifield-assertion) (set! ifield-assertion (cadr arg)))
1007 ((getter) (set! getter (cadr arg)))
1008 ((setter) (set! setter (cadr arg)))
1009 (else (parse-error context "invalid derived-operand arg" arg)))
1010 (loop (cdr arg-list)))))
1012 ; Now that we've identified the elements, build the object.
1013 (/derived-operand-parse context name comment attrs mode args
1014 syntax base-ifield encoding ifield-assertion
1018 ; Define a derived operand object, name/value pair list version.
1020 (define define-derived-operand
1022 (let ((op (apply /derived-operand-read
1023 (cons (make-current-context "define-derived-operand")
1026 (current-op-add! op))
1030 ; Define a derived operand object, all arguments specified.
1031 ; ??? Not supported (yet).
1033 ;(define (define-full-derived-operand name comment attrs mode ...)
1034 ; (let ((op (/derived-operand-parse (make-current-context "define-full-derived-operand")
1035 ; name comment attrs
1038 ; (current-op-add! op))
1042 ; Parse an "anyof" choice, which is a derived-operand name.
1043 ; The result is {choice} unchanged.
1045 (define (/anyof-parse-choice context choice isa-name-list)
1046 (if (not (symbol? choice))
1047 (parse-error context "anyof choice not a symbol" choice))
1048 (let ((op (current-op-lookup choice isa-name-list)))
1049 (if (not (derived-operand? op))
1050 (parse-error context "anyof choice not a derived-operand" choice))
1054 ; Parse an "anyof" derived operand.
1055 ; This is the main routine for building a derived operand object from a
1056 ; description in the .cpu file.
1057 ; All arguments are in raw (non-evaluated) form.
1058 ; The result is the parsed object or #f if object isn't for selected mach(s).
1060 ; ??? Currently no support for handlers(,???) found in normal operands.
1061 ; Later, when necessary.
1063 (define (/anyof-operand-parse context name comment attrs mode
1064 base-ifield choices)
1065 (logit 2 "Processing anyof operand " name " ...\n")
1067 ;; Pick out name first to augment the error context.
1068 (let* ((name (parse-name context name))
1069 (context (context-append-name context name))
1070 (atlist-obj (atlist-parse context attrs "cgen_operand")))
1072 (if (keep-atlist? atlist-obj #f)
1074 (let ((mode-obj (parse-mode-name context mode))
1075 (isa-name-list (atlist-attr-value atlist-obj 'ISA #f)))
1077 (parse-error context "unknown mode" mode))
1079 (make <anyof-operand>
1081 (parse-comment context comment)
1086 (/anyof-parse-choice context c isa-name-list))
1090 (logit 2 "Ignoring " name ".\n")
1094 ; Read an anyof operand description.
1095 ; This is the main routine for analyzing anyof operands in the .cpu file.
1096 ; CONTEXT is a <context> object for error messages.
1097 ; ARG-LIST is an associative list of field name and field value.
1098 ; /anyof-operand-parse is invoked to create the <anyof-operand> object.
1100 (define (/anyof-operand-read context . arg-list)
1105 (mode 'DFLT) ; use default mode of TYPE
1110 (let loop ((arg-list arg-list))
1111 (if (null? arg-list)
1113 (let ((arg (car arg-list))
1114 (elm-name (caar arg-list)))
1116 ((name) (set! name (cadr arg)))
1117 ((comment) (set! comment (cadr arg)))
1118 ((attrs) (set! attrs (cdr arg)))
1119 ((mode) (set! mode (cadr arg)))
1120 ((base-ifield) (set! base-ifield (cadr arg)))
1121 ((choices) (set! choices (cdr arg)))
1122 (else (parse-error context "invalid anyof-operand arg" arg)))
1123 (loop (cdr arg-list)))))
1125 ; Now that we've identified the elements, build the object.
1126 (/anyof-operand-parse context name comment attrs mode base-ifield choices))
1129 ; Define an anyof operand object, name/value pair list version.
1131 (define define-anyof-operand
1133 (let ((op (apply /anyof-operand-read
1134 (cons (make-current-context "define-anyof-operand")
1137 (current-op-add! op))
1141 ; Utilities to flatten out the <anyof-operand> derivation heirarchy.
1143 ; Utility class used when instantiating insns with derived operands.
1144 ; This collects together in one place all the appropriate data of an
1145 ; instantiated "anyof" operand.
1147 (define <anyof-instance>
1148 (class-make '<anyof-instance>
1149 '(<derived-operand>)
1151 ; <anyof-operand> object we were instantiated from.
1157 (method-make-make! <anyof-instance>
1158 '(name comment attrs mode
1159 args syntax base-ifield encoding ifield-assertion
1160 getter setter parent)
1163 (define-getters <anyof-instance> anyof-instance (parent))
1165 (define (anyof-instance? x) (class-instance? <anyof-instance> x))
1167 ; Return initial list of known ifield values in {anyof-instance}.
1169 (define (/anyof-initial-known anyof-instance)
1170 (assert (derived-operand? anyof-instance))
1171 (let ((encoding (derived-encoding anyof-instance)))
1172 (assert (derived-ifield? encoding))
1173 (ifld-known-values (derived-ifield-subfields encoding)))
1176 ; Return true if {anyof-instance} satisfies its ifield assertions.
1177 ; {known-values} is the {known} argument to rtx-solve.
1179 (define (anyof-satisfies-assertions? anyof-instance known-values)
1180 (assert (derived-operand? anyof-instance))
1181 (let ((assertion (derived-ifield-assertion anyof-instance)))
1183 (rtx-solve (make-obj-context anyof-instance #f)
1184 anyof-instance ; owner
1190 ; Subroutine of /anyof-merge-subchoices.
1191 ; Merge syntaxes of VALUE-NAMES/VALUES into SYNTAX.
1194 ; If SYNTAX is "$a+$b", and VALUE-NAMES is (b), and VALUES is
1195 ; ("$c+$d"-object), then return "$a+$c+$d".
1197 (define (/anyof-syntax anyof-instance)
1198 (elm-get anyof-instance 'syntax)
1201 (define (/anyof-name anyof-instance)
1202 (elm-get anyof-instance 'name)
1205 ; CONTAINER is the <anyof-operand> containing SYNTAX.
1207 (define (/anyof-merge-syntax syntax value-names values container)
1208 (let* ((isa-name-list (obj-isa-list container))
1209 (syntax-elements (syntax-break-out syntax isa-name-list)))
1210 (syntax-make (map (lambda (e)
1211 (if (anyof-operand? e)
1212 (let* ((name (obj:name e))
1213 (indx (element-lookup-index name value-names 0)))
1215 (error "Name " name " not one of " values)
1217 (/anyof-syntax (list-ref values indx)))
1222 ; Subroutine of /anyof-merge-subchoices.
1223 ; Merge syntaxes of {value-names}/{values} into <derived-ifield> {encoding}.
1224 ; The result is a new <derived-ifield> object with subfields matching
1225 ; {value-names} replaced with {values}.
1226 ; {container} is the containing <anyof-operand>.
1229 ; If {encoding} is (a-ifield-object b-anyof-ifield-object), and {value-names}
1230 ; is (b), and {values} is (c-choice-of-b-object), then return
1231 ; (a-ifield-object c-choice-of-b-ifield-object).
1233 (define (/anyof-merge-encoding container encoding value-names values)
1234 (assert (derived-ifield? encoding))
1235 (let ((subfields (derived-ifield-subfields encoding))
1236 (result (object-copy-top encoding)))
1237 ; Delete all the elements that are being replaced with ifields from
1238 ; {values} and add the new ifields.
1239 (derived-ifield-set-subfields! result
1242 (not (memq (obj:name f) value-names)))
1244 (map derived-encoding values)))
1248 ; Subroutine of /anyof-merge-subchoices.
1249 ; Merge semantics of VALUE-NAMES/VALUES into GETTER.
1252 ; If GETTER is (mem QI foo), and VALUE-NAMES is (foo), and VALUES is
1253 ; ((add a b)-object), then return (mem QI (add a b)).
1255 (define (/anyof-merge-getter getter value-names values)
1256 ;(debug-repl-env getter value-names values)
1257 ; ??? This implementation is a quick hack, intended to evolve or be replaced.
1263 (let ((indx (element-lookup-index e value-names 0)))
1265 (op:getter (list-ref values indx))
1267 ((pair? e) ; pair? -> cheap non-null-list?
1268 (/anyof-merge-getter e value-names values))
1274 ; Subroutine of /anyof-merge-subchoices.
1275 ; Merge semantics of VALUE-NAMES/VALUES into SETTER.
1278 ; If SETTER is (set (mem QI foo) newval), and VALUE-NAMES is (foo),
1279 ; and VALUES is ((add a b)-object), then return
1280 ; (set (mem QI (add a b)) newval).
1282 ; ??? `newval' in this context is a reserved word.
1284 (define (/anyof-merge-setter setter value-names values)
1285 ;(debug-repl-env setter value-names values)
1286 ; ??? This implementation is a quick hack, intended to evolve or be replaced.
1289 ((rtx-single-set? setter)
1290 (let ((src (rtx-set-src setter))
1291 (dest (rtx-set-dest setter))
1292 (mode (rtx-mode setter))
1293 (options (rtx-options setter))
1294 (name (rtx-name setter)))
1295 (if (rtx-kind 'mem dest)
1297 (rtx-change-address dest
1298 (/anyof-merge-getter
1300 value-names values))))
1301 (set! src (/anyof-merge-getter src value-names values))
1302 (rtx-make name options mode dest src)))
1304 (error "/anyof-merge-setter: unsupported form" (car setter))))
1307 ; Subroutine of -sub-insn-make!.
1308 ; Merge semantics of VALUE-NAMES/VALUES into SEMANTICS.
1309 ; Defined here and not in insn.scm to keep it with the getter/setter mergers.
1312 ; If SEMANTICS is (mem QI foo), and VALUE-NAMES is (foo), and VALUES is
1313 ; ((add a b)-object), then return (mem QI (add a b)).
1315 (define (anyof-merge-semantics semantics value-names values)
1316 ;(debug-repl-env semantics value-names values)
1317 ; ??? This implementation is a quick hack, intended to evolve or be replaced.
1319 (cond ((not semantics)
1324 (let ((indx (element-lookup-index e value-names 0)))
1326 (/anyof-name (list-ref values indx))
1327 ; (op:sem-name (list-ref values indx))
1329 ((pair? e) ; pair? -> cheap non-null-list?
1330 (anyof-merge-semantics e value-names values))
1334 (logit 4 " merged semantics: [" semantics "] -> [" result "]\n")
1338 ; Subroutine of /anyof-merge-subchoices.
1339 ; Merge assertion of VALUE-NAMES/VALUES into ASSERTION.
1342 ; If ASSERTION is (ne f-base-reg 5), and VALUE-NAMES is
1343 ; (foo), and VALUES is ((ne f-mod 0)), then return
1344 ; (andif (ne f-base-reg 5) (ne f-mod 0)).
1346 ; FIXME: Perform simplification pass, based on combined set of known
1349 (define (/anyof-merge-ifield-assertion assertion value-names values)
1350 (let ((assertions (find identity
1352 (map derived-ifield-assertion values)))))
1353 (if (null? assertions)
1355 (rtx-combine 'andif assertions)))
1358 ; Subroutine of /anyof-all-subchoices.
1359 ; Return a copy of <derived-operand> CHOICE with NEW-ARGS from ANYOF-ARGS
1360 ; merged in. This is for when a derived operand is itself composed of
1362 ; ANYOF-ARGS is a list of <anyof-operand>'s to be replaced in CHOICE.
1363 ; NEW-ARGS is a corresponding list of values (<derived-operands>'s) of each
1364 ; element in ANYOF-ARGS.
1365 ; CONTAINER is the <anyof-operand> containing CHOICE.
1367 (define (/anyof-merge-subchoices container choice anyof-args new-args)
1368 (assert (all-true? (map anyof-operand? anyof-args)))
1369 (assert (all-true? (map derived-operand? new-args)))
1371 (let* ((arg-names (map obj:name anyof-args))
1372 (encoding (/anyof-merge-encoding container (derived-encoding choice)
1373 arg-names new-args))
1375 (make <anyof-instance>
1376 (apply symbol-append
1377 (cons (obj:name choice)
1378 (map (lambda (anyof)
1379 (symbol-append '- (obj:name anyof)))
1381 (obj:comment choice)
1384 (derived-args choice)
1385 (/anyof-merge-syntax (derived-syntax choice)
1388 (derived-base-ifield choice)
1390 (/anyof-merge-ifield-assertion (derived-ifield-assertion choice)
1391 anyof-args new-args)
1392 (/anyof-merge-getter (op:getter choice)
1394 (/anyof-merge-setter (op:setter choice)
1398 (elm-set! result 'index encoding)
1399 ; Creating the link from {encoding} to {result}.
1400 (derived-ifield-set-owner! encoding result)
1404 ; Subroutine of /anyof-all-choices-1.
1405 ; Return a list of all possible subchoices of <derived-operand> ANYOF-CHOICE,
1406 ; known to use <anyof-operand>'s itself.
1407 ; CONTAINER is the containing <anyof-operand>.
1409 (define (/anyof-all-subchoices container anyof-choice)
1410 ; Split args into anyof and non-anyof elements.
1411 (let* ((args (derived-args anyof-choice))
1412 (anyof-args (find anyof-operand? args)))
1414 (assert (not (null? anyof-args)))
1416 ; Iterate over all combinations.
1417 ; {todo} is a list with one element for each anyof argument.
1418 ; Each element is in turn a list of all <derived-operand> choices for the
1419 ; <anyof-operand>. The result we want is every possible combination.
1421 ; If {todo} is ((1 2 3) (a) (B C)) the result we want is
1422 ; ((1 a B) (1 a C) (2 a B) (2 a C) (3 a B) (3 a C)).
1424 ; Note that some of these values may be derived from nested
1425 ; <anyof-operand>'s which is why we recursively call /anyof-all-choices-1.
1426 ; ??? /anyof-all-choices-1 should cache the results.
1428 (let* ((todo (map /anyof-all-choices-1 anyof-args))
1429 (lengths (map length todo))
1430 (total (apply * lengths))
1433 ; ??? One might prefer a `do' loop here, but every time I see one I
1434 ; have to spend too long remembering its syntax.
1437 (let* ((indices (split-value lengths i))
1438 (new-args (map list-ref todo indices)))
1439 ;(display "new-args: " (current-error-port))
1440 ;(display (map obj:name new-args) (current-error-port))
1441 ;(newline (current-error-port))
1443 (cons (/anyof-merge-subchoices container
1453 ; Return an <anyof-instance> object from <derived-operand> {derop}, which is a
1454 ; choice of {anyof-operand}.
1456 (define (/anyof-instance-from-derived anyof-operand derop)
1457 (let* ((encoding (object-copy-top (derived-encoding derop)))
1459 (make <anyof-instance>
1464 (derived-args derop)
1465 (derived-syntax derop)
1466 (derived-base-ifield derop)
1468 (derived-ifield-assertion derop)
1472 ; Creating the link from {encoding} to {result}.
1473 (derived-ifield-set-owner! encoding result)
1477 ; Return list of <anyof-instance> objects, one for each possible variant of
1480 ; One could move this up into the cpu description file using pmacros.
1481 ; However, that's not the right way to go. How we currently implement
1482 ; the notion of derived operands is separate from the notion of having them
1483 ; in the description language. pmacros are not "in" the language (to the
1484 ; extent that the cpu description file reader "sees" them), they live
1485 ; above it. And the right way to do this is with something "in" the language.
1486 ; Derived operands are the first cut at it. They'll evolve or be replaced
1487 ; (and it's the implementation of them that will evolve first).
1489 (define (/anyof-all-choices-1 anyof-operand)
1490 (assert (anyof-operand? anyof-operand))
1494 ; For each choice, scan the operands for further derived operands.
1495 ; If found, replace the choice with the list of its subchoices.
1496 ; If not found, create an <anyof-instance> object for it. This is
1497 ; basically just a copy of the object, but {anyof-operand} is recorded
1498 ; with it so that we can later resolve `follows' specs.
1500 (let loop ((choices (anyof-choices anyof-operand)))
1501 (if (not (null? choices))
1502 (let* ((this (car choices))
1503 (args (derived-args this)))
1505 (if (any-true? (map anyof-operand? args))
1507 ; This operand has "anyof" operands so we need to turn this
1508 ; choice into a list of all possible subchoices.
1509 (let ((subchoices (/anyof-all-subchoices anyof-operand this)))
1511 (append subchoices result)))
1513 ; No <anyof-operand> arguments.
1515 (cons (/anyof-instance-from-derived anyof-operand this)
1518 (loop (cdr choices)))))
1520 (assert (all-true? (map anyof-instance? result)))
1524 ; Cover fn of /anyof-all-choices-1.
1525 ; Return list of <anyof-instance> objects, one for each possible variant of
1527 ; We want to delete choices that fail their ifield assertions, but since
1528 ; /anyof-all-choices-1 can recursively call itself, assertion checking is
1529 ; defered until it returns.
1531 (define (anyof-all-choices anyof-operand)
1532 (let ((all-choices (/anyof-all-choices-1 anyof-operand)))
1534 ; Delete ones that fail their ifield assertions.
1535 ; Sometimes there isn't enough information yet to completely do this.
1536 ; When that happens it is the caller's responsibility to deal with it.
1537 ; However, it is our responsibility to assert as much as we can.
1539 (anyof-satisfies-assertions? op
1540 (/anyof-initial-known op)))
1544 ; Operand utilities.
1546 ; Look up operand NAME in the operand table.
1547 ; This proc isolates the strategy we use to record operand objects.
1549 ; Look up an operand via SEM-NAME.
1551 (define (op:lookup-sem-name op-list sem-name)
1552 (let loop ((op-list op-list))
1553 (cond ((null? op-list) #f)
1554 ((eq? sem-name (op:sem-name (car op-list))) (car op-list))
1555 (else (loop (cdr op-list)))))
1558 ; Given an operand, return the starting bit number.
1559 ; Note that the field isn't necessarily contiguous.
1561 (define (op:start operand) (send operand 'field-start))
1563 ; Given an operand, return the total length in bits.
1564 ; Note that the field isn't necessarily contiguous.
1566 (define (op:length operand) (send operand 'field-length))
1568 ; Return a sorted list of operand lists.
1569 ; Each element in the inner list is an operand with the same name, but for
1570 ; whatever reason were defined separately.
1571 ; The outer list is sorted by name.
1573 (define (op-sort op-list)
1574 ; We assume there is at least one operand.
1576 (error "op-sort: no operands!"))
1577 ; First sort by name.
1578 (let ((sorted-ops (alpha-sort-obj-list op-list)))
1579 (let loop ((result nil)
1580 ; Current set of operands with same name.
1581 (this-elm (list (car sorted-ops)))
1582 (ops (cdr sorted-ops))
1585 ; Reverse things to keep them in file order (minimizes random
1586 ; changes in generated files).
1587 (reverse! (cons (reverse! this-elm) result))
1588 ; Not done. Check for new set.
1589 (if (eq? (obj:name (car ops)) (obj:name (car this-elm)))
1590 (loop result (cons (car ops) this-elm) (cdr ops))
1591 (loop (cons (reverse! this-elm) result) (list (car ops))
1595 ; FIXME: Not used anymore but leave in for now.
1596 ; Objects used in assembler syntax ($0, $1, ...).
1598 ;(define <syntax-operand>
1599 ; (class-make '<syntax-operand> nil '(number value) nil))
1600 ;(method-make-make! <syntax-operand> '(number))
1602 ;(define $0 (make <syntax-operand> 0))
1603 ;(define $1 (make <syntax-operand> 1))
1604 ;(define $2 (make <syntax-operand> 2))
1605 ;(define $3 (make <syntax-operand> 3))
1608 ;; This is a subclass of <operand>, used to give the simulator a place to
1609 ;; hang a couple of methods.
1610 ;; At the moment we only support one pc, a reasonable place to stop for now.
1612 (define <pc> (class-make '<pc> '(<operand>) nil nil))
1617 (send-next self '<pc> 'make!
1618 (builtin-location) 'pc "program counter"
1619 (atlist-parse (make-prefix-context "make! of pc")
1620 '(SEM-ONLY) "cgen_operand")
1621 'h-pc ;; FIXME: keep name h-pc hardwired?
1623 ;;(hw-index-scalar) ;; FIXME: change to this
1624 (make <hw-index> 'anonymous
1625 'ifield 'UINT (current-ifld-lookup 'f-nil))
1627 #f #f) ;; getter setter
1631 ; Return a boolean indicating if operand op is the pc.
1632 ; This must not call op:type. op:type will try to resolve a hardware
1633 ; element that may be multiply specified, and this is used in contexts
1634 ; where that's not possible.
1636 (define (pc? op) (class-instance? <pc> op))
1638 ; Called before/after loading the .cpu file to initialize/finalize.
1641 ; The pc operand used in rtl expressions.
1644 ; Called before reading a .cpu file in.
1646 (define (operand-init!)
1647 (reader-add-command! 'define-operand
1649 Define an operand, name/value pair list version.
1651 nil 'arg-list define-operand)
1652 (reader-add-command! 'define-full-operand
1654 Define an operand, all arguments specified.
1656 nil '(name comment attrs hw-type mode hw-index handlers getter setter)
1657 define-full-operand)
1659 (reader-add-command! 'define-derived-operand
1661 Define a derived operand, name/value pair list version.
1663 nil 'arg-list define-derived-operand)
1665 (reader-add-command! 'define-anyof-operand
1667 Define an anyof operand, name/value pair list version.
1669 nil 'arg-list define-anyof-operand)
1674 ; Install builtin operands.
1676 (define (operand-builtin!)
1677 ; Standard operand attributes.
1678 ; ??? Some of these can be combined into one.
1680 (define-attr '(for operand) '(type boolean) '(name NEGATIVE)
1681 '(comment "value is negative"))
1683 ; Operand plays a part in RELAXABLE/RELAXED insns.
1684 (define-attr '(for operand) '(type boolean) '(name RELAX)
1685 '(comment "operand is the relax participant"))
1687 ; ??? Might be able to make SEM-ONLY go away (or machine compute it)
1688 ; by scanning which operands are refered to by the insn syntax strings.
1689 (define-attr '(for operand) '(type boolean) '(name SEM-ONLY)
1690 '(comment "operand is for semantic use only"))
1692 ; Also (defined elsewhere): PCREL-ADDR ABS-ADDR.
1694 (set! pc (make <pc>))
1695 (obj-cons-attr! pc (all-isas-attr))
1696 (current-op-add! pc)
1701 ; Called after a .cpu file has been read in.
1703 (define (operand-finish!)