Open64 (mfef90, whirl2f, and IR tools)
TAG: version-openad; SVN changeset: 916
|
00001 /* 00002 00003 Copyright (C) 2003 Rice University. 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 */ 00025 00026 #ifndef unparse_target_INCLUDED 00027 #define unparse_target_INCLUDED 00028 /* ==================================================================== 00029 * 00030 * 00031 * Revision history: 00032 * 06-Jun-03 - Original Version 00033 * 00034 * Description: 00035 * 00036 * Runtime tests for the target language are abstracted by this pure 00037 * virtual class. 00038 * 00039 * Specific language unparsers create a derived class that implements the 00040 * tests for target language, and the main routine creates an instance 00041 * of that derived class which is queried as required by the general 00042 * purpose support routines. 00043 * 00044 * This is a work in progress. For now, at least, there is a global 00045 * pointer to this object, to enable incremental conversion of the 00046 * original implementation, which was based on conditional compilation 00047 * depending on the target language. The intent is to eliminate all 00048 * conditional compilation based on "ifdef BUILD_WHIRL2x". 00049 * Eventually, it might be better to have this object passed through the 00050 * unparser as a parameter, or to make the unparser itself a derived class 00051 * of this class. 00052 * ==================================================================== 00053 */ 00054 00055 #include "symtab.h" 00056 #include <set> 00057 00058 struct ltstr 00059 { 00060 bool operator()(const char* s1, const char* s2) const 00061 { 00062 return strcmp(s1, s2) < 0; 00063 } 00064 }; 00065 00066 00067 class Reserved_Name_Set { 00068 set<const char*, ltstr> name_set; 00069 public: 00070 Reserved_Name_Set (int count, const char *vals[]) 00071 { 00072 int i; 00073 for (i = 0; i < count; i++) name_set.insert (vals[i]); 00074 } 00075 00076 BOOL Is_Member (const char *name) 00077 { 00078 return name_set.count (name) > 0; 00079 } 00080 00081 virtual ~Reserved_Name_Set () {}; 00082 }; 00083 00084 class Unparse_Target { 00085 protected: 00086 Reserved_Name_Set *reserved_ty_names; 00087 Reserved_Name_Set *reserved_st_names; 00088 public: 00089 virtual ~Unparse_Target () {}; 00090 00091 /* If name==NULL, then return NULL; otherwise, if a valid name, 00092 * then keep it unaltered; otherwise, construct a valid name 00093 * in a new Name_Buf by removing invalid characters (never return 00094 * NULL for this case) 00095 */ 00096 virtual const char *Make_Valid_Name(const char *name, BOOL allow_dot) = 0; 00097 00098 virtual const char *Get_St_Name(const ST *st, const char *original_name) = 0; 00099 virtual const char *Intrinsic_Name(INTRINSIC intr_opc) = 0; 00100 00101 /* Some globals eg: COMMONs, functions, should get the same name */ 00102 /* if they appear in the global symbol table more than once. They */ 00103 /* may have been created by different PUs. */ 00104 virtual BOOL Avoid_Common_Suffix(void) = 0; 00105 00106 virtual BOOL Reduce_Const_Ptr_Exprs(void) = 0; 00107 00108 virtual BOOL Enter_Symtab_Pointee_Names(void) = 0; 00109 00110 virtual BOOL Is_Binary_Or_Tertiary_Op (char c) = 0; 00111 00112 virtual BOOL Redeclare_File_Types (void) = 0; 00113 00114 virtual BOOL Builtin_Type (TY_IDX ty) = 0; 00115 00116 /*------ Function type attributes ------*/ 00117 /*--------------------------------------*/ 00118 00119 virtual BOOL Func_Return_Character(TY_IDX func_ty) = 0; 00120 00121 virtual TY_IDX Func_Return_Type(TY_IDX func_ty) = 0; 00122 00123 virtual BOOL Func_Return_To_Param(TY_IDX func_ty) = 0; 00124 00125 00126 /*------------------- Reserved Names Information ----------------- 00127 *----------------------------------------------------------------*/ 00128 00129 /* Denote the reserved names for the target language. 00130 * These are names referred to in the header files included by the 00131 * source generated by the unparser, and as such must be 00132 * reserved and not declared in the generated sources. 00133 */ 00134 00135 BOOL Reserved_Ty_Name(const char *name) 00136 { return reserved_ty_names->Is_Member(name); } 00137 00138 BOOL Reserved_St_Name(const char *name) 00139 { return reserved_st_names->Is_Member(name); } 00140 }; 00141 00142 extern Unparse_Target *W2X_Unparse_Target; 00143 00144 #endif /* unparse_target_INCLUDED */