1 - callname recognition is moved to rmach.c.
2 - The overall scheme is altered. first, all input files are processed until a combining phase is met. then, all the combining phases are executed, the resulting files are again processed until a combiner (or final) phase is met. 3 - The EM_DIR shell variable can be used to set ack's idea of the EM home directory.
This commit is contained in:
parent
31f96c6850
commit
c504e2e22a
1 changed files with 156 additions and 90 deletions
178
util/ack/main.c
178
util/ack/main.c
|
@ -36,6 +36,7 @@ main(argc,argv) char **argv ; {
|
||||||
register list_elem *elem ;
|
register list_elem *elem ;
|
||||||
register char *frontend ;
|
register char *frontend ;
|
||||||
register int *n_sig ;
|
register int *n_sig ;
|
||||||
|
register trf *phase ;
|
||||||
|
|
||||||
progname=argv[0];
|
progname=argv[0];
|
||||||
varinit();
|
varinit();
|
||||||
|
@ -45,10 +46,24 @@ main(argc,argv) char **argv ; {
|
||||||
} else {
|
} else {
|
||||||
setlist(FRONTENDS);
|
setlist(FRONTENDS);
|
||||||
}
|
}
|
||||||
|
if ( callname ) {
|
||||||
|
if ( machine ) {
|
||||||
|
fuerror("can not produce code for both %s and %s",
|
||||||
|
callname,machine) ;
|
||||||
|
}
|
||||||
|
machine= callname ;
|
||||||
|
}
|
||||||
|
if ( !machine && ! (machine=getenv("ACKM")) ) {
|
||||||
|
#ifdef ACKM
|
||||||
|
machine= ACKM; /* The default machine */
|
||||||
|
#else
|
||||||
|
fuerror("No machine specified") ;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
setlist(machine);
|
setlist(machine);
|
||||||
transini();
|
transini();
|
||||||
scanneeds();
|
scanneeds();
|
||||||
template= mktemp(ACKNAME) ;
|
sprintf(template,TMPNAME,getpid()) ;
|
||||||
if ( n_error && !k_flag ) return n_error ;
|
if ( n_error && !k_flag ) return n_error ;
|
||||||
|
|
||||||
for ( n_sig=sigs ; *n_sig ; n_sig++ ) {
|
for ( n_sig=sigs ; *n_sig ; n_sig++ ) {
|
||||||
|
@ -56,23 +71,47 @@ main(argc,argv) char **argv ; {
|
||||||
signal(*n_sig,SIG_IGN) ;
|
signal(*n_sig,SIG_IGN) ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( !stopsuffix ) {
|
||||||
|
/* Find the linker, needed for argument building */
|
||||||
|
scanlist(l_first(tr_list),elem) {
|
||||||
|
if ( t_cont(*elem)->t_linker ) {
|
||||||
|
linker= t_cont(*elem) ;
|
||||||
|
linker->t_do= YES ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
scanlist ( l_first(arguments), elem ) {
|
scanlist ( l_first(arguments), elem ) {
|
||||||
if ( !process(l_content(*elem)) && !k_flag ) return 1 ;
|
if ( !process(l_content(*elem)) && !k_flag ) return 1 ;
|
||||||
}
|
}
|
||||||
orig.p_path= (char *)0 ;
|
orig.p_path= (char *)0 ;
|
||||||
|
if ( !rts ) rts="" ;
|
||||||
|
setsvar(keeps(RTS),rts) ;
|
||||||
|
|
||||||
if ( !combiner && !stopsuffix ) {
|
|
||||||
/* Call combiner directly without any transformation */
|
|
||||||
scanlist(l_first(tr_list),elem) {
|
scanlist(l_first(tr_list),elem) {
|
||||||
if ( t_cont(*elem)->t_combine ) {
|
phase=t_cont(*elem) ;
|
||||||
combiner= t_cont(*elem) ;
|
if ( phase->t_combine && phase->t_do ) {
|
||||||
|
if ( phase->t_blocked ) {
|
||||||
|
#ifdef DEBUG
|
||||||
|
if ( debug ) {
|
||||||
|
vprint("phase %s is blocked\n",
|
||||||
|
phase->t_name) ;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
disc_inputs(phase) ;
|
||||||
|
continue ;
|
||||||
|
}
|
||||||
|
orig.p_keep=YES ;
|
||||||
|
orig.p_keeps=NO ;
|
||||||
|
orig.p_path=phase->t_origname ;
|
||||||
|
if ( p_basename ) throws(p_basename) ;
|
||||||
|
p_basename= keeps(basename(orig.p_path)) ;
|
||||||
|
if ( !startrf(phase) && !k_flag ) return 1 ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !combiner || n_error ) return n_error ;
|
if ( n_error ) return n_error ;
|
||||||
|
|
||||||
if ( !do_combine() ) return 1 ;
|
|
||||||
|
|
||||||
if ( g_flag ) {
|
if ( g_flag ) {
|
||||||
return do_run();
|
return do_run();
|
||||||
|
@ -87,7 +126,13 @@ char *srcvar() {
|
||||||
|
|
||||||
varinit() {
|
varinit() {
|
||||||
/* initialize the string variables */
|
/* initialize the string variables */
|
||||||
|
register char *envstr ;
|
||||||
|
|
||||||
|
if ( envstr=getenv("EM_DIR") ) {
|
||||||
|
setsvar(keeps(HOME),keeps(envstr)) ;
|
||||||
|
} else {
|
||||||
setsvar(keeps(HOME),keeps(EM_DIR)) ;
|
setsvar(keeps(HOME),keeps(EM_DIR)) ;
|
||||||
|
}
|
||||||
setpvar(keeps(SRC),srcvar) ;
|
setpvar(keeps(SRC),srcvar) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -147,9 +192,14 @@ vieuwargs(argc,argv) char **argv ; {
|
||||||
}
|
}
|
||||||
keeptail(&argp[2]); eaten=1 ;
|
keeptail(&argp[2]); eaten=1 ;
|
||||||
break ;
|
break ;
|
||||||
case '.': if ( rts ) fuerror("Two run-time systems?") ;
|
case '.': if ( rts ) {
|
||||||
rts= &argp[1] ; eaten=1;
|
if ( strcmp(rts,&argp[1])!=0 )
|
||||||
|
fuerror("Two run-time systems?") ;
|
||||||
|
} else {
|
||||||
|
rts= &argp[1] ;
|
||||||
keephead(rts) ; keeptail(rts) ;
|
keephead(rts) ; keeptail(rts) ;
|
||||||
|
}
|
||||||
|
eaten=1 ;
|
||||||
break ;
|
break ;
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
case 'd': debug++ ;
|
case 'd': debug++ ;
|
||||||
|
@ -179,13 +229,6 @@ vieuwargs(argc,argv) char **argv ; {
|
||||||
werror("Unexpected characters at end of %s",argp) ;
|
werror("Unexpected characters at end of %s",argp) ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( !machine && ! (machine=getenv("ACKM")) ) {
|
|
||||||
#ifdef ACKM
|
|
||||||
machine= ACKM; /* The default machine */
|
|
||||||
#else
|
|
||||||
fuerror("No machine specified") ;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -198,60 +241,61 @@ firstarg(argp) register char *argp ; {
|
||||||
} else {
|
} else {
|
||||||
name= argp ;
|
name= argp ;
|
||||||
}
|
}
|
||||||
if ( strcmp(name,"ack")==0 ) return ;
|
callname= name;
|
||||||
if ( strcmp(name,"acc")==0 || strcmp(name,"cc")==0 ) {
|
|
||||||
rts= ".c" ; keephead(rts) ; keeptail(rts) ;
|
|
||||||
return ;
|
|
||||||
}
|
|
||||||
if ( strcmp(name,"apc")==0 || strcmp(name,"pc")==0 ) {
|
|
||||||
rts= ".p" ; keephead(rts) ; keeptail(rts) ;
|
|
||||||
return ;
|
|
||||||
}
|
|
||||||
machine= name;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/************************* argument processing ***********************/
|
/************************* argument processing ***********************/
|
||||||
|
|
||||||
process(arg) char *arg ; {
|
process(arg) char *arg ; {
|
||||||
/* Process files & library arguments */
|
/* Process files & library arguments */
|
||||||
register list_elem *elem ;
|
trf *phase ;
|
||||||
register trf *phase ;
|
|
||||||
int first=YES ;
|
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
if ( debug ) vprint("Processing %s\n",arg) ;
|
if ( debug ) vprint("Processing %s\n",arg) ;
|
||||||
#endif
|
#endif
|
||||||
if ( arg[0]=='-' ) { l_add(&c_arguments,keeps(arg)) ; return 1 ; }
|
|
||||||
p_suffix= rindex(arg,SUFCHAR) ;
|
p_suffix= rindex(arg,SUFCHAR) ;
|
||||||
if ( p_basename ) throws(p_basename) ;
|
|
||||||
orig.p_keep= YES ; /* Don't throw away the original ! */
|
orig.p_keep= YES ; /* Don't throw away the original ! */
|
||||||
|
orig.p_keeps= NO;
|
||||||
orig.p_path= arg ;
|
orig.p_path= arg ;
|
||||||
|
if ( arg[0]=='-' || !p_suffix ) {
|
||||||
|
if ( linker ) add_input(&orig,linker) ;
|
||||||
|
return 1 ;
|
||||||
|
}
|
||||||
|
if ( p_basename ) throws(p_basename) ;
|
||||||
p_basename= keeps(basename(arg)) ;
|
p_basename= keeps(basename(arg)) ;
|
||||||
if ( !p_suffix ) { l_add(&c_arguments,keeps(arg)) ; return 1 ; }
|
|
||||||
/* Try to find a path through the transformations */
|
/* Try to find a path through the transformations */
|
||||||
switch( setpath() ) {
|
switch( getpath(&phase) ) {
|
||||||
case F_NOPATH :
|
case F_NOPATH :
|
||||||
error("Cannot produce the desired file from %s",arg) ;
|
error("Cannot produce the desired file from %s",arg) ;
|
||||||
l_add(&c_arguments,keeps(arg)) ;
|
if ( linker ) add_input(&orig,linker) ;
|
||||||
return 1 ;
|
return 1 ;
|
||||||
case F_NOMATCH :
|
case F_NOMATCH :
|
||||||
if ( stopsuffix ) werror("Unknown suffix in %s",arg) ;
|
if ( stopsuffix ) werror("Unknown suffix in %s",arg) ;
|
||||||
l_add(&c_arguments,keeps(arg)) ;
|
if ( linker ) add_input(&orig,linker) ;
|
||||||
return 1 ;
|
return 1 ;
|
||||||
case F_OK :
|
case F_OK :
|
||||||
break ;
|
break ;
|
||||||
}
|
}
|
||||||
orig.p_keeps= NO;
|
if ( !phase ) return 1 ;
|
||||||
|
if ( phase->t_combine ) {
|
||||||
|
add_input(&orig,phase) ;
|
||||||
|
return 1 ;
|
||||||
|
}
|
||||||
in= orig ;
|
in= orig ;
|
||||||
scanlist(l_first(tr_list), elem) {
|
|
||||||
phase= t_cont(*elem) ;
|
|
||||||
if ( phase->t_do ) { /* perform this transformation */
|
|
||||||
if ( first ) {
|
|
||||||
if ( !nill_flag ) {
|
if ( !nill_flag ) {
|
||||||
printf("%s\n",arg) ;
|
printf("%s\n",arg) ;
|
||||||
}
|
}
|
||||||
}
|
return startrf(phase) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
int startrf(first) trf *first ; {
|
||||||
|
/* Start the transformations at the indicated phase */
|
||||||
|
register trf *phase ;
|
||||||
|
|
||||||
|
phase=first ;
|
||||||
|
for(;;) {
|
||||||
switch ( phase->t_prep ) {
|
switch ( phase->t_prep ) {
|
||||||
|
/* BEWARE, sign extension */
|
||||||
default : if ( !mayprep() ) break ;
|
default : if ( !mayprep() ) break ;
|
||||||
case YES: if ( !transform(cpp_trafo) ) {
|
case YES: if ( !transform(cpp_trafo) ) {
|
||||||
n_error++ ;
|
n_error++ ;
|
||||||
|
@ -269,26 +313,52 @@ process(arg) char *arg ; {
|
||||||
}
|
}
|
||||||
if ( !transform(phase) ) {
|
if ( !transform(phase) ) {
|
||||||
n_error++ ;
|
n_error++ ;
|
||||||
|
block(phase->t_next) ;
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
if ( debug ) {
|
if ( debug ) {
|
||||||
|
if ( !orig.p_path ) {
|
||||||
|
vprint("phase %s failed\n",
|
||||||
|
phase->t_name ) ;
|
||||||
|
} else {
|
||||||
vprint("phase %s for %s failed\n",
|
vprint("phase %s for %s failed\n",
|
||||||
phase->t_name,orig.p_path) ;
|
phase->t_name,orig.p_path) ;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
return 0 ;
|
return 0 ;
|
||||||
}
|
}
|
||||||
first=NO ;
|
first=NO ;
|
||||||
}
|
phase=phase->t_next ;
|
||||||
}
|
if ( !phase ) {
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
if ( debug ) vprint("Transformation complete for %s\n",orig.p_path) ;
|
if ( debug ) vprint("Transformation sequence complete for %s\n",
|
||||||
|
orig.p_path) ;
|
||||||
#endif
|
#endif
|
||||||
if ( !in.p_keep ) fatal("attempt to discard the result file") ;
|
/* No more work on this file */
|
||||||
l_add(&c_arguments,keeps(in.p_path));
|
if ( !in.p_keep ) {
|
||||||
disc_files() ;
|
fatal("attempt to discard the result file") ;
|
||||||
|
}
|
||||||
|
if ( in.p_keeps ) throws(in.p_path) ;
|
||||||
|
in.p_keep=NO ; in.p_keeps=NO ; in.p_path= (char *) 0 ;
|
||||||
|
return 1 ;
|
||||||
|
}
|
||||||
|
if ( phase->t_combine ) {
|
||||||
|
add_input(&in,phase) ;
|
||||||
|
break ;
|
||||||
|
}
|
||||||
|
}
|
||||||
return 1 ;
|
return 1 ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
block(first) trf *first ; {
|
||||||
|
/* One of the input files of this phase could not be produced,
|
||||||
|
block all combiners taking their input from this one.
|
||||||
|
*/
|
||||||
|
register trf *phase ;
|
||||||
|
for ( phase=first ; phase ; phase=phase->t_next ) {
|
||||||
|
if ( phase->t_combine ) phase->t_blocked=YES ;
|
||||||
|
}
|
||||||
|
}
|
||||||
mayprep() {
|
mayprep() {
|
||||||
int file ;
|
int file ;
|
||||||
char fc ;
|
char fc ;
|
||||||
|
@ -316,15 +386,12 @@ scanneeds() {
|
||||||
}
|
}
|
||||||
|
|
||||||
setneeds(suffix,tail) char *suffix ; {
|
setneeds(suffix,tail) char *suffix ; {
|
||||||
register list_elem *elem ;
|
trf *phase ;
|
||||||
register trf *phase ;
|
|
||||||
|
|
||||||
p_suffix= suffix ;
|
p_suffix= suffix ;
|
||||||
switch ( setpath() ) {
|
switch ( getpath(&phase) ) {
|
||||||
case F_OK :
|
case F_OK :
|
||||||
scanlist( l_first(tr_list), elem ) {
|
for ( ; phase ; phase= phase->t_next ) {
|
||||||
phase = t_cont(*elem) ;
|
|
||||||
if ( phase->t_do ) {
|
|
||||||
if ( phase->t_needed ) {
|
if ( phase->t_needed ) {
|
||||||
if ( tail )
|
if ( tail )
|
||||||
add_tail(phase->t_needed) ;
|
add_tail(phase->t_needed) ;
|
||||||
|
@ -332,13 +399,12 @@ setneeds(suffix,tail) char *suffix ; {
|
||||||
add_head(phase->t_needed) ;
|
add_head(phase->t_needed) ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
break ;
|
break ;
|
||||||
case F_NOMATCH :
|
case F_NOMATCH :
|
||||||
werror("\"%s\": unrecognized suffix",suffix) ;
|
werror("\"%s\": unrecognized suffix",suffix) ;
|
||||||
break ;
|
break ;
|
||||||
case F_NOPATH :
|
case F_NOPATH :
|
||||||
werror("incomplete internal specification for %s files",
|
werror("sorry, cannot produce the desired file(s) from %s files",
|
||||||
suffix) ;
|
suffix) ;
|
||||||
break ;
|
break ;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue