Home
computer systems laboratory - The Stanford University InfoLab
Contents
1. 7 3 Sym bol Tables 27 ARRY_INFO PACKED RECORO DIMENSION INTEGER THIS MUSTNOT BE 0 FOLLOWING 2 ARRAYS USED ONLY UP TO OIMENSION DIMEN ARRAYL1 MAXDIM OF OIM EITHER THE CONSTANT OIMENSION OR THE POINTER TO THE SYMBOL TABLE ENTRY IF VARIABLE OIMENSION S CONM ARRAY 1 MAXDIM Of BOOLEAN TRUE IF THE ITH OIMENSION IS CONSTANT NUM CONST DIMS THE FIRST N C O OF S CON ARE TRUE FIRST OFFSET INTEGER CORRECTION FOR COMPUTE OFFSET END Its main procedure FSYMBOL has parameters that correspond to the record fields whose contents are checked inside this procedure PROCEDURE FSYMBOL VAR SPTR POINTSYMBOL RETURNS ALWAYS A POINTER TO THE ENTRY IN THE SYMBOL TABLE SYMNAME THENAME SYMTYPE DATATYPE NONE IF NO INFO IS SENT SYMWHEREDEF INED INTEGER THIS WILL CONTAIN THE PROGRAM LINE NUMBER BEING PROCESSED O SYMF UNCSUBR FUNCTYPE NOTEXTERNAL IF NO INFO THE PROPER FUNCTYPE OTHERWISE SYMCOMMON SYMDUMMY SYMEQUIVALENCE SYMLHS SYMRHS SYMINITIALIZED BOOLEAN FALSE IF NO INFO OR FALSE Most of the entries in this symbol table assume an implicit value if no information is asserted When it is necessary to check that an entry is having a certain value it is possible to accomplish the check by asserting the entry to that value using the corresponding parameter in the call to FSYMBOL Note that in this case if the entry is having the implici
2. Check the label and symbol tables and issue warnings if any label or variable have been used only on the left hand side or only on the right hand side Generate code for the end of the U Code procedure for the current program unit 7 25 7 Symbol Tables 7 1 The structure of the tables There are five symbol tables in UFORT l The main symbol table keeps track of variables subprogram and entry names intrinsic and standard function names and Format labels used within a single program unit main program or subprogram 2 The label table keeps track of Fortran labels within a single program unit 3 The common name table keeps track of common areas 4 The external name table keeps track of subprogram and entry names throughout ail the program units 5 The standard function table contains the names of all standard functions Each of these tables is made up of records which form a binary tree The symbols are ordered lexicographically in the tree The heads of the tables are pointed to by pointers stored the global variables SYMHEAD LABELHEAD COMHEAD EXTHEAD and HEADSTDTABLE The main symbol table and the label table are cleared at the beginning of each new program unit The other three are cleared only once at the beginning of compilation The storage used by the cleared entries is automatically reclaimed through the garbage coliection facility in amp he Pascal in which UFORT is written 7 2 The associated r
3. ii TABLE Of CONTENTS Section Page 7 3 The main symbol table 26 7 4 The label number table 21 7 5 The common table 28 7 6 The external name table 29 7 7 The standard function table 30 8 Processing of Declarations 31 8 1 Representation of types 31 8 2 Type specific declarations 8 3 Dimension declaration 32 8 4 Implicit declaration 32 8 5 Common declaration 33 8 6 Equivalence declaration 33 8 7 External Declaration 3 9 Initialization of Variables 35 9 1 The initialization list 35 9 2 The DATA statement 36 9 3 Procedure FORMVARLIST 37 94 Procedure FILL ADDRESS INITIALIST 38 9 5 Procedure VARINITIALIZATION 38 10 Storage A location Structure 40 10 1 Pascal representation 41 11 Storage Allocation 42 11 1 Preprocessing equivalence groups 42 1 1 2 Allocating space for common areas 43 11 3 Allocating space for non common variables 43 12 U Code generating routines 44 13 Temporary storage management 46 14 Loading and storing variables 48 14 1 Example of indirect load and store 49 15 Expression Evaluation 50 15 1 Syntax 50 15 2 Processing identifiers 51 15 3 Type checking and error recovery inside ARITH 52 15 4 Example 52 15 5 The assignment statement 53 TABLE Of CONTENTS Section 16 17 19 20 21 22 23 Complex Number Arithmetic 16 1 Addition and subtraction 16 2 Multiplication 16 3 Division 16 4 Complex valued functions Subroutine and Function Statements 17 1 Initialization of a segment b
4. AND p Wy COMPUTER SYSTEMS LABORATORY gt LELAND SAM STANFORD UNIVERSITY STANFORD CA 943054055 UFORT A Fortran to Universal Pcode Translator FIXFOR 2 CSL Technical Report No 168 Stanford University January 30 1980 13 06 Frederick Chow Peter Nye Cio Wiederhoid TABLE OF CONTENTS Section Introduction 1 1 Objectives and constraints 1 2 Conclusion 2 User s Guide 2 Statements 2 2 Program format 2 3 Data types and constants 2 3 Data types 23 2 Constants 2 4 Arrays and storage management 2 5 Initializing variables 2 5 1 Loops in variabie lists in DATA statements 25 2 General initialization rules 2 5 3 Initialization by character strings 2 5 3 Examples 2 6 Subprograms 2 7 Subprogram names as parameters 2 8 Multiple entries to subprograms 2 9 User options the SET statement 2 10 Input Output 2 IO i File handling 2 10 2 The READ and WRITE statements 2 10 3 The PRINT statement 2 1 1 Miscellaneous Overall Organization 3 1 Structural scheme 3 2 Error handling Lexer 4 Summary 4 2 Lexeme types 4 3 Reading in a statement 4 4 Scanning the statement Statement Classifier Main block 6 1 Main procedure 6 2 Procedure BLOCK Symbol Tables 7 1 The structure of the tables 7 2 The associated routines PEEN 1 O tn tn 10 12 12 13 14 14 14 15 15 17 18 19 19 19 20 22 23 23 23 25 25 ome KC
5. BACKSPACE PAUSE 6 User s Gu ide 22 2 2 Program format Some restrictions on program format are imposed by UFORT Source text_ format Identifiers including keywords must be separated by delimiters For example 00381 1 3 is illegal it should be 00 30 I 1 3 Similarly 8 should be COMMON Blanks are not allowed within identifiers keywords and real constants Blanks within dotted keywords however are allowed e g TR U E The usual convention of specifying a quote embedded within a quoted literal using two consecutive quotes is followed Blank lines are allowed A line cannot contain more than one statement Position of declaration statements All declaration statements including DATA statements must appear before the first executable statement in a program unit Statement functions must appear after the declarative statements and before the first executable statement The only restriction regarding the order among the declaration statements is that the type and dimension declaration of a variable must precede its initialization specification FORMAT statements may appear either with the declarative or the executable statements if an IMPLICIT statement is used it must be the very first statement in the program unit Variable names Fortran keywords and standard and intrinsic function names can be used as variable names except the keyword FORMAT Also the name of a com
6. U Code SETVA0O77 ENT R4 77 11 the multientry procedure LEX 1 1 LEX 2 72 LEX 3 15 PSTR A R 77 0 36 sreceive the branch parameter UJP 11002 jump to branch code L1001 LAB 0 label for normal entry point 100 AM 1 576 36 parameter Pl kept at level 1 1100 R 0 36 STR RM 77 0 36 PLOO R M 77 0 36 RET L1003 LAB 100 1 612 36 slabel for the ENTRY statement 518 5 Multiple Entry Subprograms 100 M 1 576 36 1100 0 36 ISTR R 0 36 PLOD RM 77 0 36 RET 1002 LAB 0 label for the branch code Loo JR 77 0 36 load branch parameter XP Ji100411005 0 1 1004 CLAB 2 jump table UJP 11001 UJP 1003 11005 148 0 PLOD R M 77 9 36 RET DEF R 36 OEF M 72 END SETVA077 SETVAO76 ENT R 4 76 11 entry procedure for FUNCTION statement LEX 1 1 LEX 272 LEX 3 73 PSTR A R 76 0 36 receive parameter LOO A R 76 0 36 sload and store address for Pl STR A M 1 576 36 in level 1 MST 4 call the multientry procedure Loc J 36 0 PAR J 0 O 36 CUP R 77 SETVAO77 11 STR R M 76 0 36 recsive value returned PLOO R M 76 0 36 return value received RET OEF R 36 OEF M 72 END SETVA076 ASSIG078 ENT R 4 78 11 sentry procedure for ENTRY statement LEX 1 1 LEX 272 LEX 3 73 PSTR A R 78 0 36 jreceive parameter P2 LOO A R 78 0 36 load and store address for P2 STRA M 1 612 36 in level 2 MST 4 call the multientry procedure Loc J 36 1 PAR JM 0 0 36 CUP R 77 SETVAO7 1 1 STR R M 78 0 36 receive value retu
7. relational expression relational expression ar i th expr re I operator ar i th expr rel operator LE LT 6E GT NE EQ a j nan nl ari th expr a term addop term term addopl factor mul top factor factor primary xx pr i mary addop mul top s x primary ar i th expr integer constant real constnat complex constant logical constant variable array element 15 1 Expression Evaluation 51 function call complex constant arith expr arith expr logical constant a TRUE FALSE I 5 2 Processing identifiers When ARITH encounters an identifier it must determine whether it is a variable a call to a stand ard function a call to a user defined function or a call using a function dummy argument There are two procedures for processing function calls STANDARDFUNC which processes calls to intrinsic and standard external functions and USERFUNC which processes calls to statement functions and external functions For the latter refer to Section 19 One of the fields of every record in the symbol table is _FUNCSUBR It has one of the following values FUNCTYPE NOTEXTERNAL EXTERNAL EXTSUBR EXTFUNC STMTFUNC 1 NTRI NSTDEXT PARAHPROC How a symbol functions in the program is determined by its FUNCTYPE attribute NOTEXTERNAL denotes that the identifier is a variable or array na
8. FJP L1001 sif equal jump to statement 10 100 JM 1 504 36 lead J back LDC J 36 20 load constant 20 NEQ J compare FJP 11002 if equal jump to statement 20 100 JM 1 504 36 load J back LDC 36 30 load constant 30 NEQ J compare FJP L1003 sif equal jump to statement 30 23 73 23 The Arithmetic IF and Logical IF Statements 23 1 Logical IF The logical IF is the only type of Fortran statement that is compound The compilation is separated into two parts The first part procedure LOGICALIF processes the logical expression enclosed by the parentheses Procedure LOGICALEXPR is called which will generate the U Code that evaluates the IF condition and puts the result on top of the stack The outermost pair of parentheses is not checked here since they have been checked inside procedure CLASSIFY The global variabie IFDEST serves as a flag to indicate whether current processing is inside a logical IF statement it is initialized to 1 in procedure INITBLOCK When a logical IF statement is encountered it is set to the number of the U Code label which will be generated a amp the end of the whole rr statement Code is generated to jump to this label if the IF condition is false The second part is compiled as an independent Fortran statement the only difference being that IFDEST is set and consequently a new statement is not read in from the source file A check is made if the type of the statement is among those allowed as the second par
9. THE LIST OF PARAMETER ADDRESSES a NEXT ENTRYREC THIS IS USED FOR FORMING A LIST THAT KEEP THE GLOBAL ADORESSES ASSIGNED FOR ENTRY PARAMETERS IN THE ORDER OF THEIR APPEARANCES IN THE MULTIENTRY SUBPROGRAM HEADING OR ENTRY STATEMENT THIS LIST IS POINTED TO FROM THE ENTRYREC RECORO THAT REPRESENTS EACH ENTRY POINT THE PURPOSE Of THIS LIST IS TO GENERATE THE COOE THAT COPIES AOORESSES OF ACTUAL PARAMETERS TO THEIR GLOBAL ASSIGNED LOCATIONS IN THE UCOOE PROCEDURE FOR EACH ENTRY POINT ENTAOOR RECORD ADDR INTEGER NEXT NTADOR ENO The global pointer HEADENTRYLIST points to the list of the ENTRYREC records when processing a multiple entry subprogram HEADENTRYLIST is reset to NIL at the start of each program unit 62 Multiple Entry Subprograms 18 4 18 4 Processing multiple entry subprograms Procedure ENTRYPROCESSING processes an entry point definition It is called from the SUBROUTINE FUNCTION or ENTRY statement processors the former two cases being the beginning of the multiple entry subprogram Its job is to form an ENTRYREC node and fill in the information The ENTRYREC node is then appended to the list pointed to by HEADENTRYLIST No code is generated The dummy argument list is then processed The list of ENTADDR nodes formed is attached to the ENTRYREC node If a dummy argument appears for the first time a location in the global level is allocated for tt Procedure ENTRYSTMT processes an enrry st
10. The information inserted by this routine consists of a pointer to the symbol table entry for the element being initialized its displacement in memory with respect to the beginning of the array which is 0 for a simple variabie the size of the location and the flag CONTINUING which is used to indicate if the current location is a continuation of the location in the previous node as in the succeeding elements in the initialization of whole arrays and the second halves of complex variables Procedure FILL VALUES updates the list of variables in the initializatron list with the corresponding initial values FIRST m usr points to the first element of the list that needs initialization value and POINT TO LIST is used to traverse the list of INITIALIST records while saving the values in the AMOUNT field For each initializatron value this procedure gets the number of times the value is repeated iwsERT VALUE is then called this number of times Fieids NEGATIVE and STRLEN Of INITIALIST are set directly in FILL VALUES depending on the type of the constan t For string constants INSERT VALUE is called as many times as required depending on the length of the string and depending on the flag cowrrwurwe Procedure iwsERT vanLvUE completes the information in the INITIALIST record entry by filling in the lexeme type and the initialization values expressed as an array of characters The procedures EXTEND LIST FILL VALUES and INSERT VALUE are also used in
11. bound checking if turned on for an array with adjustable dimension is made against the current value of the argument used in the dimension declaration Change to the value of this dummy argument is allowed in the subprogram If the actual argument is an uninitialized integer variable no assumption should be made as to the declared bound in the subprogram COMMON declarations There are two special areas which are used for the common variables one is used for the blank common area and the other is for the rest of the common areas The blank common may be of any different length in each program unit as specified in ANS76 The COMMON declaration of any labelled common may not require a storage area larger than the amount specified in the first declaration of the common as in the following example 24 User s G uide Q wrong right COMMON A COMMON X A DUMMY DIMENSION 28 DIMENSION A 28 DUMMY 18 ENO END SUBROUTINE R SUBROUTINE R COMMON X 8 COMMON X 8 DIMENSION B 38 DIMENSION 8 38 END END Alternatively it is possible to use the CSIZ switch that fixes a minimum size for the common areas If the length occupied by a common area in its first declaration is smaller than that specified in any of its later declarations the switch should be set to the space needed for the larger one Storage allocation No assumption should be made about the location of one variable or array in relation to anot her outside a common
12. processing initializations in type specific declaration statements 9 3 Initialization of Variables 37 9 3 Procedure FORMVARLIST In order to handle arbitrarily nested loops in a variable list in the DATA statement this procedure uses two phases to process a variable list The first phase represented by procedure CONSTRUCT builds a list recursively according to the loop structure in the variabie list The second phase represented by procedure EXTEND traverses the list just created recursively and in the process expands the nested loops into linear counts of initializations being added at the end of the global initialization list The list constructed is made up of two kinds of records which represent respectively an element in a variable list and a loop The structures of these two records are as follows e NOOES THAT FORM A LIST OF VARIABLES ANY OF WHICH CAN INSTEAD BE ANOTHER LEVEL Of AN IMPLIED LOOP IN WHICH CASE ISLOOP IS TRUE VARREC x RECORD NEXT VARREC NEXT IN LIST CASE ISLOOP BCOLEAN OF TRUE NEXTLEVEL POINTLEVELREC POINT TO THE NOOE THAT REPRESENTS THE NESTED LEVEL FALSE SPTR POINTSYMBOL NUMSUBS INTEGER 40f SUBSCRIPTS SUBSINFO ARRYSUBSCRIPTS ENO NOOE TO REPRESENT A LEVEL OF IMPLIED LOOP VARLIST POINTS TO THE LIST OF VARIABLES OR AOOITIONAL NESTED LOOPS THAT BELONGS TO THIS LEVEL PREVIOUS POINTS TO THE NODE OF THE LEVEL INSIDE WHICH THIS LOOP IS NESTED CONTROLVAR KEE
13. 3 Subroutine statement After the call to INITBLOCK routine SUBR_STMT inserts the subprogram name in the symbol table with type wow and level 4 The symbol table is updated by a call to FEXTNAME Then it calls the procedure to process the dummy arguments 1 7 4 Function statement Procedure FUNC STMT calls INITBLOCK to initialize a new block gets the type of the function if this is specifically indicated gets its size modification if specified inserts the function name in the symbol table indicating its type size and address level 4 displacement 0 and processes its dummy arguments by calling procedure DUMMY PROCESSING The return value of complex functions are not returned in displacement 0 of the type M memory at level 4 because 2 separate values have to be returned Instead space is allocated for it after the space reserved for the function parameters on the level of the function in type M memory The address of this space is the return value of the function and so an indirect reference is needed in order to access the complex returned value of the function For this reason such functions are declared internally as being of type address 7 7 5 Code generation Code for the head of the new program unit is generated in procedure BLKCODE GENERATION This procedure is called by global procedure Brock after all the declarations of the program unit have been processed This is necessary because all the code for the statement functions mu
14. 32 3 2 Error handling UFORT always checks the validity of a program construct before it operates on it In this way it safeguards itself from execution errors during compilation It distinguishes between two kinds of errors 1 Errors discovered while scanning a program statement UFORT will stop processing the statement at the point where the error is discovered The error message is output with printed under the word that causes the error At most one error message will thus be output for a single statement In some cases UFORT will try to generate extra dummy U Code to make the code already generated for the statement acceptable by the U Code translator UFORT will continue to parse and generate code for the rest of the statements in the user program 2 Errors discovered while processing an internal structure of the compiler For this type of error called SPECIAL ERROR in the compiler the error message is printed with a name that tells from where the error originates The recovery procedure may involve deleting the trouble causing element or altering its contents to make it compatible with the rest of the program Such actions are invisible to the user To enable the features of 1 the statement processing procedures in the compiler always use the global lexeme pointer LXC as index while scanning a statement The error routine will print under the word that LXC points to Since different parts of a statement are usually processe
15. ALLOCATION which indicates if the storage allocation of the variables declared in the program unit has occurred and HAS RETURN which indicates if a RETURN statement for the program unit has been encountered 5 It reinitializes the displacement pointers for the level of the program unit 6 It initializes the global variabie 1IFDEST to indicate that no logical IF statement is being processed 17 2 Processing dummy arguments Procedure pummy processine scans the parameters of a subroutine or a function allocating space for them and inserting their names levels always 4 addresses and an indication that they are dummy arguments in the symbol table 58 Subroutine and Function Statements 172 In allocating space for the dummy arguments in the level of the program unit two memory types type R registers and M main memory are available The maximum number of type R memory available for parameters is set by the constant MAxPREGS If the number of dummy arguments exceeds MAXPREGS the remaining parameters are allocated in type M memory Unused space of type R within the range specified by maxprecs is available for use as temporary locations The constant MAxPREGS is never greater than MAXREGS See Section 13 Eight quarter words of type M memory are always reserved starting at address O for the return value of a U Code procedure Dummy arguments to muitipie entry subprograms are processed in a different way See Section 18 17
16. Code for the S 1 Project 5 1 project document PAIL 6 August 1979 GWa78 Erik J Gilbert and David W Wall Specification for Run time Support for Pascal S I project document PRUN 0 20MAR78 Gri71 David Gries Compiler Construction for Digital Computers John Wiley and Sons 197 1 pp 304 3 12 HiN80 Bruce Hitson and Peter Nye Run time Specification for a Pascal U Code System S I project document PRUN 1 Dec 1979 JeW75 Jensen and N Wirth Pascal User Manual and Report Springer Verlag New York 1975 KeW79 Arthur Keller and Gio Wiederhold S i intermediate Loader Format and S 1 Linker S I project document LDI 8 amp SLIM O Dec 1979 NAJ75 Nori U Amman Jensen et al Pascal Compiler mplementation Notes ETH Zurich 1975 66 Elliott I Organick A Fortran IV Primer Addison Wesiey 1966 p 48 88 Ref erences P5i79 Daniel R Perkins and Richard L Sites Univeral P Code Definition version 0 3 UCSO CS 78 037 July 1979 SPT79 Richard L Sites Daniel R Perkins J Richard Tinting and John B Collings Machine independent Pascal Optimizer Project Final Report UCSO CS 79 038 Nov 1979 71870 Gio Wiederhold and Gary Breitbard A Method for increasing The M odularity of Large System IEEE Computer Vol 3 no 2 March April 1970 page 30 22180 Polle Zellweger Code Generator and Optimizer 5 1 project document SOPADOPE 2 Jan 80
17. Equivalence declaration Procedure EQUIVALDECL scans and processes EQUIVALENCE declarations This procedure builds the list of equivalence groups and it also builds the circular lists of equivalenced variables that form the equivalence groups The list of equivalence groups is formed with EQGROUP records and the lists of equivalenced variables are formed with EQLIST records EQGROUP PACKED RECORD LOW HIGH INTEGER STORE THE LOWER AND HIGHER BOUNDS OF THE EQUIVALENCE GROUP LEADER EQLIST e POINTS TO FIRST ELEMENT IN LIST OF EQUIVALENCE VARIABLES THAT FORM 6ROUP NEXT QGROUP POINTS TO NEXT GROUP ALLOCATED TRUE IF THE 6ROUP HAS ALREADY BEEN ALLOCATED IN MEMORY 6 MAS INIT HAS ONE VARIABLE INITIALIZED HAS COMMON BOOLEAN TRUE WHEN THIS GROUP HAS A COMMON ELEMENT 4 END EQLIST RECORD STPTR SYMBOL 34 Processing of Declarations 8 6 e POINT TO SYMBOL TABLE ENTRY OF EQUIVALENCEO VAR DIMENSION ARRAYC1 MAXDOIM OF INTEGER USED TO STORE THE COORDINATES OF ARRAY ELEMENT EQU IVALENCED OFFSET INTEGER OFFSET OF THE ELEMENT WITH RESPECT TO THE LEADER OF THE LIST NEXT EQL IST NEXT IN THE LIST END THIS LIST IS USED TO STORE THE VARIABLES THAT ARE EQUIVALENCED IN ONE EQUIVALENCE GROUP For each equivalence group procedure EQUIVALDECL calls procedure EQUIVARLIST This procedure gets the names of the variables that form the group inserts the
18. FORMAT cannot be used as the name of a variable Blanks are skipped everywhere except in identifiers numbers and key words The syntax for lexemes is described below using Wirth s variant of BNF lexeme special symbol dot word number Hollerith identifier special symbo 4 on x ist pm ge ig t net amp it Maan en i n 128 men y nyu mae do t uor d LE b LT GE de ae GT EQ AND 0R C NOT FALSE TRUE number mantissa exponent mantissa digit string digit string digit string digi t string s digit digit exponent 0 digit string Holieri th digit string character character identifier 2letter letterjdigit 22 5 6 Statement Classifier Once a statement has been read in by LEXER it is determined to be one of the following types by procedure ctassiry STATEMENT CLASS XNONE XARITH XASSIGN XLOGICALIF XARITHIF XGOTO XCALL XRETURN XEND XPRINT XBLOCKOATA XFORMAT XSET XOPEN XCONTINUE XSTOP XPAUSE XDO XREAD XWRITE XREWIND XBACKSPACE XENDF ILE XEXTERNALFUNC XSUBROUTINE XENTRY XD IMENSION XCOMMON XEQUIVALENCE XIMPLICIT XEXTERNAL XLOG ICAL XINTEGER XCOMPLEX XREAL XDOUBLE XOATA XINTERNALFUNC CLASSIFY first checks to see if the statement is an assignment statemen
19. Output always goes to the Pascal standard file OUTPUT Here are some examples PRINT THE ANSWER IS 2 result THE ANSWER IS 4 8 PRINT THE ANSWER IS result THE ANSWER IS 4 0 PAINT Xx2 PRINT THE ANSWER 1S 28 2 10 result THE ANSWER IS 4 8 COMPLEX 8 x result THE ANSWER IS 2 0 8 0 PRINT THE ANSWER IS Xx 2 8 18 PRINT 2 THE ANSWER 15 2 result THE ANSWER IS 4 0 2 11 Miscellaneous DO statement An integer expression may be used as the lower bound upper bound or step amount The control variable must not be an array element The default step size is 1 Negative step sizes are allowed In the case that the upper bound or step size is an integer variable if a change is made to the value of the variable during execution of the loop the upper bound or step size is changed accordingly Jumping into the range of a DO loop including the terminal statement from outside the DO range is allowed The control variable assumes the value it has at the time of the jump If the control variable is not initialized no assumption should be made as to the value of the variable A DO loop cannot be closed by a FORMAT statement 16 User s Gu ide 2 11 Use of inte ger variables as abel variables No distinction is made between integer variables and label variables Le the usage of an integer variable is not restricted with regard to whether it has assumed its value by regular integer assignmen
20. P Code there are a number of static levels each of which may have one or more procedures associated with it Each procedure owns a set of local variables When a procedure is entered space for its variables is allocated On exit the space is deallocated Thus the values of all the local variables of a procedure are undefined when that procedure is entered In common Fortran implementation however ail of the variables of each subroutrne are own variables that is their values remain the same between the end of one invocation of a subroutine and the beginning of the next Hence space for ail of these variables must have been allocated at the beginning of program execution even though some of them may only be accessed when certain subroutines are entered In U Code terms this means that ail variables in a Fortran program must be on some level that is lower than or the same as the level of the main program If both the common and regular variables are on the same level the address of any variable following those declared to be in a common area cannot be definitely determined until the size of that common area is known To solve this problem the size of each common area except the biank common is restricted to the space that it occupies the first time it is declared in a program unit The fixed space can be explicitly set using the CsiZ option The size of the blank common area is unrestricted by assigning to it its own storage level A storage l
21. TYPEOf THE FUNCTION IF SUBROUTINE THIS FIELD NOT USED NAME THENAME NUMOFARG INTEGER NUMBEROF ARGUMENTS 1 IF NO INFO END and accessed by the routine FEXTNAME PROCEDURE FEXTNAME VAR EPOINTER POINTEXTNAME EXNAME THENAME EXTYPEEXPLICIT BOOLEAN TRUE IF EXPLICIT TYPE IN SUBPROGRAM HEADING EXTYPE OATATWE NONE IF NO INFO 30 Symbol Tables 7 6 EXFUNCSUBR FUNCTYPE NOTEXTERNAL IF NO INFO EXDEFINED EXCALLED BOOLEAN FALSE IF NO INFO NUMBER is filled automatically inside CLEAREXTNAME immediately after the external name table is created in such a way that each external program unit is associated with a different segment number FEXTNAME is designed both for asserting and checking This is because it is not sure when the mode is assertion and when it is checking since the position of a subprogram bears no relationship to where its calls originate FEXTNAME checks the STYPE and XFUNCSUBR fields if the external symbol is either previously called or defined Otherwise it goes ahead to assert STYPE and XFUNCSUBR to the values given in the parameters When FEXTNAME is called from a parameter EXTYPE is to be the STYPE Value of the symbol s entry in the symbol table even if its type is implicit since the type in the external table is fixed after the first call When FEXTNAME is called from b or c parameter EXTYPEEXPLICIT indicates whether typing is explicit in the FUNCTION
22. USERFUNC 15 3 Type checking and error recovery inside ARITH UFORT conducts full type checking and always emits explicit conversion code whenever type coercions are required This eliminates the need to look out for implicit type conversions in any translator or interpretor of U Code generated from UFORT The checks for type compatibility involving expressions are done using the procedures MATCHTYPE Or FITTYPE which are called on different occasions MATCHTYPE is used when the types of two values are to be matched performing coercion on one of them if necessary Coercions are always done in the direction of integer values to real values to complex values For example if one of the values IS a real and the other is a complex the real value is converted to its corresponding complex number and not the other way round FITTYPE is used when the type of a value is to be fitted to a desired result type as in the case of an assignment to a variabie In this case any coercion performed will be the conversion of the value to the result type An additional procedure MATCHSIZE is called from both maTCHTvPE and FITTYPE it is for checking the correspondence of sizes after the types have been matched If size incompatibility occurs the or CVT2 instructions will be generated for size coercions with warnings output at the same time UFORT always attempts to generate correct U Code even if an error occurs In the case of an arithmetic expres
23. Y1 x2 XI e Y2 load X22822 Y2 2 back Y1 x2 XI Y2 X21 2 Y2 a2 store imaginary part of final result store real part of final result 55 56 Complex Number Arithmetic 16 4 16 4 Complex valued functions Since U Code does not have multiple return values for functions complex valued functions in Fortran are compiled into U Code functions that return the addresses of their complex results The responsibility of loading the complex result of a function on the stack then rests on the callee The following illustrates how a callee does the call to a complex valued function Fortran CFUNC C1 U Code MST 4 LOA M 1 576 72 lead address of PAR A MO 0 36 CUP 76 CFUNCO76 1 1 11 to complex valued function OUP duplicate address returned 1100 R 0 36 load real part SWP R A ILOO R 36 36 load imaginary part STR R M 1 540 36 sstore imaginary part STR R M 1 504 36 tore real part 17 57 17 Subroutine and Function Statements Procedures SUBR_STMT and FUNC STMT process the subroutine and function statements Both of them initiate a new program unit by calling procedure rNiTBLOCK The global flag SUBR FUNC is set to TRUE whenever the compiler is processing a subprogram and the global pointer SEGPTR points to the symbol table entry of the subprogram name All the parameters of a function or a subroutine are passed by reference thus each is allocated 4 quarter words of storage the
24. about the FoRMAT statements in the various program units is pointed to by the global variable HEADFORMTLST The structure of the FORMTLIST record is FORMTLIST RECORO PTRFMTSTR FORMTSTR POINTER TO THE FORMAT STRING LIST NEXT FORMTLIST AOORESS LEVEL INTEGER ADDRESS WHERE FORMAT STRING IS STORED O END The FORMAT string specification is also saved in a list formed with records called FORMTSTR with the structure FORMATSTRING PACKED ARRAY 1 MAXCHARINLCA OF CHAR FORMTSTR RECORD STR FORMATSTRING FORMAT STRING NEXT FORMTSTR END The purpose of this second list is to save space Only increments of MAXCHARINLCA units of storage need be allocated by the complier The constant MAXCHARINLCA defines the limit on the length of the literal allowed in the U Code LCA Instruction Currently it is 64 Thus another advantage of this scheme is that the characters on each record can be loaded by a single LCA instruction 25 1 The FORMAT statement Procedure scans and processes a FORMAT statement It gets the label of the FORMAT statement in character form and inserts it into the symbol table indicating that 1t IS a FORMAT label An address is allocated to the Format label which hoids the address of the location where the FORMAT string specification is stored A new entry in the list of formats FORMTLIST is created and the following information IS obtained and inserted a the address an
25. are handled differently inside LOADVAR and srorevar as each variable requires the loading or storing to be performed twice Variables are accessed differently as to whether it is a regular variable a variable passed as a parameter or an array element For the last two cases it is necessary to access the variables indirectly by loading the address on the stack first and then doing a load or store Indirect The loading of the address is done by LOAD_VAR_ ADDR LOAD VAR ADDR is passed a pointer to the symbol table for the variable in question If the variable is not an array variabie it loads its address If the variable is an array it loads its address and then calls LOAD ARRAY ELEMENT which reads the subscripts and generates code to calculate the offset The offset of an array element is computed by a loop which iterates according to the number of subscripts specified For an array A of dimensions bl bo PE bn the offset for the element A ij i9 in is given by ip I in 1 ig 10 GS ple xb kba kbo xb If the first m dimensions of the array have constant bounds the above algorithm can be made more efficient by accumulating the decrements by l of the 2nd to m 1 th subscripts into one single Offset adjustment As an illustration suppose the array A above has all constant dimensions Then the offset computation can be compressed into Ip Goa in ptig kbp C 4 y eb 9 1 1
26. area Additional quarter words are inserted as necessary to align half words on half word boundaries single words on single word boundaries and double words on double word boundaries Thus a quarter word variable followed by a single word variable in a common area would require two full words of storage 2 5 Init ializing variables Variables can be initialized in both pata and type declaration statements The type declaration statement with initiaiitations and DATA statement are formed as follows typexs axs ky 0 2 2 oe 2 89 k3 x3 DATA 1 dlkg xy elke cos h kgl xo where type 1S INTEGER REAL LOGICAL DOUBLE PRECISION or COMPLEX X81 X95 are optional each s representing one of the permissible length specifications for its associated type a b Z are variable or array names ky j ko give dimension information for arrays in declaration statements and subscript information for array elements in DATA statements In a declaration statement this always specifies the entire array If absent for an array in a DATA statement short form specification for the entire array is impiied 1 2 are constants lists of constants xo x3 optional in a declarative statement and are used to specify initial values for single preceding variables and 10 User s Gu ide 2 5 array names In a parA statement they are not optional and specify initial v
27. by an then the lexeme is a Hollerith string If it is followed by a dot then t may be either a real or an integer followed by a dot word as in 33 EQ X The procedure FINDWORD is called to get the character string if it is a dot word If this is the case it results in two lexemes being processed in a single pass the integer and the dot word If the dot is not followed by a letter DIGITSTRING is called again to find the last digit of the fraction of the real number and then FINDEXPONENT to get the exponent If the first digit string is followed by neither a dot nor an H then the lexeme is an integer If the first character is a dot then the lexeme is either a dot word or a real again FINDWORD and FINDEXPONENT are used If the first character is a single quote then the lexeme is a string When an embedded quote occurs in a string constant one of the two quotes is deleted and the string content to the left is shifted right by one position This is because after LEXER the compiler will use the information in the array LEXEME to determine the extent of the string constant If the first character is a letter then the lexeme is an identifier and characters are skipped until the next non alphanumeric letter is read in The identifier FORMAT is recognized as a reserved word and it is processed as a special case The FORMAT specification including both surrounding parentheses is processed as a string constant Consequently the name
28. corresponds to the order in which they are allocated The structure of each node is TEMPLOCNOOE RECORD Loc SIZE INTEGER MTYPE CHAR FREE BOOLEAN NEXT fTEMPLOCNOOE END 13 Temporary storage management 47 GETTEMP first searches the list to see if there is a temporary location of the appropriate size that has already been claimed as a temporary location but is now free The search starts from the beginning of the list so that any type R memory location is found first If there is none it claims a new one by incrementing the displacement variable of the appropriate level and memory type by an amount which is the size of the location needed plus any extra it needs to assure that the location starts on a single word boundary The new node to remember this temporary location is added to the list RELTEMP merely searches through the list until it finds the specified location then sets FREE to TRUE TEMPLOCHEAD is reset to NIL before the start of a new program unit or statement function since the temporary locations previously allocated no longer apply 48 14 14 Loading and storing variables The procedures used to generate code to load and store variables are LOAD_ VAR LOAD VAR ADDR toap array eremenr and STORE VAR To load the value of a variable LoAD VAR is called To store a value in a variable store VAR is called then the value is loaded usually by ARITH and then STOREVAR is called Complex variables
29. is found At the end of the I O statement when procedure WRITTRM or READTRM is called NEXTFIELD has to be called the last time to bring the scan to the next I O field or the end of the FORMAT string Here FIELDFOUND is first set to be false before calling NEXTFIELD so that no backing up is done at the end of the FORMAT string 2 7 3 I O management An I O buffer of fixed length currently 256 characters is maintained This stores the next output line being built or the next input line from the input file In output the buffer is written to the output file when a new output line is specified In input the next line from the input file is read to the buffer when the next input line is specified The length of the output or input line is variable If the output line exceeds the length of the I O buffer a next output line 15 automatically created to accomodate the extra characters if the input line exceeds the length of the I O buffer the input line still assumes its length but the characters to the right of the line limit that cannot be accomodated within the buffer are ail taken to be the blank character 27 4 Internal external correspondence of data values In standard Fortran the type of conversion in formatted I O is determined by the field type in the FORMAT s amp ring and not according to the type of the variable in the READ or WRITE statement The same content bit pattern of the location in I O is to be treated as different typ
30. not by the type of the variable being initialized Only the size of the variable affects the initialization 2 The initialization of arrays is done in storage order In a declarative statement each list of constants must correspond in number to the preceding variable or array In a DATA statement the correspondence is ta the total number of variables and array elements specified in the preceding list taking account of loop iterations if any If extra constants are given they are ignored If not enough constants are given the extra variables or array elements are not initialized In both cases warnings are given A complex variabie is taken as two reai variables and they correspond to two initialization constants The parentheses in specifying a complex constant are optional 3 A replication factor can be used to specify how many times the constant following tht asterisk is to be repeated in the initializing process The syntax is rep x val where rep is the replication factor and val is the constant value E g 5x3 2 means that the constant vaiue 3 2 is going to be used 5 times 4 Function names or subprogram parameters cannot be initialized 5 Arrays must be dimensioned before initialization in a DATA statement or in a type 2 5 2 User s Guide 11 declaration statement Also any type declaration for a variable in para statement must appear before the para statement 6 If the initializatron of a vari
31. the global level 1 memory Is allocated to store the final value and the address of this location IS passed For subprogram names a double word is allocated in the global memory in which the level and address of the U Code procedure generated using the LDP instruction is stored and the address of the double word is passed For a dummy argument as parameter which includes a subprogram name argument to be passed on the address as stored in the parameter location IS passed 7 9 2 Function call Procedure USERFUNC is used to scan and process the arguments of a function or subroutine call and to generate the code that actually does the call This procedure counts the arguments with procedure cOUNT arcumeNTs generates MST U Code instruction that indicates the beginning and size of the stack for the call processes the arguments with procedure PROCESS ARGUMENTS and generates the code for the call The segment number for the CUP instruction is obtained from field SEGMENNUM of the symbol table for call to a statement function and from the field NUMBER of the external table for call to a subroutine or an external function Procedure USERFUNC updates the external table when an external subprogram is called 19 3 Subroutine call Procedure CALL sTATemenr scans and processes a subroutine call It gets and Inserts the name of the subroutine into the symbol table The data type for the subroutine is set to NONE explicitly after its insertion in th
32. the various subprograms An entry in the external name table implies the existence of a subprogram with that name A symbol can be in the ExTNAME table and in the SYMBOL table at the same time when the external subprogram name is referenced in the program unit or there is an internal variable or statement function name which happens to have the same name as another subprogram When processing a subprogram the subprogram name is also in both tables and in the case of function subprograms the name is used internally as a function variabie An identifier declared EXTERNAL is not necessarily entered in the external name table See Section 8 7 A symbol is inserted in the external table when it is called defined or passed as a subprogram name parameter This occurs in a procedure USERFUNC which processes calls b the FUNCTION statement processor c the SUBROUTINE statement processor d the ENTRY statement processor and e procedure PROCESS ARGUMENTS The table is made up of records of type EXTNAME EXTNAME PACKED RECORD LSON RSON tEXTNAME NUHBER INTEGER SEGMENT NUMBER ASSOCIATED TO THIS SEGMENT NAME ENTRY XFUNCSUBR FUNCTWE MUST BE ONE OF EXTFUNC EXTSUBR NOTEXTERNAL e TYPEEXPL ICIT TRUE IF EXPLICIT TYPE IN SUBPROGRAM HEADING IS DEFINED SUBPROGRAM BLOCK EXISTS FOR IT IS CALLED e INVOKED AT LEAST ONCE IS PASSED BOOLEAN HAS BEEN PASSEO AS PARAHETER STYPE POIMTOEFTYPE THE
33. to minimize the height of the U Code stack In the following the methods for complex number arithmetic are illustrated with examples Note that some manipulations on the first operand are performed on seeing the operator and before processing the second operand In the description the two complex operands will be referred to as X 1 1 and X2 Y2 respectively 16 1 Addition and subtraction Fortran c z Cl c U Code 100 M 1 576 36 sload XI 100 M 1 612 36 load Yl SWP R R swap and Yl LOO R M 1 648 36 lead X2 100 M 1 684 36 load Y2 STR R M 74 72 36 store Y2 temporarily ADO R Xl x2 SWP R R swap Yl and XI X2 LOO R M 74 72 36 load Y2 back ADD R Y2 STR R M 1 540 36 store Y2 STR R M 1 504 36 stors XI X2 Subtraction is similar and is not repeated 16 2 Multiplication Fortran c a C2 U Code 100 R 1 576 36 oad LOO R M 1 612 36 sload Yl SWP R R swap Xl and Yl NSTR R M 74 72 36 store XI temporarily SWP R R swap Yland XI DUP R 1 icate Y1 LOO R M74 72 36 load back LOO R M1 648 36 load X2 LOD R M1 664 36 load Y2 STR R M 74 108 36 sstore Y2 temporarily 16 2 NSTR R MPY R SUP R 100 R MPY SUB R SWP R 100 R MPY R STR R SWP R 100 R MPY R 100 R ADO R STR R STR R 16 3 Division Fortrsn U Code C Cl LOO R LOO R SWP R NSTR R SWP R OUP R 100 R 100 R 100 R STR R NSTR R MPY R SWP 100 x
34. variable in the list of equivalence groups If the variable appears two times in the same equivalence group the second one is deleted If the variable appears in two different groups the first group is deleted and appended to the beginning of the second one In this second group the variables that have already been processed at the moment the double equivalence is found have their offsets adjusted in accordance to the new leader of the group The doubly equivalenced variable is skipped in the second list and the variables not yet processed will still be at the end of the enlarged group being processed 7 1 2 Allocating space for common areas Once all the offsets for the equivalenced variables have been computed and all necessary mergings have been performed space for the common variables is allocated The address where the common area begins is given in the STADDR field in the common name table It is 1 if no space has been allocated for that area in any previously compiled program unit and in this case STADDR is set to the next available address in the general common area If space has already been allocated for the common area STADDR gives the address where the area was previously allocated For the blank common variables allocation always starts with the first address in the level for the blank common area If common variable is also equivalenced procedure CHECK kxrENsioN zs called This checks for invalid extensions to the left of a c
35. within boundary THEN DONE TRUE END ELSE DONE TRUE Input digits are always decoded into an integer variable even if the digits belong to the mantissa of a real number 86 The Fortran I O Run time Package 27 6 To check for overflow error and to ensure that any representable integer can be input the scheme used is Given MAXINT 34359738367 KEEPNUM 0 WHILE NXTCHAR in 8 9 DO BEGIN IF KEEPNUM gt 3435973836 OR ININT 3435973836 AND NXTCHAR IN 8 9 1 THEN over f ow error ELSE KEEPNUM KEEPNUM 10 ORD NXTCHAR ORD 8 get NXTCHAR END In reading real numbers the input is decoded into the integer variable KEEPNUM which keeps the mantissa and integer variable E which keeps the exponent such that KEEPNUM xx E gives the correct real value In this case too many digits in the mantissa should not cause overflow if still representable as a real number Here the decoding part of the WHILE loop that processes the digits in the mantissa is IF KEEPNUM gt 3435973836 OR KEEPNUM 3435973836 AND NXTCHAR IN 8 9 1 THENE E 1 ELSE KEEPNUM KEEPNUM x 10 ORD NXTCHAR ORD 8 If current digit is after the decimal then increment of E above is not necessary In practice the IF condition above can be replaced by just IF KEEPNUM gt 3435973836 for greater efficiency without much loss of accuracy 87 References AKe80 J J Allchin and A
36. x OXECX XXE OxXorkr EZ x X 74 74 74 74 74 74 72 36 108 36 72 36 72 36 108 36 72 36 1 540 36 1 504 36 C2 1 576 36 1 612 36 74 74 72 36 72 36 1 648 36 1 684 36 74 74 74 74 74 74 74 74 74 74 74 108 36 72 36 108 38 72 36 108 36 144 36 72 36 72 36 108 36 72 36 144 36 1 540 36 1 504 36 Complex Number Arithmetic store X2 temporarily 1 x2 swap Yl XI X2 load Y2 back Yl Ye 3 X1 t 2 sswap Xl e 2 Yl e Y2 sload X2 back Yl x2 store 2 X2 temporarily swap XI and X2 Y1 v2 load Y2 back Xl1 5 Y2 load Yl X2 back Xl e Y2 X2 sstore imaginary part of result stora real part of result load XI load Yl swap Xl and Yl store Xl temporarily swap Yl and duplicate Y1 ead back load X2 load Y2 store Y2 temporarily store X2 temporarily Xl x2 swap Yl and X2 load Y2 back Yl Y2 3 X1 X2 Y1 5 Y2 sload X2 back 2 2 load Y2 back Y2 2 X2 2 Y2 2 store X2 2 Y2 2 temporarily X1 X2 Y15 2 X2 2 Y2 2 swap Yl and real part of final result load X2 back x2 sstore Yl X2 temporarily swap Xl and real part of final result load Y2 back 3X1 e Y2 z Y2 load Yl e X2 back
37. 0 36 CUP 29 REAO0TO 29 1 0 code to check value of trap execution If in Read and Write Statements 26 3 store sire of af array C MAXPRI NTARRAY load initial value in COMPRINTARRAY labe for beginning of generated loop load address of array element load size of data value sload coded type call data transmission routine load control variable from CONPRI NTARRAY increment it update it load it back lead final value from MAXPRI NTARRAY compare jump back if smaller simplied 00 loop ssave initial value in control variable sload address of current element of P sload size of data value lead coded type call data transmission routine load control variable increment control variable update control variable load back control variable lead termination value compare sjump back if not reached 1 0 termination sload address of indicator call to I O termination routine indi cator returned and error 27 81 27 The Fortran I O Run time Package The Fortran I O run time routines are used for the execution of READ and write statements These routines are written in Pascal and make use of the lowest level Pascal I O run time routines The I O routines require the double precision facility in Pascal to properly process the I O of doubie precision variables in Fortran When this facility is not available double precision I O may be processed only up to the accuracy allowed by sin
38. 1 The last adjustment term is computed during compile time when processing the dimension declaration of the array In the following example the array has both constant and variable dimensions 14 1 Loading and storing variables 14 1 Example of indirect load and store Fortran U Code SUBROUTIHE X 1 DIMENSION J 3 4 1 J 2 3 5 I RETURN END X0000076 EMT P 4 76 1 0 LEX 1 LEX 72 LEX 73 A 76 0 36 LOA 1504 0 sload address of array J LOC LDC LDC LDC MPY ADO LDC MPY ADO DEC 16 1 XA 36 up to here load address of 3 2 3 4 LOO A R 76 0 36 iload address stored at address of I 1100 J 0 36 load content of address just loaded ISTR J 0 36 store value at address 2nd on stack RET ihds is from the RETURN statement RET thds is always generated DEF R 36 DEF M 72 END X0000076 AAD Pow gt 36 3 ce ce occ 49 50 15 15 Expression Evaluation Expression evaluation is done by recursive descent Although this is somewhat less efficient than using operator precedence it 1s cleaner and makes it easier to deal with parentheses Expression evaluation procedures are divided into logical expression procedures and arithmetic expression procedures Logical expressions are expressions involving logical operators such as AND They may include arithmetic expressions if relational operators such as EQ occur inside the logical expression Ari
39. 2613 7 FORMaT string s contents as it scans past them The value is transmitted according to the field description which also implies the type of the data value taking into account the size of the variable given as the 2nd parameter If I O is unformatted then the 3rd parameter type is taken into account to determine the desired conversion 26 1 4 Termination These calls finish the transmission for each READ WRITE statement release buffers and return an error code Any further I O has to begin with initialization calls READT 29 WRI TT026 Parameter address of indicator The FORMAT string is scanned until the end or the next I O field if it occurs first In output the I O buffer is written out The indicator is a quarter word in the global memory and is set to one of the following 0 O perceived correct 1 1 0 error detected 2 I O end of file detected 26 1 5 Rewind Lastly calito REWIN032 Parameter file number is generated at mEwiwp or oPEN statement in the Fortran source program This causes a reset if the file has been reset before or a rewrite if the file has been rewritten before Otherwise no operation is performed This enables the user to start at the beginning of the file again for the same operation on the file 26 2 Compiler routines Procedure ro srArEwENT scans and processes the READ WRITE statements Parameter READING to this procedure indicates the kind of I O statement being TRUE for a
40. CDEFGHI DATA E ONEISPORE TWO THREE FOUR FIVE SIX SEVEN DATA F 3x MOM Initializations performed VARIABLE VALUE M ABCD A 1 ABCD A 2 EFGH D 1 unintialized 0 2 AB 0 3 CD C 1 ABCD C 2 EFGH C 3 T 12 User s Guide 253 1 E 1 2 TWO earlier E 2 contained SMORE but this was overwritten with the next element in the list 3 THRE E 4 FOUR 5 FIVE E 6 SIX E 7 SEVE E 8 N sno more elements in list thus not overwritten F 1 MOM F 2 MOM F 3 MOM 2 6 Subprograms The restrictions with regard to subprograms are A statement function must have at least one argument A function with no parameter must be declared EXTERNAL in each program unit in which it is referenced Otherwise the function name is taken as a variable name Parameters to Subprograms All parameters are passed by reference including array elements used as arguments Thus their values can be altered as the result of a subprogram call External Subprograms Currently all program units used in a program are compiled at the same time as the main program separately compiled subroutines or functions have not yet been Implemented 2 7 Subprogram names as parameters Subprogram names can be passed as parameters in a call to another subprogram and they can be passed onwards in another call in the subpr
41. EFIELD prints a real number in an E formatted field d procedure PRGFIELD prints a real number 1n an G formatted field e procedure PRLFIELD prints a boolean in an L formatted field f procedure PRAFIELD prints the contents of a variable in an A formatted field 3 procedures for formatted input conversions of data values a procedure REIFIELD reads in an integer in an I formatted field b procedure reads in a real number in an E F or G formatted field the effect being defined as identical c procedure RELFIELD reads in a boolean from an L formatted field d procedure REAFIELD reads in the characters in an A formatted field to a variable 82 The Fortran I O Run time Package 27 1 6 procedures for unformatted input conversions of data values a procedure uweiwriweur scans and inputs an integer b procedure UNFREALINPUT scans and inputs a real number c procedure UNFBOOLINPUT scans and inputs a booiean 7 procedures called externally a procedure WRITINI U Code name is READ 026 b procedure WRITTRM WR T1 823 c procedure WRITVAL WRI TV 2S d procedure READINKREAD 826 e procedure READTRM REAOT827 f procedure READVAL READY828 g procedure FILINI FILE T0923 h procedure REWIND REW N 3 In writva and READVAL for formatted O 3 NEXTFIELD is first called followed by the appropriate procedure in 4 or 5 For unformatted I O in WRITVA
42. ENT AMPE RSANO COLON SEMICOLON LESSS IGH BIGGERSIGN QUESMARK ATSYM LSQBRACKET RSQBRACKET BACKSLASH CARET EOS end of statement NON none of the above DRA x LUC v Awe 6 4 3 Reading in a statement When LEXER is called LEXSTRING is cleared by putting In blanks It then invokes the procedure GETSTATEMENT to load the characters of the next statement into LEXSTRING It assumes that the first six characters of the next line are already in the array COL1TOS If the first letter is then the line 1s a comment line COLiTOe6 is printed in the listing file and the comment itself is read into the listing file procedure SKIPLINE The variable LINENO is used to keep track of the number of lines that are read in As soon as a non comment line is read in this may be a blank line the global variable LINENUMBER which always contains the line number of the first line of the current statement IS set to LINENO If the end of file has been reached this is indicated by setting LEXSTRLENGTH to 0 COL1TOS is copied to both the listing file and LEXSTRING The rest of the statement is read in putting each character in both the listing file and LEXSTRING until the end of the statement 1s encountered If comment lines occur they are skipped over as previously Continuation lines are recognized and appended To determine this GETSTATEMENT must always look ahead to the next 6 characters of the next line Thus at the end of GETSTATEMENT
43. G complix complix inline exponenti a7 EXP rea 1 real CSP EXP DEXP doubl doubl CSP EXP CEXP complix complix CUP natural log ALOG real real CSP LOG DLOG doubl doubl CSP LOG CLOG compl x complix CUP common 1 og ALOG1O real real CUP 0 0610 doubl doubl CUP sin SIN real real CSP SIN DSI doubl doubl CSP SIN CSIN complx complx CUP 66 cos tanh IBM Square root arctan arctan al a2 Subroutine and Function Calls cos real Dcos doubl CCOS compl x TANH real DTANH doubl SQRT real DSQRT doubl CSQRT complx ATAN real DTAN doubl ATAN2 real DTAN2 doubl real doubl compl x real doubl real doubl compl x real doubl real doubl CSP cos CSP cos CUP CUP CUP CSP SQT CSP SQT CUP CSP TAN CSP TAN CUP CUP 19 4 20 67_ 20 Statement Functions Procedure STMT_FUNCTION scans and processes a statement function The dummy arguments of a statement function are local to it They have to be present in the symbol table when processing the function definition and they must disappear after the declaration IS processed if their names are the same as other variable names used in that program unit they must be recovered in the symbol table In order to do this it is necessary to save the symbol table entries the dummy arguments replace This is done by forming a list of records called DUMMY LIST The fields saved in these records are those in the symbol table that can possibly be altered while processing the state
44. IMPLICIT statement The following precisions are possible LOGICAL quarter word half word single word default and double word INTEGER quarter word half word single word default and double word REAL half word single word default and double word COMPLEX two single words default and two double words Precisions are specified in quarter words as in IBM Fortran INTEGERX1AAA LOG I CAL x8 BBB COMPLEX CCC COMPLEX 16 FUNCTION DOO DOUBLE PRECISION EEE REALx8 EEE Automatic conversion occurs whenever necessary between and among any precisions of the integer real and complex types Real numbers are converted to integers by truncation Conversion to complex number is done by adding a zero imaginary part When a complex number is converted to real or integer its imaginary part is discarded Integer variables used as the control variable of a DO statement for storing a label or for storing a device number for use in a READ WRITE or REWIND statement must be of single precision 2 3 2 Constants The upper limits allowed for integer values are 255 for quarter word integers 13 1071 for half word integers 34359738367 for full word integers and 73786976294838206463 for double word integers The lower limits are 1 less then the negatives of these numbers The upper and lower limits for reals 1 70141 1843E 38 and 1 4693680 0E 39 respectively for all precisions 8 User s Guide 2 3 2 Complex numbers consist
45. Keller FLASH A Language independent Portable File System S I project document Jan 1980 ANS64 American Standard Association X3 4 3 Fortran vs Basic Fortran Comm of the ACM Vol 7 No 10 October 1964 pp 591 625 ANS68 ANSI USA Standard Fortran USA Standards Institute USAS X3 9 1966 New York 1966 ANS71 J Americal National Standards Committee X3J3 Clarification of Fortran standards second report Comm of the ACM Vol 14 No 10 October 1971 pp 628 642 ANS76 American National Standards Committee X3J3 Draft Proposed ANS Fortran Sigplan Notices Voi 11 No 3 March 1976 254 pages Brw68 Gary Y Breitbard and Gio Wlederhoid PL ACME An incremental Compiler for a Subset of PL I information Processing 1968 Proceedings of the 1968 IFIPS Conference Edinburgh North Holland 1969 pages 358 363 Bsn78 Randy Bush UASMINT A U Code Assembler and Interpreter 5 1 project document June 1979 CCN78 F Castaneda Chow P Nye D Sleator and Wiederhold PCFORT A Fortran to P Code Translator CSL Technical Report 160 Stanford University Jan 1979 F1278 Jim Finnel and Polle T Zellweger The S 1 Multi processor OSL Technical Note 142 Stanford University June 1978 G1W77 Erik J Gilbert and David W Wail P Code Intermediate Assembly Language S I project document PAIL 3 18JUL77 GNR78 Phillip Geering Peter Nye Armando Rodriguez and Arthur Samuel S U Code A Universal P
46. L the standard field width is assigned and the appropriate procedure in 4 a c and e is called In READVAL the appropriate procedure in 6 is called Note that the procedures in 4 5 or 6 treat the transmitted data value in double word size WRITVAL will do the necessary shifting for data values of smaller sizes before calling 4 READVAL will do the necessary shifting after calling 5 or 6 PRAFIELD and REAFIELD however are exceptions since the number of transmitted characters is different for variables of different sizes four characters per single word 9 bits for each character These two procedures are called from WRITVAL and READVAL with an extra parameter that gives the size information of the variable 27 2 Processing the FORMAT string The entities allowed in a romwar string are numbers Hoilerith string literal string enclosed in quotes comma slash X the left and right parentheses P and the field specifications for I E F G L A fields Items enclosed in parentheses form a group The number of groups in the same level is not limited but only three leveis of grouping are allowed including the outermost group which is the FORMAT string itself Procedure NEXTFIELD is in the form of a loop which scans and processes one of the above entities each round Two booleans COMMAED and COUNTED keep track of the syntactic information in checking for syntax errors The comma is not mandatory in the FORMAT string in cases where its abs
47. NLEXES generates the LEX instruction at the beginning of each U Code block according to the global array sEGLEV The following two procedures are called from the above U Code generating procedures PRINTLABEL prints a U Code label e g 115 512 U Code generating routines 45 PRINTNAME prints the name of a program unit in U Code form e g PEPE9993 The maximum iength of the name is 5 letters The maximum segment number is 999 Each procedure has its own segment number The global variable SEGNUMBER always contains the segment number that was last allotted 46 13 13 Temporary storage management Temporary locations are used in UFORT in a number of places They are made available for reuse whenever possible New temporary locations are generated only if the existing ones are not free Temporary locations are used in the foilowing cases l In processing complex number arithmetic 2 In different cases connected with complex numbers the assrgnment to a complex variable with an indirect address the relational and bitwise operations on complex operands and the printing of a complex number by the PRINT statement processor 3 In processing the assigned GOTO statement 4 In processing the arithmetic IF statement 3 In processing READ wire of whole arrays 6 In statements when the final value or step value is an expression the temporary locations for these cannot be reused 7 In connection with type co
48. OL POINTER TO SYMBOL TABLE ENTRY OF COMMON ELEMENT NEXT COML IST END The root of the list of common variables for each common area is stored in the field PTRCOMLIST of its entry in the common name table For each common area COMDECL first gets its name and inserts it in the common name table If it is already in the table it obtains the last entry in the common variable list for that area Using this pointer the declared variables in this area are inserted in the order they are declared These variables are also entered in the main symbol table if necessary along with the information that they are in a common area fields s common is set to TRUE and PTRCOM is set to point to the correct entry in the common table Any dimension information of a variable in a common declaration is treated as dimension declaration and this information is obtained with procedure ISARRAY Information about the length and starting address of the common areas is not inserted here but in procedure STORAGE ALLOCATION where the addresses for the common variables are assigned The reason for this is that a variable may be dimensioned in a later statement so there is no way to be sure how much space it will take until all the declarations have been processed The blank common area is called M M internally in the compiler The spaces between the M s make it impossible for any user to use this name as a name for one of its common areas 8 6
49. PS THE NAME OF THE CONTROL VARIABLE OF THIS LOOP CURRENTVAL IS USED TO STEPS FROM STARTVAL TO ENDVAL INSIDE PROCEDURE CONSTRUCT 8 LEVELREC RECORO VARLIST POINTVARREC CONTROLVAR THENAME STARTVAL ENDVAL STEPVAL CURRENTVAL INTEGER PREVIOUS LEVELREC END The recursive algorithm to process a variable list is then as follows Formvarlist 1 Call CONSTRUCT to scan and build the list representation for the variable list 2 Call EXTEND to do the extensions to the initialization list according to the structure just created Construct 1 While not end of variable list a Create a VARREC node b If next item is a loop current node is a loop Create a LEVELREC node pointed to from the VARREC node 1 Enter the loop information to the LEVELREC node 2 Call construct to scan and build the list representation for the variable list pointed to from the LEVELREC node c Else next item is a variable Enter the variable information together with any subscript specification in the VARREC node d Append the VARREC node to the end of the list being built 38 Initialization of Variables 59 3 Extend For each node in the VARREC list do a If current VARREC node is a loop get to the LEVELREC node 1 Initialize CURRENTVAL to STARTVAL 2 While CURRENTVAL lt STEPVAL Call exrenp using the variable list of this loop b Increment CURRENTVAL by the amount given by STEPVAL b El
50. READ statemen t and FALSE for a WRITE statement The general form for the I O statements is READ DEVICE FORMAT 11 st READ DEVICE I ist if unformatted where i i s t is a list of variables that may only include simple variable names array names and array elements OEVICE is the device number and FORMAT may be a FORMAT statement label or an array name 26 2 Read and Write Statements 79 For the I O of arrays when no control variable is explicitly established two temporary locations are obtained These temporary locations pointed to by variables MAXPRINTARRAY and CONPRINTARRAY store the upper bound number of elements in the array and index respectively for the array Procedure 10 STATEMENT gets amp he device number and the FoRMAT specification either a FORMAT statement label or an array name and generates the code to call the run time routines for the initialization of the I O of the current statement the code for data transmission of the variables by calling procedure LIsT PROCESSING and the code to call the routines for the termination of the I O for the statement Procedure LIST PROCESSING processes the variables in an I O statement It is called by procedure 10_ STATEMENT the first time and by itself recursively when an implied DO or another list of variables surrounded by parentheses is found in the list being processed Parameter IN DO IMPLIED indicates if the list of variables being processed belongs to an implie
51. Representation of types The numerous data types which the compiler recognizes are represented in records defined as follows DATACLASS INTEGERCLASS REALCLASS COMPLEXCLASS LOGICALCLASS STRINGCLASS OTHERCLASS POINTDEFTYPE s tDEFTYPE DEFTYPE s RECORD SIZE INTEGER GENTYPE CHAR CASE CLASS DATACLASS OF COMPLEXCLASS COMPPART DEFTYPE END The different data types are represented by pointers to their own individually defined records The pointer variables are named after the type names and they are globally defined and initialized in procedure INITCOMPILER see Section 6 This structure allows easy access to the size U Code type and class of each data type In the case of the types for complex numbers an additional pointer field in this record points to the type of the real and imaginary component parts The data types used in the compiler are LOGICAL 1 LOGICAL2 LOGICAL4 LOGICALS for booleans INT 1 INT2 INT4 INTS for integers RE1 RE2 RE4 RES for rea numbers comp4 COM P8 for complex numbers STRING for string constants FORMATLABEL for labels of FORMAT statements for the data type of subroutines POINTER for addresses the U Code type A SINGCHAR for a single character U Code type C 32 Processing of Declarations 8 1 PROC for procedures the U Code type SINGSET DOUBSET for the U Code set types 8 2 Type specific declarations Procedure T
52. THE FIRST TIME LEVEL ADORESS ING LEVEL FOR THE VARIABLE ADDRESS INTEGER 1 IF NOT YET ESTABLISHED MTYPE CHAR e CHARACTER FOR THE MEMORY TYPE USED LHS TRUE IF VARIABLE WAS GIVEN A VALUE NOT USED FOR EXTERNL EXTSUBR INTRINSTDEXT PARAMPROC EXTFUNC EXCEPT WHEN A FUNCTION VARIABLE 6 USED RHS TRUE IF VARIABLE S VALUE WAS USED NOT USED FOR INTRINSTDEXT FORMATLABEL o S DUMMY TRUE IF DUMMY ARGUMENT S EXPLICIT BOOLEAN e TRUE IF TYPE EXPLICITLY DECLARED CASE S FUNCSUBR FUNCTYPE OF NOTEXTERNAL IF NOT EXPLICITLY ASSERTED INTRINSTOEXT PTRSTO STOFUNCTABLE POINTER TO STANDARD FUNCTION TABLE IF STARDARD FUNCTION NAME STMTFUNC SEGMENNUM SEGMENT NUMBER OF ITS U CODE PROC BLOCK NUMOFARG INTEGER NOTEXTERNAL S1 EQUIVALENCE TRUE IF EQUIVALENCED 2 EQUIVALENCE USED TO INOICATE IF AN EQUIV VARIABLE HAS BEEN PROCESSED IN STORAGE ALLOCATION TO CHECK EOUIVALENCING TWICE S COMMON TRUE IF COMMON VARIABLE INITIALIZED BOOLEAN TRUE IF VARIABLE INITIALIZED FALSE OTHERWISE FOLLOWING FIELOS DO NOT HAVE CORRESPONDING PARAMETER IN PROCEDURE FSYMBOL NUM ELEMENTS INTEGER ONE IF SCALAR ELSE NUMBER OF ELEMENTS IN ARRAY ZERO IF ADJUSTABLE OIMENSION PTRCOM COMNAME POINTER TO THE COMNAME TABLE USED ONLY IF COMMON SYMBOL ARRY POINTARRY INFO POINTER TO TABLE Of DIMENSIONS NULL IF NOT AM ARRAY 1
53. YPEDECL scans and processes this kind of declaration Variables are inserted in the symbol table with the information specified by the declaration First it obtains the type for the variable based on the type of the declaration It then scans forward and obtains its size modified by if one 1s specified The variable is inserted in the symbol table and a pointer to the symbol table entry is passed to procedure ISARRAY This procedure is responsible for obtaining the dimension information for creating the record that stores this information and putting its pointer in the symbol table entry of the variable If the variable is initialized procedure VARINIT is responsible for the steps involved This procedure builds a list of the variables to be initialized See Section 9 VARINIT is entered with LXC the global pointer to the Iexeme array pointing to the lexeme with the first initialization value The initialization list is extended at the end by calling EXTEND LIST a number of times according to the number of elements in the variable declared Procedure VALUES is then called which traverses the list of the initialization values in the statement and enters them into the fields of the nodes just created In this process it calls procedure INSERT VALUE Procedures ExrEwp usr FILL VALUES and INSERT VALUE are also used in processing the DATA statement See Section 9 2 8 3 Dimension declaration Procedure scans and
54. able or location is specified more than once only the last initialization is effective 2 5 3 lnitialization by character strings The initialization of variables by character strings in DATA statements or type declaration statements follows these rules 1 One character will be stored per quarter word A full word has hence the capacity to hold four characters half and double words hold 2 and 8 characters respectively An array has a capacity which is the product of its size and the capacity of its elements 2 If the string is larger than the capacity of the variable being initialized only the initial characters of the string are used and the rest are discarded 3 If the number of characters in the string is smaller than the capacity of the variable then the string is padded with NULL binary zeroes 4 Character strings may be preceded by a replication factor followed by an asterisk The replication factor increases the number of string elements not their length 5 An array or the two halves of a complex variable may be filled with successive characters from the string If an element is incomplete it will be filled with NULL If successive elements are not reached they remain uninitialized Characters can also be assigned to variables using an assignment statement 2 5 3 4 Examples Initialization statement INTEGER H ABCD A 2 ABCDEFGH DIMENSION C 3 D 3 E 8 F 3 DATA 0 2 0 3 C AB AB
55. alues for the preceding list of variables array elements or array names 2 5 1 Loops in variable lists in DATA statements Nested loops are allowed in specifying variable lists in a DATA statements The form of these loops is similar to that used in the READ and WRITE statements Syntactically each variable or array element in amp he above specification a k e g can be replaced by a pair of parantheses enclosing a list of variables or array elements The loops can be nested to any arbitrary depth The general form of the loops is DATA C ili mnt j l2 m2 n2 kzl4 m3 n3 vr lxil where i j are control variables Their appearances imply that they can be used in specifying subscripts among the array elements which occur anywhere inside the loop The control variables have no relation to any other regular variable with the same name in the program and they do not obey the implicit typing since they must be integers If a control variable name occurs more than once in a single nesting of loops the one in the level nearest its occurrence in a subscript is effective when the subscript is inside the ranges of both loops ly Io ml mo and nj no specify lower bounds upper bounds and step amounts respectively for the loops The appearance of the step amount is optional 2 5 2 General initialization rules i The type of initialization is determined by the type of the constant specified and
56. and storing variables c the procedure to process function calls d the procedures to process initialization specifications 3 t processes an internal structure and possibly generates code from it These are a the procedure to close either a DO loop or a loop in an I O statement b the storage allocation procedure c the variable initialization code generating procedure d the procedures to generate code related to multiple entry procedures 4 t manages an internal table a the symbol table routines b the standard function table routines c the temporary storage management routines 5 It is a pre processing procedure for each input statement a the lexer b the statement classifier Apart from these are the error and warning routines the code generating routines the type checking routines and a number of general utility procedures Some of these utilities scan and process specific constructs a procedure GETHTYPE processes an explicit type specification E g LOGI CAL b procedure GETTYPE processes the x modification of a type specification E g 4 c procedure GETCOORDINATE processes the subscript specification of an array element in a DATA or EQUIVALENCE statement E g A 1 3 d procedure ISARRAY processes the dimension specification in the declaration of an array which occurs in the DIMENSION COMMON and type declaration statements E g 1 4 18 Overall Organization
57. ated run time package is of course sensitive to the machine architecture The dependencies are easy to manage since this package is written in Pascal The U Code generated from the run time by our Pascal compiler can be combined with the U Code from UFORT before being interpreted or the run time U Code can be translated to machine code and loaded for execution together with the machine code translated from Fortran programs via UFORT The run time package is hence easily changed or augmented by more Pascal written routines This approach also makes available to Pascal programs the FORMAT conversion routines implemented within the Fortran run time package The two components which make up UFORT the compiler and the run time package are of course constrained due to the facilities provided by the Pascal U Code environment The most serious of these 1s no doubt the unavailability of direct access to files We plan to extend our system with direct files supporting variable length records and at that time both Fortran and Pascal will be augmented to support these features A Ke80 Another aspect of the U Code environment is that it does not sufficiently provide for the separate compilation of routines UFORT wiil hence accept a complete set of program units the main program any BLOCK DATA program all SUBROUTINEs and FUNCTIONS together and generate a single block of executable U Code After translation to 5 1 machine code the resulting relocatable instru
58. atement Apart from calling snrryprocessinc it generates the U Code label on site that marks the entry point represented by the ENTRY statement in the multientry procedure Since the jump table for the multientry procedure is at the end of the procedure a UJP is always issued as the first instruction of this procedure This jump directs the branch to the code of the jump table The code related to the jump table is generated by procedure GENENTJUMPS called from procedure BLOCK Preceeding the Jump table is the code to load the branch parameter and an xJP instruction which directs the jump with reference to the jump table The Jump table is emitted by traversing the list of entries pointed to by HEADENTRYLIST The code for the entry procedures is generated by procedure GENENTPROCS called at the end of procedure BLocK One procedure is generated for each node in the list of entries After the procedure heading a series of top str is generated for the parameters to that procedure for copying addresses to global locations Then follows the code to call the multientry procedure with an integer parameter that conveys the entry point For functions the call will result in a value returned and additional code to take in the value and in turn return it is emitted 18 5 Example The following example illustrates how a multiple entry function is compiled Fortran FUNCTION SETVAL P1 ENTRY SETVALsP1 RETURN ENTRY ASSIGN P2 P2 s RETURN END
59. been completely defined before the initialization specifications 9 2 The DATA statement Procedure para stwr scans and processes a DATA statement and builds the list of the variables to be initialized A DATA statement is composed of the alternate appearances of a variable list followed by the initialization constants enclosed by the slashes Procedure FORM VAR LIST processes a variable list and adds nodes to the initialization list for the variables to be initialized Procedure FILL vaLuEs then processes the upcoming list of constants and updates the list with the initial values in the nodes for the variables just inserted Variable FIRST IN LIST is returned from FORMVARLIST pointing to the first element of the group just inserted and is used by FILL VALUES to teli where to start entering the initializatron values Here is a more detailed description of the procedures used Procedure Frormvartist gets and inserts the names of the variables to be initialized into the symbol table indicating that they are being initialized by setting the field inrrIALizep to TRUE It then creates the entries in the initialization list for these variables by calling procedure EXTEND LIST Since the variable list can consist of arbitrarily nested loops FORMVARLIST uses special data structures and an recursive algorithm to process the variable list These are presented in the next section Procedure rxrENp usr does the actual building of the initialization list
60. call CLASSIFY to determine the statement type 4 Call STORAGE ALLOCATION to allocate storage for the variables that have been declared 5 Call FILL ADDRESS INITIALIST to copy these addresses into the list of variabies to be initialized 6 While there are statement function declarations FORMAT or SET statements do a call STMT FUNCTION FORMAT STMT or SET STMT b call texer to get the next statement c call CLASSIFY to determine the statement type 7 Generate code for the head of the U Code procedure for the current program unit 8 Initialize the list of temporary locations to NIL 24 9 Main block 6 2 While statement is an executable statement FORMAT or SET statement do b if there is a Fortran label enter it in the label table if it is not there already and generate code for a U Code label by calling ENTERLABEL c call the routine to process the statement d if we are not about to process a statement within a logical IF statement then do 1 if we have been processing an IF statement then generate the U Code label to be jumped to if the condition is false 2 if there is a Fortran label and it is the end for a do loop then generate the appropriate code 3 call LEXER to get the next statement 4 call CLASSIFY to determine the statement type a Process the enD statement b call LEXER to get the next statement c call CLASSIFY to determine the statement type Check if any do loop is still open
61. comment is written on the U Code file Default is T The Loc instruction in U Code is regarded as comment in this case CSIZ The argument is a number It specifies the minimum size in number of words to be allocated to the common areas that appear for the first time in the next COMMON statement It is reset to 0 at the end of each COMMON statement and at the beginning of each program unit 14 User s Guide 29 The argument is a number It gives how many parameters should be passed in registers Default is 10 Maximum is 15 2 10 Input Output 2 10 1 File handling UFORT uses Pascal run time routines for input and output on the character level Pascal treats all I O as being to files of characters Fortran device numbers 0 through 5 are given internal representations of FILEO FILE1 FILE2 FILES Provisions exist for extending the number of devices to above 5 The mapping between these pseudo files and actual devices or disk files is done at execution time usually by a direct prompt at the terminal E g FILE1 DATAI FILE23 QUT1 FILE3 TTY A file is opened immediately after the prompt is answered This may occur at the beginning of the program or at the first appearence of a READ or WRITE statement using the device number of the file depending on the Pascal run time used For the S l these are specified GWa78 and the current HiN80 Files are always closed only at the end of the program Random acce
62. ctions can be combined with other program units through the use of a linking loader 791 1 2 Conclusion The UFORT Fortran compiler is a building block within a Pascal and U Code environment which can take care of existing needs for the continued use of Fortran coded algorithms By bringing Fortran into this environment a dichotomy of programming approaches can be avoided and a more consistent approach to computing can result The next section specifies the Fortran source statements recognized by UFORT together with the differences from the standard The remainder of this document describes the implementation in sufficient detail to serve ongoing maintenance and extension needs 2 5 2 User s Guide This section describes the limitations and extensions of UFORT Fortran in comparison with standard Fortran compilers and especially in comparision with the full Fortran 66 Standard CANS66 2 1 Statements The following Fortran statement types have been Implemented Declaration statements DIMENSION COMMON EQUIVALENCE IMPLICIT EXTERNAL LOGICAL INTEGER COMPLEX REAL DOUBLE PRECISION DATA Executable statements The assignment statement ASSIGN IF logical and arithmetic GOTO unconditional computed and assigned WRITE REWIND or OPEN Other statements The statement function declaration FORMAT FUNCT I ON SUBROUTINE BLOCK DATA SET CONT I NUE ENO ENTRY Not implemented END FILE
63. d by different procedures the unifying rule used is that each procedure is entered with LXC pointing to the firs amp lexeme it processes and exits with LXC pointing to the one after the last lexeme it processes Warnings are output when errors are discovered in the program which UFORT thinks will not drastically affect the normal execution of the rest of the user program Regardless of when it is discovered only a name will be printed with the message The position where the warning IS printed in relation to the program statements in the listing file serves as another clue to the user in some cases Recovery actions may also be taken by UFORT The resulting behaviour of the program is easily predictable by the user UFORT always prefers warning instances to error instances Le for each user error UFORT classifies it as an error instance only if it cannot make it a warning instance 54 19 4 Lexer 4 1 Summary The purpose of the lexer is to split the input program up into nice pieces exemes which are easier to deal with than characters Each time the lexer is called it reads the next Fortran statement from the source file moves it character by character into an array called LEXSTRING stores the Fortran statement label in LABNO generates the sequence of lexemes contained in this statement and puts the lexemes into an array called LEXEME Comments are skipped and all lines of the source file are copied to the listing file The leng
64. d DO or is just a list of variables surrounded by parentheses LIisr PRocessiNc tooks at each element of the list if it is a simple variable array element or an array procedure VARNAME is called If it is an implied DO which is detected by procedure cHECK Do iMPLIED procedure DO IMPLIED rs called to process it If it is a simple list procedure LIST PROCESSING IS called recursively to process this inner list with IN DO IMPLIED set to false Procedure VARNAME generates the code for the I O of a simple variable array element or a complete array For the simple variable or array element the parameters to the system routine that does the data transmission are loaded and then a call to it is generated For the complete array a special loop in U Code is generated This loop is preceded by in their order the code to compute the number of elements of the array and store it in MAXPRINTARRAY the code to initialize CONPRINTARRAY the indexing location to 0 and a U Code label to mark the beginning of the loop Inside the loop 15 the code to load the parameters for the system routine and a call to it The address of each element of the array is computed by loading the initial address of the array and then indexing it with the value at CONPRINTARRAY At the end of the loop is the code which increments the index and tests its value against that in MAXPRINTARRAY for loop termination condition Procedure DO IMPLIED processes an implied DO First it process
65. d level assigned to the Format label and b the pointer to the FORMAT string specification list The FORMAT string specification is copied into the FORMSTR list character by character Any unused space in the jast FORMTSTR record is cleared to blanks 25 2 Initialization of formats Procedure NIT_ FORMATS is used to generate code for amp he loading of the FORMAT string specifications into memory at execution time This procedure is called by procedure VABINITIALIZATION which is in charge of the initialization of variables for the compiler See Section 9 5 76 FORMAT Statement Processing 252 For each FORMTLIST record procedure INIT FORMATS generates a series of LCA LDA MOV instructions according to the length of the FORMTSTA list By the sequences of the three instructions the segments of each FORMAT string stored in the FORMTSTR records are moved to be adjacent to each other in a block starting at address DISPLACEMENT level 3 The LDA STR instructions then follow which stores the address where the string begins at the address of the Format label 26 77 26 Read and Write Statements 26 1 Run time 1 0 routines Fortran allows lists and loops within the READ and WRITE statements In order to manage the fairly complex variable sequences the implementation uses multiple calls to system routines listed below 26 1 1 Initialization of 1 0 routines The run time routines require initialization at the star
66. d of a program unit if the bottom marker is not at the top of the DO stack which indicates one or more do loops have not been terminated an error message is generated The stack is formed with the DOENTRY record of the form DOENTRY RECORD PREVIOUS DOENTRY POINTS TO NOOE OF PREVIOUS NESTEO 00 CONTROLVAR SYMBOL POINTS TO SYMBOL TABLE ENTRY OF CONTROL VARIABLE STMTLABEL FORTRAN LABEL THAT ENOS THE THE RANGE OF THE LOOP PCOOELABEL INTEGER PCOOE LABEL INSERTED WHERE THE DO LOOP BEGINS e STEPKI NO UPPERKINO OOKI NO EXPLEVEL IF EXP THE LEVEL OF THE TEMP LOCATION USED STEPAMOUNT IF CONST KINO THEN CONST VALUE 4 UPPERAMOUNT INTEGER IF EXP KINO THEN TEMP LOC 4 STEPMTYPE UPPERMTYPE CHAR e MEM OF THE TEMP LOC USED STEPVAR UPPERVAR POINTSYMBOL FOR VAR KINO END The DO loop routines are also used in processing implied loops in the READ and WRITE statements 2 1 1 Do loop initialization Procedure scans and processes a statement It pushes an entry in the DO stack gets the Fortran label that terminates the range of the do loop and inserts it in the en try 21 1 DO Loop 69 just created processes the control part of the do loop by calling procedure po coNTRon and generates a U Code label indicating the beginning of the do loop In procedure DO_ CONTROL the control variable IS located and inserted in the
67. e commonly followed by programmers but are not part of the standard A pass over Fortran source code with a text editor can easily correct failures to obey that constraint since these changes do not affect the semantics of Fortran programs in any way We feel of course that such constraints are a reasonable part of any programming environment we wish to support UFORT does not depend on reserved words in its method to recognize keywords and is hence extensible to additional statement types Candidates for additions are several file manipulation statements now used by existing compilers and defined in ANS76 and other features to support real time operations and aspects of parallel processing The structure of the compiler is derived from a Fortran compiler written in Fortran which was used for student programming from 1963 to 1967 at UC Berkeley Student on an IBM 7094 system A derivative of that compiler is the PL ACME compiler BRW68 a compiler for a subset of PL 1 also written in Fortran with strong support for on line laboratory operations Writing the new compiler in Pascal has allowed formalization of modular concepts used in the earlier compiler WiB70 The availability of recursion has caused us to switch to the use of recursive descent as the method for compiling arithmetic instructions a method which copes well with some of the problems of Fortran syntax The compiler while attempting to generate good U Code does no explicit opti
68. e current Do is generated the previous entry in the stack becomes the new CURRENT and it is checked if the label in LABNO also indicates the end of its range If t does code is also generated for its termmation This is repeated until the label in LABNO is not the end of the range of the current top record Then the rest of the records are checked and any that should be terminated by LABNO causes an error message which indicates bad DO nesting This procedure also checks the kind of the statement that terminates the loop and gives an error if it is one of the following RETURN PAUSE STOP DO GOTO arithmetic IF and ENTRY The generation of code for the termination of the loop is done in procedure GENCODE FOR DO 2 1 3 Do loop example Fortran DO 10 1 3 3 3 2 10 CONTINUE 1 STOP ENO U Code LOC J 36 3 STR J MI 50436 store initial value of control variable 100 JM 1 540 36 Loc J 36 3 ADD J evaluate loop termination value STR JM 14 72 36 store termination value in a temporary location L1002 LAB 0 labelto mark beginning of DO loop 70 DO Loop 21 3 code for statements inside loop L1001 LA8 0 Loo JM 1 504 36 Inc J 2 STR JM 1 504 36 Loo J M 1 504 36 Loo JM 74 72 36 GRT J 11002 label to mark tnd of load value of control increment it supdate the control sload control variable the range of the DO loop variable variable back sload loop termination value compa
69. e entry is set to NIL so that when the symbol table 1s cleared at the end of the current program unit no pointer points to its entries and the space used by the symbol table can be reclaimed for other uses At the end NEXTININIT is updated to point to the last element of the initialization list that corresponds to the last variable initialized in the most recently compiled program unit 9 5 Procedure VARINITIALIZATION This procedure is called by the main procedure after ail the program units are compiled It generates code for the initialization of variables and the loading of FORMAT specifications into memory at execution time the latter being done by calling procedure INIT FORMATS see Section 25 2 The code for the initiaiization of variables is placed inside a special U Code procedure created for the compiler called tntxx A call to procedure INIXX is always executed before anything else in the compiled U Code program The head of the special procedure INIXX is generated by calling procedure BLKCODE GENERATION Then code for the body of procedure INIXX is generated This consists of a series of rpc sr amp U Code instructions that load the constant values on the stack and store 9 5 Initialization of Variables 39 them into the variables locations in memory String constants are loaded into variable addresses using the LCA LDA MOV sequence of U Code instructions 40 10 10 Storage Allocation Structure In U Code as in
70. e table because otherwise FsymBoL would insert the default Fortran type instead of NONE with the subroutine name Procedure USERFUNC is then called 19 4 Subroutine and Function Calls 19 4 Standard function calls Standard function calls are implemented im three ways By a direct call to an equivalent U Code standard function CSP instruction 2 By generating in line code i Byacall to afunction in the Fortran run time package CUP instruction A list of the functions they are implemented follows DESCRI PTI ON NAME ARGS RESULT U CODE absolute value ABS real real ABR AB int int ABI DABS doubl doubl ABR mod CABS complx real inline truncation AI NT r eal real CUP INT real int CUP IDINT doubl int CUP mo d AMOD real real inline MOD int int MOD DMOD doubl doubl inline int real CUP AMAX1 real real CUP int int CUP MAXI real i nt CUP DMAXI doubl doubl CUP mi n AMI NO i nt real CUP AMINI real real CUP MI NO i nt i nt CUP MINI real i nt CUP 1 doubl doubl CUP int to real FLOAT int real CVT real to int IFIX real int CVT transfer sign SIGN real real CUP ISIGN i nt i nt CUP DSI GN doubl doubl CUP positive diff DI M real real CUP 0 if 1 lt 2 IDIM i nt CUP doubl to real SNGL doubl real CVT complex to real REAL complx real inline complex imag Al MAG complx real inline to real real to doubl DBLE real double CVT real to complix real complix inline conj ugate CONJ
71. ence causes no ambiguity Variables GPCOUNT2 and GPCOUNTS keep track of the current position of the cursor within groups When GPCOUNTS is O the cursor is not within a 3rd level group When the cursor is within a 3rd level group GpcounT3 indicates the number of times it still has to scan across that group It is decremented each time the end of the 3rd level group is reached The same holds for GPCOUNT2 and 2nd level group GPBEGIN1 GPBEGIN2 and GPBEGIN3 give the starting position of the current groups of the respective levels When the scanning has reached the end of the FORMAT string but still has yet to look for the next I O fieid back up is made to the beginning of the last 2nd level group For this purpose LASTGPPOS and LASTGPREP will hold the starting position of the last 2nd level group or the 151 level group the ronwAr string itself if no 2nd level group exists and its repetition factor 27 2 The Fortran I O Run time Package 83 To prevent Nexrrizezxp from looking for a field indefinitely when in fact no field exists from its back up point to the end of the FORMAT string the boolean variable FIELDFOUND is used Whenever the end of the Format string is reached there will be back up only if FIELDFOUND is true FIELDFOUND is set false when scanning the beginning of the romMaT string and at the beginning of every 2nd level group that can possibly be the back up position for the FORMAT string It is set to true whenever a field
72. ercions and error recovery inside ARITH 8 In generating in line code for some intrinsic or standard functions Temporary locations are allocated in the level of the program unit being compiled and thus they exist only while the program unit is being executed UFORT distinguishes between two memory types in U Code type R registers and type M main memory It assumes that each U Code procedure has a number of registers available for its local storage The constant MAXREGS defines this number In addition the constant MAXPREGS defines the maximum number of registers that can be allocated to the parameters of a program unit Temporary locations are allocated in type M memory only after no more R memory is available Since some temporary locations are used in connection with loops and temporary locations are reused whenever possible this scheme contributes to greater efficiency when the U Code are executed The two temporary storage management procedures are GETTEMP and RELTEMP gets a temporary location and returns its level address and memory type renreme is called to specify an allocated temporary location being now available for reuse somewhere else as a temporary storage location The temporary locations are kept in a linked list pointed to by global variable TEMPLOCHEAD In the beginning the list contains no node The list is lengthened as more and more temporary locations are allocated The order of each node in the list
73. es of data values according to the field types specified This is necessary since for instance no string variable exists but the character type field A field does exist The Fortran user has to make sure that his variables in formatted I O have the right corresponding field type in the FORMAT string for the correct values to be transmitted In the implementation the data type IOCOC record CASE INTEGER OF 0 INTVAL INTEGER 1 REALVAL REAL 2 CHARVAL ARRAY 1 4 OF CHAR 3 BOOLVAL BOOLEAN ENO allows the decoding of the content of a memory location as different types of data values The above default is implemented by making a variable of this type as the reference parameter for the I O variable in the externally called procedures READVAL and WRITVAL After calling NEXTFIELD the type of conversion is known from the field type and the corresponding conversion procedure is called using the suitable variant field as the parameter 84 The Fortran I O Run time Package 274 The size of the variable one of the parameters in READVAL and WRITVAL is taken account of by shifting the value prior to output conversion or after input conversion In formatted I O the form of the input or output field has no correspondence to the variable size In output E field and D field differ only with respect to whether E or D indicates the exponent In input D or E makes no dirference in indicating the exponent 27 5 Output conversion
74. es the control part of the do loop using procedure DO coNTROL then it generates the code for the list of variables 1n the Implied by calling procedure Li T PROCESSING with the parameter IN DO IMPLIED ser to true after this it generates the code to close the do loop using procedure CLOSEDO Each implied DO has associated a dummy Fortran label above 100000 to avoid any possible duplication with an existing Fortran label that is used by the croso routine These dummy labels are not Inserted into the label table 26 3 Code generated fortran INTEGER C 3 3 P 5 PU 1 I38N 4 1 READ 4 8 U Code MST 4 sinitialiation LOC J 36 4 load device number PAR Jil 0 0 36 LOO AM 1 1008 36 load address of FORMAT string PAR M 1 1008 36 CUP P 28 READ1028 2 0 call inittalization routine LOC J 36 9 1 0 of arrayc 80 STR J M 74 72 36 Loc 36 0 STR JM 74 108 36 1 1001 LAB 0 MST 4 LOA 15040 too J M 74 108 36 XA 36 PAR A M 0 0 36 Loc J 36 4 PAR JM 0036 LOC 3 36 0 PAR JM OO 36 CUP 30 READV030 3 0 Loo J M 74 108 36 INC J 1 STR J M 74 108 36 100 JM 74 108 36 100 JM 74 72 36 GEQ J FJP L1001 100 JM 1152 36 STR JM 1 1116 36 L1002 LAB 0 MST 4 LDA M 1 828 180 100 JM 1 1116 36 orc J1 IXA J 36 PAR A M 0 0 36 Loc J 36 4 PAR J M0 O 36 LOC J 36 0 PAR JM 0 0 36 CUP 30 REAOVO30 3 0 100 JM 1 1116 36 INC J1 STR JM 1 1116 36 100 JM 1116 36 100 JM 1188 36 GRT J FJP L1002 MST 4 LDA M 1 396 36 PAR
75. eter of type POINTDEFTYPE see Section 8 1 The compiler processes addresses in units of half words Currently bit addresses are used so that all address parameters have to be multiplied by the constant BYTELEN the number of bits per byte before written out Since the symboi table keeps only the level information of the variables the block number is given as the parameter by indexing into the global array SEGLEN using the level as index The array secLev is updated whenever a new U Code block is entered The LDC instruction is generated by a number of different procedures distinguished by the forms in which the constants are passed to the procedures GENLOADNUM the constant is to be taken directly from the Fortran statement kept in the array LEXSTRING The pointer to the lexeme is passed GENLDC the constant is passed as a string of 20 characters which can contain any possible double precision number GENLOADINT GENLOADBOOL GENLOADCHAR the constant is passed in integer boolean and character forms respectively GENOREAL the constant is always the floating point zero Other U Code generating routines are GENLOADSTRING given a pointer to a string lexeme generates code to load that lexeme GENLABEL prints a U Code label definition e g L15 LAB GENDEF GENCLAB GENLDA GENXJP GENCSP GENMST GENCUP GENEND GENLDP GENENT generates the given instruction GENSEGCODE generates the dummy blocks see Section 10 GE
76. evel is assigned to the rest of the common areas Another level is assigned for the storage of the local variables of the program units In addition space is allocated in this level for storing a the results of expressions constants or subprogram names when they are arguments in subprogram calls b format strings and c parameter addresses for parameters to multiple entry subprograms The levels in the U Code generated by UFORT are distributed as follows Level 1 non common variables dummy procedure Level 2 ail other common areas dummy procedure Levei 3 the blank common area dummy procedure Level 4 main block and subprograms Level 5 ail statement functions The storage for parameter addresses and return values in subprograms and statement functions together with any temporary location used by the compiler inside their procedures is allocated in their respective level 4 or 5 stack frames Level 5 is used for statement functions because they can only be called from the level 4 subprograms in which they are defined U Code does not require that procedures be in any specific order Thus the code for the procedures in levels 1 to 3 which includes how much storage is needed for these procedures could come after the code for levels 4 through 5 The executions of these three procedures involve only the calls to the procedure of the next higher level Here is a Pascal representation of the idea 10 1 Storage All
77. f HE PREVIOUS NODE USED IN INITIALIZATION WITH STRINGS CASE AMOUNTYPE LEXTYPE OF LEXTYPE OF THE STRING VALUE STRINGCON STRLEN INTEGER F INTIALIZAT ION WITH STRING LENGTH OF THE STRING CONSTANT INTEGERCON REALCON OPCON NEGATIVE BOOLEAN TRUE IF CONSTANT IS VE END The same initialization list is used for all the program units in a program lengthening as more initializations are specified The addresses have to be saved in this list because the symbol tabies of all previous program units are no longer available when the initialization code is being emitted in procedure VARINITIALIZATION One entry is created for a simple variable Complex vartables are inserted in the list of initraiized variables as two reais the real part and then the Imaginary part Arrays have an entry for each element of the array and the displacement in actual memory locations of each of its elements with respect to the start address of the array IS given in the ADDRESS field of its INITIALIST record entry The real address for the elements initialized 15 not entered until procedure FILL ADDRESS INITIALIST is called after storage allocation has occurred This will just add the address in the symbol table to what is already in the ADDRESS field in an INITIALIST entry Types 36 Initialization of Variables 9 1 of the initialized variables and dimensions of the arrays whose elements are being initialized must have
78. gle precision The I O requirements of quarter and half word variables are completely handled The I O routines are stored in loader format along with the intrinsic and standard function run time routines and linked to the main program by the linker for execution 27 7 Structure of the 1 0 package The separate parts that make up the I O run time package are listed with their procedures in the order as they appear in the program l error procedure This outputs I O execution error messages and sets error flags a procedure ERROR 2 routines to handle the operations of the I O buffer a procedure CALLNEWOUTLINE b procedure NEWOUTLINE These write out the buffer as the next line in the output file c procedure CALLNEWINLINE d procedure NEWINLINE These input the next line in the input file into the buffer e procedure PUTCHAR This puts the next output character to the I O buffer f procedure GETCHAR This gets the next input character in the I O buffer 3 procedures to process the romwar string a procedure NEXTFIELD When called it will scan the format string starting from where it was before processing what it encounters until it gets to the next I O field The specifications of the field are returned 4 procedures for output conversions of data values a procedure PRIFIELD prints an integer in an I formatted field b procedure PRFFIELD prints a real number in an F formatted field c procedure PR
79. ically cause an extra new line to be written An input line than 256 characters is processed as a single line but anything beyond the 256th character IS treated as blanks If an input line is shorter than that specified in the format specification an error message is given 2 10 2 User s Cu ide 15 Any internally representable character can be output via an A formatted field The writing of control characters like the carriage return or line feed to an A formatted field may cause the form of the output line to depart from that specified in the format specification The execution error messages of the READ and WRITE statements go to file OUTPUT 2 10 3 The PRINT statement Apart from the READ WRITE and FORMAT statements the PRINT statement which makes use of Pascal run time routines and acts somewhat like a Pascal WRITE statement allows the bypassing of the Fortran run times in performing output operations It prints integers reals booleans string constants or complex numbers or any legal expressions containing these items Normally a carriage return line feed will be printed at the end of the line This may be suppressed by adding a semicolon A field width may be added to any item This indicates the maximum length of the item to be printed Enough blanks will be added to make the item always have that length The default field widths are 14 for integers and reals and the actual length of the string for strings
80. ignificant digits are made ail zero The algorithm for output conversion of E field similar for F field with slight modifications is W D and S are the field descriptors 1 IF 8 gt W O 5 OR QUTREAL lt 8 AND 8 lt W O 6 OR S gt W O 5 OR DUTREAL lt 8 AND S lt W O 6 THEN print x across field field not large enough 2 ELSE IF QUTREAL lt MINREAL AND OUTREAL gt MINREAL THEN print zero MINREAL is the smallest magnitude of real number alioued Note that this is different from the smallest representable rea number which has the louest power but uithout the mantissa normalized 3 ELSE a get sign if negative b normalize QUTREAL to gt 8 1 and 1 0 and accumulate the power in variable E c 5 05 8 AND 54 0 lt 19 Here 10 is largest number of significant digits stored in a uord of memory THEN OUTREAL CUTREAL 8 5 10 5 0 Do rounding S40 is the number of significant 27 5 The Fortran I O Run time Package 85 digits printed d IF OUTREAL gt 1 0 increase to gt 1 0 due to rounding THEN BEGIN OUTREAL OUTREAL 10 E E 1END e l OUTREAL lt 34359738357 THEN CURTRUNC TRUNC OUTREAL 18 11 ELSE CURTRUNC TRUNC OUTREAL 18 18 f output digits from CURTRUNC the decimal point being governed by S 9 E S print the exponent according to 27 6 Input conversion of data values In unfor
81. lock 17 2 Processing dummy arguments 17 3 Subroutine statement 17 4 Function statement 17 5 Code generation 17 6 Example Multiple Entry Subprograms 18 1 The multiple procedures 18 2 Global storage of parameter addresses 18 3 The data structure 18 4 Processing multiple entry subprograms 18 5 Example Subroutine and Function Calls 19 1 Processing parameters in calls 19 2 Function call 19 3 Subroutine call 19 4 Standard function calls Statement Functions DO Loop 211 Do loop initialization 212 Do loop termination 213 Do loop example GOTO Statements and Statement Labels 22 Unconditional GOTO 22 2 Computed GOTO 22 2 1 Example 22 3 Assigned GOTO 22 3 1 Example The Arithmetic IF and Logical IF Statements 23 1 Logical IF 23 2 Arithmetic IF iii Page iv Section TABLE OF CONTENTS 24 The PRINT Statement 25 26 27 24 1 Example FORMAT Statement Processing 25 1 25 2 The FORMAT statement Initialization of formats Read and Write Statements 26 1 26 2 26 3 The 27 1 27 2 21 3 27 4 27 5 27 6 Run time I O routines 96 1 1 Initialization of I O routines 26 1 2 Initialization of single I O statement 26 1 3 Data transmission 26 1 4 Termination 26 1 5 Rewind Compiler routines Code generated Fortran I O Run time Package Structure of the I O package Processing the FORMAT string I O management In tern al ex tern al correspondence of data values Output conversi
82. m in the symbol table if required setting field 1__rquivaLence to TRUE and inserts them in the circular list that form the equivalence group If the variable equivalenced is an element of an array its coordinates are also obtained All this is done inside procedure EQUIVARLIST With the equivalence groups declared a list is formed using the global variable EQUIVHEAD that points to the head of the list and TAILEQGROUP that points to the most recently declared equivalence group at the tail Since the coordinates for array elements are remembered instead of being processed immediately dimension declaration of a variable can occur after its EQUIVALENCE statement 8 7 External Declaration Procedure rgxrpEcL scans and processes an external declaration The information that a variable is external 1s entered in the symbol table only since the effect of the external declaration is restricted to inside its program unit The external table is updated later in the call to the external symbol when the existence of a program unit of that name is implied Information is not entered in the external table if the variable externalled is a dummy argument 9 35 9 Initialization of Variables In most Fortran compilers initializations are handled by setting up the binary load file so that the locations which are specified by the variables to be initialized are loaded with the initial values at the time the program is loaded It is not possible to do thi
83. made up of records of type LABELNO LABELTYPE LNONE ISFORMAT ISSTMT LABELNO PACKED RECORD NAME FORTRAH LABEL PLABEL INTEGER PCOOE LABEL NUMBER ASSOCIATED LSON RSON ftLABELNO IS 0N RHS TS_ON_LHS BOOLEAN TRUE IF THIS LABEL NUMBER HAS OCCURRED ON RIGHT LEFT HAND 510 OF STATEMENT LTYPE LABELTYPE TELLS WHETHER A FORMAT OR STATEMENT LABEL NONE WHEN FIRST CREATED ENO and is accessed by the routine FLABELNO PROCEDURE FLABELNO VAR LPOINTER POINTLABELNO NUMBER INTEGER FORTRAN LABEL 1 IS ON RHS L IS ON LHS BOOLEAN FALSE IF NO INFO OR FALSE LABTYPE LABELTYPE TYPE OF LABEL MUST BE ASSERTED Places where FLABELNO is called are procedures ENTERLABEL called by BLOCK COMPLUJP and COMPLFJP used in the GOTO and arithmetic IF statement processors the DO statement processor and the READ WRITE statement processor 7 5 The common tab e The common name table COMNAME simply stores the names of the common areas thus far defined and some information about them It is made up of records of type COMNAME COMNAME RECORO LEVEL PSEUDO LEVEL NUMBER FOR THIS COMMON AREA LENGTH STADOR INTEGER LENGTH Ue THE COMMON BLOCK IN OUARTER WORDS AND STARTING ADORESS PTRCOMLIST COMLIST POINTER TO THE LINKED LIST Of COMMON ELEMENTS IN THIS AREA LSON RSON COMNAME NAME THE NAME NAME OF THE COMMON AREA END and accessed by
84. matted input conversion the input file is scanned line by line until the next non blank character is found and decoding starts from this position Blanks and end of line separate input entities In formatted input conversion variable IOBUFCURS always points to the left boundary of the input field Variable W1 indexes across the width of the field For integer and real inputs blanks in a field imply 0 For real input presence of overrides the implicit decimal place indicated by 0 in the field specification Presence of the exponent overrides the effect of the scale factor S Effects of D E F and C formatted fields are defined as identical 1n real input The loop that processes the input characters with one character look ahead is always of the form WHILE BUFFER 1 IN set of looked for char AND H1 is within boundary 00 BEGIN process this character Wl ia Wl 14 END where boundary refers to the field boundary or the decimal boundary within the field in formatted input and line boundary in unformatted input This arrangement requires that the input buffer be declared one unit longer to prevent out of bounds error of the buffer index Another possible arrangement not used which does not entail this extra declaration requires an extra flag and less straightforward structure DONE FALSE WHILE NOT DONE DO IF QUFFER W1 IN set of looked for char THEN BEGIN process this character Wi Wi 1 IF 1 not
85. me or the value for this field has not yet been asserted EXTERNAL means the identifier has been declared in an EXTERNAL statement but cannot yet be classified as EXTSUBB exrrunc or PARAMPROC EXTSUBR exrrunc INTRINSTDEXT PARAMPROC denote an external procedure an external function a statement function an intrinsic or standard function and a procedure parameter respectively This is the way ARITH processes symbois 1 Look it up in symbol table This means that if the symbol is not already there it is entered with among other things the _FUNCSUBR field set to NOTEXTERNAL If it has appeared in this program unit before then _FUNCSUBR will already contain the needed information 2 If we already know it is a user function then call USERFUNC 3 Else if we already know it is an intrinsic or standard function then call STANDARDFUNC 4 Else if next lexeme is not a left parenthesis or it has been dimensioned then it must be a simple variable or array element call LOAD VAR see Section 14 5 Else if it is a dummy argument it must be a function parameter call procedure USERFUNC to process the call Else if it is in the standard function table set 5 FUNCSUBR to INTRINSTDEXT to indicate that it is a standard function and call STANDARDFUNC 52 Expression Evaluation 152 7 Else it must be a user defined subprogram set S_FUNCSUBR to EXTFUNC to indicate this then enter it in the EXTERNAL table and call
86. med in the parameter processing procedures See Section 17 2 The storage allocation for temporaries generated by UFORT is done in the temporary storage management routines See Section 13 The storage already allocated in the different levels are monitored by displacement variables which indicate at the same time the next address available for assignment The global variable DISPLACEMENT and DISPL GENCOMMON are used for the levels of the non common variables and general common areas respectively Variable MAXDISPL BLANKCOMMON indicates the highest address so far allocated in the level for blank common variables Every time a space for a variable is needed the corresponding displacement variable is adjusted if necessary to lie on a half single or double word boundary according to the size of the variable Its value is then stored in the field ADDRESS of the symbol table It is then incremented by the proper amount The allocation of space is done in a specific order 1 Common variables and variables equivalenced to common areas The common areas are allocated in lexicographical order Inside each area the variables are allocated in the order in which they were declared as part of the common area The variables equivalenced to one in the common area are allocated according to the desired equivalence relation 2 Equivalenced variables with no common element in the equivalence group 3 All other variables in lexicographical order All com
87. ment function definition Procedure STMT FUNCTION gets and inserts the name of the statement function in the symbol table with LEVEL field set to 5 and ADDRESS field set to 0 It processes the dummy arguments by calling procedure puMMYy ARGUMENTS which inserts them in the symbol table and records the old contents in the DUMMY LIST records pointed to by HEAD pummy The dummy arguments are allocated addresses at level 5 in the same way as dummy arguments for program units are allocated at level 4 A segment number is assigned to the statement function segment and code is generated for the head of the segment by calling procedure BLKCODE GENERATION Then procedure ASSIGNVALUE which is also used in processing the assignment statement is called to evaluate the expresston and store the result of the expression in the space reserved for the statement function name at level 5 In this process temporary locations may be generated and if so they will be allocated in the level of the statement function Finally code is generated for the return of the statement function and the dummy arguments of the function are erased from the symbol table by calling procedure ERASE DUMMY S which also recovers the old contents in the symbol tabie from the DUMMY LIST records 68 21 21 Loop statement causes code to be generated at two different places at the positions corresponding to the DO statement and at the Fortran label that marks the end
88. mization of the generated code Recognition of common subexpressions for instance wrli require at least an additional pass in a compiler Current research in the Pascal P Code project at UCSD is leading to such an optimizer operating on U Code SPT79 The compiler also makes only very general assumptions about the register structure in the underlying machine It is the function of a U Code compiler e g SOPA 2 180 or a U Code interpreter e g UASMINT Bsh79 to carry out the requested U machine actions in a manner which utilizes the underlying hardware effectively The original P Code generated is a direct derivative from the original work of associates of N Wirth at the ETH NA J75 and documented by us in an S 1 project documentation note 4 Introduction li GiW 77 This was later adapted to the Universal P Code defined by the UCSD Optimizer Project PSi79 In our case the U Code is compiled into machine code for the S l processor FiZ78 a very high speed machine with a 36 bit word architecture which also supports 72 bit double word 18 bit half word and 9 bit quarter word or byte operations We hence expect 4 bytes per word that is 360 style alphabetic variables This aspect does not affect the UFORT compiler itself but 1s of major concern when transporting Fortran application programs which manipulate characters between computers since Fortran standards have ignored the issue of character to word relationships The associ
89. mon areas equivalenced variables within a common area and other equivalenced variables begin at a double word boundary For the rest of the variables quarter word variables begin at the next quarter word boundary half word variables at the next half word boundary single word variables at the next single word boundary and double and quadruple word complex variables at the next double word boundary Common variables are passed to procedure STORAGE ALLOCATION in the form of a list see Section 7 The list of variables in a common area is pointed to from the PTRCOMLIST field of its common name table entry The equivaienced variables are represented as a global list of equivalence groups see Section 7 Here is a more complete description of how storage allocation is done 7 I t Preprocessing equivalence groups Before any space is allocated the offsets of the eq uivalenced variables with respect to the leader of the group the first variable declared in the group is computed This is done in 111 Storage Allocation 49 procedure EQUIV_orrsers t also merges two equivalence groups if a variable is equivalenced both of them checking for any index conflict in array elements e g EQUIVALENCE 3 8 2 A 2 B 3 C The algorithm used in the computation of the offsets is as described in Gri 1 Procedure MERGE is called by EQUIV OFFSETS if a variable is equivalenced two times First it finds the two entries of the
90. mon block or an ENTRY statement in the same program unit can be the same as a variabie name However the same name cannot be used in a single program unit as both a variable name and a standard intrinsic or user defined subprogram name If a name is longer than 6 characters the extra characters are ignored and a warning is given FORM AT specifications Commas are not mandatory in FORMAT specifications if they cause no ambiguity For example X3XX ONE X X2 amp HFOURF8 516 and X 3X X ONE X X Z 4HFOUR F8 5 16 are equivalent If a FORMAT specification is to be kept in an array any embedded quote that occurs in the FORMAT has to be replicated when stored in the array Another level of replication might be required in specifying the quote in the program text In the following example the FORMAT co output the word DON T is stored in the array FSTR 2 2 User s Guide 7 INTEGER FSTR 2 5 DON T Statement abels Only executable statements and FORMAT statements can be assigned labels 2 3 Data types and constants 2 3 4 Data types Variables and functions may be of type INTEGER REAL COMPLEX or LOGICAL The standard naming conventions are used CO determine if a variable or function is of type integer or real names starting with letters from I CO N denoting integers but they may also be explicitly declared The naming conventions may also be overridden through the use of an
91. mpiled into a number of U Code procedures one for each entry point inciudmg the normal entry point at the beginning of the program plus an extra one which represents the body of the program unit This will be called the multientry procedure while the former ones wrii be called entry procedures Ail these procedures are at the level for program units level 4 The entry procedures bear the names of their respective entry statement names and their parameters are those of their entry statements Each of these procedures calls the multientry procedure with a single parameter giving it the entry point to branch to The multientry procedure always has only the single branch parameter as its dummy argument It contains the complete code for the body of the multiple entry subprogram with U Code labels at the places of the entry statements In addition there is a jump table containing jumps to the labels of the various entry points On entrance to the multientry procedure the branch parameter is used to determine the jump to the correct entry point Since each entry statement has its own U Code procedure a call to an entry statement IS just an ordinary procedure call to the corresponding entry procedure Therefore calls to entries are processed in the same way as ordinary calls Because UFORT is one pass it does not know about the entry points of a multiple entry subprogram until after the whole program unrt is processed Thus it has to re
92. nique program units If the ENTRY statement belongs to a function subprogram the ENTRY name is automatically made a function of the same type The ENTRY name must not be typed explicitly in any way even if its type is not the same as that implied by its name Parameters can be used for ENTRY statements Any ENTRY parameter used must appear the first time as a parameter either in the subprogram heading or an ENTRY statement except that it can possibly be typed or declared EXTERNAL in the declaration part of the program unit An ENTRY statement has no effect on the normal flow of control in the program unit if it is not called directly In the following example of a multiple entry subroutine a call to the subroutine SETVAL determines the variable whose value is to be used in assignment in any subsequent call to the en try ASSIGN SUBROUT I NE SETVAL P1 ENTRY RETURN ENTRY ASSIGN P2 P2 Pi RETURN END 2 9 User options the SET statement Options are specified using the SET statement Option names are identified by the first 4 letters only More than 1 option can be specified in a SET statement by using commas E g SET GENC T ASTR F T turns options on and F turns them off Here are the options implemented in UFORT Options related to U Code translators or interpretors are not included here BCHK When T execution time bound checking on array subscripts is turned on Defau It is GENComment When no U Code
93. ocation Structure 41 1 0 7 Pascal representation program FORVARS var i array U 181 of integer x variables in the blank common x procedure var n array 1 1688 of integer x variables in all other commons x procedure BLANKCOMMON var k real all variables not in COMMON areas stored here x procedure USERSUBROUTINE function STATEMENTFUNCTION real X begin CMIBOMSCIOM Dos ZXKq end begin x USERSUBRGUTINE x k 2 0 x normal variable x A 0 variable in blank common x end begin x Fortran main prog x 0 x normal variable x USERSUBROUT INE i1 8 blank common x Is 0 in common 1 x end begin x dummy for general common area x beg i n uo ME for b ank common area x E edd en 42 li 11 Storage Allocation In the storage allocation process each variable is assigned a level number and an offset Procedure sroRAGE ALLOCATION assigns memory locations to the variables declared during the declaration part of a block The procedure is called after all declarations have been processed and before any statement function declaration or executable statement occurs Any other variable that appears later in the program without having been previously declared is allocated through procedure SIMPLE STORAGE which is called by FsvMBOL The storage allocation for dummy arguments in subroutines functions and ENTRY statements are perfor
94. of a left parenthesis a real expression a comma another real expression and a right parenthesis Thus 3 X SIN Y is a legal complex number 2 4 Arrays and storage management Array subscripts Array subscripts may consist of any legal integer expression Up to seven dimensions are allowed Bound checking for array subscripts if turned on is done separately for the subscript of each dimension Array bound checking at compile time is done for arrays that appear in common and EQUIVALENCE declarations and for the ones that are initialized These arrays cannot have ad justable dimensions The specification of array elements in DATA and EQUIVALENCE statements with only one dimension for arrays of several dimensions is accepted For example for an array dimensioned as A 3 3 the array element A 2 3 may be specified as A 8 Arrays with adjustable dimension No restriction is made on the value of an actual argument that represents the bound of an array in the argument list of a subprogram Ie no check is made that the value is within the declared bound of the actual array parameter When an array subscript is beyond the range of the actual array no assumption should be made as to the referenced value The same applies in the case of arrays with constant bounds when the bound declared for the actual array parameter differs from that declared for the formal array parameter or when their dimensions are different In the subprogram
95. of the range of the loop In the former code is generated for the initialization of the index variable of the loop as well as for the final value and step amount if they are expressions and a U Code label is emitted to mark the beginning of the loop In the latter code is generated to increment the index variable by the step amount to check if it exceeds the final value and to branch back to the label that initiates the loop if it does not exceed the final value A list of opened do loops is built to control code generation for do loops This works in the form of a stack to keep track of the nesting of do loops Each time a new DO statement is processed an entry is created for it in the stack CURRENTDO is a global variable that points to the record of the most recently opened do loop at the top end of the stack There is a dummy entry that marks the bottom of the stack The end of the range of a do loop is determined as follows When a new label number 15 defined this is checked against the end label number of the innermost DO If it matches then the innermost Do is terminated and the same check is continued for the next outer DO This process terminates when the current label number is not the same as the label number of the DO in the top DO stack The label is then checked against the end label numbers of all the remaining outer DO s If there is any match indicating an illegal nesting of do loops an error is reported Also at the en
96. ogram to which they have been passed If a subprogram name or a parameter representing a subprogram name to be passed as parameter has not been called explicitly previously in that program unit it must have been declared EXTERNAL This rule is for ensuring that the compiler can diagnose that the actual parameter is a subprogram name A format parameter representing a subprogram name cannot be used also as a variable inside a program unit However the same parameter can be used to represent more than one functions or subroutines in different calls and they can have varying number of call parameters Statement functions cannot be passed as parameters but a statement function can have subprogram name parameters 2 8 User s Guide I3 2 8 Multiple entries to subprograms Multiple entry subprograms though not part of the standards are supported in the way they are usually used The keyword ENTRY has to be placed as the last symbol in the regular subprogram heading SUBROUTINE or FUNCTION statement to indicate the presence of ENTRY statements in the subprogram The Entry statements which indicate possible entry points to the subprogram must only be in the executable part of the subprogram An ENTRY name has no connection with any other possible identical local name in that program unit An ENTRY statement IS regarded as the declaration of a new program unit to the test of the Fortran program and they can be called there as if they were u
97. ommon area due to the equivalence and then assigns addresses to the variables in the equivalence group by calling procedure ALLOC COMMON AND EQUIV After space is allocated for ail the common variables of an area extensions to the right of the common area are checked See Section 7 5 regarding how the initial length of a common area is determined 1 1 3 Allocating space for non common variables Once space has been allocated for all the common variables the list of equivalence groups is traversed and space is assigned to those groups not yet processed Finally the symbol table IS traversed in alphabetical order and space for all remaining variables is allocated 44 12 12 U Code generating routines Almost all code that is written in the U Code file is generated by one of the U Code generating routines There are a few cases in which U Code is written directly using WRITELN The U Code generating routines are made to cope with the syntax of U Code instructron types The three routines GEN GEN2 and GEN3 cover most of the general U Code instructions The rest of the routines generate special U Code instructions or groups of instructions The parameters to the U Code generating routines convey the field contents of the instruction to be generated The most common fields are the U Code operand type memory type block number address and location size The U Code operand type together with the location size is conveyed by a single type param
98. ons of data values Input conversion of data values References Acknowledgement This work was performed as part of the software development effort at Stanford University under a subcontract from Lawrence Livermore Laboratory to the Computer Science Department Principal Investigator Professor Gio Wiederhold Contract No LLL PO 9083403 The 1 hardware and software development has been supported by the Department of the Navy via Office of Naval Research Order Numbers N00014 76 F 0023 N00014 77 F 0023 and N00014 78 F 0023 to the University of California Lawrence Livermore Laboratory which is operated for the U S Department of Energy under Contract No W 7405 Eng 48 from the Computations Group of the Stanford Linear Accelerator Center supported by the U S Department of Energy under Contract No EY 76 C 03 05 1 5 and from the Stanford Artificial Intelligence Laboratory which receives support from the Defense Advanced Research Projects Agency and the National Science Foundation The UFORT compiler is a direct derivative of the earlier PCFORT compiler written by Fernando Castaneda Frederick Chow Peter Nye Daniel Sleator and Gio Wiederhold CCN 79 The changes were implemented by Frederick Chow who also assumes responsibility for this document We are no longer maintaining the PCFORT version We also wouid like to acknowledge the invaluable assistance of Erik Gilbert Curt Widdoes and David Fuchs during the course of the devel
99. opment from PCFORT to UFORT amp 1 3 1 Introduction The Fortran compiler described in this document UFORT was written specifically to serve in a Pascal environment JeW78 using the Universal P Code as an intermediate pseudo machine NA 75 The need for implementation of Fortran these days is due to the great volume of existing Fortran programs rather than to a desire to have this language available to develop new programs We have hence implemented the full but traditional Fortran standard ANS64 ANS66 rather than the recently adopted augmented Fortran standard ANS76 All aspects of Fortran which are commonly used in large scientific programs are available including such features as SUBROUTINES labelled COMMON and COMPLEX arithmetic In addition a few common extensions such as integers of different lengths and assignment of strings to variables have been added 1 1 Objectives and constraints The foremost objective in the design of this compiler is the generation of correct code Effects of this objective are a clean approach to the design of the compiler the use of Pascal as the implementation language and the use of a simple one pass compiling technique The one pass approach has led to two additionai constraints on the source language variable declarations if given must precede all executable statements within each program unit and keywords must be separated from variable identifiers by blanks These constraints ar
100. or not If not STOREVAR lt called see Section 14 Otherwise it calls STORESTRING STORESTRING is used to store a s amp ring into any kind of variabte It generates code to load the string into the address indicated using the MOV instruction If the string is larger than the size of the variable the extra characters are Ignored If the string is shorter the variable is padded with the null character 54 16 16 Complex Number Arithmetic Complex numbers are loaded on the U Code stack as two real values with the real part second and the imaginary part on top on the stack Since there is no U Code instructions that takes a pair of stack values as an operand an operation on complex numbers consists of composite U Code instructions The SWP and DUP instructions are used extensively Storing values into temporary locations and loading them back later are necessary Each complex number operation finishes with the complex result on top of the stack If the complex result is to be combined again with another complex operand greater efficiency can be achieved if one part of the previous complex result is ieft in its temporary location But this then involves greater complexity in the processing algorithm and so is not pursued The methods implemented use the least number of temporary locations and also the least number of toad and store instructions although they certainly do not generate the least number of U Code instructions or try
101. outines The standard function table is set up at compiler initialization time and has a routine IN STNDFUNCTABLE that searches it The other four each has a main routine that searches the table for a given entry and inserts it in if it 15 not already there and then adds any information to the symboi table that is not contradictory to the information it already has about these symbols This structure is convenient in a one pass Fortran compiler because the information for a symbol is typically scattered all over the program The four main routines called FSYMBOL FLABELNO FCOMNAME and FEXTNAME are very similar in structure and have similar subsidiary routines which they call For example the routines CLEARSYMBOL CLEARLABELNO CLEARCOMNAME and CLEAREXTNAME all initialize new records for insertion into the respective table The following description of how procedure FSYMBOL works therefore is applicable to the other three routines When FSYMBOL is called it calls procedure BUILDSYMBOL with a name and a pointer to the head of the table as parameters BUILDSYMBOL which uses procedure SYMLOOK searches for an entry in the table with that name If it does not find the symbol it will create a new record and procedure CLEARSYMBOL will be called to set the fields of the record to their default values FSYMBOL then inserts all the information about this symbol that was passed to it as parameters checking for contradictions with the information i
102. ple Fortran GOTO 10 20 30 I U Code LOO JM 150436 load variable XJP J LIOOI L1002 1 3 jump according to table 1001 CLAB 3 jump table of length 3 UJP 11003 sjump to statement 10 UJP 11004 Jump to statement 20 UJ P L1005 Jump to statement 30 L1002 LA8 0 end of jump table call to execution error routines 22 3 Assigned GOTO Because U Code labels referenced 1n U Code jump instructions must be label names code for this Fortran statement IS somewhat Inefficient There are two ways this statement could be compiled into U Code The first IS to use the XJP instruction which IS like transforming the assigned statement into the corresponding computed GOTO The second method which is the one used does not use XJP and generates 72 GOTO Statements and Statement Labels 223 X denser U Code The label variable is multiply loaded and its value compared one by one with each statement label in the list until equality is found Then the corresponding jump is made If the label variable is a simple variable the multiple loading is done by calls of LOADVAR If it is an array element the subscript expression must be evaluated only once Thus LOADVAR 1s called only once and the value loaded is saved in a temporary location The value stored in this location 1s then multiply loaded 22 3 1 Example Fortran J 10 20 30 U Code 100 J M 1 594 36 load label variable J LDC 3 36 10 sload constant 10 NEQ J compare
103. processes the Fortran DIMENSION statement The symbol table entries for the variables are updated with the dimensron information It uses procedure ISARRAY to obtain the dimension information as in type specific declarations 8 4 Implicit declaration Procedure IMPLIDECL scans an IMPLICIT statement Array IMPLIARRAY is filled with the specified implied types can be entered only when processing the first statement in a program unit This procedure gets the implied types and size modifications and inserts them in IMPLIARRAY for the list of letters specified using procedure LETTERLIST If an IMPLICIT statement occurs in a subprogram the dummy arguments are affected plus the function name if it is a function subprogram Therefore once all the declarations are scanned the symbol table entry is traversed in order to change the standard Fortran implied types for the dummy arguments and function names using procedure cHANGEDEFAULTS These the only valid symbols in the symbol table at that time because the IMPLICIT statement must be the first statement in a program unit 5 Processing of Declarations 33 8 5 Common declaration Procedure COMDECL scans and processes a common declaration The common name table is built inside this procedure and linked lists of the common variables in each common area are constructed This list is formed with COMLIST records that have the following format COMLIST RECORD STPTR SYMB
104. program heading If a dummy argument is not involved in a call the content of its global location is not affected Because a dummy argument and a local variabie is accessed in different ways UFORT has to distinguish between these two types of variables when processing them Thus it IS necessary to forbid the appearance of a dummy argument in the program unit before its appearance in a dummy argument list 18 3 The data structure The data structure used in processing multiple entry subprograms is solely for the purpose of retaining information for use in generating the jump table and the U Code entry procedures after the body of the program unit has been compiled The record types used are defined as follows THIS RECORD REPRESENTS AM ENTRY POINT FOR A MULTIENTRY PROCEDURE ONE IS CREATED FOR THE MULTIENTRY SUBPROGRAM HEADING AND EACH ENTRY STATEMENT IN THAT SUBPROGRAM IN THE OROER Of THEIR APPEARANCES THIS IS USED FOR GENERATING THE ENTRY JUMP TABLE AT THE END OF THE MULTIENTRY UCOOE PROCEDURE AND EACH CALLED UCOOE PROCEOURE FOR EACH ENTRY POINT ENTRYREC RECORD EXTPTR POINTEXTNAME POINTS TO ENTRY IN EXTERNAL TABLE NUMARG Of PARAMETERS FOR THIS ENTRY POINT 4 ENTRYLABEL THE UCOOE LABEL THAT MARKS THE ENTRY POINT IN THE MULTIENTRY PROCEDURE ENTRYPOS INTEGER THE POSITION IN THE MULTIENTRY SUBPROGRAM RELATIVE TO OTHER ENTRY STATEMENTS IF SUBPROGRAM HEADING IT 18 0 HEAOENTADOR POINTENTADOR
105. re them jump back df still smaller 22 71 22 GOTO Statements and Statement Labels Format Statement labels are entered both in the label table and the symbol table All other labels are inserted only in the label table The first time a label occurs a U Code label is assigned to it and inserted in the label table The check as to whether a statement label referenced is defined or not can be made only at the end of a program unit since the left and right hand side occurrences are processed independently Procedure LABEL LHS CHECK IS called at the end of every program unit to search through the label table For each label used only on the RHS but not on the LHS a warning is given and the U Code label is generated at the end of the code for the program unit with traps Jumps to the undefined statement labels during execution will then cause a halt The three kinds of statements are processed as follows 22 1 Unconditional GOTO A simple UJP instruction is made to the corresponding U Code label 22 2 Computed GOTO This compiles into the instruction which corresponds to the CASE statement of Pascal First code to load the branch variable is generated by calling procedure LOAD VAR which takes care of cases that the variable is simple dummy or is an array element The instruction 15 then generated with the branch table immediately following This contains a list of UJP s for the statement labels 22 2 1 Exam
106. rned PLOO R M 78 0 36 return value received RET OEF R 36 OEF M 72 END 45516078 64 19 19 Subroutine and Function Calls Calls to user defined or standard or intrinsic functions occur in an expression and calls to subroutines occur in a CALL statement Procedure USERFUNC processes calls to user defined functions or subroutines Calls to standard or Intrinsic functions are processed by procedure STANDARD FuNc ways in which these calls are processed are described below 19 1 Processing parameters in calis Dummy arguments of subroutines and functions are allocated addresses in their own stack frames All parameters in Fortran are passed by reference During execution of a subroutine or function these addresses contain the addresses of the actual parameters The actual stering of the addresses of the actual parameters into these locations during procedure invocations are done by the PSTR instructions at the beginning of a U Code procedure In U Code the addresses to be passed are put on the stack with the PAR instruction to indicate that they are parameters and then the procedure is called The arguments in a call to a user defined function or subroutine are processed in procedure PROCESS ARGUMENTS The way an address is passed to the called subprogram depends on the form of the actual parameter For a simple variable array name or an array element its address is passed For a constant an expression or a string a location in
107. s in U Code since storage IS allocated on the stack only when the corresponding procedure is entered instead a series of explicit loads and stores must be executed at the beginning of the program The initialization of variables consists of three stages First a list of the variables to be initialized is formed during the processing of type specific declarations Section 8 2 and DATA statements Next the addresses of the variables to be initialized are saved in the LEVEL and ADDRESS fields of the record entries initialization list when procedure FILL__ADDRESS_INITIALIST is called after storage allocation for the current program unit has occurred Finally code are generated for the initializations at the end of compilation by calling procedure VARINITIALIZATION 9 1 The initialization list This linked list containing the variable addresses to be initialized and their initialization values is formed using the INITIALIST record with the following structure INITIALIST PACKED RECORD SYMTABPTR SYMBOL POINTER TO SYMBOL TABLE ENTRY OF VARIABLE TO BE INITIALIZED 4 LOCSIZE INTEGER SIZE OF INITIALIZED LOCATION FOR COMPLEX 5 IZE OF EACH HALF e NEXT INITIALIST NEXT NODE LEVEL LEVEL OF THE VARIABLE ADDRESS INTEGER LOCATION TO BE INITIALIZED EVEN IF ARRAY ELEMENT AMOUNT OIGIT STRING STRING WITH THE VALUE BE INITIALIZED CONTIMUING 8OOLEAN TRUE IF THIS IS A CONTINUUM O
108. s of data values Ail output conversions can be treated as formatted unformatted output being simply formatted output with standard field sizes for the different types The standard field sizes are those that allow the full content of the variable location to be displayed Thus they vary with the size of the variable In ail output conversions variable IOBUFCURS always points to the left boundary of the output field Another variable WI indexes across the width of rhe field The FOR loop is always used and W1 is the control variable Here are details for the output conversion of real numbers The real number is first normalized to 0 1 and 1 0 the power being accumulated in the integer variable E Rounding is performed at the appropriate place by adding 0 5 to the appropriate power of ten to the digit after the least significant printed digit Truncation then does the desired rounding For conversion to character form the normalized mantissa is multiplied by 10 xx 11 given MAXINT 34359738367 has II digits if lt 34359738367 and by 10 10 otherwise to convert to aninteger This arrangement is made to preserve as much accuracy as possible The output characters are then made from this integer This integer only gives the significant digits The position of the decimal point is monitored by E taking into account the exponent to be printed Thus even if the output mantissa has more than ii digits before the decimal the less s
109. se current varrec node is a variable Do the extension to the initialization list for this variable array element or whole array If any subscript is an identifier the value of the subscript is given by the CURRENTVAL field of the LEVELREC node in which the subscript identifier is the control variable 9 4 Procedure FILL ADDRESS INITIALIST This procedure finds the address of a variable once storage has been allocated to it and enters the address in its INITIALIST entry The procedure is called after sroRAGE ALLOcATION has been called which occurs after processing the last declarative statement and before the first statement function or executable statement in a program unit Global variable NEXTININIT is used to remember the record entry of the last variable initialized for the previous program unit Ail the entries in INITIALIST after that entry are traversed and the corresponding addresses are entered The displacement information stored in field ADDRESS is computed by adding the value already in the appress field of INITIALIST and the address stored in the symbol table entry for the variable This IS because the distance of an array element from the start address of the array was previously stored here If it is a simple variable this ADDRESS field would have previously stored 0 Field LEVEL is obtained directly from the LEVEL field in the symboi table entry After these two pieces of information are obtained the pointer to the symbol tabl
110. sion the fix up of the generated U Code and exit from the nested parsing procedures are effected in the following manner Each parsing procedure assumes no error occurs in the procedures which it calls for parsing its subexpressions and if it discovers an error itself it will finish parsing at the earliest possibility generating any dummy instructions which it IS expected to generate in normal processing Thus a call to ARITH will always finish with a single result on top of the stack Since the global error message routine only outputs one error message for each statement the error message output is appropriately that from the parsing procedure that first discovers an error 15 4 Example Fortran IF 3 2 e EQ 5 1 3 GOTO 233 U Code LDC 36 3 2 100 J M1 504 36 Yoad value of variable CVT R J float value of I R MST 4 LDC R 36 5 1 PAR R MO 0 36 LDC J36 3 PAR JMO 036 CUP R 52 RIEXPOS2 2 1 call exponentiation library function EQU R FJP 11001 uP 11002 15 5 Expression Evaluation 53 18 5 The assignment statement The assignment statement works as follows It first looks up the symbol in the symbol table and calls LOAD VAR ADDR to load the address on the stack if necessary It sets the global iexeme pointer LXC to point to the lexeme after the equal sign It then calls ARITH to evaluate the expression followed by ASSIGNVALUE to do the assignment ASSIGNVALUE checks whether the expression is a string
111. space required for an address Whenever an identifier used as a variable is encountered in the executable part of a program unit its STYPE field in the symbol table entry is checked and either the FUNCTYPE field is NOTEXTERNAL or the symbol table entry is identical to that pointed to by SEGPTR in which case it is the function variable An identifier not satisfying these conditions cannot be used as a variable in that program unit The fields ADDRESS S EXPLICIT USED RHS and usED LHS of the symbol table entry of a subroutine are not used Its STYPE field has to be set to NONE so that its use as a variable does not pass the above test The used and defined information for functions and subroutines is kept in the external table instead 17 1 initialization of a segment block The initialization of the global variables when a new block is found is done by procedure INITBLOCK This procedure performs the following steps 1 It clears the symboi and label tables the list of equivalenced variabies and the list of DO s that are still open 2 It restores the standard default values for variables not declared by modifying IMPLIARRAY 3 In the common table it sets the fieid PTRCOMLIST for each area to NIL since the compiler is ready to build a new list of common variables for the common area in the next program unit COMMONSIZ the variable in charge of the CSIZ option is also reset to 0 4 It sets to FALSE the global variables AFTER_STORAGE
112. ss within files is not allowed files must be written to or read from starting at the beginning of the file The first time in a program a file is written to its previous contents are destroyed and the file pointer is reset to point to the beginning of the file A file may be both read from and written to in the same program but each successive change of mode causes the file pointer to be reset to point to the beginning of the fiie The file pointer may be explicitly reset to point to the beginning of the file with the Fortran statement REWIND In the current run time a change of mode or a REWIND will aiso cause another prompt for the name of the file OPEN is an alternative name for REWIND The BACKSPACE and END FILE statements are not implemented 2 10 2 The READ and WRITE statements The standard READ WRITE and FORMAT statements use Fortran run time routines Both formatted and unformatted reads and writes are handled Unformatted writes use fields of fixed widths according to the types of the variables being output In unformatted input the input file is always scanned until the next non blank character in the input file is found Blanks are taken as delimiters and they do not have to be present if there is no ambiguity Comma should not be used as delimiters Each unformatted READ or WRITE statement starts on the next line The maximum length of an input or output line is 256 characters Any output to beyond the 256th character will automat
113. st be generated before the code for the head of the program unit IS generated 17 6 Subroutine and Function Statements 17 6 Example Fortran INTEGER FUNCTION X 1 X 24 RETURN END X0000076 ENT J 4 7611 LEX soa LEX 2 72 LEX 3 73 A R 76 0 36 Loc J 36 2 sload constant 2 100 A R 76 0 36 load address stored at address of ILOD J 0 36 fetch content of this address J compute 2 1 STR JM 76 0 36 at address 0 for the return value PLOD J M 76 O 36 RET sreturn generated due to the RETURN statement PLOD J M 76 0 36 RET return generated at the end of all program blocks OEF R 36 OEF M 72 END X0000076 type R storage type M storage 60 18 18 Multiple Entry Subprograms Multiple entry subprograms in Fortran provide two features to the Fortran user a a program unit can be entered not just at the beginning of the program block but at any defined entry point in the program unit b since a call to an entry point involves only the dummy arguments of that entry point the parameters to the program unit can be set during different calls remaining intact in the instances that the program unit is not active Since multiple entry facilities do not exist in U Code UFORT handles the above features by special means Some restrictions are imposed to enabie UFORT to preserve its one pass characteristics See Section 2 8 18 1 The multiple procedures A multiple entry subprogram in Fortran is co
114. statement This is needed because FEXTNAME is called once again before processing the first statement or after processing the IMPLICIT statement if present as the first statement in the subprogram This call is from procedure BLOCK The pointer is retrieved If the TYPEEXPLICIT field is false then if the subprogram has been called check is made against the now known implicit type Otherwise the implicit type is assigned 7 7 The standard function table The standard function table is initialized by the procedure FILL_STDNNCTABLE It is made up of the following type of record STOFUNCTABLE RECORD NAME THENAME NUMBER INTEGER EACH PROCEDURE HAS A DIFFERENT NUMBER USED WHEN THE FUNCTION IS CALLED LSON RSON S TDF UNCTABLE ENO It is searched by the function IN STDFUNCTABLE FUNCTION IN STDFUNCTABLE NAME THENAME VAR STOPTR POINTSTOFUNCTABLE BOOLEAN 8 31 8 Processing of Declarations When a variable occurs in a declaration an entry for that variable is made in the symbol table by calling procedure FSYMBOL and the information given in the declaration is filled in An error message is issued if that symbol already has some contradictory information The address of the variable is not determined at that time because when a declaration is scanned not all the information about the variables is known The assignment of an address to the variable declared occurs in procedure STORAGE ALLOCATION see Section 11 8 1
115. symbol table Code IS generated for the computation of its initial value and storage in the variable s memory location The values or addresses of the final and increment values are saved in the most recently created DOENTRY record If either of these is an expression then the address is that of a newly allocated temporary location This type of temporary is never released since jumping out of and back into do loops is supported The initial value step amount and final value can be arbitrary expressions which will be coerced to integers The evaluation of these expressions happens only once before the loop is entered so a change in any of the variables that make up the expressions will not affect the number of times the loop is iterated If however the step or final value is a simple integer variable then changing it will affect the number of times the loop is executed The default value of the increment amount is if none is specified 2 t 2 Do loop termination Procedure CLOSEDO generates code for the termination of a do loop It is called by procedure BLOCK each time a Fortran label IS found in the source code and the stack of active is not down to the bottom mark It checks if the label just found corresponds to the Fortran label that terminates the range of a do loop stored 1n the top entry of the po stack If it does code Is generated to increment the control variable and test for the termination of the loop Once code for th
116. t already has It is assumed that contradiction does not exist among the call parameters in a single call 26 Symbol Tables 7 2 The four symbol table routines FSYMBOL FLABELNO FCOMNAME and FEXTNAME can be used for 3 different purposes a to retrieve the pointer to the symbol table entry b to assert information about the symbol as given in the parameters in the call and c to test the properties of the symbol against the values given in the parameters in the call Each of the routines depart from c somewhat and the details are given in their sections following 7 3 The main symbol table The main symbol table stores information about the characteristics of the identifiers used in a block the most important of which are their addresses It also stores the FORmaT labeis A space in memory for saving the address of the FORMAT string is allocated for each FORMAT label see Section 25 It uses records of type SyMBot DIM RECORD CASE INTEGER OF array dimension 6 0 CONSDIM INTEGER constant 1 VARDIM SYMBOL variable END UNCTYPE NOTEXTERNAL EXTERNAL EXTSUBR EXTFUNC STMTFUNC INTRINSTDEXT PARAMPROC SYMBOL PACKED RECORD LSON RSON SYMBOL POINTERS TO SONS NAME THENAME e SYMBOL NAME 6 CHARACTERS LONG STYPE POINTOEFTYPE THE TYPE OF THE VARIABLE IT SHOULD SET TO NONE IF SUBROUTINE NAME WHEREDEF INED INTEGER PROGRAM LINE NUMBER IN WHICH VARIABLE APPEARS
117. t of a logical IF statement After the second part of the logical IF IS complied the U Code iabei IFDEST is generated and IFDEST is reset to 1 Note that because the second part is processed as an independent statement other statement processing procedures cannot assume that the iexemes for the statement start at position 1 23 2 Arithmetic IF The arithmetic expression in the first part of this IF statement is processed by calling procedure ARITH which will generate the U Code to evaluate the arithmetic expression and put the result on top of the stack Again the outer pair of parentheses is not checked since they are checked inside CLASSIFY Note that because of the Aree way branch two tests have to be made of the value on top of the stack Since the value disappears after a test code is first generated to store the top of stack value in a temporary location Then follows code to make the tests and do the jumps The form of the U Code generated is Fortran IF 943 10 20 30 U Coda 100 J M1 504 36 sload varlablr J LDC 3 36 3 load constant 3 ADO J compute 243 NSTR J M 74 72 36 result LDC 3 36 0 GEQ J scompare result with 0 11001 jump to statement 10 lt 0 LDC J 36 0 LOD JM D 36 lead result back NEQ J scompare result with 0 again FJP L1002 sjump to statement 20 if 20 UJP L1003 otherwise jump to statement 30 74 24 24 The PRINT Statement The syntax of this statement is based on the wa
118. t of execution of any Fortran program Therefore a call to FILEI 31 is always generated at the beginning of a Fortran program This initializes the file table which describes the status of each file or device All of them are assumed to be closed The file for the output of execution error messages is opened An error flag for the I O run time routines is initialized 26 1 2 Initiaiization of single I O statement One call to an initialization routine before executing each READ WRITE statement is required before any data transmission call can be made READI 828 WRI 1825 Parameters integer device number and address of FORMAT string The device or file as the case may be is opened if not already opened in the corresponding mode In output the cursor to the I O buffer is initialized In input the first line is read into the I O buffer If the FORMAT pointer is not NIL unformatted I O the variables for processing the Format string are initialized 26 1 3 Data transmission Each call transmits one value using one entry from the FORMAT description These 115 may be embedded in lwps within the calling program such loops being invisible to the routines READY839 WRI TV027 Parameters address of data value size of data value in bytes and coded type of data value integer 1 real 2 logical These routines scan the FORMAT string untii the next I O field is found and service the 78 Read and Write Statements
119. t or statement function declaration since keywords such as DO and GoTo are legal variable names If the statement is of the form identifier anything or identifier anything anything then it is one of the two In the second case if the symbol is a dimensioned array all pmwENsION statements must occur before all statement function declarations then the statement is an assignment statement otherwise it is a statement function declaration If the statement is not an assignment statement or a statement function then the first lexeme of the statement is compared with all keywords of the same length Normally the statement type is determined right there The oniy exceptions are For INTEGER REAL COMPLEX Or LOGICAL the next lexeme is checked to see if it is the identifier runction and the lexeme further down an identifier since FUNCTION can be used as the name of a variable For pousLe the next lexeme is checked to make sure it is the identifier PRECISION For BLOCK the next lexeme is checked to make sure it is DATA For IF CLASSIFY determines whether the statement is an arithmetic or logical IF An IF statement is an arithmetic IF if it is of the form IF anything number anything Otherwise it is a logical IF While scanning between the parentheses both in this case and while checking to see if the statement is an assignment statement it is necessary to keep track of the number of left and right parentheses in order
120. t value it will be changed to the asserted value which is undesirable in some cases When the check is for the entry to have the implicit value this does not work since the implicit value in the call parameter specifies no action Thus it is necessary sometimes to retrieve the pointer and then make the comparison explicitly If STORAGE ALLOCATION has already been called i e when processing the executable part of a program unit FSYMBOL allocates space for new variables not previously declared using procedure SIMPLE STORAGE If no allocation is desired e g when testing that a statement function name has not previously been declared as a variable BUILDSYMBOL should be used to retrieve the pointer rather than FSYMBOL Field S EXPLICIT is set to true whenever STYPE has been asserted in a call FSYMBOL will automatically infer a symbol to be EXTFUNC if it is both typed and declared EXTERNAL See Section 15 2 regarding the __FUNCSUBR field 7 4 The label number table Both statement labels and FORMAT labels are entered into this table For each statement label it also stores the U Code label associated with it This association is fixed the first time the Fortran label occurs in the program unit when the new table entry is created The position of the 28 Symbol Tables 7 4 label in the statement i e whether it is on the left hand side 100 X 1 or the right hand side GOTO 188 is kept in the table The label number table is
121. tain the information about the entry procedures and then generates the U Code for them after the program unit is processed Also the jump table has to be put at the end of the muitientry procedure since the number of entries is not known until that point The entry point identifiers are entered in the external name table since they are regarded as user defined subprograms to the rest of the program 18 2 Global storage of parameter addresses In order to preserve the identities of actual parameters during the time that the procedure IS not active the parameter addresses are stored in space specially allocated for the multiple entry subprogram dummy arguments in the global storage level level 1 During processing of the body of the program unit the symbol tabie entries of the dummy arguments indicate these addresses 18 2 Multiple Entry Subprograms 6l The addresses of actual parameters are transmitted to the entry procedures n calls to entry points The entry procedures keep the call parameters in their own storage level level 4 Before calling the multientry procedure the entry procedures copy the addresses of the actual parameters to the locations in the global storage level and in the multientry procedure the parameters are accessed only through the addresses as stored in the global locations Each dummy argument has a unique location in the global level even if it appears in more than one parameter lists including that of the sub
122. th of the string is stored in LEXSTRLENGTH the number of lexemes in LEXCOUNT the number associated to the first line of the statement in LINENUMBER and the last line in LINENO If an error occurs in the lexer LEXCOUNT is set to 0 Each element of the array texeme is a record with three pieces of information LEXEME T The type of the lexeme 2 LEXEME F The index in LEXSTRING of the first character of this lexeme 3 LEXEME L The index of the last character of this lexeme For example if the identifier COMMON occurs in columns 7 to 12 and it is the first lexeme of the statement the label is not counted as a lexeme then the entries in LEXEME will be LEXEME 1 T IDENTIFIER LEXEME 1 F 7 LEXEME J L 12 4 2 Lexemc types A lexeme is defined to be one of the following items name description PLUS sign MINUS esign STAR SLASH EXPONENT an LPAREN RPAREN EQUALS gt LE LT GE GT SE LT GE GT EQ NE EQ NE ANOOP OROP ANO OR NOTOP NOT REALCON a Fortranreal constant not including preceding sign OPCON double precision const not including preceding sign INTEGERCON an integer constant not including sign STR I NGCON quoted or Hollerith constant TRUECON true FALSECON false IDENTIFIER a sequence of characters the first of which must be a letter and the rest may be letters or numbers 20 Lexer 4 2 EXPLMARK VUOTMARK NUMS IGN DOT DOLS IGN PERC
123. the first 6 characters of the next non comment line will be in cot1T06 Each line is padded with blanks so that it always is 72 plus a multiple of 66 characters in length After a statement is read in LEXSTRLENGTH will contain the number of characters in LEXSTRING At this point LEXSTRING is aiso written to the U Code file by procedure PRINT LEXSTRING After LEXER calls GETSTATEMENT it checks to see if the statement returned consists only of blanks If it does it calls GETSTATEMENT again In this way blank lines are allowed Next it checks to see if the first 6 characters of LEXSTRING contain a label If it does this label IS converted to an integer and stored in the global variable LABNO 4 4 Scanning the statement Next the array LEXEME is filled with lexemes that are recognized through a case statement based on the first characters of the lexemes inside a WHILE loop that traverses the LEXSTRING array The procedure NEXTCHAR IS generally used to get the next character But since it skips blanks it is not used in processing identifiers numbers and keywords 4 4 Lexer 21 If the first character of the lexeme is a regular Fortran character other than a letter digit single quote or dot then the lexeme type is set to that character In the case of an asterisk the next character must be checked to see if it is a double asterisk If it is a digit then the procedure SKIPDIGITSTRING finds the last digit If the digit string IS followed
124. the routine FCOMNAME during storage allocation PROCEDURE FCOMNAME VAR CPOINTER POINTCOMNAME CONAME THENAME LEVEL is initialized inside CLEARCOMNAME immediately after the entry is created PTRCOMLIST which points to a linked list of variables is built when processing the declarations of the corresponding COMMON area At the beginning of each program unit the field PTRCOMLIST of ail entries is set to NIL When an entry is first created for a common area name LENGTH is set to the value given by 7 5 Symboi Tables 29 global variable COMMONSIZ This variable has a default value and is set by the option 512 At the end of processing a COMMON statement this variable is reset to 0 When space IS allocated the first time for a common area if the actual allocated area is greater than that specified in LENGTH this field is changed to the larger value Otherwise the amount of space allocated is equal to the value of LENGTH Thereafter its value is fixed STADDR initially set to 1 indicates whether a memory block has been allocated to the common area in a previous program unit If yes it gives the start address of this block FCOMNAME is called only in the common statement processing procedure It only returns the pointer to the common table entry During storage allocation the entries are accessed by traversing the tree 7 6 The external name table The external name table keeps track of the existence and calls of
125. thmetic expressions are constants variables function calls or other arithmetic expressions connected by arithmetic operators If the logical operators AND and NOT are used in arithmetic expressions the respective bitwise operations on the operands are implied Since the type of an expression may not be known until after the expression has been compiled as in the case of an expression which is the parameter in a function call the compilation is always started by calling the highest level logical expression procedure called ARITH ARITH expects the global lexeme pointer LXC to be pornting to the beginning of the expression when it is called and leaves it pointing to the lexeme after the expression All the intermediate parsing procedures return the data type of the parts of the expression which they parse to their next higher level calling procedure and ARITH returns the data type that will be left on the top of the stack when the whole expression is evaiuated Bitwise operations are done in U Code using the set operations with OR corresponding to set union UNI and AND corresponding to set Intersection INT The NOT operation IS handled using the set difference operation DIF between a full word of 15 and the NOT operand 15 1 Syntax The syntax for expressions is as follows logical expression logical term OR logical termi logical term logical factor AND logical factor logical factor NOT
126. to allow for nested parentheses If the current statement already has error discovered in LEXER it wilt be classified as KNONE When CLASSIFY finds any erroneous construct it will also classify the current statement as XNONE CLASSIFY outputs no error message 6 23 6 Main block The processing of an input user program is controlled by the main procedure and procedure BLOCK The control structures of these two procedures are as follows 6 1 Main procedure Call INITCOMPILER to initialize everything 2 Call BLOCK to process the main program unit 3 While there are more subprograms do a call FUNC STMT SUBR_STMT or BLKDATASTMT to process the heading of the next program unit b call BLock to process body of program unit 4 Call VARINITIALIZATION to generate the code to initialize the variables that should be initialized and to load FORMAT specifications into memory 5 Generate the bodies of the level 1 to 3 dummy U Code procedures 6 2 Procedure BLOCK 1 a Call LEXER to get the first statement of the current program unit b Call CLASSIFY to determine the statement type 2 If first statement is the IMPLICIT statement a call IMPLDECL to process it b call LEXER to get the next statement c call CLASSIFY to determine the statement type 3 While there are more declaration statements roRMaT or ser statements do a call the appropriate routine to process it b call LEXER to get the next statement c
127. ts or by the ASSIGN statement for statement labels An array element can be used for the variable Bitwise operations_on variables The bitwise AND OR and NOT operations on integer real and complex values are allowed The operands are checked for type compatibility as in the case of other arithmetic operations ntrinsic and rd functions When the intrinsic and standard functions are used their types are not affected by implicit or explicit typings 3 17 3 Overall Organization 3 1 Structural scheme UFORT s processing of an input user program is driven by its main procedure and procedure BLOCK which invoke the various modules either directly or indirectly The organization of UFORT is based on these modules It is structured according to the relationships among the various modules Despite its length about 9000 lines UFORT is easily understood once its structure is revealed When the compiler processes a given program statement it either generates code from it or remembers the information given in the program text by building some internal structure which invariably is a linked list of a particular type A module in UFORT satisfies at least one of the following conditions It scans and processes a type of statement in the user program 2 It scans and processes a specific construct which occurs in more than one type of statement These are a the arithmetic expression processor b the procedures for loading
128. y the Pascal standard output routines are called so the processing of this statement is done in a straightforward manner After generating the call co the Pascal output initialization routine a loop is entered which iterates for the list of output Items in each iteration arrra is first called to leave the expression on top of the stack The following lexemes are scanned co check for any specification of output field width The corresponding Pascal output routine is then called according to the type of the expression evaluated string integer boolean reai or complex 24 1 Example Fortran U Code PRINT Xs 5 1 C2 3 2 LDA 117 9 lead address of file OUTPUT CSP LCA Loc LOC J J CSP A J J A gt ww xv H m 8 X NN A m write X LOC LDC CSP LCA Loc LOC CSP LOC LOC STR LOC LOC CSP R 41 write real part 100 M 7472 36 back Imagrnary part LDC J 36 14 Loc J 36 9 CSP A 41 CSP 11 CSP PEIO 10 2201012000 5 w m swrite integer 5 Cs woo o A m rite Cs an PNW M 74 72 36 store imaginary part temporarily write imaginary part 25 75 2 5 FORMAT Statement Processing Format Statements are processed in two stages First the FORMAT statement is scanned and the information for the FORMAT statement IS entered in a created romMTLIST record The list of these records
Download Pdf Manuals
Related Search
Related Contents
User Manual SERVICE MANUAL MNL,SPA,INEX RR BRAND-EU,V2.4 20150304 Portrait Professional 11 AVF LF000 flat panel wall mount Manuel d`utilisation Thermomètre d`enregistrement de données à 512-CB-056-00 MB-056 Coupler Brake Inst Copyright © All rights reserved.
Failed to retrieve file