CIRCT  20.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 pointer type.
33 bool llhdTypeIsAPointerType(MlirType type) {
34  return isa<PtrType>(unwrap(type));
35 }
36 
37 /// Create a time type.
38 MlirType llhdTimeTypeGet(MlirContext ctx) {
39  return wrap(TimeType::get(unwrap(ctx)));
40 }
41 
42 /// Create a pointer type.
43 MlirType llhdPointerTypeGet(MlirType element) {
44  return wrap(PtrType::get(unwrap(element)));
45 }
46 
47 /// Get the inner type of a pointer.
48 MlirType llhdPointerTypeGetElementType(MlirType type) {
49  return wrap(cast<PtrType>(unwrap(type)).getElementType());
50 }
51 
52 //===----------------------------------------------------------------------===//
53 // Attributes
54 //===----------------------------------------------------------------------===//
55 
56 /// Check if an attribute is a time attribute.
57 bool llhdAttrIsATimeAttr(MlirAttribute attr) {
58  return isa<TimeAttr>(unwrap(attr));
59 }
60 
61 /// Create a time attribute.
62 MlirAttribute llhdTimeAttrGet(MlirContext ctx, MlirStringRef timeUnit,
63  uint64_t seconds, uint64_t delta,
64  uint64_t epsilon) {
65  return wrap(
66  TimeAttr::get(unwrap(ctx), seconds, unwrap(timeUnit), delta, epsilon));
67 }
68 
69 /// Get the time unit of a time attribute.
70 MlirStringRef llhdTimeAttrGetTimeUnit(MlirAttribute attr) {
71  return wrap(cast<TimeAttr>(unwrap(attr)).getTimeUnit());
72 }
73 
74 /// Get the seconds component of a time attribute.
75 uint64_t llhdTimeAttrGetSeconds(MlirAttribute attr) {
76  return cast<TimeAttr>(unwrap(attr)).getTime();
77 }
78 
79 /// Get the delta component of a time attribute.
80 uint64_t llhdTimeAttrGetDelta(MlirAttribute attr) {
81  return cast<TimeAttr>(unwrap(attr)).getDelta();
82 }
83 
84 /// Get the epsilon component of a time attribute.
85 uint64_t llhdTimeAttrGetEpsilon(MlirAttribute attr) {
86  return cast<TimeAttr>(unwrap(attr)).getEpsilon();
87 }
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:48
MlirType llhdTimeTypeGet(MlirContext ctx)
Create a time type.
Definition: LLHD.cpp:38
uint64_t llhdTimeAttrGetSeconds(MlirAttribute attr)
Get the seconds component of a time attribute.
Definition: LLHD.cpp:75
uint64_t llhdTimeAttrGetDelta(MlirAttribute attr)
Get the delta component of a time attribute.
Definition: LLHD.cpp:80
MlirStringRef llhdTimeAttrGetTimeUnit(MlirAttribute attr)
Get the time unit of a time attribute.
Definition: LLHD.cpp:70
bool llhdAttrIsATimeAttr(MlirAttribute attr)
Check if an attribute is a time attribute.
Definition: LLHD.cpp:57
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:33
MlirAttribute llhdTimeAttrGet(MlirContext ctx, MlirStringRef timeUnit, uint64_t seconds, uint64_t delta, uint64_t epsilon)
Create a time attribute.
Definition: LLHD.cpp:62
uint64_t llhdTimeAttrGetEpsilon(MlirAttribute attr)
Get the epsilon component of a time attribute.
Definition: LLHD.cpp:85
MlirType llhdPointerTypeGet(MlirType element)
Create a pointer type.
Definition: LLHD.cpp:43
static EvaluatorValuePtr unwrap(OMEvaluatorValue c)
Definition: OM.cpp:113
Direction get(bool isOutput)
Returns an output direction if isOutput is true, otherwise returns an input direction.
Definition: CalyxOps.cpp:55
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition: DebugAnalysis.h:21