CIRCT  19.0.0git
LLHD.cpp
Go to the documentation of this file.
1 //===- LLHD.cpp - C interface for the LLHD 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 "circt-c/Dialect/LLHD.h"
12 #include "mlir/CAPI/IR.h"
13 #include "mlir/CAPI/Registration.h"
14 #include "mlir/CAPI/Support.h"
15 
16 using namespace circt;
17 using namespace circt::llhd;
18 
19 //===----------------------------------------------------------------------===//
20 // Dialect
21 //===----------------------------------------------------------------------===//
22 
23 MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(LLHD, llhd, circt::llhd::LLHDDialect)
24 
25 //===----------------------------------------------------------------------===//
26 // Types
27 //===----------------------------------------------------------------------===//
28 
29 /// Check if a type is a time type.
30 bool llhdTypeIsATimeType(MlirType type) { return isa<TimeType>(unwrap(type)); }
31 
32 /// Check if a type is a signal type.
33 bool llhdTypeIsASignalType(MlirType type) { return isa<SigType>(unwrap(type)); }
34 
35 /// Check if a type is a pointer type.
36 bool llhdTypeIsAPointerType(MlirType type) {
37  return isa<PtrType>(unwrap(type));
38 }
39 
40 /// Create a time type.
41 MlirType llhdTimeTypeGet(MlirContext ctx) {
42  return wrap(TimeType::get(unwrap(ctx)));
43 }
44 
45 /// Create a signal type.
46 MlirType llhdSignalTypeGet(MlirType element) {
47  return wrap(SigType::get(unwrap(element)));
48 }
49 
50 /// Create a pointer type.
51 MlirType llhdPointerTypeGet(MlirType element) {
52  return wrap(PtrType::get(unwrap(element)));
53 }
54 
55 /// Get the inner type of a signal.
56 MlirType llhdSignalTypeGetElementType(MlirType type) {
57  return wrap(cast<SigType>(unwrap(type)).getUnderlyingType());
58 }
59 
60 /// Get the inner type of a pointer.
61 MlirType llhdPointerTypeGetElementType(MlirType type) {
62  return wrap(cast<PtrType>(unwrap(type)).getUnderlyingType());
63 }
64 
65 //===----------------------------------------------------------------------===//
66 // Attributes
67 //===----------------------------------------------------------------------===//
68 
69 /// Check if an attribute is a time attribute.
70 bool llhdAttrIsATimeAttr(MlirAttribute attr) {
71  return isa<TimeAttr>(unwrap(attr));
72 }
73 
74 /// Create a time attribute.
75 MlirAttribute llhdTimeAttrGet(MlirContext ctx, MlirStringRef timeUnit,
76  uint64_t seconds, uint64_t delta,
77  uint64_t epsilon) {
78  return wrap(
79  TimeAttr::get(unwrap(ctx), seconds, unwrap(timeUnit), delta, epsilon));
80 }
81 
82 /// Get the time unit of a time attribute.
83 MlirStringRef llhdTimeAttrGetTimeUnit(MlirAttribute attr) {
84  return wrap(cast<TimeAttr>(unwrap(attr)).getTimeUnit());
85 }
86 
87 /// Get the seconds component of a time attribute.
88 uint64_t llhdTimeAttrGetSeconds(MlirAttribute attr) {
89  return cast<TimeAttr>(unwrap(attr)).getTime();
90 }
91 
92 /// Get the delta component of a time attribute.
93 uint64_t llhdTimeAttrGetDelta(MlirAttribute attr) {
94  return cast<TimeAttr>(unwrap(attr)).getDelta();
95 }
96 
97 /// Get the epsilon component of a time attribute.
98 uint64_t llhdTimeAttrGetEpsilon(MlirAttribute attr) {
99  return cast<TimeAttr>(unwrap(attr)).getEpsilon();
100 }
return wrap(CMemoryType::get(unwrap(ctx), baseType, numElements))
MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(CHIRRTL, chirrtl, circt::chirrtl::CHIRRTLDialect) MlirType chirrtlTypeGetCMemory(MlirContext ctx
MlirType llhdPointerTypeGetElementType(MlirType type)
Get the inner type of a pointer.
Definition: LLHD.cpp:61
MlirType llhdTimeTypeGet(MlirContext ctx)
Create a time type.
Definition: LLHD.cpp:41
uint64_t llhdTimeAttrGetSeconds(MlirAttribute attr)
Get the seconds component of a time attribute.
Definition: LLHD.cpp:88
uint64_t llhdTimeAttrGetDelta(MlirAttribute attr)
Get the delta component of a time attribute.
Definition: LLHD.cpp:93
MlirStringRef llhdTimeAttrGetTimeUnit(MlirAttribute attr)
Get the time unit of a time attribute.
Definition: LLHD.cpp:83
bool llhdTypeIsASignalType(MlirType type)
Check if a type is a signal type.
Definition: LLHD.cpp:33
bool llhdAttrIsATimeAttr(MlirAttribute attr)
Check if an attribute is a time attribute.
Definition: LLHD.cpp:70
bool llhdTypeIsATimeType(MlirType type)
Check if a type is a time type.
Definition: LLHD.cpp:30
bool llhdTypeIsAPointerType(MlirType type)
Check if a type is a pointer type.
Definition: LLHD.cpp:36
MlirType llhdSignalTypeGet(MlirType element)
Create a signal type.
Definition: LLHD.cpp:46
MlirAttribute llhdTimeAttrGet(MlirContext ctx, MlirStringRef timeUnit, uint64_t seconds, uint64_t delta, uint64_t epsilon)
Create a time attribute.
Definition: LLHD.cpp:75
uint64_t llhdTimeAttrGetEpsilon(MlirAttribute attr)
Get the epsilon component of a time attribute.
Definition: LLHD.cpp:98
MlirType llhdSignalTypeGetElementType(MlirType type)
Get the inner type of a signal.
Definition: LLHD.cpp:56
MlirType llhdPointerTypeGet(MlirType element)
Create a pointer type.
Definition: LLHD.cpp:51
static EvaluatorValuePtr unwrap(OMEvaluatorValue c)
Definition: OM.cpp:96
Direction get(bool isOutput)
Returns an output direction if isOutput is true, otherwise returns an input direction.
Definition: CalyxOps.cpp:54
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition: DebugAnalysis.h:21