CS4:COMP LN4 COMPILER WRITING AIDS IN EMAS These fall into three categories:- 1) Low level debugging aids needed when compilers are faulty. 2) The Compile and Put routines. 3) Simulation of test programs. Low Level Aids ______________ Each command in EMAS is normally loaded and executes on the User Stack. The GLA and stack of the previous command is overwritten. If a command or program terminates in great disorder the stack can not be inspected by a subsequent command. There are thus some special comands for this purpose. Command Structure _________________ Each command has a '#' as its first character. Note that 'hash commands' (as they are known) do not invoke the loader, and there is no one-to-one correspondence between each hash command and an external routine. The parameters to a hash command often include numeric constants. These can be typed as decimal numbers in the normal way, or as hexadecimal numbers, in which case they should be preceded by an X. Commands may be typed in upper or lower case, or a mixture of both. For example, the following two commands would have the same effect: #SWORD X840000,256 #sword x840000,256 Note that, in all relevant cases, lengths are expressed in bytes. #CONNECT filename This command connects the specified file. If possible, it is connected in write mode, otherwise read mode is used. The connect address is printed in hexadecimal. Filename may describe a member of a partitioned file; in this case the connection mode is always read only. Since a file connected by this command remains connected until explicitly disconnected, it is advisable to do this (using the DISCONNECT command) as soon as any operations on it have been completed. In particular, note that a file connected in write mode will not execute correctly; it must be disconnected first. #DEC value This just prints out value in decimal. #DUMP address,length,.out This dumps the specified area (in hexadecimal and character form) to out. If out is not specified, .LP is assumed. #DUMPFILE filename,offset of start,length,.out This dumps the specified area of the specified file (in hexadecimal and character form) to out. If out is not given, .LP is assumed. The area dumped must lie within the physical limits of the file. #MON This causes statistics to be printed for each Subsystem command; currently, CPU time and page turns are given. The effect of #MON is turned off by #N (see below). #MONLOAD mask This comand is used for monitoring the loader. The bits in mask have the following significance, and may be combined: 2**0 print the name of each file as it is loaded, together with the name of the reference which caused it to be loaded. 2**1 print a map of the areas in each file, as it is loaded. 2**2 print the names and addresses of entry points in each file, as it is loaded. The effect of this command may be cancelled by #MONLOAD 0, or by #N (see below). #N This command just turns off the effect of #MON, #MONLOAD and#SSTOP. It is also useful as a simple method of including comments in an OBEY file, since its effect is usually null (unless other hash comands are being used), and its parameters are ignored. For example: #N this is a comment #PCOM n n must lie in the range 1 to 60. The contents of location n in COMREG are printed out. #PMESS fault number This comand prints out the Subsystem error message associated with fault number. Note that any variant information (that usually set by SETFNAME) will not necessarily be correct. #PVM This command prints a map of the user's virtual machine, giving connect addresses and modes, filenames, etc. The output is always to .OUT. #QUIT Sometimes the Subsystem session directory becomes so corrupt (due to a program error) that normal commands (including STOP and QUIT) no longer work. #QUIT will usually enable log-off under these circumstances. #REGS n The Subsystem records the contents of the machine registers, and the contingency class and subclass, at each program error. A cyclic buffer of the four most recent sets of values is maintained, and may be accessed by using the #REGS command. #REGS 0 (or just #REGS) prints the most recent set; #REGS -1 the set before that; and #REGS -2 and #REGS -3 the remaining sets. #SBYTE address,value This command is used for altering the value of a single byte in virtual memory; the byte must be connected in write mode. The effect of the comand is to set the byte at address to value. #SCOM n,value n must lie in the range 1 to 60. Location n in COMREG is set to value. #SNAP address,length This comand dumps the specified area of virtual memory, in hexadecimal, to .OUT. The amount printed on each line is controlled by the setting of the OPTION ITWIDTH. A further useful command for the baffled compiler writer is:- OBJANAL file,out This performs a full analysis of the object files entries, references and relocations. There can be a lot of output! A useful file is ERCC10:OPOUTS. This has all the IBM mnemonics as constintegers equal to the opcode. It will save you a lot of typing. Similarly SUBSYS: EMAS3SPECS has the routine specs for calling subsystem facilities. The Compile Routine ------------------- The compile routine handles all commands that call compilers and is already set up for Algol. The command connects and selects the source for input and also sets up the listing file and, if specified, the error file. It then searches for and permanently loads the compiler which must have a single entry "ICL9CEZALGOL". (no parameters.) On entering the compiler the following information is left set in COMREG - COMREG (14) work file address (23) the current (listing) stream number (27) the Parm setting (40) the error strains number or -1 (46) the connect address of the source file if it is a simple file or zero Both files have a normal EMAS header where - word 0 -> the first unused byte 1 -> the first useful byte 2 -> the total number of bytes in the file Having completed compilation the compiler is expected to return to COMPILE having set - Comreg(24) = 0 OK = 8 Program has errors = 16 Compiler has collapsed If COMREG(24) = 0 then COMPILE will take COMREG(47) to be the number of statements compiled. If COMREG(24) = 8 then COMREG(47) is the number of errors. COMPILE finishes by putting out the console message "n statements compiled" and deleting the workfile. The parm bits in COMREG(27) signify as follows:- Meaning of Bits in COMREG(27) 2**0 - QUOTES 2**16 - OPT 2**1 - NOLIST 2**17 - MAP 2**2 - NODIAG 2**18 - DEBUG 2**3 - STACK 2**19 - FREE 2**4 - NOCHECK 2**20 - DYNAMIC 2**5 - NOARRAY 2**21 - 'Diag stream set' 2**6 - NOTRACE 2**22 - EBCDIC 2**7 - PROFILE 2**23 - NOLINE 2**8 - IMPS 2**24 - 'Stack size set' 2**9 - INHIBIOF 2**25 - Not used 2**10 - ZERO 2**26 - PARMZ 2**11 - XREF 2**27 - PARMY 2**12 - LABELS 2**28 - PARMX 2**13 - LET 2**29 - MISMATCH 2**14 - CODE 2**30 - 'Jobber mode' 2**15 - ATTR 2**31 - Not used The Put Interface ----------------- The basic idea of the PUT interface is to enable compilers to produce object modules without needing to know the details of object module structure. It also enables a single compiler to generate object files for more than one operating system. On EMAS-A the interface has been extended to resolve the forward jump problem and provide support for switches. The current PUT is a file ERS12:IBMSCE4 which is a partitioned file. The member "put_specs" has the current routine specs for the interface while the object "TRPUTY" has all the tracing features to aid compiler debugging. A separate handout is available to describe PUT. The XA Simulator ---------------- The XA simulator is a most useful tool for investigating problems in small test programs. You will need to extend your searchlist by the command SEARCHDIR ERCLIB:GENERAL and then the command:_ SIM objfile will load objfile ready for simulation. SIM expects to find a main program with entry "S#GO". It can deal with a few common support routines like read symbol, print symbol, read and print etc. If your program accesses the ALGOL support routines you will need to LINK these with the test program before simulation. The command GO starts the simulation although you will normally want to set break points, or track registers before starting. A list of the main features follows:- 370-XA Simulator: Summary of Principal Facilities Breakpoints 1. at instruction address BREAK, B Form BREAK address address may be absolute or code-relative (use C'hexnumber' where hexnumber is required offset) 2. at IMP linenumber BL Form BL number 3. on operation-code BOP Form BOP param where param is an opcode mnemonic or byte or half-word value 4. when contents of a register change BREAKWHEN, BW Form BW regnumber value or become a value Form BW regnumber value 5. when contents of a store location change BREAKWHEN, BW Form BW address value or become a value Form BW address value address may be GLA-relative (use G'hexnumber') or Stack-relative (use S'hexnumber') 6. after n instructions BA Form BA n 6. Single stepping SS, (Can use RETURN key if previous command was SS) Display 1. Virtual store DUMP, DU Form DU address1 address2 or DU address1 bytes addresses may be Code/GLA/Stack-relative (use C/G/S'hexnumber'). address1 may be specified as "@" or "@ +". Use command EDUmp for EBCDIC interpretation 2. General registers REGS, R, GRS Form all regs R specific reg R regnumber range R reg1 reg2 or R reg1-reg2 3. Floating-point registers FPRS, Frs Form as for GRS 4. Code RECode Form REC address1 address2 or REC address1 bytes adresses may be Code-relative (use C'hexnumber') 5. Last instructions executed Listtrace, L Form L or L n where 0