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 /* -*-Mode: c++;-*- (Tell emacs to use c++ mode) */ 00037 #ifndef anl_cbuf_INCLUDED 00038 #define anl_cbuf_INCLUDED 00039 00040 // ============================================================== 00041 // ============================================================== 00042 // 00043 // 00044 // Description: 00045 // 00046 // A class used for buffering and manipulating dynamically 00047 // allocated character strings. The dynamic allocation scheme 00048 // is hidden from the user of this class. 00049 // 00050 // The memory to buffer characters is allocated in multiples 00051 // of fixed-sized chunks. Hence, the constructor with an 00052 // initial allocation size will allocate the number of "chunks" 00053 // into which the given size will fit. 00054 // 00055 // Note that any call to Write_Char() or Write_String() may 00056 // cause the dynamically allocated buffer to be reallocated, 00057 // and as such may invalidate any earlier results from Chars(). 00058 // 00059 // ============================================================== 00060 // ============================================================== 00061 00062 00063 #define CBUF_SMALLEST_ALLOC_SIZE 128 00064 00065 class ANL_CBUF 00066 { 00067 private: 00068 00069 const char *_splitchars; // Chars where it is legal to split a line 00070 const char *_continuation; // Prefix for the continuation of a line 00071 UINT32 _max_linelength; // Maximum number of chars we put on one line 00072 UINT32 _linelength; // Current line-length 00073 UINT32 _chunk_size; // Size of chunks allocated to this buffer 00074 UINT _size; // Size of buffer 00075 UINT _next; // Next available char within buffer 00076 char *_buf; // buffer 00077 MEM_POOL *_pool; 00078 00079 UINT _A_Number_Of_Chunks(UINT size) 00080 { 00081 return (size <= 0? 0 : (((size/_chunk_size) + 1) * _chunk_size)); 00082 } 00083 00084 char *_Alloc(UINT size) 00085 { 00086 char *buf; 00087 00088 if (size > 0) 00089 { 00090 buf = CXX_NEW_ARRAY(char, size, _pool); 00091 buf[0] = '\0'; 00092 } 00093 else 00094 buf = NULL; 00095 return buf; 00096 } 00097 00098 BOOL _Is_Splitc(char splitc); 00099 00100 void _Split(); 00101 00102 public: 00103 00104 // ********* Constructors ********** 00105 00106 ANL_CBUF(MEM_POOL *pool): 00107 _splitchars(""), 00108 _continuation(""), 00109 _max_linelength(UINT32_MAX), 00110 _linelength(0), 00111 _chunk_size(CBUF_SMALLEST_ALLOC_SIZE), 00112 _size(0), 00113 _next(0), 00114 _buf(NULL), 00115 _pool(pool) 00116 {} 00117 00118 ANL_CBUF(MEM_POOL *pool, UINT chunk_size, UINT size): 00119 _splitchars(""), 00120 _continuation(""), 00121 _linelength(0), 00122 _max_linelength(UINT32_MAX), 00123 _next(0), 00124 _pool(pool) 00125 { 00126 _chunk_size = (chunk_size > CBUF_SMALLEST_ALLOC_SIZE? 00127 chunk_size : CBUF_SMALLEST_ALLOC_SIZE); 00128 _size = _A_Number_Of_Chunks(size); 00129 _buf = _Alloc(_size); 00130 } 00131 00132 ANL_CBUF(MEM_POOL *pool, const char *s); 00133 00134 00135 // ********* Destructors ********** 00136 00137 ~ANL_CBUF() 00138 { 00139 if (_size > 0) 00140 CXX_DELETE_ARRAY(_buf, _pool); 00141 } 00142 00143 // ********* Modifications ********** 00144 00145 void Set_Linesplit(const char *continuation, 00146 const char *splitchars, 00147 mUINT32 max_linelength) 00148 { 00149 // Split lines at splitchars to enforce a line-length 00150 // of less than or equal to the given max-length. Insert 00151 // the continuation char-sequence at split-points. 00152 // 00153 _splitchars = splitchars; 00154 _continuation = continuation; 00155 _max_linelength = max_linelength; 00156 } 00157 00158 void Reset_Linesplit() 00159 { 00160 _splitchars = ""; 00161 _continuation = ""; 00162 _max_linelength = UINT32_MAX; 00163 } 00164 00165 void Reset() 00166 { 00167 _next = 0; 00168 } 00169 00170 void Reduce_Size(UINT by_amount) 00171 { 00172 _next = (by_amount > _next? 0 : (_next - by_amount)); 00173 _buf[_next] = '\0'; 00174 } 00175 00176 void Write_Char(char c); 00177 00178 void Write_String(const char *s); 00179 00180 void Write_Int(INT64 i) 00181 { 00182 char s[32]; 00183 00184 sprintf(s, "%1lld", i); 00185 Write_String(s); 00186 } 00187 00188 void Append_Pragma_Preamble(BOOL is_omp, BOOL lower_case); 00189 00190 // ********* Inquiries ********** 00191 00192 UINT Size() const {return _next;} 00193 const char *Chars() const {return _buf;} // Always '\0' terminated! 00194 00195 }; // ANL_CBUF 00196 00197 00198 #endif /* anl_cbuf_INCLUDED */