-
Notifications
You must be signed in to change notification settings - Fork 82
/
build-benchmarks.scm
76 lines (69 loc) · 2.19 KB
/
build-benchmarks.scm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
; run-tests.scm <filename-with-extension>
; For example,
; ./run-tests.scm bench-add-vector.kfc
; generates the file
; test.bin/bench-add-vector.kfc.out
; containing timing information
(import
(rnrs)
(util color)
(elegant-weapons match)
(elegant-weapons sets)
(except (elegant-weapons compat) make-parameter parameterize)
(util system)
(util compat)
(harlan driver)
(harlan compiler)
(harlan compile-opts))
(define (enumerate-tests)
'("bench-add-vector.kfc"
"bench-dot-prod.kfc"
"bench-nbody.kfc"
"bench-bfs-color.kfc"
;;"bench-raytrace.kfc"
))
(define-syntax try
(syntax-rules (catch)
((_ (catch (x) handler-body ... e)
body ...)
(call/cc (lambda (k)
(with-exception-handler
(lambda (x)
handler-body ... (k e))
(lambda ()
body ...)))))))
(define (do-test test)
(let* ((path (join-path "test" test))
(bin-path (join-path "./test.bin" (string-append test ".bin")))
(out-path (join-path "./test.bin" (string-append test ".out")))
(test-source
(lambda (name source)
(printf "Generating C++...")
(flush-output-port (current-output-port))
(try (catch (x)
(if (or (error? x) (condition? x))
(begin
(with-color 'red (printf "FAILED\n")))))
(let ((c++ (harlan->c++ source)))
(printf "OK\n")
(printf "Compiling...")
(g++-compile-stdin c++ bin-path)
(printf "OK\n"))))))
(printf "Test ~a\n" path)
(flush-output-port (current-output-port))
(let-values (((source spec) (read-source path)))
(begin
(if (file-exists? out-path) (delete-file out-path))
(test-source path source)))))
(define (do-*all*-the-tests)
(begin
(map do-test (enumerate-tests))
(flush-output-port (current-output-port))))
(define (run-tests cl)
(let loop ((cl (parse-args (cdr cl))))
(cond
((null? cl)
(if (do-*all*-the-tests) (exit) (exit #f)))
(else
(begin (do-test (car cl)) (exit))))))
(run-tests (command-line))