-
Notifications
You must be signed in to change notification settings - Fork 42
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
could clang library be used to handle emit
/ C code embedded in nim?
#7
Comments
well, it's not that it's impossible, but I expect it to be a quite the undertaking.. the issue with wrapping c++ is that you need to support the whole c++ abi - vtables, multiple inheritance, exceptions etc etc - using clang, you at least get away with supporting only one ABI which is an improvement, but there's still a lot to do - C++ has a lot of corner cases which is why nobody's bothered or succeeded in wrapping it successfully so far (ie see Calypso claim: "almost entire spectrum of C++ features"), and C remains the de-facto common denominator for wrappers (even llvm provides C bindings, that nlvm uses!) If you want to experiment with this, it's fairly simple - both clang and nlvm can emit llvm bytecode (same as would happen if you were to link in clang library into nlvm), then you can use llvm linking tools to link the final executable into a binary, probably with some appropriate glue code - curious to hear how it goes! |
thanks for the reply; I'll answer later but just wanted to mention another very relevant and recent project: https://github.com/atilaneves/dpp/ the skinny:
yes and no: you can still have a usable tool even on a complex code base that starts with mapping the simplest declarations and ignore the rest it doesn't support yet. That's still very useful and (IIUC) could even work on complex stuff like opencv: the tool would just map what it can (and the list would grow over time). The preprocessing/parsing step would be completely handled by libclang.
|
for example, for Calypso (cf my other post nim-lang/Nim#8327), IIRC, when ldc(calypso produced binary) encounters a C++ import such as
modmap (C++) "OGRE/SdkCameraMan.h";
(eghttps://github.com/Syniurge/Calypso/blob/bc928fbd0226cd3ab39053fc3f12d3c2178f1194/examples/ogre3d/demo.d#L14) it uses clang library (linked in the binary) to produce LLVM IR from it, I believe it's handled here: https://github.com/Syniurge/Calypso/blob/master/ddmd/cpp/calypso.h
(maybe @Syniurge can confirm)
By the work, really curious what you think of nim-lang/Nim#8327 ; this could be a killer application for your project
The text was updated successfully, but these errors were encountered: