1 ; Assembler/disassembler support generator.
2 ; Copyright (C) 2000, 2001 Red Hat, Inc.
3 ; This file is part of CGEN.
7 (define (-gen-parse-switch)
8 (logit 2 "Generating parse switch ...\n")
11 const char * @arch@_cgen_parse_operand
12 PARAMS ((CGEN_CPU_DESC, int, const char **, CGEN_FIELDS *));
14 /* Main entry point for operand parsing.
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.
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
28 @arch@_cgen_parse_operand (cd, opindex, strp, fields)
34 const char * errmsg = NULL;
35 /* Used by scalar operands that still need to be parsed. */
36 " (gen-ifield-default-type) " junk ATTRIBUTE_UNUSED;
44 /* xgettext:c-format */
45 fprintf (stderr, _(\"Unrecognized field %d while parsing.\\n\"), opindex);
53 ; Assembler initialization C code
54 ; Code is appended during processing.
56 (define -asm-init-code "")
57 (define (add-asm-init code)
58 (set! -asm-init-code (string-append -asm-init-code code))
61 ; Return C code to define the assembler init function.
62 ; This is called after opcode_open.
64 (define (-gen-init-asm-fn)
68 @arch@_cgen_init_asm (cd)
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;
81 ; Generate C code that is inserted into the assembler source.
84 (logit 1 "Generating " (current-arch-name) "-asm.in ...\n")
86 ; No need for copyright, appended to file with one.
88 (lambda () (gen-extra-asm.c (opc-file-path) (current-arch-name)))
91 (lambda () (gen-handler-table "parse" opc-parse-handlers))
96 ; Disassembler support.
98 (define (-gen-print-switch)
99 (logit 2 "Generating print switch ...\n")
102 void @arch@_cgen_print_operand
103 PARAMS ((CGEN_CPU_DESC, int, PTR, CGEN_FIELDS *,
104 void const *, bfd_vma, int));
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.
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.
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
122 @arch@_cgen_print_operand (cd, opindex, xinfo, fields, attrs, pc, length)
127 void const *attrs ATTRIBUTE_UNUSED;
131 disassemble_info *info = (disassemble_info *) xinfo;
139 /* xgettext:c-format */
140 fprintf (stderr, _(\"Unrecognized field %d while printing insn.\\n\"),
147 ; Disassembler initialization C code.
148 ; Code is appended during processing.
150 (define -dis-init-code "")
151 (define (add-dis-init code)
152 (set! -dis-init-code (string-append -dis-init-code code))
155 ; Return C code to define the disassembler init function.
157 (define (-gen-init-dis-fn)
161 @arch@_cgen_init_dis (cd)
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;
174 ; Generate C code that is inserted into the disassembler source.
176 (define (cgen-dis.in)
177 (logit 1 "Generating " (current-arch-name) "-dis.in ...\n")
179 ; No need for copyright, appended to file with one.
181 (lambda () (gen-extra-dis.c (opc-file-path) (current-arch-name)))
184 (lambda () (gen-handler-table "print" opc-print-handlers))