annotate src/share/vm/adlc/adlparse.cpp @ 470:ad8c8ca4ab0f

6785258: Update copyright year Summary: Update copyright for files that have been modified starting July 2008 to Dec 2008 Reviewed-by: katleman, ohair, tbell
author xdono
date Mon, 15 Dec 2008 16:55:11 -0800
parents 4d9884b01ba6
children 569b3b226089
rev   line source
duke@0 1 /*
xdono@470 2 * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved.
duke@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@0 4 *
duke@0 5 * This code is free software; you can redistribute it and/or modify it
duke@0 6 * under the terms of the GNU General Public License version 2 only, as
duke@0 7 * published by the Free Software Foundation.
duke@0 8 *
duke@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@0 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@0 13 * accompanied this code).
duke@0 14 *
duke@0 15 * You should have received a copy of the GNU General Public License version
duke@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@0 18 *
duke@0 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@0 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@0 21 * have any questions.
duke@0 22 *
duke@0 23 */
duke@0 24
duke@0 25 // ADLPARSE.CPP - Architecture Description Language Parser
duke@0 26 // Authors: Chris Vick and Mike Paleczny
duke@0 27 #include "adlc.hpp"
duke@0 28
duke@0 29 //----------------------------ADLParser----------------------------------------
duke@0 30 // Create a new ADL parser
duke@0 31 ADLParser::ADLParser(FileBuff& buffer, ArchDesc& archDesc)
duke@0 32 : _buf(buffer), _AD(archDesc),
duke@0 33 _globalNames(archDesc.globalNames()) {
duke@0 34 _AD._syntax_errs = _AD._semantic_errs = 0; // No errors so far this file
duke@0 35 _AD._warnings = 0; // No warnings either
duke@0 36 _curline = _ptr = NULL; // No pointers into buffer yet
duke@0 37
duke@0 38 _preproc_depth = 0;
duke@0 39 _preproc_not_taken = 0;
duke@0 40
duke@0 41 // Delimit command-line definitions from in-file definitions:
duke@0 42 _AD._preproc_list.add_signal();
duke@0 43 }
duke@0 44
duke@0 45 //------------------------------~ADLParser-------------------------------------
duke@0 46 // Delete an ADL parser.
duke@0 47 ADLParser::~ADLParser() {
duke@0 48 if (!_AD._quiet_mode)
duke@0 49 fprintf(stderr,"---------------------------- Errors and Warnings ----------------------------\n");
duke@0 50 #ifndef ASSERT
duke@0 51 fprintf(stderr, "**************************************************************\n");
duke@0 52 fprintf(stderr, "***** WARNING: ASSERT is undefined, assertions disabled. *****\n");
duke@0 53 fprintf(stderr, "**************************************************************\n");
duke@0 54 #endif
duke@0 55 if( _AD._syntax_errs + _AD._semantic_errs + _AD._warnings == 0 ) {
duke@0 56 if (!_AD._quiet_mode)
duke@0 57 fprintf(stderr,"No errors or warnings to report from phase-1 parse.\n" );
duke@0 58 }
duke@0 59 else {
duke@0 60 if( _AD._syntax_errs ) { // Any syntax errors?
duke@0 61 fprintf(stderr,"%s: Found %d syntax error", _buf._fp->_name, _AD._syntax_errs);
duke@0 62 if( _AD._syntax_errs > 1 ) fprintf(stderr,"s.\n\n");
duke@0 63 else fprintf(stderr,".\n\n");
duke@0 64 }
duke@0 65 if( _AD._semantic_errs ) { // Any semantic errors?
duke@0 66 fprintf(stderr,"%s: Found %d semantic error", _buf._fp->_name, _AD._semantic_errs);
duke@0 67 if( _AD._semantic_errs > 1 ) fprintf(stderr,"s.\n\n");
duke@0 68 else fprintf(stderr,".\n\n");
duke@0 69 }
duke@0 70 if( _AD._warnings ) { // Any warnings?
duke@0 71 fprintf(stderr,"%s: Found %d warning", _buf._fp->_name, _AD._warnings);
duke@0 72 if( _AD._warnings > 1 ) fprintf(stderr,"s.\n\n");
duke@0 73 else fprintf(stderr,".\n\n");
duke@0 74 }
duke@0 75 }
duke@0 76 if (!_AD._quiet_mode)
duke@0 77 fprintf(stderr,"-----------------------------------------------------------------------------\n");
never@415 78 _AD._TotalLines += linenum()-1; // -1 for overshoot in "nextline" routine
duke@0 79
duke@0 80 // Write out information we have stored
duke@0 81 // // UNIXism == fsync(stderr);
duke@0 82 }
duke@0 83
duke@0 84 //------------------------------parse------------------------------------------
duke@0 85 // Each top-level keyword should appear as the first non-whitespace on a line.
duke@0 86 //
duke@0 87 void ADLParser::parse() {
duke@0 88 char *ident;
duke@0 89
duke@0 90 // Iterate over the lines in the file buffer parsing Level 1 objects
duke@0 91 for( next_line(); _curline != NULL; next_line()) {
duke@0 92 _ptr = _curline; // Reset ptr to start of new line
duke@0 93 skipws(); // Skip any leading whitespace
duke@0 94 ident = get_ident(); // Get first token
duke@0 95 if (ident == NULL) { // Empty line
duke@0 96 continue; // Get the next line
duke@0 97 }
duke@0 98 if (!strcmp(ident, "instruct")) instr_parse();
duke@0 99 else if (!strcmp(ident, "operand")) oper_parse();
duke@0 100 else if (!strcmp(ident, "opclass")) opclass_parse();
duke@0 101 else if (!strcmp(ident, "ins_attrib")) ins_attr_parse();
duke@0 102 else if (!strcmp(ident, "op_attrib")) op_attr_parse();
duke@0 103 else if (!strcmp(ident, "source")) source_parse();
duke@0 104 else if (!strcmp(ident, "source_hpp")) source_hpp_parse();
duke@0 105 else if (!strcmp(ident, "register")) reg_parse();
duke@0 106 else if (!strcmp(ident, "frame")) frame_parse();
duke@0 107 else if (!strcmp(ident, "encode")) encode_parse();
duke@0 108 else if (!strcmp(ident, "pipeline")) pipe_parse();
duke@0 109 else if (!strcmp(ident, "definitions")) definitions_parse();
duke@0 110 else if (!strcmp(ident, "peephole")) peep_parse();
duke@0 111 else if (!strcmp(ident, "#define")) preproc_define();
duke@0 112 else if (!strcmp(ident, "#undef")) preproc_undef();
duke@0 113 else {
duke@0 114 parse_err(SYNERR, "expected one of - instruct, operand, ins_attrib, op_attrib, source, register, pipeline, encode\n Found %s",ident);
duke@0 115 }
duke@0 116 }
duke@0 117
duke@0 118 // Done with parsing, check consistency.
duke@0 119
duke@0 120 if (_preproc_depth != 0) {
duke@0 121 parse_err(SYNERR, "End of file inside #ifdef");
duke@0 122 }
duke@0 123
duke@0 124 // AttributeForms ins_cost and op_cost must be defined for default behaviour
duke@0 125 if (_globalNames[AttributeForm::_ins_cost] == NULL) {
duke@0 126 parse_err(SEMERR, "Did not declare 'ins_cost' attribute");
duke@0 127 }
duke@0 128 if (_globalNames[AttributeForm::_ins_pc_relative] == NULL) {
duke@0 129 parse_err(SEMERR, "Did not declare 'ins_pc_relative' attribute");
duke@0 130 }
duke@0 131 if (_globalNames[AttributeForm::_op_cost] == NULL) {
duke@0 132 parse_err(SEMERR, "Did not declare 'op_cost' attribute");
duke@0 133 }
duke@0 134 }
duke@0 135
duke@0 136 // ******************** Private Level 1 Parse Functions ********************
duke@0 137 //------------------------------instr_parse------------------------------------
duke@0 138 // Parse the contents of an instruction definition, build the InstructForm to
duke@0 139 // represent that instruction, and add it to the InstructForm list.
duke@0 140 void ADLParser::instr_parse(void) {
duke@0 141 char *ident;
duke@0 142 InstructForm *instr;
duke@0 143 MatchRule *rule;
duke@0 144 int match_rules_cnt = 0;
duke@0 145
duke@0 146 // First get the name of the instruction
duke@0 147 if( (ident = get_unique_ident(_globalNames,"instruction")) == NULL )
duke@0 148 return;
duke@0 149 instr = new InstructForm(ident); // Create new instruction form
never@415 150 instr->_linenum = linenum();
duke@0 151 _globalNames.Insert(ident, instr); // Add name to the name table
duke@0 152 // Debugging Stuff
duke@0 153 if (_AD._adl_debug > 1)
duke@0 154 fprintf(stderr,"Parsing Instruction Form %s\n", ident);
duke@0 155
duke@0 156 // Then get the operands
duke@0 157 skipws();
duke@0 158 if (_curchar != '(') {
duke@0 159 parse_err(SYNERR, "missing '(' in instruct definition\n");
duke@0 160 }
duke@0 161 // Parse the operand list
duke@0 162 else get_oplist(instr->_parameters, instr->_localNames);
duke@0 163 skipws(); // Skip leading whitespace
duke@0 164 // Check for block delimiter
duke@0 165 if ( (_curchar != '%')
duke@0 166 || ( next_char(), (_curchar != '{')) ) {
duke@0 167 parse_err(SYNERR, "missing '%{' in instruction definition\n");
duke@0 168 return;
duke@0 169 }
duke@0 170 next_char(); // Maintain the invariant
duke@0 171 do {
duke@0 172 ident = get_ident(); // Grab next identifier
duke@0 173 if (ident == NULL) {
duke@0 174 parse_err(SYNERR, "keyword identifier expected at %c\n", _curchar);
duke@0 175 continue;
duke@0 176 }
duke@0 177 if (!strcmp(ident, "predicate")) instr->_predicate = pred_parse();
duke@0 178 else if (!strcmp(ident, "match")) {
duke@0 179 // Allow one instruction have several match rules.
duke@0 180 rule = instr->_matrule;
duke@0 181 if (rule == NULL) {
duke@0 182 // This is first match rule encountered
duke@0 183 rule = match_parse(instr->_localNames);
duke@0 184 if (rule) {
duke@0 185 instr->_matrule = rule;
duke@0 186 // Special case the treatment of Control instructions.
duke@0 187 if( instr->is_ideal_control() ) {
duke@0 188 // Control instructions return a special result, 'Universe'
duke@0 189 rule->_result = "Universe";
duke@0 190 }
duke@0 191 // Check for commutative operations with tree operands.
duke@0 192 matchrule_clone_and_swap(rule, instr->_ident, match_rules_cnt);
duke@0 193 }
duke@0 194 } else {
duke@0 195 // Find the end of the match rule list
duke@0 196 while (rule->_next != NULL)
duke@0 197 rule = rule->_next;
duke@0 198 // Add the new match rule to the list
duke@0 199 rule->_next = match_parse(instr->_localNames);
duke@0 200 if (rule->_next) {
duke@0 201 rule = rule->_next;
duke@0 202 if( instr->is_ideal_control() ) {
duke@0 203 parse_err(SYNERR, "unique match rule expected for %s\n", rule->_name);
duke@0 204 return;
duke@0 205 }
duke@0 206 assert(match_rules_cnt < 100," too many match rule clones");
duke@0 207 char* buf = (char*) malloc(strlen(instr->_ident) + 4);
duke@0 208 sprintf(buf, "%s_%d", instr->_ident, match_rules_cnt++);
duke@0 209 rule->_result = buf;
duke@0 210 // Check for commutative operations with tree operands.
duke@0 211 matchrule_clone_and_swap(rule, instr->_ident, match_rules_cnt);
duke@0 212 }
duke@0 213 }
duke@0 214 }
duke@0 215 else if (!strcmp(ident, "encode")) {
duke@0 216 parse_err(SYNERR, "Instructions specify ins_encode, not encode\n");
duke@0 217 }
duke@0 218 else if (!strcmp(ident, "ins_encode"))
duke@0 219 instr->_insencode = ins_encode_parse(*instr);
duke@0 220 else if (!strcmp(ident, "opcode")) instr->_opcode = opcode_parse(instr);
duke@0 221 else if (!strcmp(ident, "size")) instr->_size = size_parse(instr);
duke@0 222 else if (!strcmp(ident, "effect")) effect_parse(instr);
duke@0 223 else if (!strcmp(ident, "expand")) instr->_exprule = expand_parse(instr);
duke@0 224 else if (!strcmp(ident, "rewrite")) instr->_rewrule = rewrite_parse();
duke@0 225 else if (!strcmp(ident, "constraint")) {
duke@0 226 parse_err(SYNERR, "Instructions do not specify a constraint\n");
duke@0 227 }
duke@0 228 else if (!strcmp(ident, "construct")) {
duke@0 229 parse_err(SYNERR, "Instructions do not specify a construct\n");
duke@0 230 }
duke@0 231 else if (!strcmp(ident, "format")) instr->_format = format_parse();
duke@0 232 else if (!strcmp(ident, "interface")) {
duke@0 233 parse_err(SYNERR, "Instructions do not specify an interface\n");
duke@0 234 }
duke@0 235 else if (!strcmp(ident, "ins_pipe")) ins_pipe_parse(*instr);
duke@0 236 else { // Done with staticly defined parts of instruction definition
duke@0 237 // Check identifier to see if it is the name of an attribute
duke@0 238 const Form *form = _globalNames[ident];
duke@0 239 AttributeForm *attr = form ? form->is_attribute() : NULL;
duke@0 240 if( attr && (attr->_atype == INS_ATTR) ) {
duke@0 241 // Insert the new attribute into the linked list.
duke@0 242 Attribute *temp = attr_parse(ident);
duke@0 243 temp->_next = instr->_attribs;
duke@0 244 instr->_attribs = temp;
duke@0 245 } else {
duke@0 246 parse_err(SYNERR, "expected one of:\n predicate, match, encode, or the name of an instruction attribute at %s\n", ident);
duke@0 247 }
duke@0 248 }
duke@0 249 skipws();
duke@0 250 } while(_curchar != '%');
duke@0 251 next_char();
duke@0 252 if (_curchar != '}') {
duke@0 253 parse_err(SYNERR, "missing '%}' in instruction definition\n");
duke@0 254 return;
duke@0 255 }
duke@0 256 // Check for "Set" form of chain rule
duke@0 257 adjust_set_rule(instr);
duke@0 258 if (_AD._pipeline ) {
duke@0 259 if( instr->expands() ) {
duke@0 260 if( instr->_ins_pipe )
duke@0 261 parse_err(WARN, "ins_pipe and expand rule both specified for instruction \"%s\"; ins_pipe will be unused\n", instr->_ident);
duke@0 262 } else {
duke@0 263 if( !instr->_ins_pipe )
duke@0 264 parse_err(WARN, "No ins_pipe specified for instruction \"%s\"\n", instr->_ident);
duke@0 265 }
duke@0 266 }
duke@0 267 // Add instruction to tail of instruction list
duke@0 268 _AD.addForm(instr);
duke@0 269
duke@0 270 // Create instruction form for each additional match rule
duke@0 271 rule = instr->_matrule;
duke@0 272 if (rule != NULL) {
duke@0 273 rule = rule->_next;
duke@0 274 while (rule != NULL) {
duke@0 275 ident = (char*)rule->_result;
duke@0 276 InstructForm *clone = new InstructForm(ident, instr, rule); // Create new instruction form
duke@0 277 _globalNames.Insert(ident, clone); // Add name to the name table
duke@0 278 // Debugging Stuff
duke@0 279 if (_AD._adl_debug > 1)
duke@0 280 fprintf(stderr,"Parsing Instruction Form %s\n", ident);
duke@0 281 // Check for "Set" form of chain rule
duke@0 282 adjust_set_rule(clone);
duke@0 283 // Add instruction to tail of instruction list
duke@0 284 _AD.addForm(clone);
duke@0 285 rule = rule->_next;
duke@0 286 clone->_matrule->_next = NULL; // One match rule per clone
duke@0 287 }
duke@0 288 }
duke@0 289 }
duke@0 290
duke@0 291 //------------------------------matchrule_clone_and_swap-----------------------
duke@0 292 // Check for commutative operations with subtree operands,
duke@0 293 // create clones and swap operands.
duke@0 294 void ADLParser::matchrule_clone_and_swap(MatchRule* rule, const char* instr_ident, int& match_rules_cnt) {
duke@0 295 // Check for commutative operations with tree operands.
duke@0 296 int count = 0;
duke@0 297 rule->count_commutative_op(count);
duke@0 298 if (count > 0) {
duke@0 299 // Clone match rule and swap commutative operation's operands.
duke@0 300 rule->swap_commutative_op(instr_ident, count, match_rules_cnt);
duke@0 301 }
duke@0 302 }
duke@0 303
duke@0 304 //------------------------------adjust_set_rule--------------------------------
duke@0 305 // Check for "Set" form of chain rule
duke@0 306 void ADLParser::adjust_set_rule(InstructForm *instr) {
duke@0 307 if (instr->_matrule == NULL || instr->_matrule->_rChild == NULL) return;
duke@0 308 const char *rch = instr->_matrule->_rChild->_opType;
duke@0 309 const Form *frm = _globalNames[rch];
duke@0 310 if( (! strcmp(instr->_matrule->_opType,"Set")) &&
duke@0 311 frm && frm->is_operand() && (! frm->ideal_only()) ) {
duke@0 312 // Previous implementation, which missed leaP*, but worked for loadCon*
duke@0 313 unsigned position = 0;
duke@0 314 const char *result = NULL;
duke@0 315 const char *name = NULL;
duke@0 316 const char *optype = NULL;
duke@0 317 MatchNode *right = instr->_matrule->_rChild;
duke@0 318 if (right->base_operand(position, _globalNames, result, name, optype)) {
duke@0 319 position = 1;
duke@0 320 const char *result2 = NULL;
duke@0 321 const char *name2 = NULL;
duke@0 322 const char *optype2 = NULL;
duke@0 323 // Can not have additional base operands in right side of match!
duke@0 324 if ( ! right->base_operand( position, _globalNames, result2, name2, optype2) ) {
duke@0 325 assert( instr->_predicate == NULL, "ADLC does not support instruction chain rules with predicates");
duke@0 326 // Chain from input _ideal_operand_type_,
duke@0 327 // Needed for shared roots of match-trees
duke@0 328 ChainList *lst = (ChainList *)_AD._chainRules[optype];
duke@0 329 if (lst == NULL) {
duke@0 330 lst = new ChainList();
duke@0 331 _AD._chainRules.Insert(optype, lst);
duke@0 332 }
duke@0 333 if (!lst->search(instr->_matrule->_lChild->_opType)) {
duke@0 334 const char *cost = instr->cost();
duke@0 335 if (cost == NULL) {
duke@0 336 cost = ((AttributeForm*)_globalNames[AttributeForm::_ins_cost])->_attrdef;
duke@0 337 }
duke@0 338 // The ADLC does not support chaining from the ideal operand type
duke@0 339 // of a predicated user-defined operand
duke@0 340 if( frm->is_operand() == NULL || frm->is_operand()->_predicate == NULL ) {
duke@0 341 lst->insert(instr->_matrule->_lChild->_opType,cost,instr->_ident);
duke@0 342 }
duke@0 343 }
duke@0 344 // Chain from input _user_defined_operand_type_,
duke@0 345 lst = (ChainList *)_AD._chainRules[result];
duke@0 346 if (lst == NULL) {
duke@0 347 lst = new ChainList();
duke@0 348 _AD._chainRules.Insert(result, lst);
duke@0 349 }
duke@0 350 if (!lst->search(instr->_matrule->_lChild->_opType)) {
duke@0 351 const char *cost = instr->cost();
duke@0 352 if (cost == NULL) {
duke@0 353 cost = ((AttributeForm*)_globalNames[AttributeForm::_ins_cost])->_attrdef;
duke@0 354 }
duke@0 355 // It is safe to chain from the top-level user-defined operand even
duke@0 356 // if it has a predicate, since the predicate is checked before
duke@0 357 // the user-defined type is available.
duke@0 358 lst->insert(instr->_matrule->_lChild->_opType,cost,instr->_ident);
duke@0 359 }
duke@0 360 } else {
duke@0 361 // May have instruction chain rule if root of right-tree is an ideal
duke@0 362 OperandForm *rightOp = _globalNames[right->_opType]->is_operand();
duke@0 363 if( rightOp ) {
duke@0 364 const Form *rightRoot = _globalNames[rightOp->_matrule->_opType];
duke@0 365 if( rightRoot && rightRoot->ideal_only() ) {
duke@0 366 const char *chain_op = NULL;
duke@0 367 if( rightRoot->is_instruction() )
duke@0 368 chain_op = rightOp->_ident;
duke@0 369 if( chain_op ) {
duke@0 370 // Look-up the operation in chain rule table
duke@0 371 ChainList *lst = (ChainList *)_AD._chainRules[chain_op];
duke@0 372 if (lst == NULL) {
duke@0 373 lst = new ChainList();
duke@0 374 _AD._chainRules.Insert(chain_op, lst);
duke@0 375 }
duke@0 376 // if (!lst->search(instr->_matrule->_lChild->_opType)) {
duke@0 377 const char *cost = instr->cost();
duke@0 378 if (cost == NULL) {
duke@0 379 cost = ((AttributeForm*)_globalNames[AttributeForm::_ins_cost])->_attrdef;
duke@0 380 }
duke@0 381 // This chains from a top-level operand whose predicate, if any,
duke@0 382 // has been checked.
duke@0 383 lst->insert(instr->_matrule->_lChild->_opType,cost,instr->_ident);
duke@0 384 // }
duke@0 385 }
duke@0 386 }
duke@0 387 }
duke@0 388 } // end chain rule from right-tree's ideal root
duke@0 389 }
duke@0 390 }
duke@0 391 }
duke@0 392
duke@0 393
duke@0 394 //------------------------------oper_parse-------------------------------------
duke@0 395 void ADLParser::oper_parse(void) {
duke@0 396 char *ident;
duke@0 397 OperandForm *oper;
duke@0 398 AttributeForm *attr;
duke@0 399 MatchRule *rule;
duke@0 400
duke@0 401 // First get the name of the operand
duke@0 402 skipws();
duke@0 403 if( (ident = get_unique_ident(_globalNames,"operand")) == NULL )
duke@0 404 return;
duke@0 405 oper = new OperandForm(ident); // Create new operand form
never@415 406 oper->_linenum = linenum();
duke@0 407 _globalNames.Insert(ident, oper); // Add name to the name table
duke@0 408
duke@0 409 // Debugging Stuff
duke@0 410 if (_AD._adl_debug > 1) fprintf(stderr,"Parsing Operand Form %s\n", ident);
duke@0 411
duke@0 412 // Get the component operands
duke@0 413 skipws();
duke@0 414 if (_curchar != '(') {
duke@0 415 parse_err(SYNERR, "missing '(' in operand definition\n");
duke@0 416 return;
duke@0 417 }
duke@0 418 else get_oplist(oper->_parameters, oper->_localNames); // Parse the component operand list
duke@0 419 skipws();
duke@0 420 // Check for block delimiter
duke@0 421 if ((_curchar != '%') || (*(_ptr+1) != '{')) { // If not open block
duke@0 422 parse_err(SYNERR, "missing '%c{' in operand definition\n","%");
duke@0 423 return;
duke@0 424 }
duke@0 425 next_char(); next_char(); // Skip over "%{" symbol
duke@0 426 do {
duke@0 427 ident = get_ident(); // Grab next identifier
duke@0 428 if (ident == NULL) {
duke@0 429 parse_err(SYNERR, "keyword identifier expected at %c\n", _curchar);
duke@0 430 continue;
duke@0 431 }
duke@0 432 if (!strcmp(ident, "predicate")) oper->_predicate = pred_parse();
duke@0 433 else if (!strcmp(ident, "match")) {
duke@0 434 // Find the end of the match rule list
duke@0 435 rule = oper->_matrule;
duke@0 436 if (rule) {
duke@0 437 while (rule->_next) rule = rule->_next;
duke@0 438 // Add the new match rule to the list
duke@0 439 rule->_next = match_parse(oper->_localNames);
duke@0 440 if (rule->_next) {
duke@0 441 rule->_next->_result = oper->_ident;
duke@0 442 }
duke@0 443 }
duke@0 444 else {
duke@0 445 // This is first match rule encountered
duke@0 446 oper->_matrule = match_parse(oper->_localNames);
duke@0 447 if (oper->_matrule) {
duke@0 448 oper->_matrule->_result = oper->_ident;
duke@0 449 }
duke@0 450 }
duke@0 451 }
duke@0 452 else if (!strcmp(ident, "encode")) oper->_interface = interface_parse();
duke@0 453 else if (!strcmp(ident, "ins_encode")) {
duke@0 454 parse_err(SYNERR, "Operands specify 'encode', not 'ins_encode'\n");
duke@0 455 }
duke@0 456 else if (!strcmp(ident, "opcode")) {
duke@0 457 parse_err(SYNERR, "Operands do not specify an opcode\n");
duke@0 458 }
duke@0 459 else if (!strcmp(ident, "effect")) {
duke@0 460 parse_err(SYNERR, "Operands do not specify an effect\n");
duke@0 461 }
duke@0 462 else if (!strcmp(ident, "expand")) {
duke@0 463 parse_err(SYNERR, "Operands do not specify an expand\n");
duke@0 464 }
duke@0 465 else if (!strcmp(ident, "rewrite")) {
duke@0 466 parse_err(SYNERR, "Operands do not specify a rewrite\n");
duke@0 467 }
duke@0 468 else if (!strcmp(ident, "constraint"))oper->_constraint= constraint_parse();
duke@0 469 else if (!strcmp(ident, "construct")) oper->_construct = construct_parse();
duke@0 470 else if (!strcmp(ident, "format")) oper->_format = format_parse();
duke@0 471 else if (!strcmp(ident, "interface")) oper->_interface = interface_parse();
duke@0 472 // Check identifier to see if it is the name of an attribute
duke@0 473 else if (((attr = _globalNames[ident]->is_attribute()) != NULL) &&
duke@0 474 (attr->_atype == OP_ATTR)) oper->_attribs = attr_parse(ident);
duke@0 475 else {
duke@0 476 parse_err(SYNERR, "expected one of - constraint, predicate, match, encode, format, construct, or the name of a defined operand attribute at %s\n", ident);
duke@0 477 }
duke@0 478 skipws();
duke@0 479 } while(_curchar != '%');
duke@0 480 next_char();
duke@0 481 if (_curchar != '}') {
duke@0 482 parse_err(SYNERR, "missing '%}' in operand definition\n");
duke@0 483 return;
duke@0 484 }
duke@0 485 // Add operand to tail of operand list
duke@0 486 _AD.addForm(oper);
duke@0 487 }
duke@0 488
duke@0 489 //------------------------------opclass_parse----------------------------------
duke@0 490 // Operand Classes are a block with a comma delimited list of operand names
duke@0 491 void ADLParser::opclass_parse(void) {
duke@0 492 char *ident;
duke@0 493 OpClassForm *opc;
duke@0 494 OperandForm *opForm;
duke@0 495
duke@0 496 // First get the name of the operand class
duke@0 497 skipws();
duke@0 498 if( (ident = get_unique_ident(_globalNames,"opclass")) == NULL )
duke@0 499 return;
duke@0 500 opc = new OpClassForm(ident); // Create new operand class form
duke@0 501 _globalNames.Insert(ident, opc); // Add name to the name table
duke@0 502
duke@0 503 // Debugging Stuff
duke@0 504 if (_AD._adl_debug > 1)
duke@0 505 fprintf(stderr,"Parsing Operand Class Form %s\n", ident);
duke@0 506
duke@0 507 // Get the list of operands
duke@0 508 skipws();
duke@0 509 if (_curchar != '(') {
duke@0 510 parse_err(SYNERR, "missing '(' in operand definition\n");
duke@0 511 return;
duke@0 512 }
duke@0 513 do {
duke@0 514 next_char(); // Skip past open paren or comma
duke@0 515 ident = get_ident(); // Grab next identifier
duke@0 516 if (ident == NULL) {
duke@0 517 parse_err(SYNERR, "keyword identifier expected at %c\n", _curchar);
duke@0 518 continue;
duke@0 519 }
duke@0 520 // Check identifier to see if it is the name of an operand
duke@0 521 const Form *form = _globalNames[ident];
duke@0 522 opForm = form ? form->is_operand() : NULL;
duke@0 523 if ( opForm ) {
duke@0 524 opc->_oplst.addName(ident); // Add operand to opclass list
duke@0 525 opForm->_classes.addName(opc->_ident);// Add opclass to operand list
duke@0 526 }
duke@0 527 else {
duke@0 528 parse_err(SYNERR, "expected name of a defined operand at %s\n", ident);
duke@0 529 }
duke@0 530 skipws(); // skip trailing whitespace
duke@0 531 } while (_curchar == ','); // Check for the comma
duke@0 532 // Check for closing ')'
duke@0 533 if (_curchar != ')') {
duke@0 534 parse_err(SYNERR, "missing ')' or ',' in opclass definition\n");
duke@0 535 return;
duke@0 536 }
duke@0 537 next_char(); // Consume the ')'
duke@0 538 skipws();
duke@0 539 // Check for closing ';'
duke@0 540 if (_curchar != ';') {
duke@0 541 parse_err(SYNERR, "missing ';' in opclass definition\n");
duke@0 542 return;
duke@0 543 }
duke@0 544 next_char(); // Consume the ';'
duke@0 545 // Add operand to tail of operand list
duke@0 546 _AD.addForm(opc);
duke@0 547 }
duke@0 548
duke@0 549 //------------------------------ins_attr_parse---------------------------------
duke@0 550 void ADLParser::ins_attr_parse(void) {
duke@0 551 char *ident;
duke@0 552 char *aexpr;
duke@0 553 AttributeForm *attrib;
duke@0 554
duke@0 555 // get name for the instruction attribute
duke@0 556 skipws(); // Skip leading whitespace
duke@0 557 if( (ident = get_unique_ident(_globalNames,"inst_attrib")) == NULL )
duke@0 558 return;
duke@0 559 // Debugging Stuff
duke@0 560 if (_AD._adl_debug > 1) fprintf(stderr,"Parsing Ins_Attribute Form %s\n", ident);
duke@0 561
duke@0 562 // Get default value of the instruction attribute
duke@0 563 skipws(); // Skip whitespace
duke@0 564 if ((aexpr = get_paren_expr("attribute default expression string")) == NULL) {
duke@0 565 parse_err(SYNERR, "missing '(' in ins_attrib definition\n");
duke@0 566 return;
duke@0 567 }
duke@0 568 // Debug Stuff
duke@0 569 if (_AD._adl_debug > 1) fprintf(stderr,"Attribute Expression: %s\n", aexpr);
duke@0 570
duke@0 571 // Check for terminator
duke@0 572 if (_curchar != ';') {
duke@0 573 parse_err(SYNERR, "missing ';' in ins_attrib definition\n");
duke@0 574 return;
duke@0 575 }
duke@0 576 next_char(); // Advance past the ';'
duke@0 577
duke@0 578 // Construct the attribute, record global name, and store in ArchDesc
duke@0 579 attrib = new AttributeForm(ident, INS_ATTR, aexpr);
duke@0 580 _globalNames.Insert(ident, attrib); // Add name to the name table
duke@0 581 _AD.addForm(attrib);
duke@0 582 }
duke@0 583
duke@0 584 //------------------------------op_attr_parse----------------------------------
duke@0 585 void ADLParser::op_attr_parse(void) {
duke@0 586 char *ident;
duke@0 587 char *aexpr;
duke@0 588 AttributeForm *attrib;
duke@0 589
duke@0 590 // get name for the operand attribute
duke@0 591 skipws(); // Skip leading whitespace
duke@0 592 if( (ident = get_unique_ident(_globalNames,"op_attrib")) == NULL )
duke@0 593 return;
duke@0 594 // Debugging Stuff
duke@0 595 if (_AD._adl_debug > 1) fprintf(stderr,"Parsing Op_Attribute Form %s\n", ident);
duke@0 596
duke@0 597 // Get default value of the instruction attribute
duke@0 598 skipws(); // Skip whitespace
duke@0 599 if ((aexpr = get_paren_expr("attribute default expression string")) == NULL) {
duke@0 600 parse_err(SYNERR, "missing '(' in op_attrib definition\n");
duke@0 601 return;
duke@0 602 }
duke@0 603 // Debug Stuff
duke@0 604 if (_AD._adl_debug > 1) fprintf(stderr,"Attribute Expression: %s\n", aexpr);
duke@0 605
duke@0 606 // Check for terminator
duke@0 607 if (_curchar != ';') {
duke@0 608 parse_err(SYNERR, "missing ';' in op_attrib definition\n");
duke@0 609 return;
duke@0 610 }
duke@0 611 next_char(); // Advance past the ';'
duke@0 612
duke@0 613 // Construct the attribute, record global name, and store in ArchDesc
duke@0 614 attrib = new AttributeForm(ident, OP_ATTR, aexpr);
duke@0 615 _globalNames.Insert(ident, attrib);
duke@0 616 _AD.addForm(attrib);
duke@0 617 }
duke@0 618
duke@0 619 //------------------------------definitions_parse-----------------------------------
duke@0 620 void ADLParser::definitions_parse(void) {
duke@0 621 skipws(); // Skip leading whitespace
duke@0 622 if (_curchar == '%' && *(_ptr+1) == '{') {
duke@0 623 next_char(); next_char(); // Skip "%{"
duke@0 624 skipws();
duke@0 625 while (_curchar != '%' && *(_ptr+1) != '}') {
duke@0 626 // Process each definition until finding closing string "%}"
duke@0 627 char *token = get_ident();
duke@0 628 if (token == NULL) {
duke@0 629 parse_err(SYNERR, "missing identifier inside definitions block.\n");
duke@0 630 return;
duke@0 631 }
duke@0 632 if (strcmp(token,"int_def")==0) { int_def_parse(); }
duke@0 633 // if (strcmp(token,"str_def")==0) { str_def_parse(); }
duke@0 634 skipws();
duke@0 635 }
duke@0 636 }
duke@0 637 else {
duke@0 638 parse_err(SYNERR, "Missing %%{ ... %%} block after definitions keyword.\n");
duke@0 639 return;
duke@0 640 }
duke@0 641 }
duke@0 642
duke@0 643 //------------------------------int_def_parse----------------------------------
duke@0 644 // Parse Example:
duke@0 645 // int_def MEMORY_REF_COST ( 200, DEFAULT_COST * 2);
duke@0 646 // <keyword> <name> ( <int_value>, <description> );
duke@0 647 //
duke@0 648 void ADLParser::int_def_parse(void) {
duke@0 649 char *name = NULL; // Name of definition
duke@0 650 char *value = NULL; // its value,
duke@0 651 int int_value = -1; // positive values only
duke@0 652 char *description = NULL; // textual description
duke@0 653
duke@0 654 // Get definition name
duke@0 655 skipws(); // Skip whitespace
duke@0 656 name = get_ident();
duke@0 657 if (name == NULL) {
duke@0 658 parse_err(SYNERR, "missing definition name after int_def\n");
duke@0 659 return;
duke@0 660 }
duke@0 661
duke@0 662 // Check for value of int_def dname( integer_value [, string_expression ] )
duke@0 663 skipws();
duke@0 664 if (_curchar == '(') {
duke@0 665
duke@0 666 // Parse the integer value.
duke@0 667 next_char();
duke@0 668 value = get_ident();
duke@0 669 if (value == NULL) {
duke@0 670 parse_err(SYNERR, "missing value in int_def\n");
duke@0 671 return;
duke@0 672 }
duke@0 673 if( !is_int_token(value, int_value) ) {
duke@0 674 parse_err(SYNERR, "value in int_def is not recognized as integer\n");
duke@0 675 return;
duke@0 676 }
duke@0 677 skipws();
duke@0 678
duke@0 679 // Check for description
duke@0 680 if (_curchar == ',') {
duke@0 681 next_char(); // skip ','
duke@0 682
duke@0 683 description = get_expr("int_def description", ")");
duke@0 684 if (description == NULL) {
duke@0 685 parse_err(SYNERR, "invalid or missing description in int_def\n");
duke@0 686 return;
duke@0 687 }
duke@0 688 trim(description);
duke@0 689 }
duke@0 690
duke@0 691 if (_curchar != ')') {
duke@0 692 parse_err(SYNERR, "missing ')' in register definition statement\n");
duke@0 693 return;
duke@0 694 }
duke@0 695 next_char();
duke@0 696 }
duke@0 697
duke@0 698 // Check for closing ';'
duke@0 699 skipws();
duke@0 700 if (_curchar != ';') {
duke@0 701 parse_err(SYNERR, "missing ';' after int_def\n");
duke@0 702 return;
duke@0 703 }
duke@0 704 next_char(); // move past ';'
duke@0 705
duke@0 706 // Debug Stuff
duke@0 707 if (_AD._adl_debug > 1) {
duke@0 708 fprintf(stderr,"int_def: %s ( %s, %s )\n", name,
duke@0 709 (value), (description ? description : ""));
duke@0 710 }
duke@0 711
duke@0 712 // Record new definition.
duke@0 713 Expr *expr = new Expr(name, description, int_value, int_value);
duke@0 714 const Expr *old_expr = _AD.globalDefs().define(name, expr);
duke@0 715 if (old_expr != NULL) {
duke@0 716 parse_err(SYNERR, "Duplicate definition\n");
duke@0 717 return;
duke@0 718 }
duke@0 719
duke@0 720 return;
duke@0 721 }
duke@0 722
duke@0 723
duke@0 724 //------------------------------source_parse-----------------------------------
duke@0 725 void ADLParser::source_parse(void) {
duke@0 726 SourceForm *source; // Encode class for instruction/operand
duke@0 727 char *rule = NULL; // String representation of encode rule
duke@0 728
duke@0 729 skipws(); // Skip leading whitespace
duke@0 730 if ( (rule = find_cpp_block("source block")) == NULL ) {
duke@0 731 parse_err(SYNERR, "incorrect or missing block for 'source'.\n");
duke@0 732 return;
duke@0 733 }
duke@0 734 // Debug Stuff
duke@0 735 if (_AD._adl_debug > 1) fprintf(stderr,"Source Form: %s\n", rule);
duke@0 736
duke@0 737 source = new SourceForm(rule); // Build new Source object
duke@0 738 _AD.addForm(source);
duke@0 739 // skipws();
duke@0 740 }
duke@0 741
duke@0 742 //------------------------------source_hpp_parse-------------------------------
duke@0 743 // Parse a source_hpp %{ ... %} block.
duke@0 744 // The code gets stuck into the ad_<arch>.hpp file.
duke@0 745 // If the source_hpp block appears before the register block in the AD
duke@0 746 // file, it goes up at the very top of the ad_<arch>.hpp file, so that
duke@0 747 // it can be used by register encodings, etc. Otherwise, it goes towards
duke@0 748 // the bottom, where it's useful as a global definition to *.cpp files.
duke@0 749 void ADLParser::source_hpp_parse(void) {
duke@0 750 char *rule = NULL; // String representation of encode rule
duke@0 751
duke@0 752 skipws(); // Skip leading whitespace
duke@0 753 if ( (rule = find_cpp_block("source_hpp block")) == NULL ) {
duke@0 754 parse_err(SYNERR, "incorrect or missing block for 'source_hpp'.\n");
duke@0 755 return;
duke@0 756 }
duke@0 757 // Debug Stuff
duke@0 758 if (_AD._adl_debug > 1) fprintf(stderr,"Header Form: %s\n", rule);
duke@0 759
duke@0 760 if (_AD.get_registers() == NULL) {
duke@0 761 // Very early in the file, before reg_defs, we collect pre-headers.
duke@0 762 PreHeaderForm* pre_header = new PreHeaderForm(rule);
duke@0 763 _AD.addForm(pre_header);
duke@0 764 } else {
duke@0 765 // Normally, we collect header info, placed at the bottom of the hpp file.
duke@0 766 HeaderForm* header = new HeaderForm(rule);
duke@0 767 _AD.addForm(header);
duke@0 768 }
duke@0 769 }
duke@0 770
duke@0 771 //------------------------------reg_parse--------------------------------------
duke@0 772 void ADLParser::reg_parse(void) {
duke@0 773
duke@0 774 // Create the RegisterForm for the architecture description.
duke@0 775 RegisterForm *regBlock = new RegisterForm(); // Build new Source object
never@415 776 regBlock->_linenum = linenum();
duke@0 777 _AD.addForm(regBlock);
duke@0 778
duke@0 779 skipws(); // Skip leading whitespace
duke@0 780 if (_curchar == '%' && *(_ptr+1) == '{') {
duke@0 781 next_char(); next_char(); // Skip "%{"
duke@0 782 skipws();
duke@0 783 while (_curchar != '%' && *(_ptr+1) != '}') {
duke@0 784 char *token = get_ident();
duke@0 785 if (token == NULL) {
duke@0 786 parse_err(SYNERR, "missing identifier inside register block.\n");
duke@0 787 return;
duke@0 788 }
duke@0 789 if (strcmp(token,"reg_def")==0) { reg_def_parse(); }
duke@0 790 if (strcmp(token,"reg_class")==0) { reg_class_parse(); }
duke@0 791 if (strcmp(token,"alloc_class")==0) { alloc_class_parse(); }
duke@0 792 skipws();
duke@0 793 }
duke@0 794 }
duke@0 795 else {
duke@0 796 parse_err(SYNERR, "Missing %c{ ... %c} block after register keyword.\n",'%','%');
duke@0 797 return;
duke@0 798 }
duke@0 799
duke@0 800 // Add reg_class spill_regs
duke@0 801 regBlock->addSpillRegClass();
duke@0 802 }
duke@0 803
duke@0 804 //------------------------------encode_parse-----------------------------------
duke@0 805 void ADLParser::encode_parse(void) {
duke@0 806 EncodeForm *encBlock; // Information about instruction/operand encoding
duke@0 807 char *desc = NULL; // String representation of encode rule
duke@0 808
duke@0 809 _AD.getForm(&encBlock);
duke@0 810 if ( encBlock == NULL) {
duke@0 811 // Create the EncodeForm for the architecture description.
duke@0 812 encBlock = new EncodeForm(); // Build new Source object
duke@0 813 _AD.addForm(encBlock);
duke@0 814 }
duke@0 815
duke@0 816 skipws(); // Skip leading whitespace
duke@0 817 if (_curchar == '%' && *(_ptr+1) == '{') {
duke@0 818 next_char(); next_char(); // Skip "%{"
duke@0 819 skipws();
duke@0 820 while (_curchar != '%' && *(_ptr+1) != '}') {
duke@0 821 char *token = get_ident();
duke@0 822 if (token == NULL) {
duke@0 823 parse_err(SYNERR, "missing identifier inside encoding block.\n");
duke@0 824 return;
duke@0 825 }
duke@0 826 if (strcmp(token,"enc_class")==0) { enc_class_parse(); }
duke@0 827 skipws();
duke@0 828 }
duke@0 829 }
duke@0 830 else {
duke@0 831 parse_err(SYNERR, "Missing %c{ ... %c} block after encode keyword.\n",'%','%');
duke@0 832 return;
duke@0 833 }
duke@0 834 }
duke@0 835
duke@0 836 //------------------------------enc_class_parse--------------------------------
duke@0 837 void ADLParser::enc_class_parse(void) {
duke@0 838 char *ec_name; // Name of encoding class being defined
duke@0 839
duke@0 840 // Get encoding class name
duke@0 841 skipws(); // Skip whitespace
duke@0 842 ec_name = get_ident();
duke@0 843 if (ec_name == NULL) {
duke@0 844 parse_err(SYNERR, "missing encoding class name after encode.\n");
duke@0 845 return;
duke@0 846 }
duke@0 847
duke@0 848 EncClass *encoding = _AD._encode->add_EncClass(ec_name);
never@415 849 encoding->_linenum = linenum();
duke@0 850
duke@0 851 skipws(); // Skip leading whitespace
duke@0 852 // Check for optional parameter list
duke@0 853 if (_curchar == '(') {
duke@0 854 do {
duke@0 855 char *pType = NULL; // parameter type
duke@0 856 char *pName = NULL; // parameter name
duke@0 857
duke@0 858 next_char(); // skip open paren & comma characters
duke@0 859 skipws();
duke@0 860 if (_curchar == ')') break;
duke@0 861
duke@0 862 // Get parameter type
duke@0 863 pType = get_ident();
duke@0 864 if (pType == NULL) {
duke@0 865 parse_err(SYNERR, "parameter type expected at %c\n", _curchar);
duke@0 866 return;
duke@0 867 }
duke@0 868
duke@0 869 skipws();
duke@0 870 // Get parameter name
duke@0 871 pName = get_ident();
duke@0 872 if (pName == NULL) {
duke@0 873 parse_err(SYNERR, "parameter name expected at %c\n", _curchar);
duke@0 874 return;
duke@0 875 }
duke@0 876
duke@0 877 // Record parameter type and name
duke@0 878 encoding->add_parameter( pType, pName );
duke@0 879
duke@0 880 skipws();
duke@0 881 } while(_curchar == ',');
duke@0 882
duke@0 883 if (_curchar != ')') parse_err(SYNERR, "missing ')'\n");
duke@0 884 else {
duke@0 885 next_char(); // Skip ')'
duke@0 886 }
duke@0 887 } // Done with parameter list
duke@0 888
duke@0 889 skipws();
duke@0 890 // Check for block starting delimiters
duke@0 891 if ((_curchar != '%') || (*(_ptr+1) != '{')) { // If not open block
duke@0 892 parse_err(SYNERR, "missing '%c{' in enc_class definition\n", '%');
duke@0 893 return;
duke@0 894 }
duke@0 895 next_char(); // Skip '%'
duke@0 896 next_char(); // Skip '{'
duke@0 897
duke@0 898 enc_class_parse_block(encoding, ec_name);
duke@0 899 }
duke@0 900
duke@0 901
duke@0 902 void ADLParser::enc_class_parse_block(EncClass* encoding, char* ec_name) {
duke@0 903 skipws_no_preproc(); // Skip leading whitespace
duke@0 904 // Prepend location descriptor, for debugging; cf. ADLParser::find_cpp_block
duke@0 905 if (_AD._adlocation_debug) {
duke@0 906 const char* file = _AD._ADL_file._name;
never@415 907 int line = linenum();
duke@0 908 char* location = (char *)malloc(strlen(file) + 100);
duke@0 909 sprintf(location, "#line %d \"%s\"\n", line, file);
duke@0 910 encoding->add_code(location);
duke@0 911 }
duke@0 912
duke@0 913 // Collect the parts of the encode description
duke@0 914 // (1) strings that are passed through to output
duke@0 915 // (2) replacement/substitution variable, preceeded by a '$'
duke@0 916 while ( (_curchar != '%') && (*(_ptr+1) != '}') ) {
duke@0 917
duke@0 918 // (1)
duke@0 919 // Check if there is a string to pass through to output
duke@0 920 char *start = _ptr; // Record start of the next string
duke@0 921 while ((_curchar != '$') && ((_curchar != '%') || (*(_ptr+1) != '}')) ) {
duke@0 922 // If at the start of a comment, skip past it
duke@0 923 if( (_curchar == '/') && ((*(_ptr+1) == '/') || (*(_ptr+1) == '*')) ) {
duke@0 924 skipws_no_preproc();
duke@0 925 } else {
duke@0 926 // ELSE advance to the next character, or start of the next line
duke@0 927 next_char_or_line();
duke@0 928 }
duke@0 929 }
duke@0 930 // If a string was found, terminate it and record in EncClass
duke@0 931 if ( start != _ptr ) {
duke@0 932 *_ptr = '\0'; // Terminate the string
duke@0 933 encoding->add_code(start);
duke@0 934 }
duke@0 935
duke@0 936 // (2)
duke@0 937 // If we are at a replacement variable,
duke@0 938 // copy it and record in EncClass
duke@0 939 if ( _curchar == '$' ) {
duke@0 940 // Found replacement Variable
duke@0 941 char *rep_var = get_rep_var_ident_dup();
duke@0 942 // Add flag to _strings list indicating we should check _rep_vars
duke@0 943 encoding->add_rep_var(rep_var);
duke@0 944 }
duke@0 945 } // end while part of format description
duke@0 946 next_char(); // Skip '%'
duke@0 947 next_char(); // Skip '}'
duke@0 948
duke@0 949 skipws();
duke@0 950
duke@0 951 // Debug Stuff
duke@0 952 if (_AD._adl_debug > 1) fprintf(stderr,"EncodingClass Form: %s\n", ec_name);
duke@0 953 }
duke@0 954
duke@0 955 //------------------------------frame_parse-----------------------------------
duke@0 956 void ADLParser::frame_parse(void) {
duke@0 957 FrameForm *frame; // Information about stack-frame layout
duke@0 958 char *desc = NULL; // String representation of frame
duke@0 959
duke@0 960 skipws(); // Skip leading whitespace
duke@0 961
duke@0 962 frame = new FrameForm(); // Build new Frame object
duke@0 963 // Check for open block sequence
duke@0 964 skipws(); // Skip leading whitespace
duke@0 965 if (_curchar == '%' && *(_ptr+1) == '{') {
duke@0 966 next_char(); next_char(); // Skip "%{"
duke@0 967 skipws();
duke@0 968 while (_curchar != '%' && *(_ptr+1) != '}') {
duke@0 969 char *token = get_ident();
duke@0 970 if (token == NULL) {
duke@0 971 parse_err(SYNERR, "missing identifier inside frame block.\n");
duke@0 972 return;
duke@0 973 }
duke@0 974 if (strcmp(token,"stack_direction")==0) {
duke@0 975 stack_dir_parse(frame);
duke@0 976 }
duke@0 977 if (strcmp(token,"sync_stack_slots")==0) {
duke@0 978 sync_stack_slots_parse(frame);
duke@0 979 }
duke@0 980 if (strcmp(token,"frame_pointer")==0) {
duke@0 981 frame_pointer_parse(frame, false);
duke@0 982 }
duke@0 983 if (strcmp(token,"interpreter_frame_pointer")==0) {
duke@0 984 interpreter_frame_pointer_parse(frame, false);
duke@0 985 // Add reg_class interpreter_frame_pointer_reg
duke@0 986 if( _AD._register != NULL ) {
duke@0 987 RegClass *reg_class = _AD._register->addRegClass("interpreter_frame_pointer_reg");
duke@0 988 char *interpreter_frame_pointer_reg = frame->_interpreter_frame_pointer_reg;
duke@0 989 if( interpreter_frame_pointer_reg != NULL ) {
duke@0 990 RegDef *regDef = _AD._register->getRegDef(interpreter_frame_pointer_reg);
duke@0 991 reg_class->addReg(regDef); // add regDef to regClass
duke@0 992 }
duke@0 993 }
duke@0 994 }
duke@0 995 if (strcmp(token,"inline_cache_reg")==0) {
duke@0 996 inline_cache_parse(frame, false);
duke@0 997 // Add reg_class inline_cache_reg
duke@0 998 if( _AD._register != NULL ) {
duke@0 999 RegClass *reg_class = _AD._register->addRegClass("inline_cache_reg");
duke@0 1000 char *inline_cache_reg = frame->_inline_cache_reg;
duke@0 1001 if( inline_cache_reg != NULL ) {
duke@0 1002 RegDef *regDef = _AD._register->getRegDef(inline_cache_reg);
duke@0 1003 reg_class->addReg(regDef); // add regDef to regClass
duke@0 1004 }
duke@0 1005 }
duke@0 1006 }
duke@0 1007 if (strcmp(token,"compiler_method_oop_reg")==0) {
duke@0 1008 parse_err(WARN, "Using obsolete Token, compiler_method_oop_reg");
duke@0 1009 skipws();
duke@0 1010 }
duke@0 1011 if (strcmp(token,"interpreter_method_oop_reg")==0) {
duke@0 1012 interpreter_method_oop_parse(frame, false);
duke@0 1013 // Add reg_class interpreter_method_oop_reg
duke@0 1014 if( _AD._register != NULL ) {
duke@0 1015 RegClass *reg_class = _AD._register->addRegClass("interpreter_method_oop_reg");
duke@0 1016 char *method_oop_reg = frame->_interpreter_method_oop_reg;
duke@0 1017 if( method_oop_reg != NULL ) {
duke@0 1018 RegDef *regDef = _AD._register->getRegDef(method_oop_reg);
duke@0 1019 reg_class->addReg(regDef); // add regDef to regClass
duke@0 1020 }
duke@0 1021 }
duke@0 1022 }
duke@0 1023 if (strcmp(token,"cisc_spilling_operand_name")==0) {
duke@0 1024 cisc_spilling_operand_name_parse(frame, false);
duke@0 1025 }
duke@0 1026 if (strcmp(token,"stack_alignment")==0) {
duke@0 1027 stack_alignment_parse(frame);
duke@0 1028 }
duke@0 1029 if (strcmp(token,"return_addr")==0) {
duke@0 1030 return_addr_parse(frame, false);
duke@0 1031 }
duke@0 1032 if (strcmp(token,"in_preserve_stack_slots")==0) {
duke@0 1033 preserve_stack_parse(frame);
duke@0 1034 }
duke@0 1035 if (strcmp(token,"out_preserve_stack_slots")==0) {
duke@0 1036 parse_err(WARN, "Using obsolete token, out_preserve_stack_slots");
duke@0 1037 skipws();
duke@0 1038 }
duke@0 1039 if (strcmp(token,"varargs_C_out_slots_killed")==0) {
duke@0 1040 frame->_varargs_C_out_slots_killed = parse_one_arg("varargs C out slots killed");
duke@0 1041 }
duke@0 1042 if (strcmp(token,"calling_convention")==0) {
duke@0 1043 frame->_calling_convention = calling_convention_parse();
duke@0 1044 }
duke@0 1045 if (strcmp(token,"return_value")==0) {
duke@0 1046 frame->_return_value = return_value_parse();
duke@0 1047 }
duke@0 1048 if (strcmp(token,"c_frame_pointer")==0) {
duke@0 1049 frame_pointer_parse(frame, true);
duke@0 1050 }
duke@0 1051 if (strcmp(token,"c_return_addr")==0) {
duke@0 1052 return_addr_parse(frame, true);
duke@0 1053 }
duke@0 1054 if (strcmp(token,"c_calling_convention")==0) {
duke@0 1055 frame->_c_calling_convention = calling_convention_parse();
duke@0 1056 }
duke@0 1057 if (strcmp(token,"c_return_value")==0) {
duke@0 1058 frame->_c_return_value = return_value_parse();
duke@0 1059 }
duke@0 1060
duke@0 1061 skipws();
duke@0 1062 }
duke@0 1063 }
duke@0 1064 else {
duke@0 1065 parse_err(SYNERR, "Missing %c{ ... %c} block after encode keyword.\n",'%','%');
duke@0 1066 return;
duke@0 1067 }
duke@0 1068 // All Java versions are required, native versions are optional
duke@0 1069 if(frame->_frame_pointer == NULL) {
duke@0 1070 parse_err(SYNERR, "missing frame pointer definition in frame section.\n");
duke@0 1071 return;
duke@0 1072 }
duke@0 1073 // !!!!! !!!!!
duke@0 1074 // if(frame->_interpreter_frame_ptr_reg == NULL) {
duke@0 1075 // parse_err(SYNERR, "missing interpreter frame pointer definition in frame section.\n");
duke@0 1076 // return;
duke@0 1077 // }
duke@0 1078 if(frame->_alignment == NULL) {
duke@0 1079 parse_err(SYNERR, "missing alignment definition in frame section.\n");
duke@0 1080 return;
duke@0 1081 }
duke@0 1082 if(frame->_return_addr == NULL) {
duke@0 1083 parse_err(SYNERR, "missing return address location in frame section.\n");
duke@0 1084 return;
duke@0 1085 }
duke@0 1086 if(frame->_in_preserve_slots == NULL) {
duke@0 1087 parse_err(SYNERR, "missing stack slot preservation definition in frame section.\n");
duke@0 1088 return;
duke@0 1089 }
duke@0 1090 if(frame->_varargs_C_out_slots_killed == NULL) {
duke@0 1091 parse_err(SYNERR, "missing varargs C out slots killed definition in frame section.\n");
duke@0 1092 return;
duke@0 1093 }
duke@0 1094 if(frame->_calling_convention == NULL) {
duke@0 1095 parse_err(SYNERR, "missing calling convention definition in frame section.\n");
duke@0 1096 return;
duke@0 1097 }
duke@0 1098 if(frame->_return_value == NULL) {
duke@0 1099 parse_err(SYNERR, "missing return value definition in frame section.\n");
duke@0 1100 return;
duke@0 1101 }
duke@0 1102 // Fill natives in identically with the Java versions if not present.
duke@0 1103 if(frame->_c_frame_pointer == NULL) {
duke@0 1104 frame->_c_frame_pointer = frame->_frame_pointer;
duke@0 1105 }
duke@0 1106 if(frame->_c_return_addr == NULL) {
duke@0 1107 frame->_c_return_addr = frame->_return_addr;
duke@0 1108 frame->_c_return_addr_loc = frame->_return_addr_loc;
duke@0 1109 }
duke@0 1110 if(frame->_c_calling_convention == NULL) {
duke@0 1111 frame->_c_calling_convention = frame->_calling_convention;
duke@0 1112 }
duke@0 1113 if(frame->_c_return_value == NULL) {
duke@0 1114 frame->_c_return_value = frame->_return_value;
duke@0 1115 }
duke@0 1116
duke@0 1117 // Debug Stuff
duke@0 1118 if (_AD._adl_debug > 1) fprintf(stderr,"Frame Form: %s\n", desc);
duke@0 1119
duke@0 1120 // Create the EncodeForm for the architecture description.
duke@0 1121 _AD.addForm(frame);
duke@0 1122 // skipws();
duke@0 1123 }
duke@0 1124
duke@0 1125 //------------------------------stack_dir_parse--------------------------------
duke@0 1126 void ADLParser::stack_dir_parse(FrameForm *frame) {
duke@0 1127 char *direction = parse_one_arg("stack direction entry");
duke@0 1128 if (strcmp(direction, "TOWARDS_LOW") == 0) {
duke@0 1129 frame->_direction = false;
duke@0 1130 }
duke@0 1131 else if (strcmp(direction, "TOWARDS_HIGH") == 0) {
duke@0 1132 frame->_direction = true;
duke@0 1133 }
duke@0 1134 else {
duke@0 1135 parse_err(SYNERR, "invalid value inside stack direction entry.\n");
duke@0 1136 return;
duke@0 1137 }
duke@0 1138 }
duke@0 1139
duke@0 1140 //------------------------------sync_stack_slots_parse-------------------------
duke@0 1141 void ADLParser::sync_stack_slots_parse(FrameForm *frame) {
duke@0 1142 // Assign value into frame form
duke@0 1143 frame->_sync_stack_slots = parse_one_arg("sync stack slots entry");
duke@0 1144 }
duke@0 1145
duke@0 1146 //------------------------------frame_pointer_parse----------------------------
duke@0 1147 void ADLParser::frame_pointer_parse(FrameForm *frame, bool native) {
duke@0 1148 char *frame_pointer = parse_one_arg("frame pointer entry");
duke@0 1149 // Assign value into frame form
duke@0 1150 if (native) { frame->_c_frame_pointer = frame_pointer; }
duke@0 1151 else { frame->_frame_pointer = frame_pointer; }
duke@0 1152 }
duke@0 1153
duke@0 1154 //------------------------------interpreter_frame_pointer_parse----------------------------
duke@0 1155 void ADLParser::interpreter_frame_pointer_parse(FrameForm *frame, bool native) {
duke@0 1156 frame->_interpreter_frame_pointer_reg = parse_one_arg("interpreter frame pointer entry");
duke@0 1157 }
duke@0 1158
duke@0 1159 //------------------------------inline_cache_parse-----------------------------
duke@0 1160 void ADLParser::inline_cache_parse(FrameForm *frame, bool native) {
duke@0 1161 frame->_inline_cache_reg = parse_one_arg("inline cache reg entry");
duke@0 1162 }
duke@0 1163
duke@0 1164 //------------------------------interpreter_method_oop_parse------------------
duke@0 1165 void ADLParser::interpreter_method_oop_parse(FrameForm *frame, bool native) {
duke@0 1166 frame->_interpreter_method_oop_reg = parse_one_arg("method oop reg entry");
duke@0 1167 }
duke@0 1168
duke@0 1169 //------------------------------cisc_spilling_operand_parse---------------------
duke@0 1170 void ADLParser::cisc_spilling_operand_name_parse(FrameForm *frame, bool native) {
duke@0 1171 frame->_cisc_spilling_operand_name = parse_one_arg("cisc spilling operand name");
duke@0 1172 }
duke@0 1173
duke@0 1174 //------------------------------stack_alignment_parse--------------------------
duke@0 1175 void ADLParser::stack_alignment_parse(FrameForm *frame) {
duke@0 1176 char *alignment = parse_one_arg("stack alignment entry");
duke@0 1177 // Assign value into frame
duke@0 1178 frame->_alignment = alignment;
duke@0 1179 }
duke@0 1180
duke@0 1181 //------------------------------parse_one_arg-------------------------------
duke@0 1182 char *ADLParser::parse_one_arg(const char *description) {
duke@0 1183 char *token = NULL;
duke@0 1184 if(_curchar == '(') {
duke@0 1185 next_char();
duke@0 1186 skipws();
duke@0 1187 token = get_expr(description, ")");
duke@0 1188 if (token == NULL) {
duke@0 1189 parse_err(SYNERR, "missing value inside %s.\n", description);
duke@0 1190 return NULL;
duke@0 1191 }
duke@0 1192 next_char(); // skip the close paren
duke@0 1193 if(_curchar != ';') { // check for semi-colon
duke@0 1194 parse_err(SYNERR, "missing %c in.\n", ';', description);
duke@0 1195 return NULL;
duke@0 1196 }
duke@0 1197 next_char(); // skip the semi-colon
duke@0 1198 }
duke@0 1199 else {
duke@0 1200 parse_err(SYNERR, "Missing %c in.\n", '(', description);
duke@0 1201 return NULL;
duke@0 1202 }
duke@0 1203
duke@0 1204 trim(token);
duke@0 1205 return token;
duke@0 1206 }
duke@0 1207
duke@0 1208 //------------------------------return_addr_parse------------------------------
duke@0 1209 void ADLParser::return_addr_parse(FrameForm *frame, bool native) {
duke@0 1210 bool in_register = true;
duke@0 1211 if(_curchar == '(') {
duke@0 1212 next_char();
duke@0 1213 skipws();
duke@0 1214 char *token = get_ident();
duke@0 1215 if (token == NULL) {
duke@0 1216 parse_err(SYNERR, "missing value inside return address entry.\n");
duke@0 1217 return;
duke@0 1218 }
duke@0 1219 // check for valid values for stack/register
duke@0 1220 if (strcmp(token, "REG") == 0) {
duke@0 1221 in_register = true;
duke@0 1222 }
duke@0 1223 else if (strcmp(token, "STACK") == 0) {
duke@0 1224 in_register = false;
duke@0 1225 }
duke@0 1226 else {
duke@0 1227 parse_err(SYNERR, "invalid value inside return_address entry.\n");
duke@0 1228 return;
duke@0 1229 }
duke@0 1230 if (native) { frame->_c_return_addr_loc = in_register; }
duke@0 1231 else { frame->_return_addr_loc = in_register; }
duke@0 1232
duke@0 1233 // Parse expression that specifies register or stack position
duke@0 1234 skipws();
duke@0 1235 char *token2 = get_expr("return address entry", ")");
duke@0 1236 if (token2 == NULL) {
duke@0 1237 parse_err(SYNERR, "missing value inside return address entry.\n");
duke@0 1238 return;
duke@0 1239 }
duke@0 1240 next_char(); // skip the close paren
duke@0 1241 if (native) { frame->_c_return_addr = token2; }
duke@0 1242 else { frame->_return_addr = token2; }
duke@0 1243
duke@0 1244 if(_curchar != ';') { // check for semi-colon
duke@0 1245 parse_err(SYNERR, "missing %c in return address entry.\n", ';');
duke@0 1246 return;
duke@0 1247 }
duke@0 1248 next_char(); // skip the semi-colon
duke@0 1249 }
duke@0 1250 else {
duke@0 1251 parse_err(SYNERR, "Missing %c in return_address entry.\n", '(');
duke@0 1252 }
duke@0 1253 }
duke@0 1254
duke@0 1255 //------------------------------preserve_stack_parse---------------------------
duke@0 1256 void ADLParser::preserve_stack_parse(FrameForm *frame) {
duke@0 1257 if(_curchar == '(') {
duke@0 1258 char *token = get_paren_expr("preserve_stack_slots");
duke@0 1259 frame->_in_preserve_slots = token;
duke@0 1260
duke@0 1261 if(_curchar != ';') { // check for semi-colon
duke@0 1262 parse_err(SYNERR, "missing %c in preserve stack slot entry.\n", ';');
duke@0 1263 return;
duke@0 1264 }
duke@0 1265 next_char(); // skip the semi-colon
duke@0 1266 }
duke@0 1267 else {
duke@0 1268 parse_err(SYNERR, "Missing %c in preserve stack slot entry.\n", '(');
duke@0 1269 }
duke@0 1270 }
duke@0 1271
duke@0 1272 //------------------------------calling_convention_parse-----------------------
duke@0 1273 char *ADLParser::calling_convention_parse() {
duke@0 1274 char *desc = NULL; // String representation of calling_convention
duke@0 1275
duke@0 1276 skipws(); // Skip leading whitespace
duke@0 1277 if ( (desc = find_cpp_block("calling convention block")) == NULL ) {
duke@0 1278 parse_err(SYNERR, "incorrect or missing block for 'calling_convention'.\n");
duke@0 1279 }
duke@0 1280 return desc;
duke@0 1281 }
duke@0 1282
duke@0 1283 //------------------------------return_value_parse-----------------------------
duke@0 1284 char *ADLParser::return_value_parse() {
duke@0 1285 char *desc = NULL; // String representation of calling_convention
duke@0 1286
duke@0 1287 skipws(); // Skip leading whitespace
duke@0 1288 if ( (desc = find_cpp_block("return value block")) == NULL ) {
duke@0 1289 parse_err(SYNERR, "incorrect or missing block for 'return_value'.\n");
duke@0 1290 }
duke@0 1291 return desc;
duke@0 1292 }
duke@0 1293
duke@0 1294 //------------------------------ins_pipe_parse---------------------------------
duke@0 1295 void ADLParser::ins_pipe_parse(InstructForm &instr) {
duke@0 1296 char * ident;
duke@0 1297
duke@0 1298 skipws();
duke@0 1299 if ( _curchar != '(' ) { // Check for delimiter
duke@0 1300 parse_err(SYNERR, "missing \"(\" in ins_pipe definition\n");
duke@0 1301 return;
duke@0 1302 }
duke@0 1303
duke@0 1304 next_char();
duke@0 1305 ident = get_ident(); // Grab next identifier
duke@0 1306
duke@0 1307 if (ident == NULL) {
duke@0 1308 parse_err(SYNERR, "keyword identifier expected at %c\n", _curchar);
duke@0 1309 return;
duke@0 1310 }
duke@0 1311
duke@0 1312 skipws();
duke@0 1313 if ( _curchar != ')' ) { // Check for delimiter
duke@0 1314 parse_err(SYNERR, "missing \")\" in ins_pipe definition\n");
duke@0 1315 return;
duke@0 1316 }
duke@0 1317
duke@0 1318 next_char(); // skip the close paren
duke@0 1319 if(_curchar != ';') { // check for semi-colon
duke@0 1320 parse_err(SYNERR, "missing %c in return value entry.\n", ';');
duke@0 1321 return;
duke@0 1322 }
duke@0 1323 next_char(); // skip the semi-colon
duke@0 1324
duke@0 1325 // Check ident for validity
duke@0 1326 if (_AD._pipeline && !_AD._pipeline->_classlist.search(ident)) {
duke@0 1327 parse_err(SYNERR, "\"%s\" is not a valid pipeline class\n", ident);
duke@0 1328 return;
duke@0 1329 }
duke@0 1330
duke@0 1331 // Add this instruction to the list in the pipeline class
duke@0 1332 _AD._pipeline->_classdict[ident]->is_pipeclass()->_instructs.addName(instr._ident);
duke@0 1333
duke@0 1334 // Set the name of the pipeline class in the instruction
duke@0 1335 instr._ins_pipe = ident;
duke@0 1336 return;
duke@0 1337 }
duke@0 1338
duke@0 1339 //------------------------------pipe_parse-------------------------------------
duke@0 1340 void ADLParser::pipe_parse(void) {
duke@0 1341 PipelineForm *pipeline; // Encode class for instruction/operand
duke@0 1342 char * ident;
duke@0 1343
duke@0 1344 pipeline = new PipelineForm(); // Build new Source object
duke@0 1345 _AD.addForm(pipeline);
duke@0 1346
duke@0 1347 skipws(); // Skip leading whitespace
duke@0 1348 // Check for block delimiter
duke@0 1349 if ( (_curchar != '%')
duke@0 1350 || ( next_char(), (_curchar != '{')) ) {
duke@0 1351 parse_err(SYNERR, "missing '%{' in pipeline definition\n");
duke@0 1352 return;
duke@0 1353 }
duke@0 1354 next_char(); // Maintain the invariant
duke@0 1355 do {
duke@0 1356 ident = get_ident(); // Grab next identifier
duke@0 1357 if (ident == NULL) {
duke@0 1358 parse_err(SYNERR, "keyword identifier expected at %c\n", _curchar);
duke@0 1359 continue;
duke@0 1360 }
duke@0 1361 if (!strcmp(ident, "resources" )) resource_parse(*pipeline);
duke@0 1362 else if (!strcmp(ident, "pipe_desc" )) pipe_desc_parse(*pipeline);
duke@0 1363 else if (!strcmp(ident, "pipe_class")) pipe_class_parse(*pipeline);
duke@0 1364 else if (!strcmp(ident, "define")) {
duke@0 1365 skipws();
duke@0 1366 if ( (_curchar != '%')
duke@0 1367 || ( next_char(), (_curchar != '{')) ) {
duke@0 1368 parse_err(SYNERR, "expected '%{'\n");
duke@0 1369 return;
duke@0 1370 }
duke@0 1371 next_char(); skipws();
duke@0 1372
duke@0 1373 char *node_class = get_ident();
duke@0 1374 if (node_class == NULL) {
duke@0 1375 parse_err(SYNERR, "expected identifier, found \"%c\"\n", _curchar);
duke@0 1376 return;
duke@0 1377 }
duke@0 1378
duke@0 1379 skipws();
duke@0 1380 if (_curchar != ',' && _curchar != '=') {
duke@0 1381 parse_err(SYNERR, "expected `=`, found '%c'\n", _curchar);
duke@0 1382 break;
duke@0 1383 }
duke@0 1384 next_char(); skipws();
duke@0 1385
duke@0 1386 char *pipe_class = get_ident();
duke@0 1387 if (pipe_class == NULL) {
duke@0 1388 parse_err(SYNERR, "expected identifier, found \"%c\"\n", _curchar);
duke@0 1389 return;
duke@0 1390 }
duke@0 1391 if (_curchar != ';' ) {
duke@0 1392 parse_err(SYNERR, "expected `;`, found '%c'\n", _curchar);
duke@0 1393 break;
duke@0 1394 }
duke@0 1395 next_char(); // Skip over semi-colon
duke@0 1396
duke@0 1397 skipws();
duke@0 1398 if ( (_curchar != '%')
duke@0 1399 || ( next_char(), (_curchar != '}')) ) {
duke@0 1400 parse_err(SYNERR, "expected '%%}', found \"%c\"\n", _curchar);
duke@0 1401 }
duke@0 1402 next_char();
duke@0 1403
duke@0 1404 // Check ident for validity
duke@0 1405 if (_AD._pipeline && !_AD._pipeline->_classlist.search(pipe_class)) {
duke@0 1406 parse_err(SYNERR, "\"%s\" is not a valid pipeline class\n", pipe_class);
duke@0 1407 return;
duke@0 1408 }
duke@0 1409
duke@0 1410 // Add this machine node to the list in the pipeline class
duke@0 1411 _AD._pipeline->_classdict[pipe_class]->is_pipeclass()->_instructs.addName(node_class);
duke@0 1412
duke@0 1413 MachNodeForm *machnode = new MachNodeForm(node_class); // Create new machnode form
duke@0 1414 machnode->_machnode_pipe = pipe_class;
duke@0 1415
duke@0 1416 _AD.addForm(machnode);
duke@0 1417 }
duke@0 1418 else if (!strcmp(ident, "attributes")) {
duke@0 1419 bool vsi_seen = false, bhds_seen = false;
duke@0 1420
duke@0 1421 skipws();
duke@0 1422 if ( (_curchar != '%')
duke@0 1423 || ( next_char(), (_curchar != '{')) ) {
duke@0 1424 parse_err(SYNERR, "expected '%{'\n");
duke@0 1425 return;
duke@0 1426 }
duke@0 1427 next_char(); skipws();
duke@0 1428
duke@0 1429 while (_curchar != '%') {
duke@0 1430 ident = get_ident();
duke@0 1431 if (ident == NULL)
duke@0 1432 break;
duke@0 1433
duke@0 1434 if (!strcmp(ident, "variable_size_instructions")) {
duke@0 1435 skipws();
duke@0 1436 if (_curchar == ';') {
duke@0 1437 next_char(); skipws();
duke@0 1438 }
duke@0 1439
duke@0 1440 pipeline->_variableSizeInstrs = true;
duke@0 1441 vsi_seen = true;
duke@0 1442 continue;
duke@0 1443 }
duke@0 1444
duke@0 1445 if (!strcmp(ident, "fixed_size_instructions")) {
duke@0 1446 skipws();
duke@0 1447 if (_curchar == ';') {
duke@0 1448 next_char(); skipws();
duke@0 1449 }
duke@0 1450
duke@0 1451 pipeline->_variableSizeInstrs = false;
duke@0 1452 vsi_seen = true;
duke@0 1453 continue;
duke@0 1454 }
duke@0 1455
duke@0 1456 if (!strcmp(ident, "branch_has_delay_slot")) {
duke@0 1457 skipws();
duke@0 1458 if (_curchar == ';') {
duke@0 1459 next_char(); skipws();
duke@0 1460 }
duke@0 1461
duke@0 1462 pipeline->_branchHasDelaySlot = true;
duke@0 1463 bhds_seen = true;
duke@0 1464 continue;
duke@0 1465 }
duke@0 1466
duke@0 1467 if (!strcmp(ident, "max_instructions_per_bundle")) {
duke@0 1468 skipws();
duke@0 1469 if (_curchar != '=') {
duke@0 1470 parse_err(SYNERR, "expected `=`\n");
duke@0 1471 break;
duke@0 1472 }
duke@0 1473
duke@0 1474 next_char(); skipws();
duke@0 1475 pipeline->_maxInstrsPerBundle = get_int();
duke@0 1476 skipws();
duke@0 1477
duke@0 1478 if (_curchar == ';') {
duke@0 1479 next_char(); skipws();
duke@0 1480 }
duke@0 1481
duke@0 1482 continue;
duke@0 1483 }
duke@0 1484
duke@0 1485 if (!strcmp(ident, "max_bundles_per_cycle")) {
duke@0 1486 skipws();
duke@0 1487 if (_curchar != '=') {
duke@0 1488 parse_err(SYNERR, "expected `=`\n");
duke@0 1489 break;
duke@0 1490 }
duke@0 1491
duke@0 1492 next_char(); skipws();
duke@0 1493 pipeline->_maxBundlesPerCycle = get_int();
duke@0 1494 skipws();
duke@0 1495
duke@0 1496 if (_curchar == ';') {
duke@0 1497 next_char(); skipws();
duke@0 1498 }
duke@0 1499
duke@0 1500 continue;
duke@0 1501 }
duke@0 1502
duke@0 1503 if (!strcmp(ident, "instruction_unit_size")) {
duke@0 1504 skipws();
duke@0 1505 if (_curchar != '=') {
duke@0 1506 parse_err(SYNERR, "expected `=`, found '%c'\n", _curchar);
duke@0 1507 break;
duke@0 1508 }
duke@0 1509
duke@0 1510 next_char(); skipws();
duke@0 1511 pipeline->_instrUnitSize = get_int();
duke@0 1512 skipws();
duke@0 1513
duke@0 1514 if (_curchar == ';') {
duke@0 1515 next_char(); skipws();
duke@0 1516 }
duke@0 1517
duke@0 1518 continue;
duke@0 1519 }
duke@0 1520
duke@0 1521 if (!strcmp(ident, "bundle_unit_size")) {
duke@0 1522 skipws();
duke@0 1523 if (_curchar != '=') {
duke@0 1524 parse_err(SYNERR, "expected `=`, found '%c'\n", _curchar);
duke@0 1525 break;
duke@0 1526 }
duke@0 1527
duke@0 1528 next_char(); skipws();
duke@0 1529 pipeline->_bundleUnitSize = get_int();
duke@0 1530 skipws();
duke@0 1531
duke@0 1532 if (_curchar == ';') {
duke@0 1533 next_char(); skipws();
duke@0 1534 }
duke@0 1535
duke@0 1536 continue;
duke@0 1537 }
duke@0 1538
duke@0 1539 if (!strcmp(ident, "instruction_fetch_unit_size")) {
duke@0 1540 skipws();
duke@0 1541 if (_curchar != '=') {
duke@0 1542 parse_err(SYNERR, "expected `=`, found '%c'\n", _curchar);
duke@0 1543 break;
duke@0 1544 }
duke@0 1545
duke@0 1546 next_char(); skipws();
duke@0 1547 pipeline->_instrFetchUnitSize = get_int();
duke@0 1548 skipws();
duke@0 1549
duke@0 1550 if (_curchar == ';') {
duke@0 1551 next_char(); skipws();
duke@0 1552 }
duke@0 1553
duke@0 1554 continue;
duke@0 1555 }
duke@0 1556
duke@0 1557 if (!strcmp(ident, "instruction_fetch_units")) {
duke@0 1558 skipws();
duke@0 1559 if (_curchar != '=') {
duke@0 1560 parse_err(SYNERR, "expected `=`, found '%c'\n", _curchar);
duke@0 1561 break;
duke@0 1562 }
duke@0 1563
duke@0 1564 next_char(); skipws();
duke@0 1565 pipeline->_instrFetchUnits = get_int();
duke@0 1566 skipws();
duke@0 1567
duke@0 1568 if (_curchar == ';') {
duke@0 1569 next_char(); skipws();
duke@0 1570 }
duke@0 1571
duke@0 1572 continue;
duke@0 1573 }
duke@0 1574
duke@0 1575 if (!strcmp(ident, "nops")) {
duke@0 1576 skipws();
duke@0 1577 if (_curchar != '(') {
duke@0 1578 parse_err(SYNERR, "expected `(`, found '%c'\n", _curchar);
duke@0 1579 break;
duke@0 1580 }
duke@0 1581
duke@0 1582 next_char(); skipws();
duke@0 1583
duke@0 1584 while (_curchar != ')') {
duke@0 1585 ident = get_ident();
duke@0 1586 if (ident == NULL) {
duke@0 1587 parse_err(SYNERR, "expected identifier for nop instruction, found '%c'\n", _curchar);
duke@0 1588 break;
duke@0 1589 }
duke@0 1590
duke@0 1591 pipeline->_noplist.addName(ident);
duke@0 1592 pipeline->_nopcnt++;
duke@0 1593 skipws();
duke@0 1594
duke@0 1595 if (_curchar == ',') {
duke@0 1596 next_char(); skipws();
duke@0 1597 }
duke@0 1598 }
duke@0 1599
duke@0 1600 next_char(); skipws();
duke@0 1601
duke@0 1602 if (_curchar == ';') {
duke@0 1603 next_char(); skipws();
duke@0 1604 }
duke@0 1605
duke@0 1606 continue;
duke@0 1607 }
duke@0 1608
duke@0 1609 parse_err(SYNERR, "unknown specifier \"%s\"\n", ident);
duke@0 1610 }
duke@0 1611
duke@0 1612 if ( (_curchar != '%')
duke@0 1613 || ( next_char(), (_curchar != '}')) ) {
duke@0 1614 parse_err(SYNERR, "expected '%}', found \"%c\"\n", _curchar);
duke@0 1615 }
duke@0 1616 next_char(); skipws();
duke@0 1617
duke@0 1618 if (pipeline->_maxInstrsPerBundle == 0)
duke@0 1619 parse_err(SYNERR, "\"max_instructions_per_bundle\" unspecified\n");
duke@0 1620 if (pipeline->_instrUnitSize == 0 && pipeline->_bundleUnitSize == 0)
duke@0 1621 parse_err(SYNERR, "\"instruction_unit_size\" and \"bundle_unit_size\" unspecified\n");
duke@0 1622 if (pipeline->_instrFetchUnitSize == 0)
duke@0 1623 parse_err(SYNERR, "\"instruction_fetch_unit_size\" unspecified\n");
duke@0 1624 if (pipeline->_instrFetchUnits == 0)
duke@0 1625 parse_err(SYNERR, "\"instruction_fetch_units\" unspecified\n");
duke@0 1626 if (!vsi_seen)
duke@0 1627 parse_err(SYNERR, "\"variable_size_instruction\" or \"fixed_size_instruction\" unspecified\n");
duke@0 1628 }
duke@0 1629 else { // Done with staticly defined parts of instruction definition
duke@0 1630 parse_err(SYNERR, "expected one of \"resources\", \"pipe_desc\", \"pipe_class\", found \"%s\"\n", ident);
duke@0 1631 return;
duke@0 1632 }
duke@0 1633 skipws();
duke@0 1634 if (_curchar == ';')
duke@0 1635 skipws();
duke@0 1636 } while(_curchar != '%');
duke@0 1637
duke@0 1638 next_char();
duke@0 1639 if (_curchar != '}') {
duke@0 1640 parse_err(SYNERR, "missing \"%}\" in pipeline definition\n");
duke@0 1641 return;
duke@0 1642 }
duke@0 1643
duke@0 1644 next_char();
duke@0 1645 }
duke@0 1646
duke@0 1647 //------------------------------resource_parse----------------------------
duke@0 1648 void ADLParser::resource_parse(PipelineForm &pipeline) {
duke@0 1649 ResourceForm *resource;
duke@0 1650 char * ident;
duke@0 1651 char * expr;
duke@0 1652 unsigned mask;
duke@0 1653 pipeline._rescount = 0;
duke@0 1654
duke@0 1655 skipws(); // Skip leading whitespace
duke@0 1656
duke@0 1657 if (_curchar != '(') {
duke@0 1658 parse_err(SYNERR, "missing \"(\" in resource definition\n");
duke@0 1659 return;
duke@0 1660 }
duke@0 1661
duke@0 1662 do {
duke@0 1663 next_char(); // Skip "(" or ","
duke@0 1664 ident = get_ident(); // Grab next identifier
duke@0 1665
duke@0 1666 if (ident == NULL) {
duke@0 1667 parse_err(SYNERR, "keyword identifier expected at \"%c\"\n", _curchar);
duke@0 1668 return;
duke@0 1669 }
duke@0 1670 skipws();
duke@0 1671
duke@0 1672 if (_curchar != '=') {
duke@0 1673 mask = (1 << pipeline._rescount++);
duke@0 1674 }
duke@0 1675 else {
duke@0 1676 next_char(); skipws();
duke@0 1677 expr = get_ident(); // Grab next identifier
duke@0 1678 if (expr == NULL) {
duke@0 1679 parse_err(SYNERR, "keyword identifier expected at \"%c\"\n", _curchar);
duke@0 1680 return;
duke@0 1681 }
duke@0 1682 resource = (ResourceForm *) pipeline._resdict[expr];
duke@0 1683 if (resource == NULL) {
duke@0 1684 parse_err(SYNERR, "resource \"%s\" is not defined\n", expr);
duke@0 1685 return;
duke@0 1686 }
duke@0 1687 mask = resource->mask();
duke@0 1688
duke@0 1689 skipws();
duke@0 1690 while (_curchar == '|') {
duke@0 1691 next_char(); skipws();
duke@0 1692
duke@0 1693 expr = get_ident(); // Grab next identifier
duke@0 1694 if (expr == NULL) {
duke@0 1695 parse_err(SYNERR, "keyword identifier expected at \"%c\"\n", _curchar);
duke@0 1696 return;
duke@0 1697 }
duke@0 1698
duke@0 1699 resource = (ResourceForm *) pipeline._resdict[expr]; // Look up the value
duke@0 1700 if (resource == NULL) {
duke@0 1701 parse_err(SYNERR, "resource \"%s\" is not defined\n", expr);
duke@0 1702 return;
duke@0 1703 }
duke@0 1704
duke@0 1705 mask |= resource->mask();
duke@0 1706 skipws();
duke@0 1707 }
duke@0 1708 }
duke@0 1709
duke@0 1710 resource = new ResourceForm(mask);
duke@0 1711
duke@0 1712 pipeline._resdict.Insert(ident, resource);
duke@0 1713 pipeline._reslist.addName(ident);
duke@0 1714 } while (_curchar == ',');
duke@0 1715
duke@0 1716 if (_curchar != ')') {
duke@0 1717 parse_err(SYNERR, "\")\" expected at \"%c\"\n", _curchar);
duke@0 1718 return;
duke@0 1719 }
duke@0 1720
duke@0 1721 next_char(); // Skip ")"
duke@0 1722 if (_curchar == ';')
duke@0 1723 next_char(); // Skip ";"
duke@0 1724 }
duke@0 1725
duke@0 1726 //------------------------------resource_parse----------------------------
duke@0 1727 void ADLParser::pipe_desc_parse(PipelineForm &pipeline) {
duke@0 1728 char * ident;
duke@0 1729
duke@0 1730 skipws(); // Skip leading whitespace
duke@0 1731
duke@0 1732 if (_curchar != '(') {
duke@0 1733 parse_err(SYNERR, "missing \"(\" in pipe_desc definition\n");
duke@0 1734 return;
duke@0 1735 }
duke@0 1736
duke@0 1737 do {
duke@0 1738 next_char(); // Skip "(" or ","
duke@0 1739 ident = get_ident(); // Grab next identifier
duke@0 1740 if (ident == NULL) {
duke@0 1741 parse_err(SYNERR, "keyword identifier expected at \"%c\"\n", _curchar);
duke@0 1742 return;
duke@0 1743 }
duke@0 1744
duke@0 1745 // Add the name to the list
duke@0 1746 pipeline._stages.addName(ident);
duke@0 1747 pipeline._stagecnt++;
duke@0 1748
duke@0 1749 skipws();
duke@0 1750 } while (_curchar == ',');
duke@0 1751
duke@0 1752 if (_curchar != ')') {
duke@0 1753 parse_err(SYNERR, "\")\" expected at \"%c\"\n", _curchar);
duke@0 1754 return;
duke@0 1755 }
duke@0 1756
duke@0 1757 next_char(); // Skip ")"
duke@0 1758 if (_curchar == ';')
duke@0 1759 next_char(); // Skip ";"
duke@0 1760 }
duke@0 1761
duke@0 1762 //------------------------------pipe_class_parse--------------------------
duke@0 1763 void ADLParser::pipe_class_parse(PipelineForm &pipeline) {
duke@0 1764 PipeClassForm *pipe_class;
duke@0 1765 char * ident;
duke@0 1766 char * stage;
duke@0 1767 char * read_or_write;
duke@0 1768 int is_write;
duke@0 1769 int is_read;
duke@0 1770 OperandForm *oper;
duke@0 1771
duke@0 1772 skipws(); // Skip leading whitespace
duke@0 1773
duke@0 1774 ident = get_ident(); // Grab next identifier
duke@0 1775
duke@0 1776 if (ident == NULL) {
duke@0 1777 parse_err(SYNERR, "keyword identifier expected at \"%c\"\n", _curchar);
duke@0 1778 return;
duke@0 1779 }
duke@0 1780
duke@0 1781 // Create a record for the pipe_class
duke@0 1782 pipe_class = new PipeClassForm(ident, ++pipeline._classcnt);
duke@0 1783 pipeline._classdict.Insert(ident, pipe_class);
duke@0 1784 pipeline._classlist.addName(ident);
duke@0 1785
duke@0 1786 // Then get the operands
duke@0 1787 skipws();
duke@0 1788 if (_curchar != '(') {
duke@0 1789 parse_err(SYNERR, "missing \"(\" in pipe_class definition\n");
duke@0 1790 }
duke@0 1791 // Parse the operand list
duke@0 1792 else get_oplist(pipe_class->_parameters, pipe_class->_localNames);
duke@0 1793 skipws(); // Skip leading whitespace
duke@0 1794 // Check for block delimiter
duke@0 1795 if ( (_curchar != '%')
duke@0 1796 || ( next_char(), (_curchar != '{')) ) {
duke@0 1797 parse_err(SYNERR, "missing \"%{\" in pipe_class definition\n");
duke@0 1798 return;
duke@0 1799 }
duke@0 1800 next_char();
duke@0 1801
duke@0 1802 do {
duke@0 1803 ident = get_ident(); // Grab next identifier
duke@0 1804 if (ident == NULL) {
duke@0 1805 parse_err(SYNERR, "keyword identifier expected at \"%c\"\n", _curchar);
duke@0 1806 continue;
duke@0 1807 }
duke@0 1808 skipws();
duke@0 1809
duke@0 1810 if (!strcmp(ident, "fixed_latency")) {
duke@0 1811 skipws();
duke@0 1812 if (_curchar != '(') {
duke@0 1813 parse_err(SYNERR, "missing \"(\" in latency definition\n");
duke@0 1814 return;
duke@0 1815 }
duke@0 1816 next_char(); skipws();
duke@0 1817 if( !isdigit(_curchar) ) {
duke@0 1818 parse_err(SYNERR, "number expected for \"%c\" in latency definition\n", _curchar);
duke@0 1819 return;
duke@0 1820 }
duke@0 1821 int fixed_latency = get_int();
duke@0 1822 skipws();
duke@0 1823 if (_curchar != ')') {
duke@0 1824 parse_err(SYNERR, "missing \")\" in latency definition\n");
duke@0 1825 return;
duke@0 1826 }
duke@0 1827 next_char(); skipws();
duke@0 1828 if (_curchar != ';') {
duke@0 1829 parse_err(SYNERR, "missing \";\" in latency definition\n");
duke@0 1830 return;
duke@0 1831 }
duke@0 1832
duke@0 1833 pipe_class->setFixedLatency(fixed_latency);
duke@0 1834 next_char(); skipws();
duke@0 1835 continue;
duke@0 1836 }
duke@0 1837
duke@0 1838 if (!strcmp(ident, "zero_instructions") ||
duke@0 1839 !strcmp(ident, "no_instructions")) {
duke@0 1840 skipws();
duke@0 1841 if (_curchar != ';') {
duke@0 1842 parse_err(SYNERR, "missing \";\" in latency definition\n");
duke@0 1843 return;
duke@0 1844 }
duke@0 1845
duke@0 1846 pipe_class->setInstructionCount(0);
duke@0 1847 next_char(); skipws();
duke@0 1848 continue;
duke@0 1849 }
duke@0 1850
duke@0 1851 if (!strcmp(ident, "one_instruction_with_delay_slot") ||
duke@0 1852 !strcmp(ident, "single_instruction_with_delay_slot")) {
duke@0 1853 skipws();
duke@0 1854 if (_curchar != ';') {
duke@0 1855 parse_err(SYNERR, "missing \";\" in latency definition\n");
duke@0 1856 return;
duke@0 1857 }
duke@0 1858
duke@0 1859 pipe_class->setInstructionCount(1);
duke@0 1860 pipe_class->setBranchDelay(true);
duke@0 1861 next_char(); skipws();
duke@0 1862 continue;
duke@0 1863 }
duke@0 1864
duke@0 1865 if (!strcmp(ident, "one_instruction") ||
duke@0 1866 !strcmp(ident, "single_instruction")) {
duke@0 1867 skipws();
duke@0 1868 if (_curchar != ';') {
duke@0 1869 parse_err(SYNERR, "missing \";\" in latency definition\n");
duke@0 1870 return;
duke@0 1871 }
duke@0 1872
duke@0 1873 pipe_class->setInstructionCount(1);
duke@0 1874 next_char(); skipws();
duke@0 1875 continue;
duke@0 1876 }
duke@0 1877
duke@0 1878 if (!strcmp(ident, "instructions_in_first_bundle") ||
duke@0 1879 !strcmp(ident, "instruction_count")) {
duke@0 1880 skipws();
duke@0 1881
duke@0 1882 int number_of_instructions = 1;
duke@0 1883
duke@0 1884 if (_curchar != '(') {
duke@0 1885 parse_err(SYNERR, "\"(\" expected at \"%c\"\n", _curchar);
duke@0 1886 continue;
duke@0 1887 }
duke@0 1888
duke@0 1889 next_char(); skipws();
duke@0 1890 number_of_instructions = get_int();
duke@0 1891
duke@0 1892 skipws();
duke@0 1893 if (_curchar != ')') {
duke@0 1894 parse_err(SYNERR, "\")\" expected at \"%c\"\n", _curchar);
duke@0 1895 continue;
duke@0 1896 }
duke@0 1897
duke@0 1898 next_char(); skipws();
duke@0 1899 if (_curchar != ';') {
duke@0 1900 parse_err(SYNERR, "missing \";\" in latency definition\n");
duke@0 1901 return;
duke@0 1902 }
duke@0 1903
duke@0 1904 pipe_class->setInstructionCount(number_of_instructions);
duke@0 1905 next_char(); skipws();
duke@0 1906 continue;
duke@0 1907 }
duke@0 1908
duke@0 1909 if (!strcmp(ident, "multiple_bundles")) {
duke@0 1910 skipws();
duke@0 1911 if (_curchar != ';') {
duke@0 1912 parse_err(SYNERR, "missing \";\" after multiple bundles\n");
duke@0 1913 return;
duke@0 1914 }
duke@0 1915
duke@0 1916 pipe_class->setMultipleBundles(true);
duke@0 1917 next_char(); skipws();
duke@0 1918 continue;
duke@0 1919 }
duke@0 1920
duke@0 1921 if (!strcmp(ident, "has_delay_slot")) {
duke@0 1922 skipws();
duke@0 1923 if (_curchar != ';') {
duke@0 1924 parse_err(SYNERR, "missing \";\" after \"has_delay_slot\"\n");
duke@0 1925 return;
duke@0 1926 }
duke@0 1927
duke@0 1928 pipe_class->setBranchDelay(true);
duke@0 1929 next_char(); skipws();
duke@0 1930 continue;
duke@0 1931 }
duke@0 1932
duke@0 1933 if (!strcmp(ident, "force_serialization")) {
duke@0 1934 skipws();
duke@0 1935 if (_curchar != ';') {
duke@0 1936 parse_err(SYNERR, "missing \";\" after \"force_serialization\"\n");
duke@0 1937 return;
duke@0 1938 }
duke@0 1939
duke@0 1940 pipe_class->setForceSerialization(true);
duke@0 1941 next_char(); skipws();
duke@0 1942 continue;
duke@0 1943 }
duke@0 1944
duke@0 1945 if (!strcmp(ident, "may_have_no_code")) {
duke@0 1946 skipws();
duke@0 1947 if (_curchar != ';') {
duke@0 1948 parse_err(SYNERR, "missing \";\" after \"may_have_no_code\"\n");
duke@0 1949 return;
duke@0 1950 }
duke@0 1951
duke@0 1952 pipe_class->setMayHaveNoCode(true);
duke@0 1953 next_char(); skipws();
duke@0 1954 continue;
duke@0 1955 }
duke@0 1956
duke@0 1957 const Form *parm = pipe_class->_localNames[ident];
duke@0 1958 if (parm != NULL) {
duke@0 1959 oper = parm->is_operand();
duke@0 1960 if (oper == NULL && !parm->is_opclass()) {
duke@0 1961 parse_err(SYNERR, "operand name expected at %s\n", ident);
duke@0 1962 continue;
duke@0 1963 }
duke@0 1964
duke@0 1965 if (_curchar != ':') {
duke@0 1966 parse_err(SYNERR, "\":\" expected at \"%c\"\n", _curchar);
duke@0 1967 continue;
duke@0 1968 }
duke@0 1969 next_char(); skipws();
duke@0 1970 stage = get_ident();
duke@0 1971 if (stage == NULL) {
duke@0 1972 parse_err(SYNERR, "pipeline stage identifier expected at \"%c\"\n", _curchar);
duke@0 1973 continue;
duke@0 1974 }
duke@0 1975
duke@0 1976 skipws();
duke@0 1977 if (_curchar != '(') {
duke@0 1978 parse_err(SYNERR, "\"(\" expected at \"%c\"\n", _curchar);
duke@0 1979 continue;
duke@0 1980 }
duke@0 1981
duke@0 1982 next_char();
duke@0 1983 read_or_write = get_ident();
duke@0 1984 if (read_or_write == NULL) {
duke@0 1985 parse_err(SYNERR, "\"read\" or \"write\" expected at \"%c\"\n", _curchar);
duke@0 1986 continue;
duke@0 1987 }
duke@0 1988
duke@0 1989 is_read = strcmp(read_or_write, "read") == 0;
duke@0 1990 is_write = strcmp(read_or_write, "write") == 0;
duke@0 1991 if (!is_read && !is_write) {
duke@0 1992 parse_err(SYNERR, "\"read\" or \"write\" expected at \"%c\"\n", _curchar);
duke@0 1993 continue;
duke@0 1994 }
duke@0 1995
duke@0 1996 skipws();
duke@0 1997 if (_curchar != ')') {
duke@0 1998 parse_err(SYNERR, "\")\" expected at \"%c\"\n", _curchar);
duke@0 1999 continue;
duke@0 2000 }
duke@0 2001
duke@0 2002 next_char(); skipws();
duke@0 2003 int more_instrs = 0;
duke@0 2004 if (_curchar == '+') {
duke@0 2005 next_char(); skipws();
duke@0 2006 if (_curchar < '0' || _curchar > '9') {
duke@0 2007 parse_err(SYNERR, "<number> expected at \"%c\"\n", _curchar);
duke@0 2008 continue;
duke@0 2009 }
duke@0 2010 while (_curchar >= '0' && _curchar <= '9') {
duke@0 2011 more_instrs *= 10;
duke@0 2012 more_instrs += _curchar - '0';
duke@0 2013 next_char();
duke@0 2014 }
duke@0 2015 skipws();
duke@0 2016 }
duke@0 2017
duke@0 2018 PipeClassOperandForm *pipe_operand = new PipeClassOperandForm(stage, is_write, more_instrs);
duke@0 2019 pipe_class->_localUsage.Insert(ident, pipe_operand);
duke@0 2020
duke@0 2021 if (_curchar == '%')
duke@0 2022 continue;
duke@0 2023
duke@0 2024 if (_curchar != ';') {
duke@0 2025 parse_err(SYNERR, "\";\" expected at \"%c\"\n", _curchar);
duke@0 2026 continue;
duke@0 2027 }
duke@0 2028 next_char(); skipws();
duke@0 2029 continue;
duke@0 2030 }
duke@0 2031
duke@0 2032 // Scan for Resource Specifier
duke@0 2033 const Form *res = pipeline._resdict[ident];
duke@0 2034 if (res != NULL) {
duke@0 2035 int cyclecnt = 1;
duke@0 2036 if (_curchar != ':') {
duke@0 2037 parse_err(SYNERR, "\":\" expected at \"%c\"\n", _curchar);
duke@0 2038 continue;
duke@0 2039 }
duke@0 2040 next_char(); skipws();
duke@0 2041 stage = get_ident();
duke@0 2042 if (stage == NULL) {
duke@0 2043 parse_err(SYNERR, "pipeline stage identifier expected at \"%c\"\n", _curchar);
duke@0 2044 continue;
duke@0 2045 }
duke@0 2046
duke@0 2047 skipws();
duke@0 2048 if (_curchar == '(') {
duke@0 2049 next_char();
duke@0 2050 cyclecnt = get_int();
duke@0 2051
duke@0 2052 skipws();
duke@0 2053 if (_curchar != ')') {
duke@0 2054 parse_err(SYNERR, "\")\" expected at \"%c\"\n", _curchar);
duke@0 2055 continue;
duke@0 2056 }
duke@0 2057
duke@0 2058 next_char(); skipws();
duke@0 2059 }
duke@0 2060
duke@0 2061 PipeClassResourceForm *resource = new PipeClassResourceForm(ident, stage, cyclecnt);
duke@0 2062 int stagenum = pipeline._stages.index(stage);
duke@0 2063 if (pipeline._maxcycleused < (stagenum+cyclecnt))
duke@0 2064 pipeline._maxcycleused = (stagenum+cyclecnt);
duke@0 2065 pipe_class->_resUsage.addForm(resource);
duke@0 2066
duke@0 2067 if (_curchar == '%')
duke@0 2068 continue;
duke@0 2069
duke@0 2070 if (_curchar != ';') {
duke@0 2071 parse_err(SYNERR, "\";\" expected at \"%c\"\n", _curchar);
duke@0 2072 continue;
duke@0 2073 }
duke@0 2074 next_char(); skipws();
duke@0 2075 continue;
duke@0 2076 }
duke@0 2077
duke@0 2078 parse_err(SYNERR, "resource expected at \"%s\"\n", ident);
duke@0 2079 return;
duke@0 2080 } while(_curchar != '%');
duke@0 2081
duke@0 2082 next_char();
duke@0 2083 if (_curchar != '}') {
duke@0 2084 parse_err(SYNERR, "missing \"%}\" in pipe_class definition\n");
duke@0 2085 return;
duke@0 2086 }
duke@0 2087
duke@0 2088 next_char();
duke@0 2089 }
duke@0 2090
duke@0 2091 //------------------------------peep_parse-------------------------------------
duke@0 2092 void ADLParser::peep_parse(void) {
duke@0 2093 Peephole *peep; // Pointer to current peephole rule form
duke@0 2094 char *desc = NULL; // String representation of rule
duke@0 2095
duke@0 2096 skipws(); // Skip leading whitespace
duke@0 2097
duke@0 2098 peep = new Peephole(); // Build new Peephole object
duke@0 2099 // Check for open block sequence
duke@0 2100 skipws(); // Skip leading whitespace
duke@0 2101 if (_curchar == '%' && *(_ptr+1) == '{') {
duke@0 2102 next_char(); next_char(); // Skip "%{"
duke@0 2103 skipws();
duke@0 2104 while (_curchar != '%' && *(_ptr+1) != '}') {
duke@0 2105 char *token = get_ident();
duke@0 2106 if (token == NULL) {
duke@0 2107 parse_err(SYNERR, "missing identifier inside peephole rule.\n");
duke@0 2108 return;
duke@0 2109 }
duke@0 2110 // check for legal subsections of peephole rule
duke@0 2111 if (strcmp(token,"peepmatch")==0) {
duke@0 2112 peep_match_parse(*peep); }
duke@0 2113 else if (strcmp(token,"peepconstraint")==0) {
duke@0 2114 peep_constraint_parse(*peep); }
duke@0 2115 else if (strcmp(token,"peepreplace")==0) {
duke@0 2116 peep_replace_parse(*peep); }
duke@0 2117 else {
duke@0 2118 parse_err(SYNERR, "expected peepmatch, peepconstraint, or peepreplace for identifier %s.\n", token);
duke@0 2119 }
duke@0 2120 skipws();
duke@0 2121 }
duke@0 2122 }
duke@0 2123 else {
duke@0 2124 parse_err(SYNERR, "Missing %%{ ... %%} block after peephole keyword.\n");
duke@0 2125 return;
duke@0 2126 }
duke@0 2127 next_char(); // Skip past '%'
duke@0 2128 next_char(); // Skip past '}'
duke@0 2129 }
duke@0 2130
duke@0 2131 // ******************** Private Level 2 Parse Functions ********************
duke@0 2132 //------------------------------constraint_parse------------------------------
duke@0 2133 Constraint *ADLParser::constraint_parse(void) {
duke@0 2134 char *func;
duke@0 2135 char *arg;
duke@0 2136
duke@0 2137 // Check for constraint expression
duke@0 2138 skipws();
duke@0 2139 if (_curchar != '(') {
duke@0 2140 parse_err(SYNERR, "missing constraint expression, (...)\n");
duke@0 2141 return NULL;
duke@0 2142 }
duke@0 2143 next_char(); // Skip past '('
duke@0 2144
duke@0 2145 // Get constraint function
duke@0 2146 skipws();
duke@0 2147 func = get_ident();
duke@0 2148 if (func == NULL) {
duke@0 2149 parse_err(SYNERR, "missing function in constraint expression.\n");
duke@0 2150 return NULL;
duke@0 2151 }
duke@0 2152 if (strcmp(func,"ALLOC_IN_RC")==0
duke@0 2153 || strcmp(func,"IS_R_CLASS")==0) {
duke@0 2154 // Check for '(' before argument
duke@0 2155 skipws();
duke@0 2156 if (_curchar != '(') {
duke@0 2157 parse_err(SYNERR, "missing '(' for constraint function's argument.\n");
duke@0 2158 return NULL;
duke@0 2159 }
duke@0 2160 next_char();
duke@0 2161
duke@0 2162 // Get it's argument
duke@0 2163 skipws();
duke@0 2164 arg = get_ident();
duke@0 2165 if (arg == NULL) {
duke@0 2166 parse_err(SYNERR, "missing argument for constraint function %s\n",func);
duke@0 2167 return NULL;
duke@0 2168 }
duke@0 2169 // Check for ')' after argument
duke@0 2170 skipws();
duke@0 2171 if (_curchar != ')') {
duke@0 2172 parse_err(SYNERR, "missing ')' after constraint function argument %s\n",arg);
duke@0 2173 return NULL;
duke@0 2174 }
duke@0 2175 next_char();
duke@0 2176 } else {
duke@0 2177 parse_err(SYNERR, "Invalid constraint function %s\n",func);
duke@0 2178 return NULL;
duke@0 2179 }
duke@0 2180
duke@0 2181 // Check for closing paren and ';'
duke@0 2182 skipws();
duke@0 2183 if (_curchar != ')') {
duke@0 2184 parse_err(SYNERR, "Missing ')' for constraint function %s\n",func);
duke@0 2185 return NULL;
duke@0 2186 }
duke@0 2187 next_char();
duke@0 2188 skipws();
duke@0 2189 if (_curchar != ';') {
duke@0 2190 parse_err(SYNERR, "Missing ';' after constraint.\n");
duke@0 2191 return NULL;
duke@0 2192 }
duke@0 2193 next_char();
duke@0 2194
duke@0 2195 // Create new "Constraint"
duke@0 2196 Constraint *constraint = new Constraint(func,arg);
duke@0 2197 return constraint;
duke@0 2198 }
duke@0 2199
duke@0 2200 //------------------------------constr_parse-----------------------------------
duke@0 2201 ConstructRule *ADLParser::construct_parse(void) {
duke@0 2202 return NULL;
duke@0 2203 }
duke@0 2204
duke@0 2205
duke@0 2206 //------------------------------reg_def_parse----------------------------------
duke@0 2207 void ADLParser::reg_def_parse(void) {
duke@0 2208 char *rname; // Name of register being defined
duke@0 2209
duke@0 2210 // Get register name
duke@0 2211 skipws(); // Skip whitespace
duke@0 2212 rname = get_ident();
duke@0 2213 if (rname == NULL) {
duke@0 2214 parse_err(SYNERR, "missing register name after reg_def\n");
duke@0 2215 return;
duke@0 2216 }
duke@0 2217
duke@0 2218 // Check for definition of register calling convention (save on call, ...),
duke@0 2219 // register save type, and register encoding value.
duke@0 2220 skipws();
duke@0 2221 char *callconv = NULL;
duke@0 2222 char *c_conv = NULL;
duke@0 2223 char *idealtype = NULL;
duke@0 2224 char *encoding = NULL;
duke@0 2225 char *concrete = NULL;
duke@0 2226 if (_curchar == '(') {
duke@0 2227 next_char();
duke@0 2228 callconv = get_ident();
duke@0 2229 // Parse the internal calling convention, must be NS, SOC, SOE, or AS.
duke@0 2230 if (callconv == NULL) {
duke@0 2231 parse_err(SYNERR, "missing register calling convention value\n");
duke@0 2232 return;
duke@0 2233 }
duke@0 2234 if(strcmp(callconv, "SOC") && strcmp(callconv,"SOE") &&
duke@0 2235 strcmp(callconv, "NS") && strcmp(callconv, "AS")) {
duke@0 2236 parse_err(SYNERR, "invalid value for register calling convention\n");
duke@0 2237 }
duke@0 2238 skipws();
duke@0 2239 if (_curchar != ',') {
duke@0 2240 parse_err(SYNERR, "missing comma in register definition statement\n");
duke@0 2241 return;
duke@0 2242 }
duke@0 2243 next_char();
duke@0 2244
duke@0 2245 // Parse the native calling convention, must be NS, SOC, SOE, AS
duke@0 2246 c_conv = get_ident();
duke@0 2247 if (c_conv == NULL) {
duke@0 2248 parse_err(SYNERR, "missing register native calling convention value\n");
duke@0 2249 return;
duke@0 2250 }
duke@0 2251 if(strcmp(c_conv, "SOC") && strcmp(c_conv,"SOE") &&
duke@0 2252 strcmp(c_conv, "NS") && strcmp(c_conv, "AS")) {
duke@0 2253 parse_err(SYNERR, "invalid value for register calling convention\n");
duke@0 2254 }
duke@0 2255 skipws();
duke@0 2256 if (_curchar != ',') {
duke@0 2257 parse_err(SYNERR, "missing comma in register definition statement\n");
duke@0 2258 return;
duke@0 2259 }
duke@0 2260 next_char();
duke@0 2261 skipws();
duke@0 2262
duke@0 2263 // Parse the ideal save type
duke@0 2264 idealtype = get_ident();
duke@0 2265 if (idealtype == NULL) {
duke@0 2266 parse_err(SYNERR, "missing register save type value\n");
duke@0 2267 return;
duke@0 2268 }
duke@0 2269 skipws();
duke@0 2270 if (_curchar != ',') {
duke@0 2271 parse_err(SYNERR, "missing comma in register definition statement\n");
duke@0 2272 return;
duke@0 2273 }
duke@0 2274 next_char();
duke@0 2275 skipws();
duke@0 2276
duke@0 2277 // Parse the encoding value
duke@0 2278 encoding = get_expr("encoding", ",");
duke@0 2279 if (encoding == NULL) {
duke@0 2280 parse_err(SYNERR, "missing register encoding value\n");
duke@0 2281 return;
duke@0 2282 }
duke@0 2283 trim(encoding);
duke@0 2284 if (_curchar != ',') {
duke@0 2285 parse_err(SYNERR, "missing comma in register definition statement\n");
duke@0 2286 return;
duke@0 2287 }
duke@0 2288 next_char();
duke@0 2289 skipws();
duke@0 2290 // Parse the concrete name type
duke@0 2291 // concrete = get_ident();
duke@0 2292 concrete = get_expr("concrete", ")");
duke@0 2293 if (concrete == NULL) {
duke@0 2294 parse_err(SYNERR, "missing vm register name value\n");
duke@0 2295 return;
duke@0 2296 }
duke@0 2297
duke@0 2298 if (_curchar != ')') {
duke@0 2299 parse_err(SYNERR, "missing ')' in register definition statement\n");
duke@0 2300 return;
duke@0 2301 }
duke@0 2302 next_char();
duke@0 2303 }
duke@0 2304
duke@0 2305 // Check for closing ';'
duke@0 2306 skipws();
duke@0 2307 if (_curchar != ';') {
duke@0 2308 parse_err(SYNERR, "missing ';' after reg_def\n");
duke@0 2309 return;
duke@0 2310 }
duke@0 2311 next_char(); // move past ';'
duke@0 2312
duke@0 2313 // Debug Stuff
duke@0 2314 if (_AD._adl_debug > 1) {
duke@0 2315 fprintf(stderr,"Register Definition: %s ( %s, %s %s )\n", rname,
duke@0 2316 (callconv ? callconv : ""), (c_conv ? c_conv : ""), concrete);
duke@0 2317 }
duke@0 2318
duke@0 2319 // Record new register definition.
duke@0 2320 _AD._register->addRegDef(rname, callconv, c_conv, idealtype, encoding, concrete);
duke@0 2321 return;
duke@0 2322 }
duke@0 2323
duke@0 2324 //------------------------------reg_class_parse--------------------------------
duke@0 2325 void ADLParser::reg_class_parse(void) {
duke@0 2326 char *cname; // Name of register class being defined
duke@0 2327
duke@0 2328 // Get register class name
duke@0 2329 skipws(); // Skip leading whitespace
duke@0 2330 cname = get_ident();
duke@0 2331 if (cname == NULL) {
duke@0 2332 parse_err(SYNERR, "missing register class name after 'reg_class'\n");
duke@0 2333 return;
duke@0 2334 }
duke@0 2335 // Debug Stuff
duke@0 2336 if (_AD._adl_debug >1) fprintf(stderr,"Register Class: %s\n", cname);
duke@0 2337
duke@0 2338 RegClass *reg_class = _AD._register->addRegClass(cname);
duke@0 2339
duke@0 2340 // Collect registers in class
duke@0 2341 skipws();
duke@0 2342 if (_curchar == '(') {
duke@0 2343 next_char(); // Skip '('
duke@0 2344 skipws();
duke@0 2345 while (_curchar != ')') {
duke@0 2346 char *rname = get_ident();
duke@0 2347 if (rname==NULL) {
duke@0 2348 parse_err(SYNERR, "missing identifier inside reg_class list.\n");
duke@0 2349 return;
duke@0 2350 }
duke@0 2351 RegDef *regDef = _AD._register->getRegDef(rname);
duke@0 2352 reg_class->addReg(regDef); // add regDef to regClass
duke@0 2353
duke@0 2354 // Check for ',' and position to next token.
duke@0 2355 skipws();
duke@0 2356 if (_curchar == ',') {
duke@0 2357 next_char(); // Skip trailing ','
duke@0 2358 skipws();
duke@0 2359 }
duke@0 2360 }
duke@0 2361 next_char(); // Skip closing ')'
duke@0 2362 }
duke@0 2363
duke@0 2364 // Check for terminating ';'
duke@0 2365 skipws();
duke@0 2366 if (_curchar != ';') {
duke@0 2367 parse_err(SYNERR, "missing ';' at end of reg_class definition.\n");
duke@0 2368 return;
duke@0 2369 }
duke@0 2370 next_char(); // Skip trailing ';'
duke@0 2371
duke@0 2372 // Check RegClass size, must be <= 32 registers in class.
duke@0 2373
duke@0 2374 return;
duke@0 2375 }
duke@0 2376
duke@0 2377 //------------------------------alloc_class_parse------------------------------
duke@0 2378 void ADLParser::alloc_class_parse(void) {
duke@0 2379 char *name; // Name of allocation class being defined
duke@0 2380
duke@0 2381 // Get allocation class name
duke@0 2382 skipws(); // Skip leading whitespace
duke@0 2383 name = get_ident();
duke@0 2384 if (name == NULL) {
duke@0 2385 parse_err(SYNERR, "missing allocation class name after 'reg_class'\n");
duke@0 2386 return;
duke@0 2387 }
duke@0 2388 // Debug Stuff
duke@0 2389 if (_AD._adl_debug >1) fprintf(stderr,"Allocation Class: %s\n", name);
duke@0 2390
duke@0 2391 AllocClass *alloc_class = _AD._register->addAllocClass(name);
duke@0 2392
duke@0 2393 // Collect registers in class
duke@0 2394 skipws();
duke@0 2395 if (_curchar == '(') {
duke@0 2396 next_char(); // Skip '('
duke@0 2397 skipws();
duke@0 2398 while (_curchar != ')') {
duke@0 2399 char *rname = get_ident();
duke@0 2400 if (rname==NULL) {
duke@0 2401 parse_err(SYNERR, "missing identifier inside reg_class list.\n");
duke@0 2402 return;
duke@0 2403 }
duke@0 2404 // Check if name is a RegDef
duke@0 2405 RegDef *regDef = _AD._register->getRegDef(rname);
duke@0 2406 if (regDef) {
duke@0 2407 alloc_class->addReg(regDef); // add regDef to allocClass
duke@0 2408 } else {
duke@0 2409
duke@0 2410 // name must be a RegDef or a RegClass
duke@0 2411 parse_err(SYNERR, "name %s should be a previously defined reg_def.\n", rname);
duke@0 2412 return;
duke@0 2413 }
duke@0 2414
duke@0 2415 // Check for ',' and position to next token.
duke@0 2416 skipws();
duke@0 2417 if (_curchar == ',') {
duke@0 2418 next_char(); // Skip trailing ','
duke@0 2419 skipws();
duke@0 2420 }
duke@0 2421 }
duke@0 2422 next_char(); // Skip closing ')'
duke@0 2423 }
duke@0 2424
duke@0 2425 // Check for terminating ';'
duke@0 2426 skipws();
duke@0 2427 if (_curchar != ';') {
duke@0 2428 parse_err(SYNERR, "missing ';' at end of reg_class definition.\n");
duke@0 2429 return;
duke@0 2430 }
duke@0 2431 next_char(); // Skip trailing ';'
duke@0 2432
duke@0 2433 return;
duke@0 2434 }
duke@0 2435
duke@0 2436 //------------------------------peep_match_child_parse-------------------------
duke@0 2437 InstructForm *ADLParser::peep_match_child_parse(PeepMatch &match, int parent, int &position, int input){
duke@0 2438 char *token = NULL;
duke@0 2439 int lparen = 0; // keep track of parenthesis nesting depth
duke@0 2440 int rparen = 0; // position of instruction at this depth
duke@0 2441 InstructForm *inst_seen = NULL;
duke@0 2442 InstructForm *child_seen = NULL;
duke@0 2443
duke@0 2444 // Walk the match tree,
duke@0 2445 // Record <parent, position, instruction name, input position>
duke@0 2446 while ( lparen >= rparen ) {
duke@0 2447 skipws();
duke@0 2448 // Left paren signals start of an input, collect with recursive call
duke@0 2449 if (_curchar == '(') {
duke@0 2450 ++lparen;
duke@0 2451 next_char();
duke@0 2452 child_seen = peep_match_child_parse(match, parent, position, rparen);
duke@0 2453 }
duke@0 2454 // Right paren signals end of an input, may be more
duke@0 2455 else if (_curchar == ')') {
duke@0 2456 ++rparen;
duke@0 2457 if( rparen == lparen ) { // IF rparen matches an lparen I've seen
duke@0 2458 next_char(); // move past ')'
duke@0 2459 } else { // ELSE leave ')' for parent
duke@0 2460 assert( rparen == lparen + 1, "Should only see one extra ')'");
duke@0 2461 // if an instruction was not specified for this paren-pair
duke@0 2462 if( ! inst_seen ) { // record signal entry
duke@0 2463 match.add_instruction( parent, position, NameList::_signal, input );
duke@0 2464 ++position;
duke@0 2465 }
duke@0 2466 // ++input; // TEMPORARY
duke@0 2467 return inst_seen;
duke@0 2468 }
duke@0 2469 }
duke@0 2470 // if no parens, then check for instruction name
duke@0 2471 // This instruction is the parent of a sub-tree
duke@0 2472 else if ((token = get_ident_dup()) != NULL) {
duke@0 2473 const Form *form = _AD._globalNames[token];
duke@0 2474 if (form) {
duke@0 2475 InstructForm *inst = form->is_instruction();
duke@0 2476 // Record the first instruction at this level
duke@0 2477 if( inst_seen == NULL ) {
duke@0 2478 inst_seen = inst;
duke@0 2479 }
duke@0 2480 if (inst) {
duke@0 2481 match.add_instruction( parent, position, token, input );
duke@0 2482 parent = position;
duke@0 2483 ++position;
duke@0 2484 } else {
duke@0 2485 parse_err(SYNERR, "instruction name expected at identifier %s.\n",
duke@0 2486 token);
duke@0 2487 return inst_seen;
duke@0 2488 }
duke@0 2489 }
duke@0 2490 else {
duke@0 2491 parse_err(SYNERR, "missing identifier in peepmatch rule.\n");
duke@0 2492 return NULL;
duke@0 2493 }
duke@0 2494 }
duke@0 2495 else {
duke@0 2496 parse_err(SYNERR, "missing identifier in peepmatch rule.\n");
duke@0 2497 return NULL;
duke@0 2498 }
duke@0 2499
duke@0 2500 } // end while
duke@0 2501
duke@0 2502 assert( false, "ShouldNotReachHere();");
duke@0 2503 return NULL;
duke@0 2504 }
duke@0 2505
duke@0 2506 //------------------------------peep_match_parse-------------------------------
duke@0 2507 // Syntax for a peepmatch rule
duke@0 2508 //
duke@0 2509 // peepmatch ( root_instr_name [(instruction subtree)] [,(instruction subtree)]* );
duke@0 2510 //
duke@0 2511 void ADLParser::peep_match_parse(Peephole &peep) {
duke@0 2512
duke@0 2513 skipws();
duke@0 2514 // Check the structure of the rule
duke@0 2515 // Check for open paren
duke@0 2516 if (_curchar != '(') {
duke@0 2517 parse_err(SYNERR, "missing '(' at start of peepmatch rule.\n");
duke@0 2518 return;
duke@0 2519 }
duke@0 2520 next_char(); // skip '('
duke@0 2521
duke@0 2522 // Construct PeepMatch and parse the peepmatch rule.
duke@0 2523 PeepMatch *match = new PeepMatch(_ptr);
duke@0 2524 int parent = -1; // parent of root
duke@0 2525 int position = 0; // zero-based positions
duke@0 2526 int input = 0; // input position in parent's operands
duke@0 2527 InstructForm *root= peep_match_child_parse( *match, parent, position, input);
duke@0 2528 if( root == NULL ) {
duke@0 2529 parse_err(SYNERR, "missing instruction-name at start of peepmatch.\n");
duke@0 2530 return;
duke@0 2531 }
duke@0 2532
duke@0 2533 if( _curchar != ')' ) {
duke@0 2534 parse_err(SYNERR, "missing ')' at end of peepmatch.\n");
duke@0 2535 return;
duke@0 2536 }
duke@0 2537 next_char(); // skip ')'
duke@0 2538
duke@0 2539 // Check for closing semicolon
duke@0 2540 skipws();
duke@0 2541 if( _curchar != ';' ) {
duke@0 2542 parse_err(SYNERR, "missing ';' at end of peepmatch.\n");
duke@0 2543 return;
duke@0 2544 }
duke@0 2545 next_char(); // skip ';'
duke@0 2546
duke@0 2547 // Store match into peep, and store peep into instruction
duke@0 2548 peep.add_match(match);
duke@0 2549 root->append_peephole(&peep);
duke@0 2550 }
duke@0 2551
duke@0 2552 //------------------------------peep_constraint_parse--------------------------
duke@0 2553 // Syntax for a peepconstraint rule
duke@0 2554 // A parenthesized list of relations between operands in peepmatch subtree
duke@0 2555 //
duke@0 2556 // peepconstraint %{
duke@0 2557 // (instruction_number.operand_name
duke@0 2558 // relational_op
duke@0 2559 // instruction_number.operand_name OR register_name
duke@0 2560 // [, ...] );
duke@0 2561 //
duke@0 2562 // // instruction numbers are zero-based using topological order in peepmatch
duke@0 2563 //
duke@0 2564 void ADLParser::peep_constraint_parse(Peephole &peep) {
duke@0 2565
duke@0 2566 skipws();
duke@0 2567 // Check the structure of the rule
duke@0 2568 // Check for open paren
duke@0 2569 if (_curchar != '(') {
duke@0 2570 parse_err(SYNERR, "missing '(' at start of peepconstraint rule.\n");
duke@0 2571 return;
duke@0 2572 }
duke@0 2573 else {
duke@0 2574 next_char(); // Skip '('
duke@0 2575 }
duke@0 2576
duke@0 2577 // Check for a constraint
duke@0 2578 skipws();
duke@0 2579 while( _curchar != ')' ) {
duke@0 2580 // Get information on the left instruction and its operand
duke@0 2581 // left-instructions's number
duke@0 2582 intptr_t left_inst = get_int();
duke@0 2583 // Left-instruction's operand
duke@0 2584 skipws();
duke@0 2585 if( _curchar != '.' ) {
duke@0 2586 parse_err(SYNERR, "missing '.' in peepconstraint after instruction number.\n");
duke@0 2587 return;
duke@0 2588 }
duke@0 2589 next_char(); // Skip '.'
duke@0 2590 char *left_op = get_ident_dup();
duke@0 2591
duke@0 2592 skipws();
duke@0 2593 // Collect relational operator
duke@0 2594 char *relation = get_relation_dup();
duke@0 2595
duke@0 2596 skipws();
duke@0 2597 // Get information on the right instruction and its operand
duke@0 2598 intptr_t right_inst; // Right-instructions's number
duke@0 2599 if( isdigit(_curchar) ) {
duke@0 2600 right_inst = get_int();
duke@0 2601 // Right-instruction's operand
duke@0 2602 skipws();
duke@0 2603 if( _curchar != '.' ) {
duke@0 2604 parse_err(SYNERR, "missing '.' in peepconstraint after instruction number.\n");
duke@0 2605 return;
duke@0 2606 }
duke@0 2607 next_char(); // Skip '.'
duke@0 2608 } else {
duke@0 2609 right_inst = -1; // Flag as being a register constraint
duke@0 2610 }
duke@0 2611
duke@0 2612 char *right_op = get_ident_dup();
duke@0 2613
duke@0 2614 // Construct the next PeepConstraint
duke@0 2615 PeepConstraint *constraint = new PeepConstraint( left_inst, left_op,
duke@0 2616 relation,
duke@0 2617 right_inst, right_op );
duke@0 2618 // And append it to the list for this peephole rule
duke@0 2619 peep.append_constraint( constraint );
duke@0 2620
duke@0 2621 // Check for another constraint, or end of rule
duke@0 2622 skipws();
duke@0 2623 if( _curchar == ',' ) {
duke@0 2624 next_char(); // Skip ','
duke@0 2625 skipws();
duke@0 2626 }
duke@0 2627 else if( _curchar != ')' ) {
duke@0 2628 parse_err(SYNERR, "expected ',' or ')' after peephole constraint.\n");
duke@0 2629 return;
duke@0 2630 }
duke@0 2631 } // end while( processing constraints )
duke@0 2632 next_char(); // Skip ')'
duke@0 2633
duke@0 2634 // Check for terminating ';'
duke@0 2635 skipws();
duke@0 2636 if (_curchar != ';') {
duke@0 2637 parse_err(SYNERR, "missing ';' at end of peepconstraint.\n");
duke@0 2638 return;
duke@0 2639 }
duke@0 2640 next_char(); // Skip trailing ';'
duke@0 2641 }
duke@0 2642
duke@0 2643
duke@0 2644 //------------------------------peep_replace_parse-----------------------------
duke@0 2645 // Syntax for a peepreplace rule
duke@0 2646 // root instruction name followed by a
duke@0 2647 // parenthesized list of whitespace separated instruction.operand specifiers
duke@0 2648 //
duke@0 2649 // peepreplace ( instr_name ( [instruction_number.operand_name]* ) );
duke@0 2650 //
duke@0 2651 //
duke@0 2652 void ADLParser::peep_replace_parse(Peephole &peep) {
duke@0 2653 int lparen = 0; // keep track of parenthesis nesting depth
duke@0 2654 int rparen = 0; // keep track of parenthesis nesting depth
duke@0 2655 int icount = 0; // count of instructions in rule for naming
duke@0 2656 char *str = NULL;
duke@0 2657 char *token = NULL;
duke@0 2658
duke@0 2659 skipws();
duke@0 2660 // Check for open paren
duke@0 2661 if (_curchar != '(') {
duke@0 2662 parse_err(SYNERR, "missing '(' at start of peepreplace rule.\n");
duke@0 2663 return;
duke@0 2664 }
duke@0 2665 else {
duke@0 2666 lparen++;
duke@0 2667 next_char();
duke@0 2668 }
duke@0 2669
duke@0 2670 // Check for root instruction
duke@0 2671 char *inst = get_ident_dup();
duke@0 2672 const Form *form = _AD._globalNames[inst];
duke@0 2673 if( form == NULL || form->is_instruction() == NULL ) {
duke@0 2674 parse_err(SYNERR, "Instruction name expected at start of peepreplace.\n");
duke@0 2675 return;
duke@0 2676 }
duke@0 2677
duke@0 2678 // Store string representation of rule into replace
duke@0 2679 PeepReplace *replace = new PeepReplace(str);
duke@0 2680 replace->add_instruction( inst );
duke@0 2681
duke@0 2682 skipws();
duke@0 2683 // Start of root's operand-list
duke@0 2684 if (_curchar != '(') {
duke@0 2685 parse_err(SYNERR, "missing '(' at peepreplace root's operand-list.\n");
duke@0 2686 return;
duke@0 2687 }
duke@0 2688 else {
duke@0 2689 lparen++;
duke@0 2690 next_char();
duke@0 2691 }
duke@0 2692
duke@0 2693 skipws();
duke@0 2694 // Get the list of operands
duke@0 2695 while( _curchar != ')' ) {
duke@0 2696 // Get information on an instruction and its operand
duke@0 2697 // instructions's number
duke@0 2698 int inst_num = get_int();
duke@0 2699 // Left-instruction's operand
duke@0 2700 skipws();
duke@0 2701 if( _curchar != '.' ) {
duke@0 2702 parse_err(SYNERR, "missing '.' in peepreplace after instruction number.\n");
duke@0 2703 return;
duke@0 2704 }
duke@0 2705 next_char(); // Skip '.'
duke@0 2706 char *inst_op = get_ident_dup();
duke@0 2707 if( inst_op == NULL ) {
duke@0 2708 parse_err(SYNERR, "missing operand identifier in peepreplace.\n");
duke@0 2709 return;
duke@0 2710 }
duke@0 2711
duke@0 2712 // Record this operand's position in peepmatch
duke@0 2713 replace->add_operand( inst_num, inst_op );
duke@0 2714 skipws();
duke@0 2715 }
duke@0 2716
duke@0 2717 // Check for the end of operands list
duke@0 2718 skipws();
duke@0 2719 assert( _curchar == ')', "While loop should have advanced to ')'.");
duke@0 2720 next_char(); // Skip ')'
duke@0 2721
duke@0 2722 skipws();
duke@0 2723 // Check for end of peepreplace
duke@0 2724 if( _curchar != ')' ) {
duke@0 2725 parse_err(SYNERR, "missing ')' at end of peepmatch.\n");
duke@0 2726 parse_err(SYNERR, "Support one replacement instruction.\n");
duke@0 2727 return;
duke@0 2728 }
duke@0 2729 next_char(); // Skip ')'
duke@0 2730
duke@0 2731 // Check for closing semicolon
duke@0 2732 skipws();
duke@0 2733 if( _curchar != ';' ) {
duke@0 2734 parse_err(SYNERR, "missing ';' at end of peepreplace.\n");
duke@0 2735 return;
duke@0 2736 }
duke@0 2737 next_char(); // skip ';'
duke@0 2738
duke@0 2739 // Store replace into peep
duke@0 2740 peep.add_replace( replace );
duke@0 2741 }
duke@0 2742
duke@0 2743 //------------------------------pred_parse-------------------------------------
duke@0 2744 Predicate *ADLParser::pred_parse(void) {
duke@0 2745 Predicate *predicate; // Predicate class for operand
duke@0 2746 char *rule = NULL; // String representation of predicate
duke@0 2747
duke@0 2748 skipws(); // Skip leading whitespace
duke@0 2749 if ( (rule = get_paren_expr("pred expression")) == NULL ) {
duke@0 2750 parse_err(SYNERR, "incorrect or missing expression for 'predicate'\n");
duke@0 2751 return NULL;
duke@0 2752 }
duke@0 2753 // Debug Stuff
duke@0 2754 if (_AD._adl_debug > 1) fprintf(stderr,"Predicate: %s\n", rule);
duke@0 2755 if (_curchar != ';') {
duke@0 2756 parse_err(SYNERR, "missing ';' in predicate definition\n");
duke@0 2757 return NULL;
duke@0 2758 }
duke@0 2759 next_char(); // Point after the terminator
duke@0 2760
duke@0 2761 predicate = new Predicate(rule); // Build new predicate object
duke@0 2762 skipws();
duke@0 2763 return predicate;
duke@0 2764 }
duke@0 2765
duke@0 2766
duke@0 2767 //------------------------------ins_encode_parse_block-------------------------
duke@0 2768 // Parse the block form of ins_encode. See ins_encode_parse for more details
duke@0 2769 InsEncode *ADLParser::ins_encode_parse_block(InstructForm &inst) {
duke@0 2770 // Create a new encoding name based on the name of the instruction
duke@0 2771 // definition, which should be unique.
duke@0 2772 const char * prefix = "__enc_";
duke@0 2773 char* ec_name = (char*)malloc(strlen(inst._ident) + strlen(prefix) + 1);
duke@0 2774 sprintf(ec_name, "%s%s", prefix, inst._ident);
duke@0 2775
duke@0 2776 assert(_AD._encode->encClass(ec_name) == NULL, "shouldn't already exist");
duke@0 2777 EncClass *encoding = _AD._encode->add_EncClass(ec_name);
never@415 2778 encoding->_linenum = linenum();
duke@0 2779
duke@0 2780 // synthesize the arguments list for the enc_class from the
duke@0 2781 // arguments to the instruct definition.
duke@0 2782 const char * param = NULL;
duke@0 2783 inst._parameters.reset();
duke@0 2784 while ((param = inst._parameters.iter()) != NULL) {
duke@0 2785 OperandForm *opForm = (OperandForm*)inst._localNames[param];
duke@0 2786 encoding->add_parameter(opForm->_ident, param);
duke@0 2787 }
duke@0 2788
duke@0 2789 // Add the prologue to create the MacroAssembler
duke@0 2790 encoding->add_code("\n"
duke@0 2791 " // Define a MacroAssembler instance for use by the encoding. The\n"
duke@0 2792 " // name is chosen to match the __ idiom used for assembly in other\n"
duke@0 2793 " // parts of hotspot and assumes the existence of the standard\n"
duke@0 2794 " // #define __ _masm.\n"
duke@0 2795 " MacroAssembler _masm(&cbuf);\n");
duke@0 2796
duke@0 2797 // Parse the following %{ }% block
duke@0 2798 enc_class_parse_block(encoding, ec_name);
duke@0 2799
duke@0 2800 // Build an encoding rule which invokes the encoding rule we just
duke@0 2801 // created, passing all arguments that we received.
duke@0 2802 InsEncode *encrule = new InsEncode(); // Encode class for instruction
duke@0 2803 NameAndList *params = encrule->add_encode(ec_name);
duke@0 2804 inst._parameters.reset();
duke@0 2805 while ((param = inst._parameters.iter()) != NULL) {
duke@0 2806 params->add_entry(param);
duke@0 2807 }
duke@0 2808
duke@0 2809 return encrule;
duke@0 2810 }
duke@0 2811
duke@0 2812
duke@0 2813 //------------------------------ins_encode_parse-------------------------------
duke@0 2814 // Encode rules have the form
duke@0 2815 // ins_encode( encode_class_name(parameter_list), ... );
duke@0 2816 //
duke@0 2817 // The "encode_class_name" must be defined in the encode section
duke@0 2818 // The parameter list contains $names that are locals.
duke@0 2819 //
duke@0 2820 // Alternatively it can be written like this:
duke@0 2821 //
duke@0 2822 // ins_encode %{
duke@0 2823 // ... // body
duke@0 2824 // %}
duke@0 2825 //
duke@0 2826 // which synthesizes a new encoding class taking the same arguments as
duke@0 2827 // the InstructForm, and automatically prefixes the definition with:
duke@0 2828 //
duke@0 2829 // MacroAssembler masm(&cbuf);\n");
duke@0 2830 //
duke@0 2831 // making it more compact to take advantage of the MacroAssembler and
duke@0 2832 // placing the assembly closer to it's use by instructions.
duke@0 2833 InsEncode *ADLParser::ins_encode_parse(InstructForm &inst) {
duke@0 2834
duke@0 2835 // Parse encode class name
duke@0 2836 skipws(); // Skip whitespace
duke@0 2837 if (_curchar != '(') {
duke@0 2838 // Check for ins_encode %{ form
duke@0 2839 if ((_curchar == '%') && (*(_ptr+1) == '{')) {
duke@0 2840 next_char(); // Skip '%'
duke@0 2841 next_char(); // Skip '{'
duke@0 2842
duke@0 2843 // Parse the block form of ins_encode
duke@0 2844 return ins_encode_parse_block(inst);
duke@0 2845 }
duke@0 2846
duke@0 2847 parse_err(SYNERR, "missing '%%{' or '(' in ins_encode definition\n");
duke@0 2848 return NULL;
duke@0 2849 }
duke@0 2850 next_char(); // move past '('
duke@0 2851 skipws();
duke@0 2852
duke@0 2853 InsEncode *encrule = new InsEncode(); // Encode class for instruction
never@415 2854 encrule->_linenum = linenum();
duke@0 2855 char *ec_name = NULL; // String representation of encode rule
duke@0 2856 // identifier is optional.
duke@0 2857 while (_curchar != ')') {
duke@0 2858 ec_name = get_ident();
duke@0 2859 if (ec_name == NULL) {
duke@0 2860 parse_err(SYNERR, "Invalid encode class name after 'ins_encode('.\n");
duke@0 2861 return NULL;
duke@0 2862 }
duke@0 2863 // Check that encoding is defined in the encode section
duke@0 2864 EncClass *encode_class = _AD._encode->encClass(ec_name);
duke@0 2865 if (encode_class == NULL) {
duke@0 2866 // Like to defer checking these till later...
duke@0 2867 // parse_err(WARN, "Using an undefined encode class '%s' in 'ins_encode'.\n", ec_name);
duke@0 2868 }
duke@0 2869
duke@0 2870 // Get list for encode method's parameters
duke@0 2871 NameAndList *params = encrule->add_encode(ec_name);
duke@0 2872
duke@0 2873 // Parse the parameters to this encode method.
duke@0 2874 skipws();
duke@0 2875 if ( _curchar == '(' ) {
duke@0 2876 next_char(); // move past '(' for parameters
duke@0 2877
duke@0 2878 // Parse the encode method's parameters
duke@0 2879 while (_curchar != ')') {
duke@0 2880 char *param = get_ident_or_literal_constant("encoding operand");
duke@0 2881 if ( param != NULL ) {
duke@0 2882 // Found a parameter:
duke@0 2883 // Check it is a local name, add it to the list, then check for more
duke@0 2884 // New: allow hex constants as parameters to an encode method.
duke@0 2885 // New: allow parenthesized expressions as parameters.
duke@0 2886 // New: allow "primary", "secondary", "tertiary" as parameters.
duke@0 2887 // New: allow user-defined register name as parameter
duke@0 2888 if ( (inst._localNames[param] == NULL) &&
duke@0 2889 !ADLParser::is_literal_constant(param) &&
duke@0 2890 (Opcode::as_opcode_type(param) == Opcode::NOT_AN_OPCODE) &&
duke@0 2891 ((_AD._register == NULL ) || (_AD._register->getRegDef(param) == NULL)) ) {
duke@0 2892 parse_err(SYNERR, "Using non-locally defined parameter %s for encoding %s.\n", param, ec_name);
duke@0 2893 return NULL;
duke@0 2894 }
duke@0 2895 params->add_entry(param);
duke@0 2896
duke@0 2897 skipws();
duke@0 2898 if (_curchar == ',' ) {
duke@0 2899 // More parameters to come
duke@0 2900 next_char(); // move past ',' between parameters
duke@0 2901 skipws(); // Skip to next parameter
duke@0 2902 }
duke@0 2903 else if (_curchar == ')') {
duke@0 2904 // Done with parameter list
duke@0 2905 }
duke@0 2906 else {
duke@0 2907 // Only ',' or ')' are valid after a parameter name
duke@0 2908 parse_err(SYNERR, "expected ',' or ')' after parameter %s.\n",
duke@0 2909 ec_name);
duke@0 2910 return NULL;
duke@0 2911 }
duke@0 2912
duke@0 2913 } else {
duke@0 2914 skipws();
duke@0 2915 // Did not find a parameter
duke@0 2916 if (_curchar == ',') {
duke@0 2917 parse_err(SYNERR, "Expected encode parameter before ',' in encoding %s.\n", ec_name);
duke@0 2918 return NULL;
duke@0 2919 }
duke@0 2920 if (_curchar != ')') {
duke@0 2921 parse_err(SYNERR, "Expected ')' after encode parameters.\n");
duke@0 2922 return NULL;
duke@0 2923 }
duke@0 2924 }
duke@0 2925 } // WHILE loop collecting parameters
duke@0 2926 next_char(); // move past ')' at end of parameters
duke@0 2927 } // done with parameter list for encoding
duke@0 2928
duke@0 2929 // Check for ',' or ')' after encoding
duke@0 2930 skipws(); // move to character after parameters
duke@0 2931 if ( _curchar == ',' ) {
duke@0 2932 // Found a ','
duke@0 2933 next_char(); // move past ',' between encode methods
duke@0 2934 skipws();
duke@0 2935 }
duke@0 2936 else if ( _curchar != ')' ) {
duke@0 2937 // If not a ',' then only a ')' is allowed
duke@0 2938 parse_err(SYNERR, "Expected ')' after encoding %s.\n", ec_name);
duke@0 2939 return NULL;
duke@0 2940 }
duke@0 2941
duke@0 2942 // Check for ',' separating parameters
duke@0 2943 // if ( _curchar != ',' && _curchar != ')' ) {
duke@0 2944 // parse_err(SYNERR, "expected ',' or ')' after encode method inside ins_encode.\n");
duke@0 2945 // return NULL;
duke@0 2946 // }
duke@0 2947
duke@0 2948 } // done parsing ins_encode methods and their parameters
duke@0 2949 if (_curchar != ')') {
duke@0 2950 parse_err(SYNERR, "Missing ')' at end of ins_encode description.\n");
duke@0 2951 return NULL;
duke@0 2952 }
duke@0 2953 next_char(); // move past ')'
duke@0 2954 skipws(); // Skip leading whitespace
duke@0 2955
duke@0 2956 if ( _curchar != ';' ) {
duke@0 2957 parse_err(SYNERR, "Missing ';' at end of ins_encode.\n");
duke@0 2958 return NULL;
duke@0 2959 }
duke@0 2960 next_char(); // move past ';'
duke@0 2961 skipws(); // be friendly to oper_parse()
duke@0 2962
duke@0 2963 // Debug Stuff
duke@0 2964 if (_AD._adl_debug > 1) fprintf(stderr,"Instruction Encode: %s\n", ec_name);
duke@0 2965
duke@0 2966 return encrule;
duke@0 2967 }
duke@0 2968
duke@0 2969
duke@0 2970 //------------------------------size_parse-----------------------------------
duke@0 2971 char* ADLParser::size_parse(InstructForm *instr) {
duke@0 2972 char* sizeOfInstr = NULL;
duke@0 2973
duke@0 2974 // Get value of the instruction's size
duke@0 2975 skipws();
duke@0 2976
duke@0 2977 // Parse size
duke@0 2978 sizeOfInstr = get_paren_expr("size expression");
duke@0 2979 if (sizeOfInstr == NULL) {
duke@0 2980 parse_err(SYNERR, "size of opcode expected at %c\n", _curchar);
duke@0 2981 return NULL;
duke@0 2982 }
duke@0 2983
duke@0 2984 skipws();
duke@0 2985
duke@0 2986 // Check for terminator
duke@0 2987 if (_curchar != ';') {
duke@0 2988 parse_err(SYNERR, "missing ';' in ins_attrib definition\n");
duke@0 2989 return NULL;
duke@0 2990 }
duke@0 2991 next_char(); // Advance past the ';'
duke@0 2992 skipws(); // necessary for instr_parse()
duke@0 2993
duke@0 2994 // Debug Stuff
duke@0 2995 if (_AD._adl_debug > 1) {
duke@0 2996 if (sizeOfInstr != NULL) {
duke@0 2997 fprintf(stderr,"size of opcode: %s\n", sizeOfInstr);
duke@0 2998 }
duke@0 2999 }
duke@0 3000
duke@0 3001 return sizeOfInstr;
duke@0 3002 }
duke@0 3003
duke@0 3004
duke@0 3005 //------------------------------opcode_parse-----------------------------------
duke@0 3006 Opcode * ADLParser::opcode_parse(InstructForm *instr) {
duke@0 3007 char *primary = NULL;
duke@0 3008 char *secondary = NULL;
duke@0 3009 char *tertiary = NULL;
duke@0 3010
duke@0 3011 char *val = NULL;
duke@0 3012 Opcode *opcode = NULL;
duke@0 3013
duke@0 3014 // Get value of the instruction's opcode
duke@0 3015 skipws();
duke@0 3016 if (_curchar != '(') { // Check for parenthesized operand list
duke@0 3017 parse_err(SYNERR, "missing '(' in expand instruction declaration\n");
duke@0 3018 return NULL;
duke@0 3019 }
duke@0 3020 next_char(); // skip open paren
duke@0 3021 skipws();
duke@0 3022 if (_curchar != ')') {
duke@0 3023 // Parse primary, secondary, and tertiary opcodes, if provided.
duke@0 3024 if ( ((primary = get_ident_or_literal_constant("primary opcode")) == NULL) ) {
duke@0 3025 parse_err(SYNERR, "primary hex opcode expected at %c\n", _curchar);
duke@0 3026 return NULL;
duke@0 3027 }
duke@0 3028 skipws();
duke@0 3029 if (_curchar == ',') {
duke@0 3030 next_char();
duke@0 3031 skipws();
duke@0 3032 // Parse secondary opcode
duke@0 3033 if ( ((secondary = get_ident_or_literal_constant("secondary opcode")) == NULL) ) {
duke@0 3034 parse_err(SYNERR, "secondary hex opcode expected at %c\n", _curchar);
duke@0 3035 return NULL;
duke@0 3036 }
duke@0 3037 skipws();
duke@0 3038 if (_curchar == ',') {
duke@0 3039 next_char();
duke@0 3040 skipws();
duke@0 3041 // Parse tertiary opcode
duke@0 3042 if ( ((tertiary = get_ident_or_literal_constant("tertiary opcode")) == NULL) ) {
duke@0 3043 parse_err(SYNERR,"tertiary hex opcode expected at %c\n", _curchar);
duke@0 3044 return NULL;
duke@0 3045 }
duke@0 3046 skipws();
duke@0 3047 }
duke@0 3048 }
duke@0 3049 skipws();
duke@0 3050 if (_curchar != ')') {
duke@0 3051 parse_err(SYNERR, "Missing ')' in opcode description\n");
duke@0 3052 return NULL;
duke@0 3053 }
duke@0 3054 }
duke@0 3055 next_char(); // Skip ')'
duke@0 3056 skipws();
duke@0 3057 // Check for terminator
duke@0 3058 if (_curchar != ';') {
duke@0 3059 parse_err(SYNERR, "missing ';' in ins_attrib definition\n");
duke@0 3060 return NULL;
duke@0 3061 }
duke@0 3062 next_char(); // Advance past the ';'
duke@0 3063 skipws(); // necessary for instr_parse()
duke@0 3064
duke@0 3065 // Debug Stuff
duke@0 3066 if (_AD._adl_debug > 1) {
duke@0 3067 if (primary != NULL) fprintf(stderr,"primary opcode: %s\n", primary);
duke@0 3068 if (secondary != NULL) fprintf(stderr,"secondary opcode: %s\n", secondary);
duke@0 3069 if (tertiary != NULL) fprintf(stderr,"tertiary opcode: %s\n", tertiary);
duke@0 3070 }
duke@0 3071
duke@0 3072 // Generate new object and return
duke@0 3073 opcode = new Opcode(primary, secondary, tertiary);
duke@0 3074 return opcode;
duke@0 3075 }
duke@0 3076
duke@0 3077
duke@0 3078 //------------------------------interface_parse--------------------------------
duke@0 3079 Interface *ADLParser::interface_parse(void) {
duke@0 3080 char *iface_name = NULL; // Name of interface class being used
duke@0 3081 char *iface_code = NULL; // Describe components of this class
duke@0 3082
duke@0 3083 // Get interface class name
duke@0 3084 skipws(); // Skip whitespace
duke@0 3085 if (_curchar != '(') {
duke@0 3086 parse_err(SYNERR, "Missing '(' at start of interface description.\n");
duke@0 3087 return NULL;
duke@0 3088 }
duke@0 3089 next_char(); // move past '('
duke@0 3090 skipws();
duke@0 3091 iface_name = get_ident();
duke@0 3092 if (iface_name == NULL) {
duke@0 3093 parse_err(SYNERR, "missing interface name after 'interface'.\n");
duke@0 3094 return NULL;
duke@0 3095 }
duke@0 3096 skipws();
duke@0 3097 if (_curchar != ')') {
duke@0 3098 parse_err(SYNERR, "Missing ')' after name of interface.\n");
duke@0 3099 return NULL;
duke@0 3100 }
duke@0 3101 next_char(); // move past ')'
duke@0 3102
duke@0 3103 // Get details of the interface,
duke@0 3104 // for the type of interface indicated by iface_name.
duke@0 3105 Interface *inter = NULL;
duke@0 3106 skipws();
duke@0 3107 if ( _curchar != ';' ) {
duke@0 3108 if ( strcmp(iface_name,"MEMORY_INTER") == 0 ) {
duke@0 3109 inter = mem_interface_parse();
duke@0 3110 }
duke@0 3111 else if ( strcmp(iface_name,"COND_INTER") == 0 ) {
duke@0 3112 inter = cond_interface_parse();
duke@0 3113 }
duke@0 3114 // The parse routines consume the "%}"
duke@0 3115
duke@0 3116 // Check for probable extra ';' after defining block.
duke@0 3117 if ( _curchar == ';' ) {
duke@0 3118 parse_err(SYNERR, "Extra ';' after defining interface block.\n");
duke@0 3119 next_char(); // Skip ';'
duke@0 3120 return NULL;
duke@0 3121 }
duke@0 3122 } else {
duke@0 3123 next_char(); // move past ';'
duke@0 3124
duke@0 3125 // Create appropriate interface object
duke@0 3126 if ( strcmp(iface_name,"REG_INTER") == 0 ) {
duke@0 3127 inter = new RegInterface();
duke@0 3128 }
duke@0 3129 else if ( strcmp(iface_name,"CONST_INTER") == 0 ) {
duke@0 3130 inter = new ConstInterface();
duke@0 3131 }
duke@0 3132 }
duke@0 3133 skipws(); // be friendly to oper_parse()
duke@0 3134 // Debug Stuff
duke@0 3135 if (_AD._adl_debug > 1) fprintf(stderr,"Interface Form: %s\n", iface_name);
duke@0 3136
duke@0 3137 // Create appropriate interface object and return.
duke@0 3138 return inter;
duke@0 3139 }
duke@0 3140
duke@0 3141
duke@0 3142 //------------------------------mem_interface_parse----------------------------
duke@0 3143 Interface *ADLParser::mem_interface_parse(void) {
duke@0 3144 // Fields for MemInterface
duke@0 3145 char *base = NULL;
duke@0 3146 char *index = NULL;
duke@0 3147 char *scale = NULL;
duke@0 3148 char *disp = NULL;
duke@0 3149
duke@0 3150 if (_curchar != '%') {
duke@0 3151 parse_err(SYNERR, "Missing '%{' for 'interface' block.\n");
duke@0 3152 return NULL;
duke@0 3153 }
duke@0 3154 next_char(); // Skip '%'
duke@0 3155 if (_curchar != '{') {
duke@0 3156 parse_err(SYNERR, "Missing '%{' for 'interface' block.\n");
duke@0 3157 return NULL;
duke@0 3158 }
duke@0 3159 next_char(); // Skip '{'
duke@0 3160 skipws();
duke@0 3161 do {
duke@0 3162 char *field = get_ident();
duke@0 3163 if (field == NULL) {
duke@0 3164 parse_err(SYNERR, "Expected keyword, base|index|scale|disp, or '%}' ending interface.\n");
duke@0 3165 return NULL;
duke@0 3166 }
duke@0 3167 if ( strcmp(field,"base") == 0 ) {
duke@0 3168 base = interface_field_parse();
duke@0 3169 }
duke@0 3170 else if ( strcmp(field,"index") == 0 ) {
duke@0 3171 index = interface_field_parse();
duke@0 3172 }
duke@0 3173 else if ( strcmp(field,"scale") == 0 ) {
duke@0 3174 scale = interface_field_parse();
duke@0 3175 }
duke@0 3176 else if ( strcmp(field,"disp") == 0 ) {
duke@0 3177 disp = interface_field_parse();
duke@0 3178 }
duke@0 3179 else {
duke@0 3180 parse_err(SYNERR, "Expected keyword, base|index|scale|disp, or '%}' ending interface.\n");
duke@0 3181 return NULL;
duke@0 3182 }
duke@0 3183 } while( _curchar != '%' );
duke@0 3184 next_char(); // Skip '%'
duke@0 3185 if ( _curchar != '}' ) {
duke@0 3186 parse_err(SYNERR, "Missing '%}' for 'interface' block.\n");
duke@0 3187 return NULL;
duke@0 3188 }
duke@0 3189 next_char(); // Skip '}'
duke@0 3190
duke@0 3191 // Construct desired object and return
duke@0 3192 Interface *inter = new MemInterface(base, index, scale, disp);
duke@0 3193 return inter;
duke@0 3194 }
duke@0 3195
duke@0 3196
duke@0 3197 //------------------------------cond_interface_parse---------------------------
duke@0 3198 Interface *ADLParser::cond_interface_parse(void) {
duke@0 3199 char *equal;
duke@0 3200 char *not_equal;
duke@0 3201 char *less;
duke@0 3202 char *greater_equal;
duke@0 3203 char *less_equal;
duke@0 3204 char *greater;
never@415 3205 const char *equal_format = "eq";
never@415 3206 const char *not_equal_format = "ne";
never@415 3207 const char *less_format = "lt";
never@415 3208 const char *greater_equal_format = "ge";
never@415 3209 const char *less_equal_format = "le";
never@415 3210 const char *greater_format = "gt";
duke@0 3211
duke@0 3212 if (_curchar != '%') {
duke@0 3213 parse_err(SYNERR, "Missing '%{' for 'cond_interface' block.\n");
duke@0 3214 return NULL;
duke@0 3215 }
duke@0 3216 next_char(); // Skip '%'
duke@0 3217 if (_curchar != '{') {
duke@0 3218 parse_err(SYNERR, "Missing '%{' for 'cond_interface' block.\n");
duke@0 3219 return NULL;
duke@0 3220 }
duke@0 3221 next_char(); // Skip '{'
duke@0 3222 skipws();
duke@0 3223 do {
duke@0 3224 char *field = get_ident();
duke@0 3225 if (field == NULL) {
duke@0 3226 parse_err(SYNERR, "Expected keyword, base|index|scale|disp, or '%}' ending interface.\n");
duke@0 3227 return NULL;
duke@0 3228 }
duke@0 3229 if ( strcmp(field,"equal") == 0 ) {
never@415 3230 equal = interface_field_parse(&equal_format);
duke@0 3231 }
duke@0 3232 else if ( strcmp(field,"not_equal") == 0 ) {
never@415 3233 not_equal = interface_field_parse(&not_equal_format);
duke@0 3234 }
duke@0 3235 else if ( strcmp(field,"less") == 0 ) {
never@415 3236 less = interface_field_parse(&less_format);
duke@0 3237 }
duke@0 3238 else if ( strcmp(field,"greater_equal") == 0 ) {
never@415 3239 greater_equal = interface_field_parse(&greater_equal_format);
duke@0 3240 }
duke@0 3241 else if ( strcmp(field,"less_equal") == 0 ) {
never@415 3242 less_equal = interface_field_parse(&less_equal_format);
duke@0 3243 }
duke@0 3244 else if ( strcmp(field,"greater") == 0 ) {
never@415 3245 greater = interface_field_parse(&greater_format);
duke@0 3246 }
duke@0 3247 else {
duke@0 3248 parse_err(SYNERR, "Expected keyword, base|index|scale|disp, or '%}' ending interface.\n");
duke@0 3249 return NULL;
duke@0 3250 }
duke@0 3251 } while( _curchar != '%' );
duke@0 3252 next_char(); // Skip '%'
duke@0 3253 if ( _curchar != '}' ) {
duke@0 3254 parse_err(SYNERR, "Missing '%}' for 'interface' block.\n");
duke@0 3255 return NULL;
duke@0 3256 }
duke@0 3257 next_char(); // Skip '}'
duke@0 3258
duke@0 3259 // Construct desired object and return
never@415 3260 Interface *inter = new CondInterface(equal, equal_format,
never@415 3261 not_equal, not_equal_format,
never@415 3262 less, less_format,
never@415 3263 greater_equal, greater_equal_format,
never@415 3264 less_equal, less_equal_format,
never@415 3265 greater, greater_format);
duke@0 3266 return inter;
duke@0 3267 }
duke@0 3268
duke@0 3269
duke@0 3270 //------------------------------interface_field_parse--------------------------
never@415 3271 char *ADLParser::interface_field_parse(const char ** format) {
duke@0 3272 char *iface_field = NULL;
duke@0 3273
duke@0 3274 // Get interface field
duke@0 3275 skipws(); // Skip whitespace
duke@0 3276 if (_curchar != '(') {
duke@0 3277 parse_err(SYNERR, "Missing '(' at start of interface field.\n");
duke@0 3278 return NULL;
duke@0 3279 }
duke@0 3280 next_char(); // move past '('
duke@0 3281 skipws();
duke@0 3282 if ( _curchar != '0' && _curchar != '$' ) {
duke@0 3283 parse_err(SYNERR, "missing or invalid interface field contents.\n");
duke@0 3284 return NULL;
duke@0 3285 }
duke@0 3286 iface_field = get_rep_var_ident();
duke@0 3287 if (iface_field == NULL) {
duke@0 3288 parse_err(SYNERR, "missing or invalid interface field contents.\n");
duke@0 3289 return NULL;
duke@0 3290 }
duke@0 3291 skipws();
never@415 3292 if (format != NULL && _curchar == ',') {
never@415 3293 next_char();
never@415 3294 skipws();
never@415 3295 if (_curchar != '"') {
never@415 3296 parse_err(SYNERR, "Missing '\"' in field format .\n");
never@415 3297 return NULL;
never@415 3298 }
never@415 3299 next_char();
never@415 3300 char *start = _ptr; // Record start of the next string
never@415 3301 while ((_curchar != '"') && (_curchar != '%') && (_curchar != '\n')) {
never@415 3302 if (_curchar == '\\') next_char(); // superquote
never@415 3303 if (_curchar == '\n') parse_err(SYNERR, "newline in string"); // unimplemented!
never@415 3304 next_char();
never@415 3305 }
never@415 3306 if (_curchar != '"') {
never@415 3307 parse_err(SYNERR, "Missing '\"' at end of field format .\n");
never@415 3308 return NULL;
never@415 3309 }
never@415 3310 // If a string was found, terminate it and record in FormatRule
never@415 3311 if ( start != _ptr ) {
never@415 3312 *_ptr = '\0'; // Terminate the string
never@415 3313 *format = start;
never@415 3314 }
never@415 3315 next_char();
never@415 3316 skipws();
never@415 3317 }
duke@0 3318 if (_curchar != ')') {
duke@0 3319 parse_err(SYNERR, "Missing ')' after interface field.\n");
duke@0 3320 return NULL;
duke@0 3321 }
duke@0 3322 next_char(); // move past ')'
duke@0 3323 skipws();
duke@0 3324 if ( _curchar != ';' ) {
duke@0 3325 parse_err(SYNERR, "Missing ';' at end of interface field.\n");
duke@0 3326 return NULL;
duke@0 3327 }
duke@0 3328 next_char(); // move past ';'
duke@0 3329 skipws(); // be friendly to interface_parse()
duke@0 3330
duke@0 3331 return iface_field;
duke@0 3332 }
duke@0 3333
duke@0 3334
duke@0 3335 //------------------------------match_parse------------------------------------
duke@0 3336 MatchRule *ADLParser::match_parse(FormDict &operands) {
duke@0 3337 MatchRule *match; // Match Rule class for instruction/operand
duke@0 3338 char *cnstr = NULL; // Code for constructor
duke@0 3339 int depth = 0; // Counter for matching parentheses
duke@0 3340 int numleaves = 0; // Counter for number of leaves in rule
duke@0 3341
duke@0 3342 // Parse the match rule tree
duke@0 3343 MatchNode *mnode = matchNode_parse(operands, depth, numleaves, true);
duke@0 3344
duke@0 3345 // Either there is a block with a constructor, or a ';' here
duke@0 3346 skipws(); // Skip whitespace
duke@0 3347 if ( _curchar == ';' ) { // Semicolon is valid terminator
duke@0 3348 cnstr = NULL; // no constructor for this form
duke@0 3349 next_char(); // Move past the ';', replaced with '\0'
duke@0 3350 }
duke@0 3351 else if ((cnstr = find_cpp_block("match constructor")) == NULL ) {
duke@0 3352 parse_err(SYNERR, "invalid construction of match rule\n"
duke@0 3353 "Missing ';' or invalid '%{' and '%}' constructor\n");
duke@0 3354 return NULL; // No MatchRule to return
duke@0 3355 }
duke@0 3356 if (_AD._adl_debug > 1)
duke@0 3357 if (cnstr) fprintf(stderr,"Match Constructor: %s\n", cnstr);
duke@0 3358 // Build new MatchRule object
duke@0 3359 match = new MatchRule(_AD, mnode, depth, cnstr, numleaves);
duke@0 3360 skipws(); // Skip any trailing whitespace
duke@0 3361 return match; // Return MatchRule object
duke@0 3362 }
duke@0 3363
duke@0 3364 //------------------------------format_parse-----------------------------------
duke@0 3365 FormatRule* ADLParser::format_parse(void) {
duke@0 3366 char *desc = NULL;
duke@0 3367 FormatRule *format = (new FormatRule(desc));
duke@0 3368
duke@0 3369 // Without expression form, MUST have a code block;
duke@0 3370 skipws(); // Skip whitespace
duke@0 3371 if ( _curchar == ';' ) { // Semicolon is valid terminator
duke@0 3372 desc = NULL; // no constructor for this form
duke@0 3373 next_char(); // Move past the ';', replaced with '\0'
duke@0 3374 }
duke@0 3375 else if ( _curchar == '%' && *(_ptr+1) == '{') {
duke@0 3376 next_char(); // Move past the '%'
duke@0 3377 next_char(); // Move past the '{'
duke@0 3378
duke@0 3379 skipws();
never@415 3380 if (_curchar == '$') {
never@415 3381 char* ident = get_rep_var_ident();
never@415 3382 if (strcmp(ident, "$$template") == 0) return template_parse();
never@415 3383 parse_err(SYNERR, "Unknown \"%s\" directive in format", ident);
never@415 3384 return NULL;
never@415 3385 }
duke@0 3386 // Check for the opening '"' inside the format description
duke@0 3387 if ( _curchar == '"' ) {
duke@0 3388 next_char(); // Move past the initial '"'
duke@0 3389 if( _curchar == '"' ) { // Handle empty format string case
duke@0 3390 *_ptr = '\0'; // Terminate empty string
duke@0 3391 format->_strings.addName(_ptr);
duke@0 3392 }
duke@0 3393
duke@0 3394 // Collect the parts of the format description
duke@0 3395 // (1) strings that are passed through to tty->print
duke@0 3396 // (2) replacement/substitution variable, preceeded by a '$'
duke@0 3397 // (3) multi-token ANSIY C style strings
duke@0 3398 while ( true ) {
duke@0 3399 if ( _curchar == '%' || _curchar == '\n' ) {
duke@0 3400 if ( _curchar != '"' ) {
duke@0 3401 parse_err(SYNERR, "missing '\"' at end of format block");
duke@0 3402 return NULL;
duke@0 3403 }
duke@0 3404 }
duke@0 3405
duke@0 3406 // (1)
duke@0 3407 // Check if there is a string to pass through to output
duke@0 3408 char *start = _ptr; // Record start of the next string
duke@0 3409 while ((_curchar != '$') && (_curchar != '"') && (_curchar != '%') && (_curchar != '\n')) {
duke@0 3410 if (_curchar == '\\') next_char(); // superquote
duke@0 3411 if (_curchar == '\n') parse_err(SYNERR, "newline in string"); // unimplemented!
duke@0 3412 next_char();
duke@0 3413 }
duke@0 3414 // If a string was found, terminate it and record in FormatRule
duke@0 3415 if ( start != _ptr ) {
duke@0 3416 *_ptr = '\0'; // Terminate the string
duke@0 3417 format->_strings.addName(start);
duke@0 3418 }
duke@0 3419
duke@0 3420 // (2)
duke@0 3421 // If we are at a replacement variable,
duke@0 3422 // copy it and record in FormatRule
duke@0 3423 if ( _curchar == '$' ) {
duke@0 3424 next_char(); // Move past the '$'
duke@0 3425 char* rep_var = get_ident(); // Nil terminate the variable name
duke@0 3426 rep_var = strdup(rep_var);// Copy the string
duke@0 3427 *_ptr = _curchar; // and replace Nil with original character
duke@0 3428 format->_rep_vars.addName(rep_var);
duke@0 3429 // Add flag to _strings list indicating we should check _rep_vars
duke@0 3430 format->_strings.addName(NameList::_signal);
duke@0 3431 }
duke@0 3432
duke@0 3433 // (3)
duke@0 3434 // Allow very long strings to be broken up,
duke@0 3435 // using the ANSI C syntax "foo\n" <newline> "bar"
duke@0 3436 if ( _curchar == '"') {
duke@0 3437 next_char(); // Move past the '"'
duke@0 3438 skipws(); // Skip white space before next string token
duke@0 3439 if ( _curchar != '"') {
duke@0 3440 break;
duke@0 3441 } else {
duke@0 3442 // Found one. Skip both " and the whitespace in between.
duke@0 3443 next_char();
duke@0 3444 }
duke@0 3445 }
duke@0 3446 } // end while part of format description
duke@0 3447
duke@0 3448 // Check for closing '"' and '%}' in format description
duke@0 3449 skipws(); // Move to closing '%}'
duke@0 3450 if ( _curchar != '%' ) {
duke@0 3451 parse_err(SYNERR, "non-blank characters between closing '\"' and '%' in format");
duke@0 3452 return NULL;
duke@0 3453 }
duke@0 3454 } // Done with format description inside
duke@0 3455
duke@0 3456 skipws();
duke@0 3457 // Past format description, at '%'
duke@0 3458 if ( _curchar != '%' || *(_ptr+1) != '}' ) {
duke@0 3459 parse_err(SYNERR, "missing '%}' at end of format block");
duke@0 3460 return NULL;
duke@0 3461 }
duke@0 3462 next_char(); // Move past the '%'
duke@0 3463 next_char(); // Move past the '}'
duke@0 3464 }
duke@0 3465 else { // parameter list alone must terminate with a ';'
duke@0 3466 parse_err(SYNERR, "missing ';' after Format expression");
duke@0 3467 return NULL;
duke@0 3468 }
duke@0 3469 // Debug Stuff
duke@0 3470 if (_AD._adl_debug > 1) fprintf(stderr,"Format Rule: %s\n", desc);
duke@0 3471
duke@0 3472 skipws();
duke@0 3473 return format;
duke@0 3474 }
duke@0 3475
duke@0 3476
never@415 3477 //------------------------------template_parse-----------------------------------
never@415 3478 FormatRule* ADLParser::template_parse(void) {
never@415 3479 char *desc = NULL;
never@415 3480 FormatRule *format = (new FormatRule(desc));
never@415 3481
never@415 3482 skipws();
never@415 3483 while ( (_curchar != '%') && (*(_ptr+1) != '}') ) {
never@415 3484
never@415 3485 // (1)
never@415 3486 // Check if there is a string to pass through to output
never@415 3487 char *start = _ptr; // Record start of the next string
never@415 3488 while ((_curchar != '$') && ((_curchar != '%') || (*(_ptr+1) != '}')) ) {
never@415 3489 // If at the start of a comment, skip past it
never@415 3490 if( (_curchar == '/') && ((*(_ptr+1) == '/') || (*(_ptr+1) == '*')) ) {
never@415 3491 skipws_no_preproc();
never@415 3492 } else {
never@415 3493 // ELSE advance to the next character, or start of the next line
never@415 3494 next_char_or_line();
never@415 3495 }
never@415 3496 }
never@415 3497 // If a string was found, terminate it and record in EncClass
never@415 3498 if ( start != _ptr ) {
never@415 3499 *_ptr = '\0'; // Terminate the string
never@415 3500 // Add flag to _strings list indicating we should check _rep_vars
never@415 3501 format->_strings.addName(NameList::_signal2);
never@415 3502 format->_strings.addName(start);
never@415 3503 }
never@415 3504
never@415 3505 // (2)
never@415 3506 // If we are at a replacement variable,
never@415 3507 // copy it and record in EncClass
never@415 3508 if ( _curchar == '$' ) {
never@415 3509 // Found replacement Variable
never@415 3510 char *rep_var = get_rep_var_ident_dup();
never@415 3511 if (strcmp(rep_var, "$emit") == 0) {
never@415 3512 // switch to normal format parsing
never@415 3513 next_char();
never@415 3514 next_char();
never@415 3515 skipws();
never@415 3516 // Check for the opening '"' inside the format description
never@415 3517 if ( _curchar == '"' ) {
never@415 3518 next_char(); // Move past the initial '"'
never@415 3519 if( _curchar == '"' ) { // Handle empty format string case
never@415 3520 *_ptr = '\0'; // Terminate empty string
never@415 3521 format->_strings.addName(_ptr);
never@415 3522 }
never@415 3523
never@415 3524 // Collect the parts of the format description
never@415 3525 // (1) strings that are passed through to tty->print
never@415 3526 // (2) replacement/substitution variable, preceeded by a '$'
never@415 3527 // (3) multi-token ANSIY C style strings
never@415 3528 while ( true ) {
never@415 3529 if ( _curchar == '%' || _curchar == '\n' ) {
never@415 3530 parse_err(SYNERR, "missing '\"' at end of format block");
never@415 3531 return NULL;
never@415 3532 }
never@415 3533
never@415 3534 // (1)
never@415 3535 // Check if there is a string to pass through to output
never@415 3536 char *start = _ptr; // Record start of the next string
never@415 3537 while ((_curchar != '$') && (_curchar != '"') && (_curchar != '%') && (_curchar != '\n')) {
never@415 3538 if (_curchar == '\\') next_char(); // superquote
never@415 3539 if (_curchar == '\n') parse_err(SYNERR, "newline in string"); // unimplemented!
never@415 3540 next_char();
never@415 3541 }
never@415 3542 // If a string was found, terminate it and record in FormatRule
never@415 3543 if ( start != _ptr ) {
never@415 3544 *_ptr = '\0'; // Terminate the string
never@415 3545 format->_strings.addName(start);
never@415 3546 }
never@415 3547
never@415 3548 // (2)
never@415 3549 // If we are at a replacement variable,
never@415 3550 // copy it and record in FormatRule
never@415 3551 if ( _curchar == '$' ) {
never@415 3552 next_char(); // Move past the '$'
never@415 3553 char* rep_var = get_ident(); // Nil terminate the variable name
never@415 3554 rep_var = strdup(rep_var);// Copy the string
never@415 3555 *_ptr = _curchar; // and replace Nil with original character
never@415 3556 format->_rep_vars.addName(rep_var);
never@415 3557 // Add flag to _strings list indicating we should check _rep_vars
never@415 3558 format->_strings.addName(NameList::_signal);
never@415 3559 }
never@415 3560
never@415 3561 // (3)
never@415 3562 // Allow very long strings to be broken up,
never@415 3563 // using the ANSI C syntax "foo\n" <newline> "bar"
never@415 3564 if ( _curchar == '"') {
never@415 3565 next_char(); // Move past the '"'
never@415 3566 skipws(); // Skip white space before next string token
never@415 3567 if ( _curchar != '"') {
never@415 3568 break;
never@415 3569 } else {
never@415 3570 // Found one. Skip both " and the whitespace in between.
never@415 3571 next_char();
never@415 3572 }
never@415 3573 }
never@415 3574 } // end while part of format description
never@415 3575 }
never@415 3576 } else {
never@415 3577 // Add flag to _strings list indicating we should check _rep_vars
never@415 3578 format->_rep_vars.addName(rep_var);
never@415 3579 // Add flag to _strings list indicating we should check _rep_vars
never@415 3580 format->_strings.addName(NameList::_signal3);
never@415 3581 }
never@415 3582 } // end while part of format description
never@415 3583 }
never@415 3584
never@415 3585 skipws();
never@415 3586 // Past format description, at '%'
never@415 3587 if ( _curchar != '%' || *(_ptr+1) != '}' ) {
never@415 3588 parse_err(SYNERR, "missing '%}' at end of format block");
never@415 3589 return NULL;
never@415 3590 }
never@415 3591 next_char(); // Move past the '%'
never@415 3592 next_char(); // Move past the '}'
never@415 3593
never@415 3594 // Debug Stuff
never@415 3595 if (_AD._adl_debug > 1) fprintf(stderr,"Format Rule: %s\n", desc);
never@415 3596
never@415 3597 skipws();
never@415 3598 return format;
never@415 3599 }
never@415 3600
never@415 3601
duke@0 3602 //------------------------------effect_parse-----------------------------------
duke@0 3603 void ADLParser::effect_parse(InstructForm *instr) {
duke@0 3604 char* desc = NULL;
duke@0 3605
duke@0 3606 skipws(); // Skip whitespace
duke@0 3607 if (_curchar != '(') {
duke@0 3608 parse_err(SYNERR, "missing '(' in effect definition\n");
duke@0 3609 return;
duke@0 3610 }
duke@0 3611 // Get list of effect-operand pairs and insert into dictionary
duke@0 3612 else get_effectlist(instr->_effects, instr->_localNames);
duke@0 3613
duke@0 3614 // Debug Stuff
duke@0 3615 if (_AD._adl_debug > 1) fprintf(stderr,"Effect description: %s\n", desc);
duke@0 3616 if (_curchar != ';') {
duke@0 3617 parse_err(SYNERR, "missing ';' in Effect definition\n");
duke@0 3618 }
duke@0 3619 next_char(); // Skip ';'
duke@0 3620
duke@0 3621 }
duke@0 3622
duke@0 3623 //------------------------------expand_parse-----------------------------------
duke@0 3624 ExpandRule* ADLParser::expand_parse(InstructForm *instr) {
duke@0 3625 char *ident, *ident2;
duke@0 3626 OperandForm *oper;
duke@0 3627 InstructForm *ins;
duke@0 3628 NameAndList *instr_and_operands = NULL;
duke@0 3629 ExpandRule *exp = new ExpandRule();
duke@0 3630
duke@0 3631 // Expand is a block containing an ordered list of instructions, each of
duke@0 3632 // which has an ordered list of operands.
duke@0 3633 // Check for block delimiter
duke@0 3634 skipws(); // Skip leading whitespace
duke@0 3635 if ((_curchar != '%')
duke@0 3636 || (next_char(), (_curchar != '{')) ) { // If not open block
duke@0 3637 parse_err(SYNERR, "missing '%{' in expand definition\n");
duke@0 3638 return(NULL);
duke@0 3639 }
duke@0 3640 next_char(); // Maintain the invariant
duke@0 3641 do {
duke@0 3642 ident = get_ident(); // Grab next identifier
duke@0 3643 if (ident == NULL) {
duke@0 3644 parse_err(SYNERR, "identifier expected at %c\n", _curchar);
duke@0 3645 continue;
duke@0 3646 } // Check that you have a valid instruction
duke@0 3647 const Form *form = _globalNames[ident];
duke@0 3648 ins = form ? form->is_instruction() : NULL;
duke@0 3649 if (ins == NULL) {
duke@0 3650 // This is a new operand
duke@0 3651 oper = form ? form->is_operand() : NULL;
duke@0 3652 if (oper == NULL) {
duke@0 3653 parse_err(SYNERR, "instruction/operand name expected at %s\n", ident);
duke@0 3654 continue;
duke@0 3655 }
duke@0 3656 // Throw the operand on the _newopers list
duke@0 3657 skipws();
duke@0 3658 ident = get_unique_ident(instr->_localNames,"Operand");
duke@0 3659 if (ident == NULL) {
duke@0 3660 parse_err(SYNERR, "identifier expected at %c\n", _curchar);
duke@0 3661 continue;
duke@0 3662 }
duke@0 3663 exp->_newopers.addName(ident);
duke@0 3664 // Add new operand to LocalNames
duke@0 3665 instr->_localNames.Insert(ident, oper);
duke@0 3666 // Grab any constructor code and save as a string
duke@0 3667 char *c = NULL;
duke@0 3668 skipws();
duke@0 3669 if (_curchar == '%') { // Need a constructor for the operand
duke@0 3670 c = find_cpp_block("Operand Constructor");
duke@0 3671 if (c == NULL) {
duke@0 3672 parse_err(SYNERR, "Invalid code block for operand constructor\n", _curchar);
duke@0 3673 continue;
duke@0 3674 }
duke@0 3675 // Add constructor to _newopconst Dict
duke@0 3676 exp->_newopconst.Insert(ident, c);
duke@0 3677 }
duke@0 3678 else if (_curchar != ';') { // If no constructor, need a ;
duke@0 3679 parse_err(SYNERR, "Missing ; in expand rule operand declaration\n");
duke@0 3680 continue;
duke@0 3681 }
duke@0 3682 else next_char(); // Skip the ;
duke@0 3683 skipws();
duke@0 3684 }
duke@0 3685 else {
duke@0 3686 // Add instruction to list
duke@0 3687 instr_and_operands = new NameAndList(ident);
duke@0 3688 // Grab operands, build nameList of them, and then put into dictionary
duke@0 3689 skipws();
duke@0 3690 if (_curchar != '(') { // Check for parenthesized operand list
duke@0 3691 parse_err(SYNERR, "missing '(' in expand instruction declaration\n");
duke@0 3692 continue;
duke@0 3693 }
duke@0 3694 do {
duke@0 3695 next_char(); // skip open paren & comma characters
duke@0 3696 skipws();
duke@0 3697 if (_curchar == ')') break;
duke@0 3698 ident2 = get_ident();
duke@0 3699 skipws();
duke@0 3700 if (ident2 == NULL) {
duke@0 3701 parse_err(SYNERR, "identifier expected at %c\n", _curchar);
duke@0 3702 continue;
duke@0 3703 } // Check that you have a valid operand
duke@0 3704 const Form *form = instr->_localNames[ident2];
duke@0 3705 if (!form) {
duke@0 3706 parse_err(SYNERR, "operand name expected at %s\n", ident2);
duke@0 3707 continue;
duke@0 3708 }
duke@0 3709 oper = form->is_operand();
duke@0 3710 if (oper == NULL && !form->is_opclass()) {
duke@0 3711 parse_err(SYNERR, "operand name expected at %s\n", ident2);
duke@0 3712 continue;
duke@0 3713 } // Add operand to list
duke@0 3714 instr_and_operands->add_entry(ident2);
duke@0 3715 } while(_curchar == ',');
duke@0 3716 if (_curchar != ')') {
duke@0 3717 parse_err(SYNERR, "missing ')'in expand instruction declaration\n");
duke@0 3718 continue;
duke@0 3719 }
duke@0 3720 next_char();
duke@0 3721 if (_curchar != ';') {
duke@0 3722 parse_err(SYNERR, "missing ';'in expand instruction declaration\n");
duke@0 3723 continue;
duke@0 3724 }
duke@0 3725 next_char();
duke@0 3726
duke@0 3727 // Record both instruction name and its operand list
duke@0 3728 exp->add_instruction(instr_and_operands);
duke@0 3729
duke@0 3730 skipws();
duke@0 3731 }
duke@0 3732
duke@0 3733 } while(_curchar != '%');
duke@0 3734 next_char();
duke@0 3735 if (_curchar != '}') {
duke@0 3736 parse_err(SYNERR, "missing '%}' in expand rule definition\n");
duke@0 3737 return(NULL);
duke@0 3738 }
duke@0 3739 next_char();
duke@0 3740
duke@0 3741 // Debug Stuff
duke@0 3742 if (_AD._adl_debug > 1) fprintf(stderr,"Expand Rule:\n");
duke@0 3743
duke@0 3744 skipws();
duke@0 3745 return (exp);
duke@0 3746 }
duke@0 3747
duke@0 3748 //------------------------------rewrite_parse----------------------------------
duke@0 3749 RewriteRule* ADLParser::rewrite_parse(void) {
duke@0 3750 char* params = NULL;
duke@0 3751 char* desc = NULL;
duke@0 3752
duke@0 3753
duke@0 3754 // This feature targeted for second generation description language.
duke@0 3755
duke@0 3756 skipws(); // Skip whitespace
duke@0 3757 // Get parameters for rewrite
duke@0 3758 if ((params = get_paren_expr("rewrite parameters")) == NULL) {
duke@0 3759 parse_err(SYNERR, "missing '(' in rewrite rule\n");
duke@0 3760 return NULL;
duke@0 3761 }
duke@0 3762 // Debug Stuff
duke@0 3763 if (_AD._adl_debug > 1) fprintf(stderr,"Rewrite parameters: %s\n", params);
duke@0 3764
duke@0 3765 // For now, grab entire block;
duke@0 3766 skipws();
duke@0 3767 if ( (desc = find_cpp_block("rewrite block")) == NULL ) {
duke@0 3768 parse_err(SYNERR, "incorrect or missing block for 'rewrite'.\n");
duke@0 3769 return NULL;
duke@0 3770 }