Skip to content
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

libasr: Add C backend Codegeneration using --show-c #497

Merged
merged 4 commits into from
May 18, 2022

Conversation

Smit-create
Copy link
Collaborator

@Smit-create Smit-create requested a review from certik May 15, 2022 06:57
@certik
Copy link
Contributor

certik commented May 15, 2022

Thanks for the PR. Isn't most of the C backend almost identical to the C++ backend? As mentioned in #393, I would prefer to have just one file, say asr_to_cpp.cpp, and in there have some flags to determine the kind of output. It seems to me it should be doable, because:

  • We want to be able to configure how exactly the C++ is generated, things like:
    • arrays (C style, Kokkos, XTensor, ...)
    • strings (C style, std::string)
    • list (std::vector, our custom C approach)
  • C that we would generate is a subset of C++, it seems it's effectively just one of the options above, and we have to have such options anyway

I think we just have to decide how types are being translated, and we have to support multiple C++ implementations of arrays, so we just add a C version.

The general syntax for functions, expressions, etc. is I think almost the same.

@Smit-create
Copy link
Collaborator Author

Yeah, that's true. Maybe we can add a class called ASRtoC and ASRtoCPP as the child class of ASRtoC which will add/override the methods of its parent class?

@certik
Copy link
Contributor

certik commented May 16, 2022

I thought about the base/sub class approach, but it seems that while some methods might be shared, a lot of them will have just slight differences. We could use the base class for common functionality in regular methods, and the subclass implements the actual visitors. But I suspect the easiest is to have just one class, that has options in it to specify how the generated code should look like.

Copy link
Contributor

@certik certik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably fine. We will then create a common base visitor and put all the identical visitor functions as well as any other common code that is shared with the C++ backend in there. This approach allows us to work on the two backends separately, and keep the code reasonably simple. And we can always add methods to the base class that internally dispatch on C/C++, if that is easier. So it seems this is the best of all approaches.

@certik certik merged commit a9fa066 into lcompilers:main May 18, 2022
@certik
Copy link
Contributor

certik commented May 19, 2022

Simplified in #517.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants