1//===- Complex.cpp - C Interface for Complex dialect ----------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "mlir-c/Dialect/Complex.h"
10#include "mlir-c/IR.h"
11#include "mlir-c/Support.h"
12#include "mlir/CAPI/Registration.h"
13#include "mlir/Dialect/Complex/IR/Complex.h"
14
15using namespace mlir;
16
17MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(Complex, complex,
18 mlir::complex::ComplexDialect)
19
20bool mlirAttributeIsAComplex(MlirAttribute attr) {
21 return isa<complex::NumberAttr>(Val: unwrap(c: attr));
22}
23
24MlirAttribute mlirComplexAttrDoubleGet(MlirContext ctx, MlirType type,
25 double real, double imag) {
26 return wrap(
27 cpp: complex::NumberAttr::get(type: cast<ComplexType>(Val: unwrap(c: type)), real, imag));
28}
29
30MlirAttribute mlirComplexAttrDoubleGetChecked(MlirLocation loc, MlirType type,
31 double real, double imag) {
32 return wrap(cpp: complex::NumberAttr::getChecked(
33 loc: unwrap(c: loc), args: cast<ComplexType>(Val: unwrap(c: type)), args&: real, args&: imag));
34}
35
36double mlirComplexAttrGetRealDouble(MlirAttribute attr) {
37 return cast<complex::NumberAttr>(Val: unwrap(c: attr)).getReal().convertToDouble();
38}
39
40double mlirComplexAttrGetImagDouble(MlirAttribute attr) {
41 return cast<complex::NumberAttr>(Val: unwrap(c: attr)).getImag().convertToDouble();
42}
43
44MlirTypeID mlirComplexAttrGetTypeID(void) {
45 return wrap(cpp: complex::NumberAttr::getTypeID());
46}
47