Open64 (mfef90, whirl2f, and IR tools)
TAG: version-openad; SVN changeset: 916
|
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 // proc_gen.cxx 00038 // 00039 // Generate an interface to create a new PROC (actually just an enum of 00040 // all the processors). 00041 // 00043 // 00044 00045 #include <stdio.h> 00046 #include <stdlib.h> 00047 #include <string.h> 00048 #include <stdarg.h> 00049 00050 #include "gen_util.h" 00051 #include "proc_gen.h" 00052 00053 static const char * const interface[] = { 00054 "/* ====================================================================", 00055 " * ====================================================================", 00056 " *", 00057 " * Description:", 00058 " *", 00059 " * A description of the PROC (actually just an enum of all the processors).", 00060 " * The description exports the following:", 00061 " *", 00062 " * typedef (enum) PROCESSOR", 00063 " * Contains all the target processors. Their names have the form", 00064 " * PROCESSOR_<name>.", 00065 " *", 00066 " * const PROCESSOR PROCESSOR_UNDEFINED", 00067 " * Useful value guaranteed not to be a valid PROCESSOR.", 00068 " *", 00069 " * const int PROCESSOR_count", 00070 " * Gives the number of processors.", 00071 " *", 00072 " * PROCESSOR PROCESSOR_Value", 00073 " * The current processor.", 00074 " *", 00075 " * const char* PROCESSOR_Name(PROCESSOR topcode)", 00076 " * Returns a name for the given PROCESSOR.", 00077 " *", 00078 " * ====================================================================", 00079 " * ====================================================================", 00080 " */", 00081 NULL 00082 }; 00083 00084 00086 static char* Dot_To_Line(const char* str) 00088 // Copy <str> to newly allocated memory, replacing "." with "_" and return 00089 // the result. 00091 { 00092 char *result = (char*) malloc(strlen(str)+1); 00093 const char *s; 00094 char *r; 00095 00096 for (s = str, r = result; *s != 0; ++s, ++r) { 00097 if (*s == '.') 00098 *r = '_'; 00099 else 00100 *r = *s; 00101 } 00102 00103 *r = 0; 00104 00105 return result; 00106 } 00107 00108 00110 void PROC_Create (const char *proc_name, ...) 00112 // Emit the targ_proc header and c files. 00114 { 00115 FILE* hfile = fopen("targ_proc.h","w"); 00116 FILE* cfile = fopen("targ_proc.c","w"); 00117 FILE* efile = fopen("targ_proc.Exported","w"); 00118 char *instruction_name; 00119 int instruction_count = 0; 00120 va_list ap; 00121 00122 fprintf(cfile,"#include \"targ_proc.h\"\n"); 00123 00124 Emit_Header (hfile, "targ_proc", interface); 00125 00126 fprintf(hfile,"typedef enum processor {\n"); 00127 fprintf(cfile,"\nstatic const char* const processor_names[] = {\n"); 00128 00129 va_start(ap,proc_name); 00130 while ((instruction_name = va_arg (ap, char *)) != NULL) { 00131 fprintf(hfile," PROCESSOR_%s,\n", Dot_To_Line(instruction_name)); 00132 fprintf(cfile," \"%s\",\n", instruction_name); 00133 00134 instruction_count++; 00135 } 00136 va_end(ap); 00137 00138 fprintf(hfile," PROCESSOR_UNDEFINED\n" 00139 "} PROCESSOR;\n"); 00140 fprintf(cfile," \"UNDEFINED\"\n" 00141 "};\n"); 00142 00143 fprintf(hfile,"\n#define PROCESSOR_count %d\n", instruction_count); 00144 fprintf(hfile,"\nextern PROCESSOR PROCESSOR_Value;\n"); 00145 fprintf(cfile,"\nPROCESSOR PROCESSOR_Value = PROCESSOR_UNDEFINED;\n"); 00146 fprintf(hfile,"\nextern const char* PROCESSOR_Name(PROCESSOR proc);\n"); 00147 fprintf(efile,"PROCESSOR_Name\n"); 00148 fprintf(cfile,"\nconst char* PROCESSOR_Name(PROCESSOR proc)\n" 00149 "{\n" 00150 " return processor_names[(int)proc];\n" 00151 "}\n"); 00152 00153 Emit_Footer (hfile); 00154 }