-
Notifications
You must be signed in to change notification settings - Fork 285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create a minimal C API #196
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a test case which uses the library. See llvm/test/CAPI
PATTERN "*.def" | ||
PATTERN "*.h" | ||
PATTERN "*.inc" | ||
PATTERN "*.td" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are no inc, td, or def files in the c-api.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I copied this verbatim from LLVM. I don't see a problem leaving these in unless we explicitly want to take the stance that we are trying to build this API without these file types.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for tackling this, LGTM with the @darthscsi 's comment addressed. Thanks!
include/circt-c/RTLDialect.h
Outdated
@@ -0,0 +1,30 @@ | |||
/*===-- circt-c/RTLDialect.h - C API for RTL dialect --------------*- C -*-===*\ | |||
|* *| | |||
*| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: please fill in the file header
extern "C" { | ||
#endif | ||
|
||
/** Registers the RTL dialect with the given context. This allows the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I see the MLIR C bindings are doing the same thing, but this still seems a bit weird to me: The use of /**/ comments is very inclusive to old C compilers, but I think that BCPL style // comments were part of ansi c 89/90, so I think they are ok to use. Doing so gets us better alignment with the c++ side of things. Could you ask the MLIR forum what the rationale here is, and whether using // would be ok with them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://llvm.discourse.group/t/a-quick-question-about-comment-styles/2144
Seems like there is a policy, and I'm not planning on rocking the boat too much yet :)
@@ -0,0 +1,21 @@ | |||
//===- RTLDialect.cpp - C Interface for RTL Dialect -----------------------===// | |||
// |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same nit as the header.
This is great! I think I will do a similar thing for LLHD, in order to be able to switch Moore from the Rust LLHD library to CIRCT as a foreign library at some point. |
I'm a little confused at how the tests work. Can someone please clarify what the best path forward is? |
#include "mlir/CAPI/IR.h" | ||
#include "mlir/CAPI/Support.h" | ||
|
||
void mlirContextRegisterRTLDialect(MlirContext context) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Am I missing something or should these symbols be extern "C"
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mirrored the structure of StandardDialect.cpp: https://github.com/llvm/llvm-project/blob/64c0c9f01511dc300b29e7a20a13958c5932e314/mlir/lib/CAPI/Standard/StandardDialect.cpp
They are declared as extern "C"
in the header:
circt/include/circt-c/RTLDialect.h
Line 17 in 4b01c0a
extern "C" { |
Cool, I think this looks good with a few nits about the file header. I agree that you should keep the comment style consistent with the MLIR style. If/when they change, we can change to match. |
add_subdirectory is a directive to cmake. The reason it is doing it is to pickup the cmake-based build of the executable in the test directory. add_subdirectory isn't directing the testing framework to do anything, it's just building the c-based test executable and registering it so the test target can depend on it. |
It looks like ".mlir" style tests are handled differently from C tests which need to be compiled as part of the cmake project in order to be run. As such, C tests need to use "add_subdirectory" to provide their own CMakeLists.txt, which "mlir" and "fir" tests do not. The reason we don't have this yet in circt is because there are no C tests yet. |
So in my latest attempt, I'm getting the following error: https://github.com/llvm/circt/runs/1354327993#step:8:363 I've tried to copy what is happening in the MLIR C test, but for some reason it isn't finding the executable (which is present after the build and produces the correct output).
Does anyone have any thoughts as to what I may be missing? @darthscsi |
This was the spot I missed 181011e |
Cool, thank you George. It looks like MLIR just switched their comment style, could you adapt this code to follow the new approach in a follow-on? Thanks, -Chris |
Race conditions always get you :( |
If only there were some way to define them away! |
No description provided.