OSDN Git Service

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