Code Monkey home page Code Monkey logo

femscripten's Introduction

Fortran -> JS Docker image

This project provides a Docker image that contains a working FORTRAN -> Javascript compiler.

TODO

  1. Actually deliver on claim #1 above
  • make Docker image that can run emscripten
  • add gcc + dragonegg to image
  • produce C main + Fortran obj
  • make F->js library files
  • support Fortran standard library (small)
  • support Fortran main

Work in Progress

There is a docker image that includes llvm, gfortran, dragonegg, and emscripten.

I am trying to figure out how to do automate testing and how to automate compilation of simple hello-world examples.

Using the current image

To start messing around, first checkout this repository

$ git checkout ssh:github.com:smikes/femscripten.git
$ cd femscripten

get the docker image --

$ docker run -t -i -v `pwd`:/mnt/test smikes/femscripten:devel /bin/bash
$ cd /mnt/test
$ . setup-env.sh

Now you are inside the docker container and should have access to the compiler commands.

Commands

emgf

This is the main useful program. It is a shell script which takes one argument, a fortran file, and generates an emscripten-compatible object file.

$ emgf foo.f   => produces foo.o

BUGS: This currently also produces foo.s, foo.ll ; and it uses an ugly workaround to get from the dragonegg default target (below):

target datalayout = "e-p:32:32:32-S128-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f16:16:16-f32:32:32-f64:32:64-f128:128:128-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32"
target triple = "i386--linux-gnu"

to the correct emscripten target.

However it works! Good enough for now.

Examples

Times

$ cd examples/times
$ make

There is one main function, in times-main.c. It expects an external function named times_ (note the C-to-FORTRAN naming convention) which takes two floats by reference, and returns their product.

There are two implementaions of times_ provided: one in C (times-c.c) and one in FORTRAN 77 (times-f.f).

The make should succeed and you should be able to run both quasi-executables through node:

$ node times-c.js
6.000000

$ node times-f.js
6.000000

Lapack

$ cd examples/lapack
$ make

This is an example that uses a very simple subroutine from LAPACK - IDAMAX, find the index of the maximum element in an array of doubles.

$ node lapack.js
let's ask BLAS/IDAMAX what's the index of the largest value
in the array: { 0.0, 300.0, 1.345e39, -452.0 }; 

It should be the third element; we got ==> 3

Note that FORTRAN has 1-based arrays by default

Hello

Not yet working -- some gfortran library functions need to be implemented.

$ emgf hello_world.f
$ emcc -o hello_world.js hello_world.o
warning: unresolved symbol: _gfortran_st_write_done
warning: unresolved symbol: _gfortran_transfer_character_write
warning: unresolved symbol: _gfortran_set_args
warning: unresolved symbol: _gfortran_set_options
warning: unresolved symbol: _gfortran_st_write

femscripten's People

Contributors

kenany avatar smikes avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

femscripten's Issues

Need Java for closure compiler (?) do we really?

Message when using emcc:

root@ab8f73a5d01c:/mnt/test/examples# emcc hello.cc
INFO     root: (Emscripten: Running sanity checks)
WARNING  root: java does not seem to exist, required for closure compiler, which is optional (define JAVA in ~/.emscripten if you want it)

Add gcc plugin dir to path

I don't know why gfortran needs the full path in -fplugin=/usr/lib/gcc/x86_64-linux-gnu/4.6/plugin/dragonegg.so

Partial compilation to libraries

Right now I have only figured out how to use emscripten to produce a 'full binary' version that includes FORTRAN code. But it would be more useful if I could produce a js-file that had (e.g.) the LAPACK functions transpiled to JS that could be used anywhere -- essentially the analogue of a shared library, liblapack.a

Get consistent version of gcc/gfortran and dragonegg

Currently both dragonegg and gfortran claim to be 4.6, but dragonegg requires dragonegg_disable_version_check=1 to run. May be a real problem, may be just cosmetic, but it looks terrible and should be fixed.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.