-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIR.hs
59 lines (46 loc) · 1.05 KB
/
IR.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
-- defines the types of the Graph data type, which we will use to represent
-- the Torch IR in Haskell
module IR where
import Text.Printf
type Variable = String
type Nullable = Bool
type IsList = Bool
data BaseType
= Tensor
| Integer
| Boolean
| Float
| Device
| String
| Other String
deriving (Eq, Show)
data Type =
Type BaseType Nullable IsList
deriving (Eq, Show)
data VT =
VT Variable Type
deriving (Eq, Show)
data Func
= Constant (Maybe (Either Int String)) -- for constant assignments
| NamedFunc String
deriving (Eq, Show) -- for all other functions
data LineAnnot =
LineAnnot String Int Int
deriving (Eq, Show)
data Block =
Block [VT] [Statement] [Variable]
deriving (Eq, Show)
data Assignment =
Assignment [VT] Func [Variable] (Maybe LineAnnot)
deriving (Eq, Show)
data Statement
= Assign Assignment
| If Assignment Block Block
| Loop Assignment Block
deriving (Eq, Show)
data Graph =
Graph
[VT] -- args
[Statement] -- actual code
[Variable] -- return variables
deriving (Eq, Show)