Added upstream from http://ftp.icm.edu.pl/pub/loglan/
[loglan.git] / sources / gen / back.c
1 /*     Loglan82 Compiler&Interpreter
2      Copyright (C) 1993 Institute of Informatics, University of Warsaw
3      Copyright (C)  1993, 1994 LITA, Pau
4      
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.
9      
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.
14      
15 =======================================================================
16 */
17
18 #include "glodefs.h"
19
20
21 #ifndef NO_PROTOTYPES
22
23 static void rsnuse(argnr);
24 static void ptnuse(argnr);
25
26 #else
27
28 static void rsnuse();
29 static void ptnuse();
30
31 #endif
32
33
34 static void rsnuse(n) argnr n;{
35
36   /* if no next use - replace by 'nop' and exit to 55 */
37
38   qaddr0 nextuse ;
39   int notrick ;
40   quadruple * curr ; /* gsg for PASCAL WITH translation */
41
42
43   notrick  = ipmem[ tuple[ qcurr ].arg[ n ] ]  ;
44 /*   with tuple[ qcurr ] do begin */
45   {  curr = tuple + qcurr ; /* gsg PASCAL WITH translation */
46
47      nextuse = ipmem[ (curr->arg)[ n ] + 2 ]  ;
48      (curr->nxtuse)[ n ] = nextuse ;
49      if ( (nextuse == 0)  &&  (! slive(notrick)) )
50      {
51        if ((curr->opcode) >  5)   /* #lslopen */
52        {
53          (curr->opcode) = 195 ;
54          nouse  =  TRUE ;
55        }
56      }
57      else
58      { ipmem[ (curr->arg)[ n ] + 2 ] = 0 ;
59        if (ctpoint < nextuse)
60        { /* set slocal */
61          putslocal(TRUE, notrick) ;
62          ipmem[ (curr->arg)[ n ] ] = notrick ;
63        }
64      }
65    } /* with */
66  } /* rsnuse */
67
68
69
70 static void ptnuse(n) argnr n;{
71   qaddr0 nextuse ;
72   int notrick ;
73   quadruple * curr ; /* gsg for PASCAL WITH translation */
74
75 /*  with tuple[ qcurr ] do */
76   { curr = tuple + qcurr ; /* gsg PASCAL WITH translation */
77     nextuse = ipmem[ (curr->arg)[ n ] + 2 ] ;
78     ipmem[ (curr->arg)[ n ] + 2 ] = qcurr ;
79     (curr->nxtuse)[ n ] = nextuse ;
80     if (ctpoint < nextuse)
81     { /* set slocal */
82       notrick = ipmem[ (curr->arg)[ n ] ] ;
83       putslocal(TRUE,notrick) ;
84       ipmem[ (curr->arg)[ n ] ] = notrick ;
85     }
86   } /* with */
87 } /* ptnuse */
88
89
90 void back()
91
92  /* SCANS DOWN THE QUADRUPLES TABLE TO ESTABLISH 'NEXT USE' INFORMATION */
93  /* OPERATIONS YIELDING NOT REFERENCED RESULTS ARE REPLACED BY 'NOP'==195*/
94  /* IF VALUE IS USED AFTER CONTROL TRANSMISSION, THE ATTRIBUTE 'SLOCAL' */
95  /*     IS SET.                                                         */
96
97 /* LABEL 55 ; */  /* EXIST FROM RSNUSE IF NO NEXT USE */
98
99  { quadruple * curr ; /* gsg for PASCAL WITH translation */
100    
101    
102    /* Back */
103
104    ctpoint = qlast + 1 ;
105    qcurr = qlast ;
106                /*  FOR QCURR = QLAST DOWNTO 1 */
107    while (qcurr > 0) /* DO WITH TUPLE [ QCURR ] DO */
108    {   curr = tuple + qcurr ; /* PASCAL WITH translation */
109        nouse  =  FALSE ;
110        switch ( opdescr[ curr->opcode ] )
111        {  case 0 :
112           case 1 : break ;
113
114           case 2 :
115           case 3 :
116           case 4 : ptnuse(1) ;
117                    break ;
118               
119           case 5 :
120           case 6 : ptnuse(1) ;
121                    ptnuse(2) ; 
122                    if ( curr->opcode <= 160 ) 
123                      ctpoint = qcurr ;
124                    break ;
125               
126           case 7 : ptnuse(1) ; 
127                    ptnuse(2) ; 
128                    ptnuse(3) ;
129                    break ;
130               
131           case 8 :
132           case 9 :
133           case 10 : rsnuse(1) ;
134                     break ;
135                
136           case 11 :
137           case 12 : rsnuse(1) ;
138                     if ( nouse )
139                       goto label55 ;
140                     ptnuse(2) ;
141                     break ;
142                
143           case 13 : rsnuse(1) ;
144                     if ( nouse )
145                       goto label55 ;
146                     ptnuse(2) ;
147                     ptnuse(3) ;
148                     break ;
149                 
150           case 14 :
151           case 15 : rsnuse(1) ;
152                     if ( nouse )
153                       goto label55 ;
154                     rsnuse(2) ;
155                     if ( nouse )
156                        goto label55 ;
157                     if ( curr->opcode > 3 )
158                       ptnuse(3) ;
159                     break ;
160                
161        } /* switch */
162        label55 :  ;
163        qcurr-- ;
164    } /* while */
165  } /* back */
166
167
168