1 - A transformation is succesfull when

a - a stopsuffix is indicated and met,
    b - the last transformation is included in the transformation path.
2 - Maintains a 'cash' of best paths for all transformation to be executed.
This commit is contained in:
keie 1984-09-10 16:46:13 +00:00
parent 1dba1f5328
commit 1188f0e810

View file

@ -24,24 +24,23 @@
static char rcs_id[] = "$Header$" ; static char rcs_id[] = "$Header$" ;
#endif #endif
enum f_path setpath() { /* Try to find a transformation path */ enum f_path getpath(first) register trf **first ; {
/* Try to find a transformation path */
start_scan(); start_scan();
/* /*
The end result is the setting of the t_do flags The end result is the setting of the t_do flags
in the transformation list. in the transformation list and the chaining of
the consequtive phases with the t_next field.
The list is scanned for possible transformations The list is scanned for possible transformations
stopping at stopsuffix or a combine transformation. stopping at stopsuffix or the last transformation in the list.
The scan flags are set by this process. The scan flags are set by this process.
When a transformation is found, it is compared with When a transformation is found, it is compared with
the last transformation found, if better (or the first) the last transformation found. If better (or the first)
the scan bits are copied to the t_do bits, except for the scan bits are copied to the t_do bits.
the combiner which is remembered in a global pointer.
At the end of all transformations for all files, the combiner
is called, unless errors occurred.
*/ */
try(l_first(tr_list),p_suffix); try(l_first(tr_list),p_suffix);
return scan_end(); return scan_end(first);
} }
/******************** data used only while scanning *******************/ /******************** data used only while scanning *******************/
@ -51,9 +50,6 @@ static int last_ncount; /* The # of non-optimizing transformations
static int last_ocount; /* The # of optimizing transformations in the static int last_ocount; /* The # of optimizing transformations in the
best path sofar */ best path sofar */
static int com_err; /* Complain only once about multiple linkers*/
static trf *final; /* The last non-combining transformation */
static int suf_found; /* Was the suffix at least recognized ? */ static int suf_found; /* Was the suffix at least recognized ? */
@ -63,10 +59,8 @@ start_scan() {
register list_elem *scan ; register list_elem *scan ;
scanlist(l_first(tr_list),scan) { scanlist(l_first(tr_list),scan) {
t_cont(*scan)->t_do=NO ; t_cont(*scan)->t_scan=NO ; t_cont(*scan)->t_scan=NO ;
t_cont(*scan)->t_keep=NO ;
} }
final= (trf *)0 ;
suf_found= 0 ; suf_found= 0 ;
#ifdef DEBUG #ifdef DEBUG
if ( debug>=3 ) vprint("Scan_start\n"); if ( debug>=3 ) vprint("Scan_start\n");
@ -80,7 +74,7 @@ try(f_scan,suffix) list_elem *f_scan; char *suffix; {
register trf *trafo ; register trf *trafo ;
/* Try to find a transformation path starting at f_scan for a /* Try to find a transformation path starting at f_scan for a
file with the indicated suffix. file with the indicated suffix.
If the suffix is already reached or the combiner is found If the suffix is already reached or a combiner is found
call scan_found() to OK the scan. call scan_found() to OK the scan.
If a transformation is found it calls itself recursively If a transformation is found it calls itself recursively
with as starting point the next transformation in the list. with as starting point the next transformation in the list.
@ -113,23 +107,31 @@ try(f_scan,suffix) list_elem *f_scan; char *suffix; {
return ; return ;
} }
} }
if ( trafo->t_combine ) { if ( trafo->t_do ) {
if ( stopsuffix ) { /* We know what happens from this phase on,
trafo->t_scan=NO; so take a shortcut.
if ( *stopsuffix ) return ; */
} else { register trf *sneak ;
if( combiner && sneak= trafo ;
combiner!=trafo && !com_err ){ while( sneak=sneak->t_next ) {
com_err++ ; sneak->t_scan=YES ;
werror("Multiple linkers present %s and %s",
trafo->t_name,combiner->t_name) ;
} else {
combiner=trafo;
}
} }
scan_found() ; scan_found() ;
} else { sneak= trafo ;
while( sneak=sneak->t_next ) {
sneak->t_scan=NO ;
}
return ;
}
if ( trafo->t_linker && stopsuffix && !*stopsuffix ) {
trafo->t_scan=NO ;
scan_found() ;
return ;
}
if ( l_next(*scan) ) {
try(l_next(*scan),trafo->t_out); try(l_next(*scan),trafo->t_out);
} else {
if ( !stopsuffix ) scan_found() ;
} }
trafo->t_scan= NO ; trafo->t_scan= NO ;
} }
@ -139,9 +141,7 @@ werror("Multiple linkers present %s and %s",
scan_found() { scan_found() {
register list_elem *scan; register list_elem *scan;
int ncount, ocount ; int ncount, ocount ;
register trf *keepit ;
keepit= (trf *)0 ;
suf_found= 1; suf_found= 1;
#ifdef DEBUG #ifdef DEBUG
if ( debug>=3 ) vprint("Scan found\n") ; if ( debug>=3 ) vprint("Scan found\n") ;
@ -154,9 +154,6 @@ scan_found() {
if ( debug>=4 ) vprint("%s-",t_cont(*scan)->t_name) ; if ( debug>=4 ) vprint("%s-",t_cont(*scan)->t_name) ;
#endif #endif
if( t_cont(*scan)->t_optim ) ocount++ ;else ncount++ ; if( t_cont(*scan)->t_optim ) ocount++ ;else ncount++ ;
if ( !(t_cont(*scan)->t_combine) ) {
keepit= t_cont(*scan) ;
}
} }
} }
#ifdef DEBUG #ifdef DEBUG
@ -178,10 +175,9 @@ scan_found() {
if ( debug>=3 ) vprint("Better\n"); if ( debug>=3 ) vprint("Better\n");
#endif #endif
scanlist(l_first(tr_list),scan) { scanlist(l_first(tr_list),scan) {
t_cont(*scan)->t_do=t_cont(*scan)->t_scan; t_cont(*scan)->t_bscan=t_cont(*scan)->t_scan;
} }
last_ncount=ncount; last_ocount=ocount; last_ncount=ncount; last_ocount=ocount;
if ( keepit ) final=keepit ;
} }
} }
@ -208,11 +204,13 @@ int satisfy(trafo,suffix) register trf *trafo; char *suffix ; {
return 0 ; return 0 ;
} }
enum f_path scan_end() { /* Finalization */ enum f_path scan_end(first) trf **first ; { /* Finalization */
/* Return value indicating whether a transformation was found */ /* Return value indicating whether a transformation was found */
/* Set the flags for the transformation up to, but not including, /* Set the flags for the transformation up to, but not including,
the combiner the combiner
*/ */
register trf *prev, *curr ;
register list_elem *scan;
#ifdef DEBUG #ifdef DEBUG
if ( debug>=3 ) vprint("End_scan\n"); if ( debug>=3 ) vprint("End_scan\n");
@ -221,17 +219,29 @@ enum f_path scan_end() { /* Finalization */
#ifdef DEBUG #ifdef DEBUG
if ( debug>=2 ) vprint("Transformation found\n"); if ( debug>=2 ) vprint("Transformation found\n");
#endif #endif
prev= (trf *)0 ; *first= prev ;
scanlist(l_first(tr_list),scan) {
curr= t_cont(*scan) ;
if ( curr->t_bscan ) {
if ( prev ) {
prev->t_next= curr ;
if ( curr->t_linker ) prev->t_keep=YES ;
} else {
*first= curr ;
}
if ( curr->t_do ) {
return F_OK ;
}
curr->t_do=YES ;
prev=curr ;
}
}
if ( cpp_trafo && stopsuffix && if ( cpp_trafo && stopsuffix &&
strcmp(stopsuffix,cpp_trafo->t_out)==0 ) { strcmp(stopsuffix,cpp_trafo->t_out)==0 ) {
final= cpp_trafo ; cpp_trafo->t_keep=YES ;
} }
/* There might not be a final when the file can be eaten if ( prev ) {
by the combiner prev->t_keep=YES ;
*/
if ( final ) final->t_keep=YES ;
if ( combiner ) {
if ( !combiner->t_do ) error("Combiner YES/NO");
combiner->t_do=NO ;
} }
return F_OK ; return F_OK ;
} }