< prev index next >

src/share/vm/adlc/adlparse.cpp

Print this page


   1 /*
   2  * Copyright (c) 1997, 2013, 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  *


3468 
3469 //------------------------------opcode_parse-----------------------------------
3470 Opcode * ADLParser::opcode_parse(InstructForm *instr) {
3471   char *primary   = NULL;
3472   char *secondary = NULL;
3473   char *tertiary  = NULL;
3474 
3475   char   *val    = NULL;
3476   Opcode *opcode = NULL;
3477 
3478   // Get value of the instruction's opcode
3479   skipws();
3480   if (_curchar != '(') {         // Check for parenthesized operand list
3481     parse_err(SYNERR, "missing '(' in expand instruction declaration\n");
3482     return NULL;
3483   }
3484   next_char();                   // skip open paren
3485   skipws();
3486   if (_curchar != ')') {
3487     // Parse primary, secondary, and tertiary opcodes, if provided.
3488     if ( ((primary = get_ident_or_literal_constant("primary opcode")) == NULL) ) {
3489         parse_err(SYNERR, "primary hex opcode expected at %c\n", _curchar);
3490         return NULL;
3491     }
3492     skipws();
3493     if (_curchar == ',') {
3494       next_char();
3495       skipws();
3496       // Parse secondary opcode
3497       if ( ((secondary = get_ident_or_literal_constant("secondary opcode")) == NULL) ) {
3498         parse_err(SYNERR, "secondary hex opcode expected at %c\n", _curchar);
3499         return NULL;
3500       }
3501       skipws();
3502       if (_curchar == ',') {
3503         next_char();
3504         skipws();
3505         // Parse tertiary opcode
3506         if ( ((tertiary = get_ident_or_literal_constant("tertiary opcode")) == NULL) ) {
3507           parse_err(SYNERR,"tertiary hex opcode expected at %c\n", _curchar);
3508           return NULL;
3509         }
3510         skipws();
3511       }
3512     }
3513     skipws();
3514     if (_curchar != ')') {
3515       parse_err(SYNERR, "Missing ')' in opcode description\n");
3516       return NULL;
3517     }
3518   }
3519   next_char();                     // Skip ')'
3520   skipws();
3521   // Check for terminator
3522   if (_curchar != ';') {
3523     parse_err(SYNERR, "missing ';' in ins_attrib definition\n");
3524     return NULL;
3525   }
3526   next_char();                     // Advance past the ';'


4756   return ident;
4757 }
4758 
4759 
4760 //------------------------------get_int----------------------------------------
4761 // Looks for a character string integer in the buffer, and turns it into an int
4762 // invokes a parse_err if the next token is not an integer.
4763 // This routine does not leave the integer null-terminated.
4764 int ADLParser::get_int(void) {
4765   register char c;
4766   char         *start;            // Pointer to start of token
4767   char         *end;              // Pointer to end of token
4768   int           result;           // Storage for integer result
4769 
4770   if( _curline == NULL )          // Return NULL at EOF.
4771     return 0;
4772 
4773   skipws();                       // Skip whitespace before identifier
4774   start = end = _ptr;             // Start points at first character
4775   c = *end;                       // Grab character to test
4776   while ((c >= '0') && (c <= '9')
4777          || ((c == '-') && (end == start))) {
4778     end++;                        // Increment end pointer
4779     c = *end;                     // Grab character to test
4780   }
4781   if (start == end) {             // We popped out on the first try
4782     parse_err(SYNERR, "integer expected at %c\n", c);
4783     result = 0;
4784   }
4785   else {
4786     _curchar = c;                 // Save the first character of next token
4787     *end = '\0';                  // NULL terminate the string in place
4788     result = atoi(start);         // Convert the string to an integer
4789     *end = _curchar;              // Restore buffer to original condition
4790   }
4791 
4792   // Reset _ptr to next char after token
4793   _ptr = end;
4794 
4795   return result;                   // integer
4796 }
4797 
4798 
4799 //------------------------------get_relation_dup------------------------------
4800 // Looks for a relational operator in the buffer
4801 // invokes a parse_err if the next token is not a relation
4802 // This routine creates a duplicate of the string in the buffer.
4803 char *ADLParser::get_relation_dup(void) {
4804   char         *result = NULL;    // relational operator being returned
4805 
4806   if( _curline == NULL )          // Return NULL at EOF.
4807     return  NULL;
4808 
4809   skipws();                       // Skip whitespace before relation
4810   char *start = _ptr;             // Store start of relational operator
4811   char first  = *_ptr;            // the first character
4812   if( (first == '=') || (first == '!') || (first == '<') || (first == '>') ) {
4813     next_char();
4814     char second = *_ptr;          // the second character
4815     if( (second == '=') ) {
4816       next_char();
4817       char tmp  = *_ptr;
4818       *_ptr = '\0';               // NULL terminate
4819       result = strdup(start);     // Duplicate the string
4820       *_ptr = tmp;                // restore buffer
4821     } else {
4822       parse_err(SYNERR, "relational operator expected at %s\n", _ptr);
4823     }
4824   } else {
4825     parse_err(SYNERR, "relational operator expected at %s\n", _ptr);
4826   }
4827 
4828   return result;
4829 }
4830 
4831 
4832 
4833 //------------------------------get_oplist-------------------------------------
4834 // Looks for identifier pairs where first must be the name of an operand, and
4835 // second must be a name unique in the scope of this instruction.  Stores the


   1 /*
   2  * Copyright (c) 1997, 2017, 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  *


3468 
3469 //------------------------------opcode_parse-----------------------------------
3470 Opcode * ADLParser::opcode_parse(InstructForm *instr) {
3471   char *primary   = NULL;
3472   char *secondary = NULL;
3473   char *tertiary  = NULL;
3474 
3475   char   *val    = NULL;
3476   Opcode *opcode = NULL;
3477 
3478   // Get value of the instruction's opcode
3479   skipws();
3480   if (_curchar != '(') {         // Check for parenthesized operand list
3481     parse_err(SYNERR, "missing '(' in expand instruction declaration\n");
3482     return NULL;
3483   }
3484   next_char();                   // skip open paren
3485   skipws();
3486   if (_curchar != ')') {
3487     // Parse primary, secondary, and tertiary opcodes, if provided.
3488     if ( (primary = get_ident_or_literal_constant("primary opcode")) == NULL ) {
3489           parse_err(SYNERR, "primary hex opcode expected at %c\n", _curchar);
3490         return NULL;
3491     }
3492     skipws();
3493     if (_curchar == ',') {
3494       next_char();
3495       skipws();
3496       // Parse secondary opcode
3497       if ( (secondary = get_ident_or_literal_constant("secondary opcode")) == NULL ) {
3498         parse_err(SYNERR, "secondary hex opcode expected at %c\n", _curchar);
3499         return NULL;
3500       }
3501       skipws();
3502       if (_curchar == ',') {
3503         next_char();
3504         skipws();
3505         // Parse tertiary opcode
3506         if ( (tertiary = get_ident_or_literal_constant("tertiary opcode")) == NULL ) {
3507           parse_err(SYNERR,"tertiary hex opcode expected at %c\n", _curchar);
3508           return NULL;
3509         }
3510         skipws();
3511       }
3512     }
3513     skipws();
3514     if (_curchar != ')') {
3515       parse_err(SYNERR, "Missing ')' in opcode description\n");
3516       return NULL;
3517     }
3518   }
3519   next_char();                     // Skip ')'
3520   skipws();
3521   // Check for terminator
3522   if (_curchar != ';') {
3523     parse_err(SYNERR, "missing ';' in ins_attrib definition\n");
3524     return NULL;
3525   }
3526   next_char();                     // Advance past the ';'


4756   return ident;
4757 }
4758 
4759 
4760 //------------------------------get_int----------------------------------------
4761 // Looks for a character string integer in the buffer, and turns it into an int
4762 // invokes a parse_err if the next token is not an integer.
4763 // This routine does not leave the integer null-terminated.
4764 int ADLParser::get_int(void) {
4765   register char c;
4766   char         *start;            // Pointer to start of token
4767   char         *end;              // Pointer to end of token
4768   int           result;           // Storage for integer result
4769 
4770   if( _curline == NULL )          // Return NULL at EOF.
4771     return 0;
4772 
4773   skipws();                       // Skip whitespace before identifier
4774   start = end = _ptr;             // Start points at first character
4775   c = *end;                       // Grab character to test
4776   while ((c >= '0' && c <= '9') || (c == '-' && end == start)) {

4777     end++;                        // Increment end pointer
4778     c = *end;                     // Grab character to test
4779   }
4780   if (start == end) {             // We popped out on the first try
4781     parse_err(SYNERR, "integer expected at %c\n", c);
4782     result = 0;
4783   }
4784   else {
4785     _curchar = c;                 // Save the first character of next token
4786     *end = '\0';                  // NULL terminate the string in place
4787     result = atoi(start);         // Convert the string to an integer
4788     *end = _curchar;              // Restore buffer to original condition
4789   }
4790 
4791   // Reset _ptr to next char after token
4792   _ptr = end;
4793 
4794   return result;                   // integer
4795 }
4796 
4797 
4798 //------------------------------get_relation_dup------------------------------
4799 // Looks for a relational operator in the buffer
4800 // invokes a parse_err if the next token is not a relation
4801 // This routine creates a duplicate of the string in the buffer.
4802 char *ADLParser::get_relation_dup(void) {
4803   char         *result = NULL;    // relational operator being returned
4804 
4805   if( _curline == NULL )          // Return NULL at EOF.
4806     return  NULL;
4807 
4808   skipws();                       // Skip whitespace before relation
4809   char *start = _ptr;             // Store start of relational operator
4810   char first  = *_ptr;            // the first character
4811   if( (first == '=') || (first == '!') || (first == '<') || (first == '>') ) {
4812     next_char();
4813     char second = *_ptr;          // the second character
4814     if( second == '=' ) {
4815       next_char();
4816       char tmp  = *_ptr;
4817       *_ptr = '\0';               // NULL terminate
4818       result = strdup(start);     // Duplicate the string
4819       *_ptr = tmp;                // restore buffer
4820     } else {
4821       parse_err(SYNERR, "relational operator expected at %s\n", _ptr);
4822     }
4823   } else {
4824     parse_err(SYNERR, "relational operator expected at %s\n", _ptr);
4825   }
4826 
4827   return result;
4828 }
4829 
4830 
4831 
4832 //------------------------------get_oplist-------------------------------------
4833 // Looks for identifier pairs where first must be the name of an operand, and
4834 // second must be a name unique in the scope of this instruction.  Stores the


< prev index next >