Use Emscripten with Fortran: LAPACK binding

ⅰ亾dé卋堺 提交于 2019-11-30 15:07:07

Thank you for your reply! Indeed I did make progress on this. Finally it is working. I was very close, just follow these steps:

gfortran caxpy.f -S -flto -m32 -fplugin=dragonegg.so
mv caxpy.s caxpy.ll
llvm-as caxpy.ll -o caxpy.o

Note the "m32" flag which I missed earlier.

Warnings like

warning: unresolved symbol: _gfortran_st_write

can be ignored safely. Emscripten creates empty functions in the JavaScript file with this name so if these functions are not called at all there is no problem. If they get called you can easily substitute them with your own functions; the names are somewhat descriptive. Additionally you can have a look at the libgfortran source code (be aware it is GPL).

With this Emscripten source can be extended by hand to support Fortran files. Someday I may publish this on github!

I actually pulled this off recently (https://github.com/harveywi/arpack-js). The Github repo is mostly barren except for the output JS files, but I will be uploading source code, Makefiles, and other instructions soon. After wrangling unsuccessfully with dragonegg for a while, I found a different approach (not as great, but sufficient) which did the trick.

Here is roughly how I did it:

  1. Download the ARPACK source code.
  2. Run f2c on all of the Fortran files to convert them to C.
  3. (This might be the trickiest part): Modify the Makefiles to use Emscripten and LLVM toolchains.
  4. Make the project to produce an LLVM binary.
  5. Use Emscripten again to transpile the LLVM binary to JS.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!