I just implemented a Julia back-end for the LFortran project. Since it is still very primitive, it would be great if more users could try it and submit issues or provide suggestions.
To use it, you need to first clone the LFortran repo, then build the project.
cd lfortran
./build0.sh
mkdir cmake-build
cd cmake-build
cmake ..
make
this is quite cool! is it good enough yet to translate big fortran programs like the blases/packs? if this is capable of matching native Julia/Fortran performance, this would be a very easy way for us to get rid of the last remaining fortran code in Julia.
I’m not sure what you would gain by this. The auto-translated code would not be type-generic or anything — it would have the same semantics as the Fortran code (but might put a lot more pressure on the Julia load times). And because something like LAPACK is so huge, translating the automatic output to something more idiomatic would be a massive undertaking. (OpenBLAS is mostly in C.)
Auto-translation seems more useful for relatively small snippets of Fortran code, to use as a starting point for a more idiomatic and flexible Julia port.
@lucifer1004 has done an excellent job. We are hoping this will be useful for the Julia community. And we are always looking for more contributors, so if you find this interesting and want to help, please get in touch!
@Oscar_Smith right now LFortran is in alpha stage, meaning it will not translate any larger code yet. But we are working very hard to compile the SciPy Fortran code, which is about 0.5M lines of mostly various packs. Once we can compile it, and everything works, it won’t be difficult to up the Julia backend to translate everything to Julia.
@stevengj regarding idiomatic code: one simple example is the integer, intent(out) variable in Fortran, where a subroutine can have several of these to return an integer to the caller. In Python and Julia the idiomatic way to do it is to return it as a result of the function. One can work around this in various ways in both Python and Julia, and the backend is using one such approach, but to truly get out code that you would like to write by hand in Julia, one would have to explore and write ASR->ASR (Abstract Semantic Representation, the IR that LFortran is using) rewriting passes to transform the code to more idiomatic way for Python or Julia. It’s not clear how far one can get with this approach and if something usable can be made. However, if I look at my own modern Fortran codes, I think they would translate nicely.
Either way, having a robust automatic translation that can (eventually) take any Fortran code and translate to a workable and as readable as automatically possible Julia code will be useful to many, if nothing, at least as a starting point to a more idiomatic Julia port.