72 lines
2.0 KiB
Racket
72 lines
2.0 KiB
Racket
#lang racket
|
|
|
|
(require "select-instructions.rkt")
|
|
(require "test-util.rkt")
|
|
|
|
(define programs
|
|
(list
|
|
`(program ()
|
|
((start .
|
|
(return (+ 2 3)))))
|
|
`(program ()
|
|
((start .
|
|
(seq (assign x 3)
|
|
(return (+ 2 x))))))
|
|
`(program ()
|
|
((start .
|
|
(seq (assign tmp.1 (read))
|
|
(return (+ tmp.1 3))))))
|
|
`(program ()
|
|
((start .
|
|
(seq (assign tmp.1 (- 1))
|
|
(seq (assign x.1 (+ tmp.1 2))
|
|
(seq (assign tmp.2 (+ x.1 2))
|
|
(seq (assign tmp.3 (+ 4 5))
|
|
(return (+ tmp.2 tmp.3)))))))))))
|
|
|
|
|
|
(test-eq (select-instructions (list-ref programs 0))
|
|
`(AArch64VProgram
|
|
()
|
|
(start
|
|
Block
|
|
`()
|
|
((Instr mov (x0 (Imm 2)))
|
|
(Instr add (x0 x0 (Imm 3)))
|
|
(Instr b (conclusion))))))
|
|
|
|
(test-eq (select-instructions (list-ref programs 1))
|
|
`(AArch64VProgram
|
|
()
|
|
(start
|
|
Block
|
|
`()
|
|
((Instr mov ((Var x) (Imm 3)))
|
|
(Instr add (x0 (Var x) (Imm 2)))
|
|
(Instr b (conclusion))))))
|
|
|
|
(test-eq (select-instructions (list-ref programs 2))
|
|
`(AArch64VProgram
|
|
()
|
|
(start
|
|
Block
|
|
`()
|
|
((Instr bl _builtin_read)
|
|
(Instr mov ((Var tmp.1) x0))
|
|
(Instr add (x0 (Var tmp.1) (Imm 3)))
|
|
(Instr b (conclusion))))))
|
|
|
|
(test-eq (select-instructions (list-ref programs 3))
|
|
`(AArch64VProgram
|
|
()
|
|
(start
|
|
Block
|
|
`()
|
|
((Instr neg ((Var tmp.1) (Imm 1)))
|
|
(Instr add ((Var x.1) (Var tmp.1) (Imm 2)))
|
|
(Instr add ((Var tmp.2) (Var x.1) (Imm 2)))
|
|
(Instr mov ((Var tmp.3) (Imm 4)))
|
|
(Instr add ((Var tmp.3) (Var tmp.3) (Imm 5)))
|
|
(Instr add (x0 (Var tmp.2) (Var tmp.3)))
|
|
(Instr b (conclusion))))))
|