annotate src/share/vm/adlc/adlparse.hpp @ 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.HPP - Definitions for Architecture Description Language Parser
duke@0 26 // Authors: Chris Vick and Mike Paleczny
duke@0 27
duke@0 28 // Class List
duke@0 29 class Form;
duke@0 30 // ***** Top Level, 1, classes *****
duke@0 31 class InstructForm;
duke@0 32 class OperandForm;
duke@0 33 class OpClassForm;
duke@0 34 class AttributeForm;
duke@0 35 class RegisterForm;
duke@0 36 class PipelineForm;
duke@0 37 class SourceForm;
duke@0 38 class Peephole;
duke@0 39 // ***** Level 2 classes *****
duke@0 40 class Component;
duke@0 41 class Predicate;
duke@0 42 class MatchRule;
duke@0 43 class Encode;
duke@0 44 class Attribute;
duke@0 45 class Effect;
duke@0 46 class ExpandRule;
duke@0 47 class RewriteRule;
duke@0 48 class Constraint;
duke@0 49 class ConstructRule;
duke@0 50 // ***** Register Section *****
duke@0 51 class RegDef;
duke@0 52 class RegClass;
duke@0 53 class AllocClass;
duke@0 54 class ResourceForm;
duke@0 55 // ***** Pipeline Section *****
duke@0 56 class PipeDesc;
duke@0 57 class PipeClass;
duke@0 58 class RegList;
duke@0 59 // ***** Peephole Section *****
duke@0 60 class PeepMatch;
duke@0 61 class PeepConstraint;
duke@0 62 class PeepReplace;
duke@0 63
duke@0 64 // class ostream; // ostream is a typedef in some systems
duke@0 65
duke@0 66 extern char *toUpper(const char *str);
duke@0 67
duke@0 68 //---------------------------ADLParser-----------------------------------------
duke@0 69 class ADLParser {
duke@0 70 protected:
duke@0 71 char *_curline; // Start of current line
duke@0 72 char *_ptr; // Pointer into current location in File Buffer
duke@0 73 char _curchar; // Current character from buffer
duke@0 74 FormDict &_globalNames; // Global names
duke@0 75
duke@0 76 enum { _preproc_limit = 20 };
duke@0 77 int _preproc_depth; // How deep are we into ifdefs?
duke@0 78 int _preproc_not_taken; // How deep in not-taken ifdefs?
duke@0 79 bool _preproc_taken[_preproc_limit]; // Are we taking this ifdef level?
duke@0 80 bool _preproc_else[_preproc_limit]; // Did this level have an else yet?
duke@0 81
duke@0 82 // ***** Level 1 Parse functions *****
duke@0 83 void instr_parse(void); // Parse instruction definitions
duke@0 84 void oper_parse(void); // Parse operand definitions
duke@0 85 void opclass_parse(void); // Parse operand class definitions
duke@0 86 void ins_attr_parse(void); // Parse instruction attrubute definitions
duke@0 87 void op_attr_parse(void); // Parse operand attrubute definitions
duke@0 88 void source_parse(void); // Parse source section
duke@0 89 void source_hpp_parse(void); // Parse source_hpp section
duke@0 90 void reg_parse(void); // Parse register section
duke@0 91 void encode_parse(void); // Parse encoding section
duke@0 92 void frame_parse(void); // Parse frame section
duke@0 93 void pipe_parse(void); // Parse pipeline section
duke@0 94 void definitions_parse(void); // Parse definitions section
duke@0 95 void peep_parse(void); // Parse peephole rule definitions
duke@0 96 void preproc_define(void); // Parse a #define statement
duke@0 97 void preproc_undef(void); // Parse an #undef statement
duke@0 98
duke@0 99 // Helper functions for instr_parse().
duke@0 100 void adjust_set_rule(InstructForm *instr);
duke@0 101 void matchrule_clone_and_swap(MatchRule *rule, const char* instr_ident, int& match_rules_cnt);
duke@0 102
duke@0 103 // ***** Level 2 Parse functions *****
duke@0 104 // Parse the components of the encode section
duke@0 105 void enc_class_parse(void); // Parse encoding class definition
duke@0 106 void enc_class_parse_block(EncClass* encoding, char* ec_name);
duke@0 107
duke@0 108 // Parse the components of the frame section
duke@0 109 void stack_dir_parse(FrameForm *frame); // Parse the stack direction entry
duke@0 110 void sync_stack_slots_parse(FrameForm *frame);
duke@0 111 void frame_pointer_parse(FrameForm *frame, bool native);
duke@0 112 void interpreter_frame_pointer_parse(FrameForm *frame, bool native);
duke@0 113 void inline_cache_parse(FrameForm *frame, bool native);
duke@0 114 void interpreter_arg_ptr_parse(FrameForm *frame, bool native);
duke@0 115 void interpreter_method_oop_parse(FrameForm *frame, bool native);
duke@0 116 void cisc_spilling_operand_name_parse(FrameForm *frame, bool native);
duke@0 117 void stack_alignment_parse(FrameForm *frame);
duke@0 118 void return_addr_parse(FrameForm *frame, bool native);
duke@0 119 void preserve_stack_parse(FrameForm *frame);
duke@0 120 char *calling_convention_parse();
duke@0 121 char *return_value_parse();
duke@0 122
duke@0 123 // Parse components of the register section
duke@0 124 void reg_def_parse(void); // Parse register definition
duke@0 125 void reg_class_parse(void); // Parse register class definition
duke@0 126 void alloc_class_parse(void); // Parse allocation class definition
duke@0 127
duke@0 128 // Parse components of the definition section
duke@0 129 void int_def_parse(void); // Parse an integer definition
duke@0 130
duke@0 131 // Parse components of a pipeline rule
duke@0 132 void resource_parse(PipelineForm &pipe); // Parse resource definition
duke@0 133 void pipe_desc_parse(PipelineForm &pipe); // Parse pipeline description definition
duke@0 134 void pipe_class_parse(PipelineForm &pipe); // Parse pipeline class definition
duke@0 135
duke@0 136 // Parse components of a peephole rule
duke@0 137 void peep_match_parse(Peephole &peep); // Parse the peephole match rule
duke@0 138 void peep_constraint_parse(Peephole &peep);// Parse the peephole constraints
duke@0 139 void peep_replace_parse(Peephole &peep); // Parse peephole replacement rule
duke@0 140
duke@0 141 // Parse the peep match rule tree
duke@0 142 InstructForm *peep_match_child_parse(PeepMatch &match, int parent, int &position, int input);
duke@0 143
duke@0 144 // Parse components of an operand and/or instruction form
duke@0 145 Predicate *pred_parse(void); // Parse predicate rule
duke@0 146 // Parse match rule, and internal nodes
duke@0 147 MatchRule *match_parse(FormDict &operands);
duke@0 148 MatchNode *matchNode_parse(FormDict &operands, int &depth,
duke@0 149 int &numleaves, bool atroot);
duke@0 150 MatchNode *matchChild_parse(FormDict &operands, int &depth,
duke@0 151 int &numleaves, bool atroot);
duke@0 152
duke@0 153 Attribute *attr_parse(char *ident);// Parse instr/operand attribute rule
duke@0 154 // Parse instruction encode rule
duke@0 155 InsEncode *ins_encode_parse(InstructForm &inst);
duke@0 156 InsEncode *ins_encode_parse_block(InstructForm &inst);
duke@0 157 Opcode *opcode_parse(InstructForm *insr); // Parse instruction opcode
duke@0 158 char *size_parse(InstructForm *insr); // Parse instruction size
duke@0 159 Interface *interface_parse(); // Parse operand interface rule
duke@0 160 Interface *mem_interface_parse(); // Parse memory interface rule
duke@0 161 Interface *cond_interface_parse(); // Parse conditional interface rule
never@415 162 char *interface_field_parse(const char** format = NULL);// Parse field contents
duke@0 163
duke@0 164 FormatRule *format_parse(void); // Parse format rule
never@415 165 FormatRule *template_parse(void); // Parse format rule
duke@0 166 void effect_parse(InstructForm *instr); // Parse effect rule
duke@0 167 ExpandRule *expand_parse(InstructForm *instr); // Parse expand rule
duke@0 168 RewriteRule *rewrite_parse(void); // Parse rewrite rule
duke@0 169 Constraint *constraint_parse(void); // Parse constraint rule
duke@0 170 ConstructRule *construct_parse(void); // Parse construct rule
duke@0 171 void ins_pipe_parse(InstructForm &instr); // Parse ins_pipe rule
duke@0 172
duke@0 173 // ***** Preprocessor functions *****
duke@0 174 void begin_if_def(bool taken) {
duke@0 175 assert(_preproc_depth < _preproc_limit, "#ifdef nesting limit");
duke@0 176 int ppn = _preproc_depth++;
duke@0 177 _preproc_taken[ppn] = taken;
duke@0 178 // Invariant: _preproc_not_taken = SUM !_preproc_taken[0.._preproc_depth)
duke@0 179 if (!_preproc_taken[ppn]) _preproc_not_taken += 1;
duke@0 180 _preproc_else[ppn] = false;
duke@0 181 }
duke@0 182 void invert_if_def() {
duke@0 183 assert(_preproc_depth > 0, "#ifdef matching");
duke@0 184 int ppn = _preproc_depth - 1;
duke@0 185 assert(!_preproc_else[ppn], "multiple #else lines");
duke@0 186 _preproc_else[ppn] = true;
duke@0 187 if (!_preproc_taken[ppn]) _preproc_not_taken -= 1;
duke@0 188 _preproc_taken[ppn] = !_preproc_taken[ppn];
duke@0 189 if (!_preproc_taken[ppn]) _preproc_not_taken += 1;
duke@0 190 }
duke@0 191 void end_if_def() {
duke@0 192 assert(_preproc_depth > 0, "#ifdef matching");
duke@0 193 int ppn = --_preproc_depth;
duke@0 194 if (!_preproc_taken[ppn]) _preproc_not_taken -= 1;
duke@0 195 }
duke@0 196 bool preproc_taken() {
duke@0 197 // Return true only if there is no directive hiding this text position.
duke@0 198 return _preproc_not_taken == 0;
duke@0 199 }
duke@0 200 // Handle a '#' token. Return true if it disappeared.
duke@0 201 bool handle_preproc_token();
duke@0 202
duke@0 203 // ***** Utility Functions for ADL Parser ******
duke@0 204
duke@0 205 // Parse one string argument inside parens: '(' string ')' ';'
duke@0 206 char *parse_one_arg(const char *description);
duke@0 207
duke@0 208 // Return the next identifier given a pointer into a line of the buffer.
duke@0 209 char *get_ident() { return get_ident_common(true); }
duke@0 210 char *get_ident_no_preproc() { return get_ident_common(false); }
duke@0 211 char *get_ident_common(bool do_preproc); // Grab it from the file buffer
duke@0 212 char *get_ident_dup(void); // Grab a duplicate of the identifier
duke@0 213 char *get_ident_or_literal_constant(const char* description);
duke@0 214 // Grab unique identifier from file buffer
duke@0 215 char *get_unique_ident(FormDict &dict, const char *nameDescription);
duke@0 216 // Return the next replacement variable identifier
duke@0 217 char *get_rep_var_ident(void);
duke@0 218 // Skip first '$' and make a duplicate of the string
duke@0 219 char *get_rep_var_ident_dup(void);
duke@0 220 // Return the next token given as a signed integer.
duke@0 221 int get_int(void);
duke@0 222 // Return the next token, a relational operator { ==, !=, <=, >= }
duke@0 223 char *get_relation_dup(void);
duke@0 224
duke@0 225 void get_oplist(NameList &parameters, FormDict &operands);// Parse type-operand pairs
duke@0 226 void get_effectlist(FormDict &effects, FormDict &operands); // Parse effect-operand pairs
duke@0 227 // Return the contents of a parenthesized expression.
duke@0 228 // Requires initial '(' and consumes final ')', which is replaced by '\0'.
duke@0 229 char *get_paren_expr(const char *description);
duke@0 230 // Return expression up to next stop-char, which terminator replaces.
duke@0 231 // Does not require initial '('. Does not consume final stop-char.
duke@0 232 // Final stop-char is left in _curchar, but is also is replaced by '\0'.
duke@0 233 char *get_expr(const char *description, const char *stop_chars);
duke@0 234 char *find_cpp_block(const char *description); // Parse a C++ code block
duke@0 235 // Issue parser error message & go to EOL
duke@0 236 void parse_err(int flag, const char *fmt, ...);
duke@0 237
duke@0 238 // Return pointer to current character
duke@0 239 inline char cur_char(void);
duke@0 240 // Advance to next character, assign this to _curchar
duke@0 241 inline void next_char(void);
duke@0 242 inline void next_char_or_line(void);
duke@0 243 // Advance File Buffer to next line, updating _curline
duke@0 244 inline void next_line(void);
duke@0 245 // Issue an error if we are not at the beginning of a line (exc. whitespace).
duke@0 246 void ensure_start_of_line(void);
duke@0 247 // Issue an error if we are not at the end of a line (exc. whitespace).
duke@0 248 void ensure_end_of_line(void);
duke@0 249 // Skip whitespace, leaving ptr pointing to first non-whitespace character
duke@0 250 // Also handle preprocessor constructs like "#ifdef".
duke@0 251 void skipws() { skipws_common(true); }
duke@0 252 // Skip comments and spaces but not newlines or preprocessor constructs.
duke@0 253 void skipws_no_preproc() { skipws_common(false); }
duke@0 254 void skipws_common(bool do_preproc);
duke@0 255
duke@0 256 FileBuff &_buf; // File buffer to be parsed
duke@0 257 ArchDesc &_AD; // Architecture Description being built
duke@0 258
duke@0 259 public:
duke@0 260
duke@0 261 ADLParser(FileBuff &buf, ArchDesc &archDesc); // Create new ADLParser object
duke@0 262 ~ADLParser(); // Destroy ADLParser object
duke@0 263
duke@0 264 void parse(void); // Do the parsing & build forms lists
duke@0 265
never@415 266 int linenum() { return _buf.linenum(); }
duke@0 267
duke@0 268 static bool is_literal_constant(const char *hex_string);
duke@0 269 static bool is_hex_digit(char digit);
duke@0 270 static bool is_int_token(const char* token, int& intval);
duke@0 271 static void trim(char* &token); // trim leading & trailing spaces
duke@0 272 };