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 #ifndef whirl2c_common_INCLUDED 00037 #define whirl2c_common_INCLUDED 00038 /* ==================================================================== 00039 * ==================================================================== 00040 * 00041 * 00042 * Revision history: 00043 * 07-Nov-94 - Original Version 00044 * 00045 * Description: 00046 * 00047 * This file is to be included in all major translating modules 00048 * belonging to whirl2c. It includes all files that these modules 00049 * will depend on and defines some utilities that are generally 00050 * useful. 00051 * 00052 * Output files 00053 * ------------ 00054 * 00055 * 1) The Whirl2c_File is the file to which we would write the 00056 * program units (subroutines/functions) in the high-level 00057 * output language. 00058 * 00059 * 2) The Whirl2c_Header is the file to which we would write 00060 * file-level declarations in C, and this file is to be 00061 * #included at the top of the Whirl2c_File. 00062 * 00063 * 3) The Whirl2c_Srcpos_Map_File is the file into which we 00064 * will write the mapping between source positions in the 00065 * original source and source positions in the whirl2c 00066 * generated source. 00067 * 00068 * Context 00069 * ------- 00070 * We provides facilities for maintaining a CONTEXT, which 00071 * flag various aspects of the context in which a WHIRL to C 00072 * translation takes place. The flags typically say something 00073 * about surrounding expressions, statements, and scopes which 00074 * may influence the translation of types, variables, expressions 00075 * and statements 00076 * 00077 * 00078 * Identifier Naming 00079 * ----------------- 00080 * 00081 * WHIRL2C_number_as_c_name: Converts the given number into 00082 * a C identifier by converting it into a sequence of decimal 00083 * characters prepending an underscore ('_'). 00084 * 00085 * WHIRL2C_ptr_as_c_name: Converts the given pointer value into 00086 * a C identifier by converting it into a sequence of decimal 00087 * characters prepending an underscore ('_'). Note that the 00088 * number may be a 32 or 64 bits value, depending on the size 00089 * of a pointer representation. 00090 * 00091 * WHIRL2C_make_valid_c_name: If the given name is already a 00092 * valid C name, then it is simply returned. If the name 00093 * is NULL, then return NULL. Otherwise, construct a valid 00094 * C identifier by removing invalid characters, thus 00095 * returning a non-NULL name. 00096 00097 * Other General Utilities 00098 * ----------------------- 00099 * See the comments preceding their definitions for a brief 00100 * description of the other utilities. 00101 * 00102 * ==================================================================== 00103 * ==================================================================== 00104 */ 00105 00106 #include "common_include.h" 00107 #include "w2c_driver.h" 00108 00109 00110 typedef struct Context 00111 { 00112 mUINT32 flags; 00113 SRCPOS srcpos; 00114 TY_IDX given_ty; 00115 } CONTEXT; 00116 00117 /* Initialization */ 00118 #define INIT_CONTEXT {0, 0LLU, TY_IDX_ZERO} 00119 #define CONTEXT_reset(c) \ 00120 (void)(CONTEXT_reset_flags(c), \ 00121 CONTEXT_reset_srcpos(c), \ 00122 CONTEXT_reset_given_base_ty(c)) 00123 00124 /* Base-type suggestions when CONTEXT_array_basetype(c) == TRUE */ 00125 #define CONTEXT_given_base_ty(c) (c).given_ty 00126 #define CONTEXT_set_given_base_ty(c, ty) ((c).given_ty = (ty)) 00127 #define CONTEXT_reset_given_base_ty(c) ((c).given_ty = TY_IDX_ZERO) 00128 00129 /* lvalue-type suggestions when CONTEXT_lvalue_type(c) == TRUE */ 00130 #define CONTEXT_given_lvalue_ty(c) (c).given_ty 00131 #define CONTEXT_set_given_lvalue_ty(c, ty) ((c).given_ty = (ty)) 00132 #define CONTEXT_reset_given_lvalue_ty(c) ((c).given_ty = TY_IDX_ZERO) 00133 00134 /* Srcpos values */ 00135 #define CONTEXT_srcpos(c) (c).srcpos 00136 #define CONTEXT_set_srcpos(c, pos) ((c).srcpos = pos) 00137 #define CONTEXT_reset_srcpos(c) (void)((c).srcpos = 0LLU) 00138 00139 /* Flag values */ 00140 #define CONTEXT_NEEDS_LVALUE 0x000000001 /* Context could use an lvalue */ 00141 #define CONTEXT_NEW_FUNC_SCOPE 0x000000002 /* New function scope */ 00142 #define CONTEXT_UNQUALIFIED_TY2C 0x000000004 /* Emit unqualified C type */ 00143 #define CONTEXT_INCOMPLETE_TY2C 0x000000008 /* Emit incomplete C type */ 00144 #define CONTEXT_TOP_LEVEL_EXPR 0x000000010 /* Top-level of an expression */ 00145 #define CONTEXT_ARRAY_BASETYPE 0x000000020 /* Context suggests array type */ 00146 #define CONTEXT_LVALUE_TYPE 0x000000040 /* Context suggests lvalue type */ 00147 #define CONTEXT_OMP_PRAGMA 0x000000080 /* Processing an Open MP pragma */ 00148 00149 /* Accessor macros */ 00150 #define CONTEXT_reset_flags(c) ((c).flags = 0U) 00151 00152 #define CONTEXT_needs_lvalue(c) ((c).flags & CONTEXT_NEEDS_LVALUE) 00153 #define CONTEXT_set_needs_lvalue(c) \ 00154 ((c).flags = (c).flags | CONTEXT_NEEDS_LVALUE) 00155 #define CONTEXT_reset_needs_lvalue(c) \ 00156 ((c).flags = (c).flags & ~CONTEXT_NEEDS_LVALUE) 00157 00158 #define CONTEXT_new_func_scope(c) ((c).flags & CONTEXT_NEW_FUNC_SCOPE) 00159 #define CONTEXT_set_new_func_scope(c) \ 00160 ((c).flags = (c).flags | CONTEXT_NEW_FUNC_SCOPE) 00161 #define CONTEXT_reset_new_func_scope(c) \ 00162 ((c).flags = (c).flags & ~CONTEXT_NEW_FUNC_SCOPE) 00163 00164 #define CONTEXT_unqualified_ty2c(c) ((c).flags & CONTEXT_UNQUALIFIED_TY2C) 00165 #define CONTEXT_set_unqualified_ty2c(c) \ 00166 ((c).flags = (c).flags | CONTEXT_UNQUALIFIED_TY2C) 00167 #define CONTEXT_reset_unqualified_ty2c(c) \ 00168 ((c).flags = (c).flags & ~CONTEXT_UNQUALIFIED_TY2C) 00169 00170 #define CONTEXT_incomplete_ty2c(c) ((c).flags & CONTEXT_INCOMPLETE_TY2C) 00171 #define CONTEXT_set_incomplete_ty2c(c) \ 00172 ((c).flags = (c).flags | CONTEXT_INCOMPLETE_TY2C) 00173 #define CONTEXT_reset_incomplete_ty2c(c) \ 00174 ((c).flags = (c).flags & ~CONTEXT_INCOMPLETE_TY2C) 00175 00176 #define CONTEXT_top_level_expr(c) ((c).flags & CONTEXT_TOP_LEVEL_EXPR) 00177 #define CONTEXT_set_top_level_expr(c) \ 00178 ((c).flags = (c).flags | CONTEXT_TOP_LEVEL_EXPR) 00179 #define CONTEXT_reset_top_level_expr(c) \ 00180 ((c).flags = (c).flags & ~CONTEXT_TOP_LEVEL_EXPR) 00181 00182 #define CONTEXT_array_basetype(c) ((c).flags & CONTEXT_ARRAY_BASETYPE) 00183 #define CONTEXT_set_array_basetype(c) \ 00184 ((c).flags = (c).flags | CONTEXT_ARRAY_BASETYPE) 00185 #define CONTEXT_reset_array_basetype(c) \ 00186 ((c).flags = (c).flags & ~CONTEXT_ARRAY_BASETYPE) 00187 00188 #define CONTEXT_lvalue_type(c) ((c).flags & CONTEXT_LVALUE_TYPE) 00189 #define CONTEXT_set_lvalue_type(c) \ 00190 ((c).flags = (c).flags | CONTEXT_LVALUE_TYPE) 00191 #define CONTEXT_reset_lvalue_type(c) \ 00192 ((c).flags = (c).flags & ~CONTEXT_LVALUE_TYPE) 00193 00194 #define CONTEXT_omp(c) ((c).flags & CONTEXT_OMP_PRAGMA) 00195 #define CONTEXT_set_omp(c) \ 00196 ((c).flags = (c).flags | CONTEXT_OMP_PRAGMA) 00197 #define CONTEXT_reset_omp(c) \ 00198 ((c).flags = (c).flags & ~CONTEXT_OMP_PRAGMA) 00199 00200 00201 /* Identifier naming */ 00202 /*-------------------*/ 00203 00204 /* Some general utility routines for creating C identifier names. 00205 */ 00206 #define WHIRL2C_number_as_c_name(number) Number_as_String(number, "_%lld") 00207 #define WHIRL2C_ptr_as_c_name(ptr) Concat2_Strings("_", Ptr_as_String(ptr)) 00208 extern const char * WHIRL2C_make_valid_c_name(const char *name); 00209 00210 00211 /* Other generally useful macros and functions */ 00212 /*---------------------------------------------*/ 00213 00214 /* Put parenthesis around the contents of the tokens. 00215 */ 00216 extern void WHIRL2C_parenthesize(TOKEN_BUFFER tokens); 00217 00218 extern int compiling_upc_flag; 00219 #endif /* whirl2c_common_INCLUDED */ 00220 00221 00222 00223