OSDN Git Service

Hand patch: update to github/binutils.
[pf3gnuchains/pf3gnuchains4x.git] / cgen / opc-asmdis.scm
1 ; Assembler/disassembler support generator.
2 ; Copyright (C) 2000, 2001, 2005, 2009 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   (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 (CGEN_CPU_DESC cd,
29                            int opindex,
30                            const char ** strp,
31                            CGEN_FIELDS * fields)
32 {
33   const char * errmsg = NULL;
34   /* Used by scalar operands that still need to be parsed.  */
35   " (gen-ifield-default-type) " junk ATTRIBUTE_UNUSED;
36
37   switch (opindex)
38     {
39 "
40    (gen-switch 'parse)
41 "
42     default :
43       /* xgettext:c-format */
44       fprintf (stderr, _(\"Unrecognized field %d while parsing.\\n\"), opindex);
45       abort ();
46   }
47
48   return errmsg;
49 }\n\n")
50 )
51
52 ; Assembler initialization C code
53 ; Code is appended during processing.
54
55 (define /asm-init-code "")
56 (define (add-asm-init code)
57   (set! /asm-init-code (string-append /asm-init-code code))
58 )
59
60 ; Return C code to define the assembler init function.
61 ; This is called after opcode_open.
62
63 (define (/gen-init-asm-fn)
64   (string-append
65    "\
66 void
67 @arch@_cgen_init_asm (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 #ifdef CGEN_ASM_INIT_HOOK
74 CGEN_ASM_INIT_HOOK
75 #endif
76 "
77    /asm-init-code
78 "}\n\n"
79    )
80 )
81
82 ; Generate C code that is inserted into the assembler source.
83
84 (define (cgen-asm.in)
85   (logit 1 "Generating " (current-arch-name) "-asm.in ...\n")
86   (string-write
87    ; No need for copyright, appended to file with one.
88    "\n"
89    (lambda () (gen-extra-asm.c (opc-file-path) (current-arch-name)))
90    "\n"
91    /gen-parse-switch
92    (lambda () (gen-handler-table "parse" opc-parse-handlers))
93    /gen-init-asm-fn
94    )
95 )
96 \f
97 ; Disassembler support.
98
99 (define (/gen-print-switch)
100   (logit 2 "Generating print switch ...\n")
101   (string-list
102    "\
103 void @arch@_cgen_print_operand
104   (CGEN_CPU_DESC, int, PTR, CGEN_FIELDS *, 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 (CGEN_CPU_DESC cd,
123                            int opindex,
124                            void * xinfo,
125                            CGEN_FIELDS *fields,
126                            void const *attrs ATTRIBUTE_UNUSED,
127                            bfd_vma pc,
128                            int length)
129 {
130   disassemble_info *info = (disassemble_info *) xinfo;
131
132   switch (opindex)
133     {
134 "
135    (gen-switch 'print)
136 "
137     default :
138       /* xgettext:c-format */
139       fprintf (stderr, _(\"Unrecognized field %d while printing insn.\\n\"),
140                opindex);
141     abort ();
142   }
143 }\n\n")
144 )
145
146 ; Disassembler initialization C code.
147 ; Code is appended during processing.
148
149 (define /dis-init-code "")
150 (define (add-dis-init code)
151   (set! /dis-init-code (string-append /dis-init-code code))
152 )
153
154 ; Return C code to define the disassembler init function.
155
156 (define (/gen-init-dis-fn)
157   (string-append
158    "
159 void
160 @arch@_cgen_init_dis (CGEN_CPU_DESC cd)
161 {
162   @arch@_cgen_init_opcode_table (cd);
163   @arch@_cgen_init_ibld_table (cd);
164   cd->print_handlers = & @arch@_cgen_print_handlers[0];
165   cd->print_operand = @arch@_cgen_print_operand;
166 "
167    /dis-init-code
168 "}\n\n"
169    )
170 )
171
172 ; Generate C code that is inserted into the disassembler source.
173
174 (define (cgen-dis.in)
175   (logit 1 "Generating " (current-arch-name) "-dis.in ...\n")
176   (string-write
177    ; No need for copyright, appended to file with one.
178    "\n"
179    (lambda () (gen-extra-dis.c (opc-file-path) (current-arch-name)))
180    "\n"
181    /gen-print-switch
182    (lambda () (gen-handler-table "print" opc-print-handlers))
183    /gen-init-dis-fn
184    )
185 )