-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-solver.rkt
50 lines (42 loc) · 1.31 KB
/
test-solver.rkt
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
#lang s-exp rosette
(require "arm-solver.rkt" "arm-machine.rkt" "arm-printer.rkt"
"arm-parser.rkt" "arm-ast.rkt" "arm-simulator-rosette.rkt")
(define parser (new arm-parser%))
(define machine (new arm-machine%))
(send machine set-config (list 12 4 4))
(define printer (new arm-printer% [machine machine]))
(define solver (new arm-solver% [machine machine] [printer printer]))
(define simulator-rosette (new arm-simulator-rosette% [machine machine]))
(define code
(send parser ast-from-string "
mov r0, r2, asl #2
rsb r5, r0, r2
mul r2, r6, r2
mov r5, r5, asl #11
sub r5, r5, #12
rsb r3, r2, r3
mla r3, r5, r10, r3
mla r1, r11, r1, r3
"))
(define sketch
(send parser ast-from-string "
sub r5, r2, r2, lsl 2
mul r2, r6, r2
mov r5, r5, lsl 11
sub r5, r5, 12
rsb r3, r2, r3
mla r3, r5, r10, r3
mla r1, r11, r1, r3
"))
(define encoded-code (send printer encode code))
(define encoded-sketch (send printer encode sketch))
;; Return counterexample if code and sketch are different.
;; Otherwise, return #f.
(define ex
(send solver counterexample encoded-code encoded-sketch
(constraint machine [reg 1] [mem])))
(pretty-display "Counterexample:")
(if ex
(send machine display-state ex)
(pretty-display "No"))
(newline)