xref: /llvm-project/mlir/test/Target/Cpp/cast.mlir (revision 84fe39a45b7340d468378f58836c8559fda3959b)
1// RUN: mlir-translate -mlir-to-cpp %s | FileCheck %s
2// CHECK-LABEL: void cast
3func.func @cast(%arg0 : i32) {
4  // CHECK-NEXT: uint32_t [[V1:[^ ]*]] = (uint32_t) [[V0:[^ ]*]]
5  %1 = emitc.cast %arg0: i32 to ui32
6
7  // CHECK-NEXT: int64_t [[V4:[^ ]*]] = (int64_t) [[V0:[^ ]*]]
8  %2 = emitc.cast %arg0: i32 to i64
9  // CHECK-NEXT: int64_t [[V5:[^ ]*]] = (uint64_t) [[V0:[^ ]*]]
10  %3 = emitc.cast %arg0: i32 to ui64
11
12  // CHECK-NEXT: float [[V4:[^ ]*]] = (float) [[V0:[^ ]*]]
13  %4 = emitc.cast %arg0: i32 to f32
14  // CHECK-NEXT: double [[V5:[^ ]*]] = (double) [[V0:[^ ]*]]
15  %5 = emitc.cast %arg0: i32 to f64
16
17  // CHECK-NEXT: bool [[V6:[^ ]*]] = (bool) [[V0:[^ ]*]]
18  %6 = emitc.cast %arg0: i32 to i1
19
20  // CHECK-NEXT: mytype [[V7:[^ ]*]] = (mytype) [[V0:[^ ]*]]
21  %7 = emitc.cast %arg0: i32 to !emitc.opaque<"mytype">
22  return
23}
24
25// CHECK-LABEL: void cast_ptr
26func.func @cast_ptr(%arg0 : !emitc.ptr<!emitc.opaque<"void">>) {
27  // CHECK-NEXT: int32_t* [[V1:[^ ]*]] = (int32_t*) [[V0:[^ ]*]]
28  %1 = emitc.cast %arg0 : !emitc.ptr<!emitc.opaque<"void">> to !emitc.ptr<i32>
29  return
30}
31