CIRCT 24.0.0git
Loading...
Searching...
No Matches
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
14#include "mlir/CAPI/IR.h"
15#include "mlir/CAPI/Registration.h"
16#include "mlir/CAPI/Support.h"
17
18using namespace circt::sv;
19
21MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(SystemVerilog, sv, SVDialect)
22
23bool svAttrIsASVAttributeAttr(MlirAttribute cAttr) {
24 return llvm::isa<SVAttributeAttr>(unwrap(cAttr));
25}
26
27MlirAttribute svSVAttributeAttrGet(MlirContext cCtxt, MlirStringRef cName,
28 MlirStringRef cExpression,
29 bool emitAsComment) {
30 mlir::MLIRContext *ctxt = unwrap(cCtxt);
31 mlir::StringAttr expr;
32 if (cExpression.data != nullptr)
33 expr = mlir::StringAttr::get(ctxt, unwrap(cExpression));
34 return wrap(
35 SVAttributeAttr::get(ctxt, mlir::StringAttr::get(ctxt, unwrap(cName)),
36 expr, mlir::BoolAttr::get(ctxt, emitAsComment)));
37}
38
39MlirStringRef svSVAttributeAttrGetName(MlirAttribute cAttr) {
40 return wrap(llvm::cast<SVAttributeAttr>(unwrap(cAttr)).getName().getValue());
41}
42
43MlirStringRef svSVAttributeAttrGetExpression(MlirAttribute cAttr) {
44 auto expr = llvm::cast<SVAttributeAttr>(unwrap(cAttr)).getExpression();
45 if (expr)
46 return wrap(expr.getValue());
47 return {nullptr, 0};
48}
49
50bool svSVAttributeAttrGetEmitAsComment(MlirAttribute attribute) {
51 return llvm::cast<SVAttributeAttr>(unwrap(attribute))
52 .getEmitAsComment()
53 .getValue();
54}
55
56bool svTypeIsANet(MlirType type) { return llvm::isa<NetType>(unwrap(type)); }
57
58MlirType svNetTypeGet(MlirType element) {
59 return wrap(NetType::get(unwrap(element)));
60}
61
62MlirType svNetTypeGetElementType(MlirType type) {
63 return wrap(llvm::cast<NetType>(unwrap(type)).getElementType());
64}
65
66bool svTypeIsAVar(MlirType type) { return llvm::isa<VarType>(unwrap(type)); }
67
68MlirType svVarTypeGet(MlirType element) {
69 return wrap(VarType::get(unwrap(element)));
70}
71
72MlirType svVarTypeGetElementType(MlirType type) {
73 return wrap(llvm::cast<VarType>(unwrap(type)).getElementType());
74}
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()
static EvaluatorValuePtr unwrap(OMEvaluatorValue c)
Definition OM.cpp:111
MlirStringRef svSVAttributeAttrGetName(MlirAttribute cAttr)
Definition SV.cpp:39
MlirType svVarTypeGetElementType(MlirType type)
Definition SV.cpp:72
MlirType svVarTypeGet(MlirType element)
Definition SV.cpp:68
void registerSVPasses()
Definition SV.cpp:20
bool svSVAttributeAttrGetEmitAsComment(MlirAttribute attribute)
Definition SV.cpp:50
MlirStringRef svSVAttributeAttrGetExpression(MlirAttribute cAttr)
Definition SV.cpp:43
MlirType svNetTypeGet(MlirType element)
Definition SV.cpp:58
bool svTypeIsAVar(MlirType type)
Definition SV.cpp:66
MlirAttribute svSVAttributeAttrGet(MlirContext cCtxt, MlirStringRef cName, MlirStringRef cExpression, bool emitAsComment)
Definition SV.cpp:27
bool svTypeIsANet(MlirType type)
Definition SV.cpp:56
MlirType svNetTypeGetElementType(MlirType type)
Definition SV.cpp:62
MLIR_CAPI_EXPORTED bool svAttrIsASVAttributeAttr(MlirAttribute)
Definition SV.cpp:23
Definition sv.py:1