src/share/vm/adlc/adlparse.hpp

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #ifndef SHARE_VM_ADLC_ADLPARSE_HPP
aoqi@0 26 #define SHARE_VM_ADLC_ADLPARSE_HPP
aoqi@0 27
aoqi@0 28 // ADLPARSE.HPP - Definitions for Architecture Description Language Parser
aoqi@0 29 // Authors: Chris Vick and Mike Paleczny
aoqi@0 30
aoqi@0 31 // Class List
aoqi@0 32 class Form;
aoqi@0 33 // ***** Top Level, 1, classes *****
aoqi@0 34 class InstructForm;
aoqi@0 35 class OperandForm;
aoqi@0 36 class OpClassForm;
aoqi@0 37 class AttributeForm;
aoqi@0 38 class RegisterForm;
aoqi@0 39 class PipelineForm;
aoqi@0 40 class SourceForm;
aoqi@0 41 class Peephole;
aoqi@0 42 // ***** Level 2 classes *****
aoqi@0 43 class Component;
aoqi@0 44 class Predicate;
aoqi@0 45 class MatchRule;
aoqi@0 46 class Encode;
aoqi@0 47 class Attribute;
aoqi@0 48 class Effect;
aoqi@0 49 class ExpandRule;
aoqi@0 50 class RewriteRule;
aoqi@0 51 class Constraint;
aoqi@0 52 class ConstructRule;
aoqi@0 53 // ***** Register Section *****
aoqi@0 54 class RegDef;
aoqi@0 55 class RegClass;
aoqi@0 56 class AllocClass;
aoqi@0 57 class ResourceForm;
aoqi@0 58 // ***** Pipeline Section *****
aoqi@0 59 class PipeDesc;
aoqi@0 60 class PipeClass;
aoqi@0 61 class RegList;
aoqi@0 62 // ***** Peephole Section *****
aoqi@0 63 class PeepMatch;
aoqi@0 64 class PeepConstraint;
aoqi@0 65 class PeepReplace;
aoqi@0 66
aoqi@0 67 // class ostream; // ostream is a typedef in some systems
aoqi@0 68
aoqi@0 69 extern char *toUpper(const char *str);
aoqi@0 70
aoqi@0 71 //---------------------------ADLParser-----------------------------------------
aoqi@0 72 class ADLParser {
aoqi@0 73 protected:
aoqi@0 74 char *_curline; // Start of current line
aoqi@0 75 char *_ptr; // Pointer into current location in File Buffer
aoqi@0 76 char _curchar; // Current character from buffer
aoqi@0 77 FormDict &_globalNames; // Global names
aoqi@0 78
aoqi@0 79 enum { _preproc_limit = 20 };
aoqi@0 80 int _preproc_depth; // How deep are we into ifdefs?
aoqi@0 81 int _preproc_not_taken; // How deep in not-taken ifdefs?
aoqi@0 82 bool _preproc_taken[_preproc_limit]; // Are we taking this ifdef level?
aoqi@0 83 bool _preproc_else[_preproc_limit]; // Did this level have an else yet?
aoqi@0 84
aoqi@0 85 // ***** Level 1 Parse functions *****
aoqi@0 86 void instr_parse(void); // Parse instruction definitions
aoqi@0 87 void oper_parse(void); // Parse operand definitions
aoqi@0 88 void opclass_parse(void); // Parse operand class definitions
aoqi@0 89 void ins_attr_parse(void); // Parse instruction attrubute definitions
aoqi@0 90 void op_attr_parse(void); // Parse operand attrubute definitions
aoqi@0 91 void source_parse(void); // Parse source section
aoqi@0 92 void source_hpp_parse(void); // Parse source_hpp section
aoqi@0 93 void reg_parse(void); // Parse register section
aoqi@0 94 void encode_parse(void); // Parse encoding section
aoqi@0 95 void frame_parse(void); // Parse frame section
aoqi@0 96 void pipe_parse(void); // Parse pipeline section
aoqi@0 97 void definitions_parse(void); // Parse definitions section
aoqi@0 98 void peep_parse(void); // Parse peephole rule definitions
aoqi@0 99 void preproc_line(void); // Parse a #line statement
aoqi@0 100 void preproc_define(void); // Parse a #define statement
aoqi@0 101 void preproc_undef(void); // Parse an #undef statement
aoqi@0 102
aoqi@0 103 // Helper functions for instr_parse().
aoqi@0 104 void adjust_set_rule(InstructForm *instr);
aoqi@0 105 void matchrule_clone_and_swap(MatchRule *rule, const char* instr_ident, int& match_rules_cnt);
aoqi@0 106
aoqi@0 107 // ***** Level 2 Parse functions *****
aoqi@0 108 // Parse the components of the encode section
aoqi@0 109 void enc_class_parse(void); // Parse encoding class definition
aoqi@0 110 void enc_class_parse_block(EncClass* encoding, char* ec_name);
aoqi@0 111
aoqi@0 112 // Parse the components of the frame section
aoqi@0 113 void stack_dir_parse(FrameForm *frame); // Parse the stack direction entry
aoqi@0 114 void sync_stack_slots_parse(FrameForm *frame);
aoqi@0 115 void frame_pointer_parse(FrameForm *frame, bool native);
aoqi@0 116 void interpreter_frame_pointer_parse(FrameForm *frame, bool native);
aoqi@0 117 void inline_cache_parse(FrameForm *frame, bool native);
aoqi@0 118 void interpreter_arg_ptr_parse(FrameForm *frame, bool native);
aoqi@0 119 void interpreter_method_oop_parse(FrameForm *frame, bool native);
aoqi@0 120 void cisc_spilling_operand_name_parse(FrameForm *frame, bool native);
aoqi@0 121 void stack_alignment_parse(FrameForm *frame);
aoqi@0 122 void return_addr_parse(FrameForm *frame, bool native);
aoqi@0 123 void preserve_stack_parse(FrameForm *frame);
aoqi@0 124 char *calling_convention_parse();
aoqi@0 125 char *return_value_parse();
aoqi@0 126
aoqi@0 127 // Parse components of the register section
aoqi@0 128 void reg_def_parse(void); // Parse register definition
aoqi@0 129 void reg_class_parse(void); // Parse register class definition
aoqi@0 130 void alloc_class_parse(void); // Parse allocation class definition
aoqi@0 131
aoqi@0 132 // Parse components of the definition section
aoqi@0 133 void int_def_parse(void); // Parse an integer definition
aoqi@0 134
aoqi@0 135 // Parse components of a pipeline rule
aoqi@0 136 void resource_parse(PipelineForm &pipe); // Parse resource definition
aoqi@0 137 void pipe_desc_parse(PipelineForm &pipe); // Parse pipeline description definition
aoqi@0 138 void pipe_class_parse(PipelineForm &pipe); // Parse pipeline class definition
aoqi@0 139
aoqi@0 140 // Parse components of a peephole rule
aoqi@0 141 void peep_match_parse(Peephole &peep); // Parse the peephole match rule
aoqi@0 142 void peep_constraint_parse(Peephole &peep);// Parse the peephole constraints
aoqi@0 143 void peep_replace_parse(Peephole &peep); // Parse peephole replacement rule
aoqi@0 144
aoqi@0 145 // Parse the peep match rule tree
aoqi@0 146 InstructForm *peep_match_child_parse(PeepMatch &match, int parent, int &position, int input);
aoqi@0 147
aoqi@0 148 // Parse components of an operand and/or instruction form
aoqi@0 149 Predicate *pred_parse(void); // Parse predicate rule
aoqi@0 150 // Parse match rule, and internal nodes
aoqi@0 151 MatchRule *match_parse(FormDict &operands);
aoqi@0 152 MatchNode *matchNode_parse(FormDict &operands, int &depth,
aoqi@0 153 int &numleaves, bool atroot);
aoqi@0 154 MatchNode *matchChild_parse(FormDict &operands, int &depth,
aoqi@0 155 int &numleaves, bool atroot);
aoqi@0 156
aoqi@0 157 Attribute *attr_parse(char *ident);// Parse instr/operand attribute rule
aoqi@0 158 // Parse instruction encode rule
aoqi@0 159 void ins_encode_parse(InstructForm &inst);
aoqi@0 160 void ins_encode_parse_block(InstructForm &inst);
aoqi@0 161 void ins_encode_parse_block_impl(InstructForm& inst, EncClass* encoding, char* ec_name);
aoqi@0 162 // Parse instruction postalloc expand rule.
aoqi@0 163 void postalloc_expand_parse(InstructForm &inst);
aoqi@0 164
aoqi@0 165 void constant_parse(InstructForm& inst);
aoqi@0 166 void constant_parse_expression(EncClass* encoding, char* ec_name);
aoqi@0 167
aoqi@0 168 Opcode *opcode_parse(InstructForm *insr); // Parse instruction opcode
aoqi@0 169 char *size_parse(InstructForm *insr); // Parse instruction size
aoqi@0 170 Interface *interface_parse(); // Parse operand interface rule
aoqi@0 171 Interface *mem_interface_parse(); // Parse memory interface rule
aoqi@0 172 Interface *cond_interface_parse(); // Parse conditional interface rule
aoqi@0 173 char *interface_field_parse(const char** format = NULL);// Parse field contents
aoqi@0 174
aoqi@0 175 FormatRule *format_parse(void); // Parse format rule
aoqi@0 176 FormatRule *template_parse(void); // Parse format rule
aoqi@0 177 void effect_parse(InstructForm *instr); // Parse effect rule
aoqi@0 178 ExpandRule *expand_parse(InstructForm *instr); // Parse expand rule
aoqi@0 179 RewriteRule *rewrite_parse(void); // Parse rewrite rule
aoqi@0 180 Constraint *constraint_parse(void); // Parse constraint rule
aoqi@0 181 ConstructRule *construct_parse(void); // Parse construct rule
aoqi@0 182 void ins_pipe_parse(InstructForm &instr); // Parse ins_pipe rule
aoqi@0 183
aoqi@0 184 // ***** Preprocessor functions *****
aoqi@0 185 void begin_if_def(bool taken) {
aoqi@0 186 assert(_preproc_depth < _preproc_limit, "#ifdef nesting limit");
aoqi@0 187 int ppn = _preproc_depth++;
aoqi@0 188 _preproc_taken[ppn] = taken;
aoqi@0 189 // Invariant: _preproc_not_taken = SUM !_preproc_taken[0.._preproc_depth)
aoqi@0 190 if (!_preproc_taken[ppn]) _preproc_not_taken += 1;
aoqi@0 191 _preproc_else[ppn] = false;
aoqi@0 192 }
aoqi@0 193 void invert_if_def() {
aoqi@0 194 assert(_preproc_depth > 0, "#ifdef matching");
aoqi@0 195 int ppn = _preproc_depth - 1;
aoqi@0 196 assert(!_preproc_else[ppn], "multiple #else lines");
aoqi@0 197 _preproc_else[ppn] = true;
aoqi@0 198 if (!_preproc_taken[ppn]) _preproc_not_taken -= 1;
aoqi@0 199 _preproc_taken[ppn] = !_preproc_taken[ppn];
aoqi@0 200 if (!_preproc_taken[ppn]) _preproc_not_taken += 1;
aoqi@0 201 }
aoqi@0 202 void end_if_def() {
aoqi@0 203 assert(_preproc_depth > 0, "#ifdef matching");
aoqi@0 204 int ppn = --_preproc_depth;
aoqi@0 205 if (!_preproc_taken[ppn]) _preproc_not_taken -= 1;
aoqi@0 206 }
aoqi@0 207 bool preproc_taken() {
aoqi@0 208 // Return true only if there is no directive hiding this text position.
aoqi@0 209 return _preproc_not_taken == 0;
aoqi@0 210 }
aoqi@0 211 // Handle a '#' token. Return true if it disappeared.
aoqi@0 212 bool handle_preproc_token();
aoqi@0 213
aoqi@0 214 // ***** Utility Functions for ADL Parser ******
aoqi@0 215
aoqi@0 216 // Parse one string argument inside parens: '(' string ')' ';'
aoqi@0 217 char *parse_one_arg(const char *description);
aoqi@0 218
aoqi@0 219 // Return the next identifier given a pointer into a line of the buffer.
aoqi@0 220 char *get_ident() { return get_ident_common(true); }
aoqi@0 221 char *get_ident_no_preproc() { return get_ident_common(false); }
aoqi@0 222 char *get_ident_common(bool do_preproc); // Grab it from the file buffer
aoqi@0 223 char *get_ident_dup(void); // Grab a duplicate of the identifier
aoqi@0 224 char *get_ident_or_literal_constant(const char* description);
aoqi@0 225 // Grab unique identifier from file buffer
aoqi@0 226 char *get_unique_ident(FormDict &dict, const char *nameDescription);
aoqi@0 227 // Return the next replacement variable identifier
aoqi@0 228 char *get_rep_var_ident(void);
aoqi@0 229 // Skip first '$' and make a duplicate of the string
aoqi@0 230 char *get_rep_var_ident_dup(void);
aoqi@0 231 // Return the next token given as a signed integer.
aoqi@0 232 int get_int(void);
aoqi@0 233 // Return the next token, a relational operator { ==, !=, <=, >= }
aoqi@0 234 char *get_relation_dup(void);
aoqi@0 235
aoqi@0 236 void get_oplist(NameList &parameters, FormDict &operands);// Parse type-operand pairs
aoqi@0 237 void get_effectlist(FormDict &effects, FormDict &operands, bool& has_call); // Parse effect-operand pairs
aoqi@0 238 // Return the contents of a parenthesized expression.
aoqi@0 239 // Requires initial '(' and consumes final ')', which is replaced by '\0'.
aoqi@0 240 char *get_paren_expr(const char *description, bool include_location = false);
aoqi@0 241 // Return expression up to next stop-char, which terminator replaces.
aoqi@0 242 // Does not require initial '('. Does not consume final stop-char.
aoqi@0 243 // Final stop-char is left in _curchar, but is also is replaced by '\0'.
aoqi@0 244 char *get_expr(const char *description, const char *stop_chars);
aoqi@0 245 char *find_cpp_block(const char *description); // Parse a C++ code block
aoqi@0 246 // Issue parser error message & go to EOL
aoqi@0 247 void parse_err(int flag, const char *fmt, ...);
aoqi@0 248 // Create a location marker for this file and line.
aoqi@0 249 char *get_line_string(int linenum = 0);
aoqi@0 250 // Return a location marker which tells the C preprocessor to
aoqi@0 251 // forget the previous location marker. (Requires awk postprocessing.)
aoqi@0 252 char *end_line_marker() { return (char*)"\n#line 999999\n"; }
aoqi@0 253
aoqi@0 254 // Return pointer to current character
aoqi@0 255 inline char cur_char(void);
aoqi@0 256 // Advance to next character, assign this to _curchar
aoqi@0 257 inline void next_char(void);
aoqi@0 258 inline void next_char_or_line(void);
aoqi@0 259 // Advance File Buffer to next line, updating _curline
aoqi@0 260 inline void next_line(void);
aoqi@0 261 // Issue an error if we are not at the beginning of a line (exc. whitespace).
aoqi@0 262 void ensure_start_of_line(void);
aoqi@0 263 // Issue an error if we are not at the end of a line (exc. whitespace).
aoqi@0 264 void ensure_end_of_line(void);
aoqi@0 265 // Skip whitespace, leaving ptr pointing to first non-whitespace character
aoqi@0 266 // Also handle preprocessor constructs like "#ifdef".
aoqi@0 267 void skipws() { skipws_common(true); }
aoqi@0 268 // Skip comments and spaces but not newlines or preprocessor constructs.
aoqi@0 269 void skipws_no_preproc() { skipws_common(false); }
aoqi@0 270 void skipws_common(bool do_preproc);
aoqi@0 271
aoqi@0 272 FileBuff &_buf; // File buffer to be parsed
aoqi@0 273 ArchDesc &_AD; // Architecture Description being built
aoqi@0 274
aoqi@0 275 public:
aoqi@0 276
aoqi@0 277 ADLParser(FileBuff &buf, ArchDesc &archDesc); // Create new ADLParser object
aoqi@0 278 ~ADLParser(); // Destroy ADLParser object
aoqi@0 279
aoqi@0 280 void parse(void); // Do the parsing & build forms lists
aoqi@0 281
aoqi@0 282 int linenum() { return _buf.linenum(); }
aoqi@0 283
aoqi@0 284 static bool is_literal_constant(const char *hex_string);
aoqi@0 285 static bool is_hex_digit(char digit);
aoqi@0 286 static bool is_int_token(const char* token, int& intval);
aoqi@0 287 static bool equivalent_expressions(const char* str1, const char* str2);
aoqi@0 288 static void trim(char* &token); // trim leading & trailing spaces
aoqi@0 289 };
aoqi@0 290
aoqi@0 291 #endif // SHARE_VM_ADLC_ADLPARSE_HPP

mercurial