This models a one or multi-dimensional C/C++ array. The type implements the `ShapedTypeInterface` and prints similar to memref/tensor: ``` %arg0: !emitc.array<1xf32>, %arg1: !emitc.array<10x20x30xi32>, %arg2: !emitc.array<30x!emitc.ptr<i32>>, %arg3: !emitc.array<30x!emitc.opaque<"int">> ``` It can be translated to a C array type when used as function parameter or as `emitc.variable` type.
46 lines
1.5 KiB
MLIR
46 lines
1.5 KiB
MLIR
// RUN: mlir-translate -mlir-to-cpp %s | FileCheck %s -check-prefix=CPP-DEFAULT
|
|
// RUN: mlir-translate -mlir-to-cpp -declare-variables-at-top %s | FileCheck %s -check-prefix=CPP-DECLTOP
|
|
|
|
|
|
emitc.func @emitc_func(%arg0 : i32) {
|
|
emitc.call_opaque "foo" (%arg0) : (i32) -> ()
|
|
emitc.return
|
|
}
|
|
// CPP-DEFAULT: void emitc_func(int32_t [[V0:[^ ]*]]) {
|
|
// CPP-DEFAULT-NEXT: foo([[V0:[^ ]*]]);
|
|
// CPP-DEFAULT-NEXT: return;
|
|
|
|
|
|
emitc.func @return_i32() -> i32 attributes {specifiers = ["static","inline"]} {
|
|
%0 = emitc.call_opaque "foo" (): () -> i32
|
|
emitc.return %0 : i32
|
|
}
|
|
// CPP-DEFAULT: static inline int32_t return_i32() {
|
|
// CPP-DEFAULT-NEXT: [[V0:[^ ]*]] = foo();
|
|
// CPP-DEFAULT-NEXT: return [[V0:[^ ]*]];
|
|
|
|
// CPP-DECLTOP: static inline int32_t return_i32() {
|
|
// CPP-DECLTOP-NEXT: int32_t [[V0:[^ ]*]];
|
|
// CPP-DECLTOP-NEXT: [[V0:]] = foo();
|
|
// CPP-DECLTOP-NEXT: return [[V0:[^ ]*]];
|
|
|
|
|
|
emitc.func @emitc_call() -> i32 {
|
|
%0 = emitc.call @return_i32() : () -> (i32)
|
|
emitc.return %0 : i32
|
|
}
|
|
// CPP-DEFAULT: int32_t emitc_call() {
|
|
// CPP-DEFAULT-NEXT: int32_t [[V0:[^ ]*]] = return_i32();
|
|
// CPP-DEFAULT-NEXT: return [[V0:[^ ]*]];
|
|
|
|
// CPP-DECLTOP: int32_t emitc_call() {
|
|
// CPP-DECLTOP-NEXT: int32_t [[V0:[^ ]*]];
|
|
// CPP-DECLTOP-NEXT: [[V0:[^ ]*]] = return_i32();
|
|
// CPP-DECLTOP-NEXT: return [[V0:[^ ]*]];
|
|
|
|
emitc.func private @extern_func(i32) attributes {specifiers = ["extern"]}
|
|
// CPP-DEFAULT: extern void extern_func(int32_t);
|
|
|
|
emitc.func private @array_arg(!emitc.array<3xi32>) attributes {specifiers = ["extern"]}
|
|
// CPP-DEFAULT: extern void array_arg(int32_t[3]);
|