Open64 (mfef90, whirl2f, and IR tools)  TAG: version-openad; SVN changeset: 916
cwh_mkdepend.cxx
Go to the documentation of this file.
00001 /*
00002 
00003   Copyright (C) 2000, 2001 Silicon Graphics, Inc.  All Rights Reserved.
00004 
00005   This program is free software; you can redistribute it and/or modify it
00006   under the terms of version 2 of the GNU General Public License as
00007   published by the Free Software Foundation.
00008 
00009   This program is distributed in the hope that it would be useful, but
00010   WITHOUT ANY WARRANTY; without even the implied warranty of
00011   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
00012 
00013   Further, this software is distributed without any warranty that it is
00014   free of the rightful claim of any third person regarding infringement 
00015   or the like.  Any license provided herein, whether implied or 
00016   otherwise, applies only to this software file.  Patent licenses, if 
00017   any, provided herein do not apply to combinations of this program with 
00018   other software, or any other product whatsoever.  
00019 
00020   You should have received a copy of the GNU General Public License along
00021   with this program; if not, write the Free Software Foundation, Inc., 59
00022   Temple Place - Suite 330, Boston MA 02111-1307, USA.
00023 
00024   Contact information:  Silicon Graphics, Inc., 1600 Amphitheatre Pky,
00025   Mountain View, CA 94043, or:
00026 
00027   http://www.sgi.com
00028 
00029   For further information regarding this notice, see:
00030 
00031   http://oss.sgi.com/projects/GenInfo/NoticeExplan
00032 
00033 */
00034 
00035 
00036 /* ====================================================================
00037  * ====================================================================
00038  *
00039  *
00040  * Revision history:
00041  *  dd-mmm-95 - Original Version
00042  *
00043  * Description: contains administrative routines invoked from the Cray 
00044  *              FE at initialization and termination of the 
00045  *              compiler and around each program unit. PDGCS_* entry 
00046  *              points plus fei_* routines which deal with procedure
00047  *              initialization and cleanup.
00048  * 
00049  * ====================================================================
00050  * ====================================================================
00051  */
00052 
00053 static char *source_file = __FILE__;
00054 
00055 #ifdef _KEEP_RCS_ID
00056 /*REFERENCED*/
00057 #endif /* _KEEP_RCS_ID */
00058 
00059 #include <ctype.h>
00060 
00061 #include <string.h> /* for memset() */
00062 #include "x_string.h" // for strdup()
00063 
00064 /* sgi includes */
00065 
00066 #include "defs.h"
00067 #include "glob.h"
00068 #include "strtab.h"
00069 #include <sys/types.h>
00070 #include "tracing.h"
00071 #include "cmplrs/make_depend.h"
00072 #include <stdarg.h>
00073 #include "erfe90.h"
00074 
00075 #include "i_cvrt.h"
00076 
00077 /* conversion includes */
00078 
00079 #include  "sgi_cmd_line.h"
00080 #include  "cwh_mkdepend.h"
00081 
00082 
00083 char * mdupdate_file = NULL;
00084 char * mdtarget_file = NULL;
00085 
00086 /* Utility routines for tables */
00087 extern INT32
00088 cwh_next_table_entry( table_p t)
00089 {
00090    if (t->current_size == 0) {
00091       t->ptr = (void**) malloc(sizeof(void *) * TABLE_INCREMENT);
00092       memset(t->ptr, '\0', sizeof (void *) * TABLE_INCREMENT);
00093       t->current_size = TABLE_INCREMENT;
00094    } 
00095 
00096    t->current_idx += 1;
00097    if (t->current_idx >= t->current_size) {
00098       /* reallocate the table */
00099       t->current_size += TABLE_INCREMENT;
00100       t->ptr = (void **) realloc (t->ptr, sizeof (void *) * t->current_size);
00101       memset(t->ptr+(t->current_size-TABLE_INCREMENT),'\0', 
00102             sizeof (void *) * TABLE_INCREMENT);
00103    }
00104    return (t->current_idx);
00105 }
00106 
00107 static table_s name_table = INIT_TABLE;
00108 static table_s used_files_table = INIT_TABLE;
00109 static table_s module_files_table = INIT_TABLE;
00110 
00111 INT32
00112 fei_next_name(INT32 num)
00113 {
00114    /* Look at the name table. If the last pointer is NULL, return it, otherwise
00115     * get the next one.
00116     */
00117    if (TABLE_SIZE(name_table) == 0) {
00118       return (cwh_next_table_entry(&name_table));
00119    }
00120    if (TABLE_TOP(name_table,char *) == NULL) {
00121       return (TABLE_CURRENT_IDX(name_table));
00122    } else {
00123       return (cwh_next_table_entry(&name_table));
00124    }
00125 }
00126 
00127 
00128 /* Add a name to the name table */
00129 extern void
00130 cwh_mkdepend_add_name(INT32 idx, char * name)
00131 {
00132    SET_TABLE_IDX(name_table, idx, ux_strdup(name));
00133 }
00134 
00135 
00136 /* Add to the used_files_table */
00137 
00138 extern void
00139 cwh_add_to_used_files_table(char * name, INT duplicate)
00140 {
00141    INT i;
00142    char *t;
00143 
00144    /* add it to the used files table */
00145    i = cwh_next_table_entry(&used_files_table);
00146    if (duplicate) {
00147       t = ux_strdup(name);
00148    } else {
00149       t = name;
00150    }
00151    SET_TABLE_IDX(used_files_table,i,t);
00152 }
00153 
00154 /* Add to the modules generated table, appending .mod */
00155 extern void
00156 cwh_add_to_module_files_table(char *name)
00157 {
00158    INT i,len;
00159    char * fname;
00160    len = strlen(name);
00161    fname = (char *) malloc(len + 4);
00162    /* Uppercase the string */
00163    for (i = 0; i < len - 1; i++) {
00164       fname[i] = islower(name[i]) ? toupper(name[i]) : name[i];
00165    }
00166    fname[len-1]='.';
00167    fname[len]='m';
00168    fname[len+1]='o';
00169    fname[len+2]='d';
00170    fname[len+3]='\0';
00171    i = cwh_next_table_entry(&module_files_table);
00172    SET_TABLE_IDX(module_files_table,i,fname);
00173 }
00174 
00175 
00176 /*===============================================
00177  *
00178  * fei_add_use_path
00179  *
00180  * Get the name of all MODULEs used.
00181  *
00182  *===============================================
00183  */ 
00184 void
00185 fei_add_use_path(INT32 st_idx,INT32 path_idx,INT32 module_idx)
00186 {
00187    INT i;
00188    
00189    char *path_name;
00190    
00191    path_name = (char *) TABLE_IDX(name_table,path_idx);
00192    cwh_add_to_used_files_table(path_name,FALSE);
00193 }
00194 
00195 
00196 static void makedepend_error(char *fmt, ...)
00197 {
00198     static char makedepend_errbuf[400];
00199     va_list ap;
00200 
00201     va_start(ap,fmt);
00202     vsprintf(makedepend_errbuf, fmt, ap);
00203     va_end(ap);
00204     ErrMsg(EC_Makedepend_Error,makedepend_errbuf);
00205 }
00206 
00207       
00208 extern void
00209 cwh_write_makedepend(void)
00210 {
00211    INT i;
00212    MDhandle h;
00213 
00214    if (mdupdate_file == NULL || mdtarget_file == NULL) return;
00215 
00216    h = MDopen("mfef90",mdupdate_file,mdtarget_file,makedepend_error);
00217 
00218    for (i=0; i <= TABLE_CURRENT_IDX(used_files_table) ; i++) {
00219       MDupdate(h,(char *)TABLE_IDX(used_files_table,i));
00220    }
00221    MDclose(h,NULL);
00222 
00223    for (i=0; i <= TABLE_CURRENT_IDX(module_files_table) ; i++) {
00224       h = MDopen("mfef90",mdupdate_file,(char *)TABLE_IDX(module_files_table,i),NULL);
00225       MDupdate(h,mdtarget_file);
00226       MDclose(h,NULL);
00227    }
00228 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines