LFortran: IMPLEMENTING A CUSTOM WASM BACKEND
GSoC'22 Report
- Organization: Fortran-Lang
- Mentors: Ondrej Certik, Gagandeep Singh, Rohit Goswami
- Contributor: Ubaid Shaikh
This report summarizes the work done as part of my GSoC 2022 project titled LFortran: IMPLEMENTING A CUSTOM WASM BACKEND at LFortran/Fortran-Lang.
Project Outline:
The objective in this project is to implement a WebAssembly (WASM) Backend for the LFortran Compiler.
The goal is also to compile LFortran to WASM and deploy on a static webpage. Thus, this project aims
to add to fortran the capability of executing on the World Wide Web, the only truly universal platform.
What was done:
Our project was mostly completed in four phases as follows:
-
Pre-GSoC Phase: During this phase we iterated over the design of the
wasmbackend and implemented it. The weekly blogs during this phase are as follows: -
GSoC Phase-1: During this phase we designed the
watbackend and added initial support for compilinglfortrantowasm. We also deployed the builtlfortranwasmbinary to a live site. The weekly blogs during this phase are as follows: -
GSoC Phase-2: Now that we had the
wasmbackend, thewatbackend and compilation oflfortrantowasm. The next part of the project was to extend thewasmandwatbackends to support more features offortran/ASR. This extension of both the backends was accomplished in this phase. The weekly blogs during this phase are as follows: -
GSoC Ending Phase: This comprises the final week(s) of GSoC where we focused on
CI(Continuous Integration) support for wasm building, its storage and some final features and fixes. The blog during this phase is as follows:
Merge/Pull Requests
The merge/pull requests submitted during the period of GSoC from (approx)23-05-2022 to 23-08-2022 are as follows:
At Gitlab/lfortran:
At GitHub/lfortran:
At GitHub/lcompilers_frontend:
Outcome:
The outcomes of the project are the following:
-
A
WASMBackend forLFortran -
A
WATBackend forLFortran -
LFortran(along with itsruntime library) compiles toWASMusingemscripten -
CI(Continuous Integration) support for building towasmand storing builtlfortranwasmat lfortran/wasm_builds -
A frontend for the static webpage (at dev.lfortran.org) where we deploy our
lfortranwasmbinary and can see it live in action -
CI(Continuous Integration) support for building the frontend site
Live Demo:


Future Work:
There are tremendous possiblities of extending this work. Some of the future work includes the following:
-
Extending the current
wasmandwatbackends: Adding support for dynamic memory allocation and thusarrayallocations during runtime. Supportingstructsand derived types in thewasmandwatbackends. -
More Robutness: Finding and fixing bugs in the current
wasmandwatbackends. Some of the issues are noted at WASM: Future Prospects #597 and fixing them would (hopefully) make ourwasmarchitecture more robust. -
Supporting WASI: One of the directions could be to add support of
WASI(WebAssembly System Interface) to theLFortranWASMBackend. -
Data Visualization: We could also try to explore data visualization using
fortran.
My Learnings
It has been an incredible journey, full of fun and learning for me.
Following is a list of my learnings (including but not limited to):
-
GIT: I got to learn/improve
version control(git) skills. I learntrebasing,resetting(hard, soft) andcherry-pickingcommits. Previously, I used to be afraid ofmergeconflicts and now, I enjoy resolving them. -
WASM: This project provided me with the wonderful opportunity to understand how binaries are created and processed. I got to learn about the
wasmstructure and its textual format (wat). -
NextJS: I got to learn about
NextJS. We usedNextJSwhile building thelcompilers_frontend. -
CI: I also got the opportunity to work towards the
CI(Continuous Integration) part during the course of the project. -
CMake: I also got the opportunity to get my hands onto
CMakeduring the course of the project. -
Fortran: I got to learn about
fortran. I learned aboutintrinsicfunctions,runtime library, etc. -
Compilers: I got the opportunity to learn how a
compilerworks, specifically thebackend/codegenpart. -
Conda: This was the first time for me using
condaand I realized how powerfulcondaenvironments could be.
and the list goes on.
Indeed, I think this project has made me a better programmer, problem solver, analyzer and communicator.
I am thankful to Ondrej Sir and team for accepting me in this project. Thank you so much for this wonderful journey and amazing experience throughout.