CIRCT  20.0.0git
SV.cpp
Go to the documentation of this file.
1 //===- SV.cpp - C interface for the SV 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/SV.h"
13 #include "mlir/CAPI/IR.h"
14 #include "mlir/CAPI/Registration.h"
15 #include "mlir/CAPI/Support.h"
16 
17 using namespace circt::sv;
18 
20 MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(SystemVerilog, sv, SVDialect)
21 
22 bool svAttrIsASVAttributeAttr(MlirAttribute cAttr) {
23  return llvm::isa<SVAttributeAttr>(unwrap(cAttr));
24 }
25 
26 MlirAttribute svSVAttributeAttrGet(MlirContext cCtxt, MlirStringRef cName,
27  MlirStringRef cExpression,
28  bool emitAsComment) {
29  mlir::MLIRContext *ctxt = unwrap(cCtxt);
30  mlir::StringAttr expr;
31  if (cExpression.data != nullptr)
32  expr = mlir::StringAttr::get(ctxt, unwrap(cExpression));
33  return wrap(
35  expr, mlir::BoolAttr::get(ctxt, emitAsComment)));
36 }
37 
38 MlirStringRef svSVAttributeAttrGetName(MlirAttribute cAttr) {
39  return wrap(llvm::cast<SVAttributeAttr>(unwrap(cAttr)).getName().getValue());
40 }
41 
42 MlirStringRef svSVAttributeAttrGetExpression(MlirAttribute cAttr) {
43  auto expr = llvm::cast<SVAttributeAttr>(unwrap(cAttr)).getExpression();
44  if (expr)
45  return wrap(expr.getValue());
46  return {nullptr, 0};
47 }
48 
49 bool svSVAttributeAttrGetEmitAsComment(MlirAttribute attribute) {
50  return llvm::cast<SVAttributeAttr>(unwrap(attribute))
51  .getEmitAsComment()
52  .getValue();
53 }
return wrap(CMemoryType::get(unwrap(ctx), baseType, numElements))
MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(CHIRRTL, chirrtl, circt::chirrtl::CHIRRTLDialect) MlirType chirrtlTypeGetCMemory(MlirContext ctx
static void registerPasses()
Definition: CIRCTModule.cpp:45
static EvaluatorValuePtr unwrap(OMEvaluatorValue c)
Definition: OM.cpp:113
MlirStringRef svSVAttributeAttrGetName(MlirAttribute cAttr)
Definition: SV.cpp:38
bool svAttrIsASVAttributeAttr(MlirAttribute cAttr)
Definition: SV.cpp:22
void registerSVPasses()
Definition: SV.cpp:19
bool svSVAttributeAttrGetEmitAsComment(MlirAttribute attribute)
Definition: SV.cpp:49
MlirStringRef svSVAttributeAttrGetExpression(MlirAttribute cAttr)
Definition: SV.cpp:42
MlirAttribute svSVAttributeAttrGet(MlirContext cCtxt, MlirStringRef cName, MlirStringRef cExpression, bool emitAsComment)
Definition: SV.cpp:26
Direction get(bool isOutput)
Returns an output direction if isOutput is true, otherwise returns an input direction.
Definition: CalyxOps.cpp:55
StringAttr getName(ArrayAttr names, size_t idx)
Return the name at the specified index of the ArrayAttr or null if it cannot be determined.
Definition: sv.py:1