CIRCT  18.0.0git
LLHD.cpp
Go to the documentation of this file.
1 //===-- LLHD.h - C API for 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 unwrap(type).isa<TimeType>(); }
31 
32 /// Check if a type is a signal type.
33 bool llhdTypeIsASignalType(MlirType type) {
34  return unwrap(type).isa<SigType>();
35 }
36 
37 /// Check if a type is a pointer type.
38 bool llhdTypeIsAPointerType(MlirType type) {
39  return unwrap(type).isa<PtrType>();
40 }
41 
42 /// Create a time type.
43 MlirType llhdTimeTypeGet(MlirContext ctx) {
44  return wrap(TimeType::get(unwrap(ctx)));
45 }
46 
47 /// Create a signal type.
48 MlirType llhdSignalTypeGet(MlirType element) {
49  return wrap(SigType::get(unwrap(element)));
50 }
51 
52 /// Create a pointer type.
53 MlirType llhdPointerTypeGet(MlirType element) {
54  return wrap(PtrType::get(unwrap(element)));
55 }
56 
57 /// Get the inner type of a signal.
58 MlirType llhdSignalTypeGetElementType(MlirType type) {
59  return wrap(unwrap(type).cast<SigType>().getUnderlyingType());
60 }
61 
62 /// Get the inner type of a pointer.
63 MlirType llhdPointerTypeGetElementType(MlirType type) {
64  return wrap(unwrap(type).cast<PtrType>().getUnderlyingType());
65 }
66 
67 //===----------------------------------------------------------------------===//
68 // Attributes
69 //===----------------------------------------------------------------------===//
70 
71 /// Check if an attribute is a time attribute.
72 bool llhdAttrIsATimeAttr(MlirAttribute attr) {
73  return unwrap(attr).isa<TimeAttr>();
74 }
75 
76 /// Create a time attribute.
77 MlirAttribute llhdTimeAttrGet(MlirContext ctx, MlirStringRef timeUnit,
78  uint64_t seconds, uint64_t delta,
79  uint64_t epsilon) {
80  return wrap(
81  TimeAttr::get(unwrap(ctx), seconds, unwrap(timeUnit), delta, epsilon));
82 }
83 
84 /// Get the time unit of a time attribute.
85 MlirStringRef llhdTimeAttrGetTimeUnit(MlirAttribute attr) {
86  return wrap(unwrap(attr).cast<TimeAttr>().getTimeUnit());
87 }
88 
89 /// Get the seconds component of a time attribute.
90 uint64_t llhdTimeAttrGetSeconds(MlirAttribute attr) {
91  return unwrap(attr).cast<TimeAttr>().getTime();
92 }
93 
94 /// Get the delta component of a time attribute.
95 uint64_t llhdTimeAttrGetDelta(MlirAttribute attr) {
96  return unwrap(attr).cast<TimeAttr>().getDelta();
97 }
98 
99 /// Get the epsilon component of a time attribute.
100 uint64_t llhdTimeAttrGetEpsilon(MlirAttribute attr) {
101  return unwrap(attr).cast<TimeAttr>().getEpsilon();
102 }
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:63
MlirType llhdTimeTypeGet(MlirContext ctx)
Create a time type.
Definition: LLHD.cpp:43
uint64_t llhdTimeAttrGetSeconds(MlirAttribute attr)
Get the seconds component of a time attribute.
Definition: LLHD.cpp:90
uint64_t llhdTimeAttrGetDelta(MlirAttribute attr)
Get the delta component of a time attribute.
Definition: LLHD.cpp:95
MlirStringRef llhdTimeAttrGetTimeUnit(MlirAttribute attr)
Get the time unit of a time attribute.
Definition: LLHD.cpp:85
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:72
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:38
MlirType llhdSignalTypeGet(MlirType element)
Create a signal type.
Definition: LLHD.cpp:48
MlirAttribute llhdTimeAttrGet(MlirContext ctx, MlirStringRef timeUnit, uint64_t seconds, uint64_t delta, uint64_t epsilon)
Create a time attribute.
Definition: LLHD.cpp:77
uint64_t llhdTimeAttrGetEpsilon(MlirAttribute attr)
Get the epsilon component of a time attribute.
Definition: LLHD.cpp:100
MlirType llhdSignalTypeGetElementType(MlirType type)
Get the inner type of a signal.
Definition: LLHD.cpp:58
MlirType llhdPointerTypeGet(MlirType element)
Create a pointer type.
Definition: LLHD.cpp:53
static EvaluatorValuePtr unwrap(OMEvaluatorValue c)
Definition: OM.cpp:100
Direction get(bool isOutput)
Returns an output direction if isOutput is true, otherwise returns an input direction.
Definition: CalyxOps.cpp:53
This file defines an intermediate representation for circuits acting as an abstraction for constraint...
Definition: DebugAnalysis.h:21