-
Notifications
You must be signed in to change notification settings - Fork 302
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ARC][CAPI] Add basic C API for initializing ARC (#6997)
- Loading branch information
1 parent
98db979
commit 5ac7652
Showing
5 changed files
with
133 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
//===- Arc.h - C interface for the Arc dialect ------------------*- C -*-===// | ||
// | ||
// 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 CIRCT_C_DIALECT_ARC_H | ||
#define CIRCT_C_DIALECT_ARC_H | ||
|
||
#include "mlir-c/IR.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(Arc, arc); | ||
MLIR_CAPI_EXPORTED void registerArcPasses(void); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif // CIRCT_C_DIALECT_ARC_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
//===- Arc.cpp - C interface for the Arc dialect ------------------------===// | ||
// | ||
// 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "circt-c/Dialect/Arc.h" | ||
#include "circt/Dialect/Arc/ArcDialect.h" | ||
#include "circt/Dialect/Arc/ArcPasses.h" | ||
#include "mlir/CAPI/IR.h" | ||
#include "mlir/CAPI/Registration.h" | ||
#include "mlir/CAPI/Support.h" | ||
|
||
MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(Arc, arc, circt::arc::ArcDialect) | ||
|
||
void registerArcPasses() { circt::arc::registerPasses(); } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/*===- arc.c - Simple test of Arc Dialect C APIs -------------------------===*\ | ||
|* *| | ||
|* 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 *| | ||
|* *| | ||
\*===----------------------------------------------------------------------===*/ | ||
|
||
/* RUN: circt-capi-ir-test 2>&1 | FileCheck %s | ||
*/ | ||
|
||
#include "circt-c/Dialect/Arc.h" | ||
|
||
#include <stdio.h> | ||
#include <string.h> | ||
|
||
int registerOnlyArc(void) { | ||
MlirContext ctx = mlirContextCreate(); | ||
// The built-in dialect is always loaded. | ||
if (mlirContextGetNumLoadedDialects(ctx) != 1) | ||
return 1; | ||
|
||
// Arc dialect tests. | ||
MlirDialectHandle arcHandle = mlirGetDialectHandle__arc__(); | ||
|
||
MlirDialect arc = mlirContextGetOrLoadDialect( | ||
ctx, mlirDialectHandleGetNamespace(arcHandle)); | ||
if (!mlirDialectIsNull(arc)) | ||
return 2; | ||
|
||
mlirDialectHandleRegisterDialect(arcHandle, ctx); | ||
if (mlirContextGetNumRegisteredDialects(ctx) != 2) | ||
return 3; | ||
if (mlirContextGetNumLoadedDialects(ctx) != 1) | ||
return 4; | ||
|
||
arc = mlirContextGetOrLoadDialect(ctx, | ||
mlirDialectHandleGetNamespace(arcHandle)); | ||
if (mlirDialectIsNull(arc)) | ||
return 5; | ||
if (mlirContextGetNumLoadedDialects(ctx) != 2) | ||
return 6; | ||
|
||
MlirDialect alsoArc = mlirDialectHandleLoadDialect(arcHandle, ctx); | ||
if (!mlirDialectEqual(arc, alsoArc)) | ||
return 7; | ||
|
||
registerArcPasses(); | ||
|
||
mlirContextDestroy(ctx); | ||
|
||
return 0; | ||
} | ||
|
||
int main(void) { | ||
fprintf(stderr, "@registration\n"); | ||
int errcode = registerOnlyArc(); | ||
fprintf(stderr, "%d\n", errcode); | ||
|
||
// clang-format off | ||
// CHECK-LABEL: @registration | ||
// CHECK: 0 | ||
// clang-format on | ||
|
||
return 0; | ||
} |