mirror of https://github.com/llvm/circt.git
[LLHD] Add type C API
Add a few functions to LLHD's C API to interact with the LLHD dialect types.
This commit is contained in:
parent
a26ad267ce
commit
36c2d395d2
|
@ -15,8 +15,35 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Dialect
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(LLHD, llhd);
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Types
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
/// Check if a type is a time type.
|
||||
MLIR_CAPI_EXPORTED bool llhdTypeIsATimeType(MlirType);
|
||||
/// Check if a type is a signal type.
|
||||
MLIR_CAPI_EXPORTED bool llhdTypeIsASignalType(MlirType);
|
||||
/// Check if a type is a pointer type.
|
||||
MLIR_CAPI_EXPORTED bool llhdTypeIsAPointerType(MlirType);
|
||||
|
||||
/// Create a time type.
|
||||
MLIR_CAPI_EXPORTED MlirType llhdTimeTypeGet(MlirContext ctx);
|
||||
/// Create a signal type.
|
||||
MLIR_CAPI_EXPORTED MlirType llhdSignalTypeGet(MlirType element);
|
||||
/// Create a pointer type.
|
||||
MLIR_CAPI_EXPORTED MlirType llhdPointerTypeGet(MlirType element);
|
||||
|
||||
/// Get the inner type of a signal.
|
||||
MLIR_CAPI_EXPORTED MlirType llhdSignalTypeGetElementType(MlirType);
|
||||
/// Get the inner type of a pointer.
|
||||
MLIR_CAPI_EXPORTED MlirType llhdPointerTypeGetElementType(MlirType);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -8,8 +8,58 @@
|
|||
|
||||
#include "circt-c/Dialect/LLHD.h"
|
||||
#include "circt/Dialect/LLHD/IR/LLHDDialect.h"
|
||||
#include "circt/Dialect/LLHD/IR/LLHDTypes.h"
|
||||
#include "mlir/CAPI/IR.h"
|
||||
#include "mlir/CAPI/Registration.h"
|
||||
#include "mlir/CAPI/Support.h"
|
||||
|
||||
using namespace circt;
|
||||
using namespace circt::llhd;
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Dialect
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(LLHD, llhd, circt::llhd::LLHDDialect)
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Types
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
/// Check if a type is a time type.
|
||||
bool llhdTypeIsATimeType(MlirType type) { return unwrap(type).isa<TimeType>(); }
|
||||
|
||||
/// Check if a type is a signal type.
|
||||
bool llhdTypeIsASignalType(MlirType type) {
|
||||
return unwrap(type).isa<SigType>();
|
||||
}
|
||||
|
||||
/// Check if a type is a pointer type.
|
||||
bool llhdTypeIsAPointerType(MlirType type) {
|
||||
return unwrap(type).isa<PtrType>();
|
||||
}
|
||||
|
||||
/// Create a time type.
|
||||
MlirType llhdTimeTypeGet(MlirContext ctx) {
|
||||
return wrap(TimeType::get(unwrap(ctx)));
|
||||
}
|
||||
|
||||
/// Create a signal type.
|
||||
MlirType llhdSignalTypeGet(MlirType element) {
|
||||
return wrap(SigType::get(unwrap(element)));
|
||||
}
|
||||
|
||||
/// Create a pointer type.
|
||||
MlirType llhdPointerTypeGet(MlirType element) {
|
||||
return wrap(PtrType::get(unwrap(element)));
|
||||
}
|
||||
|
||||
/// Get the inner type of a signal.
|
||||
MlirType llhdSignalTypeGetElementType(MlirType type) {
|
||||
return wrap(unwrap(type).cast<SigType>().getUnderlyingType());
|
||||
}
|
||||
|
||||
/// Get the inner type of a pointer.
|
||||
MlirType llhdPointerTypeGetElementType(MlirType type) {
|
||||
return wrap(unwrap(type).cast<PtrType>().getUnderlyingType());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue