Rename member prefix -> name-prefix.
(<keyword> getters): Update.
(-keyword-parse): Update. Default enum-prefix to NAME-.
(-keyword-read): Update. Don't compute default value for
enum-prefix here.
(define-keyword): Update.
(-hw-parse-keyword): Pass "UNUSED" for enum-prefix to -keyword-parse.
* read.scm (cgen-rtl-version): New function.
(-supported-rtl-versions): Add (0 8).
* desc-cpu.scm (-gen-hw-decl): Remove cruft.
* desc.scm (<keyword> gen-defn): prefix -> name-prefix.
* gas-test.scm (<keyword> test-data): prefix -> name-prefix.
* cpu/arm.cpu (gr-names, shift-type): Call define-rtl-version.
Update, print-name -> enum-prefix, make uppercase.
Remove unnecessary name-prefix spec.
* cpu/fr30.cpu (gr-names, cr-names, dr-names): Ditto.
* cpu/ip2k.cpu (register-names): Ditto.
* cpu/m68k.cpu (dr-names, ar-names): Ditto.
* cpu/sparc.cpu (gr-names): Ditto.
* cpu/xc16x.cpu (gr-names, ext-names,psw-names): Ditto.
(grb-names, conditioncode-names, extconditioncode-names): Ditto.
(grb8-names, r8-names, regmem8-names, regdiv8-names): Ditto.
(reg0-name, reg0-name1, regbmem8-names, memgr8-names): Ditto.
* cpu/ia32.cpu (gr8-names, gr16-names, gr-names): Call
define-rtl-version. Update, print-name -> enum-prefix, make uppercase,
prefix -> name-prefix.
* cpu/sh64-compact.cpu (frc-names): Call define-rtl-version.
Update, print-name -> enum-prefix, make uppercase.
(drc-names, xf-names): Ditto.
* cpu/xstormy16.cpu (gr-names, gr-Rb-names): Ditto.
* doc/rtl.texi (Keywords): New section.
(hardware indices): Update text.
(rtl versions): Add 0.8.
2009-08-23 Doug Evans <dje@sebabeach.org>
+ * hardware.scm (<keyword>): Rename member print-name -> enum-prefix.
+ Rename member prefix -> name-prefix.
+ (<keyword> getters): Update.
+ (-keyword-parse): Update. Default enum-prefix to NAME-.
+ (-keyword-read): Update. Don't compute default value for
+ enum-prefix here.
+ (define-keyword): Update.
+ (-hw-parse-keyword): Pass "UNUSED" for enum-prefix to -keyword-parse.
+ * read.scm (cgen-rtl-version): New function.
+ (-supported-rtl-versions): Add (0 8).
+ * desc-cpu.scm (-gen-hw-decl): Remove cruft.
+ * desc.scm (<keyword> gen-defn): prefix -> name-prefix.
+ * gas-test.scm (<keyword> test-data): prefix -> name-prefix.
+ * cpu/arm.cpu (gr-names, shift-type): Call define-rtl-version.
+ Update, print-name -> enum-prefix, make uppercase.
+ Remove unnecessary name-prefix spec.
+ * cpu/fr30.cpu (gr-names, cr-names, dr-names): Ditto.
+ * cpu/ip2k.cpu (register-names): Ditto.
+ * cpu/m68k.cpu (dr-names, ar-names): Ditto.
+ * cpu/sparc.cpu (gr-names): Ditto.
+ * cpu/xc16x.cpu (gr-names, ext-names,psw-names): Ditto.
+ (grb-names, conditioncode-names, extconditioncode-names): Ditto.
+ (grb8-names, r8-names, regmem8-names, regdiv8-names): Ditto.
+ (reg0-name, reg0-name1, regbmem8-names, memgr8-names): Ditto.
+ * cpu/ia32.cpu (gr8-names, gr16-names, gr-names): Call
+ define-rtl-version. Update, print-name -> enum-prefix, make uppercase,
+ prefix -> name-prefix.
+ * cpu/sh64-compact.cpu (frc-names): Call define-rtl-version.
+ Update, print-name -> enum-prefix, make uppercase.
+ (drc-names, xf-names): Ditto.
+ * cpu/xstormy16.cpu (gr-names, gr-Rb-names): Ditto.
+ * doc/rtl.texi (Keywords): New section.
+ (hardware indices): Update text.
+ (rtl versions): Add 0.8.
+
Add define-rtl-version.
* read.scm (-CGEN-RTL-VERSION): Renamed from -CGEN-LANG-VERSION.
(cgen-rtl-major, cgen-rtl-minor): Similarly renamed.
; ARM CPU description. -*- Scheme -*-
-; Copyright (C) 2000 Red Hat, Inc.
+; Copyright (C) 2000, 2009 Red Hat, Inc.
; This file is part of CGEN.
; See file COPYING.CGEN for details.
+(define-rtl-version 0 8)
+
(include "simplify.inc")
(define-arch
(define-keyword
(name gr-names)
- (print-name h-gr)
+ (enum-prefix H-GR-)
(values (pc 15) ; put this first so it is prefered over r15
(r0 0) (r1 1) (r2 2) (r3 3) (r4 4) (r5 5) (r6 6) (r7 7)
(r8 8) (r9 9) (r10 10) (r11 11) (r12 12) (r13 13) (r14 14) (r15 15)
(define-keyword
(name shift-type)
(comment "operand 2 shift type")
- (prefix "")
(values (lsl 0) (asl 0) (lsr 1) (asr 2) (ror 3))
)
; Fujitsu FR30 CPU description. -*- Scheme -*-
-; Copyright (C) 2000 Red Hat, Inc.
+; Copyright (C) 2000, 2009 Red Hat, Inc.
; This file is part of CGEN.
; See file COPYING.CGEN for details.
+(define-rtl-version 0 8)
+
(include "simplify.inc")
; define-arch must appear first
(define-keyword
(name gr-names)
- (print-name h-gr)
- (prefix "")
+ (enum-prefix H-GR-)
(values (r0 0) (r1 1) (r2 2) (r3 3) (r4 4) (r5 5) (r6 6) (r7 7)
(r8 8) (r9 9) (r10 10) (r11 11) (r12 12) (r13 13) (r14 14) (r15 15)
(ac 13) (fp 14) (sp 15))
(define-keyword
(name cr-names)
- (print-name h-cr)
- (prefix "")
+ (enum-prefix H-CR-)
(values (cr0 0) (cr1 1) (cr2 2) (cr3 3)
(cr4 4) (cr5 5) (cr6 6) (cr7 7)
(cr8 8) (cr9 9) (cr10 10) (cr11 11)
(define-keyword
(name dr-names)
- (print-name h-dr)
- (prefix "")
+ (enum-prefix H-DR-)
(values (tbr 0) (rp 1) (ssp 2) (usp 3) (mdh 4) (mdl 5))
)
; Intel IA32 CPU description. -*- Scheme -*-
-; Copyright (C) 2000 Red Hat, Inc.
+; Copyright (C) 2000, 2009 Red Hat, Inc.
; This file is part of CGEN.
; See file COPYING.CGEN for details.
;
;
; Intel486 Processor Family, Programmer's Reference Manual, Intel
+(define-rtl-version 0 8)
+
(include "simplify.inc")
; define-arch must appear first
(define-keyword
(name gr8-names)
- (print-name h-gr8)
- (prefix "%")
+ (enum-prefix H-GR8-)
+ (name-prefix "%")
(values (al 0) (cl 1) (dl 2) (bl 3) (ah 4) (ch 5) (dh 6) (bh 7))
)
(define-keyword
(name gr16-names)
- (print-name h-gr16)
- (prefix "%")
+ (enum-prefix H-GR16-)
+ (name-prefix "%")
(values (ax 0) (cx 1) (dx 2) (bx 3) (sp 4) (bp 5) (si 6) (di 7))
)
(define-keyword
(name gr-names)
- (print-name h-gr)
- (prefix "%")
+ (enum-prefix H-GR-)
+ (name-prefix "%")
(values (eax 0) (ecx 1) (edx 2) (ebx 3) (esp 4) (ebp 5) (esi 6) (edi 7))
)
; Ubicom IP2K CPU description. -*- Scheme -*-
; Copyright (C) 2000, 2001 Red Hat, Inc.
-; Copyright (C) 2002 Free Software Foundation, Inc.
+; Copyright (C) 2002, 2009 Free Software Foundation, Inc.
; This file is part of CGEN.
; See file COPYING.CGEN for details.
+(define-rtl-version 0 8)
+
(include "simplify.inc")
; define-arch must appear first
(define-keyword
(name register-names)
- (print-name h-registers)
- (prefix "")
+ (enum-prefix H-REGISTERS-)
(values
; These are the "Special Purpose Registers" that are not reserved
("ADDRSEL" #x2) ("ADDRX" #x3)
; Motorola M68000 family CPU description. -*- Scheme -*-
-; Copyright (C) 2000 Red Hat, Inc.
+; Copyright (C) 2000, 2009 Red Hat, Inc.
; This file is part of CGEN.
; See file COPYING.CGEN for details.
+(define-rtl-version 0 8)
+
; NOTE: this file is still strictly WORK-IN-PROGRESS.
(include "simplify.inc")
(define-keyword
(name dr-names)
- (print-name h-dr)
- (prefix "")
- (values (d0 0) (d1 1) (d2 2) (d3 3) (d4 4) (d5 5) (d6 6) (d7 7))
+ (enum-prefix H-DR-)
+ (values (d0 0) (d1 1) (d2 2) (d3 3) (d4 4) (d5 5) (d6 6) (d7 7))
)
(define-keyword
(name ar-names)
- (print-name h-ar)
- (prefix "")
+ (enum-prefix H-AR-)
(values (a0 0) (a1 1) (a2 2) (a3 3) (a4 4) (a5 5) (a6 6) (a7 7)
(sp 7))
)
; Renesas / SuperH SH architecture description. -*- Scheme -*-
-; Copyright (C) 2000, 2001, 2006 Red Hat, Inc.
+; Copyright (C) 2000, 2001, 2006, 2009 Red Hat, Inc.
; This file is part of CGEN.
; See file COPYING.CGEN for details.
+(define-rtl-version 0 8)
+
(include "simplify.inc")
; Macros to handle differences in CGEN for SID vs SIM are included
(define-keyword
(name frc-names)
(attrs (ISA compact))
- (print-name h-frc)
+ (enum-prefix H-FRC-)
(values (fr0 0) (fr1 1) (fr2 2) (fr3 3) (fr4 4) (fr5 5)
(fr6 6) (fr7 7) (fr8 8) (fr9 9) (fr10 10) (fr11 11)
(fr12 12) (fr13 13) (fr14 14) (fr15 15))
(define-keyword
(name drc-names)
(attrs (ISA compact))
- (print-name h-drc)
+ (enum-prefix H-DRC-)
(values (dr0 0) (dr2 2) (dr4 4) (dr6 6) (dr8 8) (dr10 10) (dr12 12) (dr14 14))
)
(define-keyword
(name xf-names)
(attrs (ISA compact))
- (print-name h-xf)
+ (enum-prefix H-XF-)
(values (xf0 0) (xf1 1) (xf2 2) (xf3 3) (xf4 4) (xf5 5)
(xf6 6) (xf7 7) (xf8 8) (xf9 9) (xf10 10) (xf11 11)
(xf12 12) (xf13 13) (xf14 14) (xf15 15))
; SPARC CPU description. -*- Scheme -*-
-; Copyright (C) 2000 Red Hat, Inc.
+; Copyright (C) 2000, 2009 Red Hat, Inc.
; This file is part of CGEN.
; See file COPYING.CGEN for details.
; - page numbers refered to here are to the sparc architecture reference
; manuals (v8,v9).
+(define-rtl-version 0 8)
+
(include "simplify.inc")
(define-arch
(define-keyword
(name gr-names)
- (print-name h-gr)
- (prefix "%")
+ (enum-prefix H-GR-)
+ (name-prefix "%")
(values (fp 30) (sp 14)
(g0 0) (g1 1) (g2 2) (g3 3) (g4 4) (g5 5) (g6 6) (g7 7)
(o0 8) (o1 9) (o2 10) (o3 11) (o4 12) (o5 13) (o6 14) (o7 15)
; Infineon XC16X CPU description. -*- Scheme -*-
;
-; Copyright 2006 Free Software Foundation, Inc.
+; Copyright 2006, 2009 Free Software Foundation, Inc.
;
; Contributed by KPIT Cummins Infosystems Ltd.; developed under contract
; from Infineon Systems, GMBH , Germany.
; Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
; 02110-1301, USA.
+(define-rtl-version 0 8)
+
(include "simplify.inc")
; define-arch appears first
(define-keyword
(name gr-names)
- (print-name h-gr)
- (prefix "")
+ (enum-prefix H-GR-)
(values (r0 0) (r1 1) (r2 2) (r3 3) (r4 4) (r5 5) (r6 6) (r7 7)
(r8 8) (r9 9) (r10 10) (r11 11) (r12 12) (r13 13) (r14 14) (r15 15))
(define-keyword
(name ext-names)
- (print-name h-ext)
- (prefix "")
+ (enum-prefix H-EXT-)
(values (0x1 0) (0x2 1) (0x3 2) (0x4 3)
("1" 0) ("2" 1) ("3" 2) ("4" 3))
(define-keyword
(name psw-names)
- (print-name h-psw)
- (prefix "")
+ (enum-prefix H-PSW-)
(values ("IEN" 136) ("r0.11" 240) ("r1.11" 241) ("r2.11" 242) ("r3.11" 243) ("r4.11" 244)
("r5.11" 245) ("r6.11" 246) ("r7.11" 247) ("r8.11" 248)
("r9.11" 249) ("r10.11" 250) ("r11.11" 251) ("r12.11" 252)
(define-keyword
(name grb-names)
- (print-name h-grb)
- (prefix "")
+ (enum-prefix H-GRB-)
(values (rl0 0) (rh0 1) (rl1 2) (rh1 3) (rl2 4) (rh2 5) (rl3 6) (rh3 7)
(rl4 8) (rh4 9) (rl5 10) (rh5 11) (rl6 12) (rh6 13) (rl7 14) (rh7 15))
)
(define-keyword
(name conditioncode-names)
- (print-name h-cc)
- (prefix "")
+ (enum-prefix H-CC-)
(values (cc_UC 0) (cc_NET 1) (cc_Z 2) (cc_EQ 2) (cc_NZ 3) (cc_NE 3) (cc_V 4) (cc_NV 5) (cc_N 6) (cc_NN 7) (cc_ULT 8) (cc_UGE 9)
(cc_C 8) (cc_NC 9) (cc_SGT 10) (cc_SLE 11) (cc_SLT 12) (cc_SGE 13) (cc_UGT 14)
(cc_ULE 15))
(define-keyword
(name extconditioncode-names)
- (print-name h-ecc)
- (prefix "")
+ (enum-prefix H-ECC-)
(values(cc_UC 0) (cc_NET 2) (cc_Z 4) (cc_EQ 4) (cc_NZ 6) (cc_NE 6) (cc_V 8) (cc_NV 10) (cc_N 12) (cc_NN 14) (cc_ULT 16) (cc_UGE 18) (cc_C 16) (cc_NC 18) (cc_SGT 20)
(cc_SLE 22) (cc_SLT 24) (cc_SGE 26) (cc_UGT 28) (cc_ULE 30) (cc_nusr0 1)
(cc_nusr1 3) (cc_usr0 5) (cc_usr1 7))
(define-keyword
(name grb8-names)
- (print-name h-grb8)
- (prefix "")
+ (enum-prefix H-GRB8-)
(values (dpp0 0) (dpp1 1) (dpp2 2) (dpp3 3)
(psw 136) (cp 8) (mdl 7) (mdh 6)
(mdc 135) (sp 9) (csp 4) (vecseg 137)
(define-keyword
(name r8-names)
- (print-name h-r8)
- (prefix "")
+ (enum-prefix H-R8-)
(values (dpp0 0) (dpp1 1) (dpp2 2) (dpp3 3)
(psw 136) (cp 8) (mdl 7) (mdh 6)
(mdc 135) (sp 9) (csp 4) (vecseg 137)
(define-keyword
(name regmem8-names)
- (print-name h-regmem8)
- (prefix "")
+ (enum-prefix H-REGMEM8-)
(values (dpp0 0) (dpp1 1) (dpp2 2) (dpp3 3)
(psw 136) (cp 8) (mdl 7) (mdh 6)
(mdc 135) (sp 9) (csp 4) (vecseg 137)
(define-keyword
(name regdiv8-names)
- (print-name h-regdiv8)
- (prefix "")
+ (enum-prefix H-REGDIV8-)
(values (r0 0) (r1 17) (r2 34) (r3 51) (r4 68) (r5 85) (r6 102) (r7 119)
(r8 136) (r9 153) (r10 170) (r11 187) (r12 204) (r13 221) (r14 238) (r15 255))
)
(define-keyword
(name reg0-name)
- (print-name h-reg0)
- (prefix "")
+ (enum-prefix H-REG0-)
(values (0x1 1) (0x2 2) (0x3 3) (0x4 4) (0x5 5) (0x6 6) (0x7 7) (0x8 8) (0x9 9) (0xa 10) (0xb 11)
(0xc 12) (0xd 13) (0xe 14) (0xf 15)
("1" 1) ("2" 2) ("3" 3) ("4" 4) ("5" 5) ("6" 6) ("7" 7) ("8" 8) ("9" 9) ("10" 10) ("11" 11)
(define-keyword
(name reg0-name1)
- (print-name h-reg01)
- (prefix "")
+ (enum-prefix H-REG01-)
(values (0x1 1) (0x2 2) (0x3 3) (0x4 4) (0x5 5) (0x6 6) (0x7 7)
("1" 1) ("2" 2) ("3" 3) ("4" 4) ("5" 5) ("6" 6) ("7" 7))
)
(define-keyword
(name regbmem8-names)
- (print-name h-regbmem8)
- (prefix "")
+ (enum-prefix H-REGBMEM8-)
(values (dpp0 0) (dpp1 1) (dpp2 2) (dpp3 3)
(psw 136) (cp 8) (mdl 7) (mdh 6)
(mdc 135) (sp 9) (csp 4) (vecseg 137)
(define-keyword
(name memgr8-names)
- (print-name h-memgr8)
- (prefix "")
+ (enum-prefix H-MEMGR8-)
(values (dpp0 65024) (dpp1 65026) (dpp2 65028) (dpp3 65030)
(psw 65296) (cp 65040) (mdl 65038) (mdh 65036)
(mdc 65294) (sp 65042) (csp 65032) (vecseg 65298)
; xstormy16 CPU core description. -*- Scheme -*-
-; Copyright (C) 2001, 2002, 2003, 2006 Red Hat, Inc.
+; Copyright (C) 2001, 2002, 2003, 2006, 2009 Red Hat, Inc.
; This file is part of CGEN.
; See file COPYING.CGEN for details.
+(define-rtl-version 0 8)
+
(include "simplify.inc")
(define-arch
(define-keyword
(name gr-names)
- (print-name h-gr)
+ (enum-prefix H-GR-)
(values (r0 0) (r1 1) (r2 2) (r3 3)
(r4 4) (r5 5) (r6 6) (r7 7)
(r8 8) (r9 9) (r10 10) (r11 11)
(define-keyword
(name gr-Rb-names)
- (print-name h-Rbj)
+ (enum-prefix H-RBJ-)
(values (r8 0) (r9 1) (r10 2) (r11 3)
(r12 4) (r13 5) (r14 6) (r15 7)
(psw 6) (sp 7)))
(define (-gen-hw-decl hw)
(string-append
- (if (and (hw-indices hw)
- ; ??? Commented out as opcode changes are needed
- ) ; (not (obj-has-attr? (hw-indices hw) 'PRIVATE)))
+ (if (hw-indices hw)
(gen-decl (hw-indices hw))
"")
- (if (and (hw-values hw)
- ; ??? Commented out as opcode changes are needed
- ) ; (not (obj-has-attr? (hw-values hw) 'PRIVATE)))
+ (if (hw-values hw)
(gen-decl (hw-values hw))
"")
)
(string-map (lambda (e)
(string-append
" { \""
- (->string (elm-get self 'prefix))
+ (->string (elm-get self 'name-prefix))
(->string (car e)) ; operand name
"\", "
(if (string? (cadr e))
* Hardware elements:: Elements of a CPU
* Instruction fields:: Fields of an instruction
* Enumerated constants:: Assigning useful names to important numbers
+* Keywords:: Like enums, plus string table
* Instruction operands:: Operands of instructions
* Derived operands:: Operands for CISC-like architectures
* Instructions:: Instructions
If the version is set multiple times the behavior is undefined.
-The current RTL version is 0.7:
+The default RTL version, if @samp{define-rtl-version} is elided, is 0.7.
+
+The latest RTL version is 0.8:
@example
-(define-rtl-version 0 7)
+(define-rtl-version 0 8)
@end example
Every increment in major and minor versions is generally non-upward
This is the original RTL version.
It is the default if no version is specified.
It is supported by CGEN versions 1.0, 1.1, and the current development tree.
+Support for it will probably be removed for the CGEN 1.2 release.
+
+@item 0.8 @code{(define-rtl-version 0 8)}
+
+This version changed the syntax for defining keywords.
+The @samp{print-name} field was renamed to @samp{enum-prefix}
+and the @samp{prefix} field was renamed to @samp{name-prefix}.
+
+Previous syntax:
+
+@smallexample
+(define-keyword
+ (name keyword-name)
+ (comment "description")
+ (attrs attribute-list)
+ (mode mode-name)
+ (print-name "prefix-for-enum-values")
+ (prefix "prefix-for-names-in-string-table")
+ (values value-list)
+)
+@end smallexample
+
+New syntax:
+
+@smallexample
+(define-keyword
+ (name keyword-name)
+ (comment "description")
+ (attrs attribute-list)
+ (mode mode-name)
+ (enum-prefix "prefix-for-enum-values")
+ (name-prefix "prefix-for-names-in-string-table")
+ (values value-list)
+)
+@end smallexample
@end itemize
where @samp{index-type} specifies the kind of index and @samp{arg1 arg2 ...}
are arguments to @samp{index-type}.
-The are two supported values for @samp{index-type}: @code{keyword}
+There are two supported values for @samp{index-type}: @code{keyword}
and @code{extern-keyword}. The difference is that indices defined with
@code{keyword} are kept internal to the hardware element's definition
and are not usable elsewhere, whereas @code{extern-keyword} specifies
-a set of indices defined elsewhere.
+a set of indices defined elsewhere with @code{define-keyword}.
@subsubsection keyword
@example
-@code{(indices keyword "prefix" ((name1 value1) (name2 value2) ...))}
+@code{(indices keyword name-prefix ((name1 value1) (name2 value2) ...))}
@end example
-@samp{prefix} is the common prefix for each of the index names.
+@samp{name-prefix} is the assembler prefix common to each of the index names,
+and is added to name in the generated lookup table.
For example, SPARC registers usually begin with @samp{"%"}.
Each @samp{(name value)} pair maps a name with an index number.
An index can be specified multiple times, for example, when a register
has multiple names.
+There may be gaps in the index list, e.g. for invalid/reserved registers.
+
+No enum is defined for keywords defined this way.
+If you want an enum use @samp{define-keyword} and @samp{extern-keyword}.
+
Example from Thumb:
@example
@code{(indices extern-keyword keyword-name)}
@end example
+Often one wants to make the keywords available for general use,
+i.e. to arbitrary tools.
+@xref{Keywords}.
+When the collection of indices is defined with @samp{define-keyword}
+refer to it in the @samp{indices} field with @samp{extern-keyword}.
+
Example from M32R:
@example
(define-keyword
(name gr-names)
- (print-name h-gr)
- (prefix "")
+ (enum-prefix H-GR-)
(values (fp 13) (lr 14) (sp 15)
(r0 0) (r1 1) (r2 2) (r3 3) (r4 4) (r5 5) (r6 6) (r7 7)
(r8 8) (r9 9) (r10 10) (r11 11) (r12 12) (r13 13) (r14 14) (r15 15))
Convention requires each enum value to be prefixed with the same text.
Rather than specifying the prefix in each entry, it is specified once, here.
Convention requires @samp{prefix} not contain any lowercase characters.
+You generally want to end @samp{prefix} with @samp{-} or @samp{_}
+as the complete name of each enum value is @samp{prefix} + @samp{value-name}.
+The convention is to use @samp{-}, though this convention is not
+adhered to as well as the other conventions.
+@c FIXME
+
+The default value is @samp{""}.
@subsection ifield
The name of the instruction field that the enum is intended for. This
must be a simple ifield, not a multi-ifield.
+@anchor{a-enum-values}
@subsection values
A list of possible values. Each element has one of the following forms:
The syntax for numbers is Scheme's, so hex numbers are @code{#xnnnn}.
A value of @code{-} means use the next value (previous value plus 1).
+Enum values currently always have mode @samp{INT}.
+
Example:
@example
@end example
This defines an instruction enum for field @samp{f-op1} with values
-OP1_0, OP1_1, ..., OP1_15.
+OP1_0, OP1_1, ..., OP1_15. These values can be directly used in
+instruction format specs. This applies to ``instruction enums'' only.
+One can use normal enums in instruction format specs but one needs to
+explicitly specify the ifield, e.g. (f-op1 OP1_0).
+
+@node Keywords
+@section Keywords
+@cindex Keywords
+
+Keywords are like enums, @xref{Enumerated constants},
+but they also cause a table of names of each value to be generated.
+This is useful for things like registers where you want
+arbitrary tools to have access to the table of names.
+
+Syntax:
+
+@example
+(define-keyword
+ (name keyword-name)
+ (comment "description")
+ (attrs attribute-list)
+ (mode mode-name)
+ (enum-prefix "prefix-for-enum-values")
+ (name-prefix "prefix-for-names-in-string-table")
+ (values value-list)
+)
+@end example
+
+@subsection mode
+
+This is the mode to reference and record the keyword's value in.
+The default is @samp{INT}. It is normally not necessary to use
+something else.
+
+@subsection enum-prefix
+
+This value is passed as the @samp{prefix} parameter when defining the
+corresponding enum. @xref{Enumerated constants}.
+Convention requires @samp{enum-prefix} not contain any lowercase characters.
+
+The default value is the keyword's name in uppercase + @samp{-}.
+
+@subsection name-prefix
+
+@samp{name-prefix} is the assembler prefix common to each of the index names,
+and is added to name in the generated lookup table.
+For example, SPARC registers usually begin with @samp{"%"}.
+It is @emph{not} added to the corresponding enum value names.
+
+The default value is @samp{""}.
+
+@subsection values
+
+The @samp{values} field has the same syntax as the @samp{values}
+field of @samp{define-enum}. @xref{a-enum-values, Enum Values}.
+
+Example from M32R:
+
+@smallexample
+(define-keyword
+ (name gr-names)
+ (enum-prefix H-GR-)
+ (values (fp 13) (lr 14) (sp 15)
+ (r0 0) (r1 1) (r2 2) (r3 3) (r4 4) (r5 5) (r6 6) (r7 7)
+ (r8 8) (r9 9) (r10 10) (r11 11) (r12 12) (r13 13) (r14 14) (r15 15))
+)
+@end smallexample
+
+Referencing enum values from this keyword in the .cpu file would use
+@samp{H-GR-} + @samp{register-name}. E.g., H-GR-r12.
@node Instruction operands
@section Instruction operands
<keyword> 'test-data
(lambda (self ops)
(let* ((test-cases (elm-get self 'values))
- (prefix (elm-get self 'prefix))
+ (prefix (elm-get self 'name-prefix))
(find-kw (lambda (val)
(find-first (lambda (kw) (= (cadr kw) val)) test-cases))))
(map (lambda (n)
(define <keyword>
(class-make '<keyword> '(<hw-asm>)
'(
- ; Name to use in generated code, as a string.
- print-name
+ ; Prefix value to pass to the corresponding enum.
+ enum-prefix
; Prefix of each name in VALUES, as a string.
- prefix
+ ; This is *not* prepended to each name in the enum.
+ name-prefix
; Associative list of values.
; Each element is (name value [attrs]).
; Accessors
-(define kw-mode (elm-make-getter <keyword> 'mode))
-(define kw-print-name (elm-make-getter <keyword> 'print-name))
-(define kw-prefix (elm-make-getter <keyword> 'prefix))
-(define kw-values (elm-make-getter <keyword> 'values))
+(define-getters <keyword> kw (mode enum-prefix name-prefix values))
; Parse a keyword spec.
;
+; ENUM-PREFIX is for the corresponding enum.
; The syntax of VALUES is: (prefix ((name1 [value1 [(attr-list1)]]) ...))
-; PREFIX is a string prefix for each name.
+; NAME-PREFIX is a prefix added to each value's name in the generated
+; lookup table.
; Each value is a number of mode MODE.
; ??? We have no problem handling any kind of number, we're Scheme.
; However, it's not clear yet how applications will want to handle it, but
; that is left to the application. Still, it might be preferable to impose
; some restrictions which can later be relaxed as necessary.
+; ??? It would be useful to have two names for each value: asm name, enum name.
-(define (-keyword-parse context name comment attrs mode print-name prefix values)
- ; FIXME: parse values.
- (let ((result (make <keyword>
- (parse-name context name)
- (parse-comment context comment)
- (atlist-parse context attrs "")
- (parse-mode-name (context-append context ": mode") mode)
- (parse-string (context-append context ": print-name")
- print-name)
- (parse-string (context-append context ": prefix")
- prefix)
- values)))
- result)
+(define (-keyword-parse context name comment attrs mode enum-prefix
+ name-prefix values)
+ ;; Pick out name first to augment the error context.
+ (let* ((name (parse-name context name))
+ (context (context-append-name context name))
+ (enum-prefix (or enum-prefix
+ (string-append ;; default to NAME-
+ (string-upcase (->string name))
+ "-"))))
+
+ ;; FIXME: parse values.
+ (let ((result (make <keyword>
+ (parse-name context name)
+ (parse-comment context comment)
+ (atlist-parse context attrs "")
+ (parse-mode-name (context-append context ": mode") mode)
+ (parse-string (context-append context ": enum-prefix")
+ enum-prefix)
+ (parse-string (context-append context ": name-prefix")
+ name-prefix)
+ values)))
+ result))
)
; Read a keyword description
(comment "")
(attrs nil)
(mode INT)
- (print-name #f) ;; #f indicates "not set"
- (prefix "")
+ (enum-prefix #f) ;; #f indicates "not set"
+ (name-prefix "")
(values nil)
)
((comment) (set! comment (cadr arg)))
((attrs) (set! attrs (cdr arg)))
((mode) (set! mode (cadr arg)))
- ((print-name) (set! print-name (cadr arg)))
- ((prefix) (set! prefix (cadr arg)))
+ ((print-name)
+ ;; Renamed to enum-prefix in rtl version 0.8.
+ (if (not (equal? (cgen-rtl-version) '(0 7)))
+ (parse-error context "print-name renamed to enum-prefix" arg))
+ (set! enum-prefix (cadr arg)))
+ ((enum-prefix)
+ ;; enum-prefix added in rtl version 0.8.
+ (if (and (= (cgen-rtl-major) 0)
+ (< (cgen-rtl-minor) 8))
+ (parse-error context "invalid hardware arg" arg))
+ (set! enum-prefix (cadr arg)))
+ ((prefix)
+ ;; Renamed to name-prefix in rtl version 0.8.
+ (if (not (equal? (cgen-rtl-version) '(0 7)))
+ (parse-error context "prefix renamed to name-prefix" arg))
+ (set! name-prefix (cadr arg)))
+ ((name-prefix)
+ ;; name-prefix added in rtl version 0.8.
+ (if (and (= (cgen-rtl-major) 0)
+ (< (cgen-rtl-minor) 8))
+ (parse-error context "invalid hardware arg" arg))
+ (set! name-prefix (cadr arg)))
((values) (set! values (cdr arg)))
(else (parse-error context "invalid hardware arg" arg)))
(loop (cdr arg-list)))))
; Now that we've identified the elements, build the object.
(-keyword-parse context name comment attrs mode
- (or print-name name)
- prefix values))
+ enum-prefix name-prefix values))
)
; Define a keyword object, name/value pair list version.
; Define an enum so the values are usable everywhere.
; One use is giving names to register numbers and special constants
; to make periphery C/C++ code more legible.
+ ; FIXME: Should pass on mode to enum.
(define-full-enum (obj:name kw) (obj:comment kw)
(atlist-source-form (obj-atlist kw))
- (string-upcase (string-append (kw-print-name kw) "-"))
+ (if (and (= (cgen-rtl-major) 0)
+ (< (cgen-rtl-minor) 8))
+ ;; Prior to rtl version 0.8 we up-cased the prefix here
+ ;; and added the trailing - ourselves.
+ (string-upcase (string-append (kw-enum-prefix kw) "-"))
+ (kw-enum-prefix kw))
(kw-values kw))))
kw))
)
(if (!= (length args) 2)
(parse-error context "invalid keyword spec" args))
- ; These are copied from our container object.
+ ; Name, comment, and attributes are copied from our container object.
; They're needed to output the table.
- ; ??? This isn't quite right as the container may contain multiple keyword
- ; instances. To be fixed in time.
+ ; ??? This isn't quite right as some day a container may contain multiple
+ ; keyword instances. To be fixed in time.
(-keyword-parse context (obj:name container) (obj:comment container)
- ;; PRIVATE: keyword table is implicitly defined and made
- ;; "static" (in the C sense).
+ ;; PRIVATE: keyword table is implicitly defined, it isn't
+ ;; accessible with current-kw-lookup.
(cons 'PRIVATE (atlist-source-form (obj-atlist container)))
mode
- (obj:name container) ; print-name
+ ;; This is unused, use a magic value to catch any uses.
+ "UNUSED"
(car args) ; prefix
(cadr args)) ; value
)
; Note that this is different from -CGEN-VERSION.
; See section "RTL Versions" of the docs.
(define -CGEN-RTL-VERSION '(0 7))
+(define (cgen-rtl-version) -CGEN-RTL-VERSION)
(define (cgen-rtl-major) (car -CGEN-RTL-VERSION))
(define (cgen-rtl-minor) (cadr -CGEN-RTL-VERSION))
;; List of supported versions
-(define -supported-rtl-versions '((0 7)))
+(define -supported-rtl-versions '((0 7) (0 8)))
(define (-cmd-define-rtl-version major minor)
(if (not (non-negative-integer? major))
(rtx-make-ifield expr)
expected mode parent-expr op-pos tstate appstuff))
((enum-lookup-val expr)
+ ;; ??? If enums could have modes other than INT,
+ ;; we'd want to propagate that mode here.
(-rtx-traverse
(rtx-make-enum 'INT expr)
expected mode parent-expr op-pos tstate appstuff))