OSDN Git Service

From 2001-03-01 Tom Rix <trix@redhat.com>:
[pf3gnuchains/pf3gnuchains3x.git] / cgen / opc-asmdis.scm
1 ; Assembler/disassembler support generator.
2 ; Copyright (C) 2000 Red Hat, Inc.
3 ; This file is part of CGEN.
4
5 ; Assembler support.
6
7 (define (-gen-parse-switch)
8   (logit 2 "Generating parse switch ...\n")
9   (string-list
10    "\
11 /* Main entry point for operand parsing.
12
13    This function is basically just a big switch statement.  Earlier versions
14    used tables to look up the function to use, but
15    - if the table contains both assembler and disassembler functions then
16      the disassembler contains much of the assembler and vice-versa,
17    - there's a lot of inlining possibilities as things grow,
18    - using a switch statement avoids the function call overhead.
19
20    This function could be moved into `parse_insn_normal', but keeping it
21    separate makes clear the interface between `parse_insn_normal' and each of
22    the handlers.
23 */
24
25 const char *
26 @arch@_cgen_parse_operand (cd, opindex, strp, fields)
27      CGEN_CPU_DESC cd;
28      int opindex;
29      const char ** strp;
30      CGEN_FIELDS * fields;
31 {
32   const char * errmsg = NULL;
33   /* Used by scalar operands that still need to be parsed.  */
34   " (gen-ifield-default-type) " junk;
35
36   switch (opindex)
37     {
38 "
39    (gen-switch 'parse)
40 "
41     default :
42       /* xgettext:c-format */
43       fprintf (stderr, _(\"Unrecognized field %d while parsing.\\n\"), opindex);
44       abort ();
45   }
46
47   return errmsg;
48 }\n\n")
49 )
50
51 ; Assembler initialization C code
52 ; Code is appended during processing.
53
54 (define -asm-init-code "")
55 (define (add-asm-init code)
56   (set! -asm-init-code (string-append -asm-init-code code))
57 )
58
59 ; Return C code to define the assembler init function.
60 ; This is called after opcode_open.
61
62 (define (-gen-init-asm-fn)
63   (string-append
64    "\
65 void
66 @arch@_cgen_init_asm (cd)
67      CGEN_CPU_DESC cd;
68 {
69   @arch@_cgen_init_opcode_table (cd);
70   @arch@_cgen_init_ibld_table (cd);
71   cd->parse_handlers = & @arch@_cgen_parse_handlers[0];
72   cd->parse_operand = @arch@_cgen_parse_operand;
73 "
74    -asm-init-code
75 "}\n\n"
76    )
77 )
78
79 ; Generate C code that is inserted into the assembler source.
80
81 (define (cgen-asm.in)
82   (logit 1 "Generating " (current-arch-name) "-asm.in ...\n")
83   (string-write
84    ; No need for copyright, appended to file with one.
85    "\n"
86    (lambda () (gen-extra-asm.c srcdir (current-arch-name))) ; from <arch>.opc
87    "\n"
88    -gen-parse-switch
89    (lambda () (gen-handler-table "parse" opc-parse-handlers))
90    -gen-init-asm-fn
91    )
92 )
93 \f
94 ; Disassembler support.
95
96 (define (-gen-print-switch)
97   (logit 2 "Generating print switch ...\n")
98   (string-list
99    "\
100 /* Main entry point for printing operands.
101    XINFO is a `void *' and not a `disassemble_info *' to not put a requirement
102    of dis-asm.h on cgen.h.
103
104    This function is basically just a big switch statement.  Earlier versions
105    used tables to look up the function to use, but
106    - if the table contains both assembler and disassembler functions then
107      the disassembler contains much of the assembler and vice-versa,
108    - there's a lot of inlining possibilities as things grow,
109    - using a switch statement avoids the function call overhead.
110
111    This function could be moved into `print_insn_normal', but keeping it
112    separate makes clear the interface between `print_insn_normal' and each of
113    the handlers.
114 */
115
116 void
117 @arch@_cgen_print_operand (cd, opindex, xinfo, fields, attrs, pc, length)
118      CGEN_CPU_DESC cd;
119      int opindex;
120      PTR xinfo;
121      CGEN_FIELDS *fields;
122      void const *attrs;
123      bfd_vma pc;
124      int length;
125 {
126  disassemble_info *info = (disassemble_info *) xinfo;
127
128   switch (opindex)
129     {
130 "
131    (gen-switch 'print)
132 "
133     default :
134       /* xgettext:c-format */
135       fprintf (stderr, _(\"Unrecognized field %d while printing insn.\\n\"),
136                opindex);
137     abort ();
138   }
139 }\n\n")
140 )
141
142 ; Disassembler initialization C code.
143 ; Code is appended during processing.
144
145 (define -dis-init-code "")
146 (define (add-dis-init code)
147   (set! -dis-init-code (string-append -dis-init-code code))
148 )
149
150 ; Return C code to define the disassembler init function.
151
152 (define (-gen-init-dis-fn)
153   (string-append
154    "
155 void
156 @arch@_cgen_init_dis (cd)
157      CGEN_CPU_DESC cd;
158 {
159   @arch@_cgen_init_opcode_table (cd);
160   @arch@_cgen_init_ibld_table (cd);
161   cd->print_handlers = & @arch@_cgen_print_handlers[0];
162   cd->print_operand = @arch@_cgen_print_operand;
163 "
164    -dis-init-code
165 "}\n\n"
166    )
167 )
168
169 ; Generate C code that is inserted into the disassembler source.
170
171 (define (cgen-dis.in)
172   (logit 1 "Generating " (current-arch-name) "-dis.in ...\n")
173   (string-write
174    ; No need for copyright, appended to file with one.
175    "\n"
176    (lambda () (gen-extra-dis.c srcdir (current-arch-name))) ; from <arch>.opc
177    "\n"
178    -gen-print-switch
179    (lambda () (gen-handler-table "print" opc-print-handlers))
180    -gen-init-dis-fn
181    )
182 )