[HWArith, CAPI] Add CAPI boilerplate for HWArith (#3550)

This commit is contained in:
Morten Borup Petersen 2022-07-18 15:19:08 +02:00 committed by GitHub
parent 3e0ed79607
commit d904317dd1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 126 additions and 0 deletions

View File

@ -0,0 +1,26 @@
//===-- circt-c/Dialect/HWArith.h - C API for HWArith dialect -----*- C -*-===//
//
// This header declares the C interface for registering and accessing the
// HWArith dialect. A dialect should be registered with a context to make it
// available to users of the context. These users must load the dialect
// before using any of its attributes, operations or types. Parser and pass
// manager can load registered dialects automatically.
//
//===----------------------------------------------------------------------===//
#ifndef CIRCT_C_DIALECT_HWArith_H
#define CIRCT_C_DIALECT_HWArith_H
#include "mlir-c/Registration.h"
#ifdef __cplusplus
extern "C" {
#endif
MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(HWArith, hwarith);
#ifdef __cplusplus
}
#endif
#endif // CIRCT_C_DIALECT_HWArith_H

View File

@ -12,6 +12,7 @@
#include "circt-c/Dialect/ESI.h"
#include "circt-c/Dialect/FSM.h"
#include "circt-c/Dialect/HW.h"
#include "circt-c/Dialect/HWArith.h"
#include "circt-c/Dialect/MSFT.h"
#include "circt-c/Dialect/SV.h"
#include "circt-c/Dialect/Seq.h"
@ -63,6 +64,10 @@ PYBIND11_MODULE(_circt, m) {
mlirDialectHandleRegisterDialect(hw, context);
mlirDialectHandleLoadDialect(hw, context);
MlirDialectHandle hwarith = mlirGetDialectHandle__hwarith__();
mlirDialectHandleRegisterDialect(hwarith, context);
mlirDialectHandleLoadDialect(hwarith, context);
MlirDialectHandle seq = mlirGetDialectHandle__seq__();
mlirDialectHandleRegisterDialect(seq, context);
mlirDialectHandleLoadDialect(seq, context);

View File

@ -32,6 +32,7 @@ declare_mlir_python_extension(CIRCTBindingsPythonExtension.Core
CIRCTCAPIESI
CIRCTCAPIMSFT
CIRCTCAPIHW
CIRCTCAPIHWArith
CIRCTCAPISeq
CIRCTCAPISV
CIRCTCAPIExportVerilog
@ -124,6 +125,15 @@ declare_mlir_dialect_python_bindings(
circt/dialects/_fsm_ops_ext.py
DIALECT_NAME fsm)
declare_mlir_dialect_python_bindings(
ADD_TO_PARENT CIRCTBindingsPythonSources.Dialects
ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}"
TD_FILE circt/dialects/HWArithOps.td
SOURCES
circt/dialects/hwarith.py
circt/dialects/_hwarith_ops_ext.py
DIALECT_NAME hwarith)
################################################################################
# Build composite binaries
################################################################################

View File

@ -0,0 +1,15 @@
//===-- HWArithOps.td - Entry point for HWArithOps bindings *- tablegen -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef BINDINGS_PYTHON_HWARITH_OPS
#define BINDINGS_PYTHON_HWARITH_OPS
include "mlir/Bindings/Python/Attributes.td"
include "circt/Dialect/HWArith/HWArith.td"
#endif

View File

@ -0,0 +1,44 @@
from circt.dialects import hwarith
from circt.support import NamedValueOpView, get_value
from mlir.ir import IntegerAttr, IntegerType, Type
class BinaryOpBuilder(NamedValueOpView):
def operand_names(self):
return ["lhs", "rhs"]
def result_names(self):
return ["result"]
def BinaryOp(base):
class _Class(base):
@classmethod
def create(cls, lhs=None, rhs=None, result_type=None):
return cls([get_value(lhs), get_value(rhs)])
return _Class
@BinaryOp
class DivOp:
pass
@BinaryOp
class SubOp:
pass
@BinaryOp
class AddOp:
pass
@BinaryOp
class MulOp:
pass

View File

@ -0,0 +1,5 @@
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
from ._hwarith_ops_gen import *

View File

@ -4,6 +4,7 @@ set(LLVM_OPTIONAL_SOURCES
ESI.cpp
MSFT.cpp
HW.cpp
HWArith.cpp
LLHD.cpp
Moore.cpp
Seq.cpp
@ -90,3 +91,11 @@ add_mlir_public_c_api_library(CIRCTCAPIFSM
CIRCTFSMTransforms
CIRCTFSMToSV
)
add_mlir_public_c_api_library(CIRCTCAPIHWArith
HWArith.cpp
LINK_LIBS PUBLIC
MLIRCAPIIR
CIRCTHWArith
)

View File

@ -0,0 +1,12 @@
//===- SVDialect.cpp - C Interface for the HWArith Dialect ----------------===//
//
//===----------------------------------------------------------------------===//
#include "circt-c/Dialect/HWArith.h"
#include "circt/Dialect/HWArith/HWArithDialect.h"
#include "mlir/CAPI/IR.h"
#include "mlir/CAPI/Registration.h"
#include "mlir/CAPI/Support.h"
MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(HWArith, hwarith,
circt::hwarith::HWArithDialect)