-
Notifications
You must be signed in to change notification settings - Fork 77
/
Copy pathtest_llvm.py
35 lines (26 loc) · 1.27 KB
/
test_llvm.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
from xdsl.dialects import llvm, builtin, arith
def test_llvm_pointer_ops():
module = builtin.ModuleOp.from_region_or_ops([
idx := arith.Constant.from_int_and_width(0, 64),
ptr := llvm.IntToPtrOp.get(idx, ptr_type=builtin.i32),
llvm.LoadOp.get(ptr),
nullptr := llvm.NullOp.get(),
alloc_ptr := llvm.AllocaOp.get(idx, elem_type=builtin.IndexType()),
llvm.LoadOp.get(alloc_ptr),
])
module.verify()
assert len(alloc_ptr.res.uses) == 1
assert ptr.input is idx.result
assert isinstance(ptr.output.typ, llvm.LLVMPointerType)
assert ptr.output.typ.type == builtin.i32
assert isinstance(ptr.output.typ.addr_space, builtin.NoneAttr)
assert isinstance(nullptr.nullptr.typ, llvm.LLVMPointerType)
assert isinstance(nullptr.nullptr.typ.type, builtin.NoneAttr)
assert isinstance(nullptr.nullptr.typ.addr_space, builtin.NoneAttr)
def test_llvm_pointer_type():
assert llvm.LLVMPointerType.typed(builtin.i64).type is builtin.i64
assert isinstance(
llvm.LLVMPointerType.typed(builtin.i64).addr_space, builtin.NoneAttr)
assert isinstance(llvm.LLVMPointerType.untyped().type, builtin.NoneAttr)
assert isinstance(llvm.LLVMPointerType.untyped().addr_space,
builtin.NoneAttr)