1 ; CPU description file generator for the simulator testsuite.
2 ; Copyright (C) 2000 Red Hat, Inc.
3 ; This file is part of CGEN.
4 ; See file COPYING.CGEN for details.
6 ; This is invoked to build allinsn.exp and a script to run to
7 ; generate allinsn.s and allinsn.d.
9 ; Specify which application.
10 (set! APPLICATION 'SIM-TEST)
12 ; Called before/after the .cpu file has been read.
14 (define (sim-test-init!) (opcodes-init!))
15 (define (sim-test-finish!) (opcodes-finish!))
17 ; Called after .cpu file has been read and global error checks are done.
18 ; We use the `tmp' member to record the syntax split up into its components.
20 (define (sim-test-analyze!)
23 (insn) (elm-xset! insn 'tmp (syntax-break-out (insn-syntax insn))))
28 ; Methods to compute test data.
29 ; The result is a list of strings to be inserted in the assembler
30 ; in the operand's position.
35 ; FIXME: floating point support
36 (let ((signed (list 0 1 -1 2 -2))
37 (unsigned (list 0 1 2 3 4))
38 (mode (elm-get self 'mode)))
41 (if (eq? (mode:class mode) 'UINT)
49 (let* ((values (elm-get self 'values))
50 (n (min n (length values))))
51 ; FIXME: Need to handle mach variants.
52 (map car (list-take n values))))
56 <hw-address> 'test-data
58 (let ((test-data '("foodata" "4" "footext" "-4")))
59 (list-take n test-data)))
63 <hw-iaddress> 'test-data
65 (let ((test-data '("footext" "4" "foodata" "-4")))
66 (list-take n test-data)))
69 (method-make-forward! <hw-register> 'indices '(test-data))
70 (method-make-forward! <hw-immediate> 'values '(test-data))
72 ; This can't use method-make-forward! as we need to call op:type to
73 ; resolve the hardware reference.
78 (send (op:type self) 'test-data n))
81 ; Given an operand, return a set of N test data.
82 ; e.g. For a keyword operand, return a random subset.
83 ; For a number, return N numbers.
85 (define (operand-test-data op n)
86 (send op 'test-data n)
89 ; Given the broken out assembler syntax string, return the list of operand
92 (define (extract-operands syntax-list)
93 (let loop ((result nil) (l syntax-list))
94 (cond ((null? l) (reverse result))
95 ((object? (car l)) (loop (cons (car l) result) (cdr l)))
96 (else (loop result (cdr l)))))
99 ; Given a list of operands for an instruction, return the test set
100 ; (all possible combinations).
101 ; N is the number of testcases for each operand.
102 ; The result has N to-the-power (length OP-LIST) elements.
104 (define (build-test-set op-list n)
105 (let ((test-data (map (lambda (op) (operand-test-data op n)) op-list))
106 (len (length op-list)))
107 ; FIXME: Make slicker later.
108 (cond ((=? len 0) (list (list)))
109 ((=? len 1) test-data)
110 (else (list (map car test-data)))))
113 ; Given an assembler expression and a set of operands build a testcase.
114 ; SYNTAX-LIST is a list of syntax elements (characters) and <operand> objects.
115 ; TEST-DATA is a list of strings, one element per operand.
118 (define (build-sim-testcase syntax-list test-data)
119 (logit 3 "Building a testcase for: "
127 (with-output-to-string
128 (lambda () (display sl)))))))
131 (map (lambda (td) (list " " td))
134 (let loop ((result nil) (sl syntax-list) (td test-data))
135 ;(display (list result sl td "\n"))
138 (apply string-append (reverse result))
141 (loop (cons (car sl) result) (cdr sl) td))
142 (else (loop (cons (car td) result) (cdr sl) (cdr td)))))
145 ; Generate a set of testcases for INSN.
148 (define (gen-sim-test insn)
149 (logit 2 "Generating sim test set for " (obj:name insn) " ...\n")
151 "\t.global " (gen-sym insn) "\n"
153 (let* ((syntax-list (insn-tmp insn))
154 (op-list (extract-operands syntax-list))
155 (test-set (build-test-set op-list 2)))
156 (string-map (lambda (test-data)
157 (build-sim-testcase syntax-list test-data))
162 ; Generate the shell script that builds the .cgs files.
163 ; .cgs are .s files except that there may be other .s files in the directory
164 ; and we want the .exp driver script to easily find the files.
166 ; Eventually it would be nice to generate as much of the testcase as possible.
167 ; For now we just generate the template and leave the programmer to fill in
168 ; the guts of the test (i.e. set up various registers, execute the insn to be
169 ; tested, and then verify the results).
170 ; Clearly some hand generated testcases will also be needed, but this
171 ; provides a good start for each instruction.
173 (define (cgen-build.sh)
174 (logit 1 "Generating sim-build.sh ...\n")
178 # Generate test result data for " (current-arch-name) " simulator testing.
179 # This script is machine generated.
180 # It is intended to be run in the testsuite source directory.
182 # Syntax: /bin/sh sim-build.sh
184 # Put results here, so we preserve the existing set for comparison.
190 (string-map (lambda (insn)
192 "cat <<EOF > " (gen-file-name (obj:name insn)) ".cgs\n"
193 ; FIXME: Need to record assembler line comment char in .cpu.
194 "# " (current-arch-name) " testcase for " (backslash "$" (insn-syntax insn)) " -*- Asm -*-\n"
196 (let ((machs (insn-machs insn)))
199 (string-drop1 (string-map (lambda (mach)
200 (string-append "," mach))
203 "\t.include \"testutils.inc\"\n\n"
208 (non-alias-insns (current-insn-list)))
212 ; Generate the dejagnu allinsn.exp file that drives the tests.
214 (define (cgen-allinsn.exp)
215 (logit 1 "Generating sim-allinsn.exp ...\n")
218 # " (string-upcase (current-arch-name)) " simulator testsuite.
220 if [istarget " (current-arch-name) "*-*-*] {
221 # load support procs (none yet)
226 (string-drop1 (string-map (lambda (m)
229 (current-mach-list)))
232 # The .cgs suffix is for \"cgen .s\".
233 foreach src [lsort [glob -nocomplain $srcdir/$subdir/*.cgs]] {
234 # If we're only testing specific files and this isn't one of them,
236 if ![runtest_file_p $runtests $src] {
240 run_sim_test $src $all_machs