;; CPU to use for the testsuite. -*- Scheme -*-

(define-arch
  (name testsuite) ; name of cpu
  (comment ".cpu file for the testsuite")
  (insn-lsb0? #t)
  (machs testb)
  (isas test)
)

(define-isa
  (name test)
  (base-insn-bitsize 16)
  (decode-assist (0 1 2 3))
)
  
(define-cpu
  (name testf)
  (comment "experimental cpu family")
  (endian little)
  (word-bitsize 32)
)

(define-mach
  (name testb)
  (comment "mach for testsuite")
  (cpu testf)
)

(define-model
  (name test) (comment "test") (attrs)
  (mach testb)
  ;(pipeline all "" () ((fetch) (decode) (execute) (writeback)))
  (unit u-exec "Execution Unit" () 1 1 () () () ())
)

;; Some useful pmacros for testcases.

(if (rtl-version-at-least? 0 9)
    (begin
      (define-pmacro /begin %begin)
      (define-pmacro /print %print)
      (define-pmacro /dump %dump))
    (begin
      (define-pmacro /begin .begin)
      (define-pmacro /print .print)
      (define-pmacro /dump .dump)))

(define-pmacro (newline) (/print "\n"))

;; Record name of test for debugging purposes.

(define-pmacro (test-name name)
  (/print "TEST: " name "\n")
)

;; Print TEXT as the expected output.

(define-pmacro (print-match text)
  (/begin
   (/print "MATCH: ")
   (/print text)
   (newline))
)

;; Print EXPR as the text to be verified.

(define-pmacro (print-expr expr)
  (/begin
   (/print "EXPR: ")
   (/dump expr)
   (newline))
)

;; THUNK is invoked to exercise whatever is being tested.

(define-pmacro (print-thunk thunk)
  (/begin
   (/print "EXPR: ")
   (thunk)
   (newline))
)

;; Wrapper around .internal-test to include pass/fail messages.

(if (rtl-version-at-least? 0 9)
    (define-pmacro (internal-verify test-name expr)
      (%if (%internal-test expr)
	   (%print "PASS: " test-name "\n")
	   (%print "FAIL: " test-name "\n")))
    (define-pmacro (internal-verify test-name expr)
      (.if (.internal-test expr)
	   (.print "PASS: " test-name "\n")
	   (.print "FAIL: " test-name "\n")))
)
