src/share/vm/adlc/forms.cpp

Wed, 02 Jul 2008 12:55:16 -0700

author
xdono
date
Wed, 02 Jul 2008 12:55:16 -0700
changeset 631
d1605aabd0a1
parent 599
c436414a719e
child 850
4d9884b01ba6
permissions
-rw-r--r--

6719955: Update copyright year
Summary: Update copyright year for files that have been modified in 2008
Reviewed-by: ohair, tbell

     1 /*
     2  * Copyright 1997-2008 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  */
    25 // FORMS.CPP - Definitions for ADL Parser Generic & Utility Forms Classes
    26 #include "adlc.hpp"
    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 }
    35 //------------------------------NameList---------------------------------------
    36 // reserved user-defined string
    37 const char  *NameList::_signal   = "$$SIGNAL$$";
    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 }
    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 }
    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 }
    63 int    NameList::count()  const { return _cur; }
    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); }
    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 }
    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 }
    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 }
    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 }
   103 // Return name at index in list
   104 const char  *NameList::name(intptr_t  index) {
   105   return ( index < _cur ? _names[index] : NULL);
   106 }
   108 void   NameList::dump() { output(stderr); }
   110 void   NameList::output(FILE *fp) {
   111   fprintf(fp, "\n");
   113   // Run iteration over all entries, independent of position of iterator.
   114   const char *name       = NULL;
   115   int         iter       = 0;
   116   bool        justReset  = true;
   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 }
   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 }
   134 // Add to entries in list
   135 void NameAndList::add_entry(const char *entry) {
   136   _list.addName(entry);
   137 }
   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(); }
   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.");
   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   }
   155   return entry;
   156 }
   159 void   NameAndList::dump() { output(stderr); }
   160 void   NameAndList::output(FILE *fp) {
   161   fprintf(fp, "\n");
   163   // Output the Name
   164   fprintf(fp, "Name == %s", (_name ? _name : "") );
   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 }
   176 //------------------------------Form-------------------------------------------
   177 OpClassForm   *Form::is_opclass()     const {
   178   return NULL;
   179 }
   181 OperandForm   *Form::is_operand()     const {
   182   return NULL;
   183 }
   185 InstructForm  *Form::is_instruction() const {
   186   return NULL;
   187 }
   189 MachNodeForm  *Form::is_machnode() const {
   190   return NULL;
   191 }
   193 AttributeForm *Form::is_attribute() const {
   194   return NULL;
   195 }
   197 Effect        *Form::is_effect() const {
   198   return NULL;
   199 }
   201 ResourceForm  *Form::is_resource() const {
   202   return NULL;
   203 }
   205 PipeClassForm *Form::is_pipeclass() const {
   206   return NULL;
   207 }
   209 Form::DataType Form::ideal_to_const_type(const char *name) const {
   210   if( name == NULL ) { return Form::none; }
   212   if (strcmp(name,"ConI")==0) return Form::idealI;
   213   if (strcmp(name,"ConP")==0) return Form::idealP;
   214   if (strcmp(name,"ConN")==0) return Form::idealN;
   215   if (strcmp(name,"ConL")==0) return Form::idealL;
   216   if (strcmp(name,"ConF")==0) return Form::idealF;
   217   if (strcmp(name,"ConD")==0) return Form::idealD;
   218   if (strcmp(name,"Bool")==0) return Form::idealI;
   220   return Form::none;
   221 }
   223 Form::DataType Form::ideal_to_sReg_type(const char *name) const {
   224   if( name == NULL ) { return Form::none; }
   226   if (strcmp(name,"sRegI")==0) return Form::idealI;
   227   if (strcmp(name,"sRegP")==0) return Form::idealP;
   228   if (strcmp(name,"sRegF")==0) return Form::idealF;
   229   if (strcmp(name,"sRegD")==0) return Form::idealD;
   230   if (strcmp(name,"sRegL")==0) return Form::idealL;
   231   return Form::none;
   232 }
   234 Form::DataType Form::ideal_to_Reg_type(const char *name) const {
   235   if( name == NULL ) { return Form::none; }
   237   if (strcmp(name,"RegI")==0) return Form::idealI;
   238   if (strcmp(name,"RegP")==0) return Form::idealP;
   239   if (strcmp(name,"RegF")==0) return Form::idealF;
   240   if (strcmp(name,"RegD")==0) return Form::idealD;
   241   if (strcmp(name,"RegL")==0) return Form::idealL;
   243   return Form::none;
   244 }
   246 // True if 'opType', an ideal name, loads or stores.
   247 Form::DataType Form::is_load_from_memory(const char *opType) const {
   248   if( strcmp(opType,"LoadB")==0 )  return Form::idealB;
   249   if( strcmp(opType,"LoadC")==0 )  return Form::idealC;
   250   if( strcmp(opType,"LoadD")==0 )  return Form::idealD;
   251   if( strcmp(opType,"LoadD_unaligned")==0 )  return Form::idealD;
   252   if( strcmp(opType,"LoadF")==0 )  return Form::idealF;
   253   if( strcmp(opType,"LoadI")==0 )  return Form::idealI;
   254   if( strcmp(opType,"LoadKlass")==0 )  return Form::idealP;
   255   if( strcmp(opType,"LoadNKlass")==0 ) return Form::idealN;
   256   if( strcmp(opType,"LoadL")==0 )  return Form::idealL;
   257   if( strcmp(opType,"LoadL_unaligned")==0 )  return Form::idealL;
   258   if( strcmp(opType,"LoadPLocked")==0 )  return Form::idealP;
   259   if( strcmp(opType,"LoadLLocked")==0 )  return Form::idealL;
   260   if( strcmp(opType,"LoadP")==0 )  return Form::idealP;
   261   if( strcmp(opType,"LoadN")==0 )  return Form::idealN;
   262   if( strcmp(opType,"LoadRange")==0 )  return Form::idealI;
   263   if( strcmp(opType,"LoadS")==0 )  return Form::idealS;
   264   if( strcmp(opType,"Load16B")==0 )  return Form::idealB;
   265   if( strcmp(opType,"Load8B")==0 )  return Form::idealB;
   266   if( strcmp(opType,"Load4B")==0 )  return Form::idealB;
   267   if( strcmp(opType,"Load8C")==0 )  return Form::idealC;
   268   if( strcmp(opType,"Load4C")==0 )  return Form::idealC;
   269   if( strcmp(opType,"Load2C")==0 )  return Form::idealC;
   270   if( strcmp(opType,"Load8S")==0 )  return Form::idealS;
   271   if( strcmp(opType,"Load4S")==0 )  return Form::idealS;
   272   if( strcmp(opType,"Load2S")==0 )  return Form::idealS;
   273   if( strcmp(opType,"Load2D")==0 )  return Form::idealD;
   274   if( strcmp(opType,"Load4F")==0 )  return Form::idealF;
   275   if( strcmp(opType,"Load2F")==0 )  return Form::idealF;
   276   if( strcmp(opType,"Load4I")==0 )  return Form::idealI;
   277   if( strcmp(opType,"Load2I")==0 )  return Form::idealI;
   278   if( strcmp(opType,"Load2L")==0 )  return Form::idealL;
   279   assert( strcmp(opType,"Load") != 0, "Must type Loads" );
   280   return Form::none;
   281 }
   283 Form::DataType Form::is_store_to_memory(const char *opType) const {
   284   if( strcmp(opType,"StoreB")==0)  return Form::idealB;
   285   if( strcmp(opType,"StoreCM")==0)  return Form::idealB;
   286   if( strcmp(opType,"StoreC")==0)  return Form::idealC;
   287   if( strcmp(opType,"StoreD")==0)  return Form::idealD;
   288   if( strcmp(opType,"StoreF")==0)  return Form::idealF;
   289   if( strcmp(opType,"StoreI")==0)  return Form::idealI;
   290   if( strcmp(opType,"StoreL")==0)  return Form::idealL;
   291   if( strcmp(opType,"StoreP")==0)  return Form::idealP;
   292   if( strcmp(opType,"StoreN")==0) return Form::idealN;
   293   if( strcmp(opType,"Store16B")==0)  return Form::idealB;
   294   if( strcmp(opType,"Store8B")==0)  return Form::idealB;
   295   if( strcmp(opType,"Store4B")==0)  return Form::idealB;
   296   if( strcmp(opType,"Store8C")==0)  return Form::idealC;
   297   if( strcmp(opType,"Store4C")==0)  return Form::idealC;
   298   if( strcmp(opType,"Store2C")==0)  return Form::idealC;
   299   if( strcmp(opType,"Store2D")==0)  return Form::idealD;
   300   if( strcmp(opType,"Store4F")==0)  return Form::idealF;
   301   if( strcmp(opType,"Store2F")==0)  return Form::idealF;
   302   if( strcmp(opType,"Store4I")==0)  return Form::idealI;
   303   if( strcmp(opType,"Store2I")==0)  return Form::idealI;
   304   if( strcmp(opType,"Store2L")==0)  return Form::idealL;
   305   assert( strcmp(opType,"Store") != 0, "Must type Stores" );
   306   return Form::none;
   307 }
   309 Form::InterfaceType Form::interface_type(FormDict &globals) const {
   310   return Form::no_interface;
   311 }
   313 //------------------------------FormList---------------------------------------
   314 // Destructor
   315 FormList::~FormList()  {
   316   // // This list may not own its elements
   317   // Form *cur  = _root;
   318   // Form *next = NULL;
   319   // for( ; (cur = next) != NULL; ) {
   320   //   next = (Form *)cur->_next;
   321   //   delete cur;
   322   // }
   323 };
   325 //------------------------------FormDict---------------------------------------
   326 // Constructor
   327 FormDict::FormDict( CmpKey cmp, Hash hash, Arena *arena )
   328   : _form(cmp, hash, arena) {
   329 }
   330 FormDict::~FormDict() {
   331 }
   333 // Return # of name-Form pairs in dict
   334 int FormDict::Size(void) const {
   335   return _form.Size();
   336 }
   338 // Insert inserts the given key-value pair into the dictionary.  The prior
   339 // value of the key is returned; NULL if the key was not previously defined.
   340 const Form  *FormDict::Insert(const char *name, Form *form) {
   341   return (Form*)_form.Insert((void*)name, (void*)form);
   342 }
   344 // Finds the value of a given key; or NULL if not found.
   345 // The dictionary is NOT changed.
   346 const Form  *FormDict::operator [](const char *name) const {
   347   return (Form*)_form[name];
   348 }
   350 //------------------------------FormDict::private------------------------------
   351 // Disable public use of constructor, copy-ctor, operator =, operator ==
   352 FormDict::FormDict( ) : _form(cmpkey,hashkey) {
   353   assert( false, "NotImplemented");
   354 }
   355 FormDict::FormDict( const FormDict & fd) : _form(fd._form) {
   356 }
   357 FormDict &FormDict::operator =( const FormDict &rhs) {
   358   assert( false, "NotImplemented");
   359   _form = rhs._form;
   360   return *this;
   361 }
   362 // == compares two dictionaries; they must have the same keys (their keys
   363 // must match using CmpKey) and they must have the same values (pointer
   364 // comparison).  If so 1 is returned, if not 0 is returned.
   365 bool FormDict::operator ==(const FormDict &d) const {
   366   assert( false, "NotImplemented");
   367   return false;
   368 }
   370 // Print out the dictionary contents as key-value pairs
   371 static void dumpkey (const void* key)  { fprintf(stdout, "%s", key); }
   372 static void dumpform(const void* form) { fflush(stdout); ((Form*)form)->dump(); }
   374 void FormDict::dump() {
   375   _form.print(dumpkey, dumpform);
   376 }
   378 //------------------------------SourceForm-------------------------------------
   379 SourceForm::SourceForm(char* code) : _code(code) { }; // Constructor
   380 SourceForm::~SourceForm() {
   381 }
   383 void SourceForm::dump() {                    // Debug printer
   384   output(stderr);
   385 }
   387 void SourceForm::output(FILE *fp) {
   388   fprintf(fp,"\n//%s\n%s\n",classname(),(_code?_code:""));
   389 }

mercurial