[FIRRTL][CAPI] Fix undefined reference for `mlirExportFIRRTL`

This commit is contained in:
Sprite 2023-08-07 16:28:48 +02:00 committed by Asuna
parent 2e87b4998c
commit 9728f92ce2
5 changed files with 79 additions and 4 deletions

View File

@ -17,8 +17,8 @@ using namespace circt;
using namespace firrtl;
MlirLogicalResult mlirExportFIRRTL(MlirModule module,
MlirStringCallback callback, void *userData,
FIRVersion version) {
MlirStringCallback callback,
void *userData) {
mlir::detail::CallbackOstream stream(callback, userData);
return wrap(exportFIRFile(unwrap(module), stream, {}, {3, 0, 0}));
}

View File

@ -28,3 +28,17 @@ target_link_libraries(circt-capi-om-test
MLIRCAPIIR
CIRCTCAPIOM
)
add_llvm_executable(circt-capi-firrtl-test
PARTIAL_SOURCES_INTENDED
firrtl.c
)
llvm_update_compile_flags(circt-capi-firrtl-test)
target_link_libraries(circt-capi-firrtl-test
PRIVATE
MLIRCAPIIR
CIRCTCAPIFIRRTL
CIRCTCAPIExportFIRRTL
)

60
test/CAPI/firrtl.c Normal file
View File

@ -0,0 +1,60 @@
/*===- firrtl.c - Simple test of FIRRTL 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-firrtl-test 2>&1 | FileCheck %s
*/
#include "circt-c/Dialect/FIRRTL.h"
#include "circt-c/ExportFIRRTL.h"
#include "mlir-c/BuiltinAttributes.h"
#include "mlir-c/BuiltinTypes.h"
#include "mlir-c/IR.h"
#include "mlir-c/Support.h"
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
void exportCallback(MlirStringRef message, void *userData) {
printf("%.*s", (int)message.length, message.data);
}
void testExport(MlirContext ctx) {
// clang-format off
const char *testFIR =
"firrtl.circuit \"ExportTestSimpleModule\" {\n"
" firrtl.module @ExportTestSimpleModule(in %in_1: !firrtl.uint<32>,\n"
" in %in_2: !firrtl.uint<32>,\n"
" out %out: !firrtl.uint<32>) {\n"
" %0 = firrtl.and %in_1, %in_2 : (!firrtl.uint<32>, !firrtl.uint<32>) -> !firrtl.uint<32>\n"
" firrtl.connect %out, %0 : !firrtl.uint<32>, !firrtl.uint<32>\n"
" }\n"
"}\n";
// clang-format on
MlirModule module =
mlirModuleCreateParse(ctx, mlirStringRefCreateFromCString(testFIR));
assert(mlirLogicalResultIsSuccess(
mlirExportFIRRTL(module, exportCallback, NULL)));
// CHECK: FIRRTL version 3.0.0
// CHECK-NEXT: circuit ExportTestSimpleModule :
// CHECK-NEXT: module ExportTestSimpleModule : @[- 2:3]
// CHECK-NEXT: input in_1 : UInt<32> @[- 2:44]
// CHECK-NEXT: input in_2 : UInt<32> @[- 3:44]
// CHECK-NEXT: output out : UInt<32> @[- 4:45]
// CHECK-EMPTY:
// CHECK-NEXT: connect out, and(in_1, in_2) @[- 6:5]
}
int main() {
MlirContext ctx = mlirContextCreate();
mlirDialectHandleLoadDialect(mlirGetDialectHandle__firrtl__(), ctx);
testExport(ctx);
return 0;
}

View File

@ -20,6 +20,7 @@ set(CIRCT_TEST_DEPENDS
arcilator
circt-capi-ir-test
circt-capi-om-test
circt-capi-firrtl-test
circt-as
circt-dis
circt-opt

View File

@ -57,8 +57,8 @@ tool_dirs = [
]
tools = [
'arcilator', 'circt-as', 'circt-capi-ir-test', 'circt-capi-om-test',
'circt-dis', 'circt-opt', 'circt-reduce', 'circt-translate', 'esi-tester',
'firtool', 'hlstool', 'om-linker'
'circt-capi-firrtl-test', 'circt-dis', 'circt-opt', 'circt-reduce',
'circt-translate', 'esi-tester', 'firtool', 'hlstool', 'om-linker'
]
# Enable Verilator if it has been detected.