hotspot/src/share/vm/adlc/adlparse.cpp
author ihse
Tue, 15 Dec 2015 10:55:07 +0100
changeset 35164 80ecc1fdfbd6
parent 30202 6f5c48bd9b82
child 46630 75aa3e39d02c
permissions -rw-r--r--
8142909: Integration of minor fixes from the build-infra project Reviewed-by: dholmes, erikj
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
22234
da823d78ad65 8029233: Update copyright year to match last edit in jdk8 hotspot repository for 2013
mikael
parents: 20289
diff changeset
     2
 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 2154
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 2154
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 2154
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
// ADLPARSE.CPP - Architecture Description Language Parser
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
// Authors: Chris Vick and Mike Paleczny
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
#include "adlc.hpp"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
//----------------------------ADLParser----------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
// Create a new ADL parser
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
ADLParser::ADLParser(FileBuff& buffer, ArchDesc& archDesc)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
  : _buf(buffer), _AD(archDesc),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
    _globalNames(archDesc.globalNames()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
  _AD._syntax_errs = _AD._semantic_errs = 0; // No errors so far this file
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
  _AD._warnings    = 0;                      // No warnings either
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
  _curline         = _ptr = NULL;            // No pointers into buffer yet
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  _preproc_depth = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  _preproc_not_taken = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  // Delimit command-line definitions from in-file definitions:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  _AD._preproc_list.add_signal();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
//------------------------------~ADLParser-------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
// Delete an ADL parser.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
ADLParser::~ADLParser() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  if (!_AD._quiet_mode)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
    fprintf(stderr,"---------------------------- Errors and Warnings ----------------------------\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
#ifndef ASSERT
35164
80ecc1fdfbd6 8142909: Integration of minor fixes from the build-infra project
ihse
parents: 30202
diff changeset
    51
  if (!_AD._quiet_mode) {
80ecc1fdfbd6 8142909: Integration of minor fixes from the build-infra project
ihse
parents: 30202
diff changeset
    52
    fprintf(stderr, "**************************************************************\n");
80ecc1fdfbd6 8142909: Integration of minor fixes from the build-infra project
ihse
parents: 30202
diff changeset
    53
    fprintf(stderr, "***** WARNING: ASSERT is undefined, assertions disabled. *****\n");
80ecc1fdfbd6 8142909: Integration of minor fixes from the build-infra project
ihse
parents: 30202
diff changeset
    54
    fprintf(stderr, "**************************************************************\n");
80ecc1fdfbd6 8142909: Integration of minor fixes from the build-infra project
ihse
parents: 30202
diff changeset
    55
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  if( _AD._syntax_errs + _AD._semantic_errs + _AD._warnings == 0 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
    if (!_AD._quiet_mode)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
      fprintf(stderr,"No errors or warnings to report from phase-1 parse.\n" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
    if( _AD._syntax_errs ) {      // Any syntax errors?
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
      fprintf(stderr,"%s:  Found %d syntax error", _buf._fp->_name, _AD._syntax_errs);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
      if( _AD._syntax_errs > 1 ) fprintf(stderr,"s.\n\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
      else fprintf(stderr,".\n\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
    if( _AD._semantic_errs ) {    // Any semantic errors?
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
      fprintf(stderr,"%s:  Found %d semantic error", _buf._fp->_name, _AD._semantic_errs);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
      if( _AD._semantic_errs > 1 ) fprintf(stderr,"s.\n\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
      else fprintf(stderr,".\n\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
    if( _AD._warnings ) {         // Any warnings?
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
      fprintf(stderr,"%s:  Found %d warning", _buf._fp->_name, _AD._warnings);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
      if( _AD._warnings > 1 ) fprintf(stderr,"s.\n\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
      else fprintf(stderr,".\n\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  if (!_AD._quiet_mode)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
    fprintf(stderr,"-----------------------------------------------------------------------------\n");
1495
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
    80
  _AD._TotalLines += linenum()-1;     // -1 for overshoot in "nextline" routine
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  // Write out information we have stored
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  // // UNIXism == fsync(stderr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
//------------------------------parse------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
// Each top-level keyword should appear as the first non-whitespace on a line.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
void ADLParser::parse() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  char *ident;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  // Iterate over the lines in the file buffer parsing Level 1 objects
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  for( next_line(); _curline != NULL; next_line()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
    _ptr = _curline;             // Reset ptr to start of new line
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
    skipws();                    // Skip any leading whitespace
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
    ident = get_ident();         // Get first token
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
    if (ident == NULL) {         // Empty line
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
      continue;                  // Get the next line
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
    }
7433
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
   100
         if (!strcmp(ident, "instruct"))   instr_parse();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
    else if (!strcmp(ident, "operand"))    oper_parse();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
    else if (!strcmp(ident, "opclass"))    opclass_parse();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
    else if (!strcmp(ident, "ins_attrib")) ins_attr_parse();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
    else if (!strcmp(ident, "op_attrib"))  op_attr_parse();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
    else if (!strcmp(ident, "source"))     source_parse();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
    else if (!strcmp(ident, "source_hpp")) source_hpp_parse();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
    else if (!strcmp(ident, "register"))   reg_parse();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
    else if (!strcmp(ident, "frame"))      frame_parse();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
    else if (!strcmp(ident, "encode"))     encode_parse();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
    else if (!strcmp(ident, "pipeline"))   pipe_parse();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
    else if (!strcmp(ident, "definitions")) definitions_parse();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
    else if (!strcmp(ident, "peephole"))   peep_parse();
1662
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
   113
    else if (!strcmp(ident, "#line"))      preproc_line();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
    else if (!strcmp(ident, "#define"))    preproc_define();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
    else if (!strcmp(ident, "#undef"))     preproc_undef();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
    else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
      parse_err(SYNERR, "expected one of - instruct, operand, ins_attrib, op_attrib, source, register, pipeline, encode\n     Found %s",ident);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  }
13104
657b387034fb 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 11197
diff changeset
   120
  // Add reg_class spill_regs after parsing.
657b387034fb 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 11197
diff changeset
   121
  RegisterForm *regBlock = _AD.get_registers();
657b387034fb 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 11197
diff changeset
   122
  if (regBlock == NULL) {
657b387034fb 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 11197
diff changeset
   123
    parse_err(SEMERR, "Did not declare 'register' definitions");
657b387034fb 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 11197
diff changeset
   124
  }
657b387034fb 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 11197
diff changeset
   125
  regBlock->addSpillRegClass();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  // Done with parsing, check consistency.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  if (_preproc_depth != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
    parse_err(SYNERR, "End of file inside #ifdef");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  // AttributeForms ins_cost and op_cost must be defined for default behaviour
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  if (_globalNames[AttributeForm::_ins_cost] == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
    parse_err(SEMERR, "Did not declare 'ins_cost' attribute");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  if (_globalNames[AttributeForm::_op_cost] == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
    parse_err(SEMERR, "Did not declare 'op_cost' attribute");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
// ******************** Private Level 1 Parse Functions ********************
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
//------------------------------instr_parse------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
// Parse the contents of an instruction definition, build the InstructForm to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
// represent that instruction, and add it to the InstructForm list.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
void ADLParser::instr_parse(void) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  char          *ident;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  InstructForm  *instr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  MatchRule     *rule;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  int            match_rules_cnt = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  // First get the name of the instruction
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  if( (ident = get_unique_ident(_globalNames,"instruction")) == NULL )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  instr = new InstructForm(ident); // Create new instruction form
1495
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
   156
  instr->_linenum = linenum();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  _globalNames.Insert(ident, instr); // Add name to the name table
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  // Debugging Stuff
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  if (_AD._adl_debug > 1)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
    fprintf(stderr,"Parsing Instruction Form %s\n", ident);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
  // Then get the operands
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
  if (_curchar != '(') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
    parse_err(SYNERR, "missing '(' in instruct definition\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
  // Parse the operand list
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  else get_oplist(instr->_parameters, instr->_localNames);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  skipws();                        // Skip leading whitespace
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
  // Check for block delimiter
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  if ( (_curchar != '%')
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
       || ( next_char(),  (_curchar != '{')) ) {
15477
26b2c7942f07 8007403: Incorrect format arguments in adlparse.cpp
mikael
parents: 13971
diff changeset
   173
    parse_err(SYNERR, "missing '%%{' in instruction definition\n");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
  next_char();                     // Maintain the invariant
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
  do {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
    ident = get_ident();           // Grab next identifier
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
    if (ident == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
      parse_err(SYNERR, "keyword identifier expected at %c\n", _curchar);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
      continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
    if      (!strcmp(ident, "predicate")) instr->_predicate = pred_parse();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
    else if      (!strcmp(ident, "match")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
      // Allow one instruction have several match rules.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
      rule = instr->_matrule;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
      if (rule == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
        // This is first match rule encountered
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
        rule = match_parse(instr->_localNames);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
        if (rule) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
          instr->_matrule = rule;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
          // Special case the treatment of Control instructions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
          if( instr->is_ideal_control() ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
            // Control instructions return a special result, 'Universe'
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
            rule->_result = "Universe";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
          // Check for commutative operations with tree operands.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
          matchrule_clone_and_swap(rule, instr->_ident, match_rules_cnt);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
        // Find the end of the match rule list
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
        while (rule->_next != NULL)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
          rule = rule->_next;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
        // Add the new match rule to the list
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
        rule->_next = match_parse(instr->_localNames);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
        if (rule->_next) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
          rule = rule->_next;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
          if( instr->is_ideal_control() ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
            parse_err(SYNERR, "unique match rule expected for %s\n", rule->_name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
            return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
          assert(match_rules_cnt < 100," too many match rule clones");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
          char* buf = (char*) malloc(strlen(instr->_ident) + 4);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
          sprintf(buf, "%s_%d", instr->_ident, match_rules_cnt++);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
          rule->_result = buf;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
          // Check for commutative operations with tree operands.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
          matchrule_clone_and_swap(rule, instr->_ident, match_rules_cnt);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
    else if (!strcmp(ident, "encode"))  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
      parse_err(SYNERR, "Instructions specify ins_encode, not encode\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
    }
22844
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
   224
    else if (!strcmp(ident, "ins_encode"))       ins_encode_parse(*instr);
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
   225
    // Parse late expand keyword.
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
   226
    else if (!strcmp(ident, "postalloc_expand")) postalloc_expand_parse(*instr);
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
   227
    else if (!strcmp(ident, "opcode"))           instr->_opcode    = opcode_parse(instr);
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
   228
    else if (!strcmp(ident, "size"))             instr->_size      = size_parse(instr);
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
   229
    else if (!strcmp(ident, "effect"))           effect_parse(instr);
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
   230
    else if (!strcmp(ident, "expand"))           instr->_exprule   = expand_parse(instr);
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
   231
    else if (!strcmp(ident, "rewrite"))          instr->_rewrule   = rewrite_parse();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
    else if (!strcmp(ident, "constraint")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
      parse_err(SYNERR, "Instructions do not specify a constraint\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
    else if (!strcmp(ident, "construct")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
      parse_err(SYNERR, "Instructions do not specify a construct\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
    }
22844
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
   238
    else if (!strcmp(ident, "format"))           instr->_format    = format_parse();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
    else if (!strcmp(ident, "interface")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
      parse_err(SYNERR, "Instructions do not specify an interface\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
    }
7433
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
   242
    else if (!strcmp(ident, "ins_pipe"))        ins_pipe_parse(*instr);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
    else {  // Done with staticly defined parts of instruction definition
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
      // Check identifier to see if it is the name of an attribute
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
      const Form    *form = _globalNames[ident];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
      AttributeForm *attr = form ? form->is_attribute() : NULL;
22844
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
   247
      if (attr && (attr->_atype == INS_ATTR)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
        // Insert the new attribute into the linked list.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
        Attribute *temp = attr_parse(ident);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
        temp->_next = instr->_attribs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
        instr->_attribs = temp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
      } else {
22844
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
   253
        parse_err(SYNERR, "expected one of:\n predicate, match, encode, or the name of"
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
   254
                  " an instruction attribute at %s\n", ident);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
    skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
  } while(_curchar != '%');
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
  next_char();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
  if (_curchar != '}') {
15477
26b2c7942f07 8007403: Incorrect format arguments in adlparse.cpp
mikael
parents: 13971
diff changeset
   261
    parse_err(SYNERR, "missing '%%}' in instruction definition\n");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
  // Check for "Set" form of chain rule
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
  adjust_set_rule(instr);
22844
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
   266
  if (_AD._pipeline) {
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
   267
    // No pipe required for late expand.
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
   268
    if (instr->expands() || instr->postalloc_expands()) {
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
   269
      if (instr->_ins_pipe) {
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
   270
        parse_err(WARN, "ins_pipe and expand rule both specified for instruction \"%s\";"
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
   271
                  " ins_pipe will be unused\n", instr->_ident);
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
   272
      }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
    } else {
22844
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
   274
      if (!instr->_ins_pipe) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
        parse_err(WARN, "No ins_pipe specified for instruction \"%s\"\n", instr->_ident);
22844
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
   276
      }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
  // Add instruction to tail of instruction list
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
  _AD.addForm(instr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
  // Create instruction form for each additional match rule
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
  rule = instr->_matrule;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
  if (rule != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
    rule = rule->_next;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
    while (rule != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
      ident = (char*)rule->_result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
      InstructForm *clone = new InstructForm(ident, instr, rule); // Create new instruction form
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
      _globalNames.Insert(ident, clone); // Add name to the name table
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
      // Debugging Stuff
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
      if (_AD._adl_debug > 1)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
        fprintf(stderr,"Parsing Instruction Form %s\n", ident);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
      // Check for "Set" form of chain rule
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
      adjust_set_rule(clone);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
      // Add instruction to tail of instruction list
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
      _AD.addForm(clone);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
      rule = rule->_next;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
      clone->_matrule->_next = NULL; // One match rule per clone
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
//------------------------------matchrule_clone_and_swap-----------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
// Check for commutative operations with subtree operands,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
// create clones and swap operands.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
void ADLParser::matchrule_clone_and_swap(MatchRule* rule, const char* instr_ident, int& match_rules_cnt) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
  // Check for commutative operations with tree operands.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
  int count = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
  rule->count_commutative_op(count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
  if (count > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
    // Clone match rule and swap commutative operation's operands.
2129
e810a33b5c67 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 1675
diff changeset
   312
    rule->matchrule_swap_commutative_op(instr_ident, count, match_rules_cnt);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
//------------------------------adjust_set_rule--------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
// Check for "Set" form of chain rule
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
void ADLParser::adjust_set_rule(InstructForm *instr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
  if (instr->_matrule == NULL || instr->_matrule->_rChild == NULL) return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
  const char *rch = instr->_matrule->_rChild->_opType;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
  const Form *frm = _globalNames[rch];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
  if( (! strcmp(instr->_matrule->_opType,"Set")) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
      frm && frm->is_operand() && (! frm->ideal_only()) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
    // Previous implementation, which missed leaP*, but worked for loadCon*
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
    unsigned    position = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
    const char *result   = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
    const char *name     = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
    const char *optype   = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
    MatchNode  *right    = instr->_matrule->_rChild;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
    if (right->base_operand(position, _globalNames, result, name, optype)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
      position = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
      const char *result2  = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
      const char *name2    = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
      const char *optype2  = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
      // Can not have additional base operands in right side of match!
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
      if ( ! right->base_operand( position, _globalNames, result2, name2, optype2) ) {
7433
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
   337
        if (instr->_predicate != NULL)
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
   338
          parse_err(SYNERR, "ADLC does not support instruction chain rules with predicates");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
        // Chain from input  _ideal_operand_type_,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
        // Needed for shared roots of match-trees
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
        ChainList *lst = (ChainList *)_AD._chainRules[optype];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
        if (lst == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
          lst = new ChainList();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
          _AD._chainRules.Insert(optype, lst);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
        if (!lst->search(instr->_matrule->_lChild->_opType)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
          const char *cost = instr->cost();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
          if (cost == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
            cost = ((AttributeForm*)_globalNames[AttributeForm::_ins_cost])->_attrdef;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
          // The ADLC does not support chaining from the ideal operand type
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
          // of a predicated user-defined operand
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
          if( frm->is_operand() == NULL || frm->is_operand()->_predicate == NULL ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
            lst->insert(instr->_matrule->_lChild->_opType,cost,instr->_ident);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
        // Chain from input  _user_defined_operand_type_,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
        lst = (ChainList *)_AD._chainRules[result];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
        if (lst == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
          lst = new ChainList();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
          _AD._chainRules.Insert(result, lst);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
        if (!lst->search(instr->_matrule->_lChild->_opType)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
          const char *cost = instr->cost();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
          if (cost == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
            cost = ((AttributeForm*)_globalNames[AttributeForm::_ins_cost])->_attrdef;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
          // It is safe to chain from the top-level user-defined operand even
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
          // if it has a predicate, since the predicate is checked before
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
          // the user-defined type is available.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
          lst->insert(instr->_matrule->_lChild->_opType,cost,instr->_ident);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
        // May have instruction chain rule if root of right-tree is an ideal
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
        OperandForm *rightOp = _globalNames[right->_opType]->is_operand();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
        if( rightOp ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
          const Form *rightRoot = _globalNames[rightOp->_matrule->_opType];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
          if( rightRoot && rightRoot->ideal_only() ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
            const char *chain_op = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
            if( rightRoot->is_instruction() )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
              chain_op = rightOp->_ident;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
            if( chain_op ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
              // Look-up the operation in chain rule table
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
              ChainList *lst = (ChainList *)_AD._chainRules[chain_op];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
              if (lst == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
                lst = new ChainList();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
                _AD._chainRules.Insert(chain_op, lst);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
              // if (!lst->search(instr->_matrule->_lChild->_opType)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
              const char *cost = instr->cost();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
              if (cost == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
                cost = ((AttributeForm*)_globalNames[AttributeForm::_ins_cost])->_attrdef;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
              // This chains from a top-level operand whose predicate, if any,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
              // has been checked.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
              lst->insert(instr->_matrule->_lChild->_opType,cost,instr->_ident);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
              // }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
      } // end chain rule from right-tree's ideal root
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
//------------------------------oper_parse-------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
void ADLParser::oper_parse(void) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
  char          *ident;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
  OperandForm   *oper;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
  AttributeForm *attr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
  MatchRule     *rule;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
  // First get the name of the operand
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
  skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
  if( (ident = get_unique_ident(_globalNames,"operand")) == NULL )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
  oper = new OperandForm(ident);        // Create new operand form
1495
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
   419
  oper->_linenum = linenum();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
  _globalNames.Insert(ident, oper); // Add name to the name table
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
  // Debugging Stuff
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
  if (_AD._adl_debug > 1) fprintf(stderr,"Parsing Operand Form %s\n", ident);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
  // Get the component operands
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
  skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
  if (_curchar != '(') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
    parse_err(SYNERR, "missing '(' in operand definition\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
  else get_oplist(oper->_parameters, oper->_localNames); // Parse the component operand list
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
  skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
  // Check for block delimiter
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
  if ((_curchar != '%') || (*(_ptr+1) != '{')) { // If not open block
15477
26b2c7942f07 8007403: Incorrect format arguments in adlparse.cpp
mikael
parents: 13971
diff changeset
   435
    parse_err(SYNERR, "missing '%%{' in operand definition\n");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
  next_char(); next_char();        // Skip over "%{" symbol
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
  do {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
    ident = get_ident();           // Grab next identifier
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
    if (ident == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
      parse_err(SYNERR, "keyword identifier expected at %c\n", _curchar);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
      continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
    if      (!strcmp(ident, "predicate")) oper->_predicate = pred_parse();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
    else if (!strcmp(ident, "match"))     {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
      // Find the end of the match rule list
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
      rule = oper->_matrule;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
      if (rule) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
        while (rule->_next) rule = rule->_next;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
        // Add the new match rule to the list
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
        rule->_next = match_parse(oper->_localNames);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
        if (rule->_next) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
          rule->_next->_result = oper->_ident;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
      else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
        // This is first match rule encountered
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
        oper->_matrule = match_parse(oper->_localNames);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
        if (oper->_matrule) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
          oper->_matrule->_result = oper->_ident;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
    else if (!strcmp(ident, "encode"))    oper->_interface = interface_parse();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
    else if (!strcmp(ident, "ins_encode")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
      parse_err(SYNERR, "Operands specify 'encode', not 'ins_encode'\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
    else if (!strcmp(ident, "opcode"))    {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
      parse_err(SYNERR, "Operands do not specify an opcode\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
    else if (!strcmp(ident, "effect"))    {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
      parse_err(SYNERR, "Operands do not specify an effect\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
    else if (!strcmp(ident, "expand"))    {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
      parse_err(SYNERR, "Operands do not specify an expand\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
    else if (!strcmp(ident, "rewrite"))   {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
      parse_err(SYNERR, "Operands do not specify a rewrite\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
    else if (!strcmp(ident, "constraint"))oper->_constraint= constraint_parse();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
    else if (!strcmp(ident, "construct")) oper->_construct = construct_parse();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
    else if (!strcmp(ident, "format"))    oper->_format    = format_parse();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
    else if (!strcmp(ident, "interface")) oper->_interface = interface_parse();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
    // Check identifier to see if it is the name of an attribute
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
    else if (((attr = _globalNames[ident]->is_attribute()) != NULL) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
             (attr->_atype == OP_ATTR))   oper->_attribs   = attr_parse(ident);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
    else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
      parse_err(SYNERR, "expected one of - constraint, predicate, match, encode, format, construct, or the name of a defined operand attribute at %s\n", ident);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
    skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
  } while(_curchar != '%');
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
  next_char();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
  if (_curchar != '}') {
15477
26b2c7942f07 8007403: Incorrect format arguments in adlparse.cpp
mikael
parents: 13971
diff changeset
   495
    parse_err(SYNERR, "missing '%%}' in operand definition\n");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
  // Add operand to tail of operand list
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
  _AD.addForm(oper);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
//------------------------------opclass_parse----------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
// Operand Classes are a block with a comma delimited list of operand names
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
void ADLParser::opclass_parse(void) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
  char          *ident;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
  OpClassForm   *opc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
  OperandForm   *opForm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
  // First get the name of the operand class
489c9b5090e2 Initial load
duke
parents:
diff changeset
   510
  skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
  if( (ident = get_unique_ident(_globalNames,"opclass")) == NULL )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   512
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
  opc = new OpClassForm(ident);             // Create new operand class form
489c9b5090e2 Initial load
duke
parents:
diff changeset
   514
  _globalNames.Insert(ident, opc);  // Add name to the name table
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
489c9b5090e2 Initial load
duke
parents:
diff changeset
   516
  // Debugging Stuff
489c9b5090e2 Initial load
duke
parents:
diff changeset
   517
  if (_AD._adl_debug > 1)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   518
    fprintf(stderr,"Parsing Operand Class Form %s\n", ident);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   519
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
  // Get the list of operands
489c9b5090e2 Initial load
duke
parents:
diff changeset
   521
  skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   522
  if (_curchar != '(') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   523
    parse_err(SYNERR, "missing '(' in operand definition\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   524
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
  do {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   527
    next_char();                            // Skip past open paren or comma
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
    ident = get_ident();                    // Grab next identifier
489c9b5090e2 Initial load
duke
parents:
diff changeset
   529
    if (ident == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   530
      parse_err(SYNERR, "keyword identifier expected at %c\n", _curchar);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   531
      continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   532
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   533
    // Check identifier to see if it is the name of an operand
489c9b5090e2 Initial load
duke
parents:
diff changeset
   534
    const Form *form = _globalNames[ident];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   535
    opForm     = form ? form->is_operand() : NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   536
    if ( opForm ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   537
      opc->_oplst.addName(ident);           // Add operand to opclass list
489c9b5090e2 Initial load
duke
parents:
diff changeset
   538
      opForm->_classes.addName(opc->_ident);// Add opclass to operand list
489c9b5090e2 Initial load
duke
parents:
diff changeset
   539
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   540
    else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   541
      parse_err(SYNERR, "expected name of a defined operand at %s\n", ident);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   542
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   543
    skipws();                               // skip trailing whitespace
489c9b5090e2 Initial load
duke
parents:
diff changeset
   544
  } while (_curchar == ',');                // Check for the comma
489c9b5090e2 Initial load
duke
parents:
diff changeset
   545
  // Check for closing ')'
489c9b5090e2 Initial load
duke
parents:
diff changeset
   546
  if (_curchar != ')') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   547
    parse_err(SYNERR, "missing ')' or ',' in opclass definition\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   548
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   549
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   550
  next_char();                              // Consume the ')'
489c9b5090e2 Initial load
duke
parents:
diff changeset
   551
  skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   552
  // Check for closing ';'
489c9b5090e2 Initial load
duke
parents:
diff changeset
   553
  if (_curchar != ';') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   554
    parse_err(SYNERR, "missing ';' in opclass definition\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   555
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   556
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   557
  next_char();                             // Consume the ';'
489c9b5090e2 Initial load
duke
parents:
diff changeset
   558
  // Add operand to tail of operand list
489c9b5090e2 Initial load
duke
parents:
diff changeset
   559
  _AD.addForm(opc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   560
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   561
489c9b5090e2 Initial load
duke
parents:
diff changeset
   562
//------------------------------ins_attr_parse---------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   563
void ADLParser::ins_attr_parse(void) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   564
  char          *ident;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   565
  char          *aexpr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   566
  AttributeForm *attrib;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   567
489c9b5090e2 Initial load
duke
parents:
diff changeset
   568
  // get name for the instruction attribute
489c9b5090e2 Initial load
duke
parents:
diff changeset
   569
  skipws();                      // Skip leading whitespace
489c9b5090e2 Initial load
duke
parents:
diff changeset
   570
  if( (ident = get_unique_ident(_globalNames,"inst_attrib")) == NULL )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   571
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   572
  // Debugging Stuff
489c9b5090e2 Initial load
duke
parents:
diff changeset
   573
  if (_AD._adl_debug > 1) fprintf(stderr,"Parsing Ins_Attribute Form %s\n", ident);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   574
489c9b5090e2 Initial load
duke
parents:
diff changeset
   575
  // Get default value of the instruction attribute
489c9b5090e2 Initial load
duke
parents:
diff changeset
   576
  skipws();                      // Skip whitespace
489c9b5090e2 Initial load
duke
parents:
diff changeset
   577
  if ((aexpr = get_paren_expr("attribute default expression string")) == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   578
    parse_err(SYNERR, "missing '(' in ins_attrib definition\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   579
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   580
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   581
  // Debug Stuff
489c9b5090e2 Initial load
duke
parents:
diff changeset
   582
  if (_AD._adl_debug > 1) fprintf(stderr,"Attribute Expression: %s\n", aexpr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   583
489c9b5090e2 Initial load
duke
parents:
diff changeset
   584
  // Check for terminator
489c9b5090e2 Initial load
duke
parents:
diff changeset
   585
  if (_curchar != ';') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   586
    parse_err(SYNERR, "missing ';' in ins_attrib definition\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   587
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   588
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   589
  next_char();                    // Advance past the ';'
489c9b5090e2 Initial load
duke
parents:
diff changeset
   590
489c9b5090e2 Initial load
duke
parents:
diff changeset
   591
  // Construct the attribute, record global name, and store in ArchDesc
489c9b5090e2 Initial load
duke
parents:
diff changeset
   592
  attrib = new AttributeForm(ident, INS_ATTR, aexpr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   593
  _globalNames.Insert(ident, attrib);  // Add name to the name table
489c9b5090e2 Initial load
duke
parents:
diff changeset
   594
  _AD.addForm(attrib);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   595
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   596
489c9b5090e2 Initial load
duke
parents:
diff changeset
   597
//------------------------------op_attr_parse----------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   598
void ADLParser::op_attr_parse(void) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   599
  char          *ident;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   600
  char          *aexpr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   601
  AttributeForm *attrib;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   602
489c9b5090e2 Initial load
duke
parents:
diff changeset
   603
  // get name for the operand attribute
489c9b5090e2 Initial load
duke
parents:
diff changeset
   604
  skipws();                      // Skip leading whitespace
489c9b5090e2 Initial load
duke
parents:
diff changeset
   605
  if( (ident = get_unique_ident(_globalNames,"op_attrib")) == NULL )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   606
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   607
  // Debugging Stuff
489c9b5090e2 Initial load
duke
parents:
diff changeset
   608
  if (_AD._adl_debug > 1) fprintf(stderr,"Parsing Op_Attribute Form %s\n", ident);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   609
489c9b5090e2 Initial load
duke
parents:
diff changeset
   610
  // Get default value of the instruction attribute
489c9b5090e2 Initial load
duke
parents:
diff changeset
   611
  skipws();                      // Skip whitespace
489c9b5090e2 Initial load
duke
parents:
diff changeset
   612
  if ((aexpr = get_paren_expr("attribute default expression string")) == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   613
    parse_err(SYNERR, "missing '(' in op_attrib definition\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   614
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   615
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   616
  // Debug Stuff
489c9b5090e2 Initial load
duke
parents:
diff changeset
   617
  if (_AD._adl_debug > 1) fprintf(stderr,"Attribute Expression: %s\n", aexpr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   618
489c9b5090e2 Initial load
duke
parents:
diff changeset
   619
  // Check for terminator
489c9b5090e2 Initial load
duke
parents:
diff changeset
   620
  if (_curchar != ';') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   621
    parse_err(SYNERR, "missing ';' in op_attrib definition\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   622
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   623
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   624
  next_char();                    // Advance past the ';'
489c9b5090e2 Initial load
duke
parents:
diff changeset
   625
489c9b5090e2 Initial load
duke
parents:
diff changeset
   626
  // Construct the attribute, record global name, and store in ArchDesc
489c9b5090e2 Initial load
duke
parents:
diff changeset
   627
  attrib = new AttributeForm(ident, OP_ATTR, aexpr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   628
  _globalNames.Insert(ident, attrib);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   629
  _AD.addForm(attrib);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   630
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   631
489c9b5090e2 Initial load
duke
parents:
diff changeset
   632
//------------------------------definitions_parse-----------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   633
void ADLParser::definitions_parse(void) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   634
  skipws();                       // Skip leading whitespace
489c9b5090e2 Initial load
duke
parents:
diff changeset
   635
  if (_curchar == '%' && *(_ptr+1) == '{') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   636
    next_char(); next_char();     // Skip "%{"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   637
    skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   638
    while (_curchar != '%' && *(_ptr+1) != '}') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   639
      // Process each definition until finding closing string "%}"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   640
      char *token = get_ident();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   641
      if (token == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   642
        parse_err(SYNERR, "missing identifier inside definitions block.\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   643
        return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   644
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   645
      if (strcmp(token,"int_def")==0)     { int_def_parse(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   646
      // if (strcmp(token,"str_def")==0)   { str_def_parse(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   647
      skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   648
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   649
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   650
  else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   651
    parse_err(SYNERR, "Missing %%{ ... %%} block after definitions keyword.\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   652
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   653
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   654
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   655
489c9b5090e2 Initial load
duke
parents:
diff changeset
   656
//------------------------------int_def_parse----------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   657
// Parse Example:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   658
// int_def    MEMORY_REF_COST      (         200,  DEFAULT_COST * 2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   659
// <keyword>  <name>               ( <int_value>,   <description>  );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   660
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   661
void ADLParser::int_def_parse(void) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   662
  char *name        = NULL;         // Name of definition
489c9b5090e2 Initial load
duke
parents:
diff changeset
   663
  char *value       = NULL;         // its value,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   664
  int   int_value   = -1;           // positive values only
489c9b5090e2 Initial load
duke
parents:
diff changeset
   665
  char *description = NULL;         // textual description
489c9b5090e2 Initial load
duke
parents:
diff changeset
   666
489c9b5090e2 Initial load
duke
parents:
diff changeset
   667
  // Get definition name
489c9b5090e2 Initial load
duke
parents:
diff changeset
   668
  skipws();                      // Skip whitespace
489c9b5090e2 Initial load
duke
parents:
diff changeset
   669
  name = get_ident();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   670
  if (name == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   671
    parse_err(SYNERR, "missing definition name after int_def\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   672
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   673
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   674
489c9b5090e2 Initial load
duke
parents:
diff changeset
   675
  // Check for value of int_def dname( integer_value [, string_expression ] )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   676
  skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   677
  if (_curchar == '(') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   678
489c9b5090e2 Initial load
duke
parents:
diff changeset
   679
    // Parse the integer value.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   680
    next_char();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   681
    value = get_ident();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   682
    if (value == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   683
      parse_err(SYNERR, "missing value in int_def\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   684
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   685
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   686
    if( !is_int_token(value, int_value) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   687
      parse_err(SYNERR, "value in int_def is not recognized as integer\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   688
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   689
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   690
    skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   691
489c9b5090e2 Initial load
duke
parents:
diff changeset
   692
    // Check for description
489c9b5090e2 Initial load
duke
parents:
diff changeset
   693
    if (_curchar == ',') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   694
      next_char();   // skip ','
489c9b5090e2 Initial load
duke
parents:
diff changeset
   695
489c9b5090e2 Initial load
duke
parents:
diff changeset
   696
      description = get_expr("int_def description", ")");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   697
      if (description == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   698
        parse_err(SYNERR, "invalid or missing description in int_def\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   699
        return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   700
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   701
      trim(description);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   702
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   703
489c9b5090e2 Initial load
duke
parents:
diff changeset
   704
    if (_curchar != ')') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   705
      parse_err(SYNERR, "missing ')' in register definition statement\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   706
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   707
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   708
    next_char();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   709
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   710
489c9b5090e2 Initial load
duke
parents:
diff changeset
   711
  // Check for closing ';'
489c9b5090e2 Initial load
duke
parents:
diff changeset
   712
  skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   713
  if (_curchar != ';') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   714
    parse_err(SYNERR, "missing ';' after int_def\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   715
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   716
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   717
  next_char();                   // move past ';'
489c9b5090e2 Initial load
duke
parents:
diff changeset
   718
489c9b5090e2 Initial load
duke
parents:
diff changeset
   719
  // Debug Stuff
489c9b5090e2 Initial load
duke
parents:
diff changeset
   720
  if (_AD._adl_debug > 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   721
    fprintf(stderr,"int_def: %s ( %s, %s )\n", name,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   722
            (value), (description ? description : ""));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   723
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   724
489c9b5090e2 Initial load
duke
parents:
diff changeset
   725
  // Record new definition.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   726
  Expr *expr     = new Expr(name, description, int_value, int_value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   727
  const Expr *old_expr = _AD.globalDefs().define(name, expr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   728
  if (old_expr != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   729
    parse_err(SYNERR, "Duplicate definition\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   730
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   731
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   732
489c9b5090e2 Initial load
duke
parents:
diff changeset
   733
  return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   734
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   735
489c9b5090e2 Initial load
duke
parents:
diff changeset
   736
489c9b5090e2 Initial load
duke
parents:
diff changeset
   737
//------------------------------source_parse-----------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   738
void ADLParser::source_parse(void) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   739
  SourceForm *source;             // Encode class for instruction/operand
489c9b5090e2 Initial load
duke
parents:
diff changeset
   740
  char   *rule = NULL;            // String representation of encode rule
489c9b5090e2 Initial load
duke
parents:
diff changeset
   741
489c9b5090e2 Initial load
duke
parents:
diff changeset
   742
  skipws();                       // Skip leading whitespace
489c9b5090e2 Initial load
duke
parents:
diff changeset
   743
  if ( (rule = find_cpp_block("source block")) == NULL ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   744
    parse_err(SYNERR, "incorrect or missing block for 'source'.\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   745
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   746
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   747
  // Debug Stuff
489c9b5090e2 Initial load
duke
parents:
diff changeset
   748
  if (_AD._adl_debug > 1) fprintf(stderr,"Source Form: %s\n", rule);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   749
489c9b5090e2 Initial load
duke
parents:
diff changeset
   750
  source = new SourceForm(rule);    // Build new Source object
489c9b5090e2 Initial load
duke
parents:
diff changeset
   751
  _AD.addForm(source);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   752
  // skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   753
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   754
489c9b5090e2 Initial load
duke
parents:
diff changeset
   755
//------------------------------source_hpp_parse-------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   756
// Parse a source_hpp %{ ... %} block.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   757
// The code gets stuck into the ad_<arch>.hpp file.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   758
// If the source_hpp block appears before the register block in the AD
489c9b5090e2 Initial load
duke
parents:
diff changeset
   759
// file, it goes up at the very top of the ad_<arch>.hpp file, so that
489c9b5090e2 Initial load
duke
parents:
diff changeset
   760
// it can be used by register encodings, etc.  Otherwise, it goes towards
489c9b5090e2 Initial load
duke
parents:
diff changeset
   761
// the bottom, where it's useful as a global definition to *.cpp files.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   762
void ADLParser::source_hpp_parse(void) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   763
  char   *rule = NULL;            // String representation of encode rule
489c9b5090e2 Initial load
duke
parents:
diff changeset
   764
489c9b5090e2 Initial load
duke
parents:
diff changeset
   765
  skipws();                       // Skip leading whitespace
489c9b5090e2 Initial load
duke
parents:
diff changeset
   766
  if ( (rule = find_cpp_block("source_hpp block")) == NULL ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   767
    parse_err(SYNERR, "incorrect or missing block for 'source_hpp'.\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   768
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   769
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   770
  // Debug Stuff
489c9b5090e2 Initial load
duke
parents:
diff changeset
   771
  if (_AD._adl_debug > 1) fprintf(stderr,"Header Form: %s\n", rule);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   772
489c9b5090e2 Initial load
duke
parents:
diff changeset
   773
  if (_AD.get_registers() == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   774
    // Very early in the file, before reg_defs, we collect pre-headers.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   775
    PreHeaderForm* pre_header = new PreHeaderForm(rule);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   776
    _AD.addForm(pre_header);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   777
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   778
    // Normally, we collect header info, placed at the bottom of the hpp file.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   779
    HeaderForm* header = new HeaderForm(rule);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   780
    _AD.addForm(header);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   781
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   782
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   783
489c9b5090e2 Initial load
duke
parents:
diff changeset
   784
//------------------------------reg_parse--------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   785
void ADLParser::reg_parse(void) {
13104
657b387034fb 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 11197
diff changeset
   786
  RegisterForm *regBlock = _AD.get_registers(); // Information about registers encoding
657b387034fb 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 11197
diff changeset
   787
  if (regBlock == NULL) {
657b387034fb 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 11197
diff changeset
   788
    // Create the RegisterForm for the architecture description.
657b387034fb 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 11197
diff changeset
   789
    regBlock = new RegisterForm();    // Build new Source object
657b387034fb 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 11197
diff changeset
   790
    _AD.addForm(regBlock);
657b387034fb 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 11197
diff changeset
   791
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   792
489c9b5090e2 Initial load
duke
parents:
diff changeset
   793
  skipws();                       // Skip leading whitespace
489c9b5090e2 Initial load
duke
parents:
diff changeset
   794
  if (_curchar == '%' && *(_ptr+1) == '{') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   795
    next_char(); next_char();     // Skip "%{"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   796
    skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   797
    while (_curchar != '%' && *(_ptr+1) != '}') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   798
      char *token = get_ident();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   799
      if (token == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   800
        parse_err(SYNERR, "missing identifier inside register block.\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   801
        return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   802
      }
1662
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
   803
      if (strcmp(token,"reg_def")==0)          { reg_def_parse(); }
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
   804
      else if (strcmp(token,"reg_class")==0)   { reg_class_parse(); }
30202
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
   805
      else if (strcmp(token, "reg_class_dynamic") == 0) { reg_class_dynamic_parse(); }
1662
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
   806
      else if (strcmp(token,"alloc_class")==0) { alloc_class_parse(); }
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
   807
      else if (strcmp(token,"#define")==0)     { preproc_define(); }
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
   808
      else { parse_err(SYNERR, "bad token %s inside register block.\n", token); break; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   809
      skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   810
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   811
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   812
  else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   813
    parse_err(SYNERR, "Missing %c{ ... %c} block after register keyword.\n",'%','%');
489c9b5090e2 Initial load
duke
parents:
diff changeset
   814
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   815
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   816
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   817
489c9b5090e2 Initial load
duke
parents:
diff changeset
   818
//------------------------------encode_parse-----------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   819
void ADLParser::encode_parse(void) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   820
  EncodeForm *encBlock;         // Information about instruction/operand encoding
489c9b5090e2 Initial load
duke
parents:
diff changeset
   821
489c9b5090e2 Initial load
duke
parents:
diff changeset
   822
  _AD.getForm(&encBlock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   823
  if ( encBlock == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   824
    // Create the EncodeForm for the architecture description.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   825
    encBlock = new EncodeForm();    // Build new Source object
489c9b5090e2 Initial load
duke
parents:
diff changeset
   826
    _AD.addForm(encBlock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   827
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   828
489c9b5090e2 Initial load
duke
parents:
diff changeset
   829
  skipws();                       // Skip leading whitespace
489c9b5090e2 Initial load
duke
parents:
diff changeset
   830
  if (_curchar == '%' && *(_ptr+1) == '{') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   831
    next_char(); next_char();     // Skip "%{"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   832
    skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   833
    while (_curchar != '%' && *(_ptr+1) != '}') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   834
      char *token = get_ident();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   835
      if (token == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   836
            parse_err(SYNERR, "missing identifier inside encoding block.\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   837
            return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   838
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   839
      if (strcmp(token,"enc_class")==0)   { enc_class_parse(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   840
      skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   841
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   842
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   843
  else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   844
    parse_err(SYNERR, "Missing %c{ ... %c} block after encode keyword.\n",'%','%');
489c9b5090e2 Initial load
duke
parents:
diff changeset
   845
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   846
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   847
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   848
489c9b5090e2 Initial load
duke
parents:
diff changeset
   849
//------------------------------enc_class_parse--------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   850
void ADLParser::enc_class_parse(void) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   851
  char       *ec_name;           // Name of encoding class being defined
489c9b5090e2 Initial load
duke
parents:
diff changeset
   852
489c9b5090e2 Initial load
duke
parents:
diff changeset
   853
  // Get encoding class name
489c9b5090e2 Initial load
duke
parents:
diff changeset
   854
  skipws();                      // Skip whitespace
489c9b5090e2 Initial load
duke
parents:
diff changeset
   855
  ec_name = get_ident();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   856
  if (ec_name == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   857
    parse_err(SYNERR, "missing encoding class name after encode.\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   858
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   859
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   860
489c9b5090e2 Initial load
duke
parents:
diff changeset
   861
  EncClass  *encoding = _AD._encode->add_EncClass(ec_name);
1495
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
   862
  encoding->_linenum = linenum();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   863
489c9b5090e2 Initial load
duke
parents:
diff changeset
   864
  skipws();                      // Skip leading whitespace
489c9b5090e2 Initial load
duke
parents:
diff changeset
   865
  // Check for optional parameter list
489c9b5090e2 Initial load
duke
parents:
diff changeset
   866
  if (_curchar == '(') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   867
    do {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   868
      char *pType = NULL;        // parameter type
489c9b5090e2 Initial load
duke
parents:
diff changeset
   869
      char *pName = NULL;        // parameter name
489c9b5090e2 Initial load
duke
parents:
diff changeset
   870
489c9b5090e2 Initial load
duke
parents:
diff changeset
   871
      next_char();               // skip open paren & comma characters
489c9b5090e2 Initial load
duke
parents:
diff changeset
   872
      skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   873
      if (_curchar == ')') break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   874
489c9b5090e2 Initial load
duke
parents:
diff changeset
   875
      // Get parameter type
489c9b5090e2 Initial load
duke
parents:
diff changeset
   876
      pType = get_ident();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   877
      if (pType == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   878
        parse_err(SYNERR, "parameter type expected at %c\n", _curchar);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   879
        return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   880
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   881
489c9b5090e2 Initial load
duke
parents:
diff changeset
   882
      skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   883
      // Get parameter name
489c9b5090e2 Initial load
duke
parents:
diff changeset
   884
      pName = get_ident();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   885
      if (pName == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   886
        parse_err(SYNERR, "parameter name expected at %c\n", _curchar);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   887
        return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   888
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   889
489c9b5090e2 Initial load
duke
parents:
diff changeset
   890
      // Record parameter type and name
489c9b5090e2 Initial load
duke
parents:
diff changeset
   891
      encoding->add_parameter( pType, pName );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   892
489c9b5090e2 Initial load
duke
parents:
diff changeset
   893
      skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   894
    } while(_curchar == ',');
489c9b5090e2 Initial load
duke
parents:
diff changeset
   895
489c9b5090e2 Initial load
duke
parents:
diff changeset
   896
    if (_curchar != ')') parse_err(SYNERR, "missing ')'\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   897
    else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   898
      next_char();                  // Skip ')'
489c9b5090e2 Initial load
duke
parents:
diff changeset
   899
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   900
  } // Done with parameter list
489c9b5090e2 Initial load
duke
parents:
diff changeset
   901
489c9b5090e2 Initial load
duke
parents:
diff changeset
   902
  skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   903
  // Check for block starting delimiters
489c9b5090e2 Initial load
duke
parents:
diff changeset
   904
  if ((_curchar != '%') || (*(_ptr+1) != '{')) { // If not open block
489c9b5090e2 Initial load
duke
parents:
diff changeset
   905
    parse_err(SYNERR, "missing '%c{' in enc_class definition\n", '%');
489c9b5090e2 Initial load
duke
parents:
diff changeset
   906
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   907
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   908
  next_char();                      // Skip '%'
489c9b5090e2 Initial load
duke
parents:
diff changeset
   909
  next_char();                      // Skip '{'
489c9b5090e2 Initial load
duke
parents:
diff changeset
   910
489c9b5090e2 Initial load
duke
parents:
diff changeset
   911
  enc_class_parse_block(encoding, ec_name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   912
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   913
489c9b5090e2 Initial load
duke
parents:
diff changeset
   914
489c9b5090e2 Initial load
duke
parents:
diff changeset
   915
void ADLParser::enc_class_parse_block(EncClass* encoding, char* ec_name) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   916
  skipws_no_preproc();              // Skip leading whitespace
489c9b5090e2 Initial load
duke
parents:
diff changeset
   917
  // Prepend location descriptor, for debugging; cf. ADLParser::find_cpp_block
489c9b5090e2 Initial load
duke
parents:
diff changeset
   918
  if (_AD._adlocation_debug) {
1662
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
   919
    encoding->add_code(get_line_string());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   920
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   921
489c9b5090e2 Initial load
duke
parents:
diff changeset
   922
  // Collect the parts of the encode description
489c9b5090e2 Initial load
duke
parents:
diff changeset
   923
  // (1) strings that are passed through to output
489c9b5090e2 Initial load
duke
parents:
diff changeset
   924
  // (2) replacement/substitution variable, preceeded by a '$'
489c9b5090e2 Initial load
duke
parents:
diff changeset
   925
  while ( (_curchar != '%') && (*(_ptr+1) != '}') ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   926
489c9b5090e2 Initial load
duke
parents:
diff changeset
   927
    // (1)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   928
    // Check if there is a string to pass through to output
489c9b5090e2 Initial load
duke
parents:
diff changeset
   929
    char *start = _ptr;       // Record start of the next string
489c9b5090e2 Initial load
duke
parents:
diff changeset
   930
    while ((_curchar != '$') && ((_curchar != '%') || (*(_ptr+1) != '}')) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   931
      // If at the start of a comment, skip past it
489c9b5090e2 Initial load
duke
parents:
diff changeset
   932
      if( (_curchar == '/') && ((*(_ptr+1) == '/') || (*(_ptr+1) == '*')) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   933
        skipws_no_preproc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   934
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   935
        // ELSE advance to the next character, or start of the next line
489c9b5090e2 Initial load
duke
parents:
diff changeset
   936
        next_char_or_line();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   937
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   938
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   939
    // If a string was found, terminate it and record in EncClass
489c9b5090e2 Initial load
duke
parents:
diff changeset
   940
    if ( start != _ptr ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   941
      *_ptr  = '\0';          // Terminate the string
489c9b5090e2 Initial load
duke
parents:
diff changeset
   942
      encoding->add_code(start);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   943
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   944
489c9b5090e2 Initial load
duke
parents:
diff changeset
   945
    // (2)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   946
    // If we are at a replacement variable,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   947
    // copy it and record in EncClass
7433
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
   948
    if (_curchar == '$') {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   949
      // Found replacement Variable
7433
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
   950
      char* rep_var = get_rep_var_ident_dup();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   951
      // Add flag to _strings list indicating we should check _rep_vars
489c9b5090e2 Initial load
duke
parents:
diff changeset
   952
      encoding->add_rep_var(rep_var);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   953
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   954
  } // end while part of format description
489c9b5090e2 Initial load
duke
parents:
diff changeset
   955
  next_char();                      // Skip '%'
489c9b5090e2 Initial load
duke
parents:
diff changeset
   956
  next_char();                      // Skip '}'
489c9b5090e2 Initial load
duke
parents:
diff changeset
   957
489c9b5090e2 Initial load
duke
parents:
diff changeset
   958
  skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   959
1662
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
   960
  if (_AD._adlocation_debug) {
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
   961
    encoding->add_code(end_line_marker());
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
   962
  }
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
   963
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   964
  // Debug Stuff
489c9b5090e2 Initial load
duke
parents:
diff changeset
   965
  if (_AD._adl_debug > 1) fprintf(stderr,"EncodingClass Form: %s\n", ec_name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   966
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   967
489c9b5090e2 Initial load
duke
parents:
diff changeset
   968
//------------------------------frame_parse-----------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   969
void ADLParser::frame_parse(void) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   970
  FrameForm  *frame;              // Information about stack-frame layout
489c9b5090e2 Initial load
duke
parents:
diff changeset
   971
  char       *desc = NULL;        // String representation of frame
489c9b5090e2 Initial load
duke
parents:
diff changeset
   972
489c9b5090e2 Initial load
duke
parents:
diff changeset
   973
  skipws();                       // Skip leading whitespace
489c9b5090e2 Initial load
duke
parents:
diff changeset
   974
489c9b5090e2 Initial load
duke
parents:
diff changeset
   975
  frame = new FrameForm();        // Build new Frame object
489c9b5090e2 Initial load
duke
parents:
diff changeset
   976
  // Check for open block sequence
489c9b5090e2 Initial load
duke
parents:
diff changeset
   977
  skipws();                       // Skip leading whitespace
489c9b5090e2 Initial load
duke
parents:
diff changeset
   978
  if (_curchar == '%' && *(_ptr+1) == '{') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   979
    next_char(); next_char();     // Skip "%{"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   980
    skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   981
    while (_curchar != '%' && *(_ptr+1) != '}') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   982
      char *token = get_ident();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   983
      if (token == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   984
            parse_err(SYNERR, "missing identifier inside frame block.\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   985
            return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   986
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   987
      if (strcmp(token,"stack_direction")==0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   988
        stack_dir_parse(frame);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   989
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   990
      if (strcmp(token,"sync_stack_slots")==0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   991
        sync_stack_slots_parse(frame);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   992
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   993
      if (strcmp(token,"frame_pointer")==0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   994
        frame_pointer_parse(frame, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   995
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   996
      if (strcmp(token,"interpreter_frame_pointer")==0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   997
        interpreter_frame_pointer_parse(frame, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   998
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   999
      if (strcmp(token,"inline_cache_reg")==0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1000
        inline_cache_parse(frame, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1001
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1002
      if (strcmp(token,"compiler_method_oop_reg")==0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1003
        parse_err(WARN, "Using obsolete Token, compiler_method_oop_reg");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1004
        skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1005
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1006
      if (strcmp(token,"interpreter_method_oop_reg")==0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1007
        interpreter_method_oop_parse(frame, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1008
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1009
      if (strcmp(token,"cisc_spilling_operand_name")==0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1010
        cisc_spilling_operand_name_parse(frame, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1011
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1012
      if (strcmp(token,"stack_alignment")==0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1013
        stack_alignment_parse(frame);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1014
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1015
      if (strcmp(token,"return_addr")==0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1016
        return_addr_parse(frame, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1017
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1018
      if (strcmp(token,"in_preserve_stack_slots")==0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1019
        preserve_stack_parse(frame);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1020
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1021
      if (strcmp(token,"out_preserve_stack_slots")==0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1022
        parse_err(WARN, "Using obsolete token, out_preserve_stack_slots");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1023
        skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1024
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1025
      if (strcmp(token,"varargs_C_out_slots_killed")==0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1026
        frame->_varargs_C_out_slots_killed = parse_one_arg("varargs C out slots killed");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1027
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1028
      if (strcmp(token,"calling_convention")==0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1029
        frame->_calling_convention = calling_convention_parse();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1030
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1031
      if (strcmp(token,"return_value")==0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1032
        frame->_return_value = return_value_parse();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1033
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1034
      if (strcmp(token,"c_frame_pointer")==0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1035
        frame_pointer_parse(frame, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1036
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1037
      if (strcmp(token,"c_return_addr")==0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1038
        return_addr_parse(frame, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1039
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1040
      if (strcmp(token,"c_calling_convention")==0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1041
        frame->_c_calling_convention = calling_convention_parse();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1042
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1043
      if (strcmp(token,"c_return_value")==0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1044
        frame->_c_return_value = return_value_parse();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1045
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1046
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1047
      skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1048
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1049
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1050
  else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1051
    parse_err(SYNERR, "Missing %c{ ... %c} block after encode keyword.\n",'%','%');
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1052
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1053
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1054
  // All Java versions are required, native versions are optional
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1055
  if(frame->_frame_pointer == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1056
    parse_err(SYNERR, "missing frame pointer definition in frame section.\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1057
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1058
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1059
  // !!!!! !!!!!
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1060
  // if(frame->_interpreter_frame_ptr_reg == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1061
  //   parse_err(SYNERR, "missing interpreter frame pointer definition in frame section.\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1062
  //   return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1063
  // }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1064
  if(frame->_alignment == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1065
    parse_err(SYNERR, "missing alignment definition in frame section.\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1066
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1067
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1068
  if(frame->_return_addr == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1069
    parse_err(SYNERR, "missing return address location in frame section.\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1070
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1071
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1072
  if(frame->_in_preserve_slots == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1073
    parse_err(SYNERR, "missing stack slot preservation definition in frame section.\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1074
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1075
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1076
  if(frame->_varargs_C_out_slots_killed == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1077
    parse_err(SYNERR, "missing varargs C out slots killed definition in frame section.\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1078
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1079
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1080
  if(frame->_calling_convention == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1081
    parse_err(SYNERR, "missing calling convention definition in frame section.\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1082
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1083
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1084
  if(frame->_return_value == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1085
    parse_err(SYNERR, "missing return value definition in frame section.\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1086
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1087
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1088
  // Fill natives in identically with the Java versions if not present.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1089
  if(frame->_c_frame_pointer == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1090
    frame->_c_frame_pointer = frame->_frame_pointer;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1091
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1092
  if(frame->_c_return_addr == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1093
    frame->_c_return_addr = frame->_return_addr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1094
    frame->_c_return_addr_loc = frame->_return_addr_loc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1095
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1096
  if(frame->_c_calling_convention == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1097
    frame->_c_calling_convention = frame->_calling_convention;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1098
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1099
  if(frame->_c_return_value == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1100
    frame->_c_return_value = frame->_return_value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1101
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1102
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1103
  // Debug Stuff
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1104
  if (_AD._adl_debug > 1) fprintf(stderr,"Frame Form: %s\n", desc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1105
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1106
  // Create the EncodeForm for the architecture description.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1107
  _AD.addForm(frame);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1108
  // skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1109
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1110
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1111
//------------------------------stack_dir_parse--------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1112
void ADLParser::stack_dir_parse(FrameForm *frame) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1113
  char *direction = parse_one_arg("stack direction entry");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1114
  if (strcmp(direction, "TOWARDS_LOW") == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1115
    frame->_direction = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1116
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1117
  else if (strcmp(direction, "TOWARDS_HIGH") == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1118
    frame->_direction = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1119
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1120
  else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1121
    parse_err(SYNERR, "invalid value inside stack direction entry.\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1122
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1123
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1124
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1125
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1126
//------------------------------sync_stack_slots_parse-------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1127
void ADLParser::sync_stack_slots_parse(FrameForm *frame) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1128
    // Assign value into frame form
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1129
    frame->_sync_stack_slots = parse_one_arg("sync stack slots entry");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1130
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1131
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1132
//------------------------------frame_pointer_parse----------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1133
void ADLParser::frame_pointer_parse(FrameForm *frame, bool native) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1134
  char *frame_pointer = parse_one_arg("frame pointer entry");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1135
  // Assign value into frame form
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1136
  if (native) { frame->_c_frame_pointer = frame_pointer; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1137
  else        { frame->_frame_pointer   = frame_pointer; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1138
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1139
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1140
//------------------------------interpreter_frame_pointer_parse----------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1141
void ADLParser::interpreter_frame_pointer_parse(FrameForm *frame, bool native) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1142
  frame->_interpreter_frame_pointer_reg = parse_one_arg("interpreter frame pointer entry");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1143
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1144
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1145
//------------------------------inline_cache_parse-----------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1146
void ADLParser::inline_cache_parse(FrameForm *frame, bool native) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1147
  frame->_inline_cache_reg = parse_one_arg("inline cache reg entry");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1148
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1149
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1150
//------------------------------interpreter_method_oop_parse------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1151
void ADLParser::interpreter_method_oop_parse(FrameForm *frame, bool native) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1152
  frame->_interpreter_method_oop_reg = parse_one_arg("method oop reg entry");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1153
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1154
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1155
//------------------------------cisc_spilling_operand_parse---------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1156
void ADLParser::cisc_spilling_operand_name_parse(FrameForm *frame, bool native) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1157
  frame->_cisc_spilling_operand_name = parse_one_arg("cisc spilling operand name");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1158
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1159
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1160
//------------------------------stack_alignment_parse--------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1161
void ADLParser::stack_alignment_parse(FrameForm *frame) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1162
  char *alignment = parse_one_arg("stack alignment entry");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1163
  // Assign value into frame
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1164
  frame->_alignment   = alignment;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1165
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1166
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1167
//------------------------------parse_one_arg-------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1168
char *ADLParser::parse_one_arg(const char *description) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1169
  char *token = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1170
  if(_curchar == '(') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1171
    next_char();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1172
    skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1173
    token = get_expr(description, ")");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1174
    if (token == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1175
      parse_err(SYNERR, "missing value inside %s.\n", description);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1176
      return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1177
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1178
    next_char();           // skip the close paren
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1179
    if(_curchar != ';') {  // check for semi-colon
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1180
      parse_err(SYNERR, "missing %c in.\n", ';', description);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1181
      return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1182
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1183
    next_char();           // skip the semi-colon
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1184
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1185
  else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1186
    parse_err(SYNERR, "Missing %c in.\n", '(', description);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1187
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1188
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1189
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1190
  trim(token);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1191
  return token;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1192
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1193
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1194
//------------------------------return_addr_parse------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1195
void ADLParser::return_addr_parse(FrameForm *frame, bool native) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1196
  bool in_register  = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1197
  if(_curchar == '(') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1198
    next_char();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1199
    skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1200
    char *token = get_ident();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1201
    if (token == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1202
      parse_err(SYNERR, "missing value inside return address entry.\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1203
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1204
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1205
    // check for valid values for stack/register
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1206
    if (strcmp(token, "REG") == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1207
      in_register = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1208
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1209
    else if (strcmp(token, "STACK") == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1210
      in_register = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1211
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1212
    else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1213
      parse_err(SYNERR, "invalid value inside return_address entry.\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1214
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1215
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1216
    if (native) { frame->_c_return_addr_loc = in_register; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1217
    else        { frame->_return_addr_loc   = in_register; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1218
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1219
    // Parse expression that specifies register or stack position
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1220
    skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1221
    char *token2 = get_expr("return address entry", ")");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1222
    if (token2 == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1223
      parse_err(SYNERR, "missing value inside return address entry.\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1224
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1225
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1226
    next_char();           // skip the close paren
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1227
    if (native) { frame->_c_return_addr = token2; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1228
    else        { frame->_return_addr   = token2; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1229
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1230
    if(_curchar != ';') {  // check for semi-colon
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1231
      parse_err(SYNERR, "missing %c in return address entry.\n", ';');
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1232
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1233
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1234
    next_char();           // skip the semi-colon
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1235
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1236
  else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1237
    parse_err(SYNERR, "Missing %c in return_address entry.\n", '(');
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1238
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1239
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1240
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1241
//------------------------------preserve_stack_parse---------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1242
void ADLParser::preserve_stack_parse(FrameForm *frame) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1243
  if(_curchar == '(') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1244
    char *token = get_paren_expr("preserve_stack_slots");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1245
    frame->_in_preserve_slots   = token;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1246
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1247
    if(_curchar != ';') {  // check for semi-colon
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1248
      parse_err(SYNERR, "missing %c in preserve stack slot entry.\n", ';');
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1249
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1250
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1251
    next_char();           // skip the semi-colon
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1252
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1253
  else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1254
    parse_err(SYNERR, "Missing %c in preserve stack slot entry.\n", '(');
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1255
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1256
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1257
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1258
//------------------------------calling_convention_parse-----------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1259
char *ADLParser::calling_convention_parse() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1260
  char   *desc = NULL;          // String representation of calling_convention
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1261
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1262
  skipws();                     // Skip leading whitespace
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1263
  if ( (desc = find_cpp_block("calling convention block")) == NULL ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1264
    parse_err(SYNERR, "incorrect or missing block for 'calling_convention'.\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1265
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1266
  return desc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1267
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1268
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1269
//------------------------------return_value_parse-----------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1270
char *ADLParser::return_value_parse() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1271
  char   *desc = NULL;          // String representation of calling_convention
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1272
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1273
  skipws();                     // Skip leading whitespace
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1274
  if ( (desc = find_cpp_block("return value block")) == NULL ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1275
    parse_err(SYNERR, "incorrect or missing block for 'return_value'.\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1276
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1277
  return desc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1278
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1279
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1280
//------------------------------ins_pipe_parse---------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1281
void ADLParser::ins_pipe_parse(InstructForm &instr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1282
  char * ident;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1283
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1284
  skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1285
  if ( _curchar != '(' ) {       // Check for delimiter
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1286
    parse_err(SYNERR, "missing \"(\" in ins_pipe definition\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1287
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1288
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1289
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1290
  next_char();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1291
  ident = get_ident();           // Grab next identifier
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1292
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1293
  if (ident == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1294
    parse_err(SYNERR, "keyword identifier expected at %c\n", _curchar);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1295
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1296
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1297
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1298
  skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1299
  if ( _curchar != ')' ) {       // Check for delimiter
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1300
    parse_err(SYNERR, "missing \")\" in ins_pipe definition\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1301
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1302
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1303
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1304
  next_char();                   // skip the close paren
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1305
  if(_curchar != ';') {          // check for semi-colon
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1306
    parse_err(SYNERR, "missing %c in return value entry.\n", ';');
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1307
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1308
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1309
  next_char();                   // skip the semi-colon
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1310
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1311
  // Check ident for validity
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1312
  if (_AD._pipeline && !_AD._pipeline->_classlist.search(ident)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1313
    parse_err(SYNERR, "\"%s\" is not a valid pipeline class\n", ident);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1314
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1315
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1316
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1317
  // Add this instruction to the list in the pipeline class
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1318
  _AD._pipeline->_classdict[ident]->is_pipeclass()->_instructs.addName(instr._ident);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1319
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1320
  // Set the name of the pipeline class in the instruction
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1321
  instr._ins_pipe = ident;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1322
  return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1323
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1324
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1325
//------------------------------pipe_parse-------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1326
void ADLParser::pipe_parse(void) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1327
  PipelineForm *pipeline;         // Encode class for instruction/operand
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1328
  char * ident;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1329
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1330
  pipeline = new PipelineForm();  // Build new Source object
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1331
  _AD.addForm(pipeline);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1332
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1333
  skipws();                       // Skip leading whitespace
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1334
  // Check for block delimiter
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1335
  if ( (_curchar != '%')
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1336
       || ( next_char(),  (_curchar != '{')) ) {
15477
26b2c7942f07 8007403: Incorrect format arguments in adlparse.cpp
mikael
parents: 13971
diff changeset
  1337
    parse_err(SYNERR, "missing '%%{' in pipeline definition\n");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1338
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1339
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1340
  next_char();                     // Maintain the invariant
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1341
  do {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1342
    ident = get_ident();           // Grab next identifier
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1343
    if (ident == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1344
      parse_err(SYNERR, "keyword identifier expected at %c\n", _curchar);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1345
      continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1346
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1347
    if      (!strcmp(ident, "resources" )) resource_parse(*pipeline);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1348
    else if (!strcmp(ident, "pipe_desc" )) pipe_desc_parse(*pipeline);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1349
    else if (!strcmp(ident, "pipe_class")) pipe_class_parse(*pipeline);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1350
    else if (!strcmp(ident, "define")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1351
      skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1352
      if ( (_curchar != '%')
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1353
           || ( next_char(),  (_curchar != '{')) ) {
15477
26b2c7942f07 8007403: Incorrect format arguments in adlparse.cpp
mikael
parents: 13971
diff changeset
  1354
        parse_err(SYNERR, "expected '%%{'\n");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1355
        return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1356
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1357
      next_char(); skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1358
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1359
      char *node_class = get_ident();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1360
      if (node_class == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1361
        parse_err(SYNERR, "expected identifier, found \"%c\"\n", _curchar);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1362
        return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1363
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1364
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1365
      skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1366
      if (_curchar != ',' && _curchar != '=') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1367
        parse_err(SYNERR, "expected `=`, found '%c'\n", _curchar);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1368
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1369
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1370
      next_char(); skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1371
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1372
      char *pipe_class = get_ident();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1373
      if (pipe_class == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1374
        parse_err(SYNERR, "expected identifier, found \"%c\"\n", _curchar);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1375
        return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1376
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1377
      if (_curchar != ';' ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1378
        parse_err(SYNERR, "expected `;`, found '%c'\n", _curchar);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1379
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1380
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1381
      next_char();              // Skip over semi-colon
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1382
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1383
      skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1384
      if ( (_curchar != '%')
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1385
           || ( next_char(),  (_curchar != '}')) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1386
        parse_err(SYNERR, "expected '%%}', found \"%c\"\n", _curchar);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1387
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1388
      next_char();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1389
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1390
      // Check ident for validity
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1391
      if (_AD._pipeline && !_AD._pipeline->_classlist.search(pipe_class)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1392
        parse_err(SYNERR, "\"%s\" is not a valid pipeline class\n", pipe_class);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1393
        return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1394
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1395
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1396
      // Add this machine node to the list in the pipeline class
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1397
      _AD._pipeline->_classdict[pipe_class]->is_pipeclass()->_instructs.addName(node_class);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1398
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1399
      MachNodeForm *machnode = new MachNodeForm(node_class); // Create new machnode form
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1400
      machnode->_machnode_pipe = pipe_class;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1401
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1402
      _AD.addForm(machnode);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1403
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1404
    else if (!strcmp(ident, "attributes")) {
13971
3c568f3dacca 8000592: Improve adlc usability
kvn
parents: 13104
diff changeset
  1405
      bool vsi_seen = false;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1406
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1407
      skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1408
      if ( (_curchar != '%')
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1409
           || ( next_char(),  (_curchar != '{')) ) {
15477
26b2c7942f07 8007403: Incorrect format arguments in adlparse.cpp
mikael
parents: 13971
diff changeset
  1410
        parse_err(SYNERR, "expected '%%{'\n");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1411
        return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1412
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1413
      next_char(); skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1414
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1415
      while (_curchar != '%') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1416
        ident = get_ident();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1417
        if (ident == NULL)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1418
          break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1419
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1420
        if (!strcmp(ident, "variable_size_instructions")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1421
          skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1422
          if (_curchar == ';') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1423
            next_char(); skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1424
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1425
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1426
          pipeline->_variableSizeInstrs = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1427
          vsi_seen = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1428
          continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1429
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1430
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1431
        if (!strcmp(ident, "fixed_size_instructions")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1432
          skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1433
          if (_curchar == ';') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1434
            next_char(); skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1435
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1436
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1437
          pipeline->_variableSizeInstrs = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1438
          vsi_seen = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1439
          continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1440
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1441
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1442
        if (!strcmp(ident, "branch_has_delay_slot")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1443
          skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1444
          if (_curchar == ';') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1445
            next_char(); skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1446
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1447
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1448
          pipeline->_branchHasDelaySlot = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1449
          continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1450
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1451
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1452
        if (!strcmp(ident, "max_instructions_per_bundle")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1453
          skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1454
          if (_curchar != '=') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1455
            parse_err(SYNERR, "expected `=`\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1456
            break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1457
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1458
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1459
          next_char(); skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1460
          pipeline->_maxInstrsPerBundle = get_int();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1461
          skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1462
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1463
          if (_curchar == ';') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1464
            next_char(); skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1465
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1466
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1467
          continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1468
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1469
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1470
        if (!strcmp(ident, "max_bundles_per_cycle")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1471
          skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1472
          if (_curchar != '=') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1473
            parse_err(SYNERR, "expected `=`\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1474
            break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1475
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1476
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1477
          next_char(); skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1478
          pipeline->_maxBundlesPerCycle = get_int();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1479
          skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1480
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1481
          if (_curchar == ';') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1482
            next_char(); skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1483
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1484
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1485
          continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1486
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1487
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1488
        if (!strcmp(ident, "instruction_unit_size")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1489
          skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1490
          if (_curchar != '=') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1491
            parse_err(SYNERR, "expected `=`, found '%c'\n", _curchar);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1492
            break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1493
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1494
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1495
          next_char(); skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1496
          pipeline->_instrUnitSize = get_int();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1497
          skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1498
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1499
          if (_curchar == ';') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1500
            next_char(); skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1501
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1502
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1503
          continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1504
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1505
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1506
        if (!strcmp(ident, "bundle_unit_size")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1507
          skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1508
          if (_curchar != '=') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1509
            parse_err(SYNERR, "expected `=`, found '%c'\n", _curchar);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1510
            break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1511
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1512
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1513
          next_char(); skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1514
          pipeline->_bundleUnitSize = get_int();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1515
          skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1516
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1517
          if (_curchar == ';') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1518
            next_char(); skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1519
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1520
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1521
          continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1522
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1523
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1524
        if (!strcmp(ident, "instruction_fetch_unit_size")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1525
          skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1526
          if (_curchar != '=') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1527
            parse_err(SYNERR, "expected `=`, found '%c'\n", _curchar);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1528
            break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1529
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1530
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1531
          next_char(); skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1532
          pipeline->_instrFetchUnitSize = get_int();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1533
          skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1534
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1535
          if (_curchar == ';') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1536
            next_char(); skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1537
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1538
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1539
          continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1540
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1541
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1542
        if (!strcmp(ident, "instruction_fetch_units")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1543
          skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1544
          if (_curchar != '=') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1545
            parse_err(SYNERR, "expected `=`, found '%c'\n", _curchar);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1546
            break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1547
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1548
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1549
          next_char(); skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1550
          pipeline->_instrFetchUnits = get_int();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1551
          skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1552
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1553
          if (_curchar == ';') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1554
            next_char(); skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1555
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1556
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1557
          continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1558
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1559
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1560
        if (!strcmp(ident, "nops")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1561
          skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1562
          if (_curchar != '(') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1563
            parse_err(SYNERR, "expected `(`, found '%c'\n", _curchar);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1564
            break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1565
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1566
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1567
          next_char(); skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1568
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1569
          while (_curchar != ')') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1570
            ident = get_ident();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1571
            if (ident == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1572
              parse_err(SYNERR, "expected identifier for nop instruction, found '%c'\n", _curchar);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1573
              break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1574
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1575
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1576
            pipeline->_noplist.addName(ident);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1577
            pipeline->_nopcnt++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1578
            skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1579
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1580
            if (_curchar == ',') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1581
              next_char(); skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1582
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1583
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1584
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1585
          next_char(); skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1586
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1587
          if (_curchar == ';') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1588
            next_char(); skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1589
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1590
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1591
          continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1592
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1593
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1594
        parse_err(SYNERR, "unknown specifier \"%s\"\n", ident);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1595
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1596
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1597
      if ( (_curchar != '%')
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1598
           || ( next_char(),  (_curchar != '}')) ) {
15477
26b2c7942f07 8007403: Incorrect format arguments in adlparse.cpp
mikael
parents: 13971
diff changeset
  1599
        parse_err(SYNERR, "expected '%%}', found \"%c\"\n", _curchar);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1600
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1601
      next_char(); skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1602
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1603
      if (pipeline->_maxInstrsPerBundle == 0)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1604
        parse_err(SYNERR, "\"max_instructions_per_bundle\" unspecified\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1605
      if (pipeline->_instrUnitSize == 0 && pipeline->_bundleUnitSize == 0)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1606
        parse_err(SYNERR, "\"instruction_unit_size\" and \"bundle_unit_size\" unspecified\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1607
      if (pipeline->_instrFetchUnitSize == 0)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1608
        parse_err(SYNERR, "\"instruction_fetch_unit_size\" unspecified\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1609
      if (pipeline->_instrFetchUnits == 0)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1610
        parse_err(SYNERR, "\"instruction_fetch_units\" unspecified\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1611
      if (!vsi_seen)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1612
        parse_err(SYNERR, "\"variable_size_instruction\" or \"fixed_size_instruction\" unspecified\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1613
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1614
    else {  // Done with staticly defined parts of instruction definition
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1615
      parse_err(SYNERR, "expected one of \"resources\", \"pipe_desc\", \"pipe_class\", found \"%s\"\n", ident);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1616
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1617
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1618
    skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1619
    if (_curchar == ';')
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1620
      skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1621
  } while(_curchar != '%');
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1622
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1623
  next_char();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1624
  if (_curchar != '}') {
15477
26b2c7942f07 8007403: Incorrect format arguments in adlparse.cpp
mikael
parents: 13971
diff changeset
  1625
    parse_err(SYNERR, "missing \"%%}\" in pipeline definition\n");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1626
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1627
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1628
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1629
  next_char();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1630
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1631
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1632
//------------------------------resource_parse----------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1633
void ADLParser::resource_parse(PipelineForm &pipeline) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1634
  ResourceForm *resource;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1635
  char * ident;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1636
  char * expr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1637
  unsigned mask;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1638
  pipeline._rescount = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1639
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1640
  skipws();                       // Skip leading whitespace
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1641
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1642
  if (_curchar != '(') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1643
    parse_err(SYNERR, "missing \"(\" in resource definition\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1644
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1645
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1646
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1647
  do {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1648
    next_char();                   // Skip "(" or ","
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1649
    ident = get_ident();           // Grab next identifier
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1650
13971
3c568f3dacca 8000592: Improve adlc usability
kvn
parents: 13104
diff changeset
  1651
    if (_AD._adl_debug > 1) {
3c568f3dacca 8000592: Improve adlc usability
kvn
parents: 13104
diff changeset
  1652
      if (ident != NULL) {
3c568f3dacca 8000592: Improve adlc usability
kvn
parents: 13104
diff changeset
  1653
        fprintf(stderr, "resource_parse: identifier: %s\n", ident);
3c568f3dacca 8000592: Improve adlc usability
kvn
parents: 13104
diff changeset
  1654
      }
3c568f3dacca 8000592: Improve adlc usability
kvn
parents: 13104
diff changeset
  1655
    }
3c568f3dacca 8000592: Improve adlc usability
kvn
parents: 13104
diff changeset
  1656
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1657
    if (ident == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1658
      parse_err(SYNERR, "keyword identifier expected at \"%c\"\n", _curchar);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1659
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1660
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1661
    skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1662
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1663
    if (_curchar != '=') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1664
      mask = (1 << pipeline._rescount++);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1665
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1666
    else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1667
      next_char(); skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1668
      expr = get_ident();          // Grab next identifier
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1669
      if (expr == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1670
        parse_err(SYNERR, "keyword identifier expected at \"%c\"\n", _curchar);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1671
        return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1672
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1673
      resource = (ResourceForm *) pipeline._resdict[expr];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1674
      if (resource == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1675
        parse_err(SYNERR, "resource \"%s\" is not defined\n", expr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1676
        return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1677
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1678
      mask = resource->mask();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1679
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1680
      skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1681
      while (_curchar == '|') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1682
        next_char(); skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1683
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1684
        expr = get_ident();          // Grab next identifier
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1685
        if (expr == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1686
          parse_err(SYNERR, "keyword identifier expected at \"%c\"\n", _curchar);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1687
          return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1688
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1689
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1690
        resource = (ResourceForm *) pipeline._resdict[expr];   // Look up the value
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1691
        if (resource == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1692
          parse_err(SYNERR, "resource \"%s\" is not defined\n", expr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1693
          return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1694
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1695
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1696
        mask |= resource->mask();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1697
        skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1698
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1699
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1700
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1701
    resource = new ResourceForm(mask);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1702
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1703
    pipeline._resdict.Insert(ident, resource);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1704
    pipeline._reslist.addName(ident);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1705
  } while (_curchar == ',');
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1706
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1707
  if (_curchar != ')') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1708
      parse_err(SYNERR, "\")\" expected at \"%c\"\n", _curchar);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1709
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1710
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1711
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1712
  next_char();                 // Skip ")"
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1713
  if (_curchar == ';')
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1714
    next_char();               // Skip ";"
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1715
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1716
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1717
//------------------------------resource_parse----------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1718
void ADLParser::pipe_desc_parse(PipelineForm &pipeline) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1719
  char * ident;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1720
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1721
  skipws();                       // Skip leading whitespace
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1722
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1723
  if (_curchar != '(') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1724
    parse_err(SYNERR, "missing \"(\" in pipe_desc definition\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1725
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1726
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1727
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1728
  do {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1729
    next_char();                   // Skip "(" or ","
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1730
    ident = get_ident();           // Grab next identifier
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1731
    if (ident == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1732
      parse_err(SYNERR, "keyword identifier expected at \"%c\"\n", _curchar);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1733
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1734
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1735
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1736
    // Add the name to the list
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1737
    pipeline._stages.addName(ident);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1738
    pipeline._stagecnt++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1739
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1740
    skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1741
  } while (_curchar == ',');
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1742
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1743
  if (_curchar != ')') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1744
      parse_err(SYNERR, "\")\" expected at \"%c\"\n", _curchar);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1745
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1746
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1747
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1748
  next_char();                     // Skip ")"
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1749
  if (_curchar == ';')
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1750
    next_char();                   // Skip ";"
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1751
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1752
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1753
//------------------------------pipe_class_parse--------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1754
void ADLParser::pipe_class_parse(PipelineForm &pipeline) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1755
  PipeClassForm *pipe_class;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1756
  char * ident;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1757
  char * stage;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1758
  char * read_or_write;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1759
  int is_write;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1760
  int is_read;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1761
  OperandForm  *oper;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1762
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1763
  skipws();                       // Skip leading whitespace
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1764
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1765
  ident = get_ident();            // Grab next identifier
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1766
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1767
  if (ident == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1768
    parse_err(SYNERR, "keyword identifier expected at \"%c\"\n", _curchar);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1769
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1770
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1771
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1772
  // Create a record for the pipe_class
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1773
  pipe_class = new PipeClassForm(ident, ++pipeline._classcnt);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1774
  pipeline._classdict.Insert(ident, pipe_class);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1775
  pipeline._classlist.addName(ident);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1776
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1777
  // Then get the operands
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1778
  skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1779
  if (_curchar != '(') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1780
    parse_err(SYNERR, "missing \"(\" in pipe_class definition\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1781
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1782
  // Parse the operand list
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1783
  else get_oplist(pipe_class->_parameters, pipe_class->_localNames);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1784
  skipws();                        // Skip leading whitespace
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1785
  // Check for block delimiter
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1786
  if ( (_curchar != '%')
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1787
       || ( next_char(),  (_curchar != '{')) ) {
15477
26b2c7942f07 8007403: Incorrect format arguments in adlparse.cpp
mikael
parents: 13971
diff changeset
  1788
    parse_err(SYNERR, "missing \"%%{\" in pipe_class definition\n");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1789
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1790
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1791
  next_char();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1792
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1793
  do {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1794
    ident = get_ident();           // Grab next identifier
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1795
    if (ident == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1796
      parse_err(SYNERR, "keyword identifier expected at \"%c\"\n", _curchar);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1797
      continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1798
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1799
    skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1800
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1801
    if (!strcmp(ident, "fixed_latency")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1802
      skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1803
      if (_curchar != '(') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1804
        parse_err(SYNERR, "missing \"(\" in latency definition\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1805
        return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1806
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1807
      next_char(); skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1808
      if( !isdigit(_curchar) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1809
        parse_err(SYNERR, "number expected for \"%c\" in latency definition\n", _curchar);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1810
        return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1811
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1812
      int fixed_latency = get_int();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1813
      skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1814
      if (_curchar != ')') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1815
        parse_err(SYNERR, "missing \")\" in latency definition\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1816
        return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1817
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1818
      next_char(); skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1819
      if (_curchar != ';') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1820
        parse_err(SYNERR, "missing \";\" in latency definition\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1821
        return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1822
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1823
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1824
      pipe_class->setFixedLatency(fixed_latency);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1825
      next_char(); skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1826
      continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1827
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1828
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1829
    if (!strcmp(ident, "zero_instructions") ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1830
        !strcmp(ident, "no_instructions")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1831
      skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1832
      if (_curchar != ';') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1833
        parse_err(SYNERR, "missing \";\" in latency definition\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1834
        return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1835
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1836
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1837
      pipe_class->setInstructionCount(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1838
      next_char(); skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1839
      continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1840
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1841
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1842
    if (!strcmp(ident, "one_instruction_with_delay_slot") ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1843
        !strcmp(ident, "single_instruction_with_delay_slot")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1844
      skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1845
      if (_curchar != ';') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1846
        parse_err(SYNERR, "missing \";\" in latency definition\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1847
        return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1848
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1849
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1850
      pipe_class->setInstructionCount(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1851
      pipe_class->setBranchDelay(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1852
      next_char(); skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1853
      continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1854
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1855
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1856
    if (!strcmp(ident, "one_instruction") ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1857
        !strcmp(ident, "single_instruction")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1858
      skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1859
      if (_curchar != ';') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1860
        parse_err(SYNERR, "missing \";\" in latency definition\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1861
        return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1862
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1863
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1864
      pipe_class->setInstructionCount(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1865
      next_char(); skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1866
      continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1867
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1868
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1869
    if (!strcmp(ident, "instructions_in_first_bundle") ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1870
        !strcmp(ident, "instruction_count")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1871
      skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1872
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1873
      int number_of_instructions = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1874
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1875
      if (_curchar != '(') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1876
        parse_err(SYNERR, "\"(\" expected at \"%c\"\n", _curchar);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1877
        continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1878
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1879
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1880
      next_char(); skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1881
      number_of_instructions = get_int();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1882
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1883
      skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1884
      if (_curchar != ')') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1885
        parse_err(SYNERR, "\")\" expected at \"%c\"\n", _curchar);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1886
        continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1887
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1888
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1889
      next_char(); skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1890
      if (_curchar != ';') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1891
        parse_err(SYNERR, "missing \";\" in latency definition\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1892
        return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1893
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1894
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1895
      pipe_class->setInstructionCount(number_of_instructions);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1896
      next_char(); skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1897
      continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1898
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1899
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1900
    if (!strcmp(ident, "multiple_bundles")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1901
      skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1902
      if (_curchar != ';') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1903
        parse_err(SYNERR, "missing \";\" after multiple bundles\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1904
        return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1905
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1906
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1907
      pipe_class->setMultipleBundles(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1908
      next_char(); skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1909
      continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1910
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1911
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1912
    if (!strcmp(ident, "has_delay_slot")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1913
      skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1914
      if (_curchar != ';') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1915
        parse_err(SYNERR, "missing \";\" after \"has_delay_slot\"\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1916
        return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1917
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1918
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1919
      pipe_class->setBranchDelay(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1920
      next_char(); skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1921
      continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1922
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1923
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1924
    if (!strcmp(ident, "force_serialization")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1925
      skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1926
      if (_curchar != ';') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1927
        parse_err(SYNERR, "missing \";\" after \"force_serialization\"\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1928
        return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1929
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1930
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1931
      pipe_class->setForceSerialization(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1932
      next_char(); skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1933
      continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1934
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1935
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1936
    if (!strcmp(ident, "may_have_no_code")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1937
      skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1938
      if (_curchar != ';') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1939
        parse_err(SYNERR, "missing \";\" after \"may_have_no_code\"\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1940
        return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1941
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1942
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1943
      pipe_class->setMayHaveNoCode(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1944
      next_char(); skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1945
      continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1946
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1947
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1948
    const Form *parm = pipe_class->_localNames[ident];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1949
    if (parm != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1950
      oper = parm->is_operand();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1951
      if (oper == NULL && !parm->is_opclass()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1952
        parse_err(SYNERR, "operand name expected at %s\n", ident);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1953
        continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1954
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1955
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1956
      if (_curchar != ':') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1957
        parse_err(SYNERR, "\":\" expected at \"%c\"\n", _curchar);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1958
        continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1959
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1960
      next_char(); skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1961
      stage = get_ident();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1962
      if (stage == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1963
        parse_err(SYNERR, "pipeline stage identifier expected at \"%c\"\n", _curchar);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1964
        continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1965
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1966
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1967
      skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1968
      if (_curchar != '(') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1969
        parse_err(SYNERR, "\"(\" expected at \"%c\"\n", _curchar);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1970
        continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1971
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1972
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1973
      next_char();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1974
      read_or_write = get_ident();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1975
      if (read_or_write == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1976
        parse_err(SYNERR, "\"read\" or \"write\" expected at \"%c\"\n", _curchar);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1977
        continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1978
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1979
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1980
      is_read  = strcmp(read_or_write, "read")   == 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1981
      is_write = strcmp(read_or_write, "write")  == 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1982
      if (!is_read && !is_write) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1983
        parse_err(SYNERR, "\"read\" or \"write\" expected at \"%c\"\n", _curchar);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1984
        continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1985
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1986
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1987
      skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1988
      if (_curchar != ')') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1989
        parse_err(SYNERR, "\")\" expected at \"%c\"\n", _curchar);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1990
        continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1991
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1992
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1993
      next_char(); skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1994
      int more_instrs = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1995
      if (_curchar == '+') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1996
          next_char(); skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1997
          if (_curchar < '0' || _curchar > '9') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1998
            parse_err(SYNERR, "<number> expected at \"%c\"\n", _curchar);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1999
            continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2000
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2001
          while (_curchar >= '0' && _curchar <= '9') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2002
            more_instrs *= 10;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2003
            more_instrs += _curchar - '0';
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2004
            next_char();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2005
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2006
          skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2007
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2008
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2009
      PipeClassOperandForm *pipe_operand = new PipeClassOperandForm(stage, is_write, more_instrs);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2010
      pipe_class->_localUsage.Insert(ident, pipe_operand);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2011
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2012
      if (_curchar == '%')
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2013
          continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2014
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2015
      if (_curchar != ';') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2016
        parse_err(SYNERR, "\";\" expected at \"%c\"\n", _curchar);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2017
        continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2018
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2019
      next_char(); skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2020
      continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2021
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2022
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2023
    // Scan for Resource Specifier
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2024
    const Form *res = pipeline._resdict[ident];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2025
    if (res != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2026
      int cyclecnt = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2027
      if (_curchar != ':') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2028
        parse_err(SYNERR, "\":\" expected at \"%c\"\n", _curchar);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2029
        continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2030
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2031
      next_char(); skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2032
      stage = get_ident();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2033
      if (stage == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2034
        parse_err(SYNERR, "pipeline stage identifier expected at \"%c\"\n", _curchar);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2035
        continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2036
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2037
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2038
      skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2039
      if (_curchar == '(') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2040
        next_char();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2041
        cyclecnt = get_int();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2042
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2043
        skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2044
        if (_curchar != ')') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2045
          parse_err(SYNERR, "\")\" expected at \"%c\"\n", _curchar);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2046
          continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2047
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2048
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2049
        next_char(); skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2050
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2051
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2052
      PipeClassResourceForm *resource = new PipeClassResourceForm(ident, stage, cyclecnt);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2053
      int stagenum = pipeline._stages.index(stage);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2054
      if (pipeline._maxcycleused < (stagenum+cyclecnt))
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2055
        pipeline._maxcycleused = (stagenum+cyclecnt);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2056
      pipe_class->_resUsage.addForm(resource);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2057
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2058
      if (_curchar == '%')
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2059
          continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2060
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2061
      if (_curchar != ';') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2062
        parse_err(SYNERR, "\";\" expected at \"%c\"\n", _curchar);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2063
        continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2064
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2065
      next_char(); skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2066
      continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2067
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2068
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2069
    parse_err(SYNERR, "resource expected at \"%s\"\n", ident);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2070
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2071
  } while(_curchar != '%');
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2072
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2073
  next_char();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2074
  if (_curchar != '}') {
15477
26b2c7942f07 8007403: Incorrect format arguments in adlparse.cpp
mikael
parents: 13971
diff changeset
  2075
    parse_err(SYNERR, "missing \"%%}\" in pipe_class definition\n");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2076
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2077
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2078
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2079
  next_char();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2080
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2081
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2082
//------------------------------peep_parse-------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2083
void ADLParser::peep_parse(void) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2084
  Peephole  *peep;                // Pointer to current peephole rule form
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2085
  char      *desc = NULL;         // String representation of rule
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2086
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2087
  skipws();                       // Skip leading whitespace
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2088
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2089
  peep = new Peephole();          // Build new Peephole object
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2090
  // Check for open block sequence
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2091
  skipws();                       // Skip leading whitespace
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2092
  if (_curchar == '%' && *(_ptr+1) == '{') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2093
    next_char(); next_char();     // Skip "%{"
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2094
    skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2095
    while (_curchar != '%' && *(_ptr+1) != '}') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2096
      char *token = get_ident();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2097
      if (token == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2098
        parse_err(SYNERR, "missing identifier inside peephole rule.\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2099
        return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2100
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2101
      // check for legal subsections of peephole rule
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2102
      if (strcmp(token,"peepmatch")==0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2103
        peep_match_parse(*peep); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2104
      else if (strcmp(token,"peepconstraint")==0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2105
        peep_constraint_parse(*peep); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2106
      else if (strcmp(token,"peepreplace")==0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2107
        peep_replace_parse(*peep); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2108
      else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2109
        parse_err(SYNERR, "expected peepmatch, peepconstraint, or peepreplace for identifier %s.\n", token);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2110
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2111
      skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2112
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2113
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2114
  else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2115
    parse_err(SYNERR, "Missing %%{ ... %%} block after peephole keyword.\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2116
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2117
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2118
  next_char();                    // Skip past '%'
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2119
  next_char();                    // Skip past '}'
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2120
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2121
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2122
// ******************** Private Level 2 Parse Functions ********************
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2123
//------------------------------constraint_parse------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2124
Constraint *ADLParser::constraint_parse(void) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2125
  char *func;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2126
  char *arg;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2127
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2128
  // Check for constraint expression
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2129
  skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2130
  if (_curchar != '(') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2131
    parse_err(SYNERR, "missing constraint expression, (...)\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2132
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2133
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2134
  next_char();                    // Skip past '('
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2135
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2136
  // Get constraint function
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2137
  skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2138
  func = get_ident();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2139
  if (func == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2140
    parse_err(SYNERR, "missing function in constraint expression.\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2141
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2142
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2143
  if (strcmp(func,"ALLOC_IN_RC")==0
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2144
      || strcmp(func,"IS_R_CLASS")==0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2145
    // Check for '(' before argument
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2146
    skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2147
    if (_curchar != '(') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2148
      parse_err(SYNERR, "missing '(' for constraint function's argument.\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2149
      return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2150
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2151
    next_char();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2152
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2153
    // Get it's argument
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2154
    skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2155
    arg = get_ident();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2156
    if (arg == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2157
      parse_err(SYNERR, "missing argument for constraint function %s\n",func);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2158
      return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2159
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2160
    // Check for ')' after argument
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2161
    skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2162
    if (_curchar != ')') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2163
      parse_err(SYNERR, "missing ')' after constraint function argument %s\n",arg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2164
      return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2165
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2166
    next_char();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2167
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2168
    parse_err(SYNERR, "Invalid constraint function %s\n",func);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2169
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2170
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2171
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2172
  // Check for closing paren and ';'
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2173
  skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2174
  if (_curchar != ')') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2175
    parse_err(SYNERR, "Missing ')' for constraint function %s\n",func);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2176
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2177
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2178
  next_char();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2179
  skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2180
  if (_curchar != ';') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2181
    parse_err(SYNERR, "Missing ';' after constraint.\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2182
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2183
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2184
  next_char();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2185
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2186
  // Create new "Constraint"
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2187
  Constraint *constraint = new Constraint(func,arg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2188
  return constraint;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2189
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2190
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2191
//------------------------------constr_parse-----------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2192
ConstructRule *ADLParser::construct_parse(void) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2193
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2194
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2195
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2196
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2197
//------------------------------reg_def_parse----------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2198
void ADLParser::reg_def_parse(void) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2199
  char *rname;                   // Name of register being defined
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2200
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2201
  // Get register name
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2202
  skipws();                      // Skip whitespace
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2203
  rname = get_ident();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2204
  if (rname == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2205
    parse_err(SYNERR, "missing register name after reg_def\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2206
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2207
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2208
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2209
  // Check for definition of register calling convention (save on call, ...),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2210
  // register save type, and register encoding value.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2211
  skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2212
  char *callconv  = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2213
  char *c_conv    = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2214
  char *idealtype = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2215
  char *encoding  = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2216
  char *concrete = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2217
  if (_curchar == '(') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2218
    next_char();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2219
    callconv = get_ident();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2220
    // Parse the internal calling convention, must be NS, SOC, SOE, or AS.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2221
    if (callconv == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2222
      parse_err(SYNERR, "missing register calling convention value\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2223
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2224
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2225
    if(strcmp(callconv, "SOC") && strcmp(callconv,"SOE") &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2226
       strcmp(callconv, "NS") && strcmp(callconv, "AS")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2227
      parse_err(SYNERR, "invalid value for register calling convention\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2228
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2229
    skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2230
    if (_curchar != ',') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2231
      parse_err(SYNERR, "missing comma in register definition statement\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2232
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2233
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2234
    next_char();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2235
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2236
    // Parse the native calling convention, must be NS, SOC, SOE, AS
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2237
    c_conv = get_ident();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2238
    if (c_conv == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2239
      parse_err(SYNERR, "missing register native calling convention value\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2240
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2241
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2242
    if(strcmp(c_conv, "SOC") && strcmp(c_conv,"SOE") &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2243
       strcmp(c_conv, "NS") && strcmp(c_conv, "AS")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2244
      parse_err(SYNERR, "invalid value for register calling convention\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2245
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2246
    skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2247
    if (_curchar != ',') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2248
      parse_err(SYNERR, "missing comma in register definition statement\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2249
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2250
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2251
    next_char();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2252
    skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2253
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2254
    // Parse the ideal save type
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2255
    idealtype = get_ident();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2256
    if (idealtype == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2257
      parse_err(SYNERR, "missing register save type value\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2258
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2259
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2260
    skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2261
    if (_curchar != ',') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2262
      parse_err(SYNERR, "missing comma in register definition statement\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2263
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2264
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2265
    next_char();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2266
    skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2267
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2268
    // Parse the encoding value
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2269
    encoding = get_expr("encoding", ",");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2270
    if (encoding == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2271
      parse_err(SYNERR, "missing register encoding value\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2272
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2273
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2274
    trim(encoding);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2275
    if (_curchar != ',') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2276
      parse_err(SYNERR, "missing comma in register definition statement\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2277
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2278
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2279
    next_char();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2280
    skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2281
    // Parse the concrete name type
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2282
    // concrete = get_ident();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2283
    concrete = get_expr("concrete", ")");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2284
    if (concrete == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2285
      parse_err(SYNERR, "missing vm register name value\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2286
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2287
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2288
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2289
    if (_curchar != ')') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2290
      parse_err(SYNERR, "missing ')' in register definition statement\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2291
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2292
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2293
    next_char();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2294
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2295
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2296
  // Check for closing ';'
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2297
  skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2298
  if (_curchar != ';') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2299
    parse_err(SYNERR, "missing ';' after reg_def\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2300
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2301
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2302
  next_char();                   // move past ';'
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2303
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2304
  // Debug Stuff
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2305
  if (_AD._adl_debug > 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2306
    fprintf(stderr,"Register Definition: %s ( %s, %s %s )\n", rname,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2307
            (callconv ? callconv : ""), (c_conv ? c_conv : ""), concrete);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2308
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2309
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2310
  // Record new register definition.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2311
  _AD._register->addRegDef(rname, callconv, c_conv, idealtype, encoding, concrete);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2312
  return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2313
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2314
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2315
//------------------------------reg_class_parse--------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2316
void ADLParser::reg_class_parse(void) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2317
  char *cname;                    // Name of register class being defined
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2318
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2319
  // Get register class name
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2320
  skipws();                       // Skip leading whitespace
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2321
  cname = get_ident();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2322
  if (cname == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2323
    parse_err(SYNERR, "missing register class name after 'reg_class'\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2324
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2325
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2326
  // Debug Stuff
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2327
  if (_AD._adl_debug >1) fprintf(stderr,"Register Class: %s\n", cname);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2328
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2329
  skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2330
  if (_curchar == '(') {
30202
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2331
    // A register list is defined for the register class.
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2332
    // Collect registers into a generic RegClass register class.
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2333
    RegClass* reg_class = _AD._register->addRegClass<RegClass>(cname);
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2334
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2335
    next_char();                  // Skip '('
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2336
    skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2337
    while (_curchar != ')') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2338
      char *rname = get_ident();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2339
      if (rname==NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2340
        parse_err(SYNERR, "missing identifier inside reg_class list.\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2341
        return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2342
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2343
      RegDef *regDef = _AD._register->getRegDef(rname);
1662
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  2344
      if (!regDef) {
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  2345
        parse_err(SEMERR, "unknown identifier %s inside reg_class list.\n", rname);
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  2346
      } else {
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  2347
        reg_class->addReg(regDef); // add regDef to regClass
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  2348
      }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2349
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2350
      // Check for ',' and position to next token.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2351
      skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2352
      if (_curchar == ',') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2353
        next_char();              // Skip trailing ','
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2354
        skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2355
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2356
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2357
    next_char();                  // Skip closing ')'
11197
158eecd6b330 7090968: Allow adlc register class to depend on runtime conditions
roland
parents: 11196
diff changeset
  2358
  } else if (_curchar == '%') {
30202
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2359
    // A code snippet is defined for the register class.
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2360
    // Collect the code snippet into a CodeSnippetRegClass register class.
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2361
    CodeSnippetRegClass* reg_class = _AD._register->addRegClass<CodeSnippetRegClass>(cname);
11197
158eecd6b330 7090968: Allow adlc register class to depend on runtime conditions
roland
parents: 11196
diff changeset
  2362
    char *code = find_cpp_block("reg class");
158eecd6b330 7090968: Allow adlc register class to depend on runtime conditions
roland
parents: 11196
diff changeset
  2363
    if (code == NULL) {
158eecd6b330 7090968: Allow adlc register class to depend on runtime conditions
roland
parents: 11196
diff changeset
  2364
      parse_err(SYNERR, "missing code declaration for reg class.\n");
158eecd6b330 7090968: Allow adlc register class to depend on runtime conditions
roland
parents: 11196
diff changeset
  2365
      return;
158eecd6b330 7090968: Allow adlc register class to depend on runtime conditions
roland
parents: 11196
diff changeset
  2366
    }
30202
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2367
    reg_class->set_code_snippet(code);
11197
158eecd6b330 7090968: Allow adlc register class to depend on runtime conditions
roland
parents: 11196
diff changeset
  2368
    return;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2369
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2370
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2371
  // Check for terminating ';'
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2372
  skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2373
  if (_curchar != ';') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2374
    parse_err(SYNERR, "missing ';' at end of reg_class definition.\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2375
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2376
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2377
  next_char();                    // Skip trailing ';'
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2378
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2379
  // Check RegClass size, must be <= 32 registers in class.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2380
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2381
  return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2382
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2383
30202
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2384
//------------------------------reg_class_dynamic_parse------------------------
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2385
void ADLParser::reg_class_dynamic_parse(void) {
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2386
  char *cname; // Name of dynamic register class being defined
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2387
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2388
  // Get register class name
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2389
  skipws();
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2390
  cname = get_ident();
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2391
  if (cname == NULL) {
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2392
    parse_err(SYNERR, "missing dynamic register class name after 'reg_class_dynamic'\n");
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2393
    return;
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2394
  }
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2395
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2396
  if (_AD._adl_debug > 1) {
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2397
    fprintf(stdout, "Dynamic Register Class: %s\n", cname);
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2398
  }
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2399
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2400
  skipws();
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2401
  if (_curchar != '(') {
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2402
    parse_err(SYNERR, "missing '(' at the beginning of reg_class_dynamic definition\n");
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2403
    return;
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2404
  }
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2405
  next_char();
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2406
  skipws();
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2407
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2408
  // Collect two register classes and the C++ code representing the condition code used to
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2409
  // select between the two classes into a ConditionalRegClass register class.
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2410
  ConditionalRegClass* reg_class = _AD._register->addRegClass<ConditionalRegClass>(cname);
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2411
  int i;
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2412
  for (i = 0; i < 2; i++) {
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2413
    char* name = get_ident();
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2414
    if (name == NULL) {
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2415
      parse_err(SYNERR, "missing class identifier inside reg_class_dynamic list.\n");
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2416
      return;
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2417
    }
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2418
    RegClass* rc = _AD._register->getRegClass(name);
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2419
    if (rc == NULL) {
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2420
      parse_err(SEMERR, "unknown identifier %s inside reg_class_dynamic list.\n", name);
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2421
    } else {
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2422
      reg_class->set_rclass_at_index(i, rc);
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2423
    }
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2424
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2425
    skipws();
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2426
    if (_curchar == ',') {
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2427
      next_char();
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2428
      skipws();
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2429
    } else {
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2430
      parse_err(SYNERR, "missing separator ',' inside reg_class_dynamic list.\n");
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2431
    }
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2432
  }
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2433
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2434
  // Collect the condition code.
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2435
  skipws();
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2436
  if (_curchar == '%') {
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2437
    char* code = find_cpp_block("reg class dynamic");
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2438
    if (code == NULL) {
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2439
       parse_err(SYNERR, "missing code declaration for reg_class_dynamic.\n");
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2440
       return;
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2441
    }
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2442
    reg_class->set_condition_code(code);
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2443
  } else {
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2444
    parse_err(SYNERR, "missing %% at the beginning of code block in reg_class_dynamic definition\n");
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2445
    return;
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2446
  }
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2447
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2448
  skipws();
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2449
  if (_curchar != ')') {
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2450
    parse_err(SYNERR, "missing ')' at the end of reg_class_dynamic definition\n");
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2451
    return;
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2452
  }
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2453
  next_char();
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2454
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2455
  skipws();
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2456
  if (_curchar != ';') {
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2457
    parse_err(SYNERR, "missing ';' at the end of reg_class_dynamic definition.\n");
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2458
    return;
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2459
  }
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2460
  next_char();                    // Skip trailing ';'
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2461
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2462
  return;
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2463
}
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 22872
diff changeset
  2464
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2465
//------------------------------alloc_class_parse------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2466
void ADLParser::alloc_class_parse(void) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2467
  char *name;                     // Name of allocation class being defined
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2468
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2469
  // Get allocation class name
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2470
  skipws();                       // Skip leading whitespace
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2471
  name = get_ident();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2472
  if (name == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2473
    parse_err(SYNERR, "missing allocation class name after 'reg_class'\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2474
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2475
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2476
  // Debug Stuff
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2477
  if (_AD._adl_debug >1) fprintf(stderr,"Allocation Class: %s\n", name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2478
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2479
  AllocClass *alloc_class = _AD._register->addAllocClass(name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2480
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2481
  // Collect registers in class
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2482
  skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2483
  if (_curchar == '(') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2484
    next_char();                  // Skip '('
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2485
    skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2486
    while (_curchar != ')') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2487
      char *rname = get_ident();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2488
      if (rname==NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2489
        parse_err(SYNERR, "missing identifier inside reg_class list.\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2490
        return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2491
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2492
      // Check if name is a RegDef
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2493
      RegDef *regDef = _AD._register->getRegDef(rname);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2494
      if (regDef) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2495
        alloc_class->addReg(regDef);   // add regDef to allocClass
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2496
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2497
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2498
        // name must be a RegDef or a RegClass
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2499
        parse_err(SYNERR, "name %s should be a previously defined reg_def.\n", rname);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2500
        return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2501
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2502
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2503
      // Check for ',' and position to next token.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2504
      skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2505
      if (_curchar == ',') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2506
        next_char();              // Skip trailing ','
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2507
        skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2508
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2509
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2510
    next_char();                  // Skip closing ')'
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2511
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2512
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2513
  // Check for terminating ';'
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2514
  skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2515
  if (_curchar != ';') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2516
    parse_err(SYNERR, "missing ';' at end of reg_class definition.\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2517
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2518
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2519
  next_char();                    // Skip trailing ';'
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2520
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2521
  return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2522
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2523
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2524
//------------------------------peep_match_child_parse-------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2525
InstructForm *ADLParser::peep_match_child_parse(PeepMatch &match, int parent, int &position, int input){
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2526
  char      *token  = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2527
  int        lparen = 0;          // keep track of parenthesis nesting depth
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2528
  int        rparen = 0;          // position of instruction at this depth
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2529
  InstructForm *inst_seen  = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2530
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2531
  // Walk the match tree,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2532
  // Record <parent, position, instruction name, input position>
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2533
  while ( lparen >= rparen ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2534
    skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2535
    // Left paren signals start of an input, collect with recursive call
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2536
    if (_curchar == '(') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2537
      ++lparen;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2538
      next_char();
13971
3c568f3dacca 8000592: Improve adlc usability
kvn
parents: 13104
diff changeset
  2539
      ( void ) peep_match_child_parse(match, parent, position, rparen);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2540
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2541
    // Right paren signals end of an input, may be more
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2542
    else if (_curchar == ')') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2543
      ++rparen;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2544
      if( rparen == lparen ) { // IF rparen matches an lparen I've seen
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2545
        next_char();           //    move past ')'
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2546
      } else {                 // ELSE leave ')' for parent
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2547
        assert( rparen == lparen + 1, "Should only see one extra ')'");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2548
        // if an instruction was not specified for this paren-pair
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2549
        if( ! inst_seen ) {   // record signal entry
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2550
          match.add_instruction( parent, position, NameList::_signal, input );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2551
          ++position;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2552
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2553
        // ++input;   // TEMPORARY
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2554
        return inst_seen;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2555
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2556
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2557
    // if no parens, then check for instruction name
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2558
    // This instruction is the parent of a sub-tree
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2559
    else if ((token = get_ident_dup()) != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2560
      const Form *form = _AD._globalNames[token];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2561
      if (form) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2562
        InstructForm *inst = form->is_instruction();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2563
        // Record the first instruction at this level
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2564
        if( inst_seen == NULL ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2565
          inst_seen = inst;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2566
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2567
        if (inst) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2568
          match.add_instruction( parent, position, token, input );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2569
          parent = position;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2570
          ++position;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2571
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2572
          parse_err(SYNERR, "instruction name expected at identifier %s.\n",
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2573
                    token);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2574
          return inst_seen;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2575
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2576
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2577
      else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2578
        parse_err(SYNERR, "missing identifier in peepmatch rule.\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2579
        return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2580
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2581
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2582
    else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2583
      parse_err(SYNERR, "missing identifier in peepmatch rule.\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2584
      return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2585
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2586
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2587
  } // end while
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2588
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2589
  assert( false, "ShouldNotReachHere();");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2590
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2591
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2592
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2593
//------------------------------peep_match_parse-------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2594
// Syntax for a peepmatch rule
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2595
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2596
// peepmatch ( root_instr_name [(instruction subtree)] [,(instruction subtree)]* );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2597
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2598
void ADLParser::peep_match_parse(Peephole &peep) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2599
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2600
  skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2601
  // Check the structure of the rule
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2602
  // Check for open paren
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2603
  if (_curchar != '(') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2604
    parse_err(SYNERR, "missing '(' at start of peepmatch rule.\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2605
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2606
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2607
  next_char();   // skip '('
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2608
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2609
  // Construct PeepMatch and parse the peepmatch rule.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2610
  PeepMatch *match = new PeepMatch(_ptr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2611
  int  parent   = -1;                   // parent of root
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2612
  int  position = 0;                    // zero-based positions
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2613
  int  input    = 0;                    // input position in parent's operands
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2614
  InstructForm *root= peep_match_child_parse( *match, parent, position, input);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2615
  if( root == NULL ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2616
    parse_err(SYNERR, "missing instruction-name at start of peepmatch.\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2617
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2618
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2619
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2620
  if( _curchar != ')' ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2621
    parse_err(SYNERR, "missing ')' at end of peepmatch.\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2622
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2623
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2624
  next_char();   // skip ')'
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2625
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2626
  // Check for closing semicolon
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2627
  skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2628
  if( _curchar != ';' ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2629
    parse_err(SYNERR, "missing ';' at end of peepmatch.\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2630
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2631
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2632
  next_char();   // skip ';'
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2633
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2634
  // Store match into peep, and store peep into instruction
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2635
  peep.add_match(match);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2636
  root->append_peephole(&peep);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2637
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2638
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2639
//------------------------------peep_constraint_parse--------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2640
// Syntax for a peepconstraint rule
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2641
// A parenthesized list of relations between operands in peepmatch subtree
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2642
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2643
// peepconstraint %{
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2644
// (instruction_number.operand_name
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2645
//     relational_op
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2646
//  instruction_number.operand_name OR register_name
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2647
//  [, ...] );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2648
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2649
// // instruction numbers are zero-based using topological order in peepmatch
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2650
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2651
void ADLParser::peep_constraint_parse(Peephole &peep) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2652
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2653
  skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2654
  // Check the structure of the rule
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2655
  // Check for open paren
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2656
  if (_curchar != '(') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2657
    parse_err(SYNERR, "missing '(' at start of peepconstraint rule.\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2658
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2659
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2660
  else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2661
    next_char();                  // Skip '('
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2662
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2663
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2664
  // Check for a constraint
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2665
  skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2666
  while( _curchar != ')' ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2667
    // Get information on the left instruction and its operand
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2668
    // left-instructions's number
2129
e810a33b5c67 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 1675
diff changeset
  2669
    int left_inst = get_int();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2670
    // Left-instruction's operand
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2671
    skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2672
    if( _curchar != '.' ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2673
      parse_err(SYNERR, "missing '.' in peepconstraint after instruction number.\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2674
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2675
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2676
    next_char();                  // Skip '.'
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2677
    char *left_op = get_ident_dup();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2678
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2679
    skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2680
    // Collect relational operator
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2681
    char *relation = get_relation_dup();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2682
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2683
    skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2684
    // Get information on the right instruction and its operand
2129
e810a33b5c67 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 1675
diff changeset
  2685
    int right_inst;        // Right-instructions's number
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2686
    if( isdigit(_curchar) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2687
      right_inst = get_int();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2688
      // Right-instruction's operand
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2689
      skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2690
      if( _curchar != '.' ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2691
        parse_err(SYNERR, "missing '.' in peepconstraint after instruction number.\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2692
        return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2693
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2694
      next_char();              // Skip '.'
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2695
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2696
      right_inst = -1;          // Flag as being a register constraint
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2697
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2698
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2699
    char *right_op = get_ident_dup();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2700
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2701
    // Construct the next PeepConstraint
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2702
    PeepConstraint *constraint = new PeepConstraint( left_inst, left_op,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2703
                                                     relation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2704
                                                     right_inst, right_op );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2705
    // And append it to the list for this peephole rule
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2706
    peep.append_constraint( constraint );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2707
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2708
    // Check for another constraint, or end of rule
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2709
    skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2710
    if( _curchar == ',' ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2711
      next_char();                // Skip ','
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2712
      skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2713
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2714
    else if( _curchar != ')' ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2715
      parse_err(SYNERR, "expected ',' or ')' after peephole constraint.\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2716
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2717
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2718
  } // end while( processing constraints )
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2719
  next_char();                    // Skip ')'
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2720
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2721
  // Check for terminating ';'
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2722
  skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2723
  if (_curchar != ';') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2724
    parse_err(SYNERR, "missing ';' at end of peepconstraint.\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2725
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2726
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2727
  next_char();                    // Skip trailing ';'
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2728
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2729
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2730
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2731
//------------------------------peep_replace_parse-----------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2732
// Syntax for a peepreplace rule
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2733
// root instruction name followed by a
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2734
// parenthesized list of whitespace separated instruction.operand specifiers
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2735
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2736
// peepreplace ( instr_name  ( [instruction_number.operand_name]* ) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2737
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2738
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2739
void ADLParser::peep_replace_parse(Peephole &peep) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2740
  int          lparen = 0;        // keep track of parenthesis nesting depth
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2741
  int          rparen = 0;        // keep track of parenthesis nesting depth
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2742
  int          icount = 0;        // count of instructions in rule for naming
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2743
  char        *str    = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2744
  char        *token  = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2745
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2746
  skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2747
  // Check for open paren
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2748
  if (_curchar != '(') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2749
    parse_err(SYNERR, "missing '(' at start of peepreplace rule.\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2750
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2751
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2752
  else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2753
    lparen++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2754
    next_char();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2755
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2756
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2757
  // Check for root instruction
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2758
  char       *inst = get_ident_dup();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2759
  const Form *form = _AD._globalNames[inst];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2760
  if( form == NULL || form->is_instruction() == NULL ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2761
    parse_err(SYNERR, "Instruction name expected at start of peepreplace.\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2762
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2763
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2764
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2765
  // Store string representation of rule into replace
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2766
  PeepReplace *replace = new PeepReplace(str);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2767
  replace->add_instruction( inst );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2768
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2769
  skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2770
  // Start of root's operand-list
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2771
  if (_curchar != '(') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2772
    parse_err(SYNERR, "missing '(' at peepreplace root's operand-list.\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2773
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2774
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2775
  else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2776
    lparen++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2777
    next_char();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2778
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2779
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2780
  skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2781
  // Get the list of operands
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2782
  while( _curchar != ')' ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2783
    // Get information on an instruction and its operand
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2784
    // instructions's number
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2785
    int   inst_num = get_int();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2786
    // Left-instruction's operand
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2787
    skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2788
    if( _curchar != '.' ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2789
      parse_err(SYNERR, "missing '.' in peepreplace after instruction number.\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2790
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2791
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2792
    next_char();                  // Skip '.'
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2793
    char *inst_op = get_ident_dup();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2794
    if( inst_op == NULL ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2795
      parse_err(SYNERR, "missing operand identifier in peepreplace.\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2796
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2797
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2798
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2799
    // Record this operand's position in peepmatch
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2800
    replace->add_operand( inst_num, inst_op );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2801
    skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2802
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2803
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2804
  // Check for the end of operands list
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2805
  skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2806
  assert( _curchar == ')', "While loop should have advanced to ')'.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2807
  next_char();  // Skip ')'
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2808
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2809
  skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2810
  // Check for end of peepreplace
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2811
  if( _curchar != ')' ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2812
    parse_err(SYNERR, "missing ')' at end of peepmatch.\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2813
    parse_err(SYNERR, "Support one replacement instruction.\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2814
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2815
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2816
  next_char(); // Skip ')'
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2817
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2818
  // Check for closing semicolon
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2819
  skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2820
  if( _curchar != ';' ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2821
    parse_err(SYNERR, "missing ';' at end of peepreplace.\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2822
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2823
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2824
  next_char();   // skip ';'
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2825
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2826
  // Store replace into peep
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2827
  peep.add_replace( replace );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2828
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2829
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2830
//------------------------------pred_parse-------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2831
Predicate *ADLParser::pred_parse(void) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2832
  Predicate *predicate;           // Predicate class for operand
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2833
  char      *rule = NULL;         // String representation of predicate
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2834
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2835
  skipws();                       // Skip leading whitespace
1662
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  2836
  int line = linenum();
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  2837
  if ( (rule = get_paren_expr("pred expression", true)) == NULL ) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2838
    parse_err(SYNERR, "incorrect or missing expression for 'predicate'\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2839
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2840
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2841
  // Debug Stuff
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2842
  if (_AD._adl_debug > 1) fprintf(stderr,"Predicate: %s\n", rule);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2843
  if (_curchar != ';') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2844
    parse_err(SYNERR, "missing ';' in predicate definition\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2845
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2846
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2847
  next_char();                     // Point after the terminator
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2848
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2849
  predicate = new Predicate(rule); // Build new predicate object
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2850
  skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2851
  return predicate;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2852
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2853
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2854
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2855
//------------------------------ins_encode_parse_block-------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2856
// Parse the block form of ins_encode.  See ins_encode_parse for more details
7433
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2857
void ADLParser::ins_encode_parse_block(InstructForm& inst) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2858
  // Create a new encoding name based on the name of the instruction
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2859
  // definition, which should be unique.
7433
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2860
  const char* prefix = "__ins_encode_";
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2861
  char* ec_name = (char*) malloc(strlen(inst._ident) + strlen(prefix) + 1);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2862
  sprintf(ec_name, "%s%s", prefix, inst._ident);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2863
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2864
  assert(_AD._encode->encClass(ec_name) == NULL, "shouldn't already exist");
7433
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2865
  EncClass* encoding = _AD._encode->add_EncClass(ec_name);
1495
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  2866
  encoding->_linenum = linenum();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2867
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2868
  // synthesize the arguments list for the enc_class from the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2869
  // arguments to the instruct definition.
7433
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2870
  const char* param = NULL;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2871
  inst._parameters.reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2872
  while ((param = inst._parameters.iter()) != NULL) {
7433
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2873
    OperandForm* opForm = (OperandForm*) inst._localNames[param];
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2874
    encoding->add_parameter(opForm->_ident, param);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2875
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2876
22844
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  2877
  if (!inst._is_postalloc_expand) {
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  2878
    // Define a MacroAssembler instance for use by the encoding.  The
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  2879
    // name is chosen to match the __ idiom used for assembly in other
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  2880
    // parts of hotspot and assumes the existence of the standard
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  2881
    // #define __ _masm.
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  2882
    encoding->add_code("    MacroAssembler _masm(&cbuf);\n");
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  2883
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2884
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2885
  // Parse the following %{ }% block
7433
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2886
  ins_encode_parse_block_impl(inst, encoding, ec_name);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2887
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2888
  // Build an encoding rule which invokes the encoding rule we just
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2889
  // created, passing all arguments that we received.
7433
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2890
  InsEncode*   encrule = new InsEncode(); // Encode class for instruction
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2891
  NameAndList* params  = encrule->add_encode(ec_name);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2892
  inst._parameters.reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2893
  while ((param = inst._parameters.iter()) != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2894
    params->add_entry(param);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2895
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2896
10016
8020d5b49663 7061101: adlc should complain about mixing block and expression forms of ins_encode
never
parents: 7433
diff changeset
  2897
  // Check for duplicate ins_encode sections after parsing the block
8020d5b49663 7061101: adlc should complain about mixing block and expression forms of ins_encode
never
parents: 7433
diff changeset
  2898
  // so that parsing can continue and find any other errors.
8020d5b49663 7061101: adlc should complain about mixing block and expression forms of ins_encode
never
parents: 7433
diff changeset
  2899
  if (inst._insencode != NULL) {
8020d5b49663 7061101: adlc should complain about mixing block and expression forms of ins_encode
never
parents: 7433
diff changeset
  2900
    parse_err(SYNERR, "Multiple ins_encode sections defined\n");
8020d5b49663 7061101: adlc should complain about mixing block and expression forms of ins_encode
never
parents: 7433
diff changeset
  2901
    return;
8020d5b49663 7061101: adlc should complain about mixing block and expression forms of ins_encode
never
parents: 7433
diff changeset
  2902
  }
8020d5b49663 7061101: adlc should complain about mixing block and expression forms of ins_encode
never
parents: 7433
diff changeset
  2903
7433
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2904
  // Set encode class of this instruction.
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2905
  inst._insencode = encrule;
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2906
}
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2907
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2908
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2909
void ADLParser::ins_encode_parse_block_impl(InstructForm& inst, EncClass* encoding, char* ec_name) {
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2910
  skipws_no_preproc();              // Skip leading whitespace
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2911
  // Prepend location descriptor, for debugging; cf. ADLParser::find_cpp_block
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2912
  if (_AD._adlocation_debug) {
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2913
    encoding->add_code(get_line_string());
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2914
  }
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2915
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2916
  // Collect the parts of the encode description
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2917
  // (1) strings that are passed through to output
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2918
  // (2) replacement/substitution variable, preceeded by a '$'
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2919
  while ((_curchar != '%') && (*(_ptr+1) != '}')) {
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2920
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2921
    // (1)
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2922
    // Check if there is a string to pass through to output
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2923
    char *start = _ptr;       // Record start of the next string
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2924
    while ((_curchar != '$') && ((_curchar != '%') || (*(_ptr+1) != '}')) ) {
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2925
      // If at the start of a comment, skip past it
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2926
      if( (_curchar == '/') && ((*(_ptr+1) == '/') || (*(_ptr+1) == '*')) ) {
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2927
        skipws_no_preproc();
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2928
      } else {
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2929
        // ELSE advance to the next character, or start of the next line
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2930
        next_char_or_line();
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2931
      }
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2932
    }
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2933
    // If a string was found, terminate it and record in EncClass
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2934
    if (start != _ptr) {
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2935
      *_ptr = '\0';          // Terminate the string
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2936
      encoding->add_code(start);
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2937
    }
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2938
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2939
    // (2)
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2940
    // If we are at a replacement variable,
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2941
    // copy it and record in EncClass
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2942
    if (_curchar == '$') {
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2943
      // Found replacement Variable
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2944
      char* rep_var = get_rep_var_ident_dup();
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2945
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2946
      // Add flag to _strings list indicating we should check _rep_vars
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2947
      encoding->add_rep_var(rep_var);
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2948
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2949
      skipws();
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2950
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2951
      // Check if this instruct is a MachConstantNode.
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2952
      if (strcmp(rep_var, "constanttablebase") == 0) {
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2953
        // This instruct is a MachConstantNode.
22850
4e69ce7e1101 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 22847
diff changeset
  2954
        inst.set_needs_constant_base(true);
4e69ce7e1101 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 22847
diff changeset
  2955
        if (strncmp("MachCall", inst.mach_base_class(_globalNames), strlen("MachCall")) != 0 ) {
4e69ce7e1101 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 22847
diff changeset
  2956
          inst.set_is_mach_constant(true);
4e69ce7e1101 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 22847
diff changeset
  2957
        }
7433
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2958
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2959
        if (_curchar == '(')  {
22844
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  2960
          parse_err(SYNERR, "constanttablebase in instruct %s cannot have an argument "
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  2961
                            "(only constantaddress and constantoffset)", ec_name);
7433
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2962
          return;
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2963
        }
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2964
      }
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2965
      else if ((strcmp(rep_var, "constantaddress")   == 0) ||
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2966
               (strcmp(rep_var, "constantoffset")    == 0)) {
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2967
        // This instruct is a MachConstantNode.
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2968
        inst.set_is_mach_constant(true);
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2969
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2970
        // If the constant keyword has an argument, parse it.
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2971
        if (_curchar == '(')  constant_parse(inst);
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2972
      }
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2973
    }
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2974
  } // end while part of format description
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2975
  next_char();                      // Skip '%'
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2976
  next_char();                      // Skip '}'
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2977
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2978
  skipws();
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2979
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2980
  if (_AD._adlocation_debug) {
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2981
    encoding->add_code(end_line_marker());
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2982
  }
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2983
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2984
  // Debug Stuff
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  2985
  if (_AD._adl_debug > 1)  fprintf(stderr, "EncodingClass Form: %s\n", ec_name);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2986
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2987
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2988
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2989
//------------------------------ins_encode_parse-------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2990
// Encode rules have the form
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2991
//   ins_encode( encode_class_name(parameter_list), ... );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2992
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2993
// The "encode_class_name" must be defined in the encode section
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2994
// The parameter list contains $names that are locals.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2995
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2996
// Alternatively it can be written like this:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2997
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2998
//   ins_encode %{
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2999
//      ... // body
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3000
//   %}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3001
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3002
// which synthesizes a new encoding class taking the same arguments as
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3003
// the InstructForm, and automatically prefixes the definition with:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3004
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3005
//    MacroAssembler masm(&cbuf);\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3006
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3007
//  making it more compact to take advantage of the MacroAssembler and
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3008
//  placing the assembly closer to it's use by instructions.
7433
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3009
void ADLParser::ins_encode_parse(InstructForm& inst) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3010
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3011
  // Parse encode class name
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3012
  skipws();                        // Skip whitespace
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3013
  if (_curchar != '(') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3014
    // Check for ins_encode %{ form
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3015
    if ((_curchar == '%') && (*(_ptr+1) == '{')) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3016
      next_char();                      // Skip '%'
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3017
      next_char();                      // Skip '{'
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3018
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3019
      // Parse the block form of ins_encode
7433
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3020
      ins_encode_parse_block(inst);
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3021
      return;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3022
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3023
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3024
    parse_err(SYNERR, "missing '%%{' or '(' in ins_encode definition\n");
7433
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3025
    return;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3026
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3027
  next_char();                     // move past '('
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3028
  skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3029
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3030
  InsEncode *encrule  = new InsEncode(); // Encode class for instruction
1495
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  3031
  encrule->_linenum = linenum();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3032
  char      *ec_name  = NULL;      // String representation of encode rule
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3033
  // identifier is optional.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3034
  while (_curchar != ')') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3035
    ec_name = get_ident();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3036
    if (ec_name == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3037
      parse_err(SYNERR, "Invalid encode class name after 'ins_encode('.\n");
7433
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3038
      return;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3039
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3040
    // Check that encoding is defined in the encode section
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3041
    EncClass *encode_class = _AD._encode->encClass(ec_name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3042
    if (encode_class == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3043
      // Like to defer checking these till later...
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3044
      // parse_err(WARN, "Using an undefined encode class '%s' in 'ins_encode'.\n", ec_name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3045
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3046
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3047
    // Get list for encode method's parameters
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3048
    NameAndList *params = encrule->add_encode(ec_name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3049
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3050
    // Parse the parameters to this encode method.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3051
    skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3052
    if ( _curchar == '(' ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3053
      next_char();                 // move past '(' for parameters
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3054
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3055
      // Parse the encode method's parameters
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3056
      while (_curchar != ')') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3057
        char *param = get_ident_or_literal_constant("encoding operand");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3058
        if ( param != NULL ) {
22850
4e69ce7e1101 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 22847
diff changeset
  3059
4e69ce7e1101 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 22847
diff changeset
  3060
          // Check if this instruct is a MachConstantNode.
4e69ce7e1101 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 22847
diff changeset
  3061
          if (strcmp(param, "constanttablebase") == 0) {
4e69ce7e1101 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 22847
diff changeset
  3062
            // This instruct is a MachConstantNode.
4e69ce7e1101 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 22847
diff changeset
  3063
            inst.set_needs_constant_base(true);
4e69ce7e1101 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 22847
diff changeset
  3064
            if (strncmp("MachCall", inst.mach_base_class(_globalNames), strlen("MachCall")) != 0 ) {
4e69ce7e1101 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 22847
diff changeset
  3065
              inst.set_is_mach_constant(true);
4e69ce7e1101 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 22847
diff changeset
  3066
            }
4e69ce7e1101 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 22847
diff changeset
  3067
4e69ce7e1101 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 22847
diff changeset
  3068
            if (_curchar == '(')  {
4e69ce7e1101 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 22847
diff changeset
  3069
              parse_err(SYNERR, "constanttablebase in instruct %s cannot have an argument "
4e69ce7e1101 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 22847
diff changeset
  3070
                        "(only constantaddress and constantoffset)", ec_name);
4e69ce7e1101 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 22847
diff changeset
  3071
              return;
4e69ce7e1101 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 22847
diff changeset
  3072
            }
4e69ce7e1101 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 22847
diff changeset
  3073
          } else {
4e69ce7e1101 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 22847
diff changeset
  3074
            // Found a parameter:
4e69ce7e1101 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 22847
diff changeset
  3075
            // Check it is a local name, add it to the list, then check for more
4e69ce7e1101 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 22847
diff changeset
  3076
            // New: allow hex constants as parameters to an encode method.
4e69ce7e1101 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 22847
diff changeset
  3077
            // New: allow parenthesized expressions as parameters.
4e69ce7e1101 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 22847
diff changeset
  3078
            // New: allow "primary", "secondary", "tertiary" as parameters.
4e69ce7e1101 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 22847
diff changeset
  3079
            // New: allow user-defined register name as parameter
4e69ce7e1101 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 22847
diff changeset
  3080
            if ( (inst._localNames[param] == NULL) &&
4e69ce7e1101 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 22847
diff changeset
  3081
                 !ADLParser::is_literal_constant(param) &&
4e69ce7e1101 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 22847
diff changeset
  3082
                 (Opcode::as_opcode_type(param) == Opcode::NOT_AN_OPCODE) &&
4e69ce7e1101 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 22847
diff changeset
  3083
                 ((_AD._register == NULL ) || (_AD._register->getRegDef(param) == NULL)) ) {
4e69ce7e1101 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 22847
diff changeset
  3084
              parse_err(SYNERR, "Using non-locally defined parameter %s for encoding %s.\n", param, ec_name);
4e69ce7e1101 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 22847
diff changeset
  3085
              return;
4e69ce7e1101 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 22847
diff changeset
  3086
            }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3087
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3088
          params->add_entry(param);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3089
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3090
          skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3091
          if (_curchar == ',' ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3092
            // More parameters to come
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3093
            next_char();           // move past ',' between parameters
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3094
            skipws();              // Skip to next parameter
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3095
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3096
          else if (_curchar == ')') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3097
            // Done with parameter list
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3098
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3099
          else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3100
            // Only ',' or ')' are valid after a parameter name
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3101
            parse_err(SYNERR, "expected ',' or ')' after parameter %s.\n",
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3102
                      ec_name);
7433
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3103
            return;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3104
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3105
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3106
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3107
          skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3108
          // Did not find a parameter
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3109
          if (_curchar == ',') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3110
            parse_err(SYNERR, "Expected encode parameter before ',' in encoding %s.\n", ec_name);
7433
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3111
            return;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3112
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3113
          if (_curchar != ')') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3114
            parse_err(SYNERR, "Expected ')' after encode parameters.\n");
7433
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3115
            return;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3116
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3117
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3118
      } // WHILE loop collecting parameters
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3119
      next_char();                   // move past ')' at end of parameters
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3120
    } // done with parameter list for encoding
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3121
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3122
    // Check for ',' or ')' after encoding
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3123
    skipws();                      // move to character after parameters
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3124
    if ( _curchar == ',' ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3125
      // Found a ','
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3126
      next_char();                 // move past ',' between encode methods
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3127
      skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3128
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3129
    else if ( _curchar != ')' ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3130
      // If not a ',' then only a ')' is allowed
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3131
      parse_err(SYNERR, "Expected ')' after encoding %s.\n", ec_name);
7433
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3132
      return;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3133
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3134
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3135
    // Check for ',' separating parameters
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3136
    // if ( _curchar != ',' && _curchar != ')' ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3137
    //   parse_err(SYNERR, "expected ',' or ')' after encode method inside ins_encode.\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3138
    //   return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3139
    // }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3140
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3141
  } // done parsing ins_encode methods and their parameters
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3142
  if (_curchar != ')') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3143
    parse_err(SYNERR, "Missing ')' at end of ins_encode description.\n");
7433
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3144
    return;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3145
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3146
  next_char();                     // move past ')'
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3147
  skipws();                        // Skip leading whitespace
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3148
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3149
  if ( _curchar != ';' ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3150
    parse_err(SYNERR, "Missing ';' at end of ins_encode.\n");
7433
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3151
    return;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3152
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3153
  next_char();                     // move past ';'
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3154
  skipws();                        // be friendly to oper_parse()
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3155
10016
8020d5b49663 7061101: adlc should complain about mixing block and expression forms of ins_encode
never
parents: 7433
diff changeset
  3156
  // Check for duplicate ins_encode sections after parsing the block
8020d5b49663 7061101: adlc should complain about mixing block and expression forms of ins_encode
never
parents: 7433
diff changeset
  3157
  // so that parsing can continue and find any other errors.
8020d5b49663 7061101: adlc should complain about mixing block and expression forms of ins_encode
never
parents: 7433
diff changeset
  3158
  if (inst._insencode != NULL) {
8020d5b49663 7061101: adlc should complain about mixing block and expression forms of ins_encode
never
parents: 7433
diff changeset
  3159
    parse_err(SYNERR, "Multiple ins_encode sections defined\n");
8020d5b49663 7061101: adlc should complain about mixing block and expression forms of ins_encode
never
parents: 7433
diff changeset
  3160
    return;
8020d5b49663 7061101: adlc should complain about mixing block and expression forms of ins_encode
never
parents: 7433
diff changeset
  3161
  }
8020d5b49663 7061101: adlc should complain about mixing block and expression forms of ins_encode
never
parents: 7433
diff changeset
  3162
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3163
  // Debug Stuff
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3164
  if (_AD._adl_debug > 1) fprintf(stderr,"Instruction Encode: %s\n", ec_name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3165
7433
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3166
  // Set encode class of this instruction.
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3167
  inst._insencode = encrule;
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3168
}
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3169
22844
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3170
//------------------------------postalloc_expand_parse---------------------------
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3171
// Encode rules have the form
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3172
//   postalloc_expand( encode_class_name(parameter_list) );
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3173
//
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3174
// The "encode_class_name" must be defined in the encode section.
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3175
// The parameter list contains $names that are locals.
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3176
//
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3177
// This is just a copy of ins_encode_parse without the loop.
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3178
void ADLParser::postalloc_expand_parse(InstructForm& inst) {
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3179
  inst._is_postalloc_expand = true;
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3180
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3181
  // Parse encode class name.
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3182
  skipws();                        // Skip whitespace.
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3183
  if (_curchar != '(') {
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3184
    // Check for postalloc_expand %{ form
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3185
    if ((_curchar == '%') && (*(_ptr+1) == '{')) {
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3186
      next_char();                      // Skip '%'
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3187
      next_char();                      // Skip '{'
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3188
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3189
      // Parse the block form of postalloc_expand
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3190
      ins_encode_parse_block(inst);
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3191
      return;
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3192
    }
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3193
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3194
    parse_err(SYNERR, "missing '(' in postalloc_expand definition\n");
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3195
    return;
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3196
  }
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3197
  next_char();                     // Move past '('.
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3198
  skipws();
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3199
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3200
  InsEncode *encrule = new InsEncode(); // Encode class for instruction.
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3201
  encrule->_linenum = linenum();
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3202
  char      *ec_name = NULL;       // String representation of encode rule.
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3203
  // identifier is optional.
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3204
  if (_curchar != ')') {
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3205
    ec_name = get_ident();
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3206
    if (ec_name == NULL) {
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3207
      parse_err(SYNERR, "Invalid postalloc_expand class name after 'postalloc_expand('.\n");
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3208
      return;
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3209
    }
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3210
    // Check that encoding is defined in the encode section.
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3211
    EncClass *encode_class = _AD._encode->encClass(ec_name);
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3212
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3213
    // Get list for encode method's parameters
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3214
    NameAndList *params = encrule->add_encode(ec_name);
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3215
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3216
    // Parse the parameters to this encode method.
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3217
    skipws();
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3218
    if (_curchar == '(') {
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3219
      next_char();                 // Move past '(' for parameters.
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3220
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3221
      // Parse the encode method's parameters.
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3222
      while (_curchar != ')') {
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3223
        char *param = get_ident_or_literal_constant("encoding operand");
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3224
        if (param != NULL) {
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3225
          // Found a parameter:
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3226
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3227
          // First check for constant table support.
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3228
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3229
          // Check if this instruct is a MachConstantNode.
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3230
          if (strcmp(param, "constanttablebase") == 0) {
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3231
            // This instruct is a MachConstantNode.
22850
4e69ce7e1101 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 22847
diff changeset
  3232
            inst.set_needs_constant_base(true);
4e69ce7e1101 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 22847
diff changeset
  3233
            if (strncmp("MachCall", inst.mach_base_class(_globalNames), strlen("MachCall")) != 0 ) {
4e69ce7e1101 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 22847
diff changeset
  3234
              inst.set_is_mach_constant(true);
4e69ce7e1101 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 22847
diff changeset
  3235
            }
22844
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3236
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3237
            if (_curchar == '(') {
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3238
              parse_err(SYNERR, "constanttablebase in instruct %s cannot have an argument "
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3239
                        "(only constantaddress and constantoffset)", ec_name);
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3240
              return;
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3241
            }
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3242
          }
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3243
          else if ((strcmp(param, "constantaddress") == 0) ||
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3244
                   (strcmp(param, "constantoffset")  == 0))  {
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3245
            // This instruct is a MachConstantNode.
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3246
            inst.set_is_mach_constant(true);
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3247
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3248
            // If the constant keyword has an argument, parse it.
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3249
            if (_curchar == '(') constant_parse(inst);
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3250
          }
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3251
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3252
          // Else check it is a local name, add it to the list, then check for more.
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3253
          // New: allow hex constants as parameters to an encode method.
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3254
          // New: allow parenthesized expressions as parameters.
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3255
          // New: allow "primary", "secondary", "tertiary" as parameters.
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3256
          // New: allow user-defined register name as parameter.
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3257
          else if ((inst._localNames[param] == NULL) &&
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3258
                   !ADLParser::is_literal_constant(param) &&
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3259
                   (Opcode::as_opcode_type(param) == Opcode::NOT_AN_OPCODE) &&
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3260
                   ((_AD._register == NULL) || (_AD._register->getRegDef(param) == NULL))) {
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3261
            parse_err(SYNERR, "Using non-locally defined parameter %s for encoding %s.\n", param, ec_name);
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3262
            return;
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3263
          }
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3264
          params->add_entry(param);
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3265
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3266
          skipws();
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3267
          if (_curchar == ',') {
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3268
            // More parameters to come.
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3269
            next_char();           // Move past ',' between parameters.
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3270
            skipws();              // Skip to next parameter.
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3271
          } else if (_curchar == ')') {
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3272
            // Done with parameter list
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3273
          } else {
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3274
            // Only ',' or ')' are valid after a parameter name.
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3275
            parse_err(SYNERR, "expected ',' or ')' after parameter %s.\n", ec_name);
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3276
            return;
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3277
          }
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3278
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3279
        } else {
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3280
          skipws();
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3281
          // Did not find a parameter.
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3282
          if (_curchar == ',') {
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3283
            parse_err(SYNERR, "Expected encode parameter before ',' in postalloc_expand %s.\n", ec_name);
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3284
            return;
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3285
          }
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3286
          if (_curchar != ')') {
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3287
            parse_err(SYNERR, "Expected ')' after postalloc_expand parameters.\n");
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3288
            return;
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3289
          }
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3290
        }
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3291
      } // WHILE loop collecting parameters.
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3292
      next_char();                 // Move past ')' at end of parameters.
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3293
    } // Done with parameter list for encoding.
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3294
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3295
    // Check for ',' or ')' after encoding.
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3296
    skipws();                      // Move to character after parameters.
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3297
    if (_curchar != ')') {
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3298
      // Only a ')' is allowed.
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3299
      parse_err(SYNERR, "Expected ')' after postalloc_expand %s.\n", ec_name);
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3300
      return;
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3301
    }
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3302
  } // Done parsing postalloc_expand method and their parameters.
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3303
  if (_curchar != ')') {
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3304
    parse_err(SYNERR, "Missing ')' at end of postalloc_expand description.\n");
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3305
    return;
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3306
  }
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3307
  next_char();                     // Move past ')'.
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3308
  skipws();                        // Skip leading whitespace.
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3309
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3310
  if (_curchar != ';') {
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3311
    parse_err(SYNERR, "Missing ';' at end of postalloc_expand.\n");
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3312
    return;
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3313
  }
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3314
  next_char();                     // Move past ';'.
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3315
  skipws();                        // Be friendly to oper_parse().
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3316
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3317
  // Debug Stuff.
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3318
  if (_AD._adl_debug > 1) fprintf(stderr, "Instruction postalloc_expand: %s\n", ec_name);
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3319
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3320
  // Set encode class of this instruction.
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3321
  inst._insencode = encrule;
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3322
}
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 20289
diff changeset
  3323
7433
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3324
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3325
//------------------------------constant_parse---------------------------------
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3326
// Parse a constant expression.
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3327
void ADLParser::constant_parse(InstructForm& inst) {
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3328
  // Create a new encoding name based on the name of the instruction
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3329
  // definition, which should be unique.
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3330
  const char* prefix = "__constant_";
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3331
  char* ec_name = (char*) malloc(strlen(inst._ident) + strlen(prefix) + 1);
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3332
  sprintf(ec_name, "%s%s", prefix, inst._ident);
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3333
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3334
  assert(_AD._encode->encClass(ec_name) == NULL, "shouldn't already exist");
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3335
  EncClass* encoding = _AD._encode->add_EncClass(ec_name);
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3336
  encoding->_linenum = linenum();
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3337
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3338
  // synthesize the arguments list for the enc_class from the
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3339
  // arguments to the instruct definition.
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3340
  const char* param = NULL;
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3341
  inst._parameters.reset();
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3342
  while ((param = inst._parameters.iter()) != NULL) {
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3343
    OperandForm* opForm = (OperandForm*) inst._localNames[param];
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3344
    encoding->add_parameter(opForm->_ident, param);
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3345
  }
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3346
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3347
  // Parse the following ( ) expression.
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3348
  constant_parse_expression(encoding, ec_name);
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3349
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3350
  // Build an encoding rule which invokes the encoding rule we just
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3351
  // created, passing all arguments that we received.
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3352
  InsEncode*   encrule = new InsEncode(); // Encode class for instruction
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3353
  NameAndList* params  = encrule->add_encode(ec_name);
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3354
  inst._parameters.reset();
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3355
  while ((param = inst._parameters.iter()) != NULL) {
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3356
    params->add_entry(param);
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3357
  }
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3358
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3359
  // Set encode class of this instruction.
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3360
  inst._constant = encrule;
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3361
}
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3362
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3363
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3364
//------------------------------constant_parse_expression----------------------
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3365
void ADLParser::constant_parse_expression(EncClass* encoding, char* ec_name) {
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3366
  skipws();
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3367
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3368
  // Prepend location descriptor, for debugging; cf. ADLParser::find_cpp_block
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3369
  if (_AD._adlocation_debug) {
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3370
    encoding->add_code(get_line_string());
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3371
  }
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3372
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3373
  // Start code line.
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3374
  encoding->add_code("    _constant = C->constant_table().add");
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3375
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3376
  // Parse everything in ( ) expression.
11190
d561d41f241a 7003454: order constants in constant table by number of references in code
twisti
parents: 10255
diff changeset
  3377
  encoding->add_code("(this, ");
7433
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3378
  next_char();  // Skip '('
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3379
  int parens_depth = 1;
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3380
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3381
  // Collect the parts of the constant expression.
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3382
  // (1) strings that are passed through to output
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3383
  // (2) replacement/substitution variable, preceeded by a '$'
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3384
  while (parens_depth > 0) {
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3385
    if (_curchar == '(') {
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3386
      parens_depth++;
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3387
      encoding->add_code("(");
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3388
      next_char();
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3389
    }
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3390
    else if (_curchar == ')') {
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3391
      parens_depth--;
11190
d561d41f241a 7003454: order constants in constant table by number of references in code
twisti
parents: 10255
diff changeset
  3392
      if (parens_depth > 0)
d561d41f241a 7003454: order constants in constant table by number of references in code
twisti
parents: 10255
diff changeset
  3393
        encoding->add_code(")");
7433
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3394
      next_char();
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3395
    }
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3396
    else {
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3397
      // (1)
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3398
      // Check if there is a string to pass through to output
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3399
      char *start = _ptr;  // Record start of the next string
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3400
      while ((_curchar != '$') && (_curchar != '(') && (_curchar != ')')) {
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3401
        next_char();
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3402
      }
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3403
      // If a string was found, terminate it and record in EncClass
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3404
      if (start != _ptr) {
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3405
        *_ptr = '\0';  // Terminate the string
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3406
        encoding->add_code(start);
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3407
      }
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3408
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3409
      // (2)
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3410
      // If we are at a replacement variable, copy it and record in EncClass.
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3411
      if (_curchar == '$') {
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3412
        // Found replacement Variable
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3413
        char* rep_var = get_rep_var_ident_dup();
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3414
        encoding->add_rep_var(rep_var);
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3415
      }
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3416
    }
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3417
  }
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3418
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3419
  // Finish code line.
11190
d561d41f241a 7003454: order constants in constant table by number of references in code
twisti
parents: 10255
diff changeset
  3420
  encoding->add_code(");");
7433
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3421
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3422
  if (_AD._adlocation_debug) {
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3423
    encoding->add_code(end_line_marker());
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3424
  }
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3425
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3426
  // Debug Stuff
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
  3427
  if (_AD._adl_debug > 1)  fprintf(stderr, "EncodingClass Form: %s\n", ec_name);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3428
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3429
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3430
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3431
//------------------------------size_parse-----------------------------------
13971
3c568f3dacca 8000592: Improve adlc usability
kvn
parents: 13104
diff changeset
  3432
// Parse a 'size(<expr>)' attribute which specifies the size of the
3c568f3dacca 8000592: Improve adlc usability
kvn
parents: 13104
diff changeset
  3433
// emitted instructions in bytes. <expr> can be a C++ expression,
3c568f3dacca 8000592: Improve adlc usability
kvn
parents: 13104
diff changeset
  3434
// e.g. a constant.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3435
char* ADLParser::size_parse(InstructForm *instr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3436
  char* sizeOfInstr = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3437
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3438
  // Get value of the instruction's size
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3439
  skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3440
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3441
  // Parse size
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3442
  sizeOfInstr = get_paren_expr("size expression");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3443
  if (sizeOfInstr == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3444
     parse_err(SYNERR, "size of opcode expected at %c\n", _curchar);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3445
     return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3446
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3447
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3448
  skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3449
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3450
  // Check for terminator
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3451
  if (_curchar != ';') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3452
    parse_err(SYNERR, "missing ';' in ins_attrib definition\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3453
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3454
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3455
  next_char();                     // Advance past the ';'
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3456
  skipws();                        // necessary for instr_parse()
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3457
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3458
  // Debug Stuff
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3459
  if (_AD._adl_debug > 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3460
    if (sizeOfInstr != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3461
      fprintf(stderr,"size of opcode: %s\n", sizeOfInstr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3462
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3463
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3464
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3465
  return sizeOfInstr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3466
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3467
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3468
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3469
//------------------------------opcode_parse-----------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3470
Opcode * ADLParser::opcode_parse(InstructForm *instr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3471
  char *primary   = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3472
  char *secondary = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3473
  char *tertiary  = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3474
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3475
  char   *val    = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3476
  Opcode *opcode = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3477
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3478
  // Get value of the instruction's opcode
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3479
  skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3480
  if (_curchar != '(') {         // Check for parenthesized operand list
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3481
    parse_err(SYNERR, "missing '(' in expand instruction declaration\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3482
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3483
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3484
  next_char();                   // skip open paren
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3485
  skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3486
  if (_curchar != ')') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3487
    // Parse primary, secondary, and tertiary opcodes, if provided.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3488
    if ( ((primary = get_ident_or_literal_constant("primary opcode")) == NULL) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3489
        parse_err(SYNERR, "primary hex opcode expected at %c\n", _curchar);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3490
        return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3491
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3492
    skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3493
    if (_curchar == ',') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3494
      next_char();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3495
      skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3496
      // Parse secondary opcode
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3497
      if ( ((secondary = get_ident_or_literal_constant("secondary opcode")) == NULL) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3498
        parse_err(SYNERR, "secondary hex opcode expected at %c\n", _curchar);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3499
        return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3500
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3501
      skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3502
      if (_curchar == ',') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3503
        next_char();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3504
        skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3505
        // Parse tertiary opcode
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3506
        if ( ((tertiary = get_ident_or_literal_constant("tertiary opcode")) == NULL) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3507
          parse_err(SYNERR,"tertiary hex opcode expected at %c\n", _curchar);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3508
          return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3509
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3510
        skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3511
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3512
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3513
    skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3514
    if (_curchar != ')') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3515
      parse_err(SYNERR, "Missing ')' in opcode description\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3516
      return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3517
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3518
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3519
  next_char();                     // Skip ')'
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3520
  skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3521
  // Check for terminator
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3522
  if (_curchar != ';') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3523
    parse_err(SYNERR, "missing ';' in ins_attrib definition\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3524
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3525
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3526
  next_char();                     // Advance past the ';'
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3527
  skipws();                        // necessary for instr_parse()
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3528
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3529
  // Debug Stuff
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3530
  if (_AD._adl_debug > 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3531
    if (primary   != NULL) fprintf(stderr,"primary   opcode: %s\n", primary);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3532
    if (secondary != NULL) fprintf(stderr,"secondary opcode: %s\n", secondary);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3533
    if (tertiary  != NULL) fprintf(stderr,"tertiary  opcode: %s\n", tertiary);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3534
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3535
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3536
  // Generate new object and return
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3537
  opcode = new Opcode(primary, secondary, tertiary);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3538
  return opcode;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3539
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3540
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3541
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3542
//------------------------------interface_parse--------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3543
Interface *ADLParser::interface_parse(void) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3544
  char *iface_name  = NULL;      // Name of interface class being used
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3545
  char *iface_code  = NULL;      // Describe components of this class
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3546
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3547
  // Get interface class name
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3548
  skipws();                       // Skip whitespace
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3549
  if (_curchar != '(') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3550
    parse_err(SYNERR, "Missing '(' at start of interface description.\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3551
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3552
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3553
  next_char();                    // move past '('
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3554
  skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3555
  iface_name = get_ident();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3556
  if (iface_name == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3557
    parse_err(SYNERR, "missing interface name after 'interface'.\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3558
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3559
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3560
  skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3561
  if (_curchar != ')') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3562
    parse_err(SYNERR, "Missing ')' after name of interface.\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3563
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3564
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3565
  next_char();                    // move past ')'
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3566
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3567
  // Get details of the interface,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3568
  // for the type of interface indicated by iface_name.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3569
  Interface *inter = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3570
  skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3571
  if ( _curchar != ';' ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3572
    if ( strcmp(iface_name,"MEMORY_INTER") == 0 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3573
      inter = mem_interface_parse();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3574
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3575
    else if ( strcmp(iface_name,"COND_INTER") == 0 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3576
      inter = cond_interface_parse();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3577
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3578
    // The parse routines consume the "%}"
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3579
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3580
    // Check for probable extra ';' after defining block.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3581
    if ( _curchar == ';' ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3582
      parse_err(SYNERR, "Extra ';' after defining interface block.\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3583
      next_char();                // Skip ';'
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3584
      return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3585
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3586
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3587
    next_char();                  // move past ';'
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3588
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3589
    // Create appropriate interface object
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3590
    if ( strcmp(iface_name,"REG_INTER") == 0 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3591
      inter = new RegInterface();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3592
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3593
    else if ( strcmp(iface_name,"CONST_INTER") == 0 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3594
      inter = new ConstInterface();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3595
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3596
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3597
  skipws();                       // be friendly to oper_parse()
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3598
  // Debug Stuff
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3599
  if (_AD._adl_debug > 1) fprintf(stderr,"Interface Form: %s\n", iface_name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3600
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3601
  // Create appropriate interface object and return.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3602
  return inter;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3603
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3604
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3605
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3606
//------------------------------mem_interface_parse----------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3607
Interface *ADLParser::mem_interface_parse(void) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3608
  // Fields for MemInterface
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3609
  char *base        = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3610
  char *index       = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3611
  char *scale       = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3612
  char *disp        = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3613
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3614
  if (_curchar != '%') {
15477
26b2c7942f07 8007403: Incorrect format arguments in adlparse.cpp
mikael
parents: 13971
diff changeset
  3615
    parse_err(SYNERR, "Missing '%%{' for 'interface' block.\n");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3616
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3617
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3618
  next_char();                  // Skip '%'
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3619
  if (_curchar != '{') {
15477
26b2c7942f07 8007403: Incorrect format arguments in adlparse.cpp
mikael
parents: 13971
diff changeset
  3620
    parse_err(SYNERR, "Missing '%%{' for 'interface' block.\n");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3621
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3622
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3623
  next_char();                  // Skip '{'
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3624
  skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3625
  do {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3626
    char *field = get_ident();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3627
    if (field == NULL) {
15477
26b2c7942f07 8007403: Incorrect format arguments in adlparse.cpp
mikael
parents: 13971
diff changeset
  3628
      parse_err(SYNERR, "Expected keyword, base|index|scale|disp,  or '%%}' ending interface.\n");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3629
      return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3630
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3631
    if ( strcmp(field,"base") == 0 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3632
      base  = interface_field_parse();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3633
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3634
    else if ( strcmp(field,"index") == 0 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3635
      index = interface_field_parse();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3636
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3637
    else if ( strcmp(field,"scale") == 0 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3638
      scale = interface_field_parse();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3639
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3640
    else if ( strcmp(field,"disp") == 0 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3641
      disp  = interface_field_parse();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3642
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3643
    else {
15477
26b2c7942f07 8007403: Incorrect format arguments in adlparse.cpp
mikael
parents: 13971
diff changeset
  3644
      parse_err(SYNERR, "Expected keyword, base|index|scale|disp,  or '%%}' ending interface.\n");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3645
      return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3646
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3647
  } while( _curchar != '%' );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3648
  next_char();                  // Skip '%'
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3649
  if ( _curchar != '}' ) {
15477
26b2c7942f07 8007403: Incorrect format arguments in adlparse.cpp
mikael
parents: 13971
diff changeset
  3650
    parse_err(SYNERR, "Missing '%%}' for 'interface' block.\n");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3651
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3652
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3653
  next_char();                  // Skip '}'
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3654
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3655
  // Construct desired object and return
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3656
  Interface *inter = new MemInterface(base, index, scale, disp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3657
  return inter;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3658
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3659
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3660
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3661
//------------------------------cond_interface_parse---------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3662
Interface *ADLParser::cond_interface_parse(void) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3663
  char *equal;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3664
  char *not_equal;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3665
  char *less;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3666
  char *greater_equal;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3667
  char *less_equal;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3668
  char *greater;
20289
35d78de0c547 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents: 15477
diff changeset
  3669
  char *overflow;
35d78de0c547 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents: 15477
diff changeset
  3670
  char *no_overflow;
1495
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  3671
  const char *equal_format = "eq";
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  3672
  const char *not_equal_format = "ne";
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  3673
  const char *less_format = "lt";
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  3674
  const char *greater_equal_format = "ge";
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  3675
  const char *less_equal_format = "le";
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  3676
  const char *greater_format = "gt";
20289
35d78de0c547 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents: 15477
diff changeset
  3677
  const char *overflow_format = "o";
35d78de0c547 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents: 15477
diff changeset
  3678
  const char *no_overflow_format = "no";
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3679
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3680
  if (_curchar != '%') {
15477
26b2c7942f07 8007403: Incorrect format arguments in adlparse.cpp
mikael
parents: 13971
diff changeset
  3681
    parse_err(SYNERR, "Missing '%%{' for 'cond_interface' block.\n");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3682
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3683
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3684
  next_char();                  // Skip '%'
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3685
  if (_curchar != '{') {
15477
26b2c7942f07 8007403: Incorrect format arguments in adlparse.cpp
mikael
parents: 13971
diff changeset
  3686
    parse_err(SYNERR, "Missing '%%{' for 'cond_interface' block.\n");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3687
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3688
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3689
  next_char();                  // Skip '{'
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3690
  skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3691
  do {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3692
    char *field = get_ident();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3693
    if (field == NULL) {
15477
26b2c7942f07 8007403: Incorrect format arguments in adlparse.cpp
mikael
parents: 13971
diff changeset
  3694
      parse_err(SYNERR, "Expected keyword, base|index|scale|disp,  or '%%}' ending interface.\n");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3695
      return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3696
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3697
    if ( strcmp(field,"equal") == 0 ) {
1495
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  3698
      equal  = interface_field_parse(&equal_format);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3699
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3700
    else if ( strcmp(field,"not_equal") == 0 ) {
1495
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  3701
      not_equal = interface_field_parse(&not_equal_format);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3702
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3703
    else if ( strcmp(field,"less") == 0 ) {
1495
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  3704
      less = interface_field_parse(&less_format);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3705
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3706
    else if ( strcmp(field,"greater_equal") == 0 ) {
1495
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  3707
      greater_equal  = interface_field_parse(&greater_equal_format);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3708
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3709
    else if ( strcmp(field,"less_equal") == 0 ) {
1495
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  3710
      less_equal = interface_field_parse(&less_equal_format);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3711
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3712
    else if ( strcmp(field,"greater") == 0 ) {
1495
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  3713
      greater = interface_field_parse(&greater_format);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3714
    }
20289
35d78de0c547 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents: 15477
diff changeset
  3715
    else if ( strcmp(field,"overflow") == 0 ) {
35d78de0c547 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents: 15477
diff changeset
  3716
      overflow = interface_field_parse(&overflow_format);
35d78de0c547 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents: 15477
diff changeset
  3717
    }
35d78de0c547 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents: 15477
diff changeset
  3718
    else if ( strcmp(field,"no_overflow") == 0 ) {
35d78de0c547 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents: 15477
diff changeset
  3719
      no_overflow = interface_field_parse(&no_overflow_format);
35d78de0c547 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents: 15477
diff changeset
  3720
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3721
    else {
15477
26b2c7942f07 8007403: Incorrect format arguments in adlparse.cpp
mikael
parents: 13971
diff changeset
  3722
      parse_err(SYNERR, "Expected keyword, base|index|scale|disp,  or '%%}' ending interface.\n");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3723
      return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3724
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3725
  } while( _curchar != '%' );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3726
  next_char();                  // Skip '%'
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3727
  if ( _curchar != '}' ) {
15477
26b2c7942f07 8007403: Incorrect format arguments in adlparse.cpp
mikael
parents: 13971
diff changeset
  3728
    parse_err(SYNERR, "Missing '%%}' for 'interface' block.\n");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3729
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3730
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3731
  next_char();                  // Skip '}'
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3732
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3733
  // Construct desired object and return
1495
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  3734
  Interface *inter = new CondInterface(equal,         equal_format,
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  3735
                                       not_equal,     not_equal_format,
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  3736
                                       less,          less_format,
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  3737
                                       greater_equal, greater_equal_format,
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  3738
                                       less_equal,    less_equal_format,
20289
35d78de0c547 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents: 15477
diff changeset
  3739
                                       greater,       greater_format,
35d78de0c547 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents: 15477
diff changeset
  3740
                                       overflow,      overflow_format,
35d78de0c547 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents: 15477
diff changeset
  3741
                                       no_overflow,   no_overflow_format);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3742
  return inter;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3743
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3744
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3745
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3746
//------------------------------interface_field_parse--------------------------
1495
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  3747
char *ADLParser::interface_field_parse(const char ** format) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3748
  char *iface_field = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3749
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3750
  // Get interface field
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3751
  skipws();                      // Skip whitespace
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3752
  if (_curchar != '(') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3753
    parse_err(SYNERR, "Missing '(' at start of interface field.\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3754
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3755
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3756
  next_char();                   // move past '('
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3757
  skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3758
  if ( _curchar != '0' && _curchar != '$' ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3759
    parse_err(SYNERR, "missing or invalid interface field contents.\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3760
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3761
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3762
  iface_field = get_rep_var_ident();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3763
  if (iface_field == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3764
    parse_err(SYNERR, "missing or invalid interface field contents.\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3765
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3766
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3767
  skipws();
1495
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  3768
  if (format != NULL && _curchar == ',') {
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  3769
    next_char();
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  3770
    skipws();
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  3771
    if (_curchar != '"') {
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  3772
      parse_err(SYNERR, "Missing '\"' in field format .\n");
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  3773
      return NULL;
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  3774
    }
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  3775
    next_char();
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  3776
    char *start = _ptr;       // Record start of the next string
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  3777
    while ((_curchar != '"') && (_curchar != '%') && (_curchar != '\n')) {
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  3778
      if (_curchar == '\\')  next_char();  // superquote
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  3779
      if (_curchar == '\n')  parse_err(SYNERR, "newline in string");  // unimplemented!
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  3780
      next_char();
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  3781
    }
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  3782
    if (_curchar != '"') {
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  3783
      parse_err(SYNERR, "Missing '\"' at end of field format .\n");
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  3784
      return NULL;
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  3785
    }
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  3786
    // If a string was found, terminate it and record in FormatRule
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  3787
    if ( start != _ptr ) {
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  3788
      *_ptr  = '\0';          // Terminate the string
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  3789
      *format = start;
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  3790
    }
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  3791
    next_char();
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  3792
    skipws();
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  3793
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3794
  if (_curchar != ')') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3795
    parse_err(SYNERR, "Missing ')' after interface field.\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3796
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3797
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3798
  next_char();                   // move past ')'
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3799
  skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3800
  if ( _curchar != ';' ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3801
    parse_err(SYNERR, "Missing ';' at end of interface field.\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3802
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3803
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3804
  next_char();                    // move past ';'
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3805
  skipws();                       // be friendly to interface_parse()
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3806
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3807
  return iface_field;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3808
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3809
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3810
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3811
//------------------------------match_parse------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3812
MatchRule *ADLParser::match_parse(FormDict &operands) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3813
  MatchRule *match;               // Match Rule class for instruction/operand
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3814
  char      *cnstr = NULL;        // Code for constructor
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3815
  int        depth = 0;           // Counter for matching parentheses
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3816
  int        numleaves = 0;       // Counter for number of leaves in rule
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3817
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3818
  // Parse the match rule tree
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3819
  MatchNode *mnode = matchNode_parse(operands, depth, numleaves, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3820
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3821
  // Either there is a block with a constructor, or a ';' here
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3822
  skipws();                       // Skip whitespace
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3823
  if ( _curchar == ';' ) {        // Semicolon is valid terminator
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3824
    cnstr = NULL;                 // no constructor for this form
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3825
    next_char();                  // Move past the ';', replaced with '\0'
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3826
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3827
  else if ((cnstr = find_cpp_block("match constructor")) == NULL ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3828
    parse_err(SYNERR, "invalid construction of match rule\n"
15477
26b2c7942f07 8007403: Incorrect format arguments in adlparse.cpp
mikael
parents: 13971
diff changeset
  3829
              "Missing ';' or invalid '%%{' and '%%}' constructor\n");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3830
    return NULL;                  // No MatchRule to return
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3831
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3832
  if (_AD._adl_debug > 1)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3833
    if (cnstr) fprintf(stderr,"Match Constructor: %s\n", cnstr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3834
  // Build new MatchRule object
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3835
  match = new MatchRule(_AD, mnode, depth, cnstr, numleaves);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3836
  skipws();                       // Skip any trailing whitespace
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3837
  return match;                   // Return MatchRule object
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3838
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3839
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3840
//------------------------------format_parse-----------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3841
FormatRule* ADLParser::format_parse(void) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3842
  char       *desc   = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3843
  FormatRule *format = (new FormatRule(desc));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3844
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3845
  // Without expression form, MUST have a code block;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3846
  skipws();                       // Skip whitespace
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3847
  if ( _curchar == ';' ) {        // Semicolon is valid terminator
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3848
    desc  = NULL;                 // no constructor for this form
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3849
    next_char();                  // Move past the ';', replaced with '\0'
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3850
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3851
  else if ( _curchar == '%' && *(_ptr+1) == '{') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3852
    next_char();                  // Move past the '%'
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3853
    next_char();                  // Move past the '{'
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3854
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3855
    skipws();
1495
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  3856
    if (_curchar == '$') {
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  3857
      char* ident = get_rep_var_ident();
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  3858
      if (strcmp(ident, "$$template") == 0) return template_parse();
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  3859
      parse_err(SYNERR, "Unknown \"%s\" directive in format", ident);
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  3860
      return NULL;
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  3861
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3862
    // Check for the opening '"' inside the format description
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3863
    if ( _curchar == '"' ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3864
      next_char();              // Move past the initial '"'
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3865
      if( _curchar == '"' ) {   // Handle empty format string case
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3866
        *_ptr = '\0';           // Terminate empty string
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3867
        format->_strings.addName(_ptr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3868
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3869
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3870
      // Collect the parts of the format description
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3871
      // (1) strings that are passed through to tty->print
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3872
      // (2) replacement/substitution variable, preceeded by a '$'
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3873
      // (3) multi-token ANSIY C style strings
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3874
      while ( true ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3875
        if ( _curchar == '%' || _curchar == '\n' ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3876
          if ( _curchar != '"' ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3877
            parse_err(SYNERR, "missing '\"' at end of format block");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3878
            return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3879
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3880
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3881
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3882
        // (1)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3883
        // Check if there is a string to pass through to output
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3884
        char *start = _ptr;       // Record start of the next string
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3885
        while ((_curchar != '$') && (_curchar != '"') && (_curchar != '%') && (_curchar != '\n')) {
1662
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  3886
          if (_curchar == '\\') {
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  3887
            next_char();  // superquote
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  3888
            if ((_curchar == '$') || (_curchar == '%'))
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  3889
              // hack to avoid % escapes and warnings about undefined \ escapes
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  3890
              *(_ptr-1) = _curchar;
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  3891
          }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3892
          if (_curchar == '\n')  parse_err(SYNERR, "newline in string");  // unimplemented!
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3893
          next_char();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3894
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3895
        // If a string was found, terminate it and record in FormatRule
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3896
        if ( start != _ptr ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3897
          *_ptr  = '\0';          // Terminate the string
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3898
          format->_strings.addName(start);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3899
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3900
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3901
        // (2)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3902
        // If we are at a replacement variable,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3903
        // copy it and record in FormatRule
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3904
        if ( _curchar == '$' ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3905
          next_char();          // Move past the '$'
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3906
          char* rep_var = get_ident(); // Nil terminate the variable name
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3907
          rep_var = strdup(rep_var);// Copy the string
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3908
          *_ptr   = _curchar;     // and replace Nil with original character
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3909
          format->_rep_vars.addName(rep_var);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3910
          // Add flag to _strings list indicating we should check _rep_vars
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3911
          format->_strings.addName(NameList::_signal);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3912
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3913
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3914
        // (3)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3915
        // Allow very long strings to be broken up,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3916
        // using the ANSI C syntax "foo\n" <newline> "bar"
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3917
        if ( _curchar == '"') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3918
          next_char();           // Move past the '"'
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3919
          skipws();              // Skip white space before next string token
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3920
          if ( _curchar != '"') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3921
            break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3922
          } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3923
            // Found one.  Skip both " and the whitespace in between.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3924
            next_char();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3925
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3926
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3927
      } // end while part of format description
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3928
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3929
      // Check for closing '"' and '%}' in format description
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3930
      skipws();                   // Move to closing '%}'
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3931
      if ( _curchar != '%' ) {
15477
26b2c7942f07 8007403: Incorrect format arguments in adlparse.cpp
mikael
parents: 13971
diff changeset
  3932
        parse_err(SYNERR, "non-blank characters between closing '\"' and '%%' in format");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3933
        return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3934
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3935
    } // Done with format description inside
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3936
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3937
    skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3938
    // Past format description, at '%'
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3939
    if ( _curchar != '%' || *(_ptr+1) != '}' ) {
15477
26b2c7942f07 8007403: Incorrect format arguments in adlparse.cpp
mikael
parents: 13971
diff changeset
  3940
      parse_err(SYNERR, "missing '%%}' at end of format block");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3941
      return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3942
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3943
    next_char();                  // Move past the '%'
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3944
    next_char();                  // Move past the '}'
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3945
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3946
  else {  // parameter list alone must terminate with a ';'
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3947
    parse_err(SYNERR, "missing ';' after Format expression");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3948
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3949
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3950
  // Debug Stuff
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3951
  if (_AD._adl_debug > 1) fprintf(stderr,"Format Rule: %s\n", desc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3952
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3953
  skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3954
  return format;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3955
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3956
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3957
1495
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  3958
//------------------------------template_parse-----------------------------------
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  3959
FormatRule* ADLParser::template_parse(void) {
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  3960
  char       *desc   = NULL;
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  3961
  FormatRule *format = (new FormatRule(desc));
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  3962
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  3963
  skipws();
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  3964
  while ( (_curchar != '%') && (*(_ptr+1) != '}') ) {
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  3965
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  3966
    // (1)
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  3967
    // Check if there is a string to pass through to output
2129
e810a33b5c67 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 1675
diff changeset
  3968
    {
e810a33b5c67 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 1675
diff changeset
  3969
      char *start = _ptr;       // Record start of the next string
e810a33b5c67 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 1675
diff changeset
  3970
      while ((_curchar != '$') && ((_curchar != '%') || (*(_ptr+1) != '}')) ) {
e810a33b5c67 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 1675
diff changeset
  3971
        // If at the start of a comment, skip past it
e810a33b5c67 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 1675
diff changeset
  3972
        if( (_curchar == '/') && ((*(_ptr+1) == '/') || (*(_ptr+1) == '*')) ) {
e810a33b5c67 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 1675
diff changeset
  3973
          skipws_no_preproc();
e810a33b5c67 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 1675
diff changeset
  3974
        } else {
e810a33b5c67 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 1675
diff changeset
  3975
          // ELSE advance to the next character, or start of the next line
e810a33b5c67 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 1675
diff changeset
  3976
          next_char_or_line();
e810a33b5c67 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 1675
diff changeset
  3977
        }
1495
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  3978
      }
2129
e810a33b5c67 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 1675
diff changeset
  3979
      // If a string was found, terminate it and record in EncClass
e810a33b5c67 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 1675
diff changeset
  3980
      if ( start != _ptr ) {
e810a33b5c67 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 1675
diff changeset
  3981
        *_ptr  = '\0';          // Terminate the string
e810a33b5c67 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 1675
diff changeset
  3982
        // Add flag to _strings list indicating we should check _rep_vars
e810a33b5c67 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 1675
diff changeset
  3983
        format->_strings.addName(NameList::_signal2);
e810a33b5c67 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 1675
diff changeset
  3984
        format->_strings.addName(start);
e810a33b5c67 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 1675
diff changeset
  3985
      }
1495
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  3986
    }
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  3987
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  3988
    // (2)
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  3989
    // If we are at a replacement variable,
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  3990
    // copy it and record in EncClass
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  3991
    if ( _curchar == '$' ) {
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  3992
      // Found replacement Variable
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  3993
      char *rep_var = get_rep_var_ident_dup();
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  3994
      if (strcmp(rep_var, "$emit") == 0) {
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  3995
        // switch to normal format parsing
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  3996
        next_char();
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  3997
        next_char();
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  3998
        skipws();
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  3999
        // Check for the opening '"' inside the format description
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4000
        if ( _curchar == '"' ) {
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4001
          next_char();              // Move past the initial '"'
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4002
          if( _curchar == '"' ) {   // Handle empty format string case
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4003
            *_ptr = '\0';           // Terminate empty string
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4004
            format->_strings.addName(_ptr);
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4005
          }
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4006
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4007
          // Collect the parts of the format description
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4008
          // (1) strings that are passed through to tty->print
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4009
          // (2) replacement/substitution variable, preceeded by a '$'
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4010
          // (3) multi-token ANSIY C style strings
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4011
          while ( true ) {
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4012
            if ( _curchar == '%' || _curchar == '\n' ) {
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4013
              parse_err(SYNERR, "missing '\"' at end of format block");
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4014
              return NULL;
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4015
            }
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4016
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4017
            // (1)
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4018
            // Check if there is a string to pass through to output
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4019
            char *start = _ptr;       // Record start of the next string
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4020
            while ((_curchar != '$') && (_curchar != '"') && (_curchar != '%') && (_curchar != '\n')) {
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4021
              if (_curchar == '\\')  next_char();  // superquote
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4022
              if (_curchar == '\n')  parse_err(SYNERR, "newline in string");  // unimplemented!
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4023
              next_char();
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4024
            }
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4025
            // If a string was found, terminate it and record in FormatRule
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4026
            if ( start != _ptr ) {
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4027
              *_ptr  = '\0';          // Terminate the string
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4028
              format->_strings.addName(start);
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4029
            }
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4030
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4031
            // (2)
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4032
            // If we are at a replacement variable,
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4033
            // copy it and record in FormatRule
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4034
            if ( _curchar == '$' ) {
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4035
              next_char();          // Move past the '$'
2129
e810a33b5c67 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 1675
diff changeset
  4036
              char* next_rep_var = get_ident(); // Nil terminate the variable name
e810a33b5c67 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 1675
diff changeset
  4037
              next_rep_var = strdup(next_rep_var);// Copy the string
1495
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4038
              *_ptr   = _curchar;     // and replace Nil with original character
2129
e810a33b5c67 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 1675
diff changeset
  4039
              format->_rep_vars.addName(next_rep_var);
1495
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4040
              // Add flag to _strings list indicating we should check _rep_vars
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4041
              format->_strings.addName(NameList::_signal);
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4042
            }
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4043
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4044
            // (3)
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4045
            // Allow very long strings to be broken up,
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4046
            // using the ANSI C syntax "foo\n" <newline> "bar"
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4047
            if ( _curchar == '"') {
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4048
              next_char();           // Move past the '"'
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4049
              skipws();              // Skip white space before next string token
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4050
              if ( _curchar != '"') {
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4051
                break;
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4052
              } else {
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4053
                // Found one.  Skip both " and the whitespace in between.
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4054
                next_char();
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4055
              }
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4056
            }
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4057
          } // end while part of format description
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4058
        }
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4059
      } else {
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4060
        // Add flag to _strings list indicating we should check _rep_vars
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4061
        format->_rep_vars.addName(rep_var);
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4062
        // Add flag to _strings list indicating we should check _rep_vars
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4063
        format->_strings.addName(NameList::_signal3);
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4064
      }
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4065
    } // end while part of format description
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4066
  }
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4067
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4068
  skipws();
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4069
  // Past format description, at '%'
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4070
  if ( _curchar != '%' || *(_ptr+1) != '}' ) {
15477
26b2c7942f07 8007403: Incorrect format arguments in adlparse.cpp
mikael
parents: 13971
diff changeset
  4071
    parse_err(SYNERR, "missing '%%}' at end of format block");
1495
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4072
    return NULL;
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4073
  }
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4074
  next_char();                  // Move past the '%'
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4075
  next_char();                  // Move past the '}'
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4076
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4077
  // Debug Stuff
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4078
  if (_AD._adl_debug > 1) fprintf(stderr,"Format Rule: %s\n", desc);
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4079
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4080
  skipws();
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4081
  return format;
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4082
}
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4083
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  4084
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4085
//------------------------------effect_parse-----------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4086
void ADLParser::effect_parse(InstructForm *instr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4087
  char* desc   = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4088
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4089
  skipws();                      // Skip whitespace
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4090
  if (_curchar != '(') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4091
    parse_err(SYNERR, "missing '(' in effect definition\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4092
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4093
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4094
  // Get list of effect-operand pairs and insert into dictionary
11196
a310a659c580 7077312: Provide a CALL effect for instruct declaration in the ad file
roland
parents: 11190
diff changeset
  4095
  else get_effectlist(instr->_effects, instr->_localNames, instr->_has_call);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4096
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4097
  // Debug Stuff
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4098
  if (_AD._adl_debug > 1) fprintf(stderr,"Effect description: %s\n", desc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4099
  if (_curchar != ';') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4100
    parse_err(SYNERR, "missing ';' in Effect definition\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4101
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4102
  next_char();                  // Skip ';'
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4103
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4104
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4105
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4106
//------------------------------expand_parse-----------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4107
ExpandRule* ADLParser::expand_parse(InstructForm *instr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4108
  char         *ident, *ident2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4109
  NameAndList  *instr_and_operands = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4110
  ExpandRule   *exp = new ExpandRule();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4111
22847
603ad1f10e16 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 22844
diff changeset
  4112
  // Expand is a block containing an ordered list of operands with initializers,
603ad1f10e16 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 22844
diff changeset
  4113
  // or instructions, each of which has an ordered list of operands.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4114
  // Check for block delimiter
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4115
  skipws();                        // Skip leading whitespace
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4116
  if ((_curchar != '%')
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4117
      || (next_char(), (_curchar != '{')) ) { // If not open block
15477
26b2c7942f07 8007403: Incorrect format arguments in adlparse.cpp
mikael
parents: 13971
diff changeset
  4118
    parse_err(SYNERR, "missing '%%{' in expand definition\n");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4119
    return(NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4120
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4121
  next_char();                     // Maintain the invariant
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4122
  do {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4123
    ident = get_ident();           // Grab next identifier
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4124
    if (ident == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4125
      parse_err(SYNERR, "identifier expected at %c\n", _curchar);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4126
      continue;
22847
603ad1f10e16 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 22844
diff changeset
  4127
    }
603ad1f10e16 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 22844
diff changeset
  4128
603ad1f10e16 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 22844
diff changeset
  4129
    // Check whether we should parse an instruction or operand.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4130
    const Form *form = _globalNames[ident];
22847
603ad1f10e16 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 22844
diff changeset
  4131
    bool parse_oper = false;
603ad1f10e16 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 22844
diff changeset
  4132
    bool parse_ins  = false;
603ad1f10e16 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 22844
diff changeset
  4133
    if (form == NULL) {
603ad1f10e16 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 22844
diff changeset
  4134
      skipws();
603ad1f10e16 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 22844
diff changeset
  4135
      // Check whether this looks like an instruction specification.  If so,
603ad1f10e16 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 22844
diff changeset
  4136
      // just parse the instruction.  The declaration of the instruction is
603ad1f10e16 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 22844
diff changeset
  4137
      // not needed here.
603ad1f10e16 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 22844
diff changeset
  4138
      if (_curchar == '(') parse_ins = true;
603ad1f10e16 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 22844
diff changeset
  4139
    } else if (form->is_instruction()) {
603ad1f10e16 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 22844
diff changeset
  4140
      parse_ins = true;
603ad1f10e16 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 22844
diff changeset
  4141
    } else if (form->is_operand()) {
603ad1f10e16 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 22844
diff changeset
  4142
      parse_oper = true;
603ad1f10e16 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 22844
diff changeset
  4143
    } else {
603ad1f10e16 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 22844
diff changeset
  4144
      parse_err(SYNERR, "instruction/operand name expected at %s\n", ident);
603ad1f10e16 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 22844
diff changeset
  4145
      continue;
603ad1f10e16 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 22844
diff changeset
  4146
    }
603ad1f10e16 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 22844
diff changeset
  4147
603ad1f10e16 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 22844
diff changeset
  4148
    if (parse_oper) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4149
      // This is a new operand
22847
603ad1f10e16 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 22844
diff changeset
  4150
      OperandForm *oper = form->is_operand();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4151
      if (oper == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4152
        parse_err(SYNERR, "instruction/operand name expected at %s\n", ident);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4153
        continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4154
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4155
      // Throw the operand on the _newopers list
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4156
      skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4157
      ident = get_unique_ident(instr->_localNames,"Operand");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4158
      if (ident == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4159
        parse_err(SYNERR, "identifier expected at %c\n", _curchar);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4160
        continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4161
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4162
      exp->_newopers.addName(ident);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4163
      // Add new operand to LocalNames
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4164
      instr->_localNames.Insert(ident, oper);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4165
      // Grab any constructor code and save as a string
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4166
      char *c = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4167
      skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4168
      if (_curchar == '%') { // Need a constructor for the operand
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4169
        c = find_cpp_block("Operand Constructor");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4170
        if (c == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4171
          parse_err(SYNERR, "Invalid code block for operand constructor\n", _curchar);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4172
          continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4173
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4174
        // Add constructor to _newopconst Dict
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4175
        exp->_newopconst.Insert(ident, c);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4176
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4177
      else if (_curchar != ';') { // If no constructor, need a ;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4178
        parse_err(SYNERR, "Missing ; in expand rule operand declaration\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4179
        continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4180
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4181
      else next_char(); // Skip the ;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4182
      skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4183
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4184
    else {
22847
603ad1f10e16 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 22844
diff changeset
  4185
      assert(parse_ins, "sanity");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4186
      // Add instruction to list
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4187
      instr_and_operands = new NameAndList(ident);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4188
      // Grab operands, build nameList of them, and then put into dictionary
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4189
      skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4190
      if (_curchar != '(') {         // Check for parenthesized operand list
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4191
        parse_err(SYNERR, "missing '(' in expand instruction declaration\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4192
        continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4193
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4194
      do {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4195
        next_char();                 // skip open paren & comma characters
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4196
        skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4197
        if (_curchar == ')') break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4198
        ident2 = get_ident();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4199
        skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4200
        if (ident2 == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4201
          parse_err(SYNERR, "identifier expected at %c\n", _curchar);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4202
          continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4203
        }                            // Check that you have a valid operand
2129
e810a33b5c67 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 1675
diff changeset
  4204
        const Form *form2 = instr->_localNames[ident2];
e810a33b5c67 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 1675
diff changeset
  4205
        if (!form2) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4206
          parse_err(SYNERR, "operand name expected at %s\n", ident2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4207
          continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4208
        }
22847
603ad1f10e16 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 22844
diff changeset
  4209
        OperandForm *oper = form2->is_operand();
2129
e810a33b5c67 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 1675
diff changeset
  4210
        if (oper == NULL && !form2->is_opclass()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4211
          parse_err(SYNERR, "operand name expected at %s\n", ident2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4212
          continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4213
        }                            // Add operand to list
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4214
        instr_and_operands->add_entry(ident2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4215
      } while(_curchar == ',');
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4216
      if (_curchar != ')') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4217
        parse_err(SYNERR, "missing ')'in expand instruction declaration\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4218
        continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4219
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4220
      next_char();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4221
      if (_curchar != ';') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4222
        parse_err(SYNERR, "missing ';'in expand instruction declaration\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4223
        continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4224
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4225
      next_char();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4226
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4227
      // Record both instruction name and its operand list
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4228
      exp->add_instruction(instr_and_operands);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4229
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4230
      skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4231
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4232
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4233
  } while(_curchar != '%');
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4234
  next_char();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4235
  if (_curchar != '}') {
15477
26b2c7942f07 8007403: Incorrect format arguments in adlparse.cpp
mikael
parents: 13971
diff changeset
  4236
    parse_err(SYNERR, "missing '%%}' in expand rule definition\n");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4237
    return(NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4238
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4239
  next_char();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4240
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4241
  // Debug Stuff
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4242
  if (_AD._adl_debug > 1) fprintf(stderr,"Expand Rule:\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4243
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4244
  skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4245
  return (exp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4246
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4247
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4248
//------------------------------rewrite_parse----------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4249
RewriteRule* ADLParser::rewrite_parse(void) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4250
  char* params = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4251
  char* desc   = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4252
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4253
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4254
  // This feature targeted for second generation description language.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4255
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4256
  skipws();                      // Skip whitespace
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4257
  // Get parameters for rewrite
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4258
  if ((params = get_paren_expr("rewrite parameters")) == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4259
    parse_err(SYNERR, "missing '(' in rewrite rule\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4260
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4261
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4262
  // Debug Stuff
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4263
  if (_AD._adl_debug > 1) fprintf(stderr,"Rewrite parameters: %s\n", params);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4264
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4265
  // For now, grab entire block;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4266
  skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4267
  if ( (desc = find_cpp_block("rewrite block")) == NULL ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4268
    parse_err(SYNERR, "incorrect or missing block for 'rewrite'.\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4269
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4270
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4271
  // Debug Stuff
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4272
  if (_AD._adl_debug > 1) fprintf(stderr,"Rewrite Rule: %s\n", desc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4273
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4274
  skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4275
  return (new RewriteRule(params,desc));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4276
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4277
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4278
//------------------------------attr_parse-------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4279
Attribute *ADLParser::attr_parse(char* ident) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4280
  Attribute *attrib;              // Attribute class
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4281
  char      *cost = NULL;         // String representation of cost attribute
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4282
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4283
  skipws();                       // Skip leading whitespace
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4284
  if ( (cost = get_paren_expr("attribute")) == NULL ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4285
    parse_err(SYNERR, "incorrect or missing expression for 'attribute'\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4286
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4287
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4288
  // Debug Stuff
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4289
  if (_AD._adl_debug > 1) fprintf(stderr,"Attribute: %s\n", cost);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4290
  if (_curchar != ';') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4291
    parse_err(SYNERR, "missing ';' in attribute definition\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4292
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4293
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4294
  next_char();                   // Point after the terminator
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4295
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4296
  skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4297
  attrib = new Attribute(ident,cost,INS_ATTR); // Build new predicate object
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4298
  return attrib;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4299
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4300
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4301
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4302
//------------------------------matchNode_parse--------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4303
MatchNode *ADLParser::matchNode_parse(FormDict &operands, int &depth, int &numleaves, bool atroot) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4304
  // Count depth of parenthesis nesting for both left and right children
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4305
  int   lParens = depth;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4306
  int   rParens = depth;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4307
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4308
  // MatchNode objects for left, right, and root of subtree.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4309
  MatchNode *lChild = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4310
  MatchNode *rChild = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4311
  char      *token;               // Identifier which may be opcode or operand
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4312
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4313
  // Match expression starts with a '('
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4314
  if (cur_char() != '(')
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4315
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4316
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4317
  next_char();                    // advance past '('
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4318
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4319
  // Parse the opcode
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4320
  token = get_ident();            // Get identifier, opcode
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4321
  if (token == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4322
    parse_err(SYNERR, "missing opcode in match expression\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4323
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4324
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4325
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4326
  // Take note if we see one of a few special operations - those that are
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4327
  // treated differently on different architectures in the sense that on
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4328
  // one architecture there is a match rule and on another there isn't (so
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4329
  // a call will eventually be generated).
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4330
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4331
  for (int i = _last_machine_leaf + 1; i < _last_opcode; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4332
    if (strcmp(token, NodeClassNames[i]) == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4333
      _AD.has_match_rule(i, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4334
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4335
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4336
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4337
  // Lookup the root value in the operands dict to perform substitution
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4338
  const char  *result    = NULL;  // Result type will be filled in later
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4339
  const char  *name      = token; // local name associated with this node
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4340
  const char  *operation = token; // remember valid operation for later
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4341
  const Form  *form      = operands[token];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4342
  OpClassForm *opcForm = form ? form->is_opclass() : NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4343
  if (opcForm != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4344
    // If this token is an entry in the local names table, record its type
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4345
    if (!opcForm->ideal_only()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4346
      operation = opcForm->_ident;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4347
      result = operation;         // Operands result in their own type
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4348
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4349
    // Otherwise it is an ideal type, and so, has no local name
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4350
    else                        name = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4351
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4352
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4353
  // Parse the operands
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4354
  skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4355
  if (cur_char() != ')') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4356
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4357
    // Parse the left child
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4358
    if (strcmp(operation,"Set"))
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4359
      lChild = matchChild_parse(operands, lParens, numleaves, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4360
    else
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4361
      lChild = matchChild_parse(operands, lParens, numleaves, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4362
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4363
    skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4364
    if (cur_char() != ')' ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4365
      if(strcmp(operation, "Set"))
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4366
        rChild = matchChild_parse(operands,rParens,numleaves,false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4367
      else
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4368
        rChild = matchChild_parse(operands,rParens,numleaves,true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4369
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4370
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4371
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4372
  // Check for required ')'
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4373
  skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4374
  if (cur_char() != ')') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4375
    parse_err(SYNERR, "missing ')' in match expression\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4376
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4377
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4378
  next_char();                    // skip the ')'
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4379
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4380
  MatchNode* mroot = new MatchNode(_AD,result,name,operation,lChild,rChild);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4381
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4382
  // If not the root, reduce this subtree to an internal operand
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4383
  if (!atroot) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4384
    mroot->build_internalop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4385
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4386
  // depth is greater of left and right paths.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4387
  depth = (lParens > rParens) ? lParens : rParens;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4388
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4389
  return mroot;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4390
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4391
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4392
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4393
//------------------------------matchChild_parse-------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4394
MatchNode *ADLParser::matchChild_parse(FormDict &operands, int &parens, int &numleaves, bool atroot) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4395
  MatchNode  *child  = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4396
  const char *result = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4397
  const char *token  = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4398
  const char *opType = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4399
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4400
  if (cur_char() == '(') {         // child is an operation
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4401
    ++parens;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4402
    child = matchNode_parse(operands, parens, numleaves, atroot);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4403
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4404
  else {                           // child is an operand
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4405
    token = get_ident();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4406
    const Form  *form    = operands[token];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4407
    OpClassForm *opcForm = form ? form->is_opclass() : NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4408
    if (opcForm != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4409
      opType = opcForm->_ident;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4410
      result = opcForm->_ident;    // an operand's result matches its type
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4411
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4412
      parse_err(SYNERR, "undefined operand %s in match rule\n", token);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4413
      return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4414
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4415
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4416
    if (opType == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4417
      parse_err(SYNERR, "missing type for argument '%s'\n", token);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4418
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4419
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4420
    child = new MatchNode(_AD, result, token, opType);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4421
    ++numleaves;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4422
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4423
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4424
  return child;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4425
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4426
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4427
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4428
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4429
// ******************** Private Utility Functions *************************
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4430
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4431
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4432
char* ADLParser::find_cpp_block(const char* description) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4433
  char *next;                     // Pointer for finding block delimiters
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4434
  char* cppBlock = NULL;          // Beginning of C++ code block
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4435
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4436
  if (_curchar == '%') {          // Encoding is a C++ expression
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4437
    next_char();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4438
    if (_curchar != '{') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4439
      parse_err(SYNERR, "missing '{' in %s \n", description);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4440
      return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4441
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4442
    next_char();                  // Skip block delimiter
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4443
    skipws_no_preproc();          // Skip leading whitespace
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4444
    cppBlock = _ptr;              // Point to start of expression
1662
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  4445
    int line = linenum();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4446
    next = _ptr + 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4447
    while(((_curchar != '%') || (*next != '}')) && (_curchar != '\0')) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4448
      next_char_or_line();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4449
      next = _ptr+1;              // Maintain the next pointer
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4450
    }                             // Grab string
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4451
    if (_curchar == '\0') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4452
      parse_err(SYNERR, "invalid termination of %s \n", description);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4453
      return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4454
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4455
    *_ptr = '\0';                 // Terminate string
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4456
    _ptr += 2;                    // Skip block delimiter
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4457
    _curchar = *_ptr;             // Maintain invariant
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4458
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4459
    // Prepend location descriptor, for debugging.
1662
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  4460
    if (_AD._adlocation_debug) {
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  4461
      char* location = get_line_string(line);
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  4462
      char* end_loc  = end_line_marker();
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  4463
      char* result = (char *)malloc(strlen(location) + strlen(cppBlock) + strlen(end_loc) + 1);
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  4464
      strcpy(result, location);
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  4465
      strcat(result, cppBlock);
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  4466
      strcat(result, end_loc);
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  4467
      cppBlock = result;
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  4468
      free(location);
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  4469
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4470
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4471
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4472
  return cppBlock;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4473
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4474
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4475
// Move to the closing token of the expression we are currently at,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4476
// as defined by stop_chars.  Match parens and quotes.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4477
char* ADLParser::get_expr(const char *desc, const char *stop_chars) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4478
  char* expr = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4479
  int   paren = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4480
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4481
  expr = _ptr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4482
  while (paren > 0 || !strchr(stop_chars, _curchar)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4483
    if (_curchar == '(') {        // Down level of nesting
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4484
      paren++;                    // Bump the parenthesis counter
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4485
      next_char();                // maintain the invariant
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4486
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4487
    else if (_curchar == ')') {   // Up one level of nesting
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4488
      if (paren == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4489
        // Paren underflow:  We didn't encounter the required stop-char.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4490
        parse_err(SYNERR, "too many )'s, did not find %s after %s\n",
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4491
                  stop_chars, desc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4492
        return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4493
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4494
      paren--;                    // Drop the parenthesis counter
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4495
      next_char();                // Maintain the invariant
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4496
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4497
    else if (_curchar == '"' || _curchar == '\'') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4498
      int qchar = _curchar;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4499
      while (true) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4500
        next_char();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4501
        if (_curchar == qchar) { next_char(); break; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4502
        if (_curchar == '\\')  next_char();  // superquote
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4503
        if (_curchar == '\n' || _curchar == '\0') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4504
          parse_err(SYNERR, "newline in string in %s\n", desc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4505
          return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4506
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4507
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4508
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4509
    else if (_curchar == '%' && (_ptr[1] == '{' || _ptr[1] == '}')) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4510
      // Make sure we do not stray into the next ADLC-level form.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4511
      parse_err(SYNERR, "unexpected %%%c in %s\n", _ptr[1], desc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4512
      return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4513
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4514
    else if (_curchar == '\0') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4515
      parse_err(SYNERR, "unexpected EOF in %s\n", desc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4516
      return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4517
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4518
    else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4519
      // Always walk over whitespace, comments, preprocessor directives, etc.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4520
      char* pre_skip_ptr = _ptr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4521
      skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4522
      // If the parser declined to make progress on whitespace,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4523
      // skip the next character, which is therefore NOT whitespace.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4524
      if (pre_skip_ptr == _ptr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4525
        next_char();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4526
      } else if (pre_skip_ptr+strlen(pre_skip_ptr) != _ptr+strlen(_ptr)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4527
        parse_err(SYNERR, "unimplemented: preprocessor must not elide subexpression in %s", desc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4528
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4529
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4530
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4531
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4532
  assert(strchr(stop_chars, _curchar), "non-null return must be at stop-char");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4533
  *_ptr = '\0';               // Replace ')' or other stop-char with '\0'
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4534
  return expr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4535
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4536
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4537
// Helper function around get_expr
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4538
// Sets _curchar to '(' so that get_paren_expr will search for a matching ')'
1662
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  4539
char *ADLParser::get_paren_expr(const char *description, bool include_location) {
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  4540
  int line = linenum();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4541
  if (_curchar != '(')            // Escape if not valid starting position
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4542
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4543
  next_char();                    // Skip the required initial paren.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4544
  char *token2 = get_expr(description, ")");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4545
  if (_curchar == ')')
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4546
    next_char();                  // Skip required final paren.
1662
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  4547
  int junk = 0;
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  4548
  if (include_location && _AD._adlocation_debug && !is_int_token(token2, junk)) {
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  4549
    // Prepend location descriptor, for debugging.
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  4550
    char* location = get_line_string(line);
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  4551
    char* end_loc  = end_line_marker();
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  4552
    char* result = (char *)malloc(strlen(location) + strlen(token2) + strlen(end_loc) + 1);
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  4553
    strcpy(result, location);
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  4554
    strcat(result, token2);
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  4555
    strcat(result, end_loc);
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  4556
    token2 = result;
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  4557
    free(location);
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  4558
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4559
  return token2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4560
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4561
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4562
//------------------------------get_ident_common-------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4563
// Looks for an identifier in the buffer, and turns it into a null terminated
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4564
// string(still inside the file buffer).  Returns a pointer to the string or
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4565
// NULL if some other token is found instead.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4566
char *ADLParser::get_ident_common(bool do_preproc) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4567
  register char c;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4568
  char *start;                    // Pointer to start of token
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4569
  char *end;                      // Pointer to end of token
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4570
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4571
  if( _curline == NULL )          // Return NULL at EOF.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4572
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4573
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4574
  skipws_common(do_preproc);      // Skip whitespace before identifier
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4575
  start = end = _ptr;             // Start points at first character
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4576
  end--;                          // unwind end by one to prepare for loop
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4577
  do {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4578
    end++;                        // Increment end pointer
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4579
    c = *end;                     // Grab character to test
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4580
  } while ( ((c >= 'a') && (c <= 'z')) || ((c >= 'A') && (c <= 'Z'))
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4581
            || ((c >= '0') && (c <= '9'))
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4582
            || ((c == '_')) || ((c == ':')) || ((c == '#')) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4583
  if (start == end) {             // We popped out on the first try
13971
3c568f3dacca 8000592: Improve adlc usability
kvn
parents: 13104
diff changeset
  4584
    // It can occur that `start' contains the rest of the input file.
3c568f3dacca 8000592: Improve adlc usability
kvn
parents: 13104
diff changeset
  4585
    // In this case the output should be truncated.
3c568f3dacca 8000592: Improve adlc usability
kvn
parents: 13104
diff changeset
  4586
    if (strlen(start) > 24) {
3c568f3dacca 8000592: Improve adlc usability
kvn
parents: 13104
diff changeset
  4587
      char buf[32];
3c568f3dacca 8000592: Improve adlc usability
kvn
parents: 13104
diff changeset
  4588
      strncpy(buf, start, 20);
3c568f3dacca 8000592: Improve adlc usability
kvn
parents: 13104
diff changeset
  4589
      buf[20] = '\0';
3c568f3dacca 8000592: Improve adlc usability
kvn
parents: 13104
diff changeset
  4590
      strcat(buf, "[...]");
3c568f3dacca 8000592: Improve adlc usability
kvn
parents: 13104
diff changeset
  4591
      parse_err(SYNERR, "Identifier expected, but found '%s'.", buf);
3c568f3dacca 8000592: Improve adlc usability
kvn
parents: 13104
diff changeset
  4592
    } else {
3c568f3dacca 8000592: Improve adlc usability
kvn
parents: 13104
diff changeset
  4593
      parse_err(SYNERR, "Identifier expected, but found '%s'.", start);
3c568f3dacca 8000592: Improve adlc usability
kvn
parents: 13104
diff changeset
  4594
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4595
    start = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4596
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4597
  else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4598
    _curchar = c;                 // Save the first character of next token
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4599
    *end = '\0';                  // NULL terminate the string in place
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4600
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4601
  _ptr = end;                     // Reset _ptr to point to next char after token
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4602
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4603
  // Make sure we do not try to use #defined identifiers.  If start is
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4604
  // NULL an error was already reported.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4605
  if (do_preproc && start != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4606
    const char* def = _AD.get_preproc_def(start);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4607
    if (def != NULL && strcmp(def, start)) {
1662
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  4608
      const char* def1 = def;
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  4609
      const char* def2 = _AD.get_preproc_def(def1);
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  4610
      // implement up to 2 levels of #define
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  4611
      if (def2 != NULL && strcmp(def2, def1)) {
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  4612
        def = def2;
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  4613
        const char* def3 = _AD.get_preproc_def(def2);
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  4614
        if (def3 != NULL && strcmp(def3, def2) && strcmp(def3, def1)) {
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  4615
          parse_err(SYNERR, "unimplemented: using %s defined as %s => %s => %s",
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  4616
                    start, def1, def2, def3);
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  4617
        }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4618
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4619
      start = strdup(def);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4620
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4621
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4622
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4623
  return start;                   // Pointer to token in filebuf
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4624
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4625
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4626
//------------------------------get_ident_dup----------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4627
// Looks for an identifier in the buffer, and returns a duplicate
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4628
// or NULL if some other token is found instead.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4629
char *ADLParser::get_ident_dup(void) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4630
  char *ident = get_ident();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4631
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4632
  // Duplicate an identifier before returning and restore string.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4633
  if( ident != NULL ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4634
    ident = strdup(ident);  // Copy the string
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4635
    *_ptr   = _curchar;         // and replace Nil with original character
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4636
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4637
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4638
  return ident;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4639
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4640
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4641
//----------------------get_ident_or_literal_constant--------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4642
// Looks for an identifier in the buffer, or a parenthesized expression.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4643
char *ADLParser::get_ident_or_literal_constant(const char* description) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4644
  char* param = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4645
  skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4646
  if (_curchar == '(') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4647
    // Grab a constant expression.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4648
    param = get_paren_expr(description);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4649
    if (param[0] != '(') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4650
      char* buf = (char*) malloc(strlen(param) + 3);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4651
      sprintf(buf, "(%s)", param);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4652
      param = buf;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4653
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4654
    assert(is_literal_constant(param),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4655
           "expr must be recognizable as a constant");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4656
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4657
    param = get_ident();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4658
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4659
  return param;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4660
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4661
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4662
//------------------------------get_rep_var_ident-----------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4663
// Do NOT duplicate,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4664
// Leave nil terminator in buffer
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4665
// Preserve initial '$'(s) in string
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4666
char *ADLParser::get_rep_var_ident(void) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4667
  // Remember starting point
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4668
  char *rep_var = _ptr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4669
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4670
  // Check for replacement variable indicator '$' and pass if present
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4671
  if ( _curchar == '$' ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4672
    next_char();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4673
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4674
  // Check for a subfield indicator, a second '$', and pass if present
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4675
  if ( _curchar == '$' ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4676
    next_char();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4677
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4678
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4679
  // Check for a control indicator, a third '$':
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4680
  if ( _curchar == '$' ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4681
    next_char();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4682
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4683
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4684
  // Check for more than three '$'s in sequence, SYNERR
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4685
  if( _curchar == '$' ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4686
    parse_err(SYNERR, "Replacement variables and field specifiers can not start with '$$$$'");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4687
    next_char();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4688
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4689
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4690
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4691
  // Nil terminate the variable name following the '$'
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4692
  char *rep_var_name = get_ident();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4693
  assert( rep_var_name != NULL,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4694
          "Missing identifier after replacement variable indicator '$'");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4695
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4696
  return rep_var;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4697
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4698
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4699
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4700
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4701
//------------------------------get_rep_var_ident_dup-------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4702
// Return the next replacement variable identifier, skipping first '$'
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4703
// given a pointer into a line of the buffer.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4704
// Null terminates string, still inside the file buffer,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4705
// Returns a pointer to a copy of the string, or NULL on failure
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4706
char *ADLParser::get_rep_var_ident_dup(void) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4707
  if( _curchar != '$' ) return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4708
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4709
  next_char();                // Move past the '$'
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4710
  char *rep_var = _ptr;       // Remember starting point
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4711
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4712
  // Check for a subfield indicator, a second '$':
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4713
  if ( _curchar == '$' ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4714
    next_char();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4715
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4716
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4717
  // Check for a control indicator, a third '$':
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4718
  if ( _curchar == '$' ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4719
    next_char();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4720
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4721
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4722
  // Check for more than three '$'s in sequence, SYNERR
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4723
  if( _curchar == '$' ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4724
    parse_err(SYNERR, "Replacement variables and field specifiers can not start with '$$$$'");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4725
    next_char();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4726
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4727
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4728
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4729
  // Nil terminate the variable name following the '$'
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4730
  char *rep_var_name = get_ident();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4731
  assert( rep_var_name != NULL,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4732
          "Missing identifier after replacement variable indicator '$'");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4733
  rep_var = strdup(rep_var);  // Copy the string
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4734
  *_ptr   = _curchar;         // and replace Nil with original character
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4735
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4736
  return rep_var;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4737
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4738
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4739
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4740
//------------------------------get_unique_ident------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4741
// Looks for an identifier in the buffer, terminates it with a NULL,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4742
// and checks that it is unique
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4743
char *ADLParser::get_unique_ident(FormDict& dict, const char* nameDescription){
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4744
  char* ident = get_ident();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4745
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4746
  if (ident == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4747
    parse_err(SYNERR, "missing %s identifier at %c\n", nameDescription, _curchar);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4748
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4749
  else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4750
    if (dict[ident] != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4751
      parse_err(SYNERR, "duplicate name %s for %s\n", ident, nameDescription);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4752
      ident = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4753
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4754
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4755
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4756
  return ident;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4757
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4758
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4759
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4760
//------------------------------get_int----------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4761
// Looks for a character string integer in the buffer, and turns it into an int
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4762
// invokes a parse_err if the next token is not an integer.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4763
// This routine does not leave the integer null-terminated.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4764
int ADLParser::get_int(void) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4765
  register char c;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4766
  char         *start;            // Pointer to start of token
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4767
  char         *end;              // Pointer to end of token
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4768
  int           result;           // Storage for integer result
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4769
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4770
  if( _curline == NULL )          // Return NULL at EOF.
2129
e810a33b5c67 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 1675
diff changeset
  4771
    return 0;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4772
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4773
  skipws();                       // Skip whitespace before identifier
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4774
  start = end = _ptr;             // Start points at first character
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4775
  c = *end;                       // Grab character to test
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4776
  while ((c >= '0') && (c <= '9')
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4777
         || ((c == '-') && (end == start))) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4778
    end++;                        // Increment end pointer
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4779
    c = *end;                     // Grab character to test
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4780
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4781
  if (start == end) {             // We popped out on the first try
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4782
    parse_err(SYNERR, "integer expected at %c\n", c);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4783
    result = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4784
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4785
  else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4786
    _curchar = c;                 // Save the first character of next token
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4787
    *end = '\0';                  // NULL terminate the string in place
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4788
    result = atoi(start);         // Convert the string to an integer
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4789
    *end = _curchar;              // Restore buffer to original condition
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4790
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4791
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4792
  // Reset _ptr to next char after token
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4793
  _ptr = end;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4794
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4795
  return result;                   // integer
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4796
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4797
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4798
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4799
//------------------------------get_relation_dup------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4800
// Looks for a relational operator in the buffer
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4801
// invokes a parse_err if the next token is not a relation
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4802
// This routine creates a duplicate of the string in the buffer.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4803
char *ADLParser::get_relation_dup(void) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4804
  char         *result = NULL;    // relational operator being returned
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4805
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4806
  if( _curline == NULL )          // Return NULL at EOF.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4807
    return  NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4808
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4809
  skipws();                       // Skip whitespace before relation
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4810
  char *start = _ptr;             // Store start of relational operator
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4811
  char first  = *_ptr;            // the first character
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4812
  if( (first == '=') || (first == '!') || (first == '<') || (first == '>') ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4813
    next_char();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4814
    char second = *_ptr;          // the second character
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4815
    if( (second == '=') ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4816
      next_char();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4817
      char tmp  = *_ptr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4818
      *_ptr = '\0';               // NULL terminate
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4819
      result = strdup(start);     // Duplicate the string
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4820
      *_ptr = tmp;                // restore buffer
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4821
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4822
      parse_err(SYNERR, "relational operator expected at %s\n", _ptr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4823
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4824
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4825
    parse_err(SYNERR, "relational operator expected at %s\n", _ptr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4826
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4827
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4828
  return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4829
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4830
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4831
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4832
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4833
//------------------------------get_oplist-------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4834
// Looks for identifier pairs where first must be the name of an operand, and
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4835
// second must be a name unique in the scope of this instruction.  Stores the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4836
// names with a pointer to the OpClassForm of their type in a local name table.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4837
void ADLParser::get_oplist(NameList &parameters, FormDict &operands) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4838
  OpClassForm *opclass = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4839
  char        *ident   = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4840
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4841
  do {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4842
    next_char();             // skip open paren & comma characters
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4843
    skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4844
    if (_curchar == ')') break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4845
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4846
    // Get operand type, and check it against global name table
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4847
    ident = get_ident();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4848
    if (ident == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4849
      parse_err(SYNERR, "optype identifier expected at %c\n", _curchar);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4850
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4851
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4852
    else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4853
      const Form  *form = _globalNames[ident];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4854
      if( form == NULL ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4855
        parse_err(SYNERR, "undefined operand type %s\n", ident);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4856
        return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4857
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4858
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4859
      // Check for valid operand type
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4860
      OpClassForm *opc  = form->is_opclass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4861
      OperandForm *oper = form->is_operand();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4862
      if((oper == NULL) && (opc == NULL)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4863
        parse_err(SYNERR, "identifier %s not operand type\n", ident);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4864
        return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4865
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4866
      opclass = opc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4867
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4868
    // Debugging Stuff
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4869
    if (_AD._adl_debug > 1) fprintf(stderr, "\tOperand Type: %s\t", ident);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4870
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4871
    // Get name of operand and add it to local name table
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4872
    if( (ident = get_unique_ident(operands, "operand")) == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4873
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4874
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4875
    // Parameter names must not be global names.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4876
    if( _globalNames[ident] != NULL ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4877
         parse_err(SYNERR, "Reuse of global name %s as operand.\n",ident);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4878
         return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4879
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4880
    operands.Insert(ident, opclass);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4881
    parameters.addName(ident);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4882
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4883
    // Debugging Stuff
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4884
    if (_AD._adl_debug > 1) fprintf(stderr, "\tOperand Name: %s\n", ident);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4885
    skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4886
  } while(_curchar == ',');
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4887
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4888
  if (_curchar != ')') parse_err(SYNERR, "missing ')'\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4889
  else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4890
    next_char();  // set current character position past the close paren
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4891
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4892
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4893
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4894
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4895
//------------------------------get_effectlist---------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4896
// Looks for identifier pairs where first must be the name of a pre-defined,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4897
// effect, and the second must be the name of an operand defined in the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4898
// operand list of this instruction.  Stores the names with a pointer to the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4899
// effect form in a local effects table.
11196
a310a659c580 7077312: Provide a CALL effect for instruct declaration in the ad file
roland
parents: 11190
diff changeset
  4900
void ADLParser::get_effectlist(FormDict &effects, FormDict &operands, bool& has_call) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4901
  OperandForm *opForm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4902
  Effect      *eForm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4903
  char        *ident;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4904
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4905
  do {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4906
    next_char();             // skip open paren & comma characters
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4907
    skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4908
    if (_curchar == ')') break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4909
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4910
    // Get effect type, and check it against global name table
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4911
    ident = get_ident();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4912
    if (ident == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4913
      parse_err(SYNERR, "effect type identifier expected at %c\n", _curchar);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4914
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4915
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4916
    else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4917
      // Check for valid effect type
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4918
      const Form *form = _globalNames[ident];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4919
      if( form == NULL ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4920
        parse_err(SYNERR, "undefined effect type %s\n", ident);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4921
        return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4922
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4923
      else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4924
        if( (eForm = form->is_effect()) == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4925
          parse_err(SYNERR, "identifier %s not effect type\n", ident);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4926
          return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4927
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4928
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4929
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4930
      // Debugging Stuff
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4931
    if (_AD._adl_debug > 1) fprintf(stderr, "\tEffect Type: %s\t", ident);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4932
    skipws();
11196
a310a659c580 7077312: Provide a CALL effect for instruct declaration in the ad file
roland
parents: 11190
diff changeset
  4933
    if (eForm->is(Component::CALL)) {
a310a659c580 7077312: Provide a CALL effect for instruct declaration in the ad file
roland
parents: 11190
diff changeset
  4934
      if (_AD._adl_debug > 1) fprintf(stderr, "\n");
a310a659c580 7077312: Provide a CALL effect for instruct declaration in the ad file
roland
parents: 11190
diff changeset
  4935
      has_call = true;
a310a659c580 7077312: Provide a CALL effect for instruct declaration in the ad file
roland
parents: 11190
diff changeset
  4936
    } else {
a310a659c580 7077312: Provide a CALL effect for instruct declaration in the ad file
roland
parents: 11190
diff changeset
  4937
      // Get name of operand and check that it is in the local name table
a310a659c580 7077312: Provide a CALL effect for instruct declaration in the ad file
roland
parents: 11190
diff changeset
  4938
      if( (ident = get_unique_ident(effects, "effect")) == NULL) {
a310a659c580 7077312: Provide a CALL effect for instruct declaration in the ad file
roland
parents: 11190
diff changeset
  4939
        parse_err(SYNERR, "missing operand identifier in effect list\n");
a310a659c580 7077312: Provide a CALL effect for instruct declaration in the ad file
roland
parents: 11190
diff changeset
  4940
        return;
a310a659c580 7077312: Provide a CALL effect for instruct declaration in the ad file
roland
parents: 11190
diff changeset
  4941
      }
a310a659c580 7077312: Provide a CALL effect for instruct declaration in the ad file
roland
parents: 11190
diff changeset
  4942
      const Form *form = operands[ident];
a310a659c580 7077312: Provide a CALL effect for instruct declaration in the ad file
roland
parents: 11190
diff changeset
  4943
      opForm = form ? form->is_operand() : NULL;
a310a659c580 7077312: Provide a CALL effect for instruct declaration in the ad file
roland
parents: 11190
diff changeset
  4944
      if( opForm == NULL ) {
a310a659c580 7077312: Provide a CALL effect for instruct declaration in the ad file
roland
parents: 11190
diff changeset
  4945
        if( form && form->is_opclass() ) {
a310a659c580 7077312: Provide a CALL effect for instruct declaration in the ad file
roland
parents: 11190
diff changeset
  4946
          const char* cname = form->is_opclass()->_ident;
a310a659c580 7077312: Provide a CALL effect for instruct declaration in the ad file
roland
parents: 11190
diff changeset
  4947
          parse_err(SYNERR, "operand classes are illegal in effect lists (found %s %s)\n", cname, ident);
a310a659c580 7077312: Provide a CALL effect for instruct declaration in the ad file
roland
parents: 11190
diff changeset
  4948
        } else {
a310a659c580 7077312: Provide a CALL effect for instruct declaration in the ad file
roland
parents: 11190
diff changeset
  4949
          parse_err(SYNERR, "undefined operand %s in effect list\n", ident);
a310a659c580 7077312: Provide a CALL effect for instruct declaration in the ad file
roland
parents: 11190
diff changeset
  4950
        }
a310a659c580 7077312: Provide a CALL effect for instruct declaration in the ad file
roland
parents: 11190
diff changeset
  4951
        return;
a310a659c580 7077312: Provide a CALL effect for instruct declaration in the ad file
roland
parents: 11190
diff changeset
  4952
      }
a310a659c580 7077312: Provide a CALL effect for instruct declaration in the ad file
roland
parents: 11190
diff changeset
  4953
      // Add the pair to the effects table
a310a659c580 7077312: Provide a CALL effect for instruct declaration in the ad file
roland
parents: 11190
diff changeset
  4954
      effects.Insert(ident, eForm);
a310a659c580 7077312: Provide a CALL effect for instruct declaration in the ad file
roland
parents: 11190
diff changeset
  4955
      // Debugging Stuff
a310a659c580 7077312: Provide a CALL effect for instruct declaration in the ad file
roland
parents: 11190
diff changeset
  4956
      if (_AD._adl_debug > 1) fprintf(stderr, "\tOperand Name: %s\n", ident);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4957
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4958
    skipws();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4959
  } while(_curchar == ',');
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4960
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4961
  if (_curchar != ')') parse_err(SYNERR, "missing ')'\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4962
  else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4963
    next_char();  // set current character position past the close paren
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4964
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4965
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4966
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4967
1662
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  4968
//-------------------------------preproc_line----------------------------------
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  4969
// A "#line" keyword has been seen, so parse the rest of the line.
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  4970
void ADLParser::preproc_line(void) {
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  4971
  int line = get_int();
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  4972
  skipws_no_preproc();
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  4973
  const char* file = NULL;
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  4974
  if (_curchar == '"') {
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  4975
    next_char();              // Move past the initial '"'
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  4976
    file = _ptr;
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  4977
    while (true) {
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  4978
      if (_curchar == '\n') {
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  4979
        parse_err(SYNERR, "missing '\"' at end of #line directive");
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  4980
        return;
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  4981
      }
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  4982
      if (_curchar == '"') {
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  4983
        *_ptr  = '\0';          // Terminate the string
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  4984
        next_char();
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  4985
        skipws_no_preproc();
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  4986
        break;
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  4987
      }
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  4988
      next_char();
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  4989
    }
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  4990
  }
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  4991
  ensure_end_of_line();
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  4992
  if (file != NULL)
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  4993
    _AD._ADL_file._name = file;
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  4994
  _buf.set_linenum(line);
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  4995
}
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  4996
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4997
//------------------------------preproc_define---------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4998
// A "#define" keyword has been seen, so parse the rest of the line.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4999
void ADLParser::preproc_define(void) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5000
  char* flag = get_ident_no_preproc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5001
  skipws_no_preproc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5002
  // only #define x y is supported for now
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5003
  char* def = get_ident_no_preproc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5004
  _AD.set_preproc_def(flag, def);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5005
  skipws_no_preproc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5006
  if (_curchar != '\n') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5007
    parse_err(SYNERR, "non-identifier in preprocessor definition\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5008
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5009
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5010
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5011
//------------------------------preproc_undef----------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5012
// An "#undef" keyword has been seen, so parse the rest of the line.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5013
void ADLParser::preproc_undef(void) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5014
  char* flag = get_ident_no_preproc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5015
  skipws_no_preproc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5016
  ensure_end_of_line();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5017
  _AD.set_preproc_def(flag, NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5018
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5019
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5020
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5021
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5022
//------------------------------parse_err--------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5023
// Issue a parser error message, and skip to the end of the current line
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5024
void ADLParser::parse_err(int flag, const char *fmt, ...) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5025
  va_list args;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5026
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5027
  va_start(args, fmt);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5028
  if (flag == 1)
1495
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  5029
    _AD._syntax_errs += _AD.emit_msg(0, flag, linenum(), fmt, args);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5030
  else if (flag == 2)
1495
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  5031
    _AD._semantic_errs += _AD.emit_msg(0, flag, linenum(), fmt, args);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5032
  else
1495
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  5033
    _AD._warnings += _AD.emit_msg(0, flag, linenum(), fmt, args);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5034
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5035
  int error_char = _curchar;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5036
  char* error_ptr = _ptr+1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5037
  for(;*_ptr != '\n'; _ptr++) ; // Skip to the end of the current line
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5038
  _curchar = '\n';
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5039
  va_end(args);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5040
  _AD._no_output = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5041
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5042
  if (flag == 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5043
    char* error_tail = strchr(error_ptr, '\n');
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5044
    char tem = *error_ptr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5045
    error_ptr[-1] = '\0';
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5046
    char* error_head = error_ptr-1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5047
    while (error_head > _curline && *error_head)  --error_head;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5048
    if (error_tail)  *error_tail = '\0';
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5049
    fprintf(stderr, "Error Context:  %s>>>%c<<<%s\n",
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5050
            error_head, error_char, error_ptr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5051
    if (error_tail)  *error_tail = '\n';
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5052
    error_ptr[-1] = tem;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5053
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5054
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5055
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5056
//---------------------------ensure_start_of_line------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5057
// A preprocessor directive has been encountered.  Be sure it has fallen at
2131
98f9cef66a34 6810672: Comment typos
twisti
parents: 2129
diff changeset
  5058
// the beginning of a line, or else report an error.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5059
void ADLParser::ensure_start_of_line(void) {
1662
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  5060
  if (_curchar == '\n') { next_line(); return; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5061
  assert( _ptr >= _curline && _ptr < _curline+strlen(_curline),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5062
          "Must be able to find which line we are in" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5063
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5064
  for (char *s = _curline; s < _ptr; s++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5065
    if (*s > ' ') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5066
      parse_err(SYNERR, "'%c' must be at beginning of line\n", _curchar);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5067
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5068
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5069
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5070
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5071
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5072
//---------------------------ensure_end_of_line--------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5073
// A preprocessor directive has been parsed.  Be sure there is no trailing
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5074
// garbage at the end of this line.  Set the scan point to the beginning of
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5075
// the next line.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5076
void ADLParser::ensure_end_of_line(void) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5077
  skipws_no_preproc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5078
  if (_curchar != '\n' && _curchar != '\0') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5079
    parse_err(SYNERR, "garbage char '%c' at end of line\n", _curchar);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5080
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5081
    next_char_or_line();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5082
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5083
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5084
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5085
//---------------------------handle_preproc------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5086
// The '#' character introducing a preprocessor directive has been found.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5087
// Parse the whole directive name (e.g., #define, #endif) and take appropriate
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5088
// action.  If we are in an "untaken" span of text, simply keep track of
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5089
// #ifdef nesting structure, so we can find out when to start taking text
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5090
// again.  (In this state, we "sort of support" C's #if directives, enough
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5091
// to disregard their associated #else and #endif lines.)  If we are in a
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5092
// "taken" span of text, there are two cases:  "#define" and "#undef"
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5093
// directives are preserved and passed up to the caller, which eventually
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5094
// passes control to the top-level parser loop, which handles #define and
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5095
// #undef directly.  (This prevents these directives from occurring in
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5096
// arbitrary positions in the AD file--we require better structure than C.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5097
// In the other case, and #ifdef, #ifndef, #else, or #endif is silently
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5098
// processed as whitespace, with the "taken" state of the text correctly
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5099
// updated.  This routine returns "false" exactly in the case of a "taken"
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5100
// #define or #undef, which tells the caller that a preprocessor token
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5101
// has appeared which must be handled explicitly by the parse loop.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5102
bool ADLParser::handle_preproc_token() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5103
  assert(*_ptr == '#', "must be at start of preproc");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5104
  ensure_start_of_line();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5105
  next_char();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5106
  skipws_no_preproc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5107
  char* start_ident = _ptr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5108
  char* ident = (_curchar == '\n') ? NULL : get_ident_no_preproc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5109
  if (ident == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5110
    parse_err(SYNERR, "expected preprocessor command, got end of line\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5111
  } else if (!strcmp(ident, "ifdef") ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5112
             !strcmp(ident, "ifndef")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5113
    char* flag = get_ident_no_preproc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5114
    ensure_end_of_line();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5115
    // Test the identifier only if we are already in taken code:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5116
    bool flag_def  = preproc_taken() && (_AD.get_preproc_def(flag) != NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5117
    bool now_taken = !strcmp(ident, "ifdef") ? flag_def : !flag_def;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5118
    begin_if_def(now_taken);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5119
  } else if (!strcmp(ident, "if")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5120
    if (preproc_taken())
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5121
      parse_err(SYNERR, "unimplemented: #%s %s", ident, _ptr+1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5122
    next_line();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5123
    // Intelligently skip this nested C preprocessor directive:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5124
    begin_if_def(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5125
  } else if (!strcmp(ident, "else")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5126
    ensure_end_of_line();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5127
    invert_if_def();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5128
  } else if (!strcmp(ident, "endif")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5129
    ensure_end_of_line();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5130
    end_if_def();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5131
  } else if (preproc_taken()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5132
    // pass this token up to the main parser as "#define" or "#undef"
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5133
    _ptr = start_ident;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5134
    _curchar = *--_ptr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5135
    if( _curchar != '#' ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5136
      parse_err(SYNERR, "no space allowed after # in #define or #undef");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5137
      assert(_curchar == '#', "no space allowed after # in #define or #undef");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5138
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5139
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5140
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5141
  return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5142
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5143
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5144
//---------------------------skipws_common-------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5145
// Skip whitespace, including comments and newlines, while keeping an accurate
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5146
// line count.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5147
// Maybe handle certain preprocessor constructs: #ifdef, #ifndef, #else, #endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5148
void ADLParser::skipws_common(bool do_preproc) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5149
  char *start = _ptr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5150
  char *next = _ptr + 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5151
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5152
  if (*_ptr == '\0') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5153
    // Check for string terminator
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5154
    if (_curchar > ' ')  return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5155
    if (_curchar == '\n') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5156
      if (!do_preproc)  return;            // let caller handle the newline
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5157
      next_line();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5158
      _ptr = _curline; next = _ptr + 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5159
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5160
    else if (_curchar == '#' ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5161
        (_curchar == '/' && (*next == '/' || *next == '*'))) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5162
      parse_err(SYNERR, "unimplemented: comment token in a funny place");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5163
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5164
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5165
  while(_curline != NULL) {                // Check for end of file
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5166
    if (*_ptr == '\n') {                   // keep proper track of new lines
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5167
      if (!do_preproc)  break;             // let caller handle the newline
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5168
      next_line();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5169
      _ptr = _curline; next = _ptr + 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5170
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5171
    else if ((*_ptr == '/') && (*next == '/'))      // C++ comment
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5172
      do { _ptr++; next++; } while(*_ptr != '\n');  // So go to end of line
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5173
    else if ((*_ptr == '/') && (*next == '*')) {    // C comment
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5174
      _ptr++; next++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5175
      do {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5176
        _ptr++; next++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5177
        if (*_ptr == '\n') {               // keep proper track of new lines
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5178
          next_line();                     // skip newlines within comments
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5179
          if (_curline == NULL) {          // check for end of file
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5180
            parse_err(SYNERR, "end-of-file detected inside comment\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5181
            break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5182
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5183
          _ptr = _curline; next = _ptr + 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5184
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5185
      } while(!((*_ptr == '*') && (*next == '/'))); // Go to end of comment
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5186
      _ptr = ++next; next++;               // increment _ptr past comment end
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5187
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5188
    else if (do_preproc && *_ptr == '#') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5189
      // Note that this calls skipws_common(false) recursively!
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5190
      bool preproc_handled = handle_preproc_token();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5191
      if (!preproc_handled) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5192
        if (preproc_taken()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5193
          return;  // short circuit
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5194
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5195
        ++_ptr;    // skip the preprocessor character
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5196
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5197
      next = _ptr+1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5198
    } else if(*_ptr > ' ' && !(do_preproc && !preproc_taken())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5199
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5200
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5201
    else if (*_ptr == '"' || *_ptr == '\'') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5202
      assert(do_preproc, "only skip strings if doing preproc");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5203
      // skip untaken quoted string
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5204
      int qchar = *_ptr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5205
      while (true) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5206
        ++_ptr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5207
        if (*_ptr == qchar) { ++_ptr; break; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5208
        if (*_ptr == '\\')  ++_ptr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5209
        if (*_ptr == '\n' || *_ptr == '\0') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5210
          parse_err(SYNERR, "newline in string");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5211
          break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5212
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5213
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5214
      next = _ptr + 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5215
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5216
    else { ++_ptr; ++next; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5217
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5218
  if( _curline != NULL )            // at end of file _curchar isn't valid
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5219
    _curchar = *_ptr;               // reset _curchar to maintain invariant
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5220
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5221
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5222
//---------------------------cur_char-----------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5223
char ADLParser::cur_char() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5224
  return (_curchar);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5225
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5226
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5227
//---------------------------next_char-----------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5228
void ADLParser::next_char() {
1662
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  5229
  if (_curchar == '\n')  parse_err(WARN, "must call next_line!");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5230
  _curchar = *++_ptr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5231
  // if ( _curchar == '\n' ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5232
  //   next_line();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5233
  // }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5234
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5235
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5236
//---------------------------next_char_or_line---------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5237
void ADLParser::next_char_or_line() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5238
  if ( _curchar != '\n' ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5239
    _curchar = *++_ptr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5240
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5241
    next_line();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5242
    _ptr = _curline;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5243
    _curchar = *_ptr;  // maintain invariant
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5244
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5245
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5246
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5247
//---------------------------next_line-----------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5248
void ADLParser::next_line() {
1495
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 1
diff changeset
  5249
  _curline = _buf.get_line();
1662
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  5250
  _curchar = ' ';
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  5251
}
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  5252
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  5253
//------------------------get_line_string--------------------------------------
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  5254
// Prepended location descriptor, for debugging.
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  5255
// Must return a malloced string (that can be freed if desired).
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  5256
char* ADLParser::get_line_string(int linenum) {
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  5257
  const char* file = _AD._ADL_file._name;
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  5258
  int         line = linenum ? linenum : this->linenum();
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  5259
  char* location = (char *)malloc(strlen(file) + 100);
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  5260
  sprintf(location, "\n#line %d \"%s\"\n", line, file);
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  5261
  return location;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5262
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5263
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5264
//-------------------------is_literal_constant---------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5265
bool ADLParser::is_literal_constant(const char *param) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5266
  if (param[0] == 0)     return false;  // null string
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5267
  if (param[0] == '(')   return true;   // parenthesized expression
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5268
  if (param[0] == '0' && (param[1] == 'x' || param[1] == 'X')) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5269
    // Make sure it's a hex constant.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5270
    int i = 2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5271
    do {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5272
      if( !ADLParser::is_hex_digit(*(param+i)) )  return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5273
      ++i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5274
    } while( *(param+i) != 0 );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5275
    return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5276
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5277
  return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5278
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5279
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5280
//---------------------------is_hex_digit--------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5281
bool ADLParser::is_hex_digit(char digit) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5282
  return ((digit >= '0') && (digit <= '9'))
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5283
       ||((digit >= 'a') && (digit <= 'f'))
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5284
       ||((digit >= 'A') && (digit <= 'F'));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5285
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5286
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5287
//---------------------------is_int_token--------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5288
bool ADLParser::is_int_token(const char* token, int& intval) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5289
  const char* cp = token;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5290
  while (*cp != '\0' && *cp <= ' ')  cp++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5291
  if (*cp == '-')  cp++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5292
  int ndigit = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5293
  while (*cp >= '0' && *cp <= '9')  { cp++; ndigit++; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5294
  while (*cp != '\0' && *cp <= ' ')  cp++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5295
  if (ndigit == 0 || *cp != '\0') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5296
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5297
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5298
  intval = atoi(token);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5299
  return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5300
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5301
1662
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  5302
static const char* skip_expr_ws(const char* str) {
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  5303
  const char * cp = str;
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  5304
  while (cp[0]) {
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  5305
    if (cp[0] <= ' ') {
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  5306
      ++cp;
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  5307
    } else if (cp[0] == '#') {
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  5308
      ++cp;
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  5309
      while (cp[0] == ' ')  ++cp;
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  5310
      assert(0 == strncmp(cp, "line", 4), "must be a #line directive");
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  5311
      const char* eol = strchr(cp, '\n');
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  5312
      assert(eol != NULL, "must find end of line");
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  5313
      if (eol == NULL)  eol = cp + strlen(cp);
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  5314
      cp = eol;
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  5315
    } else {
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  5316
      break;
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  5317
    }
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  5318
  }
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  5319
  return cp;
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  5320
}
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  5321
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  5322
//-----------------------equivalent_expressions--------------------------------
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  5323
bool ADLParser::equivalent_expressions(const char* str1, const char* str2) {
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  5324
  if (str1 == str2)
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  5325
    return true;
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  5326
  else if (str1 == NULL || str2 == NULL)
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  5327
    return false;
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  5328
  const char* cp1 = str1;
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  5329
  const char* cp2 = str2;
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  5330
  char in_quote = '\0';
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  5331
  while (cp1[0] && cp2[0]) {
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  5332
    if (!in_quote) {
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  5333
      // skip spaces and/or cpp directives
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  5334
      const char* cp1a = skip_expr_ws(cp1);
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  5335
      const char* cp2a = skip_expr_ws(cp2);
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  5336
      if (cp1a > cp1 && cp2a > cp2) {
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  5337
        cp1 = cp1a; cp2 = cp2a;
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  5338
        continue;
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  5339
      }
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  5340
      if (cp1a > cp1 || cp2a > cp2)  break; // fail
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  5341
    }
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  5342
    // match one non-space char
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  5343
    if (cp1[0] != cp2[0])  break; // fail
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  5344
    char ch = cp1[0];
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  5345
    cp1++; cp2++;
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  5346
    // watch for quotes
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  5347
    if (in_quote && ch == '\\') {
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  5348
      if (cp1[0] != cp2[0])  break; // fail
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  5349
      if (!cp1[0])  break;
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  5350
      cp1++; cp2++;
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  5351
    }
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  5352
    if (in_quote && ch == in_quote) {
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  5353
      in_quote = '\0';
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  5354
    } else if (!in_quote && (ch == '"' || ch == '\'')) {
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  5355
      in_quote = ch;
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  5356
    }
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  5357
  }
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  5358
  return (!cp1[0] && !cp2[0]);
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  5359
}
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  5360
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
  5361
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5362
//-------------------------------trim------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5363
void ADLParser::trim(char* &token) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5364
  while (*token <= ' ')  token++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5365
  char* end = token + strlen(token);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5366
  while (end > token && *(end-1) <= ' ')  --end;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5367
  *end = '\0';
489c9b5090e2 Initial load
duke
parents:
diff changeset
  5368
}