-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathir.py
63 lines (53 loc) · 1.99 KB
/
ir.py
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
""" We use the very cool library asdl_gen to convert a
string ASDL definition to a hierarchy of classes.
"""
from asdl_gen import ADT
def generate_asdl_file():
# TODO: detect if the generated file already exists
# and if it has an earlier modification date compared to ir.py
# if so, don't bother to generate the file
ADT("""
module loma {
func = FunctionDef ( string id, arg* args, stmt* body, bool is_simd, type? ret_type )
| ForwardDiff ( string id, string primal_func )
| ReverseDiff ( string id, string primal_func )
attributes ( int? lineno )
stmt = Assign ( expr target, expr val )
| Declare ( string target, type t, expr? val )
| Return ( expr val )
| IfElse ( expr cond, stmt* then_stmts, stmt* else_stmts )
| While ( expr cond, int max_iter, stmt* body )
| CallStmt ( expr call )
attributes ( int? lineno )
expr = Var ( string id )
| ArrayAccess ( expr array, expr index )
| StructAccess ( expr struct, string member_id )
| ConstFloat ( float val )
| ConstInt ( int val )
| BinaryOp ( bin_op op, expr left, expr right )
| Call ( string id, expr* args )
attributes ( int? lineno, type? t )
arg = Arg ( string id, type t, inout i )
type = Int ( )
| Float ( )
| Array ( type t, int? static_size )
| Struct ( string id, struct_member* members, int? lineno )
| Diff ( type t )
struct_member = MemberDef ( string id, type t )
bin_op = Add()
| Sub()
| Mul()
| Div()
| Less()
| LessEqual()
| Greater()
| GreaterEqual()
| Equal()
| And()
| Or()
inout = In() | Out()
}
""",
header= '',
ext_types = {},
memoize = [])