📄 f77
字号:
.de XX.ne 3.sp .3.ti -1i.ta 1i\\$1 \c...EQdelim $$.EN.ND "1 August 1978".RP.TLA Portable Fortran 77 Compiler.AUS. I. Feldman.AUP. J. Weinberger.AI.MH.AB.LPThe Fortran language has just been revised.The new language, known as Fortran 77,became an official American National Standard on April 3, 1978.We report here on a compiler and run-time system for the new extended language.This is believed to be the first complete Fortran 77 system to be implemented.This compiler is designed to be portable,to be correct and complete,and to generate code compatible with calling sequences produced by C compilers.In particular, this Fortran is quite usable on.UXsystems.In this paper, we describe the language compiled,interfaces between procedures,and file formats assumed by the I/O system.An appendix describes the Fortran 77 language..AE.CS 9 10 19 0 0 8.NH 0INTRODUCTION.PPThe Fortran language has just been revised.The new language, known as Fortran 77, became an official American National Standard [1] on April 3, 1978.for the language, known as Fortran 77, is about to be published.Fortran 77 supplants 1966 Standard Fortran [2].We report here on a compiler and run-time system for the new extended language.The compiler and computation library were written by SIF, the I/O system by PJW.We believe ours to be the first complete Fortran 77 system to be implemented.This compiler is designed to be portable to a number of different machines,to be correct and complete,and to generate code compatible with calling sequences producedby compilers for the C language [3].In particular,it is in use on.UXsystems.Two families of C compilers are in use at Bell Laboratories,those based on D. M. Ritchie's PDP-11 compiler[4]and those based on S. C. Johnson's portable C compiler [5].This Fortran compiler can drive the second passes of either family.In this paper, we describe the language compiled,interfaces between procedures,and file formats assumed by the I/O system.We will describe implementation details in companion papers..PP.NH 2Usage.PPAt present, versions of the compiler run on and compile for the PDP-11,the VAX-11/780,and the Interdata 8/32.UXsystems.The command to run the compiler is.DS Cf\|77 \fIflags file . . .\fR.DE.B f\|77is a general-purpose command for compiling and loading Fortran and Fortran-related files.EFL [6] and Ratfor [7] source files will be preprocessed before being presented to the Fortran compiler.C and assembler source files will be compiled by the appropriate programs.Object files will be loaded.(The.B f\|77and.B cccommands cause slightly different loading sequences to be generated,since Fortran programs need a few extra libraries and a different startup routinethan do C programs.)The following file name suffixes are understood:.DS I .f Fortran source file .e EFL source file .r Ratfor source file .c C source file .s Assembler source file .o Object file.DEThe following flags are understood:.in +1i.XX \(miSGenerate assembler output for each source file, but do not assemble it.Assembler output for a source file.B x.f,.B x.e,.B x.r,or.B x.cis put on file\fBx.s\fR..XX \(micCompile but do not load.Output for.B x.f,.B x.e,.B x.r,.B x.c,or.B x.sis put on file.B x.o..XX \(mimApply the M4 macro preprocessor to each EFL or Ratfor source file before using the appropriate compiler..XX \(mifApply the EFL or Ratfor processor to allrelevant files, and leave the output from.B x.eor.B x.ron.B x.f.Do not compile the resulting Fortran program..XX \(mipGenerate code to produce usage profiles..XX "\(mio \fIf\fR"Put executable module on file.I f.(Default is\fBa.out\fR)..XX \(miwSuppress all warning messages..XX \(miw66Suppress warnings about Fortran 66 features used..XX \(miOInvoke the C object code optimizer..XX \(miCCompile code the checks that subscripts are within array bounds..XX \(mionetripCompile code that performs every.B doloop at least once.(see Section 2.10)..XX \(miUDo not convert upper case letters to lower case.The default is to convert Fortran programs to lower case..XX \(miuMake the default type of a variable.B undefined.(see Section 2.3)..XX \(miI2On machines which support short integers,make the default integer constants and variables short.(\fB\(miI4\fR is the standard value of this option). (see Section 2.14).All logical quantities will be short..XX \(miEThe remaining characters in the argument are used as an EFL flag argument..XX \(miRThe remaining characters in the argument are used as a Ratfor flag argument..XX \(miFRatfor and and EFL source programs are pre-processed into Fortran files,but those files are not compiled or removed..in -1i.LPOther flags,all library names (arguments beginning \fB\(mil\fR),and any names not ending with one of the understood suffixes are passed to the loader..NH 2Documentation Conventions.PPIn running text, we write Fortran keywords and other literal strings in boldface lower case.Examples will be presented in lightface lower case.Names representing a class of values will be printed in italics..NH 2Implementation Strategy.PPThe compiler and library are written entirely in C.The compiler generates C compiler intermediate code.Since there are C compilers running on a variety of machines,relatively small changes will make this Fortran compiler generate code for any of them.Furthermore, this approach guarantees that the resulting programs are compatible with C usage.The runtime computational library is complete.The mathematical functions are computed to at least 63 bit precision.The runtime I/O library makes use of D. M. Ritchie's Standard C I/O package [8]for transferring data.With the few exceptions described below, only documented calls are used,so it should be relatively easy to modify to run on other operatingsystems..NH 1LANGUAGE EXTENSIONS.PPFortran 77 includes almost all of Fortran 66 as a subset.We describe the differences briefly in the Appendix.The most important additions are a character string data type,file-oriented input/output statements, and random access I/O.Also, the language has been cleaned up considerably..PPIn addition to implementing the language specified in the new Standard,our compiler implements a few extensions described in this section.Most are useful additions to the language.The remainder are extensionsto make it easier to communicate with C proceduresor to permit compilation ofold (1966 Standard) programs..NH 2Double Complex Data Type.IPThe new type.B "double complex"is defined.Each datum is represented by a pair of double precision real variables.A double complex version of every.B complexbuilt-in function is provided.The specific function names begin with \fBz\fR instead of \fBc\fR..NH 2Internal Files.IPThe Fortran 77 standard introduces ``internal files'' (memory arrays), butrestricts their use to formatted sequential I/O statements.Our I/O system also permits internal files to be usedin direct and unformatted reads and writes..NH 2Implicit Undefined statement.IPFortran 66 has a fixed rule that the type of a variable that does not appear in a type statementis.B integerif its first letter is\fBi, j, k, l, m\fR or \fBn\fR,and.B realotherwise.Fortran 77 has an.B implicitstatement for overriding this rule.As an aid to good programming practice, we permit an additional type,.B undefined.The statement.DSimplicit undefined(a-z).DEturns off the automatic data typing mechanism,and the compiler will issue a diagnostic for each variable that is used but doesnot appear in a type statement.Specifying the.B \(miucompiler flag is equivalent to beginning each procedure with this statement..NH 2Recursion.IPProcedures may call themselves, directly or through a chain of other procedures..NH 2Automatic Storage.IPTwo new keywords are recognized,.B staticand.B automatic.These keywords may appear as ``types'' in type statements and in.B implicitstatements.Local variables are static by default;there is exactly one copy of the datum, and its value is retained between calls.There is one copy of each variable declared.B automaticfor each invocation of the procedure.Automatic variables may not appear in.B equivalence,.B data,or.B savestatements..NH 2Source Input Format.IPThe Standard expects input to the compiler to be in 72 column format:except in comment lines,the first five characters are the statement number, the next is the continuation character,and the next sixty-six are the body of the line.(If there are fewer than seventy-two characters on a line, the compiler pads it with blanks;characters after the seventy-second are ignored)..IPIn order to make it easier to type Fortran programs,our compiler also accepts input in variable length lines.An ampersand (``&'') in the first position of a line indicates a continuationline; the remaining characters form the body of the line.A tab character in one of the first six positions of a line signals theend of the statement number and continuation part of the line;the remaining characters form the body of the line.A tab elsewhere on the line is treated as another kind of blank by thecompiler..IPIn the Standard, there are only 26 letters \(em Fortran is a one-case language.Consistent with ordinary.UXsystem usage, our compiler expects lower case input.By default, the compiler converts all upper case characters to lower case except those inside character constants.However, if the.B \(miUcompiler flag is specified, upper case letters are not transformed.In this mode, it is possible to specify external names with upper case letters in them,and to have distinct variables differing only in case.Regardless of the setting of the flag,keywords will only be recognized in lower case..NH 2Include Statement.IPThe statement.DSinclude \(fmstuff\|\(fm.DEis replaced by the contents of the file.B stuff.\fBinclude\fRs may be nested to a reasonable depth, currently ten..NH 2Binary Initialization Constants.IPA.B logical,.B real,or.B integervariable may be initialized in a.B datastatementby a binary constant, denoted by a letter followed by a quoted string.If the letter is \fBb\fR, the string is binary, and only zeroes and ones are permitted.If the letter is \fBo\fR, the string is octal, with digits \fB0\(mi7\fR.If the letter is \fBz\fR or \fBx\fR, the string is hexadecimal, with digits \fB0\(mi9\fR, \fBa\(mif\fR.Thus, the statements.DSinteger a(3)data a / b\(fm1010\(fm, o\(fm12\(fm, z\(fma\(fm /.DEinitialize all three elements of.B ato ten..NH 2Character Strings.IPFor compatibility with C usage, the following backslash escapes are recognized:.DS\en newline\et tab\eb backspace\ef form feed\e0 null\e\(fm apostrophe (does not terminate a string)\e" quotation mark (does not terminate a string)\e\e \e\e\fIx\fR \fIx\fR, where \fIx\fR is any other character.DEFortran 77 only has one quoting character, the apostrophe.Our compiler and I/O system recognizeboth the apostrophe ( \(fm ) and the double-quote ( " ).If a string begins with one variety of quote mark, the other may be embedded within itwithout using the repeated quote or backslash escapes..IPEvery unequivalenced scalar local character variable and every character string constant is alignedon an.B integerword boundary.Each character string constant appearing outside a.B datastatement is followed by anull character to ease communication with C routines..NH 2Hollerith.IPFortran 77 does not have the old Hollerith (\fIn\|\fBh\fR)notation,though the new Standard recommends implementing the old Hollerith featurein order to improve compatibility with old programs.In our compiler, Hollerith data may be used in place of character string constants,and may also be used to initialize non-character variables in.B datastatements..NH 2Equivalence Statements.IPAs a very special and peculiar case,Fortran 66 permits an element of a multiply-dimensioned array to be represented bya singly-subscripted reference in.B equivalencestatements.Fortran 77 does not permit this usage, sincesubscript lower bounds may now be different from 1.Our compiler permits single subscripts in.B equivalencestatements,under the interpretation that all missing subscripts are equal to 1.A warning message is printed for each such incomplete subscript..NH 2One-Trip DO Loops.IPThe Fortran 77 Standard requires that the range of a.B doloop not be performedif the initial value is already past the limit value,as in.DSdo 10 i = 2, 1.DEThe 1966 Standard stated that the effect of such a statement was undefined,but it was common practice that the range of a.B doloop would be performedat least once.In order to accommodate old programs, though they were in violation of the 1966 Standard,the.B \(mionetripcompiler flag causes non-standard loops to be generated..NH 2Commas in Formatted Input.IPThe I/O system attempts to be more lenient than theStandard when it seems worthwhile.When doing a formatted read of non-character variables,commas may be used as value separators in the input record,overriding the field lengths given in the format statement.Thus,the format.DS(i10, f20.10, i4).DEwill read the record.DS\(mi345,.05e\(mi3,12.DEcorrectly..NH 2Short Integers.IPOn machines that support halfword integers,the compiler accepts declarations of type.B integer\(**2.(Ordinary integers follow the Fortran rules about occupying the samespace as a REAL variable; they are assumed to be of C type.B "long int" ;halfword integers are of C type.B "short int" .)An expression involving only objects of type.B integer\(**2is of that type.Generic functions return short or long integers depending on the actual types of their arguments.If a procedure is compiled using the.B \(miI2flag, all small integer constants will beof type.B integer\(**2.If the precision of an integer-valued intrinsic function is not determined by the generic function rules,one will be chosen that returns the prevailing length(\fBinteger\(**2\fR when the \fB\(miI2\fR command flag is in effect).When the.B \(miI2option is in effect, all quantities of type.B logicalwill be short.Note that these short integer and logical quantities do not obey the standard rules for storage association..NH 2Additional Intrinsic Functions.IPThis compiler supports all of the intrinsic functions specified in the Fortran 77 Standard.In addition, there are functions for performing bitwise Boolean operations(.B or,.B and,.B xor,and.B not)and for accessing the.UXcommand arguments(.B getargand.B iargc)..NH 1VIOLATIONS OF THE STANDARD.PPWe know only thre ways in which our Fortran system violates the new standard:.NH 2Double Precision Alignment.IPThe Fortran standards (both 1966 and 1977)permit.B commonor.B equivalencestatements to force a double precision quantity onto an odd word boundary,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -