2020-06-09 04:46:06 +08:00
|
|
|
# RUN: %PYTHON %s | npcomp-opt -split-input-file | FileCheck %s --dump-input=fail
|
|
|
|
|
|
|
|
from npcomp.compiler.frontend import *
|
|
|
|
|
|
|
|
|
|
|
|
def import_global(f):
|
|
|
|
fe = ImportFrontend()
|
|
|
|
fe.import_global_function(f)
|
|
|
|
print("// -----")
|
|
|
|
print(fe.ir_module.to_asm())
|
|
|
|
return f
|
|
|
|
|
|
|
|
|
|
|
|
# Full checking for add. Others just check validity.
|
|
|
|
# CHECK-LABEL: func @add
|
|
|
|
@import_global
|
|
|
|
def add():
|
|
|
|
# CHECK: %[[A:.*]] = constant 1 : i64
|
|
|
|
# CHECK: %[[B:.*]] = constant 2 : i64
|
|
|
|
a = 1
|
|
|
|
b = 2
|
2020-06-09 09:29:14 +08:00
|
|
|
# CHECK: {{.*}} = basicpy.binary_expr %[[A]] "Add" %[[B]] : (i64, i64) -> !basicpy.UnknownType
|
2020-06-09 04:46:06 +08:00
|
|
|
return a + b
|
|
|
|
|
2020-06-14 05:53:54 +08:00
|
|
|
|
2020-06-09 04:46:06 +08:00
|
|
|
# CHECK-LABEL: func @sub
|
|
|
|
@import_global
|
|
|
|
def sub():
|
2020-06-09 09:29:14 +08:00
|
|
|
# CHECK: basicpy.binary_expr {{.*}} "Sub"
|
2020-06-09 04:46:06 +08:00
|
|
|
return 4 - 2
|
|
|
|
|
2020-06-14 05:53:54 +08:00
|
|
|
|
2020-06-09 04:46:06 +08:00
|
|
|
# CHECK-LABEL: func @mult
|
|
|
|
@import_global
|
|
|
|
def mult():
|
2020-06-09 09:29:14 +08:00
|
|
|
# CHECK: basicpy.binary_expr {{.*}} "Mult"
|
2020-06-09 04:46:06 +08:00
|
|
|
return 4 * 2
|
|
|
|
|
2020-06-14 05:53:54 +08:00
|
|
|
|
2020-06-09 04:46:06 +08:00
|
|
|
# CHECK-LABEL: func @div
|
|
|
|
@import_global
|
|
|
|
def div():
|
2020-06-09 09:29:14 +08:00
|
|
|
# CHECK: basicpy.binary_expr {{.*}} "Div"
|
2020-06-09 04:46:06 +08:00
|
|
|
return 4 / 2
|
|
|
|
|
2020-06-14 05:53:54 +08:00
|
|
|
|
2020-06-09 04:46:06 +08:00
|
|
|
# CHECK-LABEL: func @floor_div
|
|
|
|
@import_global
|
|
|
|
def floor_div():
|
2020-06-09 09:29:14 +08:00
|
|
|
# CHECK: basicpy.binary_expr {{.*}} "FloorDiv"
|
2020-06-09 04:46:06 +08:00
|
|
|
return 4 // 2
|
|
|
|
|
2020-06-14 05:53:54 +08:00
|
|
|
|
2020-06-09 04:46:06 +08:00
|
|
|
# CHECK-LABEL: func @matmul
|
|
|
|
@import_global
|
|
|
|
def matmul():
|
2020-06-09 09:29:14 +08:00
|
|
|
# CHECK: basicpy.binary_expr {{.*}} "MatMult"
|
2020-06-09 04:46:06 +08:00
|
|
|
return 4 @ 2
|
|
|
|
|
2020-06-14 05:53:54 +08:00
|
|
|
|
2020-06-09 04:46:06 +08:00
|
|
|
# CHECK-LABEL: func @modulo
|
|
|
|
@import_global
|
|
|
|
def modulo():
|
2020-06-09 09:29:14 +08:00
|
|
|
# CHECK: basicpy.binary_expr {{.*}} "Mod"
|
2020-06-09 04:46:06 +08:00
|
|
|
return 4 % 2
|
|
|
|
|
2020-06-14 05:53:54 +08:00
|
|
|
|
2020-06-09 04:46:06 +08:00
|
|
|
# CHECK-LABEL: func @left_shift
|
|
|
|
@import_global
|
|
|
|
def left_shift():
|
2020-06-09 09:29:14 +08:00
|
|
|
# CHECK: basicpy.binary_expr {{.*}} "LShift"
|
2020-06-09 04:46:06 +08:00
|
|
|
return 4 << 2
|
|
|
|
|
2020-06-14 05:53:54 +08:00
|
|
|
|
2020-06-09 04:46:06 +08:00
|
|
|
# CHECK-LABEL: func @right_shift
|
|
|
|
@import_global
|
|
|
|
def right_shift():
|
2020-06-09 09:29:14 +08:00
|
|
|
# CHECK: basicpy.binary_expr {{.*}} "RShift"
|
2020-06-09 04:46:06 +08:00
|
|
|
return 4 >> 2
|
|
|
|
|
2020-06-14 05:53:54 +08:00
|
|
|
|
2020-06-09 04:46:06 +08:00
|
|
|
# CHECK-LABEL: func @bit_and
|
|
|
|
@import_global
|
|
|
|
def bit_and():
|
2020-06-09 09:29:14 +08:00
|
|
|
# CHECK: basicpy.binary_expr {{.*}} "BitAnd"
|
2020-06-09 04:46:06 +08:00
|
|
|
return 4 & 2
|
|
|
|
|
2020-06-14 05:53:54 +08:00
|
|
|
|
2020-06-09 04:46:06 +08:00
|
|
|
# CHECK-LABEL: func @bit_xor
|
|
|
|
@import_global
|
|
|
|
def bit_xor():
|
2020-06-09 09:29:14 +08:00
|
|
|
# CHECK: basicpy.binary_expr {{.*}} "BitXor"
|
2020-06-09 04:46:06 +08:00
|
|
|
return 4 ^ 2
|
|
|
|
|
2020-06-14 05:53:54 +08:00
|
|
|
|
2020-06-09 04:46:06 +08:00
|
|
|
# CHECK-LABEL: func @bit_or
|
|
|
|
@import_global
|
|
|
|
def bit_or():
|
2020-06-09 09:29:14 +08:00
|
|
|
# CHECK: basicpy.binary_expr {{.*}} "BitOr"
|
2020-06-09 04:46:06 +08:00
|
|
|
return 4 | 2
|