; Opcode table support.
-; Copyright (C) 2000 Red Hat, Inc.
+; Copyright (C) 2000, 2005, 2009 Red Hat, Inc.
; This file is part of CGEN.
; Append code here to be run before insn parsing/etc.
; Define CGEN_INIT_{PARSE,INSERT,EXTRACT,PRINT} macros.
; ??? These were early escape hatches. Not currently used.
-(define (-gen-init-macros)
+(define (/gen-init-macros)
(logit 2 "Generating init macros ...\n")
(string-append
"#define CGEN_INIT_PARSE(od) \\
; Return C code to declare various ifield types,decls.
-(define (-gen-ifield-decls)
+(define (/gen-ifield-decls)
(logit 2 "Generating instruction field decls ...\n")
(string-append
"/* This struct records data prior to insertion or after extraction. */\n"
; Values < 128 are characters that must be matched.
; Values >= 128 are 128 + the index into the operand table.
-(define (compute-syntax strip-mnemonic? strip-mnem-operands? syntax op-macro)
- (let ((context "syntax computation")
+(define (compute-syntax strip-mnemonic? strip-mnem-operands? syntax op-macro
+ isa-name-list)
+ (let ((context (make-prefix-context "syntax computation"))
(syntax (if strip-mnemonic?
(strip-mnemonic strip-mnem-operands? syntax)
syntax)))
(if (= n 0)
(parse-error context "empty or invalid operand name" syntax))
(let ((operand (string->symbol (substring syn 1 (1+ n)))))
- (if (not (current-op-lookup operand))
+ (if (not (current-op-lookup operand isa-name-list))
(parse-error context "undefined operand " operand syntax)))
(loop (string-drop (1+ n) syn)
(string-append result op-macro " ("
; Return C code to define the syntax string for SYNTAX
; MNEM is the C value to use to represent the instruction's mnemonic.
; OP is the C macro to use to compute an operand's syntax value.
+; ISA-NAME-LIST is the list of ISA names in which the owning insn lives.
-(define (gen-syntax-entry mnem op syntax)
+(define (gen-syntax-entry mnem op syntax isa-name-list)
(string-append
"{ { "
mnem ", "
; `mnem' is used to represent the mnemonic, so we always want to strip it
; from the syntax string, regardless of the setting of `strip-mnemonic?'.
- (compute-syntax #t #f syntax op)
+ (compute-syntax #t #f syntax op isa-name-list)
" } }")
)
\f
; Return the table for IFMT, an <iformat> object.
-(define (-gen-ifmt-table-1 ifmt)
+(define (/gen-ifmt-table-1 ifmt)
(gen-obj-sanitize
(ifmt-eg-insn ifmt) ; sanitize based on the example insn
(string-list
- "static const CGEN_IFMT " (gen-sym ifmt) " = {\n"
+ "static const CGEN_IFMT " (gen-sym ifmt) " ATTRIBUTE_UNUSED = {\n"
" "
(number->string (ifmt-mask-length ifmt)) ", "
(number->string (ifmt-length ifmt)) ", "
; Generate the insn format table.
-(define (-gen-ifmt-table)
+(define (/gen-ifmt-table)
(string-write
"/* Instruction formats. */\n\n"
(gen-define-with-symcat "F(f) & @arch@_cgen_ifld_table[@ARCH@_" "f]")
- (string-list-map -gen-ifmt-table-1 (current-ifmt-list))
+ (string-list-map /gen-ifmt-table-1 (current-ifmt-list))
"#undef F\n\n"
)
)
; Return a declaration of an enum for all insns.
-(define (-gen-insn-enum)
+(define (/gen-insn-enum)
(logit 2 "Generating instruction enum ...\n")
(let ((insns (gen-obj-list-enums (non-multi-insns (current-insn-list)))))
(string-list
; ALL-ATTRS is a list of all instruction attributes.
; NUM-NON-BOOLS is the number of non-boolean insn attributes.
-(define (-gen-insn-opcode-entry insn all-attrs num-non-bools)
+(define (/gen-insn-opcode-entry insn all-attrs num-non-bools)
(gen-obj-sanitize
insn
(string-list
"/* " (insn-syntax insn) " */\n"
" {\n"
" " (gen-insn-handlers insn) ",\n"
- " " (gen-syntax-entry "MNEM" "OP" (insn-syntax insn)) ",\n"
+ " "
+ (gen-syntax-entry "MNEM" "OP" (insn-syntax insn) (obj-isa-list insn))
+ ",\n"
; ??? 'twould save space to put a pointer here and record format separately
" " (gen-ifmt-entry insn) ", "
;"0x" (number->string (insn-value insn) 16) ",\n"
; Generate insn table.
-(define (-gen-insn-opcode-table)
+(define (/gen-insn-opcode-table)
(logit 2 "Generating instruction opcode table ...\n")
(let* ((all-attrs (current-insn-attr-list))
(num-non-bools (attr-count-non-bools all-attrs)))
(lambda ()
(string-write-map (lambda (insn)
(logit 3 "Generating insn opcode entry for " (obj:name insn) " ...\n")
- (-gen-insn-opcode-entry insn all-attrs
+ (/gen-insn-opcode-entry insn all-attrs
num-non-bools))
(non-multi-insns (current-insn-list))))
\f
; Return assembly/disassembly hashing support.
-(define (-gen-hash-fns)
+(define (/gen-hash-fns)
(string-list
"\
#ifndef CGEN_ASM_HASH_P
; Hash support decls.
-(define (-gen-hash-decls)
+(define (/gen-hash-decls)
(string-list
"\
/* The hash functions are recorded here to help keep assembler code out of
the disassembler and vice versa. */
-static int asm_hash_insn_p PARAMS ((const CGEN_INSN *));
-static unsigned int asm_hash_insn PARAMS ((const char *));
-static int dis_hash_insn_p PARAMS ((const CGEN_INSN *));
-static unsigned int dis_hash_insn PARAMS ((const char *, CGEN_INSN_INT));
+static int asm_hash_insn_p (const CGEN_INSN *);
+static unsigned int asm_hash_insn (const char *);
+static int dis_hash_insn_p (const CGEN_INSN *);
+static unsigned int dis_hash_insn (const char *, CGEN_INSN_INT);
\n"
)
)
; Return a macro-insn expansion entry.
-(define (-gen-miexpn-entry entry)
+(define (/gen-miexpn-entry entry)
; FIXME: wip
"0, "
)
; Return a macro-insn table entry.
; ??? wip, not currently used.
-(define (-gen-minsn-table-entry minsn all-attrs num-non-bools)
+(define (/gen-minsn-table-entry minsn all-attrs num-non-bools)
(gen-obj-sanitize
minsn
(string-list
" {\n"
" "
"-1, " ; macro-insns are not currently enumerated, no current need to
- "\"" (obj:name minsn) "\", "
+ "\"" (obj:str-name minsn) "\", "
"\"" (minsn-mnemonic minsn) "\",\n"
- " " (gen-syntax-entry "MNEM" "OP" (minsn-syntax minsn)) ",\n"
+ " "
+ (gen-syntax-entry "MNEM" "OP" (minsn-syntax minsn) (obj-isa-list minsn))
+ ",\n"
" (PTR) & macro_" (gen-sym minsn) "_expansions[0],\n"
" "
(gen-obj-attr-defn 'minsn minsn all-attrs num-non-bools gen-insn-attr-mask)
; Return a macro-insn opcode table entry.
; ??? wip, not currently used.
-(define (-gen-minsn-opcode-entry minsn all-attrs num-non-bools)
+(define (/gen-minsn-opcode-entry minsn all-attrs num-non-bools)
(gen-obj-sanitize
minsn
(string-list
" {\n"
" "
"-1, " ; macro-insns are not currently enumerated, no current need to
- "\"" (obj:name minsn) "\", "
+ "\"" (obj:str-name minsn) "\", "
"\"" (minsn-mnemonic minsn) "\",\n"
- " " (gen-syntax-entry "MNEM" "OP" (minsn-syntax minsn)) ",\n"
+ " "
+ (gen-syntax-entry "MNEM" "OP" (minsn-syntax minsn) (obj-isa-list minsn))
+ ",\n"
" (PTR) & macro_" (gen-sym minsn) "_expansions[0],\n"
" "
(gen-obj-attr-defn 'minsn minsn all-attrs num-non-bools gen-insn-attr-mask)
; expanding to text, the macro-expansion could invoke the builder for each
; expanded-to insn.
-(define (-gen-macro-insn-table)
+(define (/gen-macro-insn-table)
(logit 2 "Generating macro-instruction table ...\n")
(let* ((minsn-list (map (lambda (minsn)
(if (has-attr? minsn 'ALIAS)
- (minsn-make-alias "gen-macro-insn-table" minsn)
+ (minsn-make-alias (make-prefix-context "gen-macro-insn-table")
+ minsn)
minsn))
(current-minsn-list)))
(all-attrs (current-insn-attr-list))
"/* Formats for ALIAS macro-insns. */\n\n"
(gen-define-with-symcat "F(f) & @arch@_cgen_ifld_table[@ARCH@_" "f]")
(lambda ()
- (string-write-map -gen-ifmt-table-1
+ (string-write-map /gen-ifmt-table-1
(map insn-ifmt (find (lambda (minsn)
(has-attr? minsn 'ALIAS))
minsn-list))))
(string-append
"static const CGEN_MINSN_EXPANSION macro_" (gen-sym minsn) "_expansions[] =\n"
"{\n"
- (string-map -gen-miexpn-entry
+ (string-map /gen-miexpn-entry
(minsn-expansions minsn))
" { 0, 0 }\n};\n\n")))
minsn-list))
; Simple macro-insns are emitted as aliases of real insns.
(if (has-attr? minsn 'ALIAS)
(gen-insn-table-entry minsn all-attrs num-non-bools)
- (-gen-minsn-table-entry minsn all-attrs num-non-bools)))
+ (/gen-minsn-table-entry minsn all-attrs num-non-bools)))
minsn-list))
"\
};
(logit 3 "Generating macro-insn table entry for " (obj:name minsn) " ...\n")
; Simple macro-insns are emitted as aliases of real insns.
(if (has-attr? minsn 'ALIAS)
- (-gen-insn-opcode-entry minsn all-attrs num-non-bools)
- (-gen-minsn-opcode-entry minsn all-attrs num-non-bools)))
+ (/gen-insn-opcode-entry minsn all-attrs num-non-bools)
+ (/gen-minsn-opcode-entry minsn all-attrs num-non-bools)))
minsn-list))
"\
};
\f
; Emit a function to call to initialize the opcode table.
-(define (-gen-opcode-init-fn)
+(define (/gen-opcode-init-fn)
(string-write
"\
-static void set_fields_bitsize PARAMS ((CGEN_FIELDS *, int));
-
/* Set the recorded length of the insn in the CGEN_FIELDS struct. */
static void
-set_fields_bitsize (fields, size)
- CGEN_FIELDS *fields;
- int size;
+set_fields_bitsize (CGEN_FIELDS *fields, int size)
{
CGEN_FIELDS_BITSIZE (fields) = size;
}
This plugs the opcode entries and macro instructions into the cpu table. */
void
-@arch@_cgen_init_opcode_table (cd)
- CGEN_CPU_DESC cd;
+@arch@_cgen_init_opcode_table (CGEN_CPU_DESC cd)
{
int i;
int num_macros = (sizeof (@arch@_cgen_macro_insn_table) /
sizeof (@arch@_cgen_macro_insn_table[0]));
const CGEN_IBASE *ib = & @arch@_cgen_macro_insn_table[0];
const CGEN_OPCODE *oc = & @arch@_cgen_macro_insn_opcode_table[0];
- CGEN_INSN *insns = (CGEN_INSN *) xmalloc (num_macros * sizeof (CGEN_INSN));
- memset (insns, 0, num_macros * sizeof (CGEN_INSN));
+ CGEN_INSN *insns = xmalloc (num_macros * sizeof (CGEN_INSN));
+
+ /* This test has been added to avoid a warning generated
+ if memset is called with a third argument of value zero. */
+ if (num_macros >= 1)
+ memset (insns, 0, num_macros * sizeof (CGEN_INSN));
for (i = 0; i < num_macros; ++i)
{
insns[i].base = &ib[i];
#define @ARCH@_OPC_H
"
- (lambda () (gen-extra-opc.h srcdir (current-arch-name))) ; from <arch>.opc
- -gen-insn-enum
- -gen-ifield-decls
- -gen-init-macros
+ (lambda () (gen-extra-opc.h (opc-file-path) (current-arch-name)))
+ /gen-insn-enum
+ /gen-ifield-decls
+ /gen-init-macros
"
#endif /* @ARCH@_OPC_H */
#include \"@prefix@-opc.h\"
#include \"libiberty.h\"
\n"
- (lambda () (gen-extra-opc.c srcdir (current-arch-name))) ; from <arch>.opc
- -gen-hash-decls
- -gen-ifmt-table
- -gen-insn-opcode-table
- -gen-macro-insn-table
- -gen-hash-fns
- -gen-opcode-init-fn
+ (lambda () (gen-extra-opc.c (opc-file-path) (current-arch-name)))
+ /gen-hash-decls
+ /gen-ifmt-table
+ /gen-insn-opcode-table
+ /gen-macro-insn-table
+ /gen-hash-fns
+ /gen-opcode-init-fn
)
)