PageRenderTime 37ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/javac_compiler/HotspotSource/JavaHotSpotSrc/src/vm/adlc/forms.cpp

http://jvmnotebook.googlecode.com/
C++ | 394 lines | 266 code | 57 blank | 71 comment | 95 complexity | 77a4969ce981f09f19a567851eb9c1c1 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, Apache-2.0, CPL-1.0, AGPL-1.0, JSON, LGPL-2.1, GPL-2.0, BSD-3-Clause, BSD-3-Clause-No-Nuclear-License-2014, Unlicense, LGPL-2.0
  1. /*
  2. * Copyright (c) 1997, 2009, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20. * or visit www.oracle.com if you need additional information or have any
  21. * questions.
  22. *
  23. */
  24. // FORMS.CPP - Definitions for ADL Parser Generic & Utility Forms Classes
  25. #include "adlc.hpp"
  26. //------------------------------Static Initializers----------------------------
  27. // allocate arena used by forms
  28. Arena *Form::arena = Form::generate_arena(); // = Form::generate_arena();
  29. Arena *Form::generate_arena() {
  30. return (new Arena);
  31. }
  32. //------------------------------NameList---------------------------------------
  33. // reserved user-defined string
  34. const char *NameList::_signal = "$$SIGNAL$$";
  35. const char *NameList::_signal2 = "$$SIGNAL2$$";
  36. const char *NameList::_signal3 = "$$SIGNAL3$$";
  37. // Constructor and Destructor
  38. NameList::NameList() : _cur(0), _max(4), _iter(0), _justReset(true) {
  39. _names = (const char**)malloc(_max*sizeof(char*));
  40. }
  41. NameList::~NameList() {
  42. // The following free is a double-free, and crashes the program:
  43. //free(_names); // not owner of strings
  44. }
  45. void NameList::addName(const char *name) {
  46. if (_cur == _max) _names =(const char**)realloc(_names,(_max *=2)*sizeof(char*));
  47. _names[_cur++] = name;
  48. }
  49. void NameList::add_signal() {
  50. addName( _signal );
  51. }
  52. void NameList::clear() {
  53. _cur = 0;
  54. _iter = 0;
  55. _justReset = true;
  56. // _max = 4; Already allocated
  57. }
  58. int NameList::count() const { return _cur; }
  59. void NameList::reset() { _iter = 0; _justReset = true;}
  60. const char *NameList::iter() {
  61. if (_justReset) {_justReset=false; return (_iter < _cur ? _names[_iter] : NULL);}
  62. else return (_iter <_cur-1 ? _names[++_iter] : NULL);
  63. }
  64. const char *NameList::current() { return (_iter < _cur ? _names[_iter] : NULL); }
  65. const char *NameList::peek(int skip) { return (_iter + skip < _cur ? _names[_iter + skip] : NULL); }
  66. // Return 'true' if current entry is signal
  67. bool NameList::current_is_signal() {
  68. const char *entry = current();
  69. return is_signal(entry);
  70. }
  71. // Return true if entry is a signal
  72. bool NameList::is_signal(const char *entry) {
  73. return ( (strcmp(entry,NameList::_signal) == 0) ? true : false);
  74. }
  75. // Search for a name in the list
  76. bool NameList::search(const char *name) {
  77. const char *entry;
  78. for(reset(); (entry = iter()) != NULL; ) {
  79. if(!strcmp(entry,name)) return true;
  80. }
  81. return false;
  82. }
  83. // Return index of name in list
  84. int NameList::index(const char *name) {
  85. int cnt = 0;
  86. const char *entry;
  87. for(reset(); (entry = iter()) != NULL; ) {
  88. if(!strcmp(entry,name)) return cnt;
  89. cnt++;
  90. }
  91. return Not_in_list;
  92. }
  93. // Return name at index in list
  94. const char *NameList::name(intptr_t index) {
  95. return ( index < _cur ? _names[index] : NULL);
  96. }
  97. void NameList::dump() { output(stderr); }
  98. void NameList::output(FILE *fp) {
  99. fprintf(fp, "\n");
  100. // Run iteration over all entries, independent of position of iterator.
  101. const char *name = NULL;
  102. int iter = 0;
  103. bool justReset = true;
  104. while( ( name = (justReset ?
  105. (justReset=false, (iter < _cur ? _names[iter] : NULL)) :
  106. (iter < _cur-1 ? _names[++iter] : NULL)) )
  107. != NULL ) {
  108. fprintf( fp, " %s,\n", name);
  109. }
  110. fprintf(fp, "\n");
  111. }
  112. //------------------------------NameAndList------------------------------------
  113. // Storage for a name and an associated list of names
  114. NameAndList::NameAndList(char *name) : _name(name) {
  115. }
  116. NameAndList::~NameAndList() {
  117. }
  118. // Add to entries in list
  119. void NameAndList::add_entry(const char *entry) {
  120. _list.addName(entry);
  121. }
  122. // Access the name and its associated list.
  123. const char *NameAndList::name() const { return _name; }
  124. void NameAndList::reset() { _list.reset(); }
  125. const char *NameAndList::iter() { return _list.iter(); }
  126. // Return the "index" entry in the list, zero-based
  127. const char *NameAndList::operator[](int index) {
  128. assert( index >= 0, "Internal Error(): index less than 0.");
  129. _list.reset();
  130. const char *entry = _list.iter();
  131. // Iterate further if it isn't at index 0.
  132. for ( int position = 0; position != index; ++position ) {
  133. entry = _list.iter();
  134. }
  135. return entry;
  136. }
  137. void NameAndList::dump() { output(stderr); }
  138. void NameAndList::output(FILE *fp) {
  139. fprintf(fp, "\n");
  140. // Output the Name
  141. fprintf(fp, "Name == %s", (_name ? _name : "") );
  142. // Output the associated list of names
  143. const char *name;
  144. fprintf(fp, " (");
  145. for (reset(); (name = iter()) != NULL;) {
  146. fprintf(fp, " %s,\n", name);
  147. }
  148. fprintf(fp, ")");
  149. fprintf(fp, "\n");
  150. }
  151. //------------------------------Form-------------------------------------------
  152. OpClassForm *Form::is_opclass() const {
  153. return NULL;
  154. }
  155. OperandForm *Form::is_operand() const {
  156. return NULL;
  157. }
  158. InstructForm *Form::is_instruction() const {
  159. return NULL;
  160. }
  161. MachNodeForm *Form::is_machnode() const {
  162. return NULL;
  163. }
  164. AttributeForm *Form::is_attribute() const {
  165. return NULL;
  166. }
  167. Effect *Form::is_effect() const {
  168. return NULL;
  169. }
  170. ResourceForm *Form::is_resource() const {
  171. return NULL;
  172. }
  173. PipeClassForm *Form::is_pipeclass() const {
  174. return NULL;
  175. }
  176. Form::DataType Form::ideal_to_const_type(const char *name) const {
  177. if( name == NULL ) { return Form::none; }
  178. if (strcmp(name,"ConI")==0) return Form::idealI;
  179. if (strcmp(name,"ConP")==0) return Form::idealP;
  180. if (strcmp(name,"ConN")==0) return Form::idealN;
  181. if (strcmp(name,"ConL")==0) return Form::idealL;
  182. if (strcmp(name,"ConF")==0) return Form::idealF;
  183. if (strcmp(name,"ConD")==0) return Form::idealD;
  184. if (strcmp(name,"Bool")==0) return Form::idealI;
  185. return Form::none;
  186. }
  187. Form::DataType Form::ideal_to_sReg_type(const char *name) const {
  188. if( name == NULL ) { return Form::none; }
  189. if (strcmp(name,"sRegI")==0) return Form::idealI;
  190. if (strcmp(name,"sRegP")==0) return Form::idealP;
  191. if (strcmp(name,"sRegF")==0) return Form::idealF;
  192. if (strcmp(name,"sRegD")==0) return Form::idealD;
  193. if (strcmp(name,"sRegL")==0) return Form::idealL;
  194. return Form::none;
  195. }
  196. Form::DataType Form::ideal_to_Reg_type(const char *name) const {
  197. if( name == NULL ) { return Form::none; }
  198. if (strcmp(name,"RegI")==0) return Form::idealI;
  199. if (strcmp(name,"RegP")==0) return Form::idealP;
  200. if (strcmp(name,"RegF")==0) return Form::idealF;
  201. if (strcmp(name,"RegD")==0) return Form::idealD;
  202. if (strcmp(name,"RegL")==0) return Form::idealL;
  203. return Form::none;
  204. }
  205. // True if 'opType', an ideal name, loads or stores.
  206. Form::DataType Form::is_load_from_memory(const char *opType) const {
  207. if( strcmp(opType,"LoadB")==0 ) return Form::idealB;
  208. if( strcmp(opType,"LoadUB")==0 ) return Form::idealB;
  209. if( strcmp(opType,"LoadUS")==0 ) return Form::idealC;
  210. if( strcmp(opType,"LoadD")==0 ) return Form::idealD;
  211. if( strcmp(opType,"LoadD_unaligned")==0 ) return Form::idealD;
  212. if( strcmp(opType,"LoadF")==0 ) return Form::idealF;
  213. if( strcmp(opType,"LoadI")==0 ) return Form::idealI;
  214. if( strcmp(opType,"LoadUI2L")==0 ) return Form::idealI;
  215. if( strcmp(opType,"LoadKlass")==0 ) return Form::idealP;
  216. if( strcmp(opType,"LoadNKlass")==0 ) return Form::idealN;
  217. if( strcmp(opType,"LoadL")==0 ) return Form::idealL;
  218. if( strcmp(opType,"LoadL_unaligned")==0 ) return Form::idealL;
  219. if( strcmp(opType,"LoadPLocked")==0 ) return Form::idealP;
  220. if( strcmp(opType,"LoadLLocked")==0 ) return Form::idealL;
  221. if( strcmp(opType,"LoadP")==0 ) return Form::idealP;
  222. if( strcmp(opType,"LoadN")==0 ) return Form::idealN;
  223. if( strcmp(opType,"LoadRange")==0 ) return Form::idealI;
  224. if( strcmp(opType,"LoadS")==0 ) return Form::idealS;
  225. if( strcmp(opType,"Load16B")==0 ) return Form::idealB;
  226. if( strcmp(opType,"Load8B")==0 ) return Form::idealB;
  227. if( strcmp(opType,"Load4B")==0 ) return Form::idealB;
  228. if( strcmp(opType,"Load8C")==0 ) return Form::idealC;
  229. if( strcmp(opType,"Load4C")==0 ) return Form::idealC;
  230. if( strcmp(opType,"Load2C")==0 ) return Form::idealC;
  231. if( strcmp(opType,"Load8S")==0 ) return Form::idealS;
  232. if( strcmp(opType,"Load4S")==0 ) return Form::idealS;
  233. if( strcmp(opType,"Load2S")==0 ) return Form::idealS;
  234. if( strcmp(opType,"Load2D")==0 ) return Form::idealD;
  235. if( strcmp(opType,"Load4F")==0 ) return Form::idealF;
  236. if( strcmp(opType,"Load2F")==0 ) return Form::idealF;
  237. if( strcmp(opType,"Load4I")==0 ) return Form::idealI;
  238. if( strcmp(opType,"Load2I")==0 ) return Form::idealI;
  239. if( strcmp(opType,"Load2L")==0 ) return Form::idealL;
  240. assert( strcmp(opType,"Load") != 0, "Must type Loads" );
  241. return Form::none;
  242. }
  243. Form::DataType Form::is_store_to_memory(const char *opType) const {
  244. if( strcmp(opType,"StoreB")==0) return Form::idealB;
  245. if( strcmp(opType,"StoreCM")==0) return Form::idealB;
  246. if( strcmp(opType,"StoreC")==0) return Form::idealC;
  247. if( strcmp(opType,"StoreD")==0) return Form::idealD;
  248. if( strcmp(opType,"StoreF")==0) return Form::idealF;
  249. if( strcmp(opType,"StoreI")==0) return Form::idealI;
  250. if( strcmp(opType,"StoreL")==0) return Form::idealL;
  251. if( strcmp(opType,"StoreP")==0) return Form::idealP;
  252. if( strcmp(opType,"StoreN")==0) return Form::idealN;
  253. if( strcmp(opType,"Store16B")==0) return Form::idealB;
  254. if( strcmp(opType,"Store8B")==0) return Form::idealB;
  255. if( strcmp(opType,"Store4B")==0) return Form::idealB;
  256. if( strcmp(opType,"Store8C")==0) return Form::idealC;
  257. if( strcmp(opType,"Store4C")==0) return Form::idealC;
  258. if( strcmp(opType,"Store2C")==0) return Form::idealC;
  259. if( strcmp(opType,"Store2D")==0) return Form::idealD;
  260. if( strcmp(opType,"Store4F")==0) return Form::idealF;
  261. if( strcmp(opType,"Store2F")==0) return Form::idealF;
  262. if( strcmp(opType,"Store4I")==0) return Form::idealI;
  263. if( strcmp(opType,"Store2I")==0) return Form::idealI;
  264. if( strcmp(opType,"Store2L")==0) return Form::idealL;
  265. assert( strcmp(opType,"Store") != 0, "Must type Stores" );
  266. return Form::none;
  267. }
  268. Form::InterfaceType Form::interface_type(FormDict &globals) const {
  269. return Form::no_interface;
  270. }
  271. //------------------------------FormList---------------------------------------
  272. // Destructor
  273. FormList::~FormList() {
  274. // // This list may not own its elements
  275. // Form *cur = _root;
  276. // Form *next = NULL;
  277. // for( ; (cur = next) != NULL; ) {
  278. // next = (Form *)cur->_next;
  279. // delete cur;
  280. // }
  281. };
  282. //------------------------------FormDict---------------------------------------
  283. // Constructor
  284. FormDict::FormDict( CmpKey cmp, Hash hash, Arena *arena )
  285. : _form(cmp, hash, arena) {
  286. }
  287. FormDict::~FormDict() {
  288. }
  289. // Return # of name-Form pairs in dict
  290. int FormDict::Size(void) const {
  291. return _form.Size();
  292. }
  293. // Insert inserts the given key-value pair into the dictionary. The prior
  294. // value of the key is returned; NULL if the key was not previously defined.
  295. const Form *FormDict::Insert(const char *name, Form *form) {
  296. return (Form*)_form.Insert((void*)name, (void*)form);
  297. }
  298. // Finds the value of a given key; or NULL if not found.
  299. // The dictionary is NOT changed.
  300. const Form *FormDict::operator [](const char *name) const {
  301. return (Form*)_form[name];
  302. }
  303. //------------------------------FormDict::private------------------------------
  304. // Disable public use of constructor, copy-ctor, operator =, operator ==
  305. FormDict::FormDict( ) : _form(cmpkey,hashkey) {
  306. assert( false, "NotImplemented");
  307. }
  308. FormDict::FormDict( const FormDict & fd) : _form(fd._form) {
  309. }
  310. FormDict &FormDict::operator =( const FormDict &rhs) {
  311. assert( false, "NotImplemented");
  312. _form = rhs._form;
  313. return *this;
  314. }
  315. // == compares two dictionaries; they must have the same keys (their keys
  316. // must match using CmpKey) and they must have the same values (pointer
  317. // comparison). If so 1 is returned, if not 0 is returned.
  318. bool FormDict::operator ==(const FormDict &d) const {
  319. assert( false, "NotImplemented");
  320. return false;
  321. }
  322. // Print out the dictionary contents as key-value pairs
  323. static void dumpkey (const void* key) { fprintf(stdout, "%s", (char*) key); }
  324. static void dumpform(const void* form) { fflush(stdout); ((Form*)form)->dump(); }
  325. void FormDict::dump() {
  326. _form.print(dumpkey, dumpform);
  327. }
  328. //------------------------------SourceForm-------------------------------------
  329. SourceForm::SourceForm(char* code) : _code(code) { }; // Constructor
  330. SourceForm::~SourceForm() {
  331. }
  332. void SourceForm::dump() { // Debug printer
  333. output(stderr);
  334. }
  335. void SourceForm::output(FILE *fp) {
  336. fprintf(fp,"\n//%s\n%s\n",classname(),(_code?_code:""));
  337. }