Repository navigation
Expand file tree
/
Copy pathfunc.py
More file actions
58 lines (44 loc) · 1.85 KB
/
Copy pathfunc.py
File metadata and controls
58 lines (44 loc) · 1.85 KB
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
import inspect
import sys
from typing import List, Tuple, Optional, Union
from dataclasses import dataclass
import mlir.astnodes as mast
from mlir.dialect import Dialect, DialectOp, is_op
Literal = Union[mast.StringLiteral, float, int, bool]
SsaUse = Union[mast.SsaId, Literal]
@dataclass
class CallIndirectOperation(DialectOp):
func: mast.SymbolRefId
type: mast.FunctionType
args: Optional[List[SsaUse]] = None
_syntax_ = ['func.call_indirect {func.symbol_ref_id} () : {type.function_type}',
'func.call_indirect {func.symbol_ref_id} ( {args.ssa_use_list} ) : {type.function_type}']
@dataclass
class CallOperation(DialectOp):
func: mast.SymbolRefId
type: mast.FunctionType
args: Optional[List[SsaUse]] = None
_syntax_ = ['func.call {func.symbol_ref_id} () : {type.function_type}',
'func.call {func.symbol_ref_id} ( {args.ssa_use_list} ) : {type.function_type}']
@dataclass
class ConstantOperation(DialectOp):
value: mast.SymbolRefId
type: mast.Type
_syntax_ = ['func.constant {value.symbol_ref_id} : {type.type}']
# Note: The 'func.func' operation is defined as 'function' in mlir.lark.
@dataclass
class ReturnOperation(DialectOp):
values: Optional[List[SsaUse]] = None
types: Optional[List[mast.Type]] = None
_syntax_ = ['return',
'return {values.ssa_use_list} : {types.type_list_no_parens}']
def dump(self, indent: int = 0) -> str:
output = 'return'
if self.values:
output += ' ' + ', '.join([v.dump(indent) for v in self.values])
if self.types:
output += ' : ' + ', '.join([t.dump(indent) for t in self.types])
return output
# Inspect current module to get all classes defined above
func = Dialect('func', ops=[m[1] for m in inspect.getmembers(
sys.modules[__name__], lambda obj: is_op(obj, __name__))])