add more tests

This commit is contained in:
Enrico Lumetti 2022-08-15 02:30:34 +02:00
parent 3c41cf9876
commit 9c2895e4ed
2 changed files with 26 additions and 4 deletions

View File

@ -3,10 +3,16 @@
(require (prefix-in bril: bril/lang)) (require (prefix-in bril: bril/lang))
(require "aarch64var.rkt") (require "aarch64var.rkt")
(define (bril-function-to-aarch64var function)
(match function
[(bril:Function name args ret-type instrs)
(foldr append '()
(map bril-instr-to-aarch64var instrs))]))
; only deals with int64 type! ; only deals with int64 type!
(define (bril-instr-to-aarch64var bril-instr) (define (bril-instr-to-aarch64var bril-instr)
(match bril-instr (match bril-instr
[(bril:Label label) (Label label)] [(bril:Label label) (list (Label label))]
[(bril:ConstantInstr dest-name _ (bril:Int const-val)) [(bril:ConstantInstr dest-name _ (bril:Int const-val))
(list (LMov (Imm const-val) (Var dest-name)))] (list (LMov (Imm const-val) (Var dest-name)))]
[(bril:ValueInstr op dest type args _ _) [(bril:ValueInstr op dest type args _ _)

View File

@ -6,7 +6,8 @@
(require (prefix-in bril: bril/lang)) (require (prefix-in bril: bril/lang))
(require "../aarch64var.rkt") (require "../aarch64var.rkt")
(require/expose "../select-instr.rkt" (bril-instr-to-aarch64var)) (require/expose "../select-instr.rkt"
(bril-instr-to-aarch64var bril-function-to-aarch64var))
(define bril-label (bril:Label "main")) (define bril-label (bril:Label "main"))
(define bril-add (define bril-add
@ -16,6 +17,10 @@
(define bril-return (define bril-return
(bril:EffectInstr 'return '("x") '() '())) (bril:EffectInstr 'return '("x") '() '()))
(define bril-func
(bril:Function "main" '() (bril:Type 'int)
(list bril-label bril-add bril-return)))
(define select-instr-tests (define select-instr-tests
(test-suite (test-suite
"Instruction Selection Tests" "Instruction Selection Tests"
@ -24,7 +29,7 @@
(test-case (test-case
"Label" "Label"
(check-equal? (bril-instr-to-aarch64var bril-label) (check-equal? (bril-instr-to-aarch64var bril-label)
(Label "main"))) (list (Label "main"))))
(test-case (test-case
"Addition" "Addition"
(check-equal? (bril-instr-to-aarch64var bril-add) (check-equal? (bril-instr-to-aarch64var bril-add)
@ -37,4 +42,15 @@
"Return" "Return"
(check-equal? (bril-instr-to-aarch64var bril-return) (check-equal? (bril-instr-to-aarch64var bril-return)
(list (LMov (Reg 'x0) (Var "x")) (list (LMov (Reg 'x0) (Var "x"))
(RetDefault))))))) (RetDefault)))))
(test-suite
"Function translation"
(test-case
"Simple function"
(check-equal? (bril-function-to-aarch64var bril-func)
(list (Label "main")
(Add (Var "c") (Var "d") (Var "a"))
(LMov (Reg 'x0) (Var "x"))
(RetDefault)))))))