+2005-10-28 Dave Brolley <brolley@redhat.com>
+
+ Contribute the following changes:
+ 2005-09-19 Dave Brolley <brolley@redhat.com>
+
+ * attr.scm (gen-value-for-defn-raw): New methods.
+ (gen-value-for-defn): Don't test for 'SID-SIMULATOR. Call
+ gen-value-for-defn-raw.
+ * sid.scm (gen-obj-attr-sid-defn): Call gen-value-for-defn-raw.
+
+ 2002-12-13 Dave Brolley <brolley@redhat.com>
+
+ * utils-cgen.scm (gen-attr-type): Moved from sid.scm.
+ (-gen-attr-accessors): New function.
+ (gen-obj-attr-defn): Update terminating initializer.
+ (gen-obj-attr-end-defn): New function.
+ * sid.scm (gen-attr-type): Moved to utils-cgen.scm.
+ * sid-cpu.scm (cgen-desc.h): Generate code to include
+ "opcode/cgen-bitset.h"
+ * intrinsics.scm (kept-insn-isas): Correct the extraction of the isa
+ name.
+ * desc.scm ('gen-defn): Update terminating initializer.
+ * desc-cpu.scm (gen-ifld-decls): Call -gen-attr-accessors. Update
+ terminatinig initializer.
+ (gen-hw-decls): Ditto.
+ (gen-operand-decls): Ditto.
+ (gen-insn-decls): Ditto.
+ (-gen-hash-defines): Generate code to include "opcde/cgen-bitset.h"
+ (gen-insn-table): Update terminating initializer.
+ (-gen-cpu-open): Update generation of @arch@_cgen_rebuild_tables,
+ @arch@_cgen_cpu_open, @arch@_cgen_cpu_close.
+ * attr.scm (charmask-bytes): New function.
+ (bitset-attr->charmask): New function.
+ (<bitset-attribute>): Handle isa-attributes specially. Also handle
+ differences for SID-SIMULATOR.
+ (<integer-attribute>): Handle differences for SID-SIMULATOR.
+ (<enum-attribute>): Ditto.
+
2005-10-26 Kazuhiro Inaoka <inaoka.kazuhiro@renesas.com>
* cpu/m32r.opc (parse_hi16): Do not assume a 32-bit host word size.
; Attributes.
-; Copyright (C) 2000 Red Hat, Inc.
+; Copyright (C) 2000, 2003 Red Hat, Inc.
; This file is part of CGEN.
; See file COPYING.CGEN for details.
(map string->symbol (string-cut (->string x) #\,))
)
+; Generate a list representing a bit mask of the indices of 'values'
+; within 'all-values'. Each element in the resulting list represents a byte.
+; Both bits and bytes are indexed from left to right starting at 0
+; with 8 bits in a byte.
+(define (charmask-bytes values all-values vec-length)
+ (logit 3 "charmask-bytes for " values " " all-values "\n")
+ (let ((result (make-vector vec-length 0))
+ (indices (map (lambda (name)
+ (list-ref (map cadr all-values)
+ (element-lookup-index name (map car all-values) 0)))
+ values)))
+ (logit 3 "indices: " indices "\n")
+ (for-each (lambda (x)
+ (let* ((byteno (quotient x 8))
+ (bitno (- 7 (remainder x 8)))
+ (byteval (logior (vector-ref result byteno)
+ (ash 1 bitno))))
+ (vector-set! result byteno byteval)))
+ indices)
+ (logit 3 "result: " (vector->list result) "\n")
+ (vector->list result))
+)
+
+; Convert a bitset value into a bit string based on the
+; index of each member in values
+(define (bitset-attr->charmask value values)
+ (let* ((values-names (map car values))
+ (values-values (map cadr values))
+ (vec-length (+ 1 (quotient (apply max values-values) 8))))
+ (string-append "{ " (number->string vec-length) ", \""
+ (string-map (lambda (x)
+ (string-append "\\x" (number->hex x)))
+ (charmask-bytes (bitset-attr->list value)
+ values vec-length))
+ "\" }"))
+)
; Return the enum of ATTR-NAME for type TYPE.
; TYPE is one of 'ifld, 'hw, 'operand, 'insn.
; (maybe utils-cgen.scm?) and there's only a few of them.
(method-make!
- <boolean-attribute> 'gen-value-for-defn
+ <boolean-attribute> 'gen-value-for-defn-raw
(lambda (self value)
(if (not value)
"0"
;(string-upcase (string-append (obj:str-name self) "_" value)))
)
+(method-make!
+ <boolean-attribute> 'gen-value-for-defn
+ (lambda (self value)
+ (send self 'gen-value-for-defn-raw value))
+)
+
+(method-make!
+ <bitset-attribute> 'gen-value-for-defn-raw
+ (lambda (self value)
+ (if (string=? (string-downcase (gen-sym self)) "isa")
+ (bitset-attr->charmask value (elm-get self 'values))
+ (string-drop1
+ (string-upcase
+ (string-map (lambda (x)
+ (string-append "|(1<<"
+ (gen-sym self)
+ "_" (gen-c-symbol x) ")"))
+ (bitset-attr->list value)))))
+ )
+)
+
(method-make!
<bitset-attribute> 'gen-value-for-defn
(lambda (self value)
- (string-drop1
- (string-upcase
- (string-map (lambda (x)
- (string-append "|(1<<"
- (gen-sym self)
- "_" (gen-c-symbol x) ")"))
- (bitset-attr->list value)))))
+ (string-append
+ "{ "
+ (if (string=? (string-downcase (gen-sym self)) "isa")
+ (bitset-attr->charmask value (elm-get self 'values))
+ (string-append
+ "{ "
+ (string-drop1
+ (string-upcase
+ (string-map (lambda (x)
+ (string-append "|(1<<"
+ (gen-sym self)
+ "_" (gen-c-symbol x) ")"))
+ (bitset-attr->list value))))
+ ", 0 }"))
+ " }")
+ )
+)
+
+(method-make!
+ <integer-attribute> 'gen-value-for-defn-raw
+ (lambda (self value)
+ (number->string value)
+ )
)
(method-make!
<integer-attribute> 'gen-value-for-defn
(lambda (self value)
- (number->string value))
+ (string-append
+ "{ { "
+ (send self 'gen-value-for-defn-raw value)
+ ", 0 } }")
+ )
)
(method-make!
- <enum-attribute> 'gen-value-for-defn
+ <enum-attribute> 'gen-value-for-defn-raw
(lambda (self value)
(string-upcase
(gen-c-symbol (string-append (obj:str-name self)
"_"
- (symbol->string value)))))
+ (symbol->string value))))
+ )
+)
+
+(method-make!
+ <enum-attribute> 'gen-value-for-defn
+ (lambda (self value)
+ (string-append
+ "{ { "
+ (send self 'gen-value-for-defn-raw value)
+ ", 0 } }")
+ )
)
\f
; Called before loading a .cpu file to initialize.
"/* Ifield support. */\n\n"
"/* Ifield attribute indices. */\n\n"
(gen-attr-enum-decl "cgen_ifld" (current-ifld-attr-list))
+ (-gen-attr-accessors "cgen_ifld" (current-ifld-attr-list))
(gen-enum-decl 'ifield_type "@arch@ ifield types"
"@ARCH@_"
(append (gen-obj-list-enums (non-derived-ifields (current-ifld-list)))
" },\n")))
ifld-list)
"\
- { 0, 0, 0, 0, 0, 0, {0, {0}} }
+ { 0, 0, 0, 0, 0, 0, " (gen-obj-attr-end-defn all-attrs num-non-bools) " }
};
#undef A
(string-list
"/* Hardware attribute indices. */\n\n"
(gen-attr-enum-decl "cgen_hw" (current-hw-attr-list))
+ (-gen-attr-accessors "cgen_hw" (current-hw-attr-list))
(gen-enum-decl 'cgen_hw_type "@arch@ hardware types"
"HW_" ; FIXME: @ARCH@_
(append (nub (map (lambda (hw)
" },\n")))
(current-hw-list))
"\
- { 0, 0, CGEN_ASM_NONE, 0, {0, {0}} }
+ { 0, 0, CGEN_ASM_NONE, 0, " (gen-obj-attr-end-defn all-attrs num-non-bools) " }
};
#undef A
(define (-gen-hash-defines)
(logit 2 "Generating #define's ...\n")
(string-list
+ "#include \"opcode/cgen-bitset.h\"\n"
+ "\n"
"#define CGEN_ARCH @arch@\n\n"
"/* Given symbol S, return @arch@_cgen_<S>. */\n"
(gen-define-with-symcat "CGEN_SYM(s) @arch@" "_cgen_" "s")
(string-list
"/* Operand attribute indices. */\n\n"
(gen-attr-enum-decl "cgen_operand" (current-op-attr-list))
+ (-gen-attr-accessors "cgen_operand" (current-op-attr-list))
(gen-enum-decl 'cgen_operand_type "@arch@ operand types"
"@ARCH@_OPERAND_"
(nub (append (gen-obj-list-enums (current-op-list))
)))))
(current-op-list))
"/* sentinel */\n\
- { 0, 0, 0, 0, 0,\n { 0, { (const PTR) 0 } },\n { 0, { 0 } } }
+ { 0, 0, 0, 0, 0,\n { 0, { (const PTR) 0 } },\n " (gen-obj-attr-end-defn all-attrs num-non-bools) " }
};
#undef A
(string-list
"/* Insn attribute indices. */\n\n"
(gen-attr-enum-decl "cgen_insn" (current-insn-attr-list))
+ (-gen-attr-accessors "cgen_insn" (current-insn-attr-list))
)
)
/* Special null first entry.
A `num' value of zero is thus invalid.
Also, the special `invalid' insn resides here. */
- { 0, 0, 0, 0, {0, {0}} },\n"
+ { 0, 0, 0, 0, " (gen-obj-attr-end-defn all-attrs num-non-bools) " },\n"
(lambda ()
(string-write-map (lambda (insn)
@arch@_cgen_rebuild_tables (CGEN_CPU_TABLE *cd)
{
int i;
- unsigned int isas = cd->isas;
+ CGEN_BITSET *isas = cd->isas;
unsigned int machs = cd->machs;
cd->int_insn_p = CGEN_INT_INSN_P;
cd->min_insn_bitsize = 65535; /* Some ridiculously big number. */
cd->max_insn_bitsize = 0;
for (i = 0; i < MAX_ISAS; ++i)
- if (((1 << i) & isas) != 0)
+ if (cgen_bitset_contains (isas, i))
{
const CGEN_ISA *isa = & @arch@_cgen_isa_table[i];
{
CGEN_CPU_TABLE *cd = (CGEN_CPU_TABLE *) xmalloc (sizeof (CGEN_CPU_TABLE));
static int init_p;
- unsigned int isas = 0; /* 0 = \"unspecified\" */
+ CGEN_BITSET *isas = 0; /* 0 = \"unspecified\" */
unsigned int machs = 0; /* 0 = \"unspecified\" */
enum cgen_endian endian = CGEN_ENDIAN_UNKNOWN;
va_list ap;
switch (arg_type)
{
case CGEN_CPU_OPEN_ISAS :
- isas = va_arg (ap, unsigned int);
+ isas = va_arg (ap, CGEN_BITSET *);
break;
case CGEN_CPU_OPEN_MACHS :
machs = va_arg (ap, unsigned int);
machs = (1 << MAX_MACHS) - 1;
/* Base mach is always selected. */
machs |= 1;
- /* ISA unspecified means \"all\". */
- if (isas == 0)
- isas = (1 << MAX_ISAS) - 1;
if (endian == CGEN_ENDIAN_UNKNOWN)
{
/* ??? If target has only one, could have a default. */
abort ();
}
- cd->isas = isas;
+ cd->isas = cgen_bitset_copy (isas);
cd->machs = machs;
cd->endian = endian;
/* FIXME: for the sparc case we can determine insn-endianness statically.
; General cpu info generator support.
-; Copyright (C) 2000 Red Hat, Inc.
+; Copyright (C) 2000, 2003 Red Hat, Inc.
; This file is part of CGEN.
;
; This file generates C versions of the more salient parts of the description
(if (string? (cadr e))
(cadr e)
(number->string (cadr e))) ; value
- ", {0, {0}}, 0, 0"
+ ", {0, {{{0, 0}}}}, 0, 0"
" },\n"
))
(elm-get self 'values)))
; CPU architecture description.
-; Copyright (C) 2000 Red Hat, Inc.
+; Copyright (C) 2000, 2003 Red Hat, Inc.
; This file is part of CGEN.
; See file COPYING.CGEN for details.
(apply min (cons 65535
(map insn-length (find (lambda (insn)
(and (not (has-attr? insn 'ALIAS))
- (eq? (obj-attr-value insn 'ISA)
- (obj:name isa))))
+ (isa-supports? isa insn)))
(non-multi-insns (current-insn-list))))))
)
(apply max (cons 0
(map insn-length (find (lambda (insn)
(and (not (has-attr? insn 'ALIAS))
- (eq? (obj-attr-value insn 'ISA)
- (obj:name isa))))
+ (isa-supports? isa insn)))
(non-multi-insns (current-insn-list))))))
)
#ifndef DESC_@ARCH@_H
#define DESC_@ARCH@_H
+#include \"opcode/cgen-bitset.h\"
+
namespace @arch@ {
\n"
"_memory")
m 1))
modes)))
-
(logit 2 "Generating writer function ...\n")
(string-append
"
-
void @prefix@::write_stacks::writeback (int tick, @cpu@::@cpu@_cpu* current_cpu)
{
"
(attr-default attr))))
; FIXME: Are we missing attr-prefix here?
(string-append ", "
- (send attr 'gen-value-for-defn val))))
+ (send attr 'gen-value-for-defn-raw val))))
all-non-bools)))
" }"))
)
; CGEN Utilities.
-; Copyright (C) 2000 Red Hat, Inc.
+; Copyright (C) 2000, 2002, 2003 Red Hat, Inc.
; This file is part of CGEN.
; See file COPYING.CGEN for details.
;
\f
; Attributes
+; Return the C/C++ type to use to hold a value for attribute ATTR.
+
+(define (gen-attr-type attr)
+ (if (string=? (string-downcase (gen-sym attr)) "isa")
+ "CGEN_BITSET"
+ (case (attr-kind attr)
+ ((boolean) "int")
+ ((bitset) "unsigned int")
+ ((integer) "int")
+ ((enum) (string-append "enum " (string-downcase (gen-sym attr)) "_attr"))
+ ))
+)
+
+; Return C macros for accessing an object's attributes ATTRS.
+; PREFIX is one of "cgen_ifld", "cgen_hw", "cgen_operand", "cgen_insn".
+; ATTRS is an alist of attribute values. The value is unimportant except that
+; it is used to determine bool/non-bool.
+; Non-bools need to be separated from bools as they're each recorded
+; differently. Non-bools are recorded in an int for each. All bools are
+; combined into one int to save space.
+; ??? We assume there is at least one bool.
+
+(define (-gen-attr-accessors prefix attrs)
+ (string-append
+ "/* " prefix " attribute accessor macros. */\n"
+ (string-map (lambda (attr)
+ (string-append
+ "#define CGEN_ATTR_"
+ (string-upcase prefix)
+ "_"
+ (string-upcase (gen-sym attr))
+ "_VALUE(attrs) "
+ (if (bool-attr? attr)
+ (string-append
+ "(((attrs)->bool & (1 << "
+ (string-upcase prefix)
+ "_"
+ (string-upcase (gen-sym attr))
+ ")) != 0)")
+ (string-append
+ "((attrs)->nonbool["
+ (string-upcase prefix)
+ "_"
+ (string-upcase (gen-sym attr))
+ "-"
+ (string-upcase prefix)
+ "_START_NBOOLS-1]."
+ (case (attr-kind attr)
+ ((bitset)
+ (if (string=? (string-downcase (gen-sym attr)) "isa")
+ ""
+ "non"))
+ (else "non"))
+ "bitset)"))
+ "\n"))
+ attrs)
+ "\n")
+)
; Return C code to declare an enum of attributes ATTRS.
; PREFIX is one of "cgen_ifld", "cgen_hw", "cgen_operand", "cgen_insn".
; ATTRS is an alist of attribute values. The value is unimportant except that
))
)
+; Return the C definition of the terminating entry of an object's attributes.
+; ALL-ATTRS is an ordered alist of all attributes.
+; "ordered" means all the non-boolean attributes are at the front and
+; duplicate entries have been removed.
+
+(define (gen-obj-attr-end-defn all-attrs num-non-bools)
+ (let ((all-non-bools (list-take num-non-bools all-attrs)))
+ (string-append
+ "{ 0, {"
+ (if (null? all-non-bools)
+ " { 0, 0 }"
+ (string-drop1 ; drop the leading ","
+ (string-map (lambda (attr)
+ (let ((val (attr-default attr)))
+ ; FIXME: Are we missing attr-prefix here?
+ (string-append ", "
+ (send attr 'gen-value-for-defn val))))
+ all-non-bools)))
+ " } }"
+ ))
+)
; Return a boolean indicating if ATLIST indicates a CTI insn.
(define (atlist-cti? atlist)