1 ; Assembler/disassembler support generator.
2 ; Copyright (C) 2000, 2001, 2005, 2009 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 (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 (CGEN_CPU_DESC cd,
33 const char * errmsg = NULL;
34 /* Used by scalar operands that still need to be parsed. */
35 " (gen-ifield-default-type) " junk ATTRIBUTE_UNUSED;
43 /* xgettext:c-format */
44 fprintf (stderr, _(\"Unrecognized field %d while parsing.\\n\"), opindex);
52 ; Assembler initialization C code
53 ; Code is appended during processing.
55 (define /asm-init-code "")
56 (define (add-asm-init code)
57 (set! /asm-init-code (string-append /asm-init-code code))
60 ; Return C code to define the assembler init function.
61 ; This is called after opcode_open.
63 (define (/gen-init-asm-fn)
67 @arch@_cgen_init_asm (CGEN_CPU_DESC cd)
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
82 ; Generate C code that is inserted into the assembler source.
85 (logit 1 "Generating " (current-arch-name) "-asm.in ...\n")
87 ; No need for copyright, appended to file with one.
89 (lambda () (gen-extra-asm.c (opc-file-path) (current-arch-name)))
92 (lambda () (gen-handler-table "parse" opc-parse-handlers))
97 ; Disassembler support.
99 (define (/gen-print-switch)
100 (logit 2 "Generating print switch ...\n")
103 void @arch@_cgen_print_operand
104 (CGEN_CPU_DESC, int, PTR, CGEN_FIELDS *, 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 (CGEN_CPU_DESC cd,
126 void const *attrs ATTRIBUTE_UNUSED,
130 disassemble_info *info = (disassemble_info *) xinfo;
138 /* xgettext:c-format */
139 fprintf (stderr, _(\"Unrecognized field %d while printing insn.\\n\"),
146 ; Disassembler initialization C code.
147 ; Code is appended during processing.
149 (define /dis-init-code "")
150 (define (add-dis-init code)
151 (set! /dis-init-code (string-append /dis-init-code code))
154 ; Return C code to define the disassembler init function.
156 (define (/gen-init-dis-fn)
160 @arch@_cgen_init_dis (CGEN_CPU_DESC cd)
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;
172 ; Generate C code that is inserted into the disassembler source.
174 (define (cgen-dis.in)
175 (logit 1 "Generating " (current-arch-name) "-dis.in ...\n")
177 ; No need for copyright, appended to file with one.
179 (lambda () (gen-extra-dis.c (opc-file-path) (current-arch-name)))
182 (lambda () (gen-handler-table "print" opc-print-handlers))