/************************************************************************* * * (c) Copyright 1992,1993,1994 by G & A Technical Software, Inc., * 28 Research Drive, Hampton, Virginia, 23666. * * All Rights Reserved. No part of this software or publication may be * reproduced, stored in a retrieval system, or transmitted, in any form * or by any means, electronic, mechanical, photocopying, recording, or * otherwise without the prior written permission of G & A Technical * Software, Inc. * ************************************************************************* * * Filename: * * Purpose: * * Author: John Burton * * Date: 5/31/94 * ************************************************************************* * * Modification History: * * $Log: s3_symboltable.c,v $ * Revision 2.1 1994/07/08 17:52:27 jcburt * Updated typedefs, defines and function protypes to allow recursive * parsing of pct files. Enabled use of sub-PDT files and scoping of * datasets. Datasets used in a pct must be defined either in the * associated pdt file or the pdt file associated with the direct * ancestors of the current pct file. * * DataSet functions and subroutines now have an additional parameter * passed to them, indicating the number of parameters passed in the * dataset list, i.e. was: function(DataSet **dl) * now: function(int nargs, DataSet **dl) * Parameters passed to the dataset routines from the PCT level are all * still contained in the dataset list, nargs is during the function or * subroutine call from s3_exec_enode * * Revision 2.0.0.1 1994/06/28 18:48:27 jcburt * S3 Version 2.0 Initial Source * * Revision 1.2 1992/12/01 18:33:36 jcburt * added RCS ID character string (rcsid) and RCS Log * ************************************************************************* * * Revision Control Information: * *************************************************************************/ static char rcsid[] = "$Id: s3_symboltable.c,v 2.1 1994/07/08 17:52:27 jcburt Exp $"; static char rcsrev[] = "$Revision: 2.1 $"; /************************************************************************* * * Include Files * *************************************************************************/ #include #include #include "s3_defines.h" #include "s3_typedefs.h" #include "s3_externals.h" #include "s3_globals.h" #include "s3_dataset_routines.h" /************************************************************************* * * Global Variables * *************************************************************************/ #define MAX_DEPTH 64 typedef struct symbol_table_stack ST_stack; typedef struct symbol_table_stack { ST_stack *previous; ST_entry **symbol_table; } SymbolTableStack; static SymbolTableStack *current_sts; static ST_entry **Symbol_Table; static ST_entry **Symbol_Table_List[MAX_DEPTH]; static int s_t_list_top = 0; /************************************************************************* * * Module: * * Description: * * Syntax: * * Inputs: * * Outputs: * * Returns: * * Modules Called: * *************************************************************************/ ST_entry *s3_create_ST_entry(char *name) { ST_entry *entry; int size; size = sizeof(ST_entry); entry = (ST_entry *)xmalloc(size); if(name != NULL) entry->ss.name = strsave(name); entry->ss.type = NOTYPE; return entry; } /************************************************************************* * * Module: * * Description: * * Syntax: * * Inputs: * * Outputs: * * Returns: * * Modules Called: * *************************************************************************/ int s3_get_index(char *key) { unsigned int sum = 0; char *k = key; while(*k) sum = (*k++ - 'A') + (59 * sum); return (sum % MAX_ST_ENTRIES); } /************************************************************************* * * Module: * * Description: * * Syntax: * * Inputs: * * Outputs: * * Returns: * * Modules Called: * *************************************************************************/ ST_entry *s3_lookup_symbol(char *symbol) { st_ptr temp; int i; if((temp = s3_get_symbol(symbol)) == NULL) temp = s3_add_symbol(symbol); return temp; } /************************************************************************* * * Module: * * Description: * * Syntax: * * Inputs: * * Outputs: * * Returns: * * Modules Called: * *************************************************************************/ ST_entry *s3_add_symbol(char *symbol) { int i; ST_entry *curr,*prev,*node,*temp; s3_dprint("s3_add_symbol: adding %s\n",symbol); if(!CaseSensitive) for(i=0;iss.name))) { prev = curr; curr = curr->ss.next; } if(curr != NULL) temp = NULL; else { temp = s3_create_ST_entry(symbol); prev->ss.next = temp; } if(temp == NULL) s3_dprint("s3_add_symbol: unable to add %s\n",symbol); } return temp; } /************************************************************************* * * Module: * * Description: * * Syntax: * * Inputs: * * Outputs: * * Returns: * * Modules Called: * *************************************************************************/ ST_entry *s3_search_symbol_table(char *symbol, ST_entry **symbol_table) { int i,found; st_ptr temp,node; s3_dprint("s3_search_symbol_table: symbol_table = %x\n",symbol_table); s3_dprint("s3_search_symbol_table: symbol = %s\n",symbol); if(!CaseSensitive) for(i=0;iss.name))) temp = temp->ss.next; return temp; } /************************************************************************* * * Module: * * Description: * * Syntax: * * Inputs: * * Outputs: * * Returns: * * Modules Called: * *************************************************************************/ ST_entry *s3_get_symbol(char *symbol) { int i,found; st_ptr temp,node; SymbolTableStack *sts; sts = current_sts; temp = s3_search_symbol_table(symbol,sts->symbol_table); while((sts)&&((temp = s3_search_symbol_table(symbol,sts->symbol_table)) == NULL)) sts = sts->previous; if(temp) s3_dprint("s3_get_symbol: symbol = %s, temp->ss.name = %s",symbol,temp->ss.name); return temp; } /************************************************************************* * * Module: * * Description: * * Syntax: * * Inputs: * * Outputs: * * Returns: * * Modules Called: * *************************************************************************/ ST_entry *s3_global_get_symbol(char *symbol) { int i,found; ST_entry *temp,*node; ST_entry **symbol_table; i = s_t_list_top - 1; while((i>=0)&&((temp = s3_search_symbol_table(symbol,Symbol_Table_List[i])) == NULL)) i--; if(temp) s3_dprint("s3_get_symbol: symbol = %s, temp->ss.name = %s",symbol,temp->ss.name); return temp; } /************************************************************************* * * Module: * * Description: * * Syntax: * * Inputs: * * Outputs: * * Returns: * * Modules Called: * *************************************************************************/ int s3_del_symbol(char *symbol) { int ndx; ST_entry *entry, *prev, *temp; prev = NULL; ndx = s3_get_index(symbol); temp = Symbol_Table[ndx]; while((temp)&&(strcmp(symbol,temp->ss.name))) { prev = temp; temp = temp->ss.next; } if(temp == NULL) return FALSE; if(prev == NULL) Symbol_Table[ndx] = temp->ss.next; else prev->ss.next = temp->ss.next; xfree(temp); return TRUE; } /************************************************************************* * * Module: * * Description: * * Syntax: * * Inputs: * * Outputs: * * Returns: * * Modules Called: * *************************************************************************/ ST_entry **s3_create_symbol_table() { int i; ST_entry **temp; temp = (ST_entry **)xcalloc(MAX_ST_ENTRIES,sizeof(ST_entry)); for(i=0;isymbol_table = symbol_table; sts->previous = current_sts; current_sts = sts; Symbol_Table = symbol_table; s3_dprint("s3_push_symbol_table: symbol_table = %x\n",symbol_table); } /************************************************************************* * * Module: * * Description: * * Syntax: * * Inputs: * * Outputs: * * Returns: * * Modules Called: * *************************************************************************/ void s3_pop_symbol_table() { SymbolTableStack *sts; sts = current_sts; s3_dprint("s3_pop_symbol_table: symbol_table = %x\n",sts->symbol_table); current_sts = current_sts->previous; Symbol_Table = current_sts->symbol_table; xfree(sts); } /************************************************************************* * * Module: * * Description: * * Syntax: * * Inputs: * * Outputs: * * Returns: * * Modules Called: * *************************************************************************/ void s3_init_symbol_table() { int nusr; int i,ndsr; ST_entry *entry; ST_entry **temp; temp = s3_create_symbol_table(); s3_push_symbol_table(temp); ndsr = sizeof(ds_routines)/sizeof(ststr); for(i=0;iss.type = ds_routines[i].type; entry->en.function = ds_routines[i].function; entry->en.NDS = ds_routines[i].NDS; } } void s3_init_user_symbols() { int i,nusr; ST_entry *entry; extern ststr user_routines[]; extern int s3_n_user_routines(); if((nusr = s3_n_user_routines()) > 0) { Static_Link = TRUE; for(i=0;ien.type = user_routines[i].type; if(entry->en.type == PNODE) entry->pn.filename = (char *)user_routines[i].function; else entry->en.function = user_routines[i].function; entry->en.NDS = user_routines[i].NDS; } } } } /************************************************************************* * * Module: * * Description: * * Syntax: * * Inputs: * * Outputs: * * Returns: * * Modules Called: * *************************************************************************/ void s3_display_dataset(DataSet *ds, FILE *fp) { int i,j,k,l,m,n; int maxx; byte *data; char *cdata; int *idata; float *rdata; double *ddata; if(ds->name != NULL) fprintf(fp,"Name = %s\n",ds->name); else fprintf(fp,"Temporary DataSet\n"); fprintf(fp,"START = %x\n",ds->start_check[0]); fprintf(fp,"STOP = %x\n",ds->stop_check[0]); fprintf(fp,"NDIMS = %d\n",ds->NDIMS); maxx = 0; if(ds->NDIMS > 0) { fprintf(fp,"dimlist[0] = %d\n",ds->dimlist[0]->co.value); maxx = ds->dimlist[0]->co.value; for(i=1;iNDIMS;i++) { fprintf(fp,"dimlist[%d] = %d\n",i,ds->dimlist[i]->co.value); maxx *= ds->dimlist[i]->co.value; } } fprintf(fp," # elements = %d \n",maxx); fprintf(fp," type = %x \n",ds->type); switch(ds->type) { case BYTE : fprintf(fp," type => BYTE\n"); break; case STRING : fprintf(fp," type => STRING\n"); break; case CHAR: fprintf(fp," type => CHAR\n"); break; case INT : fprintf(fp," type => INTEGER\n"); break; case REAL : fprintf(fp," type => REAL\n"); break; case DREAL: fprintf(fp," type => DOUBLE\n"); break; case COMP : fprintf(fp," type => COMPLEX\n"); break; case DCOMP: fprintf(fp," type => DOUBLE COMPLEX\n"); break; } data = ds->d.data; cdata = ds->d.ch; idata = ds->d.in; rdata = ds->d.fl; ddata = ds->d.db; fprintf(fp,"ptr to 1st value = %p\n",data); fprintf(fp,"first value = "); switch(ds->type) { case BYTE : fprintf(fp,"%c, ",*cdata); break; case STRING : fprintf(fp,"%s",cdata); break; case CHAR : fprintf(fp,"%s",cdata); break; case INT : fprintf(fp,"%d, ",*idata); break; case REAL : fprintf(fp,"%g, ",*rdata); break; case DREAL: fprintf(fp,"%g, ",*ddata); break; case COMP : fprintf(fp,"(%g, %g) ",*rdata++,*rdata); break; case DCOMP: fprintf(fp,"(%g, %g) ",*ddata++,*ddata); break; } fprintf(fp,"\n"); } /************************************************************************* * * Module: * * Description: * * Syntax: * * Inputs: * * Outputs: * * Returns: * * Modules Called: * *************************************************************************/ void s3_display_pnode(Pnode *pn, FILE *fp) { int i; fprintf(fp,"PCT node name = %s\n",pn->name); fprintf(fp," modified = %d\n",pn->modified); fprintf(fp," count = %d\n",pn->count); fprintf(fp," qtime = %lg\n",pn->qtime); fprintf(fp," EOI = %d\n",pn->EOI); fprintf(fp," EOL = %s\n",pn->EOL); fprintf(fp," filename = %s\n",pn->filename); fprintf(fp," description = %s\n",pn->description); fprintf(fp," elkey = %s\n",pn->elkey); fprintf(fp," NE = %d\n",pn->NE); fprintf(fp," elist = \n"); for(i=0;iNE;i++) fprintf(fp," %d => %s\n",i,pn->elist[i]->en.name); fprintf(fp," NDS = %d\n",pn->NDS); for(i=0;iNDS;i++) fprintf(fp," %d => %s\n",i,pn->elist[i]->ds.name); } /************************************************************************* * * Module: * * Description: * * Syntax: * * Inputs: * * Outputs: * * Returns: * * Modules Called: * *************************************************************************/ void s3_display_enode(Enode *en, FILE *fp) { int i; fprintf(fp,"EXE node name = %s\n",en->name); switch(en->type) { case CSUBR : fprintf(fp," type = CSUBR\n"); break; case CFUNC : fprintf(fp," type = CFUNC\n"); break; case DSUBR : fprintf(fp," type = DSUBR\n"); break; case DFUNC : fprintf(fp," type = DFUNC\n"); break; case FSUBR : fprintf(fp," type = FSUBR\n"); break; case FFUNC : fprintf(fp," type = FFUNC\n"); break; default : fprintf(fp," type = UNKNOWN\n"); break; } fprintf(fp," modified = %d\n",en->modified); fprintf(fp," count = %d\n",en->count); fprintf(fp," qtime = %lg\n",en->qtime); fprintf(fp," filename = %s\n",en->filename); fprintf(fp," NDS = %d\n",en->NDS); /* for(i=0;iNDS;i++) fprintf(fp," %d => %s\n",i,en->dslist[i]->ds.name); */ } /************************************************************************* * * Module: * * Description: * * Syntax: * * Inputs: * * Outputs: * * Returns: * * Modules Called: * *************************************************************************/ void s3_list_symbol_table(FILE *fp) { int i, j; st_ptr temp; for(i=0;i ",i,temp->ss.name); switch(temp->ss.type) { case PNODE : s3_display_pnode((Pnode *)temp,fp); break; case CFUNC : case CSUBR : case DFUNC : case DSUBR : case FFUNC : case FSUBR : s3_display_enode((Enode *)temp,fp); break; case BYTE : case CHAR : case STRING : case INT : case REAL : case DREAL: case COMP : case DCOMP : fprintf(fp," DATASET \n"); fprintf(fp," Data type = %x\n",temp->ds.type); fprintf(fp," # Dimensions = %d\n",temp->ds.NDIMS); for(j=0;jds.NDIMS;j++) fprintf(fp," Dimension[%d] = %d\n",j,temp->ds.dimlist[j]->co.value); if(temp->ds.d.data == NULL) fprintf(fp," Data is not initialized\n"); else s3_display_dataset((DataSet *)temp, fp); break; case CONST : fprintf(fp," CONSTANT \n"); fprintf(fp," Value = %d\n",temp->co.value); break; default : fprintf(fp," UNKNOWN\n"); break; } if(temp->ss.next) fprintf(fp,"* "); temp = temp->ss.next; } } } /************************************************************************* * * Module: * * Description: * * Syntax: * * Inputs: * * Outputs: * * Returns: * * Modules Called: * *************************************************************************/ void s3_print_exe_profile(FILE *fp) { int i, j, result; int Who = RUSAGE_SELF; double ttime,utime,stime; st_ptr temp; struct rusage RUsage; ttime = 0.0; for(i=0;iss.type) { case CFUNC : case CSUBR : case DFUNC : case DSUBR : case FFUNC : case FSUBR : ttime += temp->en.qtime; break; default : break; } temp = temp->ss.next; } } fprintf(fp,"\n\n\n\n"); fprintf(fp,"Name Type Count Total time (sec) %% time\n"); fprintf(fp,"------------------ ----- ---------- ----------------- ------\n"); for(i=0;iss.count > 0) switch(temp->ss.type) { case OTHER : fprintf(fp,"%-18s OTHER ",temp->ss.name); fprintf(fp,"%10d %17g ",temp->ss.count,temp->ss.qtime); fprintf(fp,"%4g \n",(temp->ss.qtime * 100 / ttime)); break; case PNODE : fprintf(fp,"%-18s PNODE ",temp->ss.name); fprintf(fp,"%10d %17g ",temp->ss.count,temp->ss.qtime); fprintf(fp,"%4g \n",(temp->ss.qtime * 100 / ttime)); break; case CFUNC : fprintf(fp,"%-18s CFUNC ",temp->ss.name); fprintf(fp,"%10d %17g ",temp->ss.count,temp->ss.qtime); fprintf(fp,"%4g \n",(temp->ss.qtime * 100 / ttime)); break; case CSUBR : fprintf(fp,"%-18s CSUBR ",temp->ss.name); fprintf(fp,"%10d %17g ",temp->ss.count,temp->ss.qtime); fprintf(fp,"%4g \n",(temp->ss.qtime * 100 / ttime)); break; case DFUNC : fprintf(fp,"%-18s DFUNC ",temp->ss.name); fprintf(fp,"%10d %17g ",temp->ss.count,temp->ss.qtime); fprintf(fp,"%4g \n",(temp->ss.qtime * 100 / ttime)); break; case DSUBR : fprintf(fp,"%-18s DSUBR ",temp->ss.name); fprintf(fp,"%10d %17g ",temp->ss.count,temp->ss.qtime); fprintf(fp,"%4g \n",(temp->ss.qtime * 100 / ttime)); break; case FFUNC : fprintf(fp,"%-18s FFUNC ",temp->ss.name); fprintf(fp,"%10d %17g ",temp->ss.count,temp->ss.qtime); fprintf(fp,"%4g \n",(temp->ss.qtime * 100 / ttime)); break; case FSUBR : fprintf(fp,"%-18s FSUBR ",temp->ss.name); fprintf(fp,"%10d %17g ",temp->ss.count,temp->ss.qtime); fprintf(fp,"%4g \n",(temp->ss.qtime * 100 / ttime)); break; default : fprintf(fp,"%-18s %5x ",temp->ss.name,temp->ss.type); fprintf(fp,"%10d %17g ",temp->ss.count,temp->ss.qtime); fprintf(fp,"%4g \n",(temp->ss.qtime * 100 / ttime)); break; } temp = temp->ss.next; } } fprintf(fp," ----------------- \n"); fprintf(fp," (Non-PNODE) Total: %17g\n",ttime); result = getrusage(Who, &RUsage); utime = RUsage.ru_utime.tv_sec + ((double)RUsage.ru_utime.tv_usec)*(1e-6); stime = RUsage.ru_stime.tv_sec + ((double)RUsage.ru_stime.tv_usec)*(1e-6); fprintf(fp,"\n\n\n"); fprintf(fp,"* * * * * * * * System Resource Usage * * * * * * * *\n\n"); fprintf(fp,"Total time in User Mode : %10g\n",utime); fprintf(fp,"Total time in Kernel Mode: %10g\n",stime); fprintf(fp,"Maximum resident set size used: %10ld\n",RUsage.ru_maxrss); fprintf(fp,"Shared Memory used: %10ld\n",RUsage.ru_ixrss); fprintf(fp,"Unshared Data Memory used: %10ld\n",RUsage.ru_idrss); fprintf(fp,"Unshared Stack Memory used: %10ld\n",RUsage.ru_isrss); fprintf(fp,"Number of Major Page Faults: %10ld\n",RUsage.ru_majflt); fprintf(fp,"Number of Minor Page Faults: %10ld\n",RUsage.ru_minflt); fprintf(fp,"Number of Swaps: %10ld\n",RUsage.ru_nswap); fprintf(fp,"Number of Block Input Operations: %10ld\n",RUsage.ru_inblock); fprintf(fp,"Number of Block Output Operations: %10ld\n",RUsage.ru_oublock); fprintf(fp,"Number of Messages Sent: %10ld\n",RUsage.ru_msgsnd); fprintf(fp,"Number of Messages Received: %10ld\n",RUsage.ru_msgrcv); fprintf(fp,"Number of Signals Received: %10ld\n",RUsage.ru_nsignals); fprintf(fp,"Number of Voluntary Context Switches: %10ld\n",RUsage.ru_nvcsw); fprintf(fp,"Number of Involuntary Context Switches: %10ld\n",RUsage.ru_nivcsw); }