-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCLang.hs
79 lines (64 loc) · 1.78 KB
/
CLang.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
module CLang where
import Data.Word
-- C Lanuage definition, but with some of our
-- types that will later get translated by the C
-- Generator
data Prog = Prog { includes :: [String],
units :: [Unit]
}
deriving (Eq, Show)
data Mods = Extern | Const | Static
deriving (Eq, Show)
data Unit = Decl Decl
| FunDecl Funtype
| FunDef Funtype Block
deriving (Eq, Show)
type Block = ([Decl], Stmt)
data Decl = VarDecl String Type (Maybe Expr) [Mods]
deriving (Eq, Show)
data Funtype = Funtype { name :: String,
args :: [(String, Type)],
mods :: [Mods],
ret :: Type }
deriving (Eq, Show)
data LValue = LVar String
| Access Expr Expr
deriving (Eq, Show)
data Stmt = If Expr Block Block
| Seq Stmt Stmt
| Return Expr
| Skip
| For Expr Expr Expr Block
| Expr Expr
| Comment String
deriving (Eq, Show)
data Expr = BinOp BinOp Expr Expr
| UnOp UnOp Expr
| ConstInt Int
| ConstFloat Double
| Call String [Expr]
| LV LValue
| ConstBool Bool
| Arr [Expr]
| ConstStr String
| StructVal [(String, Expr)]
deriving (Eq, Show)
data BinOp = Plus | Minus | Div | Prod
| Eq | Neq | Mod | And | Or
| Lt | Gt | Le | Ge
| Band | Bor | Xor
| Member -- "->"
| Assign
deriving (Eq, Show)
data UnOp = NegateNum | Not | Bnot | Address | Deref
deriving (Eq, Show)
data Type = Int
| Bool
| ArrT Type (Maybe Int)
| Custom String
| UChar
| PtrTo Type
deriving (Eq, Show)
sseq Skip s = s
sseq s Skip = s
sseq s t = Seq s t