1 ; Operand instance support.
2 ; Copyright (C) 2000 Red Hat, Inc.
3 ; This file is part of CGEN.
5 ; Return C code to define one instance of operand object OP.
6 ; TYPE is one of "INPUT" or "OUTPUT".
8 (define (-gen-operand-instance op type)
9 (let ((index (op:index op)))
12 "\"" (gen-sym op) "\", "
13 (hw-enum (op:type op)) ", "
14 ; FIXME: Revisit CGEN_ prefix, use MODE (FOO) instead.
15 "CGEN_" (mode:enum (op:mode op)) ", "
16 ; FIXME: We don't handle memory properly yet. Later.
17 (cond ((memory? (op:type op))
19 ((has-attr? op 'SEM-ONLY)
21 ((eq? (hw-index:type index) 'ifield)
22 (if (= (ifld-length (hw-index:value index)) 0)
24 (string-append "OP_ENT ("
25 (string-upcase (gen-sym op))
27 ((eq? (hw-index:type index) 'constant)
29 (number->string (hw-index:value index))))
31 ", " (if (op:cond? op) "COND_REF" "0")
35 ; Return C code to define arrays of operand instances read from and written
36 ; to by <sformat> SFMT.
37 ; This is based on the semantics of the instruction.
38 ; ??? All runtime chosen values (e.g. a particular register in a register bank)
39 ; is assumed to be selected statically by the instruction. When some cpu
40 ; violates this assumption (say because a previous instruction determines
41 ; which register(s) the next instruction operates on), this will need
44 (define (-gen-operand-instance-table sfmt)
45 (let ((ins (sfmt-in-ops sfmt))
46 (outs (sfmt-out-ops sfmt)))
47 ; This used to exclude outputing anything if there were no ins or outs.
49 (sfmt-eg-insn sfmt) ; sanitize based on the example insn
51 "static const CGEN_OPINST "
52 (gen-sym sfmt) "_ops[] = {\n"
53 (string-map (lambda (op) (-gen-operand-instance op "INPUT"))
55 (string-map (lambda (op) (-gen-operand-instance op "OUTPUT"))
57 " { END, (const char *)0, (enum cgen_hw_type)0, (enum cgen_mode)0, (enum cgen_operand_type)0, 0, 0 }\n};\n\n")))
60 (define (-gen-operand-instance-tables)
63 /* Operand references. */
66 (gen-define-with-symcat "OP_ENT(op) @ARCH@_OPERAND_" "op")
68 #define INPUT CGEN_OPINST_INPUT
69 #define OUTPUT CGEN_OPINST_OUTPUT
70 #define END CGEN_OPINST_END
71 #define COND_REF CGEN_OPINST_COND_REF
74 (lambda () (string-write-map -gen-operand-instance-table (current-sfmt-list)))
86 ; Return C code for INSN's operand instance table.
88 (define (gen-operand-instance-ref insn)
89 (let* ((sfmt (insn-sfmt insn))
90 (ins (sfmt-in-ops sfmt))
91 (outs (sfmt-out-ops sfmt)))
92 (if (and (null? ins) (null? outs))
94 (string-append "& " (gen-sym sfmt) "_ops[0]")))
97 ; Return C code to define a table to lookup an insn's operand instance table.
99 (define (-gen-insn-opinst-lookup-table)
101 "/* Operand instance lookup table. */\n\n"
102 "static const CGEN_OPINST *@arch@_cgen_opinst_table[MAX_INSNS] = {\n"
103 " 0,\n" ; null first entry
108 (string-append " & " (gen-sym (insn-sfmt insn)) "_ops[0],\n")))
112 /* Function to call before using the operand instance table. */
115 @arch@_cgen_init_opinst_table (cd)
119 const CGEN_OPINST **oi = & @arch@_cgen_opinst_table[0];
120 CGEN_INSN *insns = (CGEN_INSN *) cd->insn_table.init_entries;
121 for (i = 0; i < MAX_INSNS; ++i)
122 insns[i].opinst = oi[i];
128 ; Return the maximum number of operand instances used by any insn.
129 ; If not generating the operand instance table, use a heuristic.
131 (define (max-operand-instances)
132 (if -opcodes-build-operand-instance-table?
135 (+ (length (sfmt-in-ops (insn-sfmt insn)))
136 (length (sfmt-out-ops (insn-sfmt insn)))))
137 (current-insn-list)))
141 ; Generate $arch-opinst.c.
143 (define (cgen-opinst.c)
144 (logit 1 "Generating " (current-arch-name) "-opinst.c ...\n")
146 ; If instruction semantics haven't been analyzed, do that now.
147 (if (not (arch-semantics-analyzed? CURRENT-ARCH))
149 (logit 1 "Instruction semantics weren't analyzed when .cpu file was loaded.\n")
150 (logit 1 "Doing so now ...\n")
151 (arch-analyze-insns! CURRENT-ARCH
153 #t) ; -opcodes-build-operand-instance-table?
157 (gen-c-copyright "Semantic operand instances for @arch@."
158 CURRENT-COPYRIGHT CURRENT-PACKAGE)
160 #include \"sysdep.h\"
161 #include \"ansidecl.h\"
163 #include \"symcat.h\"
164 #include \"@prefix@-desc.h\"
165 #include \"@prefix@-opc.h\"
167 -gen-operand-instance-tables
168 -gen-insn-opinst-lookup-table