1 /* Loglan82 Compiler&Interpreter
2 Copyright (C) 1993 Institute of Informatics, University of Warsaw
3 Copyright (C) 1993, 1994 LITA, Pau
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
16 =======================================================================
24 static void code(void);
25 static void putstmode(stmode,int *);
26 static void segments(void);
31 static void putstmode();
32 static void segments();
36 /* cas dodalem deklaracje zmiennej qcurr */
37 /* DO CELOW URUCHOMIENIOWYCH */
38 static address zmienna;
41 static void putstmode(s,i) stmode s; int *i;{
42 (*i) &= 255 ; /* CLEAR LEFT BYTE */;
58 proclist[ len ] = ipmem[ p-1 ] ;
60 proclist[ len ] = -ipmem[ -p-1 ] ;
62 } while ( ! ( (p == 0) || (len == MAXPROCLIST) )) ;
67 tuple[ qcurr ].arg[ 1 ] = len ;
73 static void segments(){
74 /* COMPLETES THE QUADRUPLES SEGMENT */
75 /* LABEL 100 ; EXIT AT END-MARKER */
76 bool stop ; /* segment completed */
77 /*!!*/ static int op ; /* opcode */ /* static for debugging purposes */
78 /*!!*/ static int a, b ; /* first and second argument */
81 quadruple * curr ; /* gsg for PASCAL WITH translation */
83 while (TRUE) /* EXIT ONLY AT END-MARKER */
85 stop = FALSE ; /* COMPLETE THE SEGMENT */
87 do /* WITH tuple[ qcurr ] DO BEGIN */
88 { curr = tuple + qcurr ; /* gsg PASCAL WITH statement translation */
90 op = next() ; /* Fetch operator */
93 printf(" op = %d\n", op) ;
95 if( op==210 || op==211 ){ printf("|opcode %d|\n",op); getchar(); }
96 if ( (op <= 194) || (op >= 220) )
99 stop = ( ((172 <= op) && (op <= 176)) || ((178 <= op) && (op <= 227)) ) ;
100 /* op in [172..176, 178..227] */
102 /* Now fetch arguments */
103 switch (opdescr[ op ])
109 case 8 : curr->arg[ 1 ] = next() ;
116 case 15 : curr->arg[ 1 ] = next() ;
117 curr->arg[ 2 ] = next() ;
126 case 14 : curr->arg[ 1 ] = next() ;
127 curr->arg[ 2 ] = next() ;
128 curr->arg[ 3 ] = next() ;
133 if ( ((223 <= op) && (op <= 225)) || (op == 227) ) /*op in [223..225,227]*/
137 else /* op in 195..219 */
139 goto label100 ; /* end-marker */
140 else /* SPECIAL CARE OPCODES */
144 if ((op < 201 ) || (op > 204))
151 /* SET DEFAULT VALUES */
152 /*SLOCAL = FALSE; SLIVE = FALSE; SMODE = TEMPVAR; SAP = APINT; */
153 putslocal(FALSE,notrick) ;
154 putslive(FALSE,notrick) ;
155 putstmode(TEMPVAR, ¬rick) ;
156 putsap(APINT,notrick) ;
159 { /* TEMPORARY VARIABLES */
162 case 202 : putsap(APFMTYPE,notrick) ; /* == apreal */
165 case 203 : putsap(APFMPROC,notrick) ;
168 case 204 : /* reference */
169 putsap(APVIRT,notrick) ;
170 putslocal(TRUE,notrick) ;
173 /* declared variables */
174 case 205 : putstmode(VARGLOB, ¬rick) ;
175 putsap(apet(b),notrick) ;
176 putslive(TRUE,notrick) ;
179 case 206 : putstmode(VARMID, ¬rick) ;
180 putsap(apet(b),notrick) ;
181 putslive(TRUE,notrick) ;
184 case 207 : putstmode(VARLOC, ¬rick) ;
185 putsap(apet(b),notrick) ;
186 putslive(TRUE,notrick) ;
189 /* real or integer constant */
190 case 197 : putstmode(REALCONST, ¬rick) ;
191 putsap(APREAL,notrick) ;
195 case 199 : putstmode(INTCONST, ¬rick) ;
198 /* temporary but live */
200 case 208 : putslocal(TRUE,notrick) ;
204 putsap(sap(trck2),notrick) ;
206 else /* live temporary */
207 putslive(TRUE,notrick) ;
208 curr->opcode = 60 ; /* #limove */
209 /* proper opcode will be chosen further */
216 ipmem[ a ] = notrick ;
217 } /* SPECIAL CARE OPCODES */
218 } while ( ! (stop || (qcurr > QMAX)) ) ;
223 back() ; /* establish 'next-use' information */
226 label100: ; /* end-marker : all has been done */
233 /* TRANSFORMS L-CODE TO L'-CODE BY REDUCTION OF NUMBER OF OPCODES */
234 /* ALLOCATES TEMPORARY VARIABLES */
236 /* INSERT 'NONE' INTO THE SYMBOL TABLE */
237 /*cdsw&ail NONE = LMEM-3 ; */
239 /* WITH TRICK.STI DO { */ /* CTRP
245 putsap(APVIRT,notrick) ;
246 putstmode(REALCONST,¬rick) ;
247 putslocal(TRUE,notrick) ;
248 putslive(TRUE,notrick) ;
249 ipmem [ none ] = notrick ;
250 ipmem [ none+1 ] = 0 ; /* --> m [realbase] */
251 ipmem [ none+2 ] = 0 ;
254 /* CLEAR THE DICTIONARY OF LABELS */
256 /* memset(m + fre, (char) 0, (MEMLIMIT - fre + 1) * sizeof(address)) ; */
257 for(zmienna = fre; zmienna <= MEMLIMIT; zmienna ++)
259 /* zerowanie pamieci */
264 /* END OF CODE PREPARING */
268 void main(argc,argv) int argc; char *argv[];{
271 log = fopen("gen.log", "w") ;
273 printf("cannot open dump file\n") ;
277 m = (address *) calloc(sizeof(address), MEMLIMIT + 1) ;
280 puts(" LOGLAN-82 Compiler Version 4.00") ;
281 puts(" January 10, 1993") ;
282 puts(" (C)Copyright Institute of Informatics, University of Warsaw") ;
283 puts(" (C)Copyleft LITA Universite de Pau");
284 puts("\n Pass Two\n") ; fflush(stdout);
285 if(argc < 2){ printf("Usage : %s filename\n",argv[0]); exit(8); }
287 puts("Setting files...") ; fflush(stdout);
290 fre = 2 ; /* SKIP TWO WORDS RESERVED FOR DUMMY VIRT. */
291 m[fre++] = 0 ; /* dsw*//* free == currfile */
292 m[fre++] = 0 ; /* place for file virtual address */ /*dsw*/
293 strings = fre ; /* START STRING AREA */
295 puts("Putting strings...") ; fflush(stdout);
297 putstrings() ; /* WRITE STRINGS INTO MEMORY */
298 realbase = fre ; /* BASE FOR REAL CONSTANTS */
300 puts("Initiating...") ; fflush(stdout);
302 initiate() ; /* READ IPMEM AND OTHER VARIABLES */
305 long seek=ftell(lfile);
307 fseek(lfile,seek,SEEK_SET);
311 puts("Putting reals...") ; fflush(stdout);
313 putreals() ; /* WRITE REAL CONSTANTS INTO MEMORY */
315 puts("Generating prototypes...") ; fflush(stdout);
318 /* PROTOTYPES ARE NUMBERED MAINBLOCK..LASTPROT */
320 temporary = base+fre ;
321 fre += MAXCOMTEMP + 1 ;
323 /* mb removed some unimportant comments to improve readability ; cf text2.gen */
326 puts("Outputing...") ; fflush(stdout);
329 for(zmienna = 0; zmienna < fre ; zmienna ++)
330 printf("M DUMP WORD # %lu VALUE %lu\n",
331 (unsigned long int)zmienna,(unsigned long int)(m[zmienna]));
340 puts("Code preparation...") ; fflush(stdout);
342 code() ; /* CODE PREPARING */
346 puts("Putting debug info...") ; fflush(stdout);
354 puts("Putting prototypes...") ; fflush(stdout);
357 outprot() ; /* PUT PROTOTYPES ONTO THE FILE */
360 /* *((int *)0xccL) = 0x1445 ;*/
363 puts("Generation ok.") ; fflush(stdout);