src/share/vm/adlc/adlparse.hpp

changeset 0
f90c822e73f8
child 6876
710a3c8b516e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/adlc/adlparse.hpp	Wed Apr 27 01:25:04 2016 +0800
     1.3 @@ -0,0 +1,291 @@
     1.4 +/*
     1.5 + * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +#ifndef SHARE_VM_ADLC_ADLPARSE_HPP
    1.29 +#define SHARE_VM_ADLC_ADLPARSE_HPP
    1.30 +
    1.31 +// ADLPARSE.HPP - Definitions for Architecture Description Language Parser
    1.32 +// Authors: Chris Vick and Mike Paleczny
    1.33 +
    1.34 +// Class List
    1.35 +class Form;
    1.36 +// ***** Top Level, 1, classes  *****
    1.37 +class InstructForm;
    1.38 +class OperandForm;
    1.39 +class OpClassForm;
    1.40 +class AttributeForm;
    1.41 +class RegisterForm;
    1.42 +class PipelineForm;
    1.43 +class SourceForm;
    1.44 +class Peephole;
    1.45 +// ***** Level 2 classes *****
    1.46 +class Component;
    1.47 +class Predicate;
    1.48 +class MatchRule;
    1.49 +class Encode;
    1.50 +class Attribute;
    1.51 +class Effect;
    1.52 +class ExpandRule;
    1.53 +class RewriteRule;
    1.54 +class Constraint;
    1.55 +class ConstructRule;
    1.56 +// ***** Register Section *****
    1.57 +class RegDef;
    1.58 +class RegClass;
    1.59 +class AllocClass;
    1.60 +class ResourceForm;
    1.61 +// ***** Pipeline Section *****
    1.62 +class PipeDesc;
    1.63 +class PipeClass;
    1.64 +class RegList;
    1.65 +// ***** Peephole Section *****
    1.66 +class PeepMatch;
    1.67 +class PeepConstraint;
    1.68 +class PeepReplace;
    1.69 +
    1.70 +// class ostream; // ostream is a typedef in some systems
    1.71 +
    1.72 +extern char *toUpper(const char *str);
    1.73 +
    1.74 +//---------------------------ADLParser-----------------------------------------
    1.75 +class ADLParser {
    1.76 +protected:
    1.77 +  char     *_curline;           // Start of current line
    1.78 +  char     *_ptr;               // Pointer into current location in File Buffer
    1.79 +  char      _curchar;           // Current character from buffer
    1.80 +  FormDict &_globalNames;       // Global names
    1.81 +
    1.82 +  enum { _preproc_limit = 20 };
    1.83 +  int       _preproc_depth;                 // How deep are we into ifdefs?
    1.84 +  int       _preproc_not_taken;             // How deep in not-taken ifdefs?
    1.85 +  bool      _preproc_taken[_preproc_limit]; // Are we taking this ifdef level?
    1.86 +  bool      _preproc_else[_preproc_limit];  // Did this level have an else yet?
    1.87 +
    1.88 +  // ***** Level 1 Parse functions *****
    1.89 +  void instr_parse(void);       // Parse instruction definitions
    1.90 +  void oper_parse(void);        // Parse operand definitions
    1.91 +  void opclass_parse(void);     // Parse operand class definitions
    1.92 +  void ins_attr_parse(void);    // Parse instruction attrubute definitions
    1.93 +  void op_attr_parse(void);     // Parse operand attrubute definitions
    1.94 +  void source_parse(void);      // Parse source section
    1.95 +  void source_hpp_parse(void);  // Parse source_hpp section
    1.96 +  void reg_parse(void);         // Parse register section
    1.97 +  void encode_parse(void);      // Parse encoding section
    1.98 +  void frame_parse(void);       // Parse frame section
    1.99 +  void pipe_parse(void);        // Parse pipeline section
   1.100 +  void definitions_parse(void); // Parse definitions section
   1.101 +  void peep_parse(void);        // Parse peephole rule definitions
   1.102 +  void preproc_line(void);      // Parse a #line statement
   1.103 +  void preproc_define(void);    // Parse a #define statement
   1.104 +  void preproc_undef(void);     // Parse an #undef statement
   1.105 +
   1.106 +  // Helper functions for instr_parse().
   1.107 +  void adjust_set_rule(InstructForm *instr);
   1.108 +  void matchrule_clone_and_swap(MatchRule *rule, const char* instr_ident, int& match_rules_cnt);
   1.109 +
   1.110 +  // ***** Level 2 Parse functions *****
   1.111 +  // Parse the components of the encode section
   1.112 +  void enc_class_parse(void);   // Parse encoding class definition
   1.113 +  void enc_class_parse_block(EncClass* encoding, char* ec_name);
   1.114 +
   1.115 +  // Parse the components of the frame section
   1.116 +  void stack_dir_parse(FrameForm *frame);   // Parse the stack direction entry
   1.117 +  void sync_stack_slots_parse(FrameForm *frame);
   1.118 +  void frame_pointer_parse(FrameForm *frame, bool native);
   1.119 +  void interpreter_frame_pointer_parse(FrameForm *frame, bool native);
   1.120 +  void inline_cache_parse(FrameForm *frame, bool native);
   1.121 +  void interpreter_arg_ptr_parse(FrameForm *frame, bool native);
   1.122 +  void interpreter_method_oop_parse(FrameForm *frame, bool native);
   1.123 +  void cisc_spilling_operand_name_parse(FrameForm *frame, bool native);
   1.124 +  void stack_alignment_parse(FrameForm *frame);
   1.125 +  void return_addr_parse(FrameForm *frame, bool native);
   1.126 +  void preserve_stack_parse(FrameForm *frame);
   1.127 +  char *calling_convention_parse();
   1.128 +  char *return_value_parse();
   1.129 +
   1.130 +  // Parse components of the register section
   1.131 +  void reg_def_parse(void);              // Parse register definition
   1.132 +  void reg_class_parse(void);            // Parse register class definition
   1.133 +  void alloc_class_parse(void);          // Parse allocation class definition
   1.134 +
   1.135 +  // Parse components of the definition section
   1.136 +  void int_def_parse(void);              // Parse an integer definition
   1.137 +
   1.138 +  // Parse components of a pipeline rule
   1.139 +  void resource_parse(PipelineForm &pipe);   // Parse resource definition
   1.140 +  void pipe_desc_parse(PipelineForm &pipe);  // Parse pipeline description definition
   1.141 +  void pipe_class_parse(PipelineForm &pipe); // Parse pipeline class definition
   1.142 +
   1.143 +  // Parse components of a peephole rule
   1.144 +  void peep_match_parse(Peephole &peep);     // Parse the peephole match rule
   1.145 +  void peep_constraint_parse(Peephole &peep);// Parse the peephole constraints
   1.146 +  void peep_replace_parse(Peephole &peep);   // Parse peephole replacement rule
   1.147 +
   1.148 +  // Parse the peep match rule tree
   1.149 +  InstructForm *peep_match_child_parse(PeepMatch &match, int parent, int &position, int input);
   1.150 +
   1.151 +  // Parse components of an operand and/or instruction form
   1.152 +  Predicate     *pred_parse(void);       // Parse predicate rule
   1.153 +  // Parse match rule, and internal nodes
   1.154 +  MatchRule     *match_parse(FormDict &operands);
   1.155 +  MatchNode     *matchNode_parse(FormDict &operands, int &depth,
   1.156 +                                 int &numleaves, bool atroot);
   1.157 +  MatchNode     *matchChild_parse(FormDict &operands, int &depth,
   1.158 +                                  int &numleaves, bool atroot);
   1.159 +
   1.160 +  Attribute     *attr_parse(char *ident);// Parse instr/operand attribute rule
   1.161 +  // Parse instruction encode rule
   1.162 +  void           ins_encode_parse(InstructForm &inst);
   1.163 +  void           ins_encode_parse_block(InstructForm &inst);
   1.164 +  void           ins_encode_parse_block_impl(InstructForm& inst, EncClass* encoding, char* ec_name);
   1.165 +  // Parse instruction postalloc expand rule.
   1.166 +  void           postalloc_expand_parse(InstructForm &inst);
   1.167 +
   1.168 +  void           constant_parse(InstructForm& inst);
   1.169 +  void           constant_parse_expression(EncClass* encoding, char* ec_name);
   1.170 +
   1.171 +  Opcode        *opcode_parse(InstructForm *insr); // Parse instruction opcode
   1.172 +  char          *size_parse(InstructForm *insr); // Parse instruction size
   1.173 +  Interface     *interface_parse();      // Parse operand interface rule
   1.174 +  Interface     *mem_interface_parse();  // Parse memory interface rule
   1.175 +  Interface     *cond_interface_parse(); // Parse conditional interface rule
   1.176 +  char          *interface_field_parse(const char** format = NULL);// Parse field contents
   1.177 +
   1.178 +  FormatRule    *format_parse(void);     // Parse format rule
   1.179 +  FormatRule    *template_parse(void);     // Parse format rule
   1.180 +  void           effect_parse(InstructForm *instr); // Parse effect rule
   1.181 +  ExpandRule    *expand_parse(InstructForm *instr); // Parse expand rule
   1.182 +  RewriteRule   *rewrite_parse(void);    // Parse rewrite rule
   1.183 +  Constraint    *constraint_parse(void); // Parse constraint rule
   1.184 +  ConstructRule *construct_parse(void);  // Parse construct rule
   1.185 +  void           ins_pipe_parse(InstructForm &instr); // Parse ins_pipe rule
   1.186 +
   1.187 +  // ***** Preprocessor functions *****
   1.188 +  void begin_if_def(bool taken) {
   1.189 +    assert(_preproc_depth < _preproc_limit, "#ifdef nesting limit");
   1.190 +    int ppn = _preproc_depth++;
   1.191 +    _preproc_taken[ppn] = taken;
   1.192 +    // Invariant:  _preproc_not_taken = SUM !_preproc_taken[0.._preproc_depth)
   1.193 +    if (!_preproc_taken[ppn])  _preproc_not_taken += 1;
   1.194 +    _preproc_else[ppn] = false;
   1.195 +  }
   1.196 +  void invert_if_def() {
   1.197 +    assert(_preproc_depth > 0, "#ifdef matching");
   1.198 +    int ppn = _preproc_depth - 1;
   1.199 +    assert(!_preproc_else[ppn], "multiple #else lines");
   1.200 +    _preproc_else[ppn] = true;
   1.201 +    if (!_preproc_taken[ppn])  _preproc_not_taken -= 1;
   1.202 +    _preproc_taken[ppn] = !_preproc_taken[ppn];
   1.203 +    if (!_preproc_taken[ppn])  _preproc_not_taken += 1;
   1.204 +  }
   1.205 +  void end_if_def() {
   1.206 +    assert(_preproc_depth > 0, "#ifdef matching");
   1.207 +    int ppn = --_preproc_depth;
   1.208 +    if (!_preproc_taken[ppn])  _preproc_not_taken -= 1;
   1.209 +  }
   1.210 +  bool preproc_taken() {
   1.211 +    // Return true only if there is no directive hiding this text position.
   1.212 +    return _preproc_not_taken == 0;
   1.213 +  }
   1.214 +  // Handle a '#' token.  Return true if it disappeared.
   1.215 +  bool handle_preproc_token();
   1.216 +
   1.217 +  // ***** Utility Functions for ADL Parser ******
   1.218 +
   1.219 +  // Parse one string argument inside parens:  '(' string ')' ';'
   1.220 +  char *parse_one_arg(const char *description);
   1.221 +
   1.222 +  // Return the next identifier given a pointer into a line of the buffer.
   1.223 +  char *get_ident()            { return get_ident_common(true); }
   1.224 +  char *get_ident_no_preproc() { return get_ident_common(false); }
   1.225 +  char *get_ident_common(bool do_preproc);      // Grab it from the file buffer
   1.226 +  char *get_ident_dup(void);    // Grab a duplicate of the identifier
   1.227 +  char *get_ident_or_literal_constant(const char* description);
   1.228 +  // Grab unique identifier from file buffer
   1.229 +  char *get_unique_ident(FormDict &dict, const char *nameDescription);
   1.230 +  // Return the next replacement variable identifier
   1.231 +  char *get_rep_var_ident(void);
   1.232 +  // Skip first '$' and make a duplicate of the string
   1.233 +  char *get_rep_var_ident_dup(void);
   1.234 +  // Return the next token given as a signed integer.
   1.235 +  int   get_int(void);
   1.236 +  // Return the next token, a relational operator { ==, !=, <=, >= }
   1.237 +  char *get_relation_dup(void);
   1.238 +
   1.239 +  void  get_oplist(NameList &parameters, FormDict &operands);// Parse type-operand pairs
   1.240 +  void  get_effectlist(FormDict &effects, FormDict &operands, bool& has_call); // Parse effect-operand pairs
   1.241 +  // Return the contents of a parenthesized expression.
   1.242 +  // Requires initial '(' and consumes final ')', which is replaced by '\0'.
   1.243 +  char *get_paren_expr(const char *description, bool include_location = false);
   1.244 +  // Return expression up to next stop-char, which terminator replaces.
   1.245 +  // Does not require initial '('.  Does not consume final stop-char.
   1.246 +  // Final stop-char is left in _curchar, but is also is replaced by '\0'.
   1.247 +  char *get_expr(const char *description, const char *stop_chars);
   1.248 +  char *find_cpp_block(const char *description); // Parse a C++ code block
   1.249 +  // Issue parser error message & go to EOL
   1.250 +  void parse_err(int flag, const char *fmt, ...);
   1.251 +  // Create a location marker for this file and line.
   1.252 +  char *get_line_string(int linenum = 0);
   1.253 +  // Return a location marker which tells the C preprocessor to
   1.254 +  // forget the previous location marker.  (Requires awk postprocessing.)
   1.255 +  char *end_line_marker() { return (char*)"\n#line 999999\n"; }
   1.256 +
   1.257 +  // Return pointer to current character
   1.258 +  inline char  cur_char(void);
   1.259 +  // Advance to next character, assign this to _curchar
   1.260 +  inline void  next_char(void);
   1.261 +  inline void  next_char_or_line(void);
   1.262 +  // Advance File Buffer to next line, updating _curline
   1.263 +  inline void  next_line(void);
   1.264 +  // Issue an error if we are not at the beginning of a line (exc. whitespace).
   1.265 +  void ensure_start_of_line(void);
   1.266 +  // Issue an error if we are not at the end of a line (exc. whitespace).
   1.267 +  void ensure_end_of_line(void);
   1.268 +  // Skip whitespace, leaving ptr pointing to first non-whitespace character
   1.269 +  // Also handle preprocessor constructs like "#ifdef".
   1.270 +  void skipws()                { skipws_common(true); }
   1.271 +  // Skip comments and spaces but not newlines or preprocessor constructs.
   1.272 +  void skipws_no_preproc()     { skipws_common(false); }
   1.273 +  void skipws_common(bool do_preproc);
   1.274 +
   1.275 +  FileBuff &_buf;               // File buffer to be parsed
   1.276 +  ArchDesc &_AD;                // Architecture Description being built
   1.277 +
   1.278 +public:
   1.279 +
   1.280 +  ADLParser(FileBuff &buf, ArchDesc &archDesc); // Create new ADLParser object
   1.281 +  ~ADLParser();                 // Destroy ADLParser object
   1.282 +
   1.283 +  void parse(void);             // Do the parsing & build forms lists
   1.284 +
   1.285 +  int linenum() { return _buf.linenum(); }
   1.286 +
   1.287 +  static bool is_literal_constant(const char *hex_string);
   1.288 +  static bool is_hex_digit(char digit);
   1.289 +  static bool is_int_token(const char* token, int& intval);
   1.290 +  static bool equivalent_expressions(const char* str1, const char* str2);
   1.291 +  static void trim(char* &token);  // trim leading & trailing spaces
   1.292 +};
   1.293 +
   1.294 +#endif // SHARE_VM_ADLC_ADLPARSE_HPP

mercurial