From 9c2895e4ed7c9932cb9a54a74041cca70272dd70 Mon Sep 17 00:00:00 2001 From: Enrico Lumetti Date: Mon, 15 Aug 2022 02:30:34 +0200 Subject: [PATCH] add more tests --- select-instr.rkt | 8 +++++++- tests/test-select-instr.rkt | 22 +++++++++++++++++++--- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/select-instr.rkt b/select-instr.rkt index ed00825..740e6d3 100644 --- a/select-instr.rkt +++ b/select-instr.rkt @@ -3,10 +3,16 @@ (require (prefix-in bril: bril/lang)) (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! (define (bril-instr-to-aarch64var bril-instr) (match bril-instr - [(bril:Label label) (Label label)] + [(bril:Label label) (list (Label label))] [(bril:ConstantInstr dest-name _ (bril:Int const-val)) (list (LMov (Imm const-val) (Var dest-name)))] [(bril:ValueInstr op dest type args _ _) diff --git a/tests/test-select-instr.rkt b/tests/test-select-instr.rkt index 8cadb2f..ede06aa 100644 --- a/tests/test-select-instr.rkt +++ b/tests/test-select-instr.rkt @@ -6,7 +6,8 @@ (require (prefix-in bril: bril/lang)) (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-add @@ -16,6 +17,10 @@ (define bril-return (bril:EffectInstr 'return '("x") '() '())) +(define bril-func + (bril:Function "main" '() (bril:Type 'int) + (list bril-label bril-add bril-return))) + (define select-instr-tests (test-suite "Instruction Selection Tests" @@ -24,7 +29,7 @@ (test-case "Label" (check-equal? (bril-instr-to-aarch64var bril-label) - (Label "main"))) + (list (Label "main")))) (test-case "Addition" (check-equal? (bril-instr-to-aarch64var bril-add) @@ -37,4 +42,15 @@ "Return" (check-equal? (bril-instr-to-aarch64var bril-return) (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))))))) + +