raymond@math.berkeley.edu (Raymond Chen) (02/08/91)
This is the prerecorded message I send out when I see requests for X-to-C conversion. -------------------- Fortran to C conversion: Karen Anderson (anderson@eecs.cs.pdx.edu) did a lot of work in collecting this information. Any additions or corrections to this document would be greatly appreciated; please send them to raymond@math.berkeley.edu. Standard disclaimers apply. Opinions are those of the original authors. Typing and editing errors are mine. =============================================================================== f2c ------------------------------------------------------------------------------- Joshua Simons (simons@think.com) and Mark.Maimone@a.gp.cs.cmu.edu posted the press release: Source for f2c, a Fortran 77 to C translator jointly developed by folks from Bell Labs, Bellcore, and Carnegie Mellon, is now freely available. F2c was derived from the original UNIX operating system's f77(1), and the generated C follows f77's calling conventions; on some machines, the resulting object files are interchangeable with (and behave indistinguishably from) objects compiled by f77. The main "advantage" of f2c is that it converts ANSI standard Fortran 77 into C without manual intervention, at least when invoked by a suitable script or makefile (that may need to exercise an f2c option to ensure that COMMON blocks are defined just once). The main "problems" are that f2c does no code restructuring (e.g., gotos are preserved) and that Fortran I/O gets converted into a bunch of calls; thus the translated C code doesn't look too pretty, and in general one would need to maintain the Fortran rather than its translation into C. [Indeed, maintainable C code was specifically *not* an objective of the f2c project. The intent is that you maintain the Fortran. The f2c tech report comments that producing maintainable C automatically seems to require some amount of manual intervention even using commercial ($$$) translator programs. -- Henry Spencer] There is a plethora of options, many of which exist to support different compilation environments for the translated C (e.g., ANSI C or C++ compatability, different type sizes, separate files for COMMON blocks to appease "smart" linkers). So far f2c (and f2c-generated source) has compiled successfully on many machines: Sun, Vax, IBMRT, Apollo, SGI, MIPS, and Cray to name a few. F2c has been under test by the net community for over six months [as of 27 Apr 90], and has been verified on the NBS tests, several large math libraries, floating point tests, even code for laying cable on the ocean floor! To find about f2c, send the following E-mail message to netlib (netlib@research.att.com or research!netlib): echo send index from f2c | mail netlib@research.att.com Your message will be answered automatically (by a program -- see CACM vol. 30 #5 (May, 1987), pp. 403-407). You will receive a reply explaining how to automatically acquire f2c source (about 600K), f2c library source (130K), and supporting info (man page, etc). To get it using anonymous FTP, ftp research.att.com and cd to directory dist/f2c. All files are stored in compressed format. [Make sure to pick up the runtime libraries libf77 and/or libi77.] ****************************** DISCLAIMER ****************************** Careful! Anything free comes with no guarantee. ************************************************************************ ------------------------------------------------------------------------------- Mike Black (black@seismo.CSS.GOV) reports: I tried using f2c from the at&t distribution. If your desperate, it might be worth it. But the code is a nightmare to read. I've done hand conversions before with much better results than f2c. ------------------------------------------------------------------------------- Larry Jones (sdrc!scjones%thor@uunet.UU.NET) writes: I haven't used f2c myself, but it's gotten rave reviews from others here who have used it. ------------------------------------------------------------------------------- Rick Stevens (zardoz!tmiuv0!rick@decwrl.dec.com) says: There's a huge bugger from ATT Bellcore called F2C. It's written in C (natch) and is FTPable. It's big, and you'll have to build it for your system, however it does work and works quite well. ------------------------------------------------------------------------------- And from Hans Georg v. Zezschwitz (zeschwitz@imdm.uke.uni-hamburg.dbp.de): I'm am currently trying to work with the standart f2c (from netlib@att...) Till now I made only one attempt with a Fortran program from a microVax. It was for parametrization of eeg-segments. Apart from screen-specific adaptions I had to edit it worked directly on a Unix (Xenix) system (under C - of course). For I rather don't know much about Unix nor Fortran I otherwise anyway would not have coped with occuring problems. =============================================================================== Cobalt Blue ------------------------------------------------------------------------------- ubbpc!wgh@PRC.Unisys.COM (William G. Hutchison) writes: We have had a client port an X-window application successfully from FORTRAN to C using the Cobalt Blue converter. ------------------------------------------------------------------------------- Tim.Ouellette@FtCollins.ncr.com says: Of the Fortran-to-C convertors I've seen. They've dealt with the simple commands okay. The main downfall I've seen is that they don't have any way of dealing with the FORTRAN 'EQUIVALENCE' statement. I've listed one's I seen advertised below. Hope it helps. FOR_C by Cobalt Blue 2940 Union Ave, Ste C San Jose CA 95124 (408)723-0474 ------------------------------------------------------------------------------- Ralph Carpenter (ralphc@tekcae.CAX.TEK.COM) adds, A demo disk is available for around $10. It converts subroutines that are less than 1K in size. The address and phone of a mail order source: The Programmer's Connection 7249 Whipple Ave NW North Canton, OH 44720-7137 (800) 336-1166 Price as of 1 Jan 1990 (including surface UPS shipping): $442 with binary runtime, ($575 list). $673 with runtime sources, ($875 list). ------------------------------------------------------------------------------- Steve Fullerton (scf%statware.uucp@cs.orst.edu) notes: Cobalt Blue, a company out of San Jose has 2 FORTRAN-to-C translator products, FOR_C and FOR_C++. I have a copy of FOR_C and have seen demos of FOR_C++. If you need to deal with complex variables, then take a look at FOR_C++. The translation results in very readable code. FOR_C also handles complex but the resulting code might be best described as spaghetti, although it does a very nice job on other standard and non-standard FORTRAN. Their address and phone: Cobalt Blue 1683 Milroy, Suite 101 San Jose, CA 95124 408/723-0474 =============================================================================== Promula.Fortran ------------------------------------------------------------------------------- orszak@cfa243.harvard.edu (Jeff Orszak) sent a post which appeared on comp.lang.fortran written by tohanson@gonzo.lerc.nasa.gov (Jeff Hanson). In Digital Review (June 18, 1990) there is a review of Promula.Fortran, a Fortran to C source code translator on pages 29 - 31. The Test Brief follows Vendor: Promula Development Corp. 3620 N. High St. Suite 301 Columbus, OH 43214 (614) 263-5454 Test configuration: Promula.Fortran version 2.01 installed on a VAXstation II/GPX running VMS 5.2 Price as Tested: $995. Pros: Includes many command line options Can produce various "flavors" of C code Supports all VAX Fortran data types except REAL*16 Successfully translated STRUCTURE and RECORD decalarations including UNION and MAP statements Cons: I/O subroutine library did not work properly with ANALYSIS and PHILCO (2 of the DR Labs test programs) Defaulted to pointer notation for representing arrays, which is unclear and less efficient in VAX C Required dialect and error message files to be copied to current working directory for translation Used double quotes for include file specifications but incorrectly defines VAXC$INCLUDE rather than C$INCLUDE Non VMS-style command line options The final 2 paragraphs of the review are: With the exception of some undesirable default options, less-than-ideal handling of some I/O statements and unsatisfactory handling of the DATA statement, Promula.Fortran is a very useful utility for users who must translate large amounts of Fortran to C. It translates quickly and generates well-written and - with some expections - immediately executable C code. Promula.Fortran has options that give users control over the C code produced. Promula.Fortran's C code is very amenable to C programmers; it uses C language conventions and, to put it simply, "feels" like C. I have not seen this product and this posting should not be seen as an endorsement for Promula. It should be seen as a high endorsement for DR Labs. =============================================================================== for2c ------------------------------------------------------------------------------- daveo@mipon3.intel.com (David O'Brien) writes: I worked with a program about 18 months ago called for2c or something like that. It was DOS based. I delt with the designer himself and had good success. If you would like, I can go dig the name/company up for you. I know right were they are at home. Let me know. =============================================================================== Green Hills Software, Inc. ------------------------------------------------------------------------------- unisoft!peritek!dig (Dave Gotwisner) found this advertisement: Green Hills Software, Inc. 425 East Colorado Street, Suite 710 Glendale, CA 91205 (818) 246-5555 FAX: 818-246-7037 I don't know how good it is, but we use one of their other products (a 68K cross compiler running under VMS), and it is quite good. Binary copies can be gotten from: OASYS, Inc. 230 Second Ave. Waltham, MA 02154 617-890-7889 From the data sheet: Language * ANSI Fortran-77 (Full language) * DoD Mil-STD 1753 * VAX/VMS Extensions * NAMELIST * Full Syntax OPEN * STRUCTURES * %VAL, %REF, %LOC * !comments * ENCODE/DECODE * INTEGER *1, *2 * Octal/Hex constants * etc. Optimizations * Register allocation * Strength reduction * Loop Invariant elimination * Common subexpressions * Value propagation * Tail recursion * Loop rotation * Static address elimination Hosts VAX/UNIX Sun-2 386 UNIX/DOS VAX/VMS Sun-3 (others by arrangement) For further information, please contact either OASYS or Green Hills. =============================================================================== A masters thesis ------------------------------------------------------------------------------- Roger Christman (dvl@psuvm.bitnet) is working on a Fortran-to-C translator for his Masters thesis at Penn State U. Here's what he says: It is designed to accept any Fortran 66 program and translate it into an equivalent C source. Program flow structure is analyzed so that even the messiest GOTO arrangements should find themselves better approximating such things as loops and switches. ... The upshot of all this is that the resulting program will be more intuitively structured, as well as more efficient than the original. As an example of current benchmarks, using the F77 and CC compilers on a Sun Workstation Unix machine, my program is doing quite well. The time required to translate into C and compile there is less than the original Fortran compilation time. Also, the object code in C executes faster than the original Fortran. If you would like to find out more later on, when I approach the end of the project, please send me mail at this address. I must warn you that this project is for academic reasons alone, and is not designed with production-scale error-checking. If your program will not compile in Fortran 66, don't expect this translator to give you very meaningful results. =============================================================================== General comments ------------------------------------------------------------------------------- On the subject of source code conversions in general ittc!fbresz@uunet.UU.NET gets the last word: Hi, I have seen this question asked a few time and I finally decided to send an email to someone so .. I used to work for a company involved in such business. We would for a price take your working FORTRAN code and convert it to C. Now this was not cheap nor was it easy. I spent 1 entire year of my life on a project which bore little fruit. So I am of the opinion that it might just be easier to recode. Also you might want to think about waht you mean by translation, we of course had the bizarre definition, runs identically to FORTRAN. This leads into reproducing all the bizarre behaviours of FORTRAN and if you think thats hard try doing PL/I => C we also did that or how about PL/I => Ada. For these reasons (i.e. my brain is fried) I no longer do much programming. I run a medium sized network for Westinghouse in which the biggest programming task is getting sendmail.cf files workking correctly . But seriously if you would care to have even more information about translation, the company I used to work for has long since evaporated. I can then tell you anything you want to know without problems of revealing corporate secrets. Frank P. Bresz }*{ ITTC Network Administrator =============================================================================== =============================================================================== Pascal to C conversion =============================================================================== Two different Pascal-to-C converters are available from a comp.sources.unix archive near you. volume10: ptoc/part[01-02] Pascal to C translator volume13: pas2c.pch Patches for Pascal-to-C translator volume21: p2c/part[01-32] Pascal to C translator " p2c/patch1 Fix to incomplete shar files for p2c, Patch1 ------------------------------------------------------------------------------- ptoc by Per Bergsten (mcvax!enea!chalmers!holtec!perb) is written in Pascal and comes with a bootstrapping C version. Don't forget to pick up the patches! ------------------------------------------------------------------------------- p2c is by Dave Gillespie. It understands several Pascal dialects (HP, partial Turbo, etc) and is very flexible and configurable. It has been compiled and used on Sun-3's, so presumably it is fairly portable among 32-bit Unix machines. The p2c package is also available for ftp from csvax.caltech.edu. Note, however, that although it can translate PC dialects of Pascal, the converter itself runs under UNIX. ------------------------------------------------------------------------------- Another converter, ptc-tex by Tor Lillqvist (tml@tik.vtt.fi), is capable even of translating TeX. It's not UNIX-specific. gtoal@tardis.computer-science.edinburgh.ac.uk recommends it heartily. ------------------------------------------------------------------------------- And of course, there is web2c which isn't really a Pascal converter, but it's close. ------------------------------------------------------------------------------- Phillip A. McReynolds (pam1@pam1@ra.MsState.Edu) mentioned the program mars.ee.msstate.edu[130.18.64.3]:/files/sources/tpc.arc when the question was raised on 26 June 1990 on comp.sys.ibm.pc. Many other IBM-specific "pascal-to-c" conversion programs can be found in the standard places, as described in the Frequently Asked Questions for comp.sys.ibm.pc.misc. =============================================================================== =============================================================================== Modula-2 to C conversion =============================================================================== Dave Gillespie's p2c converter [qv] can also convert Modula-2. =============================================================================== =============================================================================== Modula-3 to C conversion =============================================================================== The DEC Systems Research Center distributes SRC Modula-3. SRC Modula-3 compiles to C. Its runtime requires only vanilla Unix functionality (e.g. malloc, setjmp, open, read, write, ...). The compiler and library sources are freely ftp-able from gatekeeper.dec.com in /pub/DEC/Modula-3. We currently distribute versions of SRC Modula-3 that run under Ultrix on VAXen and DECstation 3100s. Others have ported the system to SPARCstations and IBM PC/RTs. We will distribute those versions as soon as they are fully integrated. -- Bill Kalsow, DEC Systems Research Center =============================================================================== =============================================================================== Scheme to C conversion =============================================================================== The Scheme-to-C compiler, Scheme->C, done at Digital Equipment Corporation's Western Research Laboratory is now available for public ftp. The Scheme->C system supports the essentials of Revised**3 and many of the optionals. Extensions include "expansion passing style" macros, a foreign function call capability, and interfaces to X11's Xlib. The system does provide call-with-current-continuation. Numbers are represented internally as 29-bit integers, or 64-bit floating point values. The compiler is written in Scheme. Most of the runtime system (including an interpreter) is written in Scheme. The generational compacting garbage collector and a few other things are written in C. There is a small (< 100 lines) amount of assembly code. The system is known to run on VAX's and DECstation 3100's running Ultrix. Other ports should be straightforward. The system is available for anonymous ftp from 'gatekeeper.dec.com' [16.1.0.2]. The Scheme->C files are in '/pub/DEC/Scheme-to-C'. Those files include: README - overview and copyright notice. 23feb90.tar.Z - compressed tar file containing all source and documentation. -- Joel Bartlett bartlett@decwrl.dec.com