-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathInferRegionScope.hs
64 lines (50 loc) · 2.05 KB
/
InferRegionScope.hs
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
{-# LANGUAGE TemplateHaskell #-}
-- | Tests for RouteEnds2
--
module InferRegionScope where
import Data.Set as S
import Data.Map as M
import Test.Tasty
import Test.Tasty.HUnit
import Test.Tasty.TH
import Gibbon.Common hiding (FunDef)
import Gibbon.L2.Syntax as L2
import Gibbon.L2.Examples
import Gibbon.Passes.InferRegionScope
import qualified Gibbon.L1.Syntax as L1
-- Region escapes scope, hence is global
case_t1 :: Assertion
case_t1 = expected @=? actual
where
actual = fst $ defaultPackedRunPassM $ inferRegScopeExp M.empty test1
test1 :: L2.Exp2
test1 = Ext $ LetRegionE (VarR "r1") Undefined Nothing $
Ext $ LetLocE (singleLocVar "l1") (StartOfRegionLE (VarR "r1")) $
LetE ("x1",[],PackedTy "A" (singleLocVar "l1"),
DataConE (singleLocVar "l1") "A" [LitE 1]) $
VarE "x1"
expected :: L2.Exp2
expected = Ext $ LetRegionE (GlobR "r1" Infinite) Undefined Nothing $
Ext $ LetLocE (singleLocVar "l1") (StartOfRegionLE (GlobR "r1" Infinite)) $
LetE ("x1",[],PackedTy "A" (singleLocVar "l1"),
DataConE (singleLocVar "l1") "A" [LitE 1]) $
VarE "x1"
-- A local, stack allocated region
case_t2 :: Assertion
case_t2 = expected @=? actual
where
actual = fst $ defaultPackedRunPassM $ inferRegScopeExp M.empty test1
test1 :: L2.Exp2
test1 = Ext $ LetRegionE (VarR "r1") Undefined Nothing $
Ext $ LetLocE (singleLocVar "l1") (StartOfRegionLE (VarR "r1")) $
LetE ("x1",[],PackedTy "A" (singleLocVar "l1"),
DataConE (singleLocVar "l1") "A" [LitE 1]) $
LitE 1
expected :: L2.Exp2
expected = Ext $ LetRegionE (GlobR "r1" Infinite) Undefined Nothing $
Ext $ LetLocE (singleLocVar "l1") (StartOfRegionLE (GlobR "r1" Infinite)) $
LetE ("x1",[],PackedTy "A" (singleLocVar "l1"),
DataConE (singleLocVar "l1") "A" [LitE 1]) $
LitE 1
inferRegScopeTests :: TestTree
inferRegScopeTests = $(testGroupGenerator)