src/share/vm/adlc/adlparse.hpp

Wed, 31 Jan 2018 19:24:57 -0500

author
dbuck
date
Wed, 31 Jan 2018 19:24:57 -0500
changeset 9289
427b2fb1944f
parent 7853
a1642365d69f
child 7994
04ff2f6cd0eb
permissions
-rw-r--r--

8189170: Add option to disable stack overflow checking in primordial thread for use with JNI_CreateJavaJVM
Reviewed-by: dcubed

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

mercurial