0
|
1 /*
|
|
2 * Copyright 1997-2007 Sun Microsystems, Inc. All Rights Reserved.
|
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 *
|
|
5 * This code is free software; you can redistribute it and/or modify it
|
|
6 * under the terms of the GNU General Public License version 2 only, as
|
|
7 * published by the Free Software Foundation.
|
|
8 *
|
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 * version 2 for more details (a copy is included in the LICENSE file that
|
|
13 * accompanied this code).
|
|
14 *
|
|
15 * You should have received a copy of the GNU General Public License version
|
|
16 * 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 *
|
|
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
20 * CA 95054 USA or visit www.sun.com if you need additional information or
|
|
21 * have any questions.
|
|
22 *
|
|
23 */
|
|
24
|
|
25 // FORMS.CPP - Definitions for ADL Parser Generic & Utility Forms Classes
|
|
26 #include "adlc.hpp"
|
|
27
|
|
28 //------------------------------Static Initializers----------------------------
|
|
29 // allocate arena used by forms
|
|
30 Arena *Form::arena = Form::generate_arena(); // = Form::generate_arena();
|
|
31 Arena *Form::generate_arena() {
|
|
32 return (new Arena);
|
|
33 }
|
|
34
|
|
35 //------------------------------NameList---------------------------------------
|
|
36 // reserved user-defined string
|
|
37 const char *NameList::_signal = "$$SIGNAL$$";
|
|
38
|
|
39 // Constructor and Destructor
|
|
40 NameList::NameList() : _cur(0), _max(4), _iter(0), _justReset(true) {
|
|
41 _names = (const char**)malloc(_max*sizeof(char*));
|
|
42 }
|
|
43 NameList::~NameList() {
|
|
44 // The following free is a double-free, and crashes the program:
|
|
45 //free(_names); // not owner of strings
|
|
46 }
|
|
47
|
|
48 void NameList::addName(const char *name) {
|
|
49 if (_cur == _max) _names =(const char**)realloc(_names,(_max *=2)*sizeof(char*));
|
|
50 _names[_cur++] = name;
|
|
51 }
|
|
52
|
|
53 void NameList::add_signal() {
|
|
54 addName( _signal );
|
|
55 }
|
|
56 void NameList::clear() {
|
|
57 _cur = 0;
|
|
58 _iter = 0;
|
|
59 _justReset = true;
|
|
60 // _max = 4; Already allocated
|
|
61 }
|
|
62
|
|
63 int NameList::count() const { return _cur; }
|
|
64
|
|
65 void NameList::reset() { _iter = 0; _justReset = true;}
|
|
66 const char *NameList::iter() {
|
|
67 if (_justReset) {_justReset=false; return (_iter < _cur ? _names[_iter] : NULL);}
|
|
68 else return (_iter <_cur-1 ? _names[++_iter] : NULL);
|
|
69 }
|
|
70 const char *NameList::current() { return (_iter < _cur ? _names[_iter] : NULL); }
|
|
71
|
|
72 // Return 'true' if current entry is signal
|
|
73 bool NameList::current_is_signal() {
|
|
74 const char *entry = current();
|
|
75 return is_signal(entry);
|
|
76 }
|
|
77
|
|
78 // Return true if entry is a signal
|
|
79 bool NameList::is_signal(const char *entry) {
|
|
80 return ( (strcmp(entry,NameList::_signal) == 0) ? true : false);
|
|
81 }
|
|
82
|
|
83 // Search for a name in the list
|
|
84 bool NameList::search(const char *name) {
|
|
85 const char *entry;
|
|
86 for(reset(); (entry = iter()) != NULL; ) {
|
|
87 if(!strcmp(entry,name)) return true;
|
|
88 }
|
|
89 return false;
|
|
90 }
|
|
91
|
|
92 // Return index of name in list
|
|
93 int NameList::index(const char *name) {
|
|
94 int cnt = 0;
|
|
95 const char *entry;
|
|
96 for(reset(); (entry = iter()) != NULL; ) {
|
|
97 if(!strcmp(entry,name)) return cnt;
|
|
98 cnt++;
|
|
99 }
|
|
100 return Not_in_list;
|
|
101 }
|
|
102
|
|
103 // Return name at index in list
|
|
104 const char *NameList::name(intptr_t index) {
|
|
105 return ( index < _cur ? _names[index] : NULL);
|
|
106 }
|
|
107
|
|
108 void NameList::dump() { output(stderr); }
|
|
109
|
|
110 void NameList::output(FILE *fp) {
|
|
111 fprintf(fp, "\n");
|
|
112
|
|
113 // Run iteration over all entries, independent of position of iterator.
|
|
114 const char *name = NULL;
|
|
115 int iter = 0;
|
|
116 bool justReset = true;
|
|
117
|
|
118 while( ( name = (justReset ?
|
|
119 (justReset=false, (iter < _cur ? _names[iter] : NULL)) :
|
|
120 (iter < _cur-1 ? _names[++iter] : NULL)) )
|
|
121 != NULL ) {
|
|
122 fprintf( fp, " %s,\n", name);
|
|
123 }
|
|
124 fprintf(fp, "\n");
|
|
125 }
|
|
126
|
|
127 //------------------------------NameAndList------------------------------------
|
|
128 // Storage for a name and an associated list of names
|
|
129 NameAndList::NameAndList(char *name) : _name(name) {
|
|
130 }
|
|
131 NameAndList::~NameAndList() {
|
|
132 }
|
|
133
|
|
134 // Add to entries in list
|
|
135 void NameAndList::add_entry(const char *entry) {
|
|
136 _list.addName(entry);
|
|
137 }
|
|
138
|
|
139 // Access the name and its associated list.
|
|
140 const char *NameAndList::name() const { return _name; }
|
|
141 void NameAndList::reset() { _list.reset(); }
|
|
142 const char *NameAndList::iter() { return _list.iter(); }
|
|
143
|
|
144 // Return the "index" entry in the list, zero-based
|
|
145 const char *NameAndList::operator[](int index) {
|
|
146 assert( index >= 0, "Internal Error(): index less than 0.");
|
|
147
|
|
148 _list.reset();
|
|
149 const char *entry = _list.iter();
|
|
150 // Iterate further if it isn't at index 0.
|
|
151 for ( int position = 0; position != index; ++position ) {
|
|
152 entry = _list.iter();
|
|
153 }
|
|
154
|
|
155 return entry;
|
|
156 }
|
|
157
|
|
158
|
|
159 void NameAndList::dump() { output(stderr); }
|
|
160 void NameAndList::output(FILE *fp) {
|
|
161 fprintf(fp, "\n");
|
|
162
|
|
163 // Output the Name
|
|
164 fprintf(fp, "Name == %s", (_name ? _name : "") );
|
|
165
|
|
166 // Output the associated list of names
|
|
167 const char *name;
|
|
168 fprintf(fp, " (");
|
|
169 for (reset(); (name = iter()) != NULL;) {
|
|
170 fprintf(fp, " %s,\n", name);
|
|
171 }
|
|
172 fprintf(fp, ")");
|
|
173 fprintf(fp, "\n");
|
|
174 }
|
|
175
|
|
176 //------------------------------Form-------------------------------------------
|
|
177 OpClassForm *Form::is_opclass() const {
|
|
178 return NULL;
|
|
179 }
|
|
180
|
|
181 OperandForm *Form::is_operand() const {
|
|
182 return NULL;
|
|
183 }
|
|
184
|
|
185 InstructForm *Form::is_instruction() const {
|
|
186 return NULL;
|
|
187 }
|
|
188
|
|
189 MachNodeForm *Form::is_machnode() const {
|
|
190 return NULL;
|
|
191 }
|
|
192
|
|
193 AttributeForm *Form::is_attribute() const {
|
|
194 return NULL;
|
|
195 }
|
|
196
|
|
197 Effect *Form::is_effect() const {
|
|
198 return NULL;
|
|
199 }
|
|
200
|
|
201 ResourceForm *Form::is_resource() const {
|
|
202 return NULL;
|
|
203 }
|
|
204
|
|
205 PipeClassForm *Form::is_pipeclass() const {
|
|
206 return NULL;
|
|
207 }
|
|
208
|
|
209 Form::DataType Form::ideal_to_const_type(const char *name) const {
|
|
210 if( name == NULL ) { return Form::none; }
|
|
211
|
|
212 if (strcmp(name,"ConI")==0) return Form::idealI;
|
|
213 if (strcmp(name,"ConP")==0) return Form::idealP;
|
|
214 if (strcmp(name,"ConL")==0) return Form::idealL;
|
|
215 if (strcmp(name,"ConF")==0) return Form::idealF;
|
|
216 if (strcmp(name,"ConD")==0) return Form::idealD;
|
|
217 if (strcmp(name,"Bool")==0) return Form::idealI;
|
|
218
|
|
219 return Form::none;
|
|
220 }
|
|
221
|
|
222 Form::DataType Form::ideal_to_sReg_type(const char *name) const {
|
|
223 if( name == NULL ) { return Form::none; }
|
|
224
|
|
225 if (strcmp(name,"sRegI")==0) return Form::idealI;
|
|
226 if (strcmp(name,"sRegP")==0) return Form::idealP;
|
|
227 if (strcmp(name,"sRegF")==0) return Form::idealF;
|
|
228 if (strcmp(name,"sRegD")==0) return Form::idealD;
|
|
229 if (strcmp(name,"sRegL")==0) return Form::idealL;
|
|
230 return Form::none;
|
|
231 }
|
|
232
|
|
233 Form::DataType Form::ideal_to_Reg_type(const char *name) const {
|
|
234 if( name == NULL ) { return Form::none; }
|
|
235
|
|
236 if (strcmp(name,"RegI")==0) return Form::idealI;
|
|
237 if (strcmp(name,"RegP")==0) return Form::idealP;
|
|
238 if (strcmp(name,"RegF")==0) return Form::idealF;
|
|
239 if (strcmp(name,"RegD")==0) return Form::idealD;
|
|
240 if (strcmp(name,"RegL")==0) return Form::idealL;
|
|
241
|
|
242 return Form::none;
|
|
243 }
|
|
244
|
|
245 // True if 'opType', an ideal name, loads or stores.
|
|
246 Form::DataType Form::is_load_from_memory(const char *opType) const {
|
|
247 if( strcmp(opType,"LoadB")==0 ) return Form::idealB;
|
|
248 if( strcmp(opType,"LoadC")==0 ) return Form::idealC;
|
|
249 if( strcmp(opType,"LoadD")==0 ) return Form::idealD;
|
|
250 if( strcmp(opType,"LoadD_unaligned")==0 ) return Form::idealD;
|
|
251 if( strcmp(opType,"LoadF")==0 ) return Form::idealF;
|
|
252 if( strcmp(opType,"LoadI")==0 ) return Form::idealI;
|
|
253 if( strcmp(opType,"LoadKlass")==0 ) return Form::idealP;
|
|
254 if( strcmp(opType,"LoadL")==0 ) return Form::idealL;
|
|
255 if( strcmp(opType,"LoadL_unaligned")==0 ) return Form::idealL;
|
|
256 if( strcmp(opType,"LoadPLocked")==0 ) return Form::idealP;
|
|
257 if( strcmp(opType,"LoadLLocked")==0 ) return Form::idealL;
|
|
258 if( strcmp(opType,"LoadP")==0 ) return Form::idealP;
|
|
259 if( strcmp(opType,"LoadRange")==0 ) return Form::idealI;
|
|
260 if( strcmp(opType,"LoadS")==0 ) return Form::idealS;
|
|
261 if( strcmp(opType,"Load16B")==0 ) return Form::idealB;
|
|
262 if( strcmp(opType,"Load8B")==0 ) return Form::idealB;
|
|
263 if( strcmp(opType,"Load4B")==0 ) return Form::idealB;
|
|
264 if( strcmp(opType,"Load8C")==0 ) return Form::idealC;
|
|
265 if( strcmp(opType,"Load4C")==0 ) return Form::idealC;
|
|
266 if( strcmp(opType,"Load2C")==0 ) return Form::idealC;
|
|
267 if( strcmp(opType,"Load8S")==0 ) return Form::idealS;
|
|
268 if( strcmp(opType,"Load4S")==0 ) return Form::idealS;
|
|
269 if( strcmp(opType,"Load2S")==0 ) return Form::idealS;
|
|
270 if( strcmp(opType,"Load2D")==0 ) return Form::idealD;
|
|
271 if( strcmp(opType,"Load4F")==0 ) return Form::idealF;
|
|
272 if( strcmp(opType,"Load2F")==0 ) return Form::idealF;
|
|
273 if( strcmp(opType,"Load4I")==0 ) return Form::idealI;
|
|
274 if( strcmp(opType,"Load2I")==0 ) return Form::idealI;
|
|
275 if( strcmp(opType,"Load2L")==0 ) return Form::idealL;
|
|
276 assert( strcmp(opType,"Load") != 0, "Must type Loads" );
|
|
277 return Form::none;
|
|
278 }
|
|
279
|
|
280 Form::DataType Form::is_store_to_memory(const char *opType) const {
|
|
281 if( strcmp(opType,"StoreB")==0) return Form::idealB;
|
|
282 if( strcmp(opType,"StoreCM")==0) return Form::idealB;
|
|
283 if( strcmp(opType,"StoreC")==0) return Form::idealC;
|
|
284 if( strcmp(opType,"StoreD")==0) return Form::idealD;
|
|
285 if( strcmp(opType,"StoreF")==0) return Form::idealF;
|
|
286 if( strcmp(opType,"StoreI")==0) return Form::idealI;
|
|
287 if( strcmp(opType,"StoreL")==0) return Form::idealL;
|
|
288 if( strcmp(opType,"StoreP")==0) return Form::idealP;
|
|
289 if( strcmp(opType,"Store16B")==0) return Form::idealB;
|
|
290 if( strcmp(opType,"Store8B")==0) return Form::idealB;
|
|
291 if( strcmp(opType,"Store4B")==0) return Form::idealB;
|
|
292 if( strcmp(opType,"Store8C")==0) return Form::idealC;
|
|
293 if( strcmp(opType,"Store4C")==0) return Form::idealC;
|
|
294 if( strcmp(opType,"Store2C")==0) return Form::idealC;
|
|
295 if( strcmp(opType,"Store2D")==0) return Form::idealD;
|
|
296 if( strcmp(opType,"Store4F")==0) return Form::idealF;
|
|
297 if( strcmp(opType,"Store2F")==0) return Form::idealF;
|
|
298 if( strcmp(opType,"Store4I")==0) return Form::idealI;
|
|
299 if( strcmp(opType,"Store2I")==0) return Form::idealI;
|
|
300 if( strcmp(opType,"Store2L")==0) return Form::idealL;
|
|
301 assert( strcmp(opType,"Store") != 0, "Must type Stores" );
|
|
302 return Form::none;
|
|
303 }
|
|
304
|
|
305 Form::InterfaceType Form::interface_type(FormDict &globals) const {
|
|
306 return Form::no_interface;
|
|
307 }
|
|
308
|
|
309 //------------------------------FormList---------------------------------------
|
|
310 // Destructor
|
|
311 FormList::~FormList() {
|
|
312 // // This list may not own its elements
|
|
313 // Form *cur = _root;
|
|
314 // Form *next = NULL;
|
|
315 // for( ; (cur = next) != NULL; ) {
|
|
316 // next = (Form *)cur->_next;
|
|
317 // delete cur;
|
|
318 // }
|
|
319 };
|
|
320
|
|
321 //------------------------------FormDict---------------------------------------
|
|
322 // Constructor
|
|
323 FormDict::FormDict( CmpKey cmp, Hash hash, Arena *arena )
|
|
324 : _form(cmp, hash, arena) {
|
|
325 }
|
|
326 FormDict::~FormDict() {
|
|
327 }
|
|
328
|
|
329 // Return # of name-Form pairs in dict
|
|
330 int FormDict::Size(void) const {
|
|
331 return _form.Size();
|
|
332 }
|
|
333
|
|
334 // Insert inserts the given key-value pair into the dictionary. The prior
|
|
335 // value of the key is returned; NULL if the key was not previously defined.
|
|
336 const Form *FormDict::Insert(const char *name, Form *form) {
|
|
337 return (Form*)_form.Insert((void*)name, (void*)form);
|
|
338 }
|
|
339
|
|
340 // Finds the value of a given key; or NULL if not found.
|
|
341 // The dictionary is NOT changed.
|
|
342 const Form *FormDict::operator [](const char *name) const {
|
|
343 return (Form*)_form[name];
|
|
344 }
|
|
345
|
|
346 //------------------------------FormDict::private------------------------------
|
|
347 // Disable public use of constructor, copy-ctor, operator =, operator ==
|
|
348 FormDict::FormDict( ) : _form(cmpkey,hashkey) {
|
|
349 assert( false, "NotImplemented");
|
|
350 }
|
|
351 FormDict::FormDict( const FormDict & fd) : _form(fd._form) {
|
|
352 }
|
|
353 FormDict &FormDict::operator =( const FormDict &rhs) {
|
|
354 assert( false, "NotImplemented");
|
|
355 _form = rhs._form;
|
|
356 return *this;
|
|
357 }
|
|
358 // == compares two dictionaries; they must have the same keys (their keys
|
|
359 // must match using CmpKey) and they must have the same values (pointer
|
|
360 // comparison). If so 1 is returned, if not 0 is returned.
|
|
361 bool FormDict::operator ==(const FormDict &d) const {
|
|
362 assert( false, "NotImplemented");
|
|
363 return false;
|
|
364 }
|
|
365
|
|
366 // Print out the dictionary contents as key-value pairs
|
|
367 static void dumpkey (const void* key) { fprintf(stdout, "%s", key); }
|
|
368 static void dumpform(const void* form) { fflush(stdout); ((Form*)form)->dump(); }
|
|
369
|
|
370 void FormDict::dump() {
|
|
371 _form.print(dumpkey, dumpform);
|
|
372 }
|
|
373
|
|
374 //------------------------------SourceForm-------------------------------------
|
|
375 SourceForm::SourceForm(char* code) : _code(code) { }; // Constructor
|
|
376 SourceForm::~SourceForm() {
|
|
377 }
|
|
378
|
|
379 void SourceForm::dump() { // Debug printer
|
|
380 output(stderr);
|
|
381 }
|
|
382
|
|
383 void SourceForm::output(FILE *fp) {
|
|
384 fprintf(fp,"\n//%s\n%s\n",classname(),(_code?_code:""));
|
|
385 }
|